|
|
|
|
<script>
|
|
|
|
|
var jsonService = axios.create({
|
|
|
|
|
method: 'post',
|
|
|
|
|
timeout: 30000,
|
|
|
|
|
baseURL: '${context?default("")}',
|
|
|
|
|
headers: {'Content-Type': 'application/json;charset=UTF-8'},
|
|
|
|
|
});
|
|
|
|
|
var downloadService = axios.create({
|
|
|
|
|
method: 'post',
|
|
|
|
|
timeout: 30000,
|
|
|
|
|
baseURL: '${context?default("")}',
|
|
|
|
|
responseType: 'blob',
|
|
|
|
|
headers: {'Content-Type': 'application/json;charset=UTF-8'},
|
|
|
|
|
});
|
|
|
|
|
var uploadService = axios.create({
|
|
|
|
|
method: 'post',
|
|
|
|
|
timeout: 30000,
|
|
|
|
|
baseURL: '${context?default("")}',
|
|
|
|
|
responseType: 'blob',
|
|
|
|
|
headers: {'Content-Type': 'multipart/form-data'},
|
|
|
|
|
onUploadProgress: function (progressEvent) {
|
|
|
|
|
var complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%'
|
|
|
|
|
nav.tipShow("上传中(" + complete + ")")
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
function handleError(status) {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 401:
|
|
|
|
|
return {message: "未授权,请登录(401)"};
|
|
|
|
|
case 403:
|
|
|
|
|
return {message: "拒绝访问(403)"};
|
|
|
|
|
case 404:
|
|
|
|
|
return {message: "请求地址错误(404)"};
|
|
|
|
|
case 408:
|
|
|
|
|
return {message: "请求超时(408)"};
|
|
|
|
|
case 500:
|
|
|
|
|
return {message: "服务器内部错误(500)"};
|
|
|
|
|
case 501:
|
|
|
|
|
return {message: "服务未实现(501)"};
|
|
|
|
|
default:
|
|
|
|
|
return {message: "请求错误(" + error.response.status + ")"};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function jsonRequest(data) {
|
|
|
|
|
nav.barShow();
|
|
|
|
|
return jsonService.request(data)
|
|
|
|
|
.then(function (response) {
|
|
|
|
|
if (response.data.errors && response.data.errors.length == 0) {
|
|
|
|
|
nav.barFinish();
|
|
|
|
|
} else if(response.data.errors && response.data.errors.length > 0) {
|
|
|
|
|
nav.barError();
|
|
|
|
|
} else {
|
|
|
|
|
response.data = {errors: [{message: '服务器响应错误'}]};
|
|
|
|
|
nav.barError();
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve(response.data);
|
|
|
|
|
}, function (error) {
|
|
|
|
|
nav.barError();
|
|
|
|
|
const rsp = {errors: []};
|
|
|
|
|
if (!error.response) {
|
|
|
|
|
rsp.errors.push({message: error.message});
|
|
|
|
|
} else {
|
|
|
|
|
rsp.errors.push(handleError(error.response.status));
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve(rsp);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
function upRequest(data) {
|
|
|
|
|
nav.barShow();
|
|
|
|
|
nav.tipShow("上传中...");
|
|
|
|
|
var fd = new FormData();
|
|
|
|
|
fd.append("file", data.data);
|
|
|
|
|
data.data = fd;
|
|
|
|
|
return uploadService.request(data)
|
|
|
|
|
.then(function (response) {
|
|
|
|
|
nav.tipClose();
|
|
|
|
|
if (!response.data) {
|
|
|
|
|
nav.barError();
|
|
|
|
|
return Promise.resolve({errors: [{message: '下载错误'}]});
|
|
|
|
|
} else if ("application/json" == response.data.type) {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.addEventListener("loadend", function () {
|
|
|
|
|
var rsp = JSON.parse(reader.result);
|
|
|
|
|
if (rsp.errors.length > 0) {
|
|
|
|
|
nav.barError();
|
|
|
|
|
nav.e(rsp.errors[0].message)
|
|
|
|
|
} else {
|
|
|
|
|
nav.barFinish();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
reader.readAsText(response.data, "utf-8");
|
|
|
|
|
return Promise.resolve({errors: []});
|
|
|
|
|
} else {
|
|
|
|
|
nav.barFinish();
|
|
|
|
|
// 获取响应header中文件信息
|
|
|
|
|
var dis = response.headers['content-disposition'];
|
|
|
|
|
// 正则匹配文件名
|
|
|
|
|
var fileName = dis.match(/filename="(.*\..*)"/)[1];
|
|
|
|
|
// 模拟下载
|
|
|
|
|
utils.blobtoDown(decodeURIComponent(fileName), new Blob([response.data]))
|
|
|
|
|
return Promise.resolve({errors: []});
|
|
|
|
|
}
|
|
|
|
|
}, function (error) {
|
|
|
|
|
nav.tipClose();
|
|
|
|
|
nav.barError();
|
|
|
|
|
const rsp = {errors: []};
|
|
|
|
|
if (!error.response) {
|
|
|
|
|
rsp.errors.push({message: error.message});
|
|
|
|
|
} else {
|
|
|
|
|
rsp.errors.push(handleError(error.response.status));
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve(rsp);
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
function downRequest(data) {
|
|
|
|
|
nav.barShow();
|
|
|
|
|
return downloadService.request(data)
|
|
|
|
|
.then(function (response) {
|
|
|
|
|
if (!response.data) {
|
|
|
|
|
nav.barError();
|
|
|
|
|
return Promise.resolve({errors: [{message: '下载错误'}]});
|
|
|
|
|
} else if ("application/json" == response.data.type) {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.addEventListener("loadend", function () {
|
|
|
|
|
var rsp = JSON.parse(reader.result);
|
|
|
|
|
if (rsp.errors.length > 0) {
|
|
|
|
|
nav.barError();
|
|
|
|
|
nav.e(rsp.errors[0].message)
|
|
|
|
|
} else {
|
|
|
|
|
nav.barFinish();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
reader.readAsText(response.data, "utf-8");
|
|
|
|
|
return Promise.resolve({errors: []});
|
|
|
|
|
} else {
|
|
|
|
|
nav.barFinish();
|
|
|
|
|
// 获取响应header中文件信息
|
|
|
|
|
var dis = response.headers['content-disposition'];
|
|
|
|
|
// 正则匹配文件名
|
|
|
|
|
var fileName = dis.match(/filename="(.*\..*)"/)[1];
|
|
|
|
|
// 模拟下载
|
|
|
|
|
utils.blobtoDown(decodeURIComponent(fileName), new Blob([response.data]))
|
|
|
|
|
return Promise.resolve({errors: []});
|
|
|
|
|
}
|
|
|
|
|
}, function (error) {
|
|
|
|
|
nav.tipClose();
|
|
|
|
|
nav.barError();
|
|
|
|
|
const rsp = {errors: []};
|
|
|
|
|
if (!error.response) {
|
|
|
|
|
rsp.errors.push({message: error.message});
|
|
|
|
|
} else {
|
|
|
|
|
rsp.errors.push(handleError(error.response.status));
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve(rsp);
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
function Ajax(module, target, method) {
|
|
|
|
|
this.mModule = module;
|
|
|
|
|
this.mTarget = target;
|
|
|
|
|
this.mMethod = method;
|
|
|
|
|
this.mData = {};
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
jsonRequest({
|
|
|
|
|
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
|
|
|
|
|
data: JSON.stringify(this.mData),
|
|
|
|
|
}).then(callback)
|
|
|
|
|
};
|
|
|
|
|
this.create = function (callback) {
|
|
|
|
|
this.mMethod = "create";
|
|
|
|
|
this.post(callback);
|
|
|
|
|
};
|
|
|
|
|
this.create = function (callback) {
|
|
|
|
|
this.mMethod = "create";
|
|
|
|
|
this.post(callback);
|
|
|
|
|
};
|
|
|
|
|
this.delete = function (callback) {
|
|
|
|
|
this.mMethod = "delete";
|
|
|
|
|
this.post(callback);
|
|
|
|
|
};
|
|
|
|
|
this.update = function (callback) {
|
|
|
|
|
this.mMethod = "update";
|
|
|
|
|
this.post(callback);
|
|
|
|
|
};
|
|
|
|
|
this.find = function (callback) {
|
|
|
|
|
this.mMethod = "find";
|
|
|
|
|
this.post(callback);
|
|
|
|
|
};
|
|
|
|
|
this.get = function (callback) {
|
|
|
|
|
this.mMethod = "get";
|
|
|
|
|
this.post(callback);
|
|
|
|
|
};
|
|
|
|
|
this.load = function (callback) {
|
|
|
|
|
this.mMethod = "load";
|
|
|
|
|
this.post(callback);
|
|
|
|
|
};
|
|
|
|
|
this.template = function (callback) {
|
|
|
|
|
this.mMethod = "template";
|
|
|
|
|
return downRequest({
|
|
|
|
|
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
|
|
|
|
|
data: JSON.stringify(this.mData),
|
|
|
|
|
}).then(callback)
|
|
|
|
|
};
|
|
|
|
|
this.imports = function (callback) {
|
|
|
|
|
this.mMethod = "imports";
|
|
|
|
|
return upRequest({
|
|
|
|
|
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
|
|
|
|
|
data: this.mData,
|
|
|
|
|
}).then(callback)
|
|
|
|
|
};
|
|
|
|
|
this.exports = function (callback) {
|
|
|
|
|
this.mMethod = "exports";
|
|
|
|
|
return downRequest({
|
|
|
|
|
url: '/ajax/' + this.mModule + "/" + this.mTarget + "/" + this.mMethod,
|
|
|
|
|
data: JSON.stringify(this.mData),
|
|
|
|
|
}).then(callback)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vue.config.productionTip = false;
|
|
|
|
|
var mixin = {
|
|
|
|
|
data: {
|
|
|
|
|
activeIndex: 'home',
|
|
|
|
|
context: '${context?default("")}',
|
|
|
|
|
isSubmit: false,
|
|
|
|
|
result: [],
|
|
|
|
|
select: []
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
onSearch: function () {
|
|
|
|
|
this.vm.pageNumber = 1;
|
|
|
|
|
this.onFind();
|
|
|
|
|
},
|
|
|
|
|
onReset: function (form) {
|
|
|
|
|
this.$refs[form].resetFields();
|
|
|
|
|
nav.w('重置成功');
|
|
|
|
|
},
|
|
|
|
|
onPageChange: function (pageNumber) {
|
|
|
|
|
this.vm.pageNumber = pageNumber;
|
|
|
|
|
this.onFind();
|
|
|
|
|
},
|
|
|
|
|
onPageSizeChange: function (pageSize) {
|
|
|
|
|
this.vm.pageSize = pageSize;
|
|
|
|
|
this.onFind();
|
|
|
|
|
},
|
|
|
|
|
onSelectionChange: function (select) {
|
|
|
|
|
this.select = select;
|
|
|
|
|
},
|
|
|
|
|
onTemplate: function () {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module(this.module)
|
|
|
|
|
.target(this.target)
|
|
|
|
|
.method("template")
|
|
|
|
|
.template(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
nav.e(response.errors[0].message);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
onImport: function (item) {
|
|
|
|
|
utils.selectFile(function (files) {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module(this.module)
|
|
|
|
|
.target(this.target)
|
|
|
|
|
.data(files[0])
|
|
|
|
|
.imports(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
nav.e(response.errors[0].message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}.bind(this))
|
|
|
|
|
},
|
|
|
|
|
onExport: function () {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module(this.module)
|
|
|
|
|
.target(this.target)
|
|
|
|
|
.data( this.vm)
|
|
|
|
|
.exports(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
nav.e(response.errors[0].message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onSave: function () {
|
|
|
|
|
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) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
nav.e(response.errors[0].message);
|
|
|
|
|
} else {
|
|
|
|
|
this.onFind();
|
|
|
|
|
this.$refs['form'].resetFields();
|
|
|
|
|
this.form.dialog = false;
|
|
|
|
|
}
|
|
|
|
|
}.bind(this))
|
|
|
|
|
} else {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module(this.module)
|
|
|
|
|
.target(this.target)
|
|
|
|
|
.data(this.form)
|
|
|
|
|
.create(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
nav.e(response.errors[0].message);
|
|
|
|
|
} else {
|
|
|
|
|
this.onFind();
|
|
|
|
|
this.$refs['form'].resetFields();
|
|
|
|
|
this.form.dialog = false;
|
|
|
|
|
}
|
|
|
|
|
}.bind(this))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}.bind(this));
|
|
|
|
|
},
|
|
|
|
|
onFind: function () {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module(this.module)
|
|
|
|
|
.target(this.target)
|
|
|
|
|
.data(this.vm)
|
|
|
|
|
.find(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
nav.e(response.errors[0].message);
|
|
|
|
|
} else {
|
|
|
|
|
this.result = response.result;
|
|
|
|
|
this.vm.totalCount = Number(response.totalCount);
|
|
|
|
|
}
|
|
|
|
|
}.bind(this))
|
|
|
|
|
},
|
|
|
|
|
onDelete: function (item) {
|
|
|
|
|
this.$confirm('将删除该项, 是否继续?', '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(function () {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module(this.module)
|
|
|
|
|
.target(this.target)
|
|
|
|
|
.data({id: item.id})
|
|
|
|
|
.delete(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
nav.e(response.errors[0].message);
|
|
|
|
|
} else {
|
|
|
|
|
nav.s("删除成功");
|
|
|
|
|
this.onFind();
|
|
|
|
|
}
|
|
|
|
|
}.bind(this))
|
|
|
|
|
}.bind(this)).catch(function (action) {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onBitchDelete: function () {
|
|
|
|
|
if (this.select.length == 0) {
|
|
|
|
|
nav.w("至少选中一项");
|
|
|
|
|
} else {
|
|
|
|
|
this.$confirm('将删除已选择的项, 是否继续?', '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(function () {
|
|
|
|
|
for (var i = 0; i < this.select.length; i++) {
|
|
|
|
|
(function (obj) {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module(this.module)
|
|
|
|
|
.target(this.target)
|
|
|
|
|
.data({id: obj.id})
|
|
|
|
|
.delete(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
nav.e(response.errors[0].message);
|
|
|
|
|
} else {
|
|
|
|
|
for (var j = 0; j < this.select.length; j++) {
|
|
|
|
|
if (this.select[j].id === obj.id) {
|
|
|
|
|
this.select.splice(j, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (this.select.length === 0) {
|
|
|
|
|
nav.s("删除成功")
|
|
|
|
|
this.onFind();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.bind(this))
|
|
|
|
|
}.bind(this))(this.select[i]);
|
|
|
|
|
}
|
|
|
|
|
}.bind(this)).catch(function (action) {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created: function () {
|
|
|
|
|
},
|
|
|
|
|
mounted: function () {
|
|
|
|
|
},
|
|
|
|
|
filters: {},
|
|
|
|
|
watch: {}
|
|
|
|
|
};
|
|
|
|
|
// 实例化工具
|
|
|
|
|
window.nav = new Vue({
|
|
|
|
|
data: {
|
|
|
|
|
loadingTip: '',
|
|
|
|
|
loadingBar: '',
|
|
|
|
|
context: '${context?default("")}',
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
tipShow: function (msg) {
|
|
|
|
|
var message = "<i class='el-icon-loading'></i> 正在加载 ..."
|
|
|
|
|
if (msg) {
|
|
|
|
|
message = "<i class='el-icon-loading'></i> " + msg
|
|
|
|
|
}
|
|
|
|
|
if (!this.loadingTip) {
|
|
|
|
|
this.loadingTip = this.$message({
|
|
|
|
|
type: '',
|
|
|
|
|
duration: 0,
|
|
|
|
|
dangerouslyUseHTMLString: true,
|
|
|
|
|
message: message
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.loadingTip.message = message;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
tipClose: function (msg) {
|
|
|
|
|
if (this.loadingTip) {
|
|
|
|
|
this.loadingTip.close();
|
|
|
|
|
this.loadingTip = '';
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
barShow: function () {
|
|
|
|
|
if (window.index) {
|
|
|
|
|
window.index.barStart();
|
|
|
|
|
} else if (window.parent.index) {
|
|
|
|
|
window.parent.index.barStart();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
barFinish: function () {
|
|
|
|
|
if (window.index) {
|
|
|
|
|
window.index.barFinish();
|
|
|
|
|
} else if (window.parent.index) {
|
|
|
|
|
window.parent.index.barFinish();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
barError: function () {
|
|
|
|
|
if (window.index) {
|
|
|
|
|
window.index.barError();
|
|
|
|
|
} else if (window.parent.index) {
|
|
|
|
|
window.parent.index.barError();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
i: function (message, callback) {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: "info",
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: message,
|
|
|
|
|
duration: 1500,
|
|
|
|
|
onClose: callback
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
e: function (message, callback) {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: "error",
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: message,
|
|
|
|
|
duration: 1500,
|
|
|
|
|
onClose: callback
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
w: function (message, callback) {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: "warning",
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: message,
|
|
|
|
|
duration: 1500,
|
|
|
|
|
onClose: callback
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
s: function (message, callback) {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: "success",
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: message,
|
|
|
|
|
duration: 1500,
|
|
|
|
|
onClose: callback
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
toOpen: function (url) {
|
|
|
|
|
this.tipShow();
|
|
|
|
|
var url = url.substring(0, 1) == "/" ? url.substring(1) : url;
|
|
|
|
|
$("body").append($("<a id='wb-open' href='" + this.context + "/" + url + "' target='_self' style='dispaly:none;'></a>"))
|
|
|
|
|
document.getElementById("wb-open").click();
|
|
|
|
|
$("#wb-open").remove();
|
|
|
|
|
},
|
|
|
|
|
toOpenNew: function (url) {
|
|
|
|
|
var url = url.substring(0, 1) == "/" ? url.substring(1) : url;
|
|
|
|
|
$("body").append($("<a id='wb-open' href='" + this.context + "/" + url + "' target='_blank' style='dispaly:none;'></a>"))
|
|
|
|
|
document.getElementById("wb-open").click();
|
|
|
|
|
$("#wb-open").remove();
|
|
|
|
|
},
|
|
|
|
|
toHome: function () {
|
|
|
|
|
this.tipShow();
|
|
|
|
|
location.href = this.context + "/"
|
|
|
|
|
},
|
|
|
|
|
// 滚动屏蔽至顶部
|
|
|
|
|
scrollToTop: function () {
|
|
|
|
|
var distance = document.documentElement.scrollTop || document.body.scrollTop;
|
|
|
|
|
var step = distance / 10;
|
|
|
|
|
|
|
|
|
|
(function jump() {
|
|
|
|
|
if (distance > 0) {
|
|
|
|
|
distance -= step;
|
|
|
|
|
window.scrollTo(0, distance);
|
|
|
|
|
setTimeout(jump, 10)
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
},
|
|
|
|
|
// 控制任一目标滚动到顶部
|
|
|
|
|
scrollToTop: function (select) {
|
|
|
|
|
var distance = $(select).scrollTop();
|
|
|
|
|
var step = distance / 10;
|
|
|
|
|
|
|
|
|
|
(function jump() {
|
|
|
|
|
if (distance > 0) {
|
|
|
|
|
distance -= step;
|
|
|
|
|
$(select).scrollTop(distance);
|
|
|
|
|
setTimeout(jump, 10)
|
|
|
|
|
} else {
|
|
|
|
|
$(select).scrollTop(distance);
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
},
|
|
|
|
|
setFullScreen: function () {
|
|
|
|
|
var el = document.documentElement;
|
|
|
|
|
var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;
|
|
|
|
|
|
|
|
|
|
//typeof rfs != "undefined" && rfs
|
|
|
|
|
if (rfs) {
|
|
|
|
|
rfs.call(el);
|
|
|
|
|
} else if (typeof window.ActiveXObject !== "undefined") {
|
|
|
|
|
//for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏
|
|
|
|
|
var wscript = new ActiveXObject("WScript.Shell");
|
|
|
|
|
if (wscript != null) {
|
|
|
|
|
wscript.SendKeys("{F11}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
cancelFullScreen: function () {
|
|
|
|
|
var el = document;
|
|
|
|
|
var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen;
|
|
|
|
|
|
|
|
|
|
//typeof cfs != "undefined" && cfs
|
|
|
|
|
if (cfs) {
|
|
|
|
|
cfs.call(el);
|
|
|
|
|
} else if (typeof window.ActiveXObject !== "undefined") {
|
|
|
|
|
//for IE,这里和fullScreen相同,模拟按下F11键退出全屏
|
|
|
|
|
var wscript = new ActiveXObject("WScript.Shell");
|
|
|
|
|
if (wscript != null) {
|
|
|
|
|
wscript.SendKeys("{F11}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
setCookie:function (name, value, expiretime) {
|
|
|
|
|
var exdate = new Date();
|
|
|
|
|
exdate.setDate(exdate.getTime() + expiretime);
|
|
|
|
|
document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + exdate.toGMTString() + ";path=/";
|
|
|
|
|
},
|
|
|
|
|
getCookie:function (name) {
|
|
|
|
|
if (document.cookie.length > 0) {
|
|
|
|
|
c_start = document.cookie.indexOf(name + "=")
|
|
|
|
|
if (c_start != -1){
|
|
|
|
|
c_start = c_start + name.length + 1
|
|
|
|
|
c_end = document.cookie.indexOf(";", c_start)
|
|
|
|
|
if (c_end == -1)
|
|
|
|
|
c_end = document.cookie.length
|
|
|
|
|
return decodeURIComponent(document.cookie.substring(c_start, c_end))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
},
|
|
|
|
|
clearCookie:function (name) {
|
|
|
|
|
this.setCookie(name, "", -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//字典组件
|
|
|
|
|
Vue.component('el-input-dict', {
|
|
|
|
|
data: function () {
|
|
|
|
|
return {
|
|
|
|
|
options: []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
value: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
dictName: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
size: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'small'
|
|
|
|
|
},
|
|
|
|
|
placeholder: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
input: function (value) {
|
|
|
|
|
this.$emit('input', value);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created: function () {
|
|
|
|
|
if (this.dictName) {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module("system")
|
|
|
|
|
.target("dict")
|
|
|
|
|
.method("load")
|
|
|
|
|
.data({dictName: this.dictName})
|
|
|
|
|
.post(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
console.error(response.errors[0].message)
|
|
|
|
|
} else {
|
|
|
|
|
this.options = response.dictItems;
|
|
|
|
|
}
|
|
|
|
|
}.bind(this))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
template: '' +
|
|
|
|
|
'<el-select :value="value" @input="input" filterable clearable placeholder="请选择" :size="size" :placeholder="placeholder">' +
|
|
|
|
|
' <el-option v-for="item in options" :key="item.key" :label="item.value" :value="item.key">' +
|
|
|
|
|
' <span style="float: left">{{ item.value }}</span>' +
|
|
|
|
|
' <span style="float: right; color: #8492a6; font-size: 12px">{{ item.key }}</span>' +
|
|
|
|
|
' </el-option>' +
|
|
|
|
|
'</el-select>'
|
|
|
|
|
});
|
|
|
|
|
//机构选择
|
|
|
|
|
Vue.component('el-input-dept', {
|
|
|
|
|
data: function () {
|
|
|
|
|
return {
|
|
|
|
|
options: [],
|
|
|
|
|
props:{
|
|
|
|
|
multiple: false,
|
|
|
|
|
checkStrictly: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
value: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
size: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'small'
|
|
|
|
|
},
|
|
|
|
|
clearable: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true
|
|
|
|
|
},
|
|
|
|
|
placeholder: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
input: function (value) {
|
|
|
|
|
this.$emit('input', value[value.length - 1]);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created: function () {
|
|
|
|
|
new Ajax()
|
|
|
|
|
.module("system")
|
|
|
|
|
.target("dept")
|
|
|
|
|
.method("tree")
|
|
|
|
|
.data({dictName: this.dictName})
|
|
|
|
|
.post(function (response) {
|
|
|
|
|
if (response.errors.length > 0) {
|
|
|
|
|
console.error(response.errors[0].message)
|
|
|
|
|
} else {
|
|
|
|
|
this.options = response.result;
|
|
|
|
|
}
|
|
|
|
|
}.bind(this))
|
|
|
|
|
},
|
|
|
|
|
template: '' +
|
|
|
|
|
'<el-cascader ' +
|
|
|
|
|
' :value="value" ' +
|
|
|
|
|
' @input="input" ' +
|
|
|
|
|
' :show-all-levels="false" ' +
|
|
|
|
|
' :options="options" ' +
|
|
|
|
|
' :clearable="clearable" ' +
|
|
|
|
|
' :size="size" ' +
|
|
|
|
|
' :props="props" ' +
|
|
|
|
|
' filterable ' +
|
|
|
|
|
' :placeholder="placeholder">' +
|
|
|
|
|
'</el-cascader>'
|
|
|
|
|
});
|
|
|
|
|
//下拉按钮
|
|
|
|
|
Vue.component('wb-dropdown', {
|
|
|
|
|
data: function () {
|
|
|
|
|
return {
|
|
|
|
|
items: []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
size: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'mini'
|
|
|
|
|
},
|
|
|
|
|
type: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'primary'
|
|
|
|
|
},
|
|
|
|
|
splitButton: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true
|
|
|
|
|
},
|
|
|
|
|
arg: {
|
|
|
|
|
type: Object | String | Number,
|
|
|
|
|
default: {}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
input: function (value) {
|
|
|
|
|
this.$emit('input', value[value.length - 1]);
|
|
|
|
|
},
|
|
|
|
|
onCommand: function (index) {
|
|
|
|
|
if (this.items[index].click) {
|
|
|
|
|
this.items[index].click(this.arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created: function () {
|
|
|
|
|
for (var i = 0; i < this.$slots.default.length; i++) {
|
|
|
|
|
var tag = this.$slots.default[i];
|
|
|
|
|
if (tag.tag === 'wb-dropdown-item') {
|
|
|
|
|
this.items.push({
|
|
|
|
|
value: tag.data.attrs ? tag.data.attrs['value'] : "",
|
|
|
|
|
icon: tag.data.attrs ? tag.data.attrs['icon'] : "",
|
|
|
|
|
click: tag.data.on ? tag.data.on['click'] : undefined
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
template: '' +
|
|
|
|
|
'<el-dropdown ' +
|
|
|
|
|
' :size="size" ' +
|
|
|
|
|
' :type="type" ' +
|
|
|
|
|
' :split-button="splitButton" ' +
|
|
|
|
|
' @click="onCommand(0)" ' +
|
|
|
|
|
' @command="onCommand"><i :class="items[0].icon"></i>{{items[0].value}}' +
|
|
|
|
|
' <el-dropdown-menu slot="dropdown">' +
|
|
|
|
|
' <el-dropdown-item v-for="(item,index) in items" :key="index" v-if="index != 0" :command="index" :icon="item.icon">' +
|
|
|
|
|
' {{item.value}}' +
|
|
|
|
|
' </el-dropdown-item>' +
|
|
|
|
|
' </el-dropdown-menu>' +
|
|
|
|
|
'</el-dropdown>'
|
|
|
|
|
});
|
|
|
|
|
</script>
|