From 75c2aefbf5b899a39a0d42af8425da65d96a71a7 Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Tue, 29 Jun 2021 09:40:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E3=80=81=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.js | 25 +++-- src/layouts/navbar/index.vue | 13 +-- src/libs/util.js | 12 +- src/pages/data/list/index.vue | 156 +++++++++++++++++--------- src/pages/index/list/index.vue | 64 +++++------ src/pages/role/list/index.vue | 105 +++++++---------- src/pages/setting/person/download.vue | 58 +++++----- src/plugins/requests/index.js | 28 ++--- src/setting.js | 2 +- 9 files changed, 250 insertions(+), 213 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index e57bed7..533298f 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -48,18 +48,27 @@ export default { queryAccountStaff:`evaluation/tms/system/queryAccount`, resetPwd:`evaluation/tms/system/resetPwd`, - // 角色权限 - rolePermissionList:`evaluation/sys-permission/rolePermissionList`, - saveRolePermission:`evaluation/sys-permission/saveRolePermission`, - updateRolePermission:`evaluation/sys-permission/updateRolePermission`, - delRolePermission:`evaluation/sys-permission/delRolePermission`, - queryPermissionArrById:`evaluation/sys-permission/queryPermissionArrById`, - roleTree:`evaluation/sys-permission/tree`, + // 角色管理 + batchRemove:`/data/data/role/batchRemove`, + getRole:`/data/data/role/get`, + getName:`/data/data/role/getName`, + listRole:`/data/data/role/list`, + removeRole:`/data/data/role/remove`, + saveOrUpdate:`/data/data/role/saveOrUpdate`, + + // 权限菜单管理 + doAssign:`/data/data/permission/doAssign`, + queryPermissionMenu:`/data/data/permission/queryPermissionMenu`, + savePer:`/data/data/permission/save`, + toAssign:`/data/data/permission/toAssign`, // 表展示 getIdQueryTable:`/data/huoran/data/table/getIdQueryTable`, getTableByClassification:`/data/huoran/data/table/getTableByClassification`, getTableByCondition:`/data/huoran/data/table/getTableByCondition`, - downloadData:`/data/data/download`, + downloadData:`${host1}/data/data/download`, previewData:`${host1}/data/data/preview`, + downloadRecord:`${host1}/data/huoran/data/myDownload/downloadRecord`, + getDownloadRecord:`${host1}/data/huoran/data/myDownload/getDownloadRecord`, + downloadAgain:`${host1}/data/data/downloadAgain`, } \ No newline at end of file diff --git a/src/layouts/navbar/index.vue b/src/layouts/navbar/index.vue index 31044e7..32dd02b 100644 --- a/src/layouts/navbar/index.vue +++ b/src/layouts/navbar/index.vue @@ -41,17 +41,14 @@ export default { } }; }, - computed: { - onRoutes() { + watch: { + '$route'(to,from) { let actives = this.actives for(let i in this.actives){ - if(actives[i].includes(this.$route.name)) return `/${i}/list` + if(actives[i].includes(this.$route.name)) this.active = `/${i}/list` } - return this.$route.path - }, - ...mapState('auth', [ - 'routes' - ]) + this.active = this.$route.path + } }, created() { this.initMenu() diff --git a/src/libs/util.js b/src/libs/util.js index 90d034c..88fc3b6 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -105,16 +105,16 @@ const util = { x.send() }, // 成功提示 - successMsg(message) { - Message.success({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration: 3000}) + successMsg(message,duration = 3000) { + Message.success({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration}) }, // 警告提示 - warningMsg(message) { - Message.warning({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration: 3000}) + warningMsg(message,duration = 3000) { + Message.warning({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration}) }, // 错误提示 - errorMsg(message) { - Message.error({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration: 3000}) + errorMsg(message,duration = 3000) { + Message.error({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration}) }, } diff --git a/src/pages/data/list/index.vue b/src/pages/data/list/index.vue index e52e8ec..a5b2f38 100644 --- a/src/pages/data/list/index.vue +++ b/src/pages/data/list/index.vue @@ -71,7 +71,7 @@
数据介绍
{{introduce}}
- + @@ -94,11 +94,8 @@ - + - @@ -106,8 +103,9 @@
+ 全选 - +
@@ -151,8 +149,10 @@ export default { pageSizePreview: 10, totalPreview: 0, downloadVisible: false, - tableName: '', + curRow: {}, + checkAllFields: false, fields: [], + fieldsList: [], startTime: '', endTime: '', frequency: '', @@ -174,19 +174,15 @@ export default { name: '年频' }, ], - fieldList: [ - { - id: 1, - name: '代码' - },{ - id: 2, - name: '名称' - } - ], } }, mounted() { this.getType() + if(this.$route.query.download){ + this.download({ + name: this.$route.query.name + }) + } }, methods: { getType(){ @@ -194,7 +190,10 @@ export default { res.map(n => { n.id = String(n.id) n.children.map(n => { - n.id = String(n.id) + n.id = String(n.id) + n.children.map(n => { + n.id = String(n.id) + }) }) }) this.typeList = res @@ -208,20 +207,7 @@ export default { }).catch(res => {}) }, getData(){ - let data = { - endTime: '', - fields: [], - frequency: '', - startTime: '', - tableName: '', - } - // util.successMsg('数据正在生成中,请稍等。') - // location.href = 'http://192.168.31.125:8888/data/data/download?endTime=&frequency=&startTime=&tableName=' - // this.$get(this.api.download,data).then(res => { - - // }).catch(res => {}) - - this.$post(`${this.api.getIdQueryTable}?categoryId=${this.active}&showName=&pageNum=${this.page}&pageSize=${this.pageSize}`).then(res => { + this.$post(`${this.api.getIdQueryTable}?categoryId=${this.active}&showName=&pageNum=${this.page}&pageSize=${this.pageSize}&updateTime=`).then(res => { this.listData = res.list this.total = res.totalCount }).catch(res => {}) @@ -236,40 +222,50 @@ export default { this.introduce = this.typeList.find(n => n.id == indexPath[0]).introduce this.previewHead = [] this.previewData = [] - this.getData() - }, - handlePreviewCurrentChange(val) { - this.pagePreview = val - this.$refs.table.clearSelection() + this.page = 1 this.getData() }, preview(row){ - this.$get(`${this.api.previewData}?tableName=${row.name}`).then(res => { + this.$get(`${this.api.previewData}?tableName=${row.name}&tableId=${row.id}`).then(res => { let comment = res.comment let previewHead = [] comment.map(n => { n.field != 'id' && n.field != 'operation_time' && previewHead.push(n) }) this.previewHead = previewHead - this.previewData = res.data + + let data = res.data + data.map(n => { + for(let i in n){ + if(typeof n[i] == 'string' && n[i].endsWith('+0000')) n[i] = util.formatDate('yyyy-MM-dd hh:mm:ss',new Date(n[i])) + } + }) + this.previewData = data }).catch(res => {}) }, + checkAllFieldsChange(val) { + this.fields = val ? this.fieldsList.map(n => n.comment) : [] + }, download(row){ - this.tableName = row.name + this.curRow = row this.downloadVisible = true - this.$get(`${this.api.previewData}?tableName=${row.name}`).then(res => { + + this.$get(`${this.api.previewData}?tableName=${row.name}&tableId=${row.id}`).then(res => { let comment = res.comment - let previewHead = [] + let fieldsList = [] comment.map(n => { - n.field != 'id' && n.field != 'operation_time' && previewHead.push(n) + n.field != 'id' && n.field != 'operation_time' && fieldsList.push(n) }) - this.previewHead = previewHead - - + this.fieldsList = fieldsList }).catch(res => {}) }, closeDownload(){ - + this.checkAllFields = false + this.fields = [] + this.startTime = '' + this.endTime = '' + this.frequency = '' + this.$router.push('/data') }, handleOpen(){ @@ -278,17 +274,72 @@ export default { }, confirmDown(){ - // return console.log(this.startTime,this.endTime) let fields = this.fields + if(!fields.length) return util.warningMsg('请选择字段') + if(!this.frequency) return util.warningMsg('请选择数据频率') + let invalid = false + if(this.startTime && this.endTime){ + let startTime = new Date(this.startTime) + let endTime = new Date(this.endTime) + let frequency = this.frequency + + if(frequency == 2){ + let week = [] + while(startTime <= endTime){ + let weekNum = startTime.getDay() + if(weekNum == 0) weekNum = 7 + week.push(weekNum) + startTime.setTime(startTime.getTime() + 86400000) + } + for(let i = 1;i <= 5;i++){ + if(!week.includes(i)){ + invalid = true + break + } + } + }else if(frequency == 3){ + if((endTime.getTime() - startTime.getTime()) / 86400000 < 30) invalid = true + }else if(frequency == 4){ + if((endTime.getTime() - startTime.getTime()) / 86400000 < 90) invalid = true + }else if(frequency == 5){ + if((endTime.getTime() - startTime.getTime()) / 86400000 < 365) invalid = true + } + } + + if(invalid) return util.warningMsg('请选择完整区间') + let newFields = [] - let previewHead = this.previewHead + let fieldsList = this.fieldsList fields.map(n => { - newFields.push(`fields=${previewHead.find(e => e.comment == n).field}`) + newFields.push(`fields=${fieldsList.find(e => e.comment == n).field}`) }) - // return console.log(this.fields,newFields) - this.$get(`${this.api.downloadData}?tableName=${this.tableName}&${newFields.join('&')}&startTime=${this.startTime}&endTime=${this.endTime}&frequency=${this.frequency}`).then(res => { + util.successMsg('数据正在生成中,请稍等片刻,生成后会自动下载,您可以先访问其他页面。',5000) + this.downloadVisible = false - }).catch(res => {}) + let startTime = this.startTime ? this.startTime : '' + let endTime = this.endTime ? this.endTime : '' + let frequency = this.frequency + axios.get(`${this.api.downloadData}?tableName=${this.curRow.name}&${newFields.join('&')}&startTime=${startTime}&endTime=${endTime}&frequency=${frequency}`,{ + responseType: 'blob' + }).then((res) => { + console.log(22,res.data) + const blob = new Blob([res.data]) + const fileName = `${this.curRow.showName}.xls` + if ('download' in document.createElement('a')) { // 非IE下载 + const elink = document.createElement('a') + elink.download = fileName + elink.style.display = 'none' + elink.href = URL.createObjectURL(blob) + document.body.appendChild(elink) + elink.click() + URL.revokeObjectURL(elink.href) // 释放URL 对象 + document.body.removeChild(elink) + } else { // IE10+下载 + navigator.msSaveBlob(blob, fileName) + } + + this.$get(`${this.api.downloadRecord}?platformUserId=4&tableId=${this.curRow.id}&${newFields.join('&')}&startTime=${startTime}&endTime=${endTime}&frequency=${frequency}`).then(res => {}).catch(res => {}) + }) } } }; @@ -313,6 +364,7 @@ export default { } .right{ flex: 1; + max-width: calc(100% - 220px); .block{ padding: 34px; margin-bottom: 20px; diff --git a/src/pages/index/list/index.vue b/src/pages/index/list/index.vue index 5030377..05c8a13 100644 --- a/src/pages/index/list/index.vue +++ b/src/pages/index/list/index.vue @@ -1,37 +1,37 @@ @@ -57,7 +57,7 @@ export default { } }, mounted() { - this.initData() + }, methods: { getData(){ @@ -76,7 +76,7 @@ export default { this.getData() }, download(row){ - + this.$router.push(`/data?download=true&name=${row.name}`) } } }; diff --git a/src/pages/role/list/index.vue b/src/pages/role/list/index.vue index 6c54beb..2ccac1e 100644 --- a/src/pages/role/list/index.vue +++ b/src/pages/role/list/index.vue @@ -15,7 +15,7 @@ - + @@ -51,15 +51,7 @@
- - +
@@ -80,6 +72,7 @@ export default { name: 'role', data() { return { + clientId: 0, keyword: '', form: { roleName : '', @@ -87,7 +80,7 @@ export default { id: '' }, isDetail: false, - roleData:[], + listData:[], defaultProps: { children: 'children', label: 'name' @@ -106,7 +99,7 @@ export default { }, computed: { ...mapState('user', [ - 'userId','clientId' + 'userId' ]) }, watch: { @@ -128,14 +121,14 @@ export default { if(this.keyword.length){ data.name = this.keyword } - this.$get(`${this.api.queryRoles}/${this.page}/${this.pageSize}`,data).then(res => { - this.roleData = res.data.items - this.total = res.data.total - if(!this.roleData.length && this.total){ + this.$get(`${this.api.listRole}/${this.page}/${this.pageSize}?name=${this.keyword}&clientId=`).then(res => { + this.listData = res.items + this.total = res.total + if(!this.listData.length && this.total){ this.page-- this.getData() } - }).catch(res => {}); + }).catch(res => {}) }, initData(){ this.page = 1 @@ -159,7 +152,7 @@ export default { getPer(){ if(!this.permissions.length){ this.$get(this.api.queryPermissionMenu).then(res => { - this.permissions = res.data.children[0].children + this.permissions = res[0].children }).catch(res => {}) } }, @@ -184,15 +177,15 @@ export default { }, async getDetail(row){ this.getPer() - let roleRes = await this.$get(`${this.api.getRole}/${row.id}`) - if(roleRes.success){ - this.form = roleRes.data.item - let perRes = await this.$get(`${this.api.toAssign}/${row.id}`) - if(perRes.success){ - this.checkedIds = this.handleRolePer(perRes.data.rolePermissions,this.permissions) + this.$get(`${this.api.getRole}/${row.id}`).then(res => { + this.form = res + this.$get(this.api.toAssign,{ + roleId: row.id + }).then(res => { + this.checkedIds = this.handleRolePer(res,this.permissions) this.$refs.per.setCheckedNodes(this.checkedIds) - } - } + }).catch(res => {}) + }).catch(res => {}) }, showRole(row){ this.isDetail = true @@ -209,49 +202,41 @@ export default { if(!this.form.roleName) return util.warningMsg('请填写角色名称') if(!this.form.remark) return util.warningMsg('请填写角色描述') // if(!this.$refs.per.getCheckedKeys().length) return util.warningMsg('请选择角色权限') - let roleData = { + + let data = { clientId: this.clientId, id: this.form.id, roleName: this.form.roleName, remark: this.form.remark, isPort: 2 } - let roleRes = await this.$post(this.api.saveOrUpdate,roleData) - if(roleRes.success){ + this.$post(this.api.saveOrUpdate,data).then(res => { let permissionId = [...this.$refs.per.getHalfCheckedKeys(),...this.$refs.per.getCheckedKeys()] let perData = { - clientId: this.clientId, - roleId: roleRes.data.roleId, + roleId: res.roleId, permissionId, isPort: 2 } - let perRes = await this.$post(this.api.doAssign,perData) - if(perRes.success){ + this.$post(this.api.doAssign,perData).then(res => { + // console.log(333) util.successMsg('新增成功') this.getData() this.roleVisible = false - } - } + }).catch(res => {}) + }).catch(res => {}) }, handleDelete(row) { this.$confirm('该角色下已有账号,删除角色会将该角色下的账号一并删除,是否继续删除?', '提示', { type: 'warning' - }) - .then(() => { - this.$del(`${this.api.removeRole}?roleIds=${row.id}`).then(res => { - if(res.success){ - util.successMsg('删除成功'); - this.getData() - } + }).then(() => { + this.$post(`${this.api.removeRole}/${row.id}`).then(res => { + util.successMsg('删除成功') + this.getData() }).catch(res => {}) - }) - .catch(() => {}); - }, - getRowKeys(row) { - return row.id; + }).catch(() => {}) }, handleSelectionChange(val) { - this.multipleSelection = val; + this.multipleSelection = val }, delAllSelection() { if(this.multipleSelection.length != ''){ @@ -260,18 +245,15 @@ export default { return item.id }) // 批量删除 - this.$confirm(`此批量删除操作不可逆,是否确认删除${util.ellipsisStr(newArr[0].roleName)}等${newArr.length}个选中项?`, '提示', { + this.$confirm(`此批量删除操作不可逆,是否确认删除?`, '提示', { type: 'warning' - }) - .then(() => { - this.$del(`${this.api.removeRole}?roleIds=${delList.join()}`).then(res => { - if(res.success){ - this.$refs.table.clearSelection() - util.successMsg('删除成功') - this.getData() - } + }).then(() => { + this.$post(`${this.api.batchRemove}?roleIds=${delList.join()}`).then(res => { + this.$refs.table.clearSelection() + util.successMsg('删除成功') + this.getData() }).catch(res => {}) - }).catch(() => {}); + }).catch(() => {}) }else{ util.errorMsg('请先选择数据 !') } @@ -281,13 +263,6 @@ export default {