去除apiAjax方法,使用vuex

This commit is contained in:
kuaifan 2021-06-11 11:24:10 +08:00
parent d94dc5ebea
commit 416ff1791f
22 changed files with 599 additions and 729 deletions

View File

@ -105,7 +105,7 @@
}, },
data () { data () {
return { return {
actionUrl: $A.apiUrl('system/imgupload'), actionUrl: this.$store.state.method.apiUrl('system/imgupload'),
params: { params: {
token: this.$store.state.userToken, token: this.$store.state.userToken,
width: this.width, width: this.width,
@ -287,22 +287,20 @@
this.browseList = []; this.browseList = [];
this.browseListNext = []; this.browseListNext = [];
this.isLoading = true; this.isLoading = true;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'system/imgview', url: 'system/imgview',
data: {path: path ? path : ''}, data: {path: path ? path : ''},
success: (res) => { }).then((data, msg) => {
this.isLoading = false; this.isLoading = false;
if (res.ret === 1) { let dirs = data['dirs'];
let dirs = res.data['dirs']; for (let i = 0; i < dirs.length; i++) {
for (let i = 0; i < dirs.length; i++) { this.browseList.push(dirs[i]);
this.browseList.push(dirs[i]);
}
this.browsePictureFor(res.data['files']);
}else if (res.ret === -2) {
this.browseVisible = false;
$A.noticeWarning(res.msg);
}
} }
this.browsePictureFor(data['files']);
}).catch((data, msg) => {
this.isLoading = false;
this.browseVisible = false;
$A.noticeWarning(msg);
}); });
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="common-spinner"> <div id="common-spinner" class="common-spinner">
<Loading class="common-circular"></Loading> <Loading class="common-circular"></Loading>
</div> </div>
</template> </template>

View File

@ -123,7 +123,7 @@
uploadIng: 0, uploadIng: 0,
uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz'], uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz'],
actionUrl: $A.apiUrl('system/fileupload'), actionUrl: this.$store.state.method.apiUrl('system/fileupload'),
params: { token: this.$store.state.userToken }, params: { token: this.$store.state.userToken },
maxSize: 10240 maxSize: 10240
}; };

View File

