瀏覽代碼

fix export

scorpio 2 年之前
父節點
當前提交
97d6a42761
共有 2 個文件被更改,包括 47 次插入3 次删除
  1. 43 0
      src/utils/tools.js
  2. 4 3
      src/views/home/component/dash.vue

+ 43 - 0
src/utils/tools.js

@@ -21,3 +21,46 @@ export function objectToParams (objs) {
   }
   return query.join('&')
 }
+
+export const getObjType = obj => {
+  const toString = Object.prototype.toString
+  const map = {
+    '[object Boolean]': 'boolean',
+    '[object Number]': 'number',
+    '[object String]': 'string',
+    '[object Function]': 'function',
+    '[object Array]': 'array',
+    '[object Date]': 'date',
+    '[object RegExp]': 'regExp',
+    '[object Undefined]': 'undefined',
+    '[object Null]': 'null',
+    '[object Object]': 'object'
+  }
+  if (obj instanceof Element) {
+    return 'element'
+  }
+  return map[toString.call(obj)]
+}
+
+export const deepClone = data => {
+  const type = getObjType(data)
+  let obj
+  if (type === 'array') {
+    obj = []
+  } else if (type === 'object') {
+    obj = {}
+  } else {
+    // 不再具有下一层次
+    return data
+  }
+  if (type === 'array') {
+    for (let i = 0, len = data.length; i < len; i++) {
+      obj.push(deepClone(data[i]))
+    }
+  } else if (type === 'object') {
+    for (const key in data) {
+      obj[key] = deepClone(data[key])
+    }
+  }
+  return obj
+}

+ 4 - 3
src/views/home/component/dash.vue

@@ -175,6 +175,7 @@ import formDialog from '@/views/home/component/form_dialog.vue'
 import { getLazyList } from '@/api/project/index.js'
 import summaryDialog from '@/views/home/component/summary_dialog.vue'
 import { useStore } from '@/store/user.js'
+import { deepClone } from '@/utils/tools.js'
 
 export default {
   name: 'dash',
@@ -526,7 +527,7 @@ export default {
       this.diaType = -1
     },
     exportExcel (res) {
-      const data = Object.assign(this.queryData, { columnName: res, projectIds: this.selectList.join(',') })
+      const data = Object.assign({ ...this.queryData }, { columnName: res, projectIds: this.selectList.join(',') })
       this.$api.params.exportResult(data).then(res => {
         if (res.hasOwnProperty('code')) {
           this.$message.error(res.msg)
@@ -536,8 +537,8 @@ export default {
       })
     },
     exportExcelTotal (item) {
-      const data = { ...this.queryData, projectIds: this.selectList.join(',') }
-      this.$api.params.summaryExport(Object.assign(item, data)).then(res => {
+      const dataIds = { ...this.queryData, projectIds: this.selectList.join(',') }
+      this.$api.params.summaryExport(Object.assign(item, dataIds)).then(res => {
         if (res.hasOwnProperty('code')) {
           this.$message.error(res.msg)
           return