瀏覽代碼

feat: 列表添加排序功能

王家程 3 年之前
父節點
當前提交
785f14439a
共有 2 個文件被更改,包括 20 次插入8 次删除
  1. 3 3
      src/components/generator/tabs.js
  2. 17 5
      src/views/Page/Edit/ListConfig.vue

+ 3 - 3
src/components/generator/tabs.js

@@ -1,8 +1,8 @@
 /*
  * @Author: WangJiaCheng
  * @Date: 2021-07-29 11:19:04
- * @LastEditors: WangJiaCheng
- * @LastEditTime: 2021-07-29 16:19:09
+ * @LastEditors: wjc
+ * @LastEditTime: 2021-12-08 18:06:10
  * @Description: tabs 配置
  */
 import { exportDefault } from '@/utils/index'
@@ -13,13 +13,13 @@ export function buildTabs(formData) {
   <div class="tab">
     ${buildHeader(formData)}
     <search-form
+      ref="searchForm"
       @search="handleSearch"
       @reset="handleReset"
     />
     <data-table
       ref="dataTable"
       :loading="tableLoading"
-      :approveData="approveData"
       @page="handlePage"
     />
   </div>

+ 17 - 5
src/views/Page/Edit/ListConfig.vue

@@ -2,7 +2,7 @@
  * @Author: WangJiaCheng
  * @Date: 2021-05-12 15:36:33
  * @LastEditors: wjc
- * @LastEditTime: 2021-12-02 17:41:33
+ * @LastEditTime: 2021-12-10 10:37:57
  * @Description:
 -->
 <template>
@@ -114,6 +114,17 @@
               />
             </template>
           </el-table-column>
+          <el-table-column
+            prop="order"
+            label="排序号"
+            width="100"
+          >
+            <template slot-scope="{row}">
+              <el-input
+                v-model="row.order"
+              />
+            </template>
+          </el-table-column>
           <el-table-column
             prop="edit"
             label="操作"
@@ -170,22 +181,23 @@ export default {
         const resBody = JSON.parse(formatApiJson.res_body)
         const { properties: { list: { items: { properties: propertyDta = {} } } } } = resBody
         if (propertyDta) {
-          for (const key of Object.keys(propertyDta)) {
+          for (const [index, key] of Object.keys(propertyDta).entries()) {
             this.tableData.push({
               type: propertyDta[key].type,
               name: propertyDta[key].description.replace(/\((.+)\)/g, ''),
-              field: key
+              field: key,
+              order: index
             })
           }
         }
       }
     },
     next() {
-      this.setListConfig({ ...this.formData, list: this.tableData })
+      this.setListConfig({ ...this.formData, list: this.tableData.sort((a, b) => a.order - b.order) })
       this.setActiveTab('detail')
     },
     previewCode() {
-      this.$emit('preview', { ...this.formData, list: this.tableData }, 'list')
+      this.$emit('preview', { ...this.formData, list: this.tableData.sort((a, b) => a.order - b.order) }, 'list')
     },
     addCol() {
       this.tableData.push({