whj 1 year ago
parent
commit
014074c28c
3 changed files with 31 additions and 13 deletions
  1. 10 7
      src/components/Table/index.js
  2. 13 0
      src/utils/tool.js
  3. 8 6
      src/views/check/checkjob/CheckJob.vue

+ 10 - 7
src/components/Table/index.js

@@ -1,6 +1,6 @@
 import T from 'ant-design-vue/es/table/Table'
 import T from 'ant-design-vue/es/table/Table'
 import get from 'lodash.get'
 import get from 'lodash.get'
-
+import BaseTool from '@/utils/tool'
 export default {
 export default {
   data () {
   data () {
     return {
     return {
@@ -194,18 +194,21 @@ export default {
      */
      */
     loadData (pagination, filters, sorter) {
     loadData (pagination, filters, sorter) {
       this.localLoading = true
       this.localLoading = true
+      const dataScope = {
+      }
+      sorter && sorter.field && (dataScope.sortName = BaseTool.String.underlineToHump(sorter.field))
+
+      sorter && sorter.order && (dataScope.sortBy = sorter.order.slice(0, -3))
       const parameter = Object.assign({
       const parameter = Object.assign({
         pageNum: (pagination && pagination.current) ||
         pageNum: (pagination && pagination.current) ||
             this.showPagination && this.localPagination.current || this.pageNum,
             this.showPagination && this.localPagination.current || this.pageNum,
         pageSize: (pagination && pagination.pageSize) ||
         pageSize: (pagination && pagination.pageSize) ||
             this.showPagination && this.localPagination.pageSize || this.pageSize
             this.showPagination && this.localPagination.pageSize || this.pageSize
       },
       },
-      (sorter && sorter.field && {
-        sortField: sorter.field
-      }) || {},
-      (sorter && sorter.order && {
-        sortOrder: sorter.order
-      }) || {}, {
+      {
+        dataScope: dataScope
+      },
+      {
         ...filters
         ...filters
       }
       }
       )
       )

+ 13 - 0
src/utils/tool.js

@@ -104,9 +104,22 @@ BaseTool.String = {
 
 
     const uuid = s.join('')
     const uuid = s.join('')
     return uuid
     return uuid
+  },
+  humpToUnderline (str) {
+    return str.replace(/([A-Z])/g, '_$1').toLowerCase()
+  },
+  underlineToHump (str) {
+    let temp = str.replace(/[A-Z]/g, function (i) {
+      return '_' + i.toLowerCase()
+    })
+    if (temp.slice(0, 1) === '_') {
+      temp = temp.slice(1) // 如果首字母是大写,执行replace时会多一个_,需要去掉
+    }
+    return temp
   }
   }
 }
 }
 BaseTool.Object = {
 BaseTool.Object = {
+
   isBlank (text) {
   isBlank (text) {
     if (typeof text === 'string') {
     if (typeof text === 'string') {
       return BaseTool.String.isBlank(text)
       return BaseTool.String.isBlank(text)

+ 8 - 6
src/views/check/checkjob/CheckJob.vue

@@ -356,7 +356,9 @@ export default {
           checked: true,
           checked: true,
           fixed: 'right',
           fixed: 'right',
           width: '200px',
           width: '200px',
-          sorter: (a, b) => new Date(a.startTime) - new Date(b.startTime)
+          sorter: (a, b) => {
+            return new Date(a.startTime) - new Date(b.startTime)
+          }
 
 
         },
         },
         {
         {
@@ -406,14 +408,11 @@ export default {
       periodTypeMap: {},
       periodTypeMap: {},
       // 加载数据方法 必须为 Promise 对象
       // 加载数据方法 必须为 Promise 对象
       loadData: parameter => {
       loadData: parameter => {
+        console.log(parameter)
         parameter = {
         parameter = {
           ...parameter,
           ...parameter,
           ...this.queryParam,
           ...this.queryParam,
-          record: this.status === 3 ? 1 : null,
-          dataScope: this.status === 3 ? {
-            sortBy: 'desc',
-            sortName: 'actual_start_time'
-          } : {}
+          record: this.status === 3 ? 1 : null
         }
         }
         return getCheckJobPage(Object.assign(parameter, this.queryParam))
         return getCheckJobPage(Object.assign(parameter, this.queryParam))
           .then(res => {
           .then(res => {
@@ -470,6 +469,9 @@ export default {
         this.optionAlertShow = false
         this.optionAlertShow = false
       }
       }
     },
     },
+    tableChange (pagination, filters, sorter) {
+      console.log(pagination, filters, sorter)
+    },
     batchDelete (id) {
     batchDelete (id) {
       let ids = []
       let ids = []
       if (this.BaseTool.String.isBlank(id)) {
       if (this.BaseTool.String.isBlank(id)) {