mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-20 07:58:12 +00:00
perf: 添加任务模板
This commit is contained in:
parent
902844e008
commit
74fecdd941
@ -2762,8 +2762,8 @@ class ProjectController extends AbstractController
|
|||||||
if (empty($name)) {
|
if (empty($name)) {
|
||||||
return Base::retError('请输入模板名称');
|
return Base::retError('请输入模板名称');
|
||||||
}
|
}
|
||||||
if (empty($title)) {
|
if (empty($title) && empty($content)) {
|
||||||
return Base::retError('请输入任务标题');
|
return Base::retError('请输入任务标题或内容');
|
||||||
}
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'project_id' => $projectId,
|
'project_id' => $projectId,
|
||||||
@ -2823,7 +2823,7 @@ class ProjectController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} api/project/task/template_default 50. 设置任务模板为默认
|
* @api {get} api/project/task/template_default 50. 设置(取消)任务模板为默认
|
||||||
*
|
*
|
||||||
* @apiDescription 需要token身份(限:项目负责人)
|
* @apiDescription 需要token身份(限:项目负责人)
|
||||||
* @apiVersion 1.0.0
|
* @apiVersion 1.0.0
|
||||||
@ -2854,9 +2854,12 @@ class ProjectController extends AbstractController
|
|||||||
if (!$template) {
|
if (!$template) {
|
||||||
return Base::retError('模板不存在或已被删除');
|
return Base::retError('模板不存在或已被删除');
|
||||||
}
|
}
|
||||||
// 先将所有模板设为非默认
|
if ($template->is_default) {
|
||||||
|
$template->update(['is_default' => false]);
|
||||||
|
return Base::retSuccess('取消成功');
|
||||||
|
}
|
||||||
|
//
|
||||||
ProjectTaskTemplate::where('project_id', $projectId)->update(['is_default' => false]);
|
ProjectTaskTemplate::where('project_id', $projectId)->update(['is_default' => false]);
|
||||||
// 设置当前模板为默认
|
|
||||||
$template->update(['is_default' => true]);
|
$template->update(['is_default' => true]);
|
||||||
return Base::retSuccess('设置成功');
|
return Base::retSuccess('设置成功');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,8 +21,8 @@
|
|||||||
<span v-if="item.is_default" class="default-tag">{{$L('默认')}}</span>
|
<span v-if="item.is_default" class="default-tag">{{$L('默认')}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="template-content">
|
<div class="template-content">
|
||||||
<div class="task-title">{{ item.title }}</div>
|
<div v-if="item.title" class="task-title">{{ item.title }}</div>
|
||||||
<div class="task-content">
|
<div v-if="item.content" class="task-content">
|
||||||
<VMPreviewNostyle ref="descPreview" :value="item.content"/>
|
<VMPreviewNostyle ref="descPreview" :value="item.content"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -96,9 +96,6 @@ export default {
|
|||||||
formRules: {
|
formRules: {
|
||||||
name: [
|
name: [
|
||||||
{ required: true, message: this.$L('请输入模板名称'), trigger: 'blur' }
|
{ required: true, message: this.$L('请输入模板名称'), trigger: 'blur' }
|
||||||
],
|
|
||||||
title: [
|
|
||||||
{ required: true, message: this.$L('请输入任务标题'), trigger: 'blur' }
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +132,7 @@ export default {
|
|||||||
})
|
})
|
||||||
this.templates = data || []
|
this.templates = data || []
|
||||||
} catch ({msg}) {
|
} catch ({msg}) {
|
||||||
this.$Message.error(msg || this.$L('加载模板失败'))
|
$A.messageError(msg || '加载模板失败')
|
||||||
}
|
}
|
||||||
this.loading = false
|
this.loading = false
|
||||||
},
|
},
|
||||||
@ -155,7 +152,7 @@ export default {
|
|||||||
// 保存模板
|
// 保存模板
|
||||||
async handleSave() {
|
async handleSave() {
|
||||||
if (!this.editingTemplate.name) {
|
if (!this.editingTemplate.name) {
|
||||||
this.$Message.warning(this.$L('请输入模板名称'))
|
$A.messageWarning('请输入模板名称')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,19 +163,19 @@ export default {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
spinner: 300
|
spinner: 300
|
||||||
})
|
})
|
||||||
this.$Message.success(this.$L('保存成功'))
|
$A.messageSuccess('保存成功')
|
||||||
this.showEditModal = false
|
this.showEditModal = false
|
||||||
this.loadTemplates()
|
this.loadTemplates()
|
||||||
} catch ({msg}) {
|
} catch ({msg}) {
|
||||||
this.$Message.error(msg || this.$L('保存失败'))
|
$A.messageError(msg || '保存失败')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 删除模板
|
// 删除模板
|
||||||
async handleDelete(template) {
|
async handleDelete(template) {
|
||||||
this.$Modal.confirm({
|
$A.modalConfirm({
|
||||||
title: this.$L('确认删除'),
|
title: '确认删除',
|
||||||
content: this.$L('确定要删除该模板吗?'),
|
content: '确定要删除该模板吗?',
|
||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch("call", {
|
await this.$store.dispatch("call", {
|
||||||
@ -188,10 +185,10 @@ export default {
|
|||||||
},
|
},
|
||||||
spinner: 300
|
spinner: 300
|
||||||
})
|
})
|
||||||
this.$Message.success(this.$L('删除成功'))
|
$A.messageSuccess('删除成功')
|
||||||
this.loadTemplates()
|
this.loadTemplates()
|
||||||
} catch ({msg}) {
|
} catch ({msg}) {
|
||||||
this.$Message.error(msg || this.$L('删除失败'))
|
$A.messageError(msg || '删除失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -199,10 +196,6 @@ export default {
|
|||||||
|
|
||||||
// 设置默认模板
|
// 设置默认模板
|
||||||
async handleSetDefault(template) {
|
async handleSetDefault(template) {
|
||||||
if (template.is_default) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch("call", {
|
await this.$store.dispatch("call", {
|
||||||
url: 'project/task/template_default',
|
url: 'project/task/template_default',
|
||||||
@ -212,10 +205,10 @@ export default {
|
|||||||
},
|
},
|
||||||
spinner: 300
|
spinner: 300
|
||||||
})
|
})
|
||||||
this.$Message.success(this.$L('设置成功'))
|
$A.messageSuccess('设置成功')
|
||||||
this.loadTemplates()
|
this.loadTemplates()
|
||||||
} catch ({msg}) {
|
} catch ({msg}) {
|
||||||
this.$Message.error(msg || this.$L('设置失败'))
|
$A.messageError(msg || '设置失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,11 @@
|
|||||||
filterable/>
|
filterable/>
|
||||||
</div>
|
</div>
|
||||||
<ul v-if="taskTemplateList.length > 0" class="task-add-template">
|
<ul v-if="taskTemplateList.length > 0" class="task-add-template">
|
||||||
<li v-for="item in taskTemplateList" :key="item.id" @click="setTaskTemplate(item)">
|
<li
|
||||||
|
v-for="item in taskTemplateList"
|
||||||
|
:key="item.id"
|
||||||
|
:class="{active:templateActiveID === item.id}"
|
||||||
|
@click="setTaskTemplate(item)">
|
||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -268,7 +272,10 @@ export default {
|
|||||||
|
|
||||||
beforeClose: [],
|
beforeClose: [],
|
||||||
|
|
||||||
addContinue: false
|
addContinue: false,
|
||||||
|
|
||||||
|
templateActiveID: 0,
|
||||||
|
templateCompareData: {name: '', content: ''},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -279,7 +286,10 @@ export default {
|
|||||||
async mounted() {
|
async mounted() {
|
||||||
this.initCascaderData();
|
this.initCascaderData();
|
||||||
await this.initProjectData();
|
await this.initProjectData();
|
||||||
this.$nextTick(() => this.$refs.input.focus())
|
this.$nextTick(() => {
|
||||||
|
this.$refs.input.focus();
|
||||||
|
this.templateCompareData = {name: this.addData.name, content: this.addData.content};
|
||||||
|
})
|
||||||
this.isMounted = true
|
this.isMounted = true
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -325,12 +335,7 @@ export default {
|
|||||||
'addData.project_id'(projectId) {
|
'addData.project_id'(projectId) {
|
||||||
if (projectId > 0) {
|
if (projectId > 0) {
|
||||||
$A.IDBSave("cacheAddTaskProjectId", projectId);
|
$A.IDBSave("cacheAddTaskProjectId", projectId);
|
||||||
this.$store.dispatch("updateTaskTemplates", projectId).then(() => {
|
this.$store.dispatch("updateTaskTemplates", projectId).then(this.setTaskDefaultTemplate)
|
||||||
const defaultTemplate = this.taskTemplateList.find(({is_default}) => is_default);
|
|
||||||
if (defaultTemplate) {
|
|
||||||
this.setTaskTemplate(defaultTemplate);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'addData.column_id'(columnId) {
|
'addData.column_id'(columnId) {
|
||||||
@ -555,11 +560,7 @@ export default {
|
|||||||
this.$store.dispatch("taskAdd", this.addData).then(({msg}) => {
|
this.$store.dispatch("taskAdd", this.addData).then(({msg}) => {
|
||||||
$A.messageSuccess(msg);
|
$A.messageSuccess(msg);
|
||||||
if (continued === true) {
|
if (continued === true) {
|
||||||
this.addData = Object.assign({}, this.addData, {
|
this.addData = Object.assign({}, this.addData, this.templateCompareData, {subtasks: []});
|
||||||
name: "",
|
|
||||||
content: "",
|
|
||||||
subtasks: [],
|
|
||||||
});
|
|
||||||
this.$refs.input.focus();
|
this.$refs.input.focus();
|
||||||
} else {
|
} else {
|
||||||
this.addData = $A.cloneJSON(this.addDefault);
|
this.addData = $A.cloneJSON(this.addDefault);
|
||||||
@ -626,11 +627,33 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setTaskTemplate(item) {
|
setTaskTemplate(item, force = false) {
|
||||||
this.addData.name = item.title
|
if (force) {
|
||||||
this.addData.content = nostyle(item.content, {
|
this.templateActiveID = item.id;
|
||||||
sanitize: false,
|
this.addData.name = item.name;
|
||||||
});
|
this.addData.content = nostyle(item.content, {sanitize: false});
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.$refs.input.focus();
|
||||||
|
this.templateCompareData = {name: this.addData.name, content: this.addData.content};
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((this.addData.name !== this.templateCompareData.name && this.addData.name !== '') ||
|
||||||
|
(this.addData.content !== this.templateCompareData.content && this.addData.content !== '')) {
|
||||||
|
$A.modalConfirm({
|
||||||
|
content: '当前已有修改的内容,是否要覆盖?',
|
||||||
|
onOk: () => this.setTaskTemplate(item, true)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setTaskTemplate(item, true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setTaskDefaultTemplate() {
|
||||||
|
const defaultTemplate = this.taskTemplateList.find(({is_default}) => is_default);
|
||||||
|
if (defaultTemplate) {
|
||||||
|
this.setTaskTemplate(defaultTemplate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,6 +53,7 @@
|
|||||||
.template-title {
|
.template-title {
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
|
height: 22px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: $primary-title-color;
|
color: $primary-title-color;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user