Cheng Jian il y a 3 ans
Parent
commit
eaf2fcafec

+ 25 - 0
src/api/system/config.js

@@ -0,0 +1,25 @@
+import request from '@/utils/request'
+
+export function getList(params) {
+  return request({
+    url: '/config/getList',
+    method: 'get',
+    params,
+  })
+}
+
+export function doEdit(data) {
+  return request({
+    url: '/config/doEdit',
+    method: 'post',
+    data,
+  })
+}
+
+export function doDelete(data) {
+  return request({
+    url: '/config/doDelete',
+    method: 'post',
+    data,
+  })
+}

+ 66 - 0
src/views/system/config/components/ConfigEdit.vue

@@ -0,0 +1,66 @@
+<template>
+  <el-dialog
+    :title="title"
+    :visible.sync="dialogFormVisible"
+    width="500px"
+    @close="close">
+    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
+      <el-form-item label="标题" prop="title">
+        <el-input v-model="form.title" />
+      </el-form-item>
+    </el-form>
+    <div slot="footer" class="dialog-footer">
+      <el-button @click="close">取 消</el-button>
+      <el-button type="primary" @click="save">确 定</el-button>
+    </div>
+  </el-dialog>
+</template>
+
+<script>
+  import { doEdit } from '@/api/system/config'
+
+  export default {
+    name: 'ConfigEdit',
+    data() {
+      return {
+        form: {
+          title: '',
+        },
+        rules: {
+          title: [{ required: true, trigger: 'blur', message: '请输入标题' }],
+        },
+        title: '',
+        dialogFormVisible: false,
+      }
+    },
+    created() {},
+    methods: {
+      showEdit(row) {
+        if (!row) {
+          this.title = '添加'
+        } else {
+          this.title = '编辑'
+          this.form = Object.assign({}, row)
+        }
+        this.dialogFormVisible = true
+      },
+      close() {
+        this.$refs['form'].resetFields()
+        this.form = this.$options.data().form
+        this.dialogFormVisible = false
+      },
+      save() {
+        this.$refs['form'].validate(async (valid) => {
+          if (valid) {
+            const { msg } = await doEdit(this.form)
+            this.$baseMessage(msg, 'success')
+            this.$emit('fetch-data')
+            this.close()
+          } else {
+            return false
+          }
+        })
+      },
+    },
+  }
+</script>

+ 217 - 0
src/views/system/config/index.vue

