优化前端变量

This commit is contained in:
kuaifan 2022-01-07 23:28:07 +08:00
parent 533e8a3742
commit b987be54bf
13 changed files with 129 additions and 155 deletions

View File

@ -293,8 +293,8 @@ export default {
'userId',
'userInfo',
'userIsAdmin',
'dialogs',
'projects',
'cacheDialogs',
'cacheProjects',
'projectTotal',
'taskId',
'dialogMsgPush',
@ -304,7 +304,7 @@ export default {
msgAllUnread() {
let num = 0;
this.dialogs.map(({unread}) => {
this.cacheDialogs.map(({unread}) => {
if (unread) {
num += unread;
}
@ -344,8 +344,8 @@ export default {
},
projectLists() {
const {projectKeyValue, projects} = this;
const data = projects.sort((a, b) => {
const {projectKeyValue, cacheProjects} = this;
const data = cacheProjects.sort((a, b) => {
return b.id - a.id;
});
if (projectKeyValue) {
@ -412,7 +412,7 @@ export default {
tag: "dialog",
requireInteraction: true
});
let dialog = this.dialogs.find((item) => item.id == dialog_id);
let dialog = this.cacheDialogs.find((item) => item.id == dialog_id);
if (dialog) {
this.notificationClass.replaceTitle(dialog.name);
this.notificationClass.userAgreed();

View File

@ -28,7 +28,6 @@
:month="calendarMonth"
:theme="calendarTheme"
:template="calendarTemplate"
:calendars="calendarList"
:schedules="list"
:taskView="false"
:useCreationPopup="false"
@ -64,7 +63,6 @@ export default {
calendarMonth: {},
calendarTheme: {},
calendarTemplate: {},
calendarList: [],
loadIng: 0,
loadTimeout: null,
@ -77,12 +75,12 @@ export default {
},
computed: {
...mapState(['userId', 'projects', 'tasks']),
...mapState(['userId', 'cacheTasks']),
...mapGetters(['transforTasks']),
list() {
const datas = this.transforTasks(this.tasks.filter(({complete_at, owner, end_at}) => {
const datas = this.transforTasks(this.cacheTasks.filter(({complete_at, owner, end_at}) => {
return !complete_at && owner && end_at;
}));
return datas.map(data => {
@ -134,21 +132,6 @@ export default {
rangeTime(time) {
this.getTask(time);
},
projects: {
handler(data) {
const list = data.map((project) => {
return {
id: String(project.id),
name: project.name,
}
});
if (JSON.stringify(list) != JSON.stringify(this.calendarList)) {
this.calendarList = list;
}
},
immediate: true,
},
},
methods: {
@ -299,7 +282,7 @@ export default {
},
onBeforeClickSchedule({type, schedule}) {
let data = this.tasks.find(({id}) => id === schedule.id);
let data = this.cacheTasks.find(({id}) => id === schedule.id);
if (!data) {
return;
}
@ -343,7 +326,7 @@ export default {
onBeforeUpdateSchedule(res) {
const {changes, schedule} = res;
let data = this.tasks.find(({id}) => id === schedule.id);
let data = this.cacheTasks.find(({id}) => id === schedule.id);
if (!data) {
return;
}

View File

@ -125,13 +125,13 @@ export default {
computed: {
...mapState([
'userId',
'dialogs',
'cacheDialogs',
'dialogMsgs',
'dialogMsgPush',
]),
dialogData() {
return this.dialogs.find(({id}) => id == this.dialogId) || {};
return this.cacheDialogs.find(({id}) => id == this.dialogId) || {};
},
dialogMsgList() {

View File

@ -542,14 +542,14 @@ export default {
'windowMax768',
'userId',
'dialogs',
'cacheDialogs',
'taskPriority',
'projectId',
'projectLoad',
'tasks',
'columns',
'cacheTasks',
'cacheColumns',
]),
...mapGetters(['projectData', 'projectParameter', 'transforTasks']),
@ -569,8 +569,8 @@ export default {
},
msgUnread() {
const {dialogs, projectData} = this;
const dialog = dialogs.find(({id}) => id === projectData.dialog_id);
const {cacheDialogs, projectData} = this;
const dialog = cacheDialogs.find(({id}) => id === projectData.dialog_id);
return dialog ? dialog.unread : 0;
},
@ -604,8 +604,8 @@ export default {
},
columnList() {
const {projectId, columns, tasks} = this;
const list = columns.filter(({project_id}) => {
const {projectId, cacheColumns, cacheTasks} = this;
const list = cacheColumns.filter(({project_id}) => {
return project_id == projectId
}).sort((a, b) => {
if (a.sort != b.sort) {
@ -614,7 +614,7 @@ export default {
return a.id - b.id;
});
list.forEach((column) => {
column.tasks = this.transforTasks(tasks.filter((task) => {
column.tasks = this.transforTasks(cacheTasks.filter((task) => {
return task.column_id == column.id;
})).sort((a, b) => {
if (a.sort != b.sort) {
@ -627,8 +627,8 @@ export default {
},
myList() {
const {projectId, tasks, searchText, tempShowTasks, sortField, sortType} = this;
const array = tasks.filter((task) => {
const {projectId, cacheTasks, searchText, tempShowTasks, sortField, sortType} = this;
const array = cacheTasks.filter((task) => {
if (task.project_id != projectId) {
return false;
}
@ -660,8 +660,8 @@ export default {
},
helpList() {
const {projectId, tasks, searchText, tempShowTasks, userId, sortField, sortType} = this;
const array = tasks.filter((task) => {
const {projectId, cacheTasks, searchText, tempShowTasks, userId, sortField, sortType} = this;
const array = cacheTasks.filter((task) => {
if (task.project_id != projectId || task.parent_id > 0) {
return false;
}
@ -693,8 +693,8 @@ export default {
},
unList() {
const {projectId, tasks, searchText, sortField, sortType} = this;
const array = tasks.filter((task) => {
const {projectId, cacheTasks, searchText, sortField, sortType} = this;
const array = cacheTasks.filter((task) => {
if (task.project_id != projectId || task.parent_id > 0) {
return false;
}
@ -721,8 +721,8 @@ export default {
},
completedList() {
const {projectId, tasks, searchText} = this;
const array = tasks.filter((task) => {
const {projectId, cacheTasks, searchText} = this;
const array = cacheTasks.filter((task) => {
if (task.project_id != projectId || task.parent_id > 0) {
return false;
}
@ -741,8 +741,8 @@ export default {
},
completedCount() {
const {projectId, tasks} = this;
return tasks.filter((task) => {
const {projectId, cacheTasks} = this;
return cacheTasks.filter((task) => {
if (task.project_id != projectId || task.parent_id > 0) {
return false;
}
@ -809,7 +809,7 @@ export default {
sort = -1;
upTask.push(...item.task.map(id => {
sort++;
upTask.push(...this.tasks.filter(({parent_id}) => parent_id == id).map(({id}) => {
upTask.push(...this.cacheTasks.filter(({parent_id}) => parent_id == id).map(({id}) => {
return {
id,
sort,

View File

@ -224,7 +224,7 @@ export default {
},
computed: {
...mapState(['userId', 'projects', 'projectId', 'columns', 'taskPriority']),
...mapState(['userId', 'cacheProjects', 'projectId', 'cacheColumns', 'taskPriority']),
taskDays() {
const {times} = this.addData;
@ -324,8 +324,8 @@ export default {
},
initCascaderData() {
this.cascaderData = this.projects.map(project => {
const children = this.columns.filter(({project_id}) => project_id == project.id).map(column => {
this.cascaderData = this.cacheProjects.map(project => {
const children = this.cacheColumns.filter(({project_id}) => project_id == project.id).map(column => {
return {
value: column.id,
label: column.name
@ -346,7 +346,7 @@ export default {
initProjectData() {
let column_id = this.addData.column_id;
if (column_id) {
let column = this.columns.find(({id}) => id == column_id);
let column = this.cacheColumns.find(({id}) => id == column_id);
if (column) {
this.addData.project_id = column.project_id;
this.addData.column_id = column.id;
@ -354,19 +354,19 @@ export default {
} else {
let cacheAddTaskProjectId = $A.getStorageInt("cacheAddTaskProjectId");
let cacheAddTaskColumnId = $A.getStorageInt("cacheAddTaskColumnId");
let project = this.projects.find(({id}) => id == this.projectId)
|| this.projects.find(({id}) => id == cacheAddTaskProjectId)
|| this.projects.find(({id}) => id > 0);
let project = this.cacheProjects.find(({id}) => id == this.projectId)
|| this.cacheProjects.find(({id}) => id == cacheAddTaskProjectId)
|| this.cacheProjects.find(({id}) => id > 0);
if (project) {
let column = this.columns.find(({project_id, id}) => project_id == project.id && id == cacheAddTaskColumnId)
|| this.columns.find(({project_id}) => project_id == project.id);
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) {
this.addData.project_id = column.project_id;
this.addData.column_id = column.id;
} else {
this.$store.dispatch("getColumns", project.id).then(() => {
column = this.columns.find(({project_id, id}) => project_id == project.id && id == cacheAddTaskColumnId)
|| this.columns.find(({project_id}) => project_id == project.id);
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;

View File

@ -519,9 +519,9 @@ export default {
computed: {
...mapState([
'userId',
'projects',
'columns',
'tasks',
'cacheProjects',
'cacheColumns',
'cacheTasks',
'taskContents',
'taskFiles',
'taskPriority',
@ -534,7 +534,7 @@ export default {
if (this.taskDetail.project_name) {
return this.taskDetail.project_name;
}
const project = this.projects.find(({id}) => id == this.taskDetail.project_id)
const project = this.cacheProjects.find(({id}) => id == this.taskDetail.project_id)
return project ? project.name : '';
},
@ -545,7 +545,7 @@ export default {
if (this.taskDetail.column_name) {
return this.taskDetail.column_name;
}
const column = this.columns.find(({id}) => id == this.taskDetail.column_id)
const column = this.cacheColumns.find(({id}) => id == this.taskDetail.column_id)
return column ? column.name : '';
},
@ -572,7 +572,7 @@ export default {
if (!this.taskId) {
return [];
}
return this.tasks.filter(({parent_id}) => {
return this.cacheTasks.filter(({parent_id}) => {
return parent_id == this.taskId
}).sort((a, b) => {
return a.id - b.id;

View File

@ -193,11 +193,11 @@ export default {
},
computed: {
...mapState(['tasks', 'taskPriority', 'columns']),
...mapState(['cacheTasks', 'taskPriority', 'cacheColumns']),
subTask() {
return function(task_id) {
return this.tasks.filter(({parent_id}) => {
return this.cacheTasks.filter(({parent_id}) => {
return parent_id == task_id
}).sort((a, b) => {
return a.id - b.id;
@ -207,7 +207,7 @@ export default {
},
methods: {
columnName(column_id) {
const column = this.columns.find(({id}) => id == column_id)
const column = this.cacheColumns.find(({id}) => id == column_id)
return column ? column.name : '';
},
@ -243,7 +243,7 @@ export default {
},
columnList(id) {
return this.columns.filter(({project_id}) => project_id == id);
return this.cacheColumns.filter(({project_id}) => project_id == id);
},
openTask(task, receive) {

View File

@ -22,7 +22,7 @@
<li>
<div class="block-title">{{$L('参与的项目')}}</div>
<div class="block-data">
<div class="block-num">{{projects.length}}</div>
<div class="block-num">{{cacheProjects.length}}</div>
<i class="taskfont">&#xe6f9;</i>
</div>
</li>
@ -139,7 +139,7 @@ export default {
},
computed: {
...mapState(['userInfo', 'projects', 'tasks', 'taskId']),
...mapState(['userInfo', 'cacheProjects', 'taskId']),
...mapGetters(['dashboardTask', 'transforTasks']),

View File

@ -118,14 +118,14 @@ export default {
},
computed: {
...mapState(['userId', 'dialogs', 'dialogOpenId']),
...mapState(['userId', 'cacheDialogs', 'dialogOpenId']),
dialogList() {
const {dialogActive, dialogKey} = this;
if (dialogActive == '' && dialogKey == '') {
return this.dialogs.filter(({name}) => name !== undefined);
return this.cacheDialogs.filter(({name}) => name !== undefined);
}
return this.dialogs.filter(({name, type, group_type, last_msg}) => {
return this.cacheDialogs.filter(({name, type, group_type, last_msg}) => {
if (name === undefined) {
return false;
}
@ -160,7 +160,7 @@ export default {
msgUnread() {
return function (type) {
let num = 0;
this.dialogs.map((dialog) => {
this.cacheDialogs.map((dialog) => {
if (dialog.unread) {
switch (type) {
case 'project':
@ -233,7 +233,7 @@ export default {
openDialogStorage() {
this.dialogId = $A.getStorageInt("messenger::dialogId")
if (this.dialogId > 0) {
const dialog = this.dialogs.find(({id}) => id === this.dialogId);
const dialog = this.cacheDialogs.find(({id}) => id === this.dialogId);
dialog && this.openDialog(dialog, false);
}
},
@ -324,7 +324,7 @@ export default {
scrollMode: 'if-needed',
});
} else {
let dialog = this.dialogs.find(({id}) => id == this.dialogId)
let dialog = this.cacheDialogs.find(({id}) => id == this.dialogId)
if (dialog && this.dialogActive) {
this.dialogActive = '';
this.$nextTick(() => {

View File

@ -6,7 +6,7 @@
</template>
<script>
import {mapGetters} from "vuex";
import {mapState, mapGetters} from "vuex";
import ProjectList from "./components/ProjectList";
import ProjectDialog from "./components/ProjectDialog";
export default {
@ -22,6 +22,7 @@ export default {
},
computed: {
...mapState(['cacheProjects']),
...mapGetters(['projectParameter']),
},
@ -40,7 +41,7 @@ export default {
$A.modalWarning({
content: msg,
onOk: () => {
const project = this.$store.state.projects.find(({id}) => id);
const project = this.cacheProjects.find(({id}) => id);
if (project) {
$A.goForward({path: '/manage/project/' + project.id});
} else {

View File

@ -380,10 +380,10 @@ export default {
window.localStorage.clear();
//
state.cacheUserBasic = [];
state.cacheDialogs = state.dialogs = [];
state.cacheProjects = state.projects = [];
state.cacheColumns = state.columns = [];
state.cacheTasks = state.tasks = [];
state.cacheDialogs = [];
state.cacheProjects = [];
state.cacheColumns = [];
state.cacheTasks = [];
//
$A.setStorage("cacheProjectParameter", state.cacheProjectParameter);
$A.setStorage("cacheServerUrl", state.cacheServerUrl);
@ -517,17 +517,17 @@ export default {
dispatch("saveColumn", data.project_column)
delete data.project_column;
}
let index = state.projects.findIndex(({id}) => id == data.id);
let index = state.cacheProjects.findIndex(({id}) => id == data.id);
if (index > -1) {
state.projects.splice(index, 1, Object.assign({}, state.projects[index], data));
state.cacheProjects.splice(index, 1, Object.assign({}, state.cacheProjects[index], data));
} else {
if (typeof data.project_user === "undefined") {
data.project_user = []
}
state.projects.push(data);
state.cacheProjects.push(data);
}
setTimeout(() => {
$A.setStorage("cacheProjects", state.cacheProjects = state.projects);
$A.setStorage("cacheProjects", state.cacheProjects);
})
}
},
@ -542,13 +542,13 @@ export default {
//
let ids = $A.isArray(project_id) ? project_id : [project_id];
ids.some(id => {
let index = state.projects.findIndex(project => project.id == id);
let index = state.cacheProjects.findIndex(project => project.id == id);
if (index > -1) {
state.projects.splice(index, 1);
state.cacheProjects.splice(index, 1);
}
})
if (ids.includes(state.projectId)) {
const project = state.projects.find(({id}) => id && id != project_id);
const project = state.cacheProjects.find(({id}) => id && id != project_id);
if (project) {
$A.goForward({path: '/manage/project/' + project.id});
} else {
@ -556,7 +556,7 @@ export default {
}
}
setTimeout(() => {
$A.setStorage("cacheProjects", state.cacheProjects = state.projects);
$A.setStorage("cacheProjects", state.cacheProjects);
})
},
@ -570,13 +570,10 @@ export default {
getProjects({state, dispatch}, data) {
return new Promise(function (resolve, reject) {
if (state.userId === 0) {
state.projects = [];
state.cacheProjects = [];
reject({msg: 'Parameter error'});
return;
}
if (state.projects.length === 0 && state.cacheProjects.length > 0) {
state.projects = state.cacheProjects;
}
dispatch("call", {
url: 'project/lists',
data: data || {}
@ -724,14 +721,14 @@ export default {
dispatch("saveColumn", column)
});
} else if ($A.isJson(data)) {
let index = state.columns.findIndex(({id}) => id == data.id);
let index = state.cacheColumns.findIndex(({id}) => id == data.id);
if (index > -1) {
state.columns.splice(index, 1, Object.assign({}, state.columns[index], data));
state.cacheColumns.splice(index, 1, Object.assign({}, state.cacheColumns[index], data));
} else {
state.columns.push(data);
state.cacheColumns.push(data);
}
setTimeout(() => {
$A.setStorage("cacheColumns", state.cacheColumns = state.columns);
$A.setStorage("cacheColumns", state.cacheColumns);
})
}
},
@ -748,17 +745,17 @@ export default {
let ids = $A.isArray(column_id) ? column_id : [column_id];
let project_ids = [];
ids.some(id => {
let index = state.columns.findIndex(column => column.id == id);
let index = state.cacheColumns.findIndex(column => column.id == id);
if (index > -1) {
project_ids.push(state.columns[index].project_id)
dispatch('getProjectOne', state.columns[index].project_id)
state.columns.splice(index, 1);
project_ids.push(state.cacheColumns[index].project_id)
dispatch('getProjectOne', state.cacheColumns[index].project_id)
state.cacheColumns.splice(index, 1);
}
})
Array.from(new Set(project_ids)).some(id => dispatch("getProjectOne", id))
//
setTimeout(() => {
$A.setStorage("cacheColumns", state.cacheColumns = state.columns);
$A.setStorage("cacheColumns", state.cacheColumns);
})
},
@ -772,13 +769,10 @@ export default {
getColumns({state, dispatch}, project_id) {
return new Promise(function (resolve, reject) {
if (state.userId === 0) {
state.columns = [];
state.cacheColumns = [];
reject({msg: 'Parameter error'})
return;
}
if (state.columns.length === 0 && state.cacheColumns.length > 0) {
state.columns = state.cacheColumns;
}
state.projectLoad++;
dispatch("call", {
url: 'project/column/lists',
@ -789,12 +783,12 @@ export default {
state.projectLoad--;
//
const ids = data.data.map(({id}) => id)
state.columns = state.columns.filter((item) => item.project_id != project_id || ids.includes(item.id));
state.cacheColumns = state.cacheColumns.filter((item) => item.project_id != project_id || ids.includes(item.id));
//
dispatch("saveColumn", data.data);
resolve(data.data)
// 判断只有1列的时候默认版面为表格模式
if (state.columns.filter(item => item.project_id == project_id).length === 1) {
if (state.cacheColumns.filter(item => item.project_id == project_id).length === 1) {
const cache = state.cacheProjectParameter.find(item => item.project_id == project_id) || {};
if (typeof cache.cardInit === "undefined" || cache.cardInit === false) {
dispatch("toggleProjectParameter", {
@ -860,14 +854,14 @@ export default {
});
} else if ($A.isJson(data)) {
data._time = $A.Time();
let index = state.tasks.findIndex(({id}) => id == data.id);
let index = state.cacheTasks.findIndex(({id}) => id == data.id);
if (index > -1) {
state.tasks.splice(index, 1, Object.assign({}, state.tasks[index], data));
state.cacheTasks.splice(index, 1, Object.assign({}, state.cacheTasks[index], data));
} else {
state.tasks.push(data);
state.cacheTasks.push(data);
}
//
if (data.parent_id > 0 && state.tasks.findIndex(({id}) => id == data.parent_id) === -1) {
if (data.parent_id > 0 && state.cacheTasks.findIndex(({id}) => id == data.parent_id) === -1) {
dispatch("getTaskOne", data.parent_id);
}
if (data.is_update_project) {
@ -884,7 +878,7 @@ export default {
}
//
setTimeout(() => {
$A.setStorage("cacheTasks", state.cacheTasks = state.tasks);
$A.setStorage("cacheTasks", state.cacheTasks);
})
}
},
@ -902,13 +896,13 @@ export default {
let parent_ids = [];
let project_ids = [];
ids.some(id => {
let index = state.tasks.findIndex(task => task.id == id);
let index = state.cacheTasks.findIndex(task => task.id == id);
if (index > -1) {
if (state.tasks[index].parent_id) {
parent_ids.push(state.tasks[index].parent_id)
if (state.cacheTasks[index].parent_id) {
parent_ids.push(state.cacheTasks[index].parent_id)
}
project_ids.push(state.tasks[index].project_id)
state.tasks.splice(index, 1);
project_ids.push(state.cacheTasks[index].project_id)
state.cacheTasks.splice(index, 1);
}
})
Array.from(new Set(parent_ids)).some(id => dispatch("getTaskOne", id))
@ -918,7 +912,7 @@ export default {
state.taskId = 0;
}
setTimeout(() => {
$A.setStorage("cacheTasks", state.cacheTasks = state.tasks);
$A.setStorage("cacheTasks", state.cacheTasks);
})
},
@ -930,7 +924,7 @@ export default {
increaseTaskMsgNum({state}, dialog_id) {
$A.execMainDispatch("increaseTaskMsgNum", dialog_id)
//
const task = state.tasks.find(task => task.dialog_id === dialog_id);
const task = state.cacheTasks.find(task => task.dialog_id === dialog_id);
if (task) task.msg_num++;
},
@ -944,12 +938,12 @@ export default {
getTasks({state, dispatch}, data) {
return new Promise(function (resolve, reject) {
if (state.userId === 0) {
state.tasks = [];
state.cacheTasks = [];
reject({msg: 'Parameter error'});
return;
}
if (state.tasks.length == 0 && state.cacheTasks.length > 0) {
state.tasks = state.cacheTasks;
if (state.cacheTasks.length == 0 && state.cacheTasks.length > 0) {
state.cacheTasks = state.cacheTasks;
}
if (data.project_id) {
state.projectLoad++;
@ -1083,10 +1077,10 @@ export default {
getTaskForProject({state, dispatch}, project_id) {
return new Promise(function (resolve, reject) {
const time = $A.Time()
const currentIds = state.tasks.filter(task => task.project_id == project_id).map(({id}) => id)
const currentIds = state.cacheTasks.filter(task => task.project_id == project_id).map(({id}) => id)
//
const call = () => {
const newIds = state.tasks.filter(task => task.project_id == project_id && task._time >= time).map(({id}) => id)
const newIds = state.cacheTasks.filter(task => task.project_id == project_id && task._time >= time).map(({id}) => id)
dispatch("forgetTask", currentIds.filter(v => newIds.indexOf(v) == -1))
}
dispatch("getTasks", {project_id}).then(() => {
@ -1109,10 +1103,10 @@ export default {
getTaskForParent({state, dispatch}, parent_id) {
return new Promise(function (resolve, reject) {
const time = $A.Time()
const currentIds = state.tasks.filter(task => task.parent_id == parent_id).map(({id}) => id)
const currentIds = state.cacheTasks.filter(task => task.parent_id == parent_id).map(({id}) => id)
//
let call = () => {
const newIds = state.tasks.filter(task => task.parent_id == parent_id && task._time >= time).map(({id}) => id)
const newIds = state.cacheTasks.filter(task => task.parent_id == parent_id && task._time >= time).map(({id}) => id)
dispatch("forgetTask", currentIds.filter(v => newIds.indexOf(v) == -1))
}
dispatch("getTasks", {parent_id}).then(() => {
@ -1428,14 +1422,14 @@ export default {
dispatch("saveDialog", dialog)
});
} else if ($A.isJson(data)) {
let index = state.dialogs.findIndex(({id}) => id == data.id);
let index = state.cacheDialogs.findIndex(({id}) => id == data.id);
if (index > -1) {
state.dialogs.splice(index, 1, Object.assign({}, state.dialogs[index], data));
state.cacheDialogs.splice(index, 1, Object.assign({}, state.cacheDialogs[index], data));
} else {
state.dialogs.push(data);
state.cacheDialogs.push(data);
}
setTimeout(() => {
$A.setStorage("cacheDialogs", state.cacheDialogs = state.dialogs);
$A.setStorage("cacheDialogs", state.cacheDialogs);
})
}
},
@ -1449,7 +1443,7 @@ export default {
updateDialogLastMsg({state, dispatch}, data) {
$A.execMainDispatch("updateDialogLastMsg", data)
//
let dialog = state.dialogs.find(({id}) => id == data.dialog_id);
let dialog = state.cacheDialogs.find(({id}) => id == data.dialog_id);
if (dialog) {
dispatch("saveDialog", {
id: data.dialog_id,
@ -1468,7 +1462,7 @@ export default {
*/
getDialogs({state, dispatch}) {
if (state.userId === 0) {
state.dialogs = [];
state.cacheDialogs = [];
return;
}
dispatch("call", {
@ -1545,11 +1539,11 @@ export default {
moveDialogTop({state}, dialog_id) {
$A.execMainDispatch("moveDialogTop", dialog_id)
//
const index = state.dialogs.findIndex(({id}) => id == dialog_id);
const index = state.cacheDialogs.findIndex(({id}) => id == dialog_id);
if (index > -1) {
const tmp = $A.cloneJSON(state.dialogs[index]);
state.dialogs.splice(index, 1);
state.dialogs.unshift(tmp);
const tmp = $A.cloneJSON(state.cacheDialogs[index]);
state.cacheDialogs.splice(index, 1);
state.cacheDialogs.unshift(tmp);
}
},
@ -1563,9 +1557,9 @@ export default {
//
let ids = $A.isArray(dialog_id) ? dialog_id : [dialog_id];
ids.some(id => {
let index = state.dialogs.findIndex(dialog => dialog.id == id);
let index = state.cacheDialogs.findIndex(dialog => dialog.id == id);
if (index > -1) {
state.dialogs.splice(index, 1);
state.cacheDialogs.splice(index, 1);
}
})
if (ids.includes($A.getStorageInt("messenger::dialogId"))) {
@ -1573,7 +1567,7 @@ export default {
}
//
setTimeout(() => {
$A.setStorage("cacheDialogs", state.cacheDialogs = state.dialogs);
$A.setStorage("cacheDialogs", state.cacheDialogs);
})
},
@ -1611,12 +1605,12 @@ export default {
* @param dialog_id
*/
getDialogMsgs({state, dispatch}, dialog_id) {
let dialog = state.dialogs.find(({id}) => id == dialog_id);
let dialog = state.cacheDialogs.find(({id}) => id == dialog_id);
if (!dialog) {
dialog = {
id: dialog_id,
};
state.dialogs.push(dialog);
state.cacheDialogs.push(dialog);
}
if (dialog.loading) {
return;
@ -1656,7 +1650,7 @@ export default {
*/
getDialogMoreMsgs({state, dispatch}, dialog_id) {
return new Promise(function (resolve, reject) {
const dialog = state.dialogs.find(({id}) => id == dialog_id);
const dialog = state.cacheDialogs.find(({id}) => id == dialog_id);
if (!dialog) {
reject({msg: 'Parameter error'});
return;
@ -1703,7 +1697,7 @@ export default {
if (data.is_read === true) return;
data.is_read = true;
//
let dialog = state.dialogs.find(({id}) => id == data.dialog_id);
let dialog = state.cacheDialogs.find(({id}) => id == data.dialog_id);
if (dialog && dialog.unread > 0) {
dialog.unread--
}
@ -1808,7 +1802,7 @@ export default {
if (mode === "chat") {
return;
}
let dialog = state.dialogs.find(({id}) => id == data.dialog_id);
let dialog = state.cacheDialogs.find(({id}) => id == data.dialog_id);
// 更新对话列表
if (dialog) {
// 新增未读数

View File

@ -11,7 +11,7 @@ export default {
}
if (projectId > 0) {
window.__projectId = projectId;
const project = state.projects.find(({id}) => id == projectId);
const project = state.cacheProjects.find(({id}) => id == projectId);
if (project) {
return project;
}
@ -50,7 +50,7 @@ export default {
}
if (taskId > 0) {
window.__taskId = taskId;
const task = state.tasks.find(({id}) => id == taskId);
const task = state.cacheTasks.find(({id}) => id == taskId);
if (task) {
return task;
}
@ -74,7 +74,7 @@ export default {
}).map(task => {
if (task.parent_id > 0) {
// 子任务
const data = state.tasks.find(({id}) => id == task.parent_id);
const data = state.cacheTasks.find(({id}) => id == task.parent_id);
if (data) {
return Object.assign({}, data, {
id: task.id,
@ -110,7 +110,7 @@ export default {
* @returns {unknown[]}
*/
ownerTasks(state) {
return state.tasks.filter(({complete_at, owner}) => {
return state.cacheTasks.filter(({complete_at, owner}) => {
if (complete_at) {
return false;
}

View File

@ -51,7 +51,6 @@ state.userIsAdmin = $A.inArray("admin", state.userInfo.identity);
state.userOnline = {};
// 会话聊天
state.dialogs = [];
state.dialogMsgs = [];
state.dialogMsgPush = {};
state.dialogOpenId = 0;
@ -62,12 +61,9 @@ state.fileContent = {};
// 项目任务
state.projectId = 0;
state.projects = [];
state.projectTotal = 0;
state.projectLoad = 0;
state.columns = [];
state.taskId = 0;
state.tasks = [];
state.taskContents = [];
state.taskFiles = [];
state.taskLogs = [];