fix: 无法添加任务的问题

This commit is contained in:
kuaifan 2022-07-20 11:35:19 +08:00
parent b73c931b8b
commit 49744a3671
2 changed files with 72 additions and 85 deletions

View File

@ -913,13 +913,19 @@ export default {
} }
}, },
onAddTask(data) { onAddTask(params) {
this.$refs.addTask.defaultPriority(); this.addTaskShow = true
this.$refs.addTask.setData($A.isJson(data) ? data : { this.$nextTick(_ => {
'owner': [this.userId], let data = {
'column_id': data, owner: [this.userId],
}); }
this.addTaskShow = true; if ($A.isJson(params)) {
data = params
} else if (/^[1-9]\d*$/.test(params)) {
data.column_id = params
}
this.$refs.addTask.setData(data)
})
}, },
openTask(task) { openTask(task) {

View File

@ -1,5 +1,5 @@
<template> <template>
<div v-if="ready" class="task-add"> <div class="task-add">
<div class="head" :class="{empty:addData.cascader.length == 0,visible:cascaderShow}"> <div class="head" :class="{empty:addData.cascader.length == 0,visible:cascaderShow}">
<Cascader <Cascader
v-model="addData.cascader" v-model="addData.cascader"
@ -157,8 +157,8 @@
<script> <script>
import TEditor from "../../../components/TEditor"; import TEditor from "../../../components/TEditor";
import {mapState} from "vuex";
import UserInput from "../../../components/UserInput"; import UserInput from "../../../components/UserInput";
import {mapState} from "vuex";
export default { export default {
name: "TaskAdd", name: "TaskAdd",
@ -171,8 +171,6 @@ export default {
}, },
data() { data() {
return { return {
ready: false,
addData: { addData: {
cascader: [], cascader: [],
name: "", name: "",
@ -229,9 +227,20 @@ export default {
beforeClose: [], beforeClose: [],
} }
}, },
mounted() {
mounted() {
this.initCascaderData();
this.initProjectData();
this.$nextTick(() => this.$refs.input.focus())
}, },
beforeDestroy() {
this.beforeClose.some(func => {
typeof func === "function" && func()
})
this.beforeClose = [];
},
computed: { computed: {
...mapState(['cacheProjects', 'projectId', 'cacheColumns', 'taskPriority']), ...mapState(['cacheProjects', 'projectId', 'cacheColumns', 'taskPriority']),
@ -251,47 +260,30 @@ export default {
return !this.addData.owner.includes(this.userId); return !this.addData.owner.includes(this.userId);
} }
}, },
watch: { watch: {
value(val) { 'addData.project_id'(projectId) {
if (val) { if (projectId > 0) {
this.ready = true; $A.setStorage("cacheAddTaskProjectId", projectId);
this.initCascaderData();
this.initProjectData();
this.$nextTick(() => {
this.$refs.input.focus()
})
} else {
this.beforeClose.some(func => {
typeof func === "function" && func()
})
this.beforeClose = [];
this.taskTimeOpen = false;
} }
}, },
'addData.project_id'(id) { 'addData.column_id'(columnId) {
if (id > 0) { if (columnId > 0) {
$A.setStorage("cacheAddTaskProjectId", id); $A.setStorage("cacheAddTaskColumnId", columnId);
} }
},
'addData.column_id'(id) {
const {project_id} = this.addData; const {project_id} = this.addData;
this.$nextTick(() => { if (project_id && columnId) {
if (project_id && id) { this.$set(this.addData, 'cascader', [project_id, columnId]);
this.$set(this.addData, 'cascader', [project_id, id]); } else {
} else { this.$set(this.addData, 'cascader', []);
this.$set(this.addData, 'cascader', []);
}
})
if (id > 0) {
$A.setStorage("cacheAddTaskColumnId", id);
} }
} }
}, },
methods: { methods: {
initLanguage() { /**
* 初始化级联数据
}, */
initCascaderData() { initCascaderData() {
const data = $A.cloneJSON(this.cacheProjects).sort((a, b) => { const data = $A.cloneJSON(this.cacheProjects).sort((a, b) => {
if (a.top_at || b.top_at) { if (a.top_at || b.top_at) {
@ -306,7 +298,7 @@ export default {
label: column.name label: column.name
} }
}); });
let data = { const data = {
value: project.id, value: project.id,
label: project.name, label: project.name,
children, children,
@ -318,42 +310,37 @@ export default {
}); });
}, },
/**
* 初始化项目列表优先级
*/
initProjectData() { initProjectData() {
let column_id = this.addData.column_id; //
if (column_id) { let cacheAddTaskProjectId = $A.getStorageInt("cacheAddTaskProjectId");
let column = this.cacheColumns.find(({id}) => id == column_id); let project = this.cacheProjects.find(({id}) => id == this.projectId)
|| this.cacheProjects.find(({id}) => id == cacheAddTaskProjectId)
|| this.cacheProjects.find(({id}) => id > 0);
if (project) {
let cacheAddTaskColumnId = $A.getStorageInt("cacheAddTaskColumnId");
let column = this.cacheColumns.find(({project_id, id}) => project_id == project.id && id == cacheAddTaskColumnId)
|| this.cacheColumns.find(({project_id}) => project_id == project.id);
if (column) { if (column) {
this.addData.project_id = column.project_id; this.addData.project_id = column.project_id;
this.addData.column_id = column.id; this.addData.column_id = column.id;
} } else {
} else { this.$store.dispatch("getColumns", project.id).then(() => {
let cacheAddTaskProjectId = $A.getStorageInt("cacheAddTaskProjectId"); column = this.cacheColumns.find(({project_id, id}) => project_id == project.id && id == cacheAddTaskColumnId)
let cacheAddTaskColumnId = $A.getStorageInt("cacheAddTaskColumnId"); || this.cacheColumns.find(({project_id}) => project_id == project.id);
let project = this.cacheProjects.find(({id}) => id == this.projectId) if (column) {
|| this.cacheProjects.find(({id}) => id == cacheAddTaskProjectId) this.addData.project_id = column.project_id;
|| this.cacheProjects.find(({id}) => id > 0); this.addData.column_id = column.id;
if (project) { }
let column = this.cacheColumns.find(({project_id, id}) => project_id == project.id && id == cacheAddTaskColumnId) }).catch(() => {});
|| this.cacheColumns.find(({project_id}) => project_id == project.id);
if (column) {
this.addData.project_id = column.project_id;
this.addData.column_id = column.id;
} else {
this.$store.dispatch("getColumns", project.id).then(() => {
column = this.cacheColumns.find(({project_id, id}) => project_id == project.id && id == cacheAddTaskColumnId)
|| this.cacheColumns.find(({project_id}) => project_id == project.id);
if (column) {
this.addData.project_id = column.project_id;
this.addData.column_id = column.id;
}
}).catch(() => {});
}
} }
} }
}, //
if (this.taskPriority.length > 0) {
taskTimeOpenChange(val) { this.choosePriority(this.taskPriority[0]);
this.taskTimeOpen = val; }
}, },
taskTimeChange(times) { taskTimeChange(times) {
@ -368,6 +355,10 @@ export default {
} }
}, },
taskTimeOpenChange(val) {
this.taskTimeOpen = val;
},
onKeydown(e) { onKeydown(e) {
if (e.keyCode === 13) { if (e.keyCode === 13) {
if (e.shiftKey) { if (e.shiftKey) {
@ -411,16 +402,6 @@ export default {
this.$set(this.addData, 'p_color', item.color) this.$set(this.addData, 'p_color', item.color)
}, },
defaultPriority() {
if (this.taskPriority.length === 0) {
return;
}
if (this.addData.p_name) {
return;
}
this.choosePriority(this.taskPriority[0]);
},
cascaderLoadData(item, callback) { cascaderLoadData(item, callback) {
item.loading = true; item.loading = true;
this.$store.dispatch("getColumns", item.value).then((data) => { this.$store.dispatch("getColumns", item.value).then((data) => {