Jelajahi Sumber

Merge pull request #9 from kikiyou/dev

fix 无法导出Excel
wenjianzhang 5 tahun lalu
induk
melakukan
313878373c

+ 1 - 1
package.json

@@ -104,7 +104,7 @@
     "serve-static": "^1.13.2",
     "svg-sprite-loader": "4.1.3",
     "svgo": "1.2.0",
-    "vue-template-compiler": "2.6.10"
+    "vue-template-compiler": "^2.6.11"
   },
   "engines": {
     "node": ">=8.9",

+ 14 - 0
src/utils/index.js

@@ -346,3 +346,17 @@ export function removeClass(ele, cls) {
   }
 }
 
+/**
+ * @param {Array} filterVal
+ * @param {Object} jsonData
+ * @returns {string}
+ */
+export function formatJson(filterVal, jsonData) {
+  return jsonData.map(v => filterVal.map(j => {
+    if (j === 'timestamp') {
+      return parseTime(v[j])
+    } else {
+      return v[j]
+    }
+  }))
+}

+ 18 - 5
src/views/config/index.vue

@@ -154,6 +154,7 @@
 
 <script>
 import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig } from '@/api/system/config'
+import { parseTime,formatJson } from '@/utils'
 
 export default {
   name: 'Config',
@@ -323,11 +324,23 @@ export default {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
-      }).then(function() {
-        return exportConfig(queryParams)
-      }).then(response => {
-        this.download(response.msg)
-      }).catch(function() {})
+      }).then( () => {
+        this.downloadLoading = true
+        import('@/vendor/Export2Excel').then(excel => {
+          const tHeader = ['参数主键', '参数名称', '参数键名', '参数键值','备注','创建时间']
+          const filterVal = ['configId', 'configName', 'configKey', 'configValue','remark', 'createdAt']
+          const list = this.configList
+          const data = formatJson(filterVal, list)
+          excel.export_json_to_excel({
+            header: tHeader,
+            data,
+            filename: "参数设置",
+            autoWidth: true, // Optional
+            bookType: 'xlsx' // Optional
+          })
+          this.downloadLoading = false
+        })
+      })
     }
   }
 }

+ 18 - 5
src/views/dict/index.vue

@@ -163,6 +163,7 @@
 
 <script>
 import { listType, getType, delType, addType, updateType, exportType } from '@/api/system/dict/type'
+import { parseTime,formatJson } from '@/utils'
 
 export default {
   name: 'Dict',
@@ -328,11 +329,23 @@ export default {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
-      }).then(function() {
-        return exportType(queryParams)
-      }).then(response => {
-        this.download(response.msg)
-      }).catch(function() {})
+      }).then( () => {
+        this.downloadLoading = true
+        import('@/vendor/Export2Excel').then(excel => {
+          const tHeader = ['字典编号', '字典名称', '字典类型', '状态', '备注']
+          const filterVal = ['dictId', 'dictName', 'dictType', 'status', 'remark']
+          const list = this.typeList
+          const data = formatJson(filterVal, list)
+          excel.export_json_to_excel({
+            header: tHeader,
+            data,
+            filename: "字典管理",
+            autoWidth: true, // Optional
+            bookType: 'xlsx' // Optional
+          })
+          this.downloadLoading = false
+        })
+      })
     }
   }
 }

+ 18 - 5
src/views/loginlog/index.vue

@@ -104,6 +104,7 @@
 
 <script>
 import { list, delLogininfor, cleanLogininfor, exportLogininfor } from '@/api/system/loginlog'
+import { parseTime,formatJson } from '@/utils'
 
 export default {
   name: 'Logininfor',
@@ -204,11 +205,23 @@ export default {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
-      }).then(function() {
-        return exportLogininfor(queryParams)
-      }).then(response => {
-        this.download(response.msg)
-      }).catch(function() {})
+      }).then( () => {
+        this.downloadLoading = true
+        import('@/vendor/Export2Excel').then(excel => {
+          const tHeader = ['编号', '用户名称', '登陆地址', '登陆地点', '浏览器','操作系统','登陆状态','操作信息','登陆日期']
+          const filterVal = ['infoId', 'username', 'ipaddr', 'loginLocation', 'browser','os','status','msg','loginTime']
+          const list = this.list
+          const data = formatJson(filterVal, list)
+          excel.export_json_to_excel({
+            header: tHeader,
+            data,
+            filename: "登陆日志",
+            autoWidth: true, // Optional
+            bookType: 'xlsx' // Optional
+          })
+          this.downloadLoading = false
+        })
+      })
     }
   }
 }

