1、Ajax优化

Former-commit-id: e4bff2f1e60ee94d1400cc521b6393b7e554d85b
master
wangbing 5 years ago
parent 817fb3e796
commit 8748f10f51

@ -193,100 +193,83 @@
return Promise.resolve(rsp);
})
};
function Ajax(module, target, method, data) {
function Ajax(module, target, method) {
this.mModule = module;
this.mTarget = target;
this.mMethod = method;
this.mData = data ? data : {};
this.module = function (module) {
this.mModule = module;
return this;
};
this.target = function (target) {
this.mTarget = target;
return this;
};
this.method = function (method) {
this.mMethod = method;
return this;
};
this.data = function (data) {
this.mData = data;
return this;
};
this.post = function (callback) {
this.post = function (data, callback) {
switch (this.mMethod) {
case "upload":
return uploadRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: this.mData
data: data
}).then(callback);
break;
case "imports":
return importRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: this.mData
data: data
}).then(callback);
break;
case "exports":
return downRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: JSON.stringify(this.mData)
data: JSON.stringify(data)
}).then(callback)
break;
case "template":
return downRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: JSON.stringify(this.mData)
data: JSON.stringify(data)
}).then(callback);
break;
default:
jsonRequest({
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
data: JSON.stringify(this.mData)
data: JSON.stringify(data)
}).then(callback);
}
};
this.create = function (callback) {
this.create = function (data, callback) {
this.mMethod = "create";
this.post(callback);
this.post(data, callback);
};
this.delete = function (callback) {
this.delete = function (data, callback) {
this.mMethod = "delete";
this.post(callback);
this.post(data, callback);
};
this.update = function (callback) {
this.update = function (data, callback) {
this.mMethod = "update";
this.post(callback);
this.post(data, callback);
};
this.find = function (callback) {
this.find = function (data, callback) {
this.mMethod = "find";
this.post(callback);
this.post(data, callback);
};
this.get = function (callback) {
this.get = function (data, callback) {
this.mMethod = "get";
this.post(callback);
this.post(data, callback);
};
this.load = function (callback) {
this.load = function (data, callback) {
this.mMethod = "load";
this.post(callback);
this.post(data, callback);
};
this.template = function (callback) {
this.template = function (data, callback) {
this.mMethod = "template";
this.post(callback);
this.post(data, callback);
};
this.imports = function (callback) {
this.imports = function (data, callback) {
this.mMethod = "imports";
this.post(callback);
this.post(data, callback);
};
this.exports = function (callback) {
this.exports = function (data, callback) {
this.mMethod = "exports";
this.post(callback);
this.post(data, callback);
};
this.upload = function (callback) {
this.upload = function (data, callback) {
this.mMethod = "upload";
this.post(callback);
this.post(data, callback);
};
}

@ -1029,11 +1029,7 @@
},
methods: {
doAjax: function () {
new Ajax()
.module("system")
.target("user")
.data({})
.find(function (response) {
new Ajax("system", "user","find").post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -374,11 +374,7 @@
onCommand: function (cmd) {
switch (cmd) {
case "logout":
new Ajax()
.module("system")
.target("User")
.method("logout")
.post(function (response) {
new Ajax("system", "User", "logout").post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -110,12 +110,7 @@
this.$refs[formName].validate(function (valid) {
if (valid) {
this.isSubmit = true;
new Ajax()
.module("system")
.target("User")
.method("login")
.data(this.form)
.post(function (response) {
new Ajax("system", "User", "login", this.form).post(function (response) {
this.isSubmit = false;
if (response.errors.length > 0) {
nav.e(response.errors[0].message);

@ -313,11 +313,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax(this.module, this.target, "delete", {id: item.id}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -302,11 +302,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "dept", "delete",{id: item.id}).post((function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -345,12 +341,7 @@
return data.deptName.indexOf(value) !== -1;
},
onLoadTree: function () {
new Ajax()
.module("system")
.target("dept")
.method("tree")
.data({})
.post(function (response) {
new Ajax("system","dept","tree").post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -362,11 +353,7 @@
this.$refs['form'].validate(function (valid) {
if (valid) {
if (this.form.id) {
new Ajax()
.module(this.module)
.target(this.target)
.data(this.form)
.update(function (response) {
new Ajax("system", "dept").data(this.form).update(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -377,11 +364,7 @@
}
}.bind(this))
} else {
new Ajax()
.module(this.module)
.target(this.target)
.data(this.form)
.create(function (response) {
new Ajax("system", "dept").data(this.form).create(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -234,11 +234,9 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "dict").delete({
id: item.id
}, function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -230,11 +230,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "dictItem", "delete", {id: item.id}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -6,7 +6,8 @@
<el-input v-model="vm.name" clearable size="mini" placeholder="请输入文件名称"></el-input>
</el-form-item>
<el-form-item label="文件类型" prop="fileType">
<el-input-dict v-model="vm.fileType" clearable size="mini" placeholder="请输入文件类型" dict-name="FILE_TYPE" ></el-input-dict>
<el-input-dict v-model="vm.fileType" clearable size="mini" placeholder="请输入文件类型"
dict-name="FILE_TYPE"></el-input-dict>
</el-form-item>
<el-form-item label="扩展属性1" prop="attribute1">
<el-input v-model="vm.attribute1" clearable size="mini" placeholder="请输入扩展属性1"></el-input>
@ -126,7 +127,8 @@
<el-input v-model="form.name" clearable size="mini" placeholder="请输入文件名称"></el-input>
</el-form-item>
<el-form-item label="文件类型" prop="fileType">
<el-input-dict v-model="form.fileType" clearable size="mini" placeholder="请输入文件类型" dict-name="FILE_TYPE" ></el-input-dict>
<el-input-dict v-model="form.fileType" clearable size="mini" placeholder="请输入文件类型"
dict-name="FILE_TYPE"></el-input-dict>
</el-form-item>
<el-form-item label="扩展属性1" prop="attribute1">
<el-input v-model="form.attribute1" clearable size="mini" placeholder="请输入扩展属性1"></el-input>
@ -186,8 +188,7 @@
{required: true, message: '文件名称不能为空', trigger: 'blur'},
{min: 1, max: 255, message: '文件名称长度在 1 到 255 个字符', trigger: 'blur'}
],
fileType: [
],
fileType: [],
attribute1: [
{min: 1, max: 50, message: '扩展属性1长度在 1 到 50 个字符', trigger: 'blur'}
],
@ -237,11 +238,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "file", "delete", {id: item.id}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -2,13 +2,15 @@
<el-card class="box-card">
<el-form class="search" :inline="true" :model="vm" ref="vm" label-position="right" label-width="90px">
<el-form-item label="错误类型" prop="logErrType">
<el-input-dict v-model="vm.logErrType" clearable size="mini" placeholder="请输入错误类型" dict-name="LOG_ERR_TYPE" ></el-input-dict>
<el-input-dict v-model="vm.logErrType" clearable size="mini" placeholder="请输入错误类型"
dict-name="LOG_ERR_TYPE"></el-input-dict>
</el-form-item>
<el-form-item label="错误标题" prop="title">
<el-input v-model="vm.title" clearable size="mini" placeholder="请输入错误标题"></el-input>
</el-form-item>
<el-form-item label="处理结果" prop="logErrResult">
<el-input-dict v-model="vm.logErrResult" clearable size="mini" placeholder="请输入处理结果" dict-name="LOG_ERR_RESULT" ></el-input-dict>
<el-input-dict v-model="vm.logErrResult" clearable size="mini" placeholder="请输入处理结果"
dict-name="LOG_ERR_RESULT"></el-input-dict>
</el-form-item>
<el-form-item label="属性1" prop="attribute1">
<el-input v-model="vm.attribute1" clearable size="mini" placeholder="请输入属性1"></el-input>
@ -140,9 +142,11 @@
:title="form.title"
:close-on-click-modal="false"
:visible.sync="form.dialog">
<el-form class="form" :model="form" :inline="true" :rules="formRules" ref="form" label-position="right" label-width="90px">
<el-form class="form" :model="form" :inline="true" :rules="formRules" ref="form" label-position="right"
label-width="90px">
<el-form-item label="错误类型" prop="logErrType">
<el-input-dict v-model="form.logErrType" clearable size="mini" placeholder="请输入错误类型" dict-name="LOG_ERR_TYPE" ></el-input-dict>
<el-input-dict v-model="form.logErrType" clearable size="mini" placeholder="请输入错误类型"
dict-name="LOG_ERR_TYPE"></el-input-dict>
</el-form-item>
<el-form-item label="错误标题" prop="title">
<el-input v-model="form.title" clearable size="mini" placeholder="请输入错误标题"></el-input>
@ -151,7 +155,8 @@
<el-input v-model="form.content" clearable size="mini" placeholder="请输入错误内容"></el-input>
</el-form-item>
<el-form-item label="处理结果" prop="logErrResult">
<el-input-dict v-model="form.logErrResult" clearable size="mini" placeholder="请输入处理结果" dict-name="LOG_ERR_RESULT" ></el-input-dict>
<el-input-dict v-model="form.logErrResult" clearable size="mini" placeholder="请输入处理结果"
dict-name="LOG_ERR_RESULT"></el-input-dict>
</el-form-item>
<el-form-item label="属性1" prop="attribute1">
<el-input v-model="form.attribute1" clearable size="mini" placeholder="请输入属性1"></el-input>
@ -203,14 +208,12 @@
rowVersion: ""
},
formRules: {
logErrType: [
],
logErrType: [],
title: [
{required: true, message: '错误标题不能为空', trigger: 'blur'},
{min: 1, max: 50, message: '错误标题长度在 1 到 50 个字符', trigger: 'blur'}
],
content: [
],
content: [],
logErrResult: [
{required: true, message: '处理结果不能为空', trigger: 'blur'},
],
@ -257,11 +260,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "logErr", "delete", {id: item.id}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -12,7 +12,8 @@
<el-input v-model="vm.resName" clearable size="mini" placeholder="请输入资源名称"></el-input>
</el-form-item>
<el-form-item label="资源类型" prop="resType">
<el-input-dict v-model="vm.resType" clearable size="mini" placeholder="请输入资源类型" dict-name="RES_TYPE"></el-input-dict>
<el-input-dict v-model="vm.resType" clearable size="mini" placeholder="请输入资源类型"
dict-name="RES_TYPE"></el-input-dict>
</el-form-item>
<el-form-item label="资源内容" prop="resValue">
<el-input v-model="vm.resValue" clearable size="mini" placeholder="请输入资源内容"></el-input>
@ -25,7 +26,8 @@
</el-form-item>
<el-form-item>
<el-button type="primary" size="mini" icon="el-icon-search" @click="onSearch">搜索</el-button>
<el-button type="warning" size="mini" icon="el-icon-refresh-left" @click="onReset('vm')">重置</el-button>
<el-button type="warning" size="mini" icon="el-icon-refresh-left" @click="onReset('vm')">重置
</el-button>
</el-form-item>
</el-form>
@ -171,8 +173,10 @@
:expand-on-click-node="false">
<div class="tree" slot-scope="{ node, data }">
<span>
<el-button type="text" size="mini" icon="el-icon-plus" @click="onTreeCreate(data)"></el-button>
{{ data.resName }}<span style="color: #409EFF" @click="onTreeEdit(data)">[{{data.resCode}}]</span>
<el-button type="text" size="mini" icon="el-icon-plus"
@click="onTreeCreate(data)"></el-button>
{{ data.resName }}<span style="color: #409EFF"
@click="onTreeEdit(data)">[{{data.resCode}}]</span>
</span>
</div>
</el-tree>
@ -307,11 +311,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "res", "delete", {id: item.id}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -352,12 +352,7 @@
return data.comment.indexOf(value) !== -1;
},
onLoadTree: function () {
new Ajax()
.module("system")
.target("res")
.method("tree")
.data({})
.post(function (response) {
new Ajax("system", "res", "tree").post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -369,11 +364,7 @@
this.$refs['form'].validate(function (valid) {
if (valid) {
if (this.form.id) {
new Ajax()
.module(this.module)
.target(this.target)
.data( this.form)
.update(function (response) {
new Ajax("system", "res", "update", this.form).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -384,11 +375,7 @@
}
}.bind(this))
} else {
new Ajax()
.module(this.module)
.target(this.target)
.data( this.form)
.create(function (response) {
new Ajax("system", "res", "create", this.form).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -227,11 +227,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "role", "delete", {id: item.id}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -248,11 +244,7 @@
this.formResource.dialog = true;
this.formResource.roleId = item.id;
this.formResource.roleCode = item.code;
new Ajax()
.module("system")
.target("roleRes")
.data({roleId: item.id, pageSize: 0})
.find(function (response) {
new Ajax("system", "roleRes", "find", {roleId: item.id, pageSize: 0}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -266,18 +258,14 @@
}.bind(this))
},
onCheck: function (item, status) {
new Ajax()
.module("system")
.target("roleRes")
.method("check")
.data({
var param = {
roleId: this.formResource.roleId,
roleCode: this.formResource.roleCode,
resId: item.id,
resCode: item.resCode,
checked: status.checkedKeys.indexOf(item.id) !== -1,
})
.post(function (response) {
checked: status.checkedKeys.indexOf(item.id) !== -1
}
new Ajax("system", "roleRes", "check", param).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -286,12 +274,7 @@
}.bind(this))
},
onLoadTree: function () {
new Ajax()
.module("system")
.target("res")
.method("tree")
.data({})
.post(function (response) {
new Ajax("system", "res", "tree").post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -55,11 +55,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "schedule", "delete", {id: item.id}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -249,12 +249,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module("system")
.target("tokens")
.method("logout")
.data({token: item.token})
.post(function (response) {
new Ajax("system", "tokens", "logout", {token: item.token}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

@ -269,11 +269,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
new Ajax()
.module(this.module)
.target(this.target)
.data({id: item.id})
.delete(function (response) {
new Ajax("system", "user", "delete", {id: item.id}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
@ -286,12 +282,7 @@
});
},
loadRoles: function () {
new Ajax()
.module("system")
.target("role")
.method("find")
.data({pageSize: 0})
.post(function (response) {
new Ajax("system", "role", "find", {pageSize: 0}).post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

Loading…
Cancel
Save

Powered by TurnKey Linux.