perf: 添加任务模板

This commit is contained in:
kuaifan 2024-12-01 20:54:38 +08:00
parent e78d850138
commit 902844e008
5 changed files with 76 additions and 1 deletions

View File

@ -12,6 +12,11 @@
@on-visible-change="cascaderShow=!cascaderShow"
filterable/>
</div>
<ul v-if="taskTemplateList.length > 0" class="task-add-template">
<li v-for="item in taskTemplateList" :key="item.id" @click="setTaskTemplate(item)">
{{ item.name }}
</li>
</ul>
<div class="task-add-form">
<div class="title">
<Input
@ -211,6 +216,7 @@ import {mapState} from "vuex";
import UserSelect from "../../../components/UserSelect.vue";
import TaskExistTips from "./TaskExistTips.vue";
import TEditorTask from "../../../components/TEditorTask.vue";
import nostyle from "../../../components/VMEditor/engine/nostyle";
export default {
name: "TaskAdd",
@ -285,7 +291,7 @@ export default {
},
computed: {
...mapState(['cacheProjects', 'projectId', 'cacheColumns', 'taskPriority', 'formOptions']),
...mapState(['cacheProjects', 'projectId', 'cacheColumns', 'taskPriority', 'taskTemplates', 'formOptions']),
taskDays() {
const {times} = this.addData;
@ -297,6 +303,10 @@ export default {
}
}
return 0;
},
taskTemplateList() {
return this.taskTemplates.filter(({project_id}) => project_id == this.addData.project_id) || []
}
},
@ -315,6 +325,12 @@ export default {
'addData.project_id'(projectId) {
if (projectId > 0) {
$A.IDBSave("cacheAddTaskProjectId", projectId);
this.$store.dispatch("updateTaskTemplates", projectId).then(() => {
const defaultTemplate = this.taskTemplateList.find(({is_default}) => is_default);
if (defaultTemplate) {
this.setTaskTemplate(defaultTemplate);
}
})
}
},
'addData.column_id'(columnId) {
@ -609,6 +625,13 @@ export default {
break;
}
},
setTaskTemplate(item) {
this.addData.name = item.title
this.addData.content = nostyle(item.content, {
sanitize: false,
});
}
}
}
</script>

View File

@ -2506,6 +2506,23 @@ export default {
});
},
/**
* 更新任务模板
* @param state
* @param dispatch
* @param projectId
* @returns {Promise<void>}
*/
async updateTaskTemplates({state, dispatch}, projectId) {
const {data} = await dispatch("call", {
url: 'project/task/template_list',
data: {
project_id: projectId
},
})
state.taskTemplates = state.taskTemplates.filter(template => template.project_id !== projectId).concat(data || [])
},
/** *****************************************************************************************/
/** ************************************** 会话 **********************************************/
/** *****************************************************************************************/

View File

@ -149,6 +149,7 @@ export default {
taskLogs: [],
taskOperation: {},
taskArchiveView: 0,
taskTemplates: [],
// 任务等待状态
taskOneLoad: {},

View File

@ -621,4 +621,14 @@ body.dark-mode-reverse {
}
}
}
.task-add {
.task-add-template {
> li {
&.active {
color: black;
}
}
}
}
}

View File

@ -68,6 +68,30 @@
}
}
}
.task-add-template {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 20px;
> li {
list-style: none;
padding: 7px 15px;
background-color: #f5f5f5;
border-radius: 20px;
transition: all 0.3s ease;
cursor: pointer;
&:hover {
background-color: #e0e0e0;
}
&.active {
background-color: $primary-color;
color: white;
}
}
}
.task-add-form,
.task-add-advanced {
.calculate-dropdown {