From 2bdbe42d8d4b03b46d2066e50e595a06cebd43c2 Mon Sep 17 00:00:00 2001
From: lzhe <181968431@qq.com>
Date: 星期六, 13 四月 2024 22:34:05 +0800
Subject: [PATCH] 1

---
 src/views/console/system/component-classification.vue |  192 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 173 insertions(+), 19 deletions(-)

diff --git a/src/views/console/system/component-classification.vue b/src/views/console/system/component-classification.vue
index 2ccc6d1..27f8f4c 100644
--- a/src/views/console/system/component-classification.vue
+++ b/src/views/console/system/component-classification.vue
@@ -1,7 +1,7 @@
 <!--
  * @Date: 2024-04-09 22:18:47
  * @LastEditors: Sneed
- * @LastEditTime: 2024-04-09 23:14:53
+ * @LastEditTime: 2024-04-11 21:36:58
  * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/console/system/component-classification.vue
  * 鍒嗙被缁存姢
 -->
@@ -12,16 +12,22 @@
             <el-button @click="del" plain type="danger" :disabled="selection.length == 0">鍒犻櫎</el-button>
         </el-header>
         <el-main>
-            <el-table stripe :data="tableData" border style="width: 100%; margin-bottom: 20px" class="multipleTableRef" @selection-change="handleSelectionChange" row-key="id" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
+            <el-table @selection-change="handleSelectionChange" :data="tableData"
+                style="width: 100%;margin-bottom: 20px;" row-key="id" border :tree-props="{ hasChildren: 'has' }">
                 <el-table-column type="selection" width="55" />
                 <el-table-column prop="name" label="鍒嗙被鍚嶇О" />
+                <el-table-column prop="parentId" label="涓婄骇鍒嗙被" />
                 <el-table-column prop="icon" label="鍒嗙被鍥炬爣">
+                    <template #default="scope">
+                        <component v-if="icons.includes(scope.row.icon)" style="width: 20px;height: 20px;"
+                            :is='scope.row.icon'></component>
+                    </template>
                 </el-table-column>
                 <el-table-column prop="type" label="鍒嗙被缂栧彿" />
                 <el-table-column prop="orderNum" label="鎺掑垪椤哄簭" />
                 <el-table-column prop="status" label="鐘舵��">
                     <template #default="scope">
-                        <span>{{scope.row.status === 1 ? '鍚敤' : '鍋滅敤'}}</span>
+                        <span>{{ scope.row.status === 1 ? '鍚敤' : '鍋滅敤' }}</span>
                     </template>
                 </el-table-column>
                 <el-table-column label="鎿嶄綔" fixed="right" align="left" width="160">
@@ -39,43 +45,191 @@
                 </el-table-column>
             </el-table>
         </el-main>
+        <el-dialog v-model="dialogVisible" :title="dialogTitle" width="750" :before-close="handleClose">
+            <el-form :model="row" :rules="rules" ref="dialogForm" label-width="120px" label-position="center">
+                <el-row>
+                    <el-col :span="12">
+                        <el-form-item label="鍒嗙被鍚嶇О" prop="name">
+                            <el-input style="width: 240px" v-model="row.name" placeholder="璇疯緭鍏ュ垎绫诲悕绉�"
+                                clearable></el-input>
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="12">
+                        <el-form-item label="涓婄骇鍒嗙被" prop="parentId">
+                            <el-select v-model="row.parentId" filterable placeholder="璇烽�夋嫨涓婄骇鍒嗙被" style="width: 240px">
+                                <el-option v-for="item in options" :key="item.value" :label="item.label"
+                                    :value="item.value" />
+                            </el-select>
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="12">
+                        <el-form-item label="鍒嗙被鍥炬爣" prop="icon">
+                            <el-input @click="showIconDialog = true" style="width: 240px" v-model="row.icon"
+                                placeholder="璇烽�夋嫨鍒嗙被鍥炬爣" clearable></el-input>
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="12">
+                        <el-form-item label="鍒嗙被缂栧彿" prop="type">
+                            <el-input style="width: 240px" v-model="row.type" placeholder="璇疯緭鍏ュ垎绫荤紪鍙�"
+                                clearable></el-input>
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="12">
+                        <el-form-item label="鎺掑垪椤哄簭" prop="orderNum">
+                            <el-input-number style="width: 240px" default v-model="row.orderNum" :min="0"
+                                placeholder="璇疯緭鍏ユ帓鍒楅『搴�" />
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="12">
+                        <el-form-item label="鐘舵��" prop="status">
+                            <el-radio-group style="width: 240px" v-model="row.status">
+                                <el-radio v-for="item in statusList" :label="item.value" :key="item.value">{{ item.label
+                                    }}</el-radio>
+                            </el-radio-group>
+                        </el-form-item>
+                    </el-col>
+                </el-row>
+            </el-form>
+            <template #footer>
+                <div class="dialog-footer">
+                    <el-button @click="dialogVisible = false">鍙栨秷</el-button>
+                    <el-button type="primary" @click="save">
+                        淇濆瓨
+                    </el-button>
+                </div>
+            </template>
+        </el-dialog>
+        <el-dialog v-model="showIconDialog" title="鍒嗙被鍥炬爣" width="750">
+            <div class="icons">
+                <component @click="setIcon(item)" class="icon" v-for="item in icons" :is='item' :key="item"></component>
+            </div>
+
+        </el-dialog>
     </el-container>
 </template>
 
 <script>
