var authComponent = { template:`
搜索
新增
批量授权
导出
取 消 确 定
取 消 确 定
`, data(){ exportconstvalidateContacts = (rule, value, callback) => { if(!value) { returncallback(new Error('请输入中文或者英文字母!')) } if(!/^[\u0391-\uFFE5A-Za-z_-]+$/.test(value)) { callback(new Error('请输入中文或者英文字母!')) } else { callback() } } // 获取当前屏幕的分辨率 let screenW = window.screen.width; let screenH = window.innerHeight; console.log("screen width:",screenW); console.log("screen height:",screenH); return { tHeight:screenH-202, tableData: [], multipleSelection: [], input:'', currentPage: 1, pagesize:50, recordTotal:0, form: { id:'', series: '', instrument_id:'', auth_date:'', expire_date: '', area_code:'', country:'', longitude:'', latitude:'', auth_count:'', auth_mark:'', authorizer:'', applicanter:'', note:'', change_series:false }, dialogVisible:false, oper_type:0, rules: { series: [ { required: true, message: '系列号不可为空', trigger: 'blur' } ], instrument_id: [ { required: true, message: '编码不可为空', trigger: 'blur' } ], expire_date: [ { required: true, message: '到期时间不可为空', trigger: 'blur' } ], authorizer: [ { required: true, message: '授权人不可为空', trigger: 'blur' } ] }, iid:'', tableData1:[], batch_auth_visible:false, } }, mounted() { var _this = this; var objs; axios.post('/deescloud/getAuth', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, methods: { tableRowClassName({row, rowIndex}) { var newDate = new Date(); var year=newDate.getFullYear(); var month=(newDate.getMonth()+1)<10?"0"+(newDate.getMonth()+1):newDate.getMonth()+1; var day=newDate.getDate()<10?"0"+newDate.getDate():newDate.getDate(); var hours=newDate.getHours()<10?"0"+newDate.getHours():newDate.getHours(); var minuts=newDate.getMinutes()<10?"0"+newDate.getMinutes():newDate.getMinutes(); var seconds=newDate.getSeconds()<10?"0"+newDate.getSeconds():newDate.getSeconds(); var tt = year+"-"+month+"-"+day+" "+hours+":"+minuts+":"+seconds //console.log(tt); if (month==12) { month=1 year=parseInt(year)+1 } else{ month=parseInt(month)+1 } if (month <10) { month='0'+month; } var t = year+"-"+month+"-"+day+" "+hours+":"+minuts+":"+seconds //console.log("t:",t); if (row.expire_date< t) { return 'warning-row'; } return ''; }, batchAuth(){ document.getElementById("bt_batch_auth").blur(); var selectdata = this.multipleSelection; if (selectdata.length == 0) { this.$message({ message: "请选择仪器!", type: "warning", duration: 1500 }); return; } console.log(selectdata); /*this.$data.tableData1=[]; for (var i = 0; i < selectdata.length; i++) { this.$data.tableData1.push(selectdata[i]); }*/ var newDate = new Date(); var year=newDate.getFullYear()+1; var month=(newDate.getMonth()+1)<10?"0"+(newDate.getMonth()+1):newDate.getMonth()+1; var day=newDate.getDate()<10?"0"+newDate.getDate():newDate.getDate(); var hours=newDate.getHours()<10?"0"+newDate.getHours():newDate.getHours(); var minuts=newDate.getMinutes()<10?"0"+newDate.getMinutes():newDate.getMinutes(); var seconds=newDate.getSeconds()<10?"0"+newDate.getSeconds():newDate.getSeconds(); this.$data.form = { id:'', series: '', instrument_id:'', auth_date:'', expire_date: year+"-"+month+"-"+day+" "+hours+":"+minuts+":"+seconds, area_code:'', country:'', longitude:'', latitude:'', auth_count:'', auth_mark:'', authorizer:localStorage.getItem("online_user"), change_series:false, applicanter:'', note:'', }; this.$nextTick(() => { this.$refs['batchAuthform'].clearValidate() }); this.$data.batch_auth_visible = true; }, batchAuth1(){ this.$refs['batchAuthform'].validate((valid) => { if (valid) { //document.getElementById("bt_batch_auth_ok").blur(); var _this = this; var selectdata = this.multipleSelection; this.$data.batch_auth_visible = false; var req = new Array(); for (var i = 0; i < selectdata.length; i++) { req[i] = {series:selectdata[i].series,instrument_id:selectdata[i].instrument_id,auth_count:selectdata[i].auth_count}; } var jreq = JSON.stringify(req); console.log(jreq); axios.post('deescloud/batchAuth',{ opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), authorizer:this.$data.form.authorizer, expire_date:this.$data.form.expire_date, auth_data:req, applicanter:this.$data.form.applicanter, note:this.$data.form.note, }) .then(function (response) { console.log(response.data); let r = response.data.r; let s = "" let errType = "" if (r == 0) { s = "批量授权成功!"; errType = "success" for (var i = 0; i < selectdata.length; i++) { let cnt = parseInt(selectdata[i].auth_count)+1 selectdata[i].auth_count = cnt.toString(); } } else{ s = "批量授权失败!"; errType = "error" } _this.getAuthinfo(_this.$data.input); _this.$message({ message: s, type: errType, duration: 1500 }); }) .catch(function (error) { console.log(error); }); } }); }, exportAuthPos(){ document.getElementById("bt_export1").blur(); /*var selectdata = this.multipleSelection; if (selectdata.length == 0) { this.$message({ message: "请选择导出仪器!", type: "warning", duration: 1500 }); return; } console.log(selectdata); var req = new Array(); for (var i = 0; i < selectdata.length; i++) { //console.log(selectdata[i]); req[i] = {series:selectdata[i].series,instrument_id:selectdata[i].instrument_id}; } var jreq = JSON.stringify(req); console.log(jreq);*/ axios.post('deescloud/getAuthorizePosCsv') .then(function (response) { console.log(response.data); var fileid = response.data.fileId; var downUrl = 'file/'+fileid; downloadUrl("仪器经纬度使用统计.csv",downUrl); }) .catch(function (error) { console.log(error); }); }, exportAuth(){ document.getElementById("bt_export").blur(); var selectdata = this.multipleSelection; if (selectdata.length == 0) { this.$message({ message: "请选择导出仪器!", type: "warning", duration: 1500 }); return; } console.log(selectdata); var req = new Array(); for (var i = 0; i < selectdata.length; i++) { //console.log(selectdata[i]); req[i] = {series:selectdata[i].series,instrument_id:selectdata[i].instrument_id}; } var jreq = JSON.stringify(req); console.log(jreq); axios.post('deescloud/getDeesAuthDb',jreq) .then(function (response) { console.log(response.data); var fileid = response.data.fileId; //console.log(data) //downloadUrl("auth.db",'deescloud/getDeesAuthDb?id=123') var downUrl = 'file/'+fileid + '.auf'; downloadUrl("auth.auf",downUrl); }) .catch(function (error) { console.log(error); }); }, handleSelectionChange(val) { this.multipleSelection = val; }, postAuth(){ this.$refs['authform'].validate((valid) => { if (valid) { /*if (this.$data.form.series =='' || this.$data.form.instrument_id == '' || this.$data.form.expire_date == '' || this.$data.form.authorizer == '') { this.$alert('仪器系列号、编码、授权到期时间、授权人不能为空!', '提示', { confirmButtonText: '确定', callback: action => { }, lockScroll:false }); return; }*/ this.$data.dialogVisible = false; console.log(this.$data.form); var _this = this; axios.post('/deescloud/postAuth', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), oper_type: _this.$data.oper_type, id:_this.$data.form.id, series: _this.$data.form.series, instrument_id:_this.$data.form.instrument_id, auth_date:_this.$data.form.auth_date, expire_date: _this.$data.form.expire_date, area_code: _this.$data.form.area_code, country:_this.$data.form.country, longitude:_this.$data.form.longitude, latitude:_this.$data.form.latitude, auth_count:_this.$data.form.auth_count, auth_mark:_this.$data.form.auth_mark, authorizer:_this.$data.form.authorizer, applicanter:_this.$data.form.applicanter, note:_this.$data.form.note, }) .then(function (response) { let r = response.data.r; let s = "" let errType = "" if (r == 0) { errType = "success" } else{ errType = "error" } if (_this.$data.oper_type == 1) { if (r ==0) { s = "新增授权信息成功!"; } else if (r ==1) { s = "已存在相同的仪器系列号和编码!"; }else{ s = "新增授权信息失败!"; } } else if (_this.$data.oper_type ==2){ if (r ==0) { s = "修改授权信息成功!"; } else if (r ==1){ s = "已存在相同的仪器系列号和编码!"; } else{ s = "修改授权信息失败!"; } } _this.$message({ message: s, type: errType, duration: 1500 }); //更新页面 if (_this.$data.oper_type == 1) { _this.getAuthinfo(""); }else{ _this.getAuthinfo(_this.$data.input); } }) .catch(function (error) { console.log(error); }); } }); }, delAuth(authinfo){ this.$data.oper_type = 3; var mul_cache = []; for (var i = 0; i < this.multipleSelection.length; i++) { if (this.multipleSelection[i].series == authinfo.series && this.multipleSelection[i].instrument_id == authinfo.instrument_id) { }else{ mul_cache.push(this.multipleSelection[i]); } } this.multipleSelection = mul_cache; var _this = this; var objs; axios.post('/deescloud/postAuth', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), id: authinfo.id, oper_type: _this.$data.oper_type, series: authinfo.series, instrument_id:authinfo.instrument_id, auth_date:authinfo.auth_date, expire_date: authinfo.expire_date, area_code: authinfo.area_code, country:authinfo.country, longitude:authinfo.longitude, latitude:authinfo.latitude, auth_count:authinfo.auth_count, auth_mark:authinfo.auth_mark, authorizer:authinfo.authorizer }) .then(function (response) { let r = response.data.r; let s = "" let errType = "" if (r == 0) { s = "删除授权信息成功!"; errType = "success" } else{ s = "删除授权信息失败!"; errType = "error" } _this.$message({ message: s, type: errType, duration: 1500 }); if (r ==0) { _this.getAuthinfo("");//更新页面 } }) .catch(function (error) { console.log(error); }); }, addAuth(){ document.getElementById("bt_add").blur(); var newDate = new Date(); var year=newDate.getFullYear()+1; var month=(newDate.getMonth()+1)<10?"0"+(newDate.getMonth()+1):newDate.getMonth()+1; var day=newDate.getDate()<10?"0"+newDate.getDate():newDate.getDate(); var hours=newDate.getHours()<10?"0"+newDate.getHours():newDate.getHours(); var minuts=newDate.getMinutes()<10?"0"+newDate.getMinutes():newDate.getMinutes(); var seconds=newDate.getSeconds()<10?"0"+newDate.getSeconds():newDate.getSeconds(); var t = year+"-"+month+"-"+day+" "+hours+":"+minuts+":"+seconds; console.log(t); this.$data.oper_type = 1; this.$data.form = { id:'', series: '', instrument_id:'', auth_date:'', expire_date: t, area_code:'', country:'', longitude:'', latitude:'', auth_count:'', auth_mark:'', authorizer:localStorage.getItem("online_user"), applicanter:'', note:'', change_series:false }; console.log(this.$data.form); this.$nextTick(() => { this.$refs['authform'].clearValidate() }); this.$data.dialogVisible = true; }, updateAuth(authinfo){ this.$data.oper_type = 2; this.$data.form = { id:authinfo.id, series: authinfo.series, instrument_id:authinfo.instrument_id, auth_date:authinfo.auth_date, expire_date: authinfo.expire_date, area_code: authinfo.area_code, country:authinfo.country, longitude:authinfo.longitude, latitude:authinfo.latitude, auth_count:authinfo.auth_count, auth_mark:authinfo.auth_mark, //authorizer:authinfo.authorizer, authorizer:localStorage.getItem("online_user"), applicanter:authinfo.applicanter, note:authinfo.note, change_series:true }; this.$nextTick(() => { this.$refs['authform'].clearValidate() }); this.$data.dialogVisible = true; }, getAuthinfo(_search_name){ document.getElementById("bt_search").blur(); /*if (_search_name == '') { this.$refs.multipleTable.clearSelection(); }*/ this.$data.currentPage=1; var _this = this; var objs; axios.post('/deescloud/getAuth', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), id: _search_name, iid:_this.$data.iid, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, handleSizeChange(val) { this.$data.pagesize = val; var _this = this; var objs; axios.post('/deescloud/getAuth', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), id: this.$data.input, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, handleCurrentChange(val) { this.$data.currentPage = val; var _this = this; var objs; axios.post('/deescloud/getAuth', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), id: this.$data.input, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, flexColumnWidth(str, tableData, flag = 'max') { // str为该列的字段名(传字符串);tableData为该表格的数据源(传变量); // flag为可选值,可不传该参数,传参时可选'max'或'equal',默认为'max' // flag为'max'则设置列宽适配该列中最长的内容,flag为'equal'则设置列宽适配该列中第一行内容的长度。 let maxContext = new Array(); str = str + '' let columnContent = '' if (!tableData || !tableData.length || tableData.length === 0 || tableData === undefined) { return '120px' } if (!str || !str.length || str.length === 0 || str === undefined) { return '120px' } if (flag === 'equal') { // 获取该列中第一个不为空的数据(内容) for (let i = 0; i < tableData.length; i++) { if (tableData[i][str].length > 0) { // console.log('该列数据[0]:', tableData[0][str]) columnContent = tableData[i][str] break } } } else { // 获取该列中最长的数据(内容) let index = 0 for (let i = 0; i < tableData.length; i++) { if (tableData[i][str] === null) { return } const now_temp = tableData[i][str] + '' const max_temp = tableData[index][str] + '' if (now_temp.length >= max_temp.length) { index = i } } columnContent = tableData[index][str] maxContext.push(columnContent); } // console.log('该列数据[i]:', columnContent) // 以下分配的单位长度可根据实际需求进行调整 //console.log(columnContent); let max_flex_width = 0 for (let i = 0; i < maxContext.length; i++) { let flexWidth = 0; for (const char of maxContext[i]) { if ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z')) { // 如果是英文字符,为字符分配8个单位宽度 flexWidth += 8 } else if (char >= '\u4e00' && char <= '\u9fa5') { // 如果是中文字符,为字符分配15个单位宽度 flexWidth += 15 } else { // 其他种类字符,为字符分配8个单位宽度 flexWidth += 8 } } if (flexWidth>max_flex_width) { max_flex_width = flexWidth; console.log(maxContext[i]); } } if (max_flex_width < 80) { // 设置最小宽度 max_flex_width = 80 } if (max_flex_width > 300) { // 设置最大宽度 max_flex_width = 300 } //flexWidth = flexWidth;//20-padding console.log("max_flex_width:",max_flex_width); return max_flex_width + 'px' }, } }