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

View File

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

View File

@ -123,7 +123,7 @@
uploadIng: 0,
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 },
maxSize: 10240
};

View File

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

View File

@ -2,163 +2,7 @@
* 页面专用
*/
(function (window) {
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);
},
});
const $ = window.$A;
/**
* =============================================================================
* ***************************** iviewui assist ****************************

View File

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

View File

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

View File

@ -30,7 +30,7 @@ export default {
data() {
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'],
actionUrl: $A.apiUrl('dialog/msg/sendfile'),
actionUrl: this.$store.state.method.apiUrl('dialog/msg/sendfile'),
}
},

View File

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

View File

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

View File

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

View File

@ -151,32 +151,28 @@ export default {
return;
}
this.loadIng++;
$A.apiAjax({
this.$store.dispatch("call", {
url: 'project/task/add',
data: this.getData(),
method: 'post',
complete: () => {
this.loadIng--;
},
success: ({ret, data, msg}) => {
if (ret === 1) {
$A.messageSuccess(msg);
this.active = false;
this.addData = {
owner: 0,
column_id: 0,
times: [],
subtasks: [],
p_level: 0,
p_name: '',
p_color: '',
}
this.$store.commit('getProjectOne', data.project_id);
this.$emit("on-success", data)
} else {
$A.modalError(msg);
}
}).then((data, msg) => {
this.loadIng--;
$A.messageSuccess(msg);
this.active = false;
this.addData = {
owner: 0,
column_id: 0,
times: [],
subtasks: [],
p_level: 0,
p_name: '',
p_color: '',
}
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;
}
this.$set(task, 'loading', true);
$A.apiAjax({
this.$store.dispatch("call", {
url: 'project/task/sublist',
data: {
task_id: task.id,
},
complete: () => {
this.$set(task, 'loading', false);
},
error: () => {
$A.modalAlert('网络繁忙,请稍后再试!');
},
success: ({ret, data, msg}) => {
if (ret === 1) {
this.$set(task, 'sub_list', data);
this.$set(task, 'sub_open', true);
} else {
$A.modalError(msg);
}
}
}).then((data, msg) => {
this.$set(task, 'loading', false);
this.$set(task, 'sub_list', data);
this.$set(task, 'sub_open', true);
}).catch((data, msg) => {
this.$set(task, 'loading', false);
$A.modalError(msg);
});
},

View File

@ -143,32 +143,29 @@ export default {
this.contactsLists = {};
}
this.contactsLoad++;
$A.apiAjax({
this.$store.dispatch("call", {
url: 'users/search',
data: {
take: 50
},
complete: () => {
this.contactsLoad--;
},
success: ({ret, data, msg}) => {
if (ret === 1) {
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);
}
});
}).then((data, msg) => {
this.contactsLoad--;
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);
}
});
}).catch((data, msg) => {
this.contactsLoad--;
});
},

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,122 @@
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
*/
getTaskPriority(state, callback) {
$A.apiAjax({
this.dispatch("call", {
url: 'system/priority',
success: ({ret, data, msg}) => {
if (ret === 1) {
state.taskPriority = data;
typeof callback === "function" && callback(data);
}
},
}).then((data, msg) => {
state.taskPriority = data;
typeof callback === "function" && callback(data);
});
},
@ -32,19 +29,14 @@ export default {
* @param callback
*/
getUserInfo(state, callback) {
$A.apiAjax({
this.dispatch("call", {
url: 'users/info',
error: () => {
$A.logout();
},
success: ({ret, data, msg}) => {
if (ret === 1) {
this.commit('setUserInfo', data);
typeof callback === "function" && callback(data);
}
},
}).then((data, msg) => {
this.commit('setUserInfo', data);
typeof callback === "function" && callback(data);
}).catch((data, msg) => {
this.commit("logout");
});
return state.userInfo;
},
/**
@ -90,15 +82,12 @@ export default {
if (state.cacheProjectList.length > 0) {
state.projectList = state.cacheProjectList;
}
$A.apiAjax({
this.dispatch("call", {
url: 'project/lists',
success: ({ret, data, msg}) => {
if (ret === 1) {
this.commit('saveProjectData', data.data);
} else {
$A.modalError(msg);
}
}
}).then((data, msg) => {
this.commit('saveProjectData', data.data);
}).catch((data, msg) => {
$A.modalError(msg);
});
},
@ -111,16 +100,13 @@ export default {
if (state.method.runNum(project_id) === 0) {
return;
}
$A.apiAjax({
this.dispatch("call", {
url: 'project/one',
data: {
project_id: project_id,
},
success: ({ret, data, msg}) => {
if (ret === 1) {
this.commit('saveProjectData', data);
}
}
}).then((data, msg) => {
this.commit('saveProjectData', data);
});
},
@ -140,21 +126,17 @@ export default {
state.projectDetail.id = project_id;
//
state.projectLoad++;
$A.apiAjax({
this.dispatch("call", {
url: 'project/detail',
data: {
project_id: project_id,
},
complete: () => {
state.projectLoad--;
},
success: ({ret, data, msg}) => {
if (ret === 1) {
this.commit('saveProjectData', data);
} else {
$A.modalError(msg);
}
}
}).then((data, msg) => {
state.projectLoad--;
this.commit('saveProjectData', data);
}).catch((data, msg) => {
state.projectLoad--;
$A.modalError(msg);
});
},
@ -245,30 +227,27 @@ export default {
return;
}
state.cacheUserBasic["::load"] = true;
$A.apiAjax({
this.dispatch("call", {
url: 'users/basic',
data: {
userid: array
},
complete: () => {
state.cacheUserBasic["::load"] = false;
typeof complete === "function" && complete()
},
success: ({ret, data, msg}) => {
if (ret === 1) {
data.forEach((item) => {
state.cacheUserBasic[item.userid] = {
time,
data: item
};
state.method.setStorage("cacheUserBasic", state.cacheUserBasic);
this.commit('setUserOnlineStatus', item);
typeof success === "function" && success(item, true)
});
} else {
$A.modalError(msg);
}
}
}).then((data, msg) => {
state.cacheUserBasic["::load"] = false;
typeof complete === "function" && complete()
data.forEach((item) => {
state.cacheUserBasic[item.userid] = {
time,
data: item
};
state.method.setStorage("cacheUserBasic", state.cacheUserBasic);
this.commit('setUserOnlineStatus', item);
typeof success === "function" && success(item, true)
});
}).catch((data, msg) => {
state.cacheUserBasic["::load"] = false;
typeof complete === "function" && complete()
$A.modalError(msg);
});
},
@ -278,16 +257,13 @@ export default {
* @param afterCallback
*/
getDialogList(state, afterCallback) {
$A.apiAjax({
this.dispatch("call", {
url: 'dialog/lists',
after: () => {
typeof afterCallback === "function" && afterCallback();
},
success: ({ret, data, msg}) => {
if (ret === 1) {
state.dialogList = data.data;
}
}
}).then((data, msg) => {
state.dialogList = data.data;
typeof afterCallback === "function" && afterCallback();
}).catch((data, msg) => {
typeof afterCallback === "function" && afterCallback();
});
},
@ -314,16 +290,13 @@ export default {
* @param dialog_id
*/
getDialogOne(state, dialog_id) {
$A.apiAjax({
this.dispatch("call", {
url: 'dialog/one',
data: {
dialog_id,
},
success: ({ret, data, msg}) => {
if (ret === 1) {
this.commit('getDialogUpdate', data);
}
}
}).then((data, msg) => {
this.commit('getDialogUpdate', data);
});
},
@ -336,20 +309,17 @@ export default {
if (userid === state.userId) {
return;
}
$A.apiAjax({
this.dispatch("call", {
url: 'dialog/open/user',
data: {
userid,
},
success: ({ret, data, msg}) => {
if (ret === 1) {
state.method.setStorage('messengerDialogId', data.id)
this.commit('getDialogMsgList', data.id);
this.commit('getDialogUpdate', data);
} else {
$A.modalError(msg);
}
}
}).then((data, msg) => {
state.method.setStorage('messengerDialogId', data.id)
this.commit('getDialogMsgList', data.id);
this.commit('getDialogUpdate', data);
}).catch((data, msg) => {
$A.modalError(msg);
});
},
@ -383,41 +353,39 @@ export default {
state.cacheDialogList[dialog_id + "::load"] = true;
//
state.dialogMsgLoad++;
$A.apiAjax({
this.dispatch("call", {
url: 'dialog/msg/lists',
data: {
dialog_id: dialog_id,
},
complete: () => {
state.dialogMsgLoad--;
state.cacheDialogList[dialog_id + "::load"] = false;
},
success: ({ret, data, msg}) => {
if (ret === 1) {
const dialog = data.dialog;
const reverse = data.data.reverse();
// 更新缓存
state.cacheDialogList[dialog_id] = {
dialog,
data: reverse,
};
state.method.setStorage("cacheDialogList", state.cacheDialogList);
// 更新当前会话消息
if (state.dialogId == dialog_id) {
state.dialogDetail = dialog;
reverse.forEach((item) => {
let index = state.dialogMsgList.findIndex(({id}) => id == item.id);
if (index === -1) {
state.dialogMsgList.push(item);
} else {
state.dialogMsgList.splice(index, 1, item);
}
})
}).then((data, msg) => {
state.dialogMsgLoad--;
state.cacheDialogList[dialog_id + "::load"] = false;
const dialog = data.dialog;
const reverse = data.data.reverse();
// 更新缓存
state.cacheDialogList[dialog_id] = {
dialog,
data: reverse,
};
state.method.setStorage("cacheDialogList", state.cacheDialogList);
// 更新当前会话消息
if (state.dialogId == dialog_id) {
state.dialogDetail = dialog;
reverse.forEach((item) => {
let index = state.dialogMsgList.findIndex(({id}) => id == item.id);
if (index === -1) {
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) {
const unread = state.dialogMsgUnread;
$A.apiAjax({
this.dispatch("call", {
url: 'dialog/msg/unread',
success: ({ret, data, msg}) => {
if (ret === 1) {
if (unread == state.dialogMsgUnread) {
state.dialogMsgUnread = data.unread;
} else {
setTimeout(() => {
this.commit('getDialogMsgUnread');
}, 200);
}
}
}).then((data, msg) => {
if (unread == state.dialogMsgUnread) {
state.dialogMsgUnread = data.unread;
} else {
setTimeout(() => {
this.commit('getDialogMsgUnread');
}, 200);
}
});
},
@ -635,7 +600,7 @@ export default {
//
const {id, dialog_id, r} = msgData;
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);
if (dialog && dialog.unread > 0) {
dialog.unread--
@ -649,7 +614,7 @@ export default {
this.commit('wsSend', {
type: 'readMsg',
data: {
id: $A.cloneJSON(state.wsReadWaitList)
id: state.method.cloneJSON(state.wsReadWaitList)
}
});
state.wsReadWaitList = [];
@ -677,4 +642,13 @@ export default {
wsClose(state) {
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 = {
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) {
return this.storage(key, value);
},
@ -159,6 +218,11 @@ const state = { method };
state[key] = state.method.getStorageBoolean('boolean:' + key, true)
})
// ajax
state.ajaxLoadNum = 0;
state.ajaxWsReady = false;
state.ajaxWsListener = [];
// 数据缓存
state.cacheUserBasic = state.method.getStorageJson("cacheUserBasic");
state.cacheDialogList = state.method.getStorageJson("cacheDialogList");

View File

@ -15,7 +15,7 @@
.login-logo {
width: 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;
}
.login-box {