Răsfoiți Sursa

增加字典详情

ljh 2 ani în urmă
părinte
comite
86b98d9ede

+ 1 - 0
chuanyi-admin/package.json

@@ -36,6 +36,7 @@
     "normalize.css": "7.0.0",
     "nprogress": "0.2.0",
     "path-to-regexp": "2.4.0",
+    "qs": "^6.11.0",
     "screenfull": "4.2.0",
     "script-loader": "0.7.2",
     "sortablejs": "1.8.4",

+ 14 - 5
chuanyi-admin/src/api/system/dict.js

@@ -39,12 +39,12 @@ export function editDict(data) {
   })
 }
 
-// 新增字典
-export function addDict(data) {
+// 根据类型查询对应数据
+export function getDictListByType(query) {
   return request({
-    url: '/dict/addDict',
-    method: 'post',
-    data
+    url: '/dict/queryByType',
+    method: 'get',
+    params: query
   })
 }
 
@@ -56,3 +56,12 @@ export function delDict(data) {
     data
   })
 }
+
+// 新增字典
+export function addDict(data) {
+  return request({
+    url: '/dict/addDict',
+    method: 'post',
+    data
+  })
+}

+ 1 - 1
chuanyi-admin/src/api/system/dictType.js

@@ -21,7 +21,7 @@ export function getAllDictTypeByType(query) {
 // 编辑字典类型
 export function editDictType(data) {
   return request({
-    url: '/dict/updateById',
+    url: '/dict/updataDictType',
     method: 'post',
     data
   })

+ 1 - 1
chuanyi-admin/src/router/index.js

@@ -110,7 +110,7 @@ export const constantRoutes = [
     hidden: true,
     children: [
       {
-        path: 'role/:keyType',
+        path: 'role',
         component: () => import('@/views/system/dict/dict-detail'),
         name: 'DictDetail',
         meta: { title: '字典详情', activeMenu: '/system/dict' }

+ 33 - 32
chuanyi-admin/src/views/system/dict/dict-detail.vue

@@ -4,11 +4,11 @@
       <el-col :span="24">
         <!-- 表单查询 -->
         <el-form ref="queryForm" :model="queryParams" :inline="true" size="small">
-          <el-form-item label="字典名称" prop="description">
-            <el-input v-model="queryParams.description" placeholder="请输入字典名称" clear />
+          <el-form-item label="字典名称" prop="dictValue">
+            <el-input v-model="queryParams.dictValue" placeholder="请输入字典名称" clear />
           </el-form-item>
-          <el-form-item label="字典值" prop="dictKeyType">
-            <el-input v-model="queryParams.dictKeyType" placeholder="请输入字典值" clear />
+          <el-form-item label="字典值" prop="dictKey">
+            <el-input v-model="queryParams.dictKey" placeholder="请输入字典值" clear />
           </el-form-item>
           <el-form-item>
             <el-button type="primary" icon="el-icon-search" size="mini" @click="handelSearch">搜索</el-button>
@@ -29,12 +29,8 @@
         <!-- 表格数据信息 -->
         <el-table v-loading="loading" :data="dictList" row-key="id" @selection-change="handleSelectionChange">
           <el-table-column type="selection" width="50" align="center" />
-          <el-table-column key="description" label="字典名称" align="center" prop="description" />
-          <el-table-column key="dictKeyType" label="字典值" align="center" prop="dictKeyType">
-            <template slot-scope="scope">
-              <el-link type="primary" @click="hendelTo(scope.row)">{{ scope.row.dictKeyType }}</el-link>
-            </template>
-          </el-table-column>
+          <el-table-column key="dictValue" label="字典名称" align="center" prop="dictValue" />
+          <el-table-column key="dictKey" label="字典值" align="center" prop="dictKey" />
           <el-table-column key="sortNum" label="排序号" align="center" prop="sortNum" />
           <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width">
             <template slot-scope="scope">
@@ -59,7 +55,7 @@
           :page.sync="queryParams.page"
           :limit.sync="queryParams.limit"
           align="right"
-          @pagination="getPageDictList"
+          @pagination="getDictListByType"
         />
       </el-col>
     </el-row>
@@ -135,8 +131,8 @@
 </template>
 
 <script>
-import { getPageDictList, getAllDictList } from '@/api/system/dict.js'
-import { getAllDictType, editDictType, addDictType, delDictType } from '@/api/system/dictType.js'
+import { getPageDictList, getAllDictList, getDictListByType, delDict, addDict } from '@/api/system/dict.js'
+import { getAllDictType, editDictType } from '@/api/system/dictType.js'
 import selectTree from '@/components/SelectTree'
 export default {
   components: { selectTree },
@@ -147,7 +143,9 @@ export default {
       // 查询参数
       queryParams: {
         page: 1,
-        num: 10
+        num: 10,
+        // 字典类型
+        keyType: null
       },
       // 总条数
       total: 0,
@@ -182,9 +180,21 @@ export default {
     }
   },
   created() {
+    const { id, dictKeyType } = this.$route.query
+    this.form.dictTypeId = id
+    this.queryParams.keyType = dictKeyType
     this.handelSearch()
   },
   methods: {
+    /** 根据类型查字典列表数据 */
+    getDictListByType() {
+      getDictListByType(this.queryParams).then(res => {
+        const data = res.data
+        this.dictList = this.$utils.toArrayTree(data.dicts)
+        this.total = data.count
+        this.getAllDictList()
+      })
+    },
     /** 查询所有字典类型 */
     getAllDictType() {
       getAllDictType(this.queryParams).then(res => {
@@ -213,7 +223,7 @@ export default {
     /** 搜索 */
     handelSearch() {
       this.queryParams.page = 1
-      this.getPageDictList()
+      this.getDictListByType()
     },
     /** 重置按钮操作 */
     handelReset() {
@@ -274,13 +284,13 @@ export default {
     },
     /** 删除接口 */
     delDictType() {
-      delDictType(this.ids).then(res => {
+      delDict(this.ids).then(res => {
         if (res.code === 200) {
           this.$message({
             type: 'success',
             message: '删除成功'
           })
-          this.getPageDictList()
+          this.getDictListByType()
         }
       })
     },
@@ -289,13 +299,14 @@ export default {
       this.$refs[formName].validate((valid) => {
         if (valid) {
           if (this.title === '添加字典') {
-            addDictType(this.form).then(res => {
+            console.log(this.form)
+            addDict(this.form).then(res => {
               if (res.code === 200) {
                 this.$message({
                   message: res.data,
                   type: 'success'
                 })
-                this.getAllDictType()
+                this.getDictListByType()
                 this.dialogVisible = false
               }
             })
@@ -306,20 +317,10 @@ export default {
                   message: res.data,
                   type: 'success'
                 })
-                this.getAllDictType()
+                this.getDictListByType()
                 this.dialogVisible = false
               }
             })
-            // editDict(this.form).then(res => {
-            //   if (res.code === 200) {
-            //     this.$message({
-            //       message: res.data,
-            //       type: 'success'
-            //     })
-            //     this.getPageDictList()
-            //     this.dialogVisible = false
-            //   }
-            // })
           }
         }
       })
@@ -343,6 +344,6 @@ export default {
 }
 </script>
 
-  <style lang="scss" rel="stylesheet/scss" scoped>
+<style lang="scss" rel="stylesheet/scss" scoped>
 
-  </style>
+</style>

+ 17 - 5
chuanyi-admin/src/views/system/dict/index.vue

@@ -102,6 +102,7 @@
 
 <script>
 import { getAllDictType, editDictType, addDictType, delDictType } from '@/api/system/dictType.js'
+import qs from 'qs'
 export default {
   data() {
     return {
@@ -110,7 +111,9 @@ export default {
       // 查询参数
       queryParams: {
         page: 1,
-        num: 10
+        num: 10,
+        description: null,
+        dictKeyType: null
       },
       // 总条数
       total: 0,
@@ -139,7 +142,10 @@ export default {
       // 控制批量删除按钮
       multiple: true,
       // 删除字典id集合
-      ids: [],
+      idsObj: {
+        ids: []
+
+      },
       // 自定义treeselect键名
       keyName: null
     }
@@ -180,7 +186,7 @@ export default {
     },
     /** 表格多选 */
     handleSelectionChange(val) {
-      this.ids = val.map(item => item.id)
+      this.idsObj.ids = val.map(item => item.id)
       this.multiple = !val.length
     },
     /** 删除按钮 */
@@ -216,7 +222,10 @@ export default {
     },
     /** 删除接口 */
     delDictType() {
-      delDictType(this.ids).then(res => {
+      console.log(this.idsObj.ids)
+      console.log(qs.stringify(this.idsObj, { indices: false }))
+      qs.stringify(this.idsObj, { indices: false })
+      delDictType(this.idsObj).then(res => {
         if (res.code === 200) {
           this.$message({
             type: 'success',
@@ -269,7 +278,10 @@ export default {
     },
     /** 选择字典类型跳转 */
     hendelTo(row) {
-      this.$router.push('/system/dict/dict-detail/role/' + row.dictKeyType)
+      this.$router.push({
+        path: '/system/dict/dict-detail/role/',
+        query: row
+      })
     }
   }
 }