+ 18 - 5
src/views/operlog/index.vue

@@ -175,6 +175,7 @@
 
 <script>
 import { list, delOperlog, cleanOperlog, exportOperlog } from '@/api/system/operlog'
+import { parseTime,formatJson } from '@/utils'
 
 export default {
   name: 'Operlog',
@@ -294,11 +295,23 @@ export default {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
-      }).then(function() {
-        return exportOperlog(queryParams)
-      }).then(response => {
-        this.download(response.msg)
-      }).catch(function() {})
+      }).then( () => {
+        this.downloadLoading = true
+        import('@/vendor/Export2Excel').then(excel => {
+          const tHeader = ['日志编号', '系统模块', '操作类型', '请求方式', '操作人员','主机','操作地点','操作状态','操作url','操作日期']
+          const filterVal = ['operId', 'title', 'businessType', 'method', 'operName', 'operIp','operLocation','status','operUrl','operTime']
+          const list = this.list
+          const data = formatJson(filterVal, list)
+          excel.export_json_to_excel({
+            header: tHeader,
+            data,
+            filename: "操作日志",
+            autoWidth: true, // Optional
+            bookType: 'xlsx' // Optional
+          })
+          this.downloadLoading = false
+        })
+      })
     }
   }
 }

+ 4 - 14
src/views/post/index.vue

@@ -158,8 +158,8 @@
 
 <script>
 import { listPost, getPost, delPost, addPost, updatePost } from '@/api/system/post'
+import { parseTime,formatJson } from '@/utils'
 
-import { parseTime } from '@/utils'
 export default {
   name: 'Post',
   data() {
@@ -325,34 +325,24 @@ export default {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
-      }).then(function() {
+      }).then( () => {
         this.downloadLoading = true
       import('@/vendor/Export2Excel').then(excel => {
         const tHeader = ['岗位编号', '岗位编码', '岗位名称', '排序', '创建时间']
         const filterVal = ['postId', 'postCode', 'postName', 'sort', 'createdAt']
         const list = this.postList
-        const data = this.formatJson(filterVal, list)
+        const data = formatJson(filterVal, list)
         excel.export_json_to_excel({
           header: tHeader,
           data,
-          filename: this.filename,
+          filename: '岗位管理',
           autoWidth: true, // Optional
           bookType: 'xlsx' // Optional
         })
         this.downloadLoading = false
       })
       }).catch(function() {})
-    },
-    formatJson(filterVal, jsonData) {
-      return jsonData.map(v => filterVal.map(j => {
-        if (j === 'timestamp') {
-          return parseTime(v[j])
-        } else {
-          return v[j]
-        }
-      }))
     }
-
   }
 }
 </script>

+ 18 - 6
src/views/role/index.vue

@@ -236,6 +236,7 @@
 import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from '@/api/system/role'
 import { treeselect as menuTreeselect, roleMenuTreeselect } from '@/api/system/menu'
 import { treeselect as deptTreeselect, roleDeptTreeselect } from '@/api/system/dept'
+import { parseTime,formatJson } from '@/utils'
 
 export default {
   name: 'Role',
@@ -538,16 +539,27 @@ export default {
     },
     /** 导出按钮操作 */
     handleExport() {
-      const queryParams = this.queryParams
       this.$confirm('是否确认导出所有角色数据项?', '警告', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
-      }).then(function() {
-        return exportRole(queryParams)
-      }).then(response => {
-        this.download(response.msg)
-      }).catch(function() {})
+      }).then( () => {
+        this.downloadLoading = true
+        import('@/vendor/Export2Excel').then(excel => {
+          const tHeader = ['角色编号', '角色名称', '权限字符', '显示顺序', '状态','创建时间']
+          const filterVal = ['roleId', 'roleName', 'roleKey', 'roleSort', 'status','createdAt']
+          const list = this.roleList
+          const data = formatJson(filterVal, list)
+          excel.export_json_to_excel({
+            header: tHeader,
+            data,
+            filename: "角色管理",
+            autoWidth: true, // Optional
+            bookType: 'xlsx' // Optional
+          })
+          this.downloadLoading = false
+        })
+      })
     }
   }
 }