import StringUtil from './StringUtil' export var byUtils = { setUser(user) { if (user === null) { sessionStorage.setItem('user', null) } else { sessionStorage.setItem('user', JSON.stringify(user)) } }, getUser() { let userStr = sessionStorage.getItem('user') if (StringUtil.isNullOrEmpty(userStr)) { return null } else { return JSON.parse(userStr) } }, /* 设置页面table高度 */ initTableMaxHeight(vm){ //let toolBarHeight = document.querySelector('.toolCard').offsetHeight; let maxHeight = document.body.offsetHeight; //console.log("toolBarHeight:"+toolBarHeight) //console.log("maxHeight:"+maxHeight) vm.pageData.maxHeight = parseInt(maxHeight)-224; }, initTableMaxHeight2(vm){ //let toolBarHeight = document.querySelector('.toolCard').offsetHeight; let maxHeight = document.body.offsetHeight; //console.log("toolBarHeight:"+toolBarHeight) //console.log("maxHeight:"+maxHeight) vm.pageConfig.maxHeight = parseInt(maxHeight)-360; }, initTableMaxHeight3(vm){ //let toolBarHeight = document.querySelector('.toolCard').offsetHeight; let maxHeight = document.body.offsetHeight; //console.log("toolBarHeight:"+toolBarHeight) //console.log("maxHeight:"+maxHeight) vm.pageConfig.maxHeight = parseInt(maxHeight)-91; }, /* 默认页面数据 */ defaultPageData() { return { rows: [], isLoading: false, loadingText: '加载中...', total: 0, page: 1, pageSize: 10, multipleSelection: [], signSelection:null } }, defaultPageData2() { return { rows: [], isLoading: false, loadingText: '加载中...', total: 0, SkipCount: 1, MaxResultCount: 10, multipleSelection: [], signSelection:null } }, getData(vm,url,data,success) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: data.message, type: 'success'}); try { vm.showDialog(false); } catch (e) { console.log(e) } try { vm.loadData(); } catch (e) { console.log(e) } } if (success) { callBackFunction = success; } var token = ""; if(this.getUser()){ token = this.getUser().token; } vm.$loading(); vm.$axios({ headers: { 'token': token }, withCredentials: false, url: url, method: 'get', params: data }).then((response) => { vm.$loading().close(); let data = response.data; if (data && data.code==0) { callBackFunction(data); } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ let a = ''; if(response.data){ if(response.data.msg){ a=response.data.msg }else { a='服务器故障' } }else { a="数据错误" } vm.$alert(a , {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.$loading().close(); vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, /** * 获取远程数据 * @param vm vue对象,一般传this * @param url,请求数据的url * @param data 数据参数 */ loadPageData(vm, url, data) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '消息', 'type': 'warning', 'center': true, 'showClose': false}); vm.pageData.isLoading = false; return; } if (null === data) { data = {}; } data.current = vm.pageData.page; data.size = vm.pageData.pageSize; vm.pageData.isLoading = true; vm.$axios({ url: url, // headers: { // 'token': this.getUser().token // }, method: 'post', data: data }).then((response) => { vm.pageData.isLoading = false; let data = response.data; if (data && data.code==0) { let page = data.data; vm.pageData.rows = page.records; vm.pageData.total = page.total; } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('操作出现错误', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.pageData.isLoading = false; vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, /** * 获取远程数据 * @param vm vue对象,一般传this * @param url,请求数据的url * @param data 数据参数 */ loadPageData2(vm, url, data) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '消息', 'type': 'warning', 'center': true, 'showClose': false}); vm.pageData.isLoading = false; return; } if (null === data) { data = {}; } data.current = vm.pageData.page; data.size = vm.pageData.pageSize; vm.pageData.isLoading = true; vm.$axios({ url: url, headers: { 'token': this.getUser().token }, withCredentials: false, method: 'post', data: data }).then((response) => { vm.pageData.isLoading = false; let data = response.data; if (data && data.code==0) { let page = data.data; vm.pageData.rows = page.records; vm.pageData.total = page.total; } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('操作出现错误', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.pageData.isLoading = false; vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, /** * 提交数据方法 * @param vm vue实例,一般传this * @param url 提交地址 * @param data 传递的数据 * @param successCallBackFunction 操作成功执行的方法 */ postData(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: data.message, type: 'success'}); try { vm.showDialog(false); } catch (e) { } try { vm.loadData(); } catch (e) { } } if (successCallBackFunction) { callBackFunction = successCallBackFunction; } // var token = ""; // if(this.getUser()){ // token = this.getUser().token; // } // vm.$loading(); vm.$axios({ // headers: { // 'token': token // }, withCredentials: false, url: url, method: 'post', data: data }).then((response) => { //vm.$loading().close(); let data = response.data; console.log(response) if (data && data.code==0) { callBackFunction(data); } else if(data.code==1) { callBackFunction(data); }else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ let a = ''; if(response.data){ if(response.data.msg){ a=response.data.msg }else { a='服务器故障' } }else { a="数据错误" } vm.$alert(a , {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { //vm.$loading().close(); vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, exportData(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: data.message, type: 'success'}); try { vm.showDialog(false); } catch (e) { } try { vm.loadData(); } catch (e) { } } if (successCallBackFunction) { callBackFunction = successCallBackFunction; } // var token = ""; // if(this.getUser()){ // token = this.getUser().token; // } // vm.$loading(); vm.$axios({ // headers: { // 'Content-Type': "application/json;charset=UTF-8" // }, withCredentials: false, responseType: "blob", url: url, method: 'post', data: data }).then((response) => { //vm.$loading().close(); let data = response.data; console.log(response,'response'); if (data) { callBackFunction(data); } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ let a = ''; if(response.data){ if(response.data.msg){ a=response.data.msg }else { a='服务器故障' } }else { a="数据错误" } vm.$alert(a , {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { //vm.$loading().close(); vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, postData4(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { //vm.$message({message: data.message, type: 'success'}); } console.log('successCallBackFunction---',successCallBackFunction) if (successCallBackFunction) { callBackFunction = successCallBackFunction; } vm.$axios({ withCredentials: false, url: url, method: 'post', data: data }).then((response) => { let data = response.data; if (data && data.code==0) { callBackFunction(data); } else { vm.$alert('操作失败:' + data.message, {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } }).catch((e) => { vm.$loading().close(); vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, /** * 删除数据方法 * @param vm vue实例,一般传this * @param url 删除地址 * @param data 传递的数据 * @param loadDataFunction 删除成功执行的方法 */ deleteData(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } if (null == data) { vm.$alert('请求参数不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: '删除成功', type: 'success'}); vm.loadData(); } if (successCallBackFunction) { callBackFunction = successCallBackFunction; } vm.$confirm('确定要删除吗,删除后不可恢复?', '提示', { type: 'warning' }).then(() => { vm.$loading(); vm.$axios({ withCredentials: false, url: url, method: 'post', data: data }).then((response) => { vm.$loading().close(); let data = response.data; if (data && data.code == 0) { callBackFunction(data); } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('删除操作失败:' + data.message, {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.$loading().close(); vm.$alert('删除出现错误:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false}); }) }).catch(() => { // 删除时点击取消不操作 }) }, /** * 停用数据方法 * @param vm vue实例,一般传this * @param url 停用地址 * @param data 传递的数据 * @param loadDataFunction 启用成功执行的方法 */ stopData(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } if (null == data) { vm.$alert('请求参数不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: data.message, type: 'success'}); vm.loadData(); } if (successCallBackFunction) { callBackFunction = successCallBackFunction; } vm.$confirm('确定要停用吗?', '提示', { type: 'warning' }).then(() => { vm.$loading(); vm.$axios({ headers: { 'token': this.getUser().token }, url: url, method: 'post', data: data }).then((response) => { vm.$loading().close(); let data = response.data; if (data && data.code==0) { callBackFunction(data); } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('停用操作失败:' + data.message, {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.$loading().close(); vm.$alert('停用出现错误:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false}); }) }).catch(() => { // 删除时点击取消不操作 }) }, /** * 启用数据方法 * @param vm vue实例,一般传this * @param url 启用地址 * @param data 传递的数据 * @param loadDataFunction 启用成功执行的方法 */ startData(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } if (null == data) { vm.$alert('请求参数不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: data.message, type: 'success'}); vm.loadData(); } if (successCallBackFunction) { callBackFunction = successCallBackFunction; } vm.$confirm('确定要启用吗?', '提示', { type: 'warning' }).then(() => { vm.$loading(); vm.$axios({ headers: { 'token': this.getUser().token }, url: url, method: 'post', data: data }).then((response) => { vm.$loading().close(); let data = response.data; if (data && data.code==0) { callBackFunction(data); } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('启用操作失败:' + data.message, {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.$loading().close(); vm.$alert('启用出现错误:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false}); }) }).catch(() => { // 删除时点击取消不操作 }) }, /** * 解绑数据方法 * @param vm vue实例,一般传this * @param url 启用地址 * @param data 传递的数据 * @param loadDataFunction 启用成功执行的方法 */ unboundData(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } if (null == data) { vm.$alert('请求参数不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: data.message, type: 'success'}); vm.loadData(); } if (successCallBackFunction) { callBackFunction = successCallBackFunction; } vm.$confirm('确定要解绑吗?', '提示', { type: 'warning' }).then(() => { vm.$loading(); vm.$axios({ headers: { 'token': this.getUser().token }, url: url, method: 'post', data: data }).then((response) => { vm.$loading().close(); let data = response.data; if (data && data.code==0) { callBackFunction(data); } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('解绑操作失败:' + data.message, {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.$loading().close(); vm.$alert('解绑出现错误:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false}); }) }).catch(() => { // 删除时点击取消不操作 }) }, getPageData(vm, url, data) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '消息', 'type': 'warning', 'center': true, 'showClose': false}); vm.pageData.isLoading = false; return; } if (null === data) { data = {}; } data.SkipCount = (vm.pageData.SkipCount-1)*10; data.MaxResultCount = vm.pageData.MaxResultCount; vm.pageData.isLoading = true; vm.$axios({ url: url, method: 'get', params: data }).then((response) => { vm.pageData.isLoading = false; let data = response.data; if (data && data.code==0) { let page = data.data; vm.pageData.rows = page.records; vm.pageData.total = page.total; vm.pageData.SkipCount = 1; } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('操作出现错误', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.pageData.isLoading = false; vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, getPageData3(vm, url, data) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '消息', 'type': 'warning', 'center': true, 'showClose': false}); vm.pageData.isLoading = false; return; } if (null === data) { data = {}; } data.SkipCount = (vm.pageData.SkipCount-1)*10; data.MaxResultCount = vm.pageData.MaxResultCount; vm.pageData.isLoading = true; vm.$axios({ url: url, method: 'get', params: data }).then((response) => { vm.pageData.isLoading = false; let data = response.data; if (data && data.code==0) { let page = data.result; vm.pageData.rows = page.items; vm.pageData.total = page.totalCount; //vm.pageData.SkipCount = 1; } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('操作出现错误', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.pageData.isLoading = false; vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, getPageData2(vm, url, data) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '消息', 'type': 'warning', 'center': true, 'showClose': false}); vm.pageData.isLoading = false; return; } if (null === data) { data = {}; } vm.pageData.isLoading = true; vm.$axios({ url: url, method: 'get', params: data }).then((response) => { vm.pageData.isLoading = false; vm.pageData.rows = response.data; }).catch((e) => { vm.pageData.isLoading = false; vm.$alert('出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, deleteData2(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } if (null == data) { vm.$alert('请求参数不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: data.message, type: 'success'}); vm.getData(); } if (successCallBackFunction) { callBackFunction = successCallBackFunction; } vm.$confirm('确定要删除吗,删除后不可恢复?', '提示', { type: 'warning' }).then(() => { vm.$axios({ url: url, method: 'post', data: data }).then((response) => { let data = response.data; if (data && data.success) { callBackFunction(data); } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('删除操作失败:' + data.message, {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.$alert('删除出现错误:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false}); }) }).catch(() => { // 删除时点击取消不操作 }) }, getRequest(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('请求地址不能为空', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); return; } let callBackFunction = function (data) { vm.$message({message: data.message, type: 'success'}); try { vm.showDialog(false); } catch (e) { } try { vm.loadData(); } catch (e) { } } if (successCallBackFunction) { callBackFunction = successCallBackFunction; } vm.$loading(); vm.$axios({ withCredentials: false, url: url, method: 'get', params: data }).then((response) => { vm.$loading().close(); let data = response.data; if (data && data.code==0) { callBackFunction(data); } else { if(data.message=='-9999'){ vm.$router.push({'path': '/login'}); vm.$alert('会话结束,请重新登录', {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); }else{ vm.$alert('操作失败:' + data.message, {'title': '提示', 'type': 'warning', 'center': true, 'showClose': false}); } } }).catch((e) => { vm.$loading().close(); vm.$alert('操作出现异常:' + e, {'title': '错误', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { // byUtils.setUser(null); // vm.$router.push({'path': '/login'}); }}); }) }, dateFormat(date,f) { let format = 'yyyy-MM-dd hh:mm:ss' if(f){ format = f; } if (date !== 'Invalid Date') { var o = { 'M+': date.getMonth() + 1, // month 'd+': date.getDate(), // day 'h+': date.getHours(), // hour 'm+': date.getMinutes(), // minute 's+': date.getSeconds(), // second 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter 'S': date.getMilliseconds() // millisecond } if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) } for (var k in o) { if (new RegExp('(' + k + ')').test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)) } } return format } return '' }, }