+import * as ElementPlusIconsVue from '@element-plus/icons-vue'
+let icons = []
+for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
+    icons.push(key)
+}
 export default {
+    components: {
+        ...ElementPlusIconsVue
+    },
     data() {
         return {
             tableData: [],
-            selection: []
+            selection: [],
+            dialogVisible: false,
+            row: {
+                id: '',
+                name: '',
+                parentId: '',
+                icon: '',
+                type: '',
+                orderNum: 0,
+                status: 1,
+            },
+            rules: {
+                name: [
+                    { required: true, message: '璇疯緭鍏ュ垎绫诲悕绉�' }
+                ],
+                type: [
+                    { required: true, message: '璇疯緭鍏ュ垎绫荤紪鍙�' }
+                ]
+            },
+            options: [],
+            statusList: [
+                {
+                    label: '鍚敤',
+                    value: 1
+                },
+                {
+                    label: '鍋滅敤',
+                    value: 0
+                }
+            ],
+            showIconDialog: false,
+            icons
         }
     },
-    created () {
+    created() {
         this.queryList()
     },
     methods: {
-        add () {
-            alert(2)
+        add() {
+            this?.$refs?.dialogForm?.resetFields()
+            Object.keys(this.row).forEach(v => {
+                this.row[v] = ''
+            })
+            this.row.orderNum = 0
+            this.dialogTitle = '鏂板'
+            this.dialogVisible = true
         },
-        del () {
-            alert(1)
-        },
-        queryList () {
-            this.$API.setting.getList.get().then(res => {
-                this.tableData = res.data
+        save() {
+            this.$refs.dialogForm.validate(async (valid) => {
+                if (valid) {
+                    let request = this.$API.setting.insert
+                    if (this?.row?.id) {
+                        request = this.$API.setting.update
+                    }
+                    request.post(this.row).then(res => {
+                        this.dialogVisible = false
+                        this.queryList()
+                    })
+                }
             })
         },
-        table_edit() {
-
+        del() {
+            this.$API.setting.del.delete({}, { data: this.selection.map(v => v.id) }).then(res => {
+                this.queryList()
+            })
         },
-        table_del() {
-
+        queryList() {
+            this.$API.setting.getList.get().then(res => {
+                this.tableData = res.data;
+                this.options = res.data.map(item => ({
+                    value: item.id,
+                    label: item.name
+                }))
+            })
         },
-        handleSelectionChange (selection) {
+        table_edit(row) {
+            this.row = { ...row }
+            console.log(this.row)
+            this.dialogTitle = '缂栬緫'
+            this.dialogVisible = true
+        },
+        table_del(row) {
+            this.$API.setting.del.delete({}, { data: [row.id] }).then(res => {
+                this.queryList()
+            })
+        },
+        handleSelectionChange(selection) {
+            console.log('>>>>>>')
             this.selection = selection;
+        },
+        setIcon(icon) {
+            console.log('>>>>>>', icon)
+            this.row.icon = icon
+            this.showIconDialog = false
         }
     },
 }
 </script>
 
-<style lang="scss" scoped></style>
\ No newline at end of file
+<style lang="scss" scoped>
+.icons {
+    display: flex;
+    flex-wrap: wrap;
+}
+
+.icon {
+    margin: 10px;
+    width: 20px;
+    height: 20px;
+    cursor: pointer;
+}
+</style>
\ No newline at end of file

--
Gitblit v1.9.3