whj hai 1 ano
pai
achega
014074c28c
Modificáronse 3 ficheiros con 31 adicións e 13 borrados
  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 get from 'lodash.get'
-
+import BaseTool from '@/utils/tool'
 export default {
   data () {
     return {
@@ -194,18 +194,21 @@ export default {
      */
     loadData (pagination, filters, sorter) {
       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({
         pageNum: (pagination && pagination.current) ||
             this.showPagination && this.localPagination.current || this.pageNum,
         pageSize: (pagination && pagination.pageSize) ||
             this.showPagination && this.localPagination.pageSize || this.pageSize
       },
-      (sorter && sorter.field && {
-        sortField: sorter.field
-      }) || {},
-      (sorter && sorter.order && {
-        sortOrder: sorter.order
-      }) || {}, {
+      {
+        dataScope: dataScope
+      },
+      {
         ...filters
       }
       )

+ 13 - 0
src/utils/tool.js

@@ -104,9 +104,22 @@ BaseTool.String = {
 
     const uuid = s.join('')
     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 = {
+
   isBlank (text) {
     if (typeof text === 'string') {
       return BaseTool.String.isBlank(text)

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

@@ -356,7 +356,9 @@ export default {
           checked: true,
           fixed: 'right',
           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: {},
       // 加载数据方法 必须为 Promise 对象
       loadData: parameter => {
+        console.log(parameter)
         parameter = {
           ...parameter,
           ...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))
           .then(res => {
@@ -470,6 +469,9 @@ export default {
         this.optionAlertShow = false
       }
     },
+    tableChange (pagination, filters, sorter) {
+      console.log(pagination, filters, sorter)
+    },
     batchDelete (id) {
       let ids = []
       if (this.BaseTool.String.isBlank(id)) {