@ -142,7 +142,7 @@
searchUser(query) { searchUser(query) {
if (query !== '') { if (query !== '') {
this.loading = true; this.loading = true;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'users/search', url: 'users/search',
data: { data: {
keys: { keys: {
@ -150,17 +150,13 @@
}, },
take: 30 take: 30
}, },
complete: () => { }).then((data, msg) => {
this.loading = false; this.loading = false;
}, this.lists = data;
success: ({ret, data, msg}) => { }).catch((data, msg) => {
if (ret === 1) { this.loading = false;
this.lists = data; this.lists = [];
} else { $A.messageWarning(msg);
this.lists = [];
$A.messageWarning(msg);
}
}
}); });
} else { } else {
this.lists = []; this.lists = [];

View File

@ -2,163 +2,7 @@
* 页面专用 * 页面专用
*/ */
(function (window) { (function (window) {
const $ = window.$A;
let apiUrl = window.location.origin + '/api/';
let $ = window.$A;
$.extend({
fillUrl(str) {
if (str.substring(0, 2) === "//" ||
str.substring(0, 7) === "http://" ||
str.substring(0, 8) === "https://" ||
str.substring(0, 6) === "ftp://" ||
str.substring(0, 1) === "/") {
return str;
}
return window.location.origin + '/' + str;
},
apiUrl(str) {
if (str.substring(0, 2) === "//" ||
str.substring(0, 7) === "http://" ||
str.substring(0, 8) === "https://" ||
str.substring(0, 6) === "ftp://" ||
str.substring(0, 1) === "/") {
return str;
}
return apiUrl + str;
},
/**
* @param params {url,data,method,timeout,header,spinner,websocket,timeout, before,complete,success,error,after}
* @returns {boolean}
*/
apiAjax(params) {
if (!$A.isJson(params)) return false;
if (typeof params.success === 'undefined') params.success = () => { };
if (typeof params.header === 'undefined') params.header = {};
params.url = this.apiUrl(params.url);
params.data = this.date2string(params.data);
params.header['Content-Type'] = 'application/json';
params.header['language'] = $A.getLanguage();
params.header['token'] = $A.store.state.userToken;
params.header['fd'] = $A.store.state.method.getStorageString("userWsFd");
//
if (params.spinner === true) {
let beforeCall = params.before;
params.before = () => {
$A.aAjaxLoadNum++;
$A(".common-spinner").show();
typeof beforeCall == "function" && beforeCall();
};
//
let completeCall = params.complete;
params.complete = () => {
$A.aAjaxLoadNum--;
if ($A.aAjaxLoadNum <= 0) {
$A(".common-spinner").hide();
}
typeof completeCall == "function" && completeCall();
};
}
//
let callback = params.success;
params.success = (data, status, xhr) => {
if (typeof data === 'object') {
if (data.ret === -1 && params.checkRole !== false) {
//身份丢失
$A.modalError({
content: data.msg,
onOk: () => {
$A.logout();
}
});
return;
}
if (data.ret === -2 && params.role !== false) {
//没有权限
$A.modalError({
content: data.msg || "你没有相关的权限查看或编辑!"
});
}
}
if (typeof callback === "function") {
callback(data, status, xhr);
}
};
//
if (params.websocket === true || params.ws === true) {
const apiWebsocket = $A.randomString(16);
const apiTimeout = setTimeout(() => {
const WListener = $A.aAjaxWsListener.find((item) => item.apiWebsocket == apiWebsocket);
$A.aAjaxWsListener = $A.aAjaxWsListener.filter((item) => item.apiWebsocket != apiWebsocket);
if (WListener) {
WListener.complete();
WListener.error("timeout");
WListener.after();
}
}, params.timeout || 30000);
$A.aAjaxWsListener.push({
apiWebsocket: apiWebsocket,
complete: typeof params.complete === "function" ? params.complete : () => { },
after: typeof params.after === "function" ? params.after : () => { },
success: typeof params.success === "function" ? params.success : () => { },
error: typeof params.error === "function" ? params.error : () => { },
});
//
params.complete = () => { };
params.success = () => { };
params.error = () => { };
params.after = () => { };
params.header['Api-Websocket'] = apiWebsocket;
//
if ($A.aAjaxWsReady === false) {
$A.aAjaxWsReady = true;
$A.store.commit("wsMsgListener", {
name: "apiWebsocket",
callback: (msg) => {
switch (msg.type) {
case 'apiWebsocket':
clearTimeout(apiTimeout);
const apiWebsocket = msg.apiWebsocket;
const apiSuccess = msg.apiSuccess;
const apiResult = msg.data;
const WListener = $A.aAjaxWsListener.find((item) => item.apiWebsocket == apiWebsocket);
$A.aAjaxWsListener = $A.aAjaxWsListener.filter((item) => item.apiWebsocket != apiWebsocket);
if (WListener) {
WListener.complete();
if (apiSuccess) {
WListener.success(apiResult);
} else {
WListener.error(apiResult);
}
WListener.after();
}
break;
}
}
});
}
}
//
$A.ajaxc(params);
return true;
},
aAjaxLoadNum: 0,
aAjaxWsReady: false,
aAjaxWsListener: [],
/**
* 登出打开登录页面
*/
logout() {
const from = window.location.pathname == '/' ? '' : encodeURIComponent(window.location.href);
$A.store.commit('setUserInfo', {});
$A.goForward({path: '/login', query: from ? {from: from} : {}}, true);
},
});
/** /**
* ============================================================================= * =============================================================================
* ***************************** iviewui assist **************************** * ***************************** iviewui assist ****************************

View File

@ -28,7 +28,7 @@ export default {
loadIng: 0, loadIng: 0,
codeNeed: false, codeNeed: false,
codeUrl: $A.apiUrl('users/login/codeimg'), codeUrl: this.$store.state.method.apiUrl('users/login/codeimg'),
loginType: 'login', loginType: 'login',
email: '', email: '',
@ -38,7 +38,7 @@ export default {
}, },
methods: { methods: {
reCode() { reCode() {
this.codeUrl = $A.apiUrl('users/login/codeimg?_=' + Math.random()) this.codeUrl = this.$store.state.method.apiUrl('users/login/codeimg?_=' + Math.random())
}, },
onBlur() { onBlur() {
@ -47,19 +47,19 @@ export default {
return; return;
} }
this.loadIng++; this.loadIng++;
$A.ajaxc({ this.$store.dispatch("call", {
url: $A.apiUrl('users/login/needcode'), url: 'users/login/needcode',
data: { data: {
email: this.email, email: this.email,
}, },
complete: () => { }).then((data, msg) => {
this.loadIng--; this.loadIng--;
}, this.reCode();
success: ({ret}) => { this.codeNeed = true;
this.reCode(); }).catch((data, msg) => {
this.codeNeed = ret === 1; this.loadIng--;
} this.codeNeed = false;
}) });
}, },
onLogin() { onLogin() {
@ -70,31 +70,26 @@ export default {
return; return;
} }
this.loadIng++; this.loadIng++;
$A.ajaxc({ this.$store.dispatch("call", {
url: $A.apiUrl('users/login'), url: 'users/login',
data: { data: {
type: this.loginType, type: this.loginType,
email: this.email, email: this.email,
password: this.password, password: this.password,
code: this.code, code: this.code,
}, },
complete: () => { }).then((data, msg) => {
this.loadIng--; this.loadIng--;
}, this.$store.commit('setUserInfo', data);
success: ({ret, data, msg}) => { this.goNext();
if (ret === 1) { }).catch((data, msg) => {
this.$store.commit('setUserInfo', data); this.loadIng--;
// $A.noticeError(msg);
this.goNext(); if (data.code === 'need') {
} else { this.reCode();
$A.noticeError(msg); this.codeNeed = true;
if (data.code === 'need') {
this.reCode();
this.codeNeed = true;
}
}
} }
}) });
}, },
goNext() { goNext() {

View File

@ -208,7 +208,7 @@ export default {
title: '退出登录', title: '退出登录',
content: '你确定要登出系统?', content: '你确定要登出系统?',
onOk: () => { onOk: () => {
$A.logout() this.$store.commit("logout")
} }
}); });
return; return;
@ -266,24 +266,20 @@ export default {
this.$refs.addProject.validate((valid) => { this.$refs.addProject.validate((valid) => {
if (valid) { if (valid) {
this.loadIng++; this.loadIng++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/add', url: 'project/add',
data: this.addData, data: this.addData,
complete: () => { }).then((data, msg) => {
this.loadIng--; this.loadIng--;
}, $A.messageSuccess(msg);
success: ({ret, data, msg}) => { this.addShow = false;
if (ret === 1) { this.$refs.addProject.resetFields();
$A.messageSuccess(msg); this.$set(this.addData, 'template', 0);
this.addShow = false; this.$store.commit('saveProjectData', data);
this.$refs.addProject.resetFields(); this.toggleRoute('project/' + data.id)
this.$set(this.addData, 'template', 0); }).catch((data, msg) => {
this.$store.commit('saveProjectData', data); this.loadIng--;
this.toggleRoute('project/' + data.id) $A.modalError(msg);
} else {
$A.modalError(msg);
}
}
}); });
} }
}); });

View File

@ -30,7 +30,7 @@ export default {
data() { data() {
return { return {
uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'], uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'],
actionUrl: $A.apiUrl('dialog/msg/sendfile'), actionUrl: this.$store.state.method.apiUrl('dialog/msg/sendfile'),
} }
}, },

View File

@ -100,16 +100,13 @@ export default {
}, },
popperShow() { popperShow() {
$A.apiAjax({ this.$store.dispatch("call", {
url: 'dialog/msg/readlist', url: 'dialog/msg/readlist',
data: { data: {
msg_id: this.msgData.id, msg_id: this.msgData.id,
}, },
success: ({ret, data, msg}) => { }).then((data, msg) => {
if (ret === 1) { this.read_list = data;
this.read_list = data;
}
}
}); });
}, },

View File

@ -117,24 +117,20 @@ export default {
}); });
this.autoBottom = true; this.autoBottom = true;
// //
$A.apiAjax({ this.$store.dispatch("call", {
url: 'dialog/msg/sendtext', url: 'dialog/msg/sendtext',
data: { data: {
dialog_id: this.dialogId, dialog_id: this.dialogId,
text: this.msgText, text: this.msgText,
}, },
error:() => { }).then((data, msg) => {
this.$store.commit('spliceDialogMsg', {id: tempId}); this.$store.commit('spliceDialogMsg', {id: tempId, data});
}, }).catch((data, msg) => {
success: ({ret, data, msg}) => { $A.modalWarning({
if (ret !== 1) { title: '发送失败',
$A.modalWarning({ content: msg
title: '发送失败', });
content: msg this.$store.commit('spliceDialogMsg', {id: tempId});
});
}
this.$store.commit('spliceDialogMsg', {id: tempId, data: ret === 1 ? data : null});
}
}); });
// //
this.msgText = ''; this.msgText = '';

View File

@ -570,59 +570,47 @@ export default {
this.sortData = newSort; this.sortData = newSort;
// //
this.sortDisabled = true; this.sortDisabled = true;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/sort', url: 'project/sort',
data: { data: {
project_id: this.projectDetail.id, project_id: this.projectDetail.id,
sort: this.sortData, sort: this.sortData,
only_column: only_column === true ? 1 : 0 only_column: only_column === true ? 1 : 0
}, },
complete: () => { }).then((data, msg) => {
this.sortDisabled = false; this.sortDisabled = false;
}, $A.messageSuccess(msg);
error: () => { }).catch((data, msg) => {
$A.modalAlert('网络繁忙,请稍后再试!'); this.sortDisabled = false;
this.$store.commit('getProjectDetail', this.projectDetail.id); this.$store.commit('getProjectDetail', this.projectDetail.id);
}, $A.modalError(msg);
success: ({ret, data, msg}) => {
if (ret === 1) {
$A.messageSuccess(msg);
} else {
this.$store.commit('getProjectDetail', this.projectDetail.id);
$A.modalError(msg);
}
}
}); });
}, },
onAddTask() { onAddTask() {
this.taskLoad++; this.taskLoad++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/task/add', url: 'project/task/add',
data: this.addData, data: this.addData,
method: 'post', method: 'post',
complete: () => { }).then((data, msg) => {
this.taskLoad--; this.taskLoad--;
}, $A.messageSuccess(msg);
success: ({ret, data, msg}) => { this.addShow = false;
if (ret === 1) { this.addData = {
$A.messageSuccess(msg); owner: 0,
this.addShow = false; column_id: 0,
this.addData = { times: [],
owner: 0, subtasks: [],
column_id: 0, p_level: 0,
times: [], p_name: '',
subtasks: [], p_color: '',
p_level: 0, };
p_name: '', this.$store.commit('getProjectOne', data.project_id);
p_color: '', this.addTaskSuccess(data)
}; }).catch((data, msg) => {
this.$store.commit('getProjectOne', data.project_id); this.taskLoad--;
this.addTaskSuccess(data) $A.modalError(msg);
} else {
$A.modalError(msg);
}
}
}); });
}, },
@ -675,24 +663,18 @@ export default {
if (name === '') { if (name === '') {
return; return;
} }
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/column/add', url: 'project/column/add',
data: { data: {
project_id: this.projectDetail.id, project_id: this.projectDetail.id,
name: name, name: name,
}, },
error: () => { }).then((data, msg) => {
$A.modalAlert('网络繁忙,请稍后再试!'); $A.messageSuccess(msg);
}, this.addColumnName = '';
success: ({ret, data, msg}) => { this.projectDetail.project_column.push(data)
if (ret === 1) { }).catch((data, msg) => {
$A.messageSuccess(msg); $A.modalError(msg, 301);
this.addColumnName = '';
this.projectDetail.project_column.push(data)
} else {
$A.modalError(msg, 301);
}
}
}); });
}, },
@ -737,31 +719,22 @@ export default {
this.$set(column, key, updata[key]); this.$set(column, key, updata[key]);
}); });
// //
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/column/update', url: 'project/column/update',
data: Object.assign(updata, { data: Object.assign(updata, {
column_id: column.id, column_id: column.id,
}), }),
complete: () => { }).then((data, msg) => {
this.$set(column, 'loading', false); this.$set(column, 'loading', false);
}, Object.keys(data).forEach(key => {
error: () => { this.$set(column, key, data[key]);
Object.keys(updata).forEach(key => { });
this.$set(column, key, backup[key]); }).catch((data, msg) => {
}); this.$set(column, 'loading', false);
}, Object.keys(updata).forEach(key => {
success: ({ret, data, msg}) => { this.$set(column, key, backup[key]);
if (ret === 1) { });
Object.keys(data).forEach(key => { $A.modalError(msg);
this.$set(column, key, data[key]);
});
} else {
Object.keys(updata).forEach(key => {
this.$set(column, key, backup[key]);
});
$A.modalError(msg);
}
}
}); });
}, },
@ -776,31 +749,24 @@ export default {
} }
this.$set(column, 'loading', true); this.$set(column, 'loading', true);
// //
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/column/delete', url: 'project/column/delete',
data: { data: {
column_id: column.id, column_id: column.id,
}, },
complete: () => { }).then((data, msg) => {
this.$set(column, 'loading', false); this.$set(column, 'loading', false);
}, this.$Modal.remove();
error: () => { $A.messageSuccess(msg);
this.$Modal.remove(); let index = this.projectDetail.project_column.findIndex(({id}) => id === column.id);
$A.modalAlert('网络繁忙,请稍后再试!'); if (index > -1) {
}, this.projectDetail.project_column.splice(index, 1);
success: ({ret, data, msg}) => {
this.$Modal.remove();
if (ret === 1) {
$A.messageSuccess(msg);
let index = this.projectDetail.project_column.findIndex(({id}) => id === column.id);
if (index > -1) {
this.projectDetail.project_column.splice(index, 1);
}
this.$store.commit('getProjectDetail', this.projectDetail.id);
}else{
$A.modalError(msg, 301);
}
} }
this.$store.commit('getProjectDetail', this.projectDetail.id);
}).catch((data, msg) => {
this.$set(column, 'loading', false);
this.$Modal.remove();
$A.modalError(msg, 301);
}); });
} }
}); });
@ -856,38 +822,29 @@ export default {
Object.keys(updata).forEach(key => { Object.keys(updata).forEach(key => {
this.$set(task, key, updata[key]); this.$set(task, key, updata[key]);
}); });
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/task/update', url: 'project/task/update',
data: Object.assign(updata, { data: Object.assign(updata, {
task_id: task.id, task_id: task.id,
}), }),
method: 'post', method: 'post',
complete: () => { }).then((data, msg) => {
this.$set(task, 'loading', false); this.$set(task, 'loading', false);
}, Object.keys(data).forEach(key => {
error: () => { this.$set(task, key, data[key]);
Object.keys(updata).forEach(key => { });
this.$set(task, key, backup[key]); if (data.parent_id) {
}); this.getTaskOne(data.parent_id);
},
success: ({ret, data, msg}) => {
if (ret === 1) {
Object.keys(data).forEach(key => {
this.$set(task, key, data[key]);
});
if (data.parent_id) {
this.getTaskOne(data.parent_id);
}
if (typeof updata.complete_at !== "undefined") {
this.$store.commit('getProjectOne', data.project_id);
}
} else {
Object.keys(updata).forEach(key => {
this.$set(task, key, backup[key]);
});
$A.modalError(msg);
}
} }
if (typeof updata.complete_at !== "undefined") {
this.$store.commit('getProjectOne', data.project_id);
}
}).catch((data, msg) => {
this.$set(task, 'loading', false);
Object.keys(updata).forEach(key => {
this.$set(task, key, backup[key]);
});
$A.modalError(msg);
}); });
}, },
@ -899,18 +856,15 @@ export default {
}); });
if (!task) return; if (!task) return;
// //
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/task/one', url: 'project/task/one',
data: { data: {
task_id: task.id task_id: task.id
}, },
success: ({ret, data, msg}) => { }).then((data, msg) => {
if (ret === 1) { Object.keys(data).forEach(key => {
Object.keys(data).forEach(key => { this.$set(task, key, data[key]);
this.$set(task, key, data[key]); });
});
}
}
}); });
}, },
@ -919,100 +873,79 @@ export default {
return; return;
} }
this.$set(task, 'loading', true); this.$set(task, 'loading', true);
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/task/' + type, url: 'project/task/' + type,
data: { data: {
task_id: task.id, task_id: task.id,
}, },
complete: () => { }).then((data, msg) => {
this.$set(task, 'loading', false); this.$Modal.remove();
}, $A.messageSuccess(msg);
error: () => { let column = this.projectDetail.project_column.find(({id}) => id === task.column_id);
this.$Modal.remove(); if (column) {
$A.modalAlert('网络繁忙,请稍后再试!'); let index = column.project_task.findIndex(({id}) => id === task.id);
}, if (index > -1) {
success: ({ret, data, msg}) => { column.project_task.splice(index, 1);
this.$Modal.remove();
if (ret === 1) {
$A.messageSuccess(msg);
let column = this.projectDetail.project_column.find(({id}) => id === task.column_id);
if (column) {
let index = column.project_task.findIndex(({id}) => id === task.id);
if (index > -1) {
column.project_task.splice(index, 1);
}
}
this.$store.commit('getProjectDetail', this.projectDetail.id);
}else{
$A.modalError(msg, 301);
} }
} }
this.$store.commit('getProjectDetail', this.projectDetail.id);
}).catch((data, msg) => {
this.$Modal.remove();
$A.modalError(msg, 301);
}); });
}, },
onSetting() { onSetting() {
this.settingLoad++; this.settingLoad++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/edit', url: 'project/edit',
data: this.settingData, data: this.settingData,
complete: () => { }).then((data, msg) => {
this.settingLoad--; this.settingLoad--;
}, $A.messageSuccess(msg);
success: ({ret, data, msg}) => { this.settingShow = false;
if (ret === 1) { this.$store.commit("saveProjectData", data)
$A.messageSuccess(msg); }).catch((data, msg) => {
this.settingShow = false; this.settingLoad--;
this.$store.commit("saveProjectData", data) $A.modalError(msg);
} else {
$A.modalError(msg);
}
}
}); });
}, },
onUser() { onUser() {
this.userLoad++; this.userLoad++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/user', url: 'project/user',
data: { data: {
project_id: this.userData.project_id, project_id: this.userData.project_id,
userid: this.userData.userids, userid: this.userData.userids,
}, },
complete: () => { }).then((data, msg) => {
this.userLoad--; this.userLoad--;
}, $A.messageSuccess(msg);
success: ({ret, data, msg}) => { this.$store.commit('getProjectDetail', this.userData.project_id);
if (ret === 1) { this.userShow = false;
$A.messageSuccess(msg); }).catch((data, msg) => {
this.$store.commit('getProjectDetail', this.userData.project_id); this.userLoad--;
this.userShow = false; $A.modalError(msg);
} else {
$A.modalError(msg);
}
}
}); });
}, },
onTransfer() { onTransfer() {
this.transferLoad++; this.transferLoad++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/transfer', url: 'project/transfer',
data: { data: {
project_id: this.transferData.project_id, project_id: this.transferData.project_id,
owner_userid: this.transferData.owner_userid[0], owner_userid: this.transferData.owner_userid[0],
}, },
complete: () => { }).then((data, msg) => {
this.transferLoad--; this.transferLoad--;
}, $A.messageSuccess(msg);
success: ({ret, data, msg}) => { this.$store.commit('getProjectDetail', this.transferData.project_id);
if (ret === 1) { this.transferShow = false;
$A.messageSuccess(msg); }).catch((data, msg) => {
this.$store.commit('getProjectDetail', this.transferData.project_id); this.transferLoad--;
this.transferShow = false; $A.modalError(msg);
} else {
$A.modalError(msg);
}
}
}); });
}, },
@ -1022,30 +955,24 @@ export default {
content: '你确定要删除项目【' + this.projectDetail.name + '】吗?', content: '你确定要删除项目【' + this.projectDetail.name + '】吗?',
loading: true, loading: true,
onOk: () => { onOk: () => {
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/delete', url: 'project/delete',
data: { data: {
project_id: this.projectDetail.id, project_id: this.projectDetail.id,
}, },
error: () => { }).then((data, msg) => {
this.$Modal.remove(); this.$Modal.remove();
$A.modalAlert('网络繁忙,请稍后再试!'); $A.messageSuccess(msg);
}, this.$store.commit('removeProjectData', this.projectDetail.id);
success: ({ret, data, msg}) => { const project = this.projectList.find(({id}) => id);
this.$Modal.remove(); if (project) {
if (ret === 1) { this.goForward({path: '/manage/project/' + project.id}, true);
$A.messageSuccess(msg); } else {
this.$store.commit('removeProjectData', this.projectDetail.id); this.goForward({path: '/manage/dashboard'}, true);
const project = this.projectList.find(({id}) => id);
if (project) {
this.goForward({path: '/manage/project/' + project.id}, true);
} else {
this.goForward({path: '/manage/dashboard'}, true);
}
}else{
$A.modalError(msg, 301);
}
} }
}).catch((data, msg) => {
this.$Modal.remove();
$A.modalError(msg, 301);
}); });
} }
}); });
@ -1057,30 +984,24 @@ export default {
content: '你确定要退出项目【' + this.projectDetail.name + '】吗?', content: '你确定要退出项目【' + this.projectDetail.name + '】吗?',
loading: true, loading: true,
onOk: () => { onOk: () => {
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/exit', url: 'project/exit',
data: { data: {
project_id: this.projectDetail.id, project_id: this.projectDetail.id,
}, },
error: () => { }).then((data, msg) => {
this.$Modal.remove(); this.$Modal.remove();
$A.modalAlert('网络繁忙,请稍后再试!'); $A.messageSuccess(msg);
}, this.$store.commit('removeProjectData', this.projectDetail.id);
success: ({ret, data, msg}) => { const project = this.projectList.find(({id}) => id);
this.$Modal.remove(); if (project) {
if (ret === 1) { this.goForward({path: '/manage/project/' + project.id}, true);
$A.messageSuccess(msg); } else {
this.$store.commit('removeProjectData', this.projectDetail.id); this.goForward({path: '/manage/dashboard'}, true);
const project = this.projectList.find(({id}) => id);
if (project) {
this.goForward({path: '/manage/project/' + project.id}, true);
} else {
this.goForward({path: '/manage/dashboard'}, true);
}
}else{
$A.modalError(msg, 301);
}
} }
}).catch((data, msg) => {
this.$Modal.remove();
$A.modalError(msg, 301);
}); });
} }
}); });

View File

@ -151,32 +151,28 @@ export default {
return; return;
} }
this.loadIng++; this.loadIng++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/task/add', url: 'project/task/add',
data: this.getData(), data: this.getData(),
method: 'post', method: 'post',
complete: () => { }).then((data, msg) => {
this.loadIng--; this.loadIng--;
}, $A.messageSuccess(msg);
success: ({ret, data, msg}) => { this.active = false;
if (ret === 1) { this.addData = {
$A.messageSuccess(msg); owner: 0,
this.active = false; column_id: 0,
this.addData = { times: [],
owner: 0, subtasks: [],
column_id: 0, p_level: 0,
times: [], p_name: '',
subtasks: [], p_color: '',
p_level: 0,
p_name: '',
p_color: '',
}
this.$store.commit('getProjectOne', data.project_id);
this.$emit("on-success", data)
} else {
$A.modalError(msg);
}
} }
this.$store.commit('getProjectOne', data.project_id);
this.$emit("on-success", data)
}).catch((data, msg) => {
this.loadIng--;
$A.modalError(msg);
}); });
}, },

View File

@ -158,25 +158,18 @@ export default {
return; return;
} }
this.$set(task, 'loading', true); this.$set(task, 'loading', true);
$A.apiAjax({ this.$store.dispatch("call", {
url: 'project/task/sublist', url: 'project/task/sublist',
data: { data: {
task_id: task.id, task_id: task.id,
}, },
complete: () => { }).then((data, msg) => {
this.$set(task, 'loading', false); this.$set(task, 'loading', false);
}, this.$set(task, 'sub_list', data);
error: () => { this.$set(task, 'sub_open', true);
$A.modalAlert('网络繁忙,请稍后再试!'); }).catch((data, msg) => {
}, this.$set(task, 'loading', false);
success: ({ret, data, msg}) => { $A.modalError(msg);
if (ret === 1) {
this.$set(task, 'sub_list', data);
this.$set(task, 'sub_open', true);
} else {
$A.modalError(msg);
}
}
}); });
}, },

View File

@ -143,32 +143,29 @@ export default {
this.contactsLists = {}; this.contactsLists = {};
} }
this.contactsLoad++; this.contactsLoad++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'users/search', url: 'users/search',
data: { data: {
take: 50 take: 50
}, },
complete: () => { }).then((data, msg) => {
this.contactsLoad--; this.contactsLoad--;
}, data.some((user) => {
success: ({ret, data, msg}) => { if (user.userid === this.userId) {
if (ret === 1) { return false;
data.some((user) => {
if (user.userid === this.userId) {
return false;
}
let az = user.az ? user.az.toUpperCase() : "#";
if (typeof this.contactsLists[az] === "undefined") this.contactsLists[az] = [];
//
let index = this.contactsLists[az].findIndex(({userid}) => userid === user.userid);
if (index > -1) {
this.contactsLists[az].splice(index, 1, user);
} else {
this.contactsLists[az].push(user);
}
});
} }
} let az = user.az ? user.az.toUpperCase() : "#";
if (typeof this.contactsLists[az] === "undefined") this.contactsLists[az] = [];
//
let index = this.contactsLists[az].findIndex(({userid}) => userid === user.userid);
if (index > -1) {
this.contactsLists[az].splice(index, 1, user);
} else {
this.contactsLists[az].push(user);
}
});
}).catch((data, msg) => {
this.contactsLoad--;
}); });
}, },

View File

@ -79,21 +79,17 @@ export default {
this.$refs.formDatum.validate((valid) => { this.$refs.formDatum.validate((valid) => {
if (valid) { if (valid) {
this.loadIng++; this.loadIng++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'users/editpass', url: 'users/editpass',
data: this.formDatum, data: this.formDatum,
complete: () => { }).then((data, msg) => {
this.loadIng--; this.loadIng--;
}, $A.messageSuccess('修改成功');
success: ({ret, data, msg}) => { this.$store.commit('setUserInfo', data);
if (ret === 1) { this.$refs.formDatum.resetFields();
$A.messageSuccess('修改成功!'); }).catch((data, msg) => {
this.$store.commit('setUserInfo', data); this.loadIng--;
this.$refs.formDatum.resetFields(); $A.modalError(msg);
} else {
$A.modalError(msg);
}
}
}); });
} }
}) })

View File

@ -72,20 +72,16 @@ export default {
this.$refs.formDatum.validate((valid) => { this.$refs.formDatum.validate((valid) => {
if (valid) { if (valid) {
this.loadIng++; this.loadIng++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'users/editdata', url: 'users/editdata',
data: this.formDatum, data: this.formDatum,
complete: () => { }).then((data, msg) => {
this.loadIng--; this.loadIng--;
}, $A.messageSuccess('修改成功');
success: ({ret, data, msg}) => { this.$store.commit('getUserInfo');
if (ret === 1) { }).catch((data, msg) => {
$A.messageSuccess('修改成功'); this.loadIng--;
this.$store.commit('getUserInfo'); $A.modalError(msg);
} else {
$A.modalError(msg);
}
}
}); });
} }
}) })

View File

@ -90,31 +90,27 @@ export default {
systemSetting(save) { systemSetting(save) {
this.loadIng++; this.loadIng++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'system/priority?type=' + (save ? 'save' : 'get'), url: 'system/priority?type=' + (save ? 'save' : 'get'),
method: 'post', method: 'post',
data: { data: {
list: this.formDatum list: this.formDatum
}, },
complete: () => { }).then((data, msg) => {
this.loadIng--; this.loadIng--;
}, this.$store.state.taskPriority = $A.cloneJSON(data);
success: ({ret, data, msg}) => { this.formDatum = data;
if (ret === 1) { if (this.formDatum.length === 0) {
this.$store.state.taskPriority = $A.cloneJSON(data); this.addDatum();
this.formDatum = data; }
if (this.formDatum.length === 0) { this.formDatum_bak = $A.cloneJSON(this.formDatum);
this.addDatum(); if (save) {
} $A.messageSuccess('修改成功');
this.formDatum_bak = $A.cloneJSON(this.formDatum); }
if (save) { }).catch((data, msg) => {
$A.messageSuccess('修改成功'); this.loadIng--;
} if (save) {
} else { $A.modalError(msg);
if (save) {
$A.modalError(msg);
}
}
} }
}); });
} }

View File

@ -51,24 +51,20 @@ export default {
systemSetting(save) { systemSetting(save) {
this.loadIng++; this.loadIng++;
$A.apiAjax({ this.$store.dispatch("call", {
url: 'system/setting?type=' + (save ? 'save' : 'get'), url: 'system/setting?type=' + (save ? 'save' : 'get'),
data: this.formDatum, data: this.formDatum,
complete: () => { }).then((data, msg) => {
this.loadIng--; this.loadIng--;
}, this.formDatum = data;
success: ({ret, data, msg}) => { this.formDatum_bak = $A.cloneJSON(this.formDatum);
if (ret === 1) { if (save) {
this.formDatum = data; $A.messageSuccess('修改成功');
this.formDatum_bak = $A.cloneJSON(this.formDatum); }
if (save) { }).catch((data, msg) => {
$A.messageSuccess('修改成功'); this.loadIng--;
} if (save) {
} else { $A.modalError(msg);
if (save) {
$A.modalError(msg);
}
}
} }
}); });
} }

View File

@ -1,3 +1,122 @@
export default { export default {
/**
* @param context
* @param params // {url,data,method,timeout,header,spinner,websocket, before,complete,success,error,after}
* @returns {Promise<unknown>}
*/
call(context, params) {
const {state, commit} = context;
if (!state.method.isJson(params)) params = {url: params}
if (!state.method.isJson(params.header)) params.header = {}
params.url = state.method.apiUrl(params.url);
params.data = state.method.date2string(params.data);
params.header['Content-Type'] = 'application/json';
params.header['language'] = $A.getLanguage();
params.header['token'] = state.userToken;
params.header['fd'] = state.method.getStorageString("userWsFd");
//
return new Promise(function (resolve, reject) {
if (params.spinner === true) {
const spinner = document.getElementById("common-spinner");
if (spinner) {
const beforeCall = params.before;
params.before = () => {
state.ajaxLoadNum++;
spinner.style.display = "block"
typeof beforeCall == "function" && beforeCall();
};
//
const completeCall = params.complete;
params.complete = () => {
state.ajaxLoadNum--;
if (state.ajaxLoadNum <= 0) {
spinner.style.display = "none"
}
typeof completeCall == "function" && completeCall();
};
}
}
//
params.success = (result, status, xhr) => {
if (!state.method.isJson(result)) {
resolve(result, status, xhr);
return;
}
const {ret, data, msg} = result;
if (ret === -1 && params.checkRole !== false) {
//身份丢失
$A.modalError({
content: msg,
onOk: () => {
commit("logout")
}
});
return;
}
if (ret === 1) {
resolve(data, msg);
} else {
reject(data, msg || "Unknown error")
}
};
params.error = () => {
reject({}, "System error")
};
//
if (params.websocket === true || params.ws === true) {
const apiWebsocket = state.method.randomString(16);
const apiTimeout = setTimeout(() => {
const WListener = state.ajaxWsListener.find((item) => item.apiWebsocket == apiWebsocket);
if (WListener) {
WListener.complete();
WListener.error("timeout");
WListener.after();
}
state.ajaxWsListener = state.ajaxWsListener.filter((item) => item.apiWebsocket != apiWebsocket);
}, params.timeout || 30000);
state.ajaxWsListener.push({
apiWebsocket: apiWebsocket,
complete: typeof params.complete === "function" ? params.complete : () => { },
success: typeof params.success === "function" ? params.success : () => { },
error: typeof params.error === "function" ? params.error : () => { },
after: typeof params.after === "function" ? params.after : () => { },
});
//
params.complete = () => { };
params.success = () => { };
params.error = () => { };
params.after = () => { };
params.header['Api-Websocket'] = apiWebsocket;
//
if (state.ajaxWsReady === false) {
state.ajaxWsReady = true;
commit("wsMsgListener", {
name: "apiWebsocket",
callback: (msg) => {
switch (msg.type) {
case 'apiWebsocket':
clearTimeout(apiTimeout);
const apiWebsocket = msg.apiWebsocket;
const apiSuccess = msg.apiSuccess;
const apiResult = msg.data;
const WListener = state.ajaxWsListener.find((item) => item.apiWebsocket == apiWebsocket);
if (WListener) {
WListener.complete();
if (apiSuccess) {
WListener.success(apiResult);
} else {
WListener.error(apiResult);
}
WListener.after();
}
state.ajaxWsListener = state.ajaxWsListener.filter((item) => item.apiWebsocket != apiWebsocket);
break;
}
}
});
}
}
$A.ajaxc(params);
})
}
} }

View File

@ -15,14 +15,11 @@ export default {
* @param callback * @param callback
*/ */
getTaskPriority(state, callback) { getTaskPriority(state, callback) {
$A.apiAjax({ this.dispatch("call", {
url: 'system/priority', url: 'system/priority',
success: ({ret, data, msg}) => { }).then((data, msg) => {
if (ret === 1) { state.taskPriority = data;
state.taskPriority = data; typeof callback === "function" && callback(data);
typeof callback === "function" && callback(data);
}
},
}); });
}, },
@ -32,19 +29,14 @@ export default {
* @param callback * @param callback
*/ */
getUserInfo(state, callback) { getUserInfo(state, callback) {
$A.apiAjax({ this.dispatch("call", {
url: 'users/info', url: 'users/info',
error: () => { }).then((data, msg) => {
$A.logout(); this.commit('setUserInfo', data);
}, typeof callback === "function" && callback(data);
success: ({ret, data, msg}) => { }).catch((data, msg) => {
if (ret === 1) { this.commit("logout");
this.commit('setUserInfo', data);
typeof callback === "function" && callback(data);
}
},
}); });
return state.userInfo;
}, },
/** /**
@ -90,15 +82,12 @@ export default {
if (state.cacheProjectList.length > 0) { if (state.cacheProjectList.length > 0) {
state.projectList = state.cacheProjectList; state.projectList = state.cacheProjectList;
} }
$A.apiAjax({ this.dispatch("call", {
url: 'project/lists', url: 'project/lists',
success: ({ret, data, msg}) => { }).then((data, msg) => {
if (ret === 1) { this.commit('saveProjectData', data.data);
this.commit('saveProjectData', data.data); }).catch((data, msg) => {
} else { $A.modalError(msg);
$A.modalError(msg);
}
}
}); });
}, },
@ -111,16 +100,13 @@ export default {
if (state.method.runNum(project_id) === 0) { if (state.method.runNum(project_id) === 0) {
return; return;
} }
$A.apiAjax({ this.dispatch("call", {
url: 'project/one', url: 'project/one',
data: { data: {
project_id: project_id, project_id: project_id,
}, },
success: ({ret, data, msg}) => { }).then((data, msg) => {
if (ret === 1) { this.commit('saveProjectData', data);
this.commit('saveProjectData', data);
}
}
}); });
}, },
@ -140,21 +126,17 @@ export default {
state.projectDetail.id = project_id; state.projectDetail.id = project_id;
// //
state.projectLoad++; state.projectLoad++;
$A.apiAjax({ this.dispatch("call", {
url: 'project/detail', url: 'project/detail',
data: { data: {
project_id: project_id, project_id: project_id,
}, },
complete: () => { }).then((data, msg) => {
state.projectLoad--; state.projectLoad--;
}, this.commit('saveProjectData', data);
success: ({ret, data, msg}) => { }).catch((data, msg) => {
if (ret === 1) { state.projectLoad--;
this.commit('saveProjectData', data); $A.modalError(msg);
} else {
$A.modalError(msg);
}
}
}); });
}, },
@ -245,30 +227,27 @@ export default {
return; return;
} }
state.cacheUserBasic["::load"] = true; state.cacheUserBasic["::load"] = true;
$A.apiAjax({ this.dispatch("call", {
url: 'users/basic', url: 'users/basic',
data: { data: {
userid: array userid: array
}, },
complete: () => { }).then((data, msg) => {
state.cacheUserBasic["::load"] = false; state.cacheUserBasic["::load"] = false;
typeof complete === "function" && complete() typeof complete === "function" && complete()
}, data.forEach((item) => {
success: ({ret, data, msg}) => { state.cacheUserBasic[item.userid] = {
if (ret === 1) { time,
data.forEach((item) => { data: item
state.cacheUserBasic[item.userid] = { };
time, state.method.setStorage("cacheUserBasic", state.cacheUserBasic);
data: item this.commit('setUserOnlineStatus', item);
}; typeof success === "function" && success(item, true)
state.method.setStorage("cacheUserBasic", state.cacheUserBasic); });
this.commit('setUserOnlineStatus', item); }).catch((data, msg) => {
typeof success === "function" && success(item, true) state.cacheUserBasic["::load"] = false;
}); typeof complete === "function" && complete()
} else { $A.modalError(msg);
$A.modalError(msg);
}
}
}); });
}, },
@ -278,16 +257,13 @@ export default {
* @param afterCallback * @param afterCallback
*/ */
getDialogList(state, afterCallback) { getDialogList(state, afterCallback) {
$A.apiAjax({ this.dispatch("call", {
url: 'dialog/lists', url: 'dialog/lists',
after: () => { }).then((data, msg) => {
typeof afterCallback === "function" && afterCallback(); state.dialogList = data.data;
}, typeof afterCallback === "function" && afterCallback();
success: ({ret, data, msg}) => { }).catch((data, msg) => {
if (ret === 1) { typeof afterCallback === "function" && afterCallback();
state.dialogList = data.data;
}
}
}); });
}, },
@ -314,16 +290,13 @@ export default {
* @param dialog_id * @param dialog_id
*/ */
getDialogOne(state, dialog_id) { getDialogOne(state, dialog_id) {
$A.apiAjax({ this.dispatch("call", {
url: 'dialog/one', url: 'dialog/one',
data: { data: {
dialog_id, dialog_id,
}, },
success: ({ret, data, msg}) => { }).then((data, msg) => {
if (ret === 1) { this.commit('getDialogUpdate', data);
this.commit('getDialogUpdate', data);
}
}
}); });
}, },
@ -336,20 +309,17 @@ export default {
if (userid === state.userId) { if (userid === state.userId) {
return; return;
} }
$A.apiAjax({ this.dispatch("call", {
url: 'dialog/open/user', url: 'dialog/open/user',
data: { data: {
userid, userid,
}, },
success: ({ret, data, msg}) => { }).then((data, msg) => {
if (ret === 1) { state.method.setStorage('messengerDialogId', data.id)
state.method.setStorage('messengerDialogId', data.id) this.commit('getDialogMsgList', data.id);
this.commit('getDialogMsgList', data.id); this.commit('getDialogUpdate', data);
this.commit('getDialogUpdate', data); }).catch((data, msg) => {
} else { $A.modalError(msg);
$A.modalError(msg);
}
}
}); });
}, },
@ -383,41 +353,39 @@ export default {
state.cacheDialogList[dialog_id + "::load"] = true; state.cacheDialogList[dialog_id + "::load"] = true;
// //
state.dialogMsgLoad++; state.dialogMsgLoad++;
$A.apiAjax({ this.dispatch("call", {
url: 'dialog/msg/lists', url: 'dialog/msg/lists',
data: { data: {
dialog_id: dialog_id, dialog_id: dialog_id,
}, },
complete: () => { }).then((data, msg) => {
state.dialogMsgLoad--; state.dialogMsgLoad--;
state.cacheDialogList[dialog_id + "::load"] = false; state.cacheDialogList[dialog_id + "::load"] = false;
}, const dialog = data.dialog;
success: ({ret, data, msg}) => { const reverse = data.data.reverse();
if (ret === 1) { // 更新缓存
const dialog = data.dialog; state.cacheDialogList[dialog_id] = {
const reverse = data.data.reverse(); dialog,
// 更新缓存 data: reverse,
state.cacheDialogList[dialog_id] = { };
dialog, state.method.setStorage("cacheDialogList", state.cacheDialogList);
data: reverse, // 更新当前会话消息
}; if (state.dialogId == dialog_id) {
state.method.setStorage("cacheDialogList", state.cacheDialogList); state.dialogDetail = dialog;
// 更新当前会话消息 reverse.forEach((item) => {
if (state.dialogId == dialog_id) { let index = state.dialogMsgList.findIndex(({id}) => id == item.id);
state.dialogDetail = dialog; if (index === -1) {
reverse.forEach((item) => { state.dialogMsgList.push(item);
let index = state.dialogMsgList.findIndex(({id}) => id == item.id); } else {
if (index === -1) { state.dialogMsgList.splice(index, 1, item);
state.dialogMsgList.push(item);
} else {
state.dialogMsgList.splice(index, 1, item);
}
})
} }
// 更新会话数据 })
this.commit('getDialogUpdate', dialog);
}
} }
// 更新会话数据
this.commit('getDialogUpdate', dialog);
}).catch((data, msg) => {
state.dialogMsgLoad--;
state.cacheDialogList[dialog_id + "::load"] = false;
}); });
}, },
@ -427,18 +395,15 @@ export default {
*/ */
getDialogMsgUnread(state) { getDialogMsgUnread(state) {
const unread = state.dialogMsgUnread; const unread = state.dialogMsgUnread;
$A.apiAjax({ this.dispatch("call", {
url: 'dialog/msg/unread', url: 'dialog/msg/unread',
success: ({ret, data, msg}) => { }).then((data, msg) => {
if (ret === 1) { if (unread == state.dialogMsgUnread) {
if (unread == state.dialogMsgUnread) { state.dialogMsgUnread = data.unread;
state.dialogMsgUnread = data.unread; } else {
} else { setTimeout(() => {
setTimeout(() => { this.commit('getDialogMsgUnread');
this.commit('getDialogMsgUnread'); }, 200);
}, 200);
}
}
} }
}); });
}, },
@ -635,7 +600,7 @@ export default {
// //
const {id, dialog_id, r} = msgData; const {id, dialog_id, r} = msgData;
if (!r.read_at) { if (!r.read_at) {
r.read_at = $A.formatDate('Y-m-d H:i:s'); r.read_at = state.method.formatDate('Y-m-d H:i:s');
let dialog = state.dialogList.find(({id}) => id == dialog_id); let dialog = state.dialogList.find(({id}) => id == dialog_id);
if (dialog && dialog.unread > 0) { if (dialog && dialog.unread > 0) {
dialog.unread-- dialog.unread--
@ -649,7 +614,7 @@ export default {
this.commit('wsSend', { this.commit('wsSend', {
type: 'readMsg', type: 'readMsg',
data: { data: {
id: $A.cloneJSON(state.wsReadWaitList) id: state.method.cloneJSON(state.wsReadWaitList)
} }
}); });
state.wsReadWaitList = []; state.wsReadWaitList = [];
@ -677,4 +642,13 @@ export default {
wsClose(state) { wsClose(state) {
state.ws && state.ws.close(); state.ws && state.ws.close();
}, },
/**
* 登出打开登录页面
*/
logout() {
const from = window.location.pathname == '/' ? '' : encodeURIComponent(window.location.href);
this.commit('setUserInfo', {});
$A.goForward({path: '/login', query: from ? {from: from} : {}}, true);
}
} }

View File

@ -1,4 +1,63 @@
const method = { const method = {
apiUrl(str) {
if (str.substring(0, 2) === "//" ||
str.substring(0, 7) === "http://" ||
str.substring(0, 8) === "https://" ||
str.substring(0, 6) === "ftp://" ||
str.substring(0, 1) === "/") {
return str;
}
return window.location.origin + '/api/' + str;
},
date2string(params, format) {
if (params === null) {
return params;
}
if (typeof format === "undefined") {
format = "Y-m-d H:i:s";
}
if (params instanceof Date) {
params = this.formatDate(format, params);
} else if (this.isJson(params)) {
for (let key in params) {
if (!params.hasOwnProperty(key)) continue;
params[key] = this.date2string(params[key], format);
}
} else if (this.isArray(params)) {
params.forEach((val, index) => {
params[index] = this.date2string(val, format);
});
}
return params;
},
formatDate: function(format, v) {
if (typeof format === 'undefined' || format === '') {
format = 'Y-m-d H:i:s';
}
let dateObj;
if (v instanceof Date) {
dateObj = v;
} else {
if (typeof v === 'undefined') {
dateObj = new Date();
} else if (/^(-)?\d{1,10}$/.test(v)) {
dateObj = new Date(v * 1000);
} else {
dateObj = new Date(v);
}
}
//
format = format.replace(/Y/g, dateObj.getFullYear() + "");
format = format.replace(/m/g, this.zeroFill(dateObj.getMonth() + 1, 2));
format = format.replace(/d/g, this.zeroFill(dateObj.getDate(), 2));
format = format.replace(/H/g, this.zeroFill(dateObj.getHours(), 2));
format = format.replace(/i/g, this.zeroFill(dateObj.getMinutes(), 2));
format = format.replace(/s/g, this.zeroFill(dateObj.getSeconds(), 2));
return format;
},
setStorage(key, value) { setStorage(key, value) {
return this.storage(key, value); return this.storage(key, value);
}, },
@ -159,6 +218,11 @@ const state = { method };
state[key] = state.method.getStorageBoolean('boolean:' + key, true) state[key] = state.method.getStorageBoolean('boolean:' + key, true)
}) })
// ajax
state.ajaxLoadNum = 0;
state.ajaxWsReady = false;
state.ajaxWsListener = [];
// 数据缓存 // 数据缓存
state.cacheUserBasic = state.method.getStorageJson("cacheUserBasic"); state.cacheUserBasic = state.method.getStorageJson("cacheUserBasic");
state.cacheDialogList = state.method.getStorageJson("cacheDialogList"); state.cacheDialogList = state.method.getStorageJson("cacheDialogList");

View File

@ -15,7 +15,7 @@
.login-logo { .login-logo {
width: 64px; width: 64px;
height: 64px; height: 64px;
background: url("../statics/images/logo.svg") no-repeat center center; background: url("../images/logo.svg") no-repeat center center;
background-size: contain; background-size: contain;
} }
.login-box { .login-box {