@@ -0,0 +1,217 @@
+<template>
+  <div class="config-container">
+    <vab-query-form>
+      <vab-query-form-left-panel :span="12">
+        <el-button icon="el-icon-plus" type="primary" @click="handleEdit">
+          添加
+        </el-button>
+        <el-button icon="el-icon-delete" type="danger" @click="handleDelete">
+          批量删除
+        </el-button>
+      </vab-query-form-left-panel>
+      <vab-query-form-right-panel :span="12">
+        <el-popover popper-class="custom-table-checkbox" trigger="hover">
+          <el-checkbox-group v-model="checkList">
+            <vab-draggable v-bind="dragOptions" :list="columns">
+              <div v-for="(item, index) in columns" :key="item + index">
+                <vab-icon icon="drag-drop-line" />
+                <el-checkbox
+                  :disabled="item.disableCheck === true"
+                  :label="item.label" />
+              </div>
+            </vab-draggable>
+          </el-checkbox-group>
+          <template #reference>
+            <el-button
+              icon="el-icon-setting"
+              style="margin: 0 0 10px 0 !important"
+              type="primary">
+              可拖拽列设置
+            </el-button>
+          </template>
+        </el-popover>
+      </vab-query-form-right-panel>
+    </vab-query-form>
+
+    <el-table
+      v-loading="listLoading"
+      border
+      :data="list"
+      :height="$baseTableHeight(1)"
+      @selection-change="setSelectRows">
+      <el-table-column align="center" show-overflow-tooltip type="selection" />
+      <el-table-column
+        v-for="(item, index) in finallyColumns"
+        :key="index"
+        align="center"
+        :label="item.label"
+        :prop="item.prop"
+        :sortable="item.sortable"
+        :width="item.width" />
+
+      <el-table-column align="center" label="操作" width="85">
+        <template #default="{ row }">
+          <el-button type="text" @click="handleEdit(row)">编辑</el-button>
+          <el-button type="text" @click="handleDelete(row)">删除</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+    <el-pagination
+      background
+      :current-page="queryForm.pageNo"
+      :layout="layout"
+      :page-size="queryForm.pageSize"
+      :total="total"
+      @current-change="handleCurrentChange"
+      @size-change="handleSizeChange" />
+    <edit ref="edit" @fetch-data="fetchData" />
+  </div>
+</template>
+
+<script>
+  import { getList, doDelete } from '@/api/system/config'
+  import Edit from './components/ConfigEdit'
+  import VabDraggable from 'vuedraggable'
+
+  export default {
+    name: 'Config',
+    components: { Edit, VabDraggable },
+    data() {
+      return {
+        checkList: [],
+        columns: [
+          {
+            prop: 'id',
+            label: '参数主键',
+            type: 'int',
+            width: 'auto',
+          },
+          {
+            prop: 'config_name',
+            label: '参数名称',
+            type: 'varchar',
+            width: 'auto',
+          },
+          {
+            prop: 'config_key',
+            label: '参数键名',
+            type: 'varchar',
+            width: 'auto',
+          },
+          {
+            prop: 'config_value',
+            label: '参数键值',
+            type: 'varchar',
+            width: 'auto',
+          },
+          {
+            prop: 'config_type',
+            label: '系统内置',
+            type: 'varchar',
+            width: 'auto',
+          },
+          {
+            prop: 'remark',
+            label: '备注',
+            type: 'text',
+            width: 'auto',
+          },
+          {
+            prop: 'created_name',
+            label: '创建人',
+            type: 'varchar',
+            width: 'auto',
+          },
+          {
+            prop: 'created_time',
+            label: '创建时间',
+            type: 'datetime',
+            width: 'auto',
+          },
+        ],
+        list: [],
+        listLoading: false,
+        layout: 'total, sizes, prev, pager, next, jumper',
+        total: 0,
+        selectRows: '',
+        queryForm: {
+          pageNo: 1,
+          pageSize: 10,
+          title: '',
+        },
+      }
+    },
+    computed: {
+      dragOptions() {
+        return {
+          animation: 600,
+          group: 'description',
+        }
+      },
+      finallyColumns() {
+        return this.columns.filter((item) =>
+          this.checkList.includes(item.label)
+        )
+      },
+    },
+    created() {
+      for (const elem of this.columns) {
+        this.checkList.push(elem.label)
+      }
+      // this.fetchData()
+    },
+    methods: {
+      setSelectRows(val) {
+        this.selectRows = val
+      },
+      handleEdit(row) {
+        if (row.id) {
+          this.$refs['edit'].showEdit(row)
+        } else {
+          this.$refs['edit'].showEdit()
+        }
+      },
+      handleDelete(row) {
+        if (row.id) {
+          this.$baseConfirm('你确定要删除当前项吗', null, async () => {
+            const { msg } = await doDelete({ ids: row.id })
+            this.$baseMessage(msg, 'success')
+            await this.fetchData()
+          })
+        } else {
+          if (this.selectRows.length > 0) {
+            const ids = this.selectRows.map((item) => item.id).join()
+            this.$baseConfirm('你确定要删除选中项吗', null, async () => {
+              const { msg } = await doDelete({ ids })
+              this.$baseMessage(msg, 'success')
+              await this.fetchData()
+            })
+          } else {
+            this.$baseMessage('未选中任何行', 'error')
+            return false
+          }
+        }
+      },
+      handleSizeChange(val) {
+        this.queryForm.pageSize = val
+        this.fetchData()
+      },
+      handleCurrentChange(val) {
+        this.queryForm.pageNo = val
+        this.fetchData()
+      },
+      queryData() {
+        this.queryForm.pageNo = 1
+        this.fetchData()
+      },
+      async fetchData() {
+        this.listLoading = true
+        const { data } = await getList(this.queryForm)
+        const { list, total } = data
+        this.list = list
+        this.total = total
+        this.listLoading = false
+      },
+    },
+  }
+</script>

+ 1 - 0
template/index.hbs

@@ -79,6 +79,7 @@
 <script>
   import { getList, doDelete } from '@/api/{{moduleName}}/{{ camelCase name }}'
   import Edit from './components/{{ properCase name }}Edit'
+  import VabDraggable from 'vuedraggable'
 
   export default {
     name: '{{ properCase name }}',