no message

This commit is contained in:
kuaifan 2021-06-10 23:29:40 +08:00
parent 1f832ece2c
commit 4eee5cced6
4 changed files with 65 additions and 71 deletions

View File

@ -269,7 +269,7 @@ export default {
this.addShow = false; this.addShow = false;
this.$refs.addProject.resetFields(); this.$refs.addProject.resetFields();
this.$set(this.addData, 'template', 0); this.$set(this.addData, 'template', 0);
this.$store.commit('storageProjectData', data); this.$store.commit('saveProjectData', data);
this.toggleRoute('project/' + data.id) this.toggleRoute('project/' + data.id)
} else { } else {
$A.modalError(msg); $A.modalError(msg);

View File

@ -963,7 +963,7 @@ export default {
if (ret === 1) { if (ret === 1) {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.settingShow = false; this.settingShow = false;
this.$store.commit("storageProjectData", data) this.$store.commit("saveProjectData", data)
} else { } else {
$A.modalError(msg); $A.modalError(msg);
} }
@ -1036,7 +1036,7 @@ export default {
this.$Modal.remove(); this.$Modal.remove();
if (ret === 1) { if (ret === 1) {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.$store.commit('forgetProjectData', this.projectDetail.id); this.$store.commit('removeProjectData', this.projectDetail.id);
const project = this.projectList.find(({id}) => id); const project = this.projectList.find(({id}) => id);
if (project) { if (project) {
this.goForward({path: '/manage/project/' + project.id}, true); this.goForward({path: '/manage/project/' + project.id}, true);
@ -1071,7 +1071,7 @@ export default {
this.$Modal.remove(); this.$Modal.remove();
if (ret === 1) { if (ret === 1) {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.$store.commit('forgetProjectData', this.projectDetail.id); this.$store.commit('removeProjectData', this.projectDetail.id);
const project = this.projectList.find(({id}) => id); const project = this.projectList.find(({id}) => id);
if (project) { if (project) {
this.goForward({path: '/manage/project/' + project.id}, true); this.goForward({path: '/manage/project/' + project.id}, true);

View File

@ -87,15 +87,14 @@ export default {
state.projectList = []; state.projectList = [];
return; return;
} }
if (state.method.isArray(state.cacheProjectList)) { if (state.cacheProjectList.length > 0) {
state.projectList = state.cacheProjectList; state.projectList = state.cacheProjectList;
} }
$A.apiAjax({ $A.apiAjax({
url: 'project/lists', url: 'project/lists',
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
state.projectList = data.data; this.commit('saveProjectData', data.data);
state.method.setStorage("cacheProjectList", state.projectList);
} else { } else {
$A.modalError(msg); $A.modalError(msg);
} }
@ -119,50 +118,12 @@ export default {
}, },
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
this.commit('storageProjectData', data); this.commit('saveProjectData', data);
} }
} }
}); });
}, },
/**
* 保存项目信息
* @param state
* @param data
*/
storageProjectData(state, data) {
if (data.id == state.projectDetail.id) {
state.projectDetail = Object.assign({}, state.projectDetail, data)
}
//
if (typeof data.project_column !== "undefined") delete data.project_column;
if (typeof data.project_user !== "undefined") delete data.project_user;
let index = state.projectList.findIndex(({id}) => id == data.id);
if (index > -1) {
state.projectList.splice(index, 1, Object.assign({}, state.projectList[index], data));
} else {
state.projectList.unshift(data);
}
state.method.setStorage("cacheProjectList", state.projectList);
},
/**
* 删除项目信息
* @param state
* @param project_id
*/
forgetProjectData(state, project_id) {
let index = state.projectList.findIndex(({id}) => id == project_id);
if (index > -1) {
state.projectList.splice(index, 1);
state.method.setStorage("cacheProjectList", state.projectList);
}
if (typeof state.cacheProjectDetail[project_id] !== "undefined") {
delete state.cacheProjectDetail[project_id];
state.method.setStorage("cacheProjectDetail", state.cacheProjectDetail);
}
},
/** /**
* 获取项目详情 * 获取项目详情
* @param state * @param state
@ -172,16 +133,12 @@ export default {
if (state.method.runNum(project_id) === 0) { if (state.method.runNum(project_id) === 0) {
return; return;
} }
if (state.method.isJson(state.cacheProjectDetail[project_id])) { const project = state.cacheProjectList.find(({id}) => id == project_id);
state.projectDetail = state.cacheProjectDetail[project_id]; if (project) {
state.projectDetail = Object.assign({project_column: [], project_user: []}, project);
} }
state.projectDetail.id = project_id; state.projectDetail.id = project_id;
// //
if (state.cacheProjectDetail[project_id + "::load"]) {
return;
}
state.cacheProjectDetail[project_id + "::load"] = true;
//
state.projectLoad++; state.projectLoad++;
$A.apiAjax({ $A.apiAjax({
url: 'project/detail', url: 'project/detail',
@ -190,13 +147,10 @@ export default {
}, },
complete: () => { complete: () => {
state.projectLoad--; state.projectLoad--;
state.cacheProjectDetail[project_id + "::load"] = false;
}, },
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
state.cacheProjectDetail[data.id] = data; this.commit('saveProjectData', data);
state.method.setStorage("cacheProjectDetail", state.cacheProjectDetail);
this.commit('storageProjectData', $A.cloneJSON(data));
} else { } else {
$A.modalError(msg); $A.modalError(msg);
} }
@ -204,6 +158,47 @@ export default {
}); });
}, },
/**
* 保存项目信息
* @param state
* @param data
*/
saveProjectData(state, data) {
if (state.method.isArray(data)) {
if (state.projectDetail.id) {
const project = data.find(({id}) => id == state.projectDetail.id);
if (project) {
state.projectDetail = Object.assign({}, state.projectDetail, project)
}
}
state.projectList = data;
} else if (state.method.isJson(data)) {
if (data.id == state.projectDetail.id) {
state.projectDetail = Object.assign({}, state.projectDetail, data)
}
let index = state.projectList.findIndex(({id}) => id == data.id);
if (index > -1) {
state.projectList.splice(index, 1, Object.assign({}, state.projectList[index], data));
} else {
state.projectList.unshift(data);
}
}
state.method.setStorage("cacheProjectList", state.projectList);
},
/**
* 删除项目信息
* @param state
* @param project_id
*/
removeProjectData(state, project_id) {
let index = state.projectList.findIndex(({id}) => id == project_id);
if (index > -1) {
state.projectList.splice(index, 1);
state.method.setStorage("cacheProjectList", state.projectList);
}
},
/** /**
* 获取用户基本信息 * 获取用户基本信息
* @param state * @param state
@ -363,20 +358,20 @@ export default {
} }
// //
state.dialogMsgList = []; state.dialogMsgList = [];
if (state.method.isJson(state.cacheDialogMsg[dialog_id])) { if (state.method.isJson(state.cacheDialogList[dialog_id])) {
let length = state.cacheDialogMsg[dialog_id].data.length; let length = state.cacheDialogList[dialog_id].data.length;
if (length > 50) { if (length > 50) {
state.cacheDialogMsg[dialog_id].data.splice(0, length - 50); state.cacheDialogList[dialog_id].data.splice(0, length - 50);
} }
state.dialogDetail = state.cacheDialogMsg[dialog_id].dialog state.dialogDetail = state.cacheDialogList[dialog_id].dialog
state.dialogMsgList = state.cacheDialogMsg[dialog_id].data state.dialogMsgList = state.cacheDialogList[dialog_id].data
} }
state.dialogId = dialog_id; state.dialogId = dialog_id;
// //
if (state.cacheDialogMsg[dialog_id + "::load"]) { if (state.cacheDialogList[dialog_id + "::load"]) {
return; return;
} }
state.cacheDialogMsg[dialog_id + "::load"] = true; state.cacheDialogList[dialog_id + "::load"] = true;
// //
state.dialogMsgLoad++; state.dialogMsgLoad++;
$A.apiAjax({ $A.apiAjax({
@ -386,18 +381,18 @@ export default {
}, },
complete: () => { complete: () => {
state.dialogMsgLoad--; state.dialogMsgLoad--;
state.cacheDialogMsg[dialog_id + "::load"] = false; state.cacheDialogList[dialog_id + "::load"] = false;
}, },
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
const dialog = data.dialog; const dialog = data.dialog;
const reverse = data.data.reverse(); const reverse = data.data.reverse();
// 更新缓存 // 更新缓存
state.cacheDialogMsg[dialog_id] = { state.cacheDialogList[dialog_id] = {
dialog, dialog,
data: reverse, data: reverse,
}; };
state.method.setStorage("cacheDialogMsg", state.cacheDialogMsg); state.method.setStorage("cacheDialogList", state.cacheDialogList);
// 更新当前会话消息 // 更新当前会话消息
if (state.dialogId == dialog_id) { if (state.dialogId == dialog_id) {
state.dialogDetail = dialog; state.dialogDetail = dialog;

View File

@ -23,7 +23,7 @@ const method = {
return typeof value === "boolean" ? value : def; return typeof value === "boolean" ? value : def;
}, },
getStorageArray(key, def = {}) { getStorageArray(key, def = []) {
let value = this.storage(key); let value = this.storage(key);
return this.isArray(value) ? value : def; return this.isArray(value) ? value : def;
}, },
@ -161,9 +161,8 @@ const state = { method };
// 数据缓存 // 数据缓存
state.cacheUserBasic = state.method.getStorageJson("cacheUserBasic"); state.cacheUserBasic = state.method.getStorageJson("cacheUserBasic");
state.cacheDialogMsg = state.method.getStorageJson("cacheDialogMsg"); state.cacheDialogList = state.method.getStorageJson("cacheDialogList");
state.cacheProjectList = state.method.getStorageArray("cacheProjectList"); state.cacheProjectList = state.method.getStorageArray("cacheProjectList");
state.cacheProjectDetail = state.method.getStorageJson("cacheProjectDetail");
// 会员信息 // 会员信息
state.userInfo = state.method.getStorageJson('userInfo'); state.userInfo = state.method.getStorageJson('userInfo');
@ -184,7 +183,7 @@ state.wsReadWaitList = [];
// 项目信息 // 项目信息
state.projectLoad = 0; state.projectLoad = 0;
state.projectList = state.cacheProjectList; state.projectList = state.cacheProjectList;
state.projectDetail = {id: 0, dialog_id: 0, project_column: [], project_user: []}; state.projectDetail = {id: 0, project_column: [], project_user: []};
// 会话消息 // 会话消息
state.dialogId = 0; state.dialogId = 0;