Browse Source

对接字典管理接口

ljh 2 years ago
parent
commit
3762aca07b

+ 32 - 23
chuanyi-admin/src/api/system/dict.js

@@ -1,5 +1,14 @@
 import request from '@/utils/request'
 
+// 根据类型查询对应数据
+export function getDictListByType(query) {
+  return request({
+    url: '/dict/queryByType',
+    method: 'get',
+    params: query
+  })
+}
+
 // 分页获取字典列表数据
 export function getPageDictList(query) {
   return request({
@@ -21,47 +30,47 @@ export function getAllDictList() {
   })
 }
 
-// 根据id或字典key条件查询
-export function getDictDetailByIdorKey(query) {
+// 删除字典
+export function delDict(data) {
   return request({
-    url: '/dict/queryByIdorKey',
-    method: 'get',
-    params: query
+    url: '/dict/deleteById',
+    method: 'post',
+    data
   })
 }
 
-// 根编辑字典
-export function editDict(data) {
+// 新增字典
+export function addDict(data) {
   return request({
-    url: '/dict/updateById',
+    url: '/dict/addDict',
     method: 'post',
     data
   })
 }
 
-// 根据类型查询对应数据
-export function getDictListByType(query) {
+// 编辑字典
+export function editDict(data) {
   return request({
-    url: '/dict/queryByType',
-    method: 'get',
-    params: query
+    url: '/dict/updateById',
+    method: 'post',
+    data
   })
 }
 
-// 删除字典
-export function delDict(data) {
+// 根据id或字典key条件查询
+export function getDictDetailByIdorKey(query) {
   return request({
-    url: '/dict/deleteById',
-    method: 'post',
-    data
+    url: '/dict/queryByIdorKey',
+    method: 'get',
+    params: query
   })
 }
 
-// 新增字典
-export function addDict(data) {
+// 根据父节点查所有子节点
+export function getDictSonListByPid(parentId) {
   return request({
-    url: '/dict/addDict',
-    method: 'post',
-    data
+    url: '/dict/queryByParentId',
+    method: 'get',
+    params: parentId
   })
 }

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

@@ -37,10 +37,10 @@ export function addDictType(data) {
 }
 
 // 删除字典类型
-export function delDictType(query) {
+export function delDictType(data) {
   return request({
     url: '/dict/deleteDictTypeById',
-    method: 'get',
-    params: query
+    method: 'post',
+    data
   })
 }

+ 11 - 5
chuanyi-admin/src/components/SelectTree/index.vue

@@ -7,7 +7,7 @@
       :value="parentId"
       @input="handelInput"
     >
-      <div slot="value-label" slot-scope="{ node }">{{ node.raw.id==0?'主菜单':node.raw[keyName] }}</div>
+      <div slot="value-label" slot-scope="{ node }">{{ node.raw.id == 0 ? '主菜单' : node.raw[keyName] }}</div>
     </treeselect>
   </div>
 </template>
@@ -25,19 +25,25 @@ export default {
   props: {
     // 树状数据
     options: {
-      type: Array
+      type: Array,
+      default: function(params) {
+        return []
+      }
     },
     // 占位符
     placeholder: {
-      type: String
+      type: String,
+      default: '请选择'
     },
     // 自定义键名
     keyName: {
-      type: String
+      type: String,
+      default: 'label'
     },
     // 回显id
     parentId: {
-      type: Number
+      type: Number,
+      default: 0
     }
   },
   data() {

+ 30 - 68
chuanyi-admin/src/views/system/dict/dict-detail.vue

@@ -25,6 +25,13 @@
           :disabled="multiple"
           @click="handelDelAll"
         >批量删除</el-button>
+        <el-button
+          size="mini"
+          icon="el-icon-close"
+          type="warning"
+          plain
+          @click="(() => { this.$router.push('/system/dict') })"
+        >返回</el-button>
 
         <!-- 表格数据信息 -->
         <el-table v-loading="loading" :data="dictList" row-key="id" @selection-change="handleSelectionChange">
@@ -55,44 +62,12 @@
           :page.sync="queryParams.page"
           :limit.sync="queryParams.limit"
           align="right"
-          @pagination="getDictListByType"
+          @pagination="getPageDictList"
         />
       </el-col>
     </el-row>
 
     <!-- 弹出框 -->
-    <!-- <el-dialog :title="title" :visible.sync="dialogVisible" width="35%" append-to-body>
-        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
-          <el-row>
-            <el-col :span="12">
-              <el-form-item label="字典描述" prop="description">
-                <el-input v-model="form.description" clearable placeholder="请输入字典名称" />
-              </el-form-item>
-            </el-col>
-            <el-col :span="12">
-              <el-form-item label="字典类型" prop="dictKeyValue">
-                <el-input v-model="form.dictKeyValue" clearable placeholder="请输入字典名称" />
-              </el-form-item>
-            </el-col>
-          </el-row>
-          <el-row>
-            <el-col :span="12">
-              <el-form-item label="字典值" prop="dictKeyType">
-                <el-input v-model="form.dictKeyType" clearable placeholder="请输入字典值" />
-              </el-form-item>
-            </el-col>
-            <el-col :span="12">
-              <el-form-item label="显示排序" prop="sortNum">
-                <el-input-number v-model="form.sortNum" placeholder="0" controls-position="right" :min="1" :max="10" />
-              </el-form-item>
-            </el-col>
-          </el-row>
-        </el-form>
-        <span slot="footer" class="dialog-footer">
-          <el-button type="primary" @click="handelSubmit('form')">确 定</el-button>
-          <el-button @click="handelCancel('form')">取 消</el-button>
-        </span>
-      </el-dialog> -->
     <el-dialog :title="title" :visible.sync="dialogVisible" width="35%" append-to-body>
       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
         <el-row>
@@ -131,8 +106,7 @@
 </template>
 
 <script>
-import { getPageDictList, getAllDictList, getDictListByType, delDict, addDict } from '@/api/system/dict.js'
-import { getAllDictType, editDictType } from '@/api/system/dictType.js'
+import { getAllDictList, getDictListByType, delDict, addDict, getPageDictList, editDict } from '@/api/system/dict.js'
 import selectTree from '@/components/SelectTree'
 export default {
   components: { selectTree },
@@ -143,9 +117,7 @@ export default {
       // 查询参数
       queryParams: {
         page: 1,
-        num: 10,
-        // 字典类型
-        keyType: null
+        num: 10
       },
       // 总条数
       total: 0,
@@ -161,10 +133,10 @@ export default {
       options: [],
       // 表单验证
       rules: {
-        description: [
+        dictValue: [
           { required: true, message: '字典名称不能为空', trigger: 'blur' }
         ],
-        dictKeyType: [
+        dictKey: [
           { required: true, message: '字典值不能为空', trigger: 'blur' }
         ],
         sortNum: [
@@ -176,18 +148,21 @@ export default {
       // 删除字典id集合
       ids: [],
       // 自定义treeselect键名
-      keyName: null
+      keyName: null,
+      // 字典类型
+      keyType: null
     }
   },
   created() {
     const { id, dictKeyType } = this.$route.query
     this.form.dictTypeId = id
-    this.queryParams.keyType = dictKeyType
-    this.handelSearch()
+    this.keyType = dictKeyType
+    this.getDictListByType()
   },
   methods: {
     /** 根据类型查字典列表数据 */
     getDictListByType() {
+      this.queryParams.keyType = this.keyType
       getDictListByType(this.queryParams).then(res => {
         const data = res.data
         this.dictList = this.$utils.toArrayTree(data.dicts)
@@ -195,21 +170,12 @@ export default {
         this.getAllDictList()
       })
     },
-    /** 查询所有字典类型 */
-    getAllDictType() {
-      getAllDictType(this.queryParams).then(res => {
-        const data = res.data
-        this.dictList = data.dictTypes
-        this.total = data.count
-      })
-    },
     /** 分页获取字典列表数据 */
     getPageDictList() {
       getPageDictList(this.queryParams).then(res => {
         const data = res.data
         this.dictList = this.$utils.toArrayTree(data.dictPage)
         this.total = data.count
-        this.getAllDictList()
       })
     },
     /** 全量获取字典列表数据 */
@@ -223,12 +189,13 @@ export default {
     /** 搜索 */
     handelSearch() {
       this.queryParams.page = 1
-      this.getDictListByType()
+      this.getPageDictList()
     },
     /** 重置按钮操作 */
     handelReset() {
       this.$refs['queryForm'].resetFields()
-      this.handelSearch()
+      this.queryParams.page = 1
+      this.getDictListByType()
     },
     /** 新增按钮 */
     handelAdd() {
@@ -237,14 +204,10 @@ export default {
       this.reset()
     },
     /** 修改按钮 */
-    handelEdit(id) {
-      // this.queryParams.dictKey = id
-      // getDictDetailByIdorKey(this.queryParams).then(res => {
-      //   const data = res.data
-      //   this.form = data.dicts[0]
-      // })
-      // this.dialogVisible = true
-      // this.title = '修改字典'
+    handelEdit(row) {
+      this.form = row
+      this.dialogVisible = true
+      this.title = '修改字典'
     },
     /** 表格多选 */
     handleSelectionChange(val) {
@@ -299,7 +262,6 @@ export default {
       this.$refs[formName].validate((valid) => {
         if (valid) {
           if (this.title === '添加字典') {
-            console.log(this.form)
             addDict(this.form).then(res => {
               if (res.code === 200) {
                 this.$message({
@@ -311,7 +273,11 @@ export default {
               }
             })
           } else {
-            editDictType(this.form).then(res => {
+            if (this.form.parentId === undefined) {
+              this.form.parentId = 0
+              return
+            }
+            editDict(this.form).then(res => {
               if (res.code === 200) {
                 this.$message({
                   message: res.data,
@@ -335,10 +301,6 @@ export default {
       if (this.$refs['form']) {
         this.$refs['form'].resetFields()
       }
-    },
-    /** 选择字典类型跳转 */
-    hendelTo(row) {
-      console.log(row)
     }
   }
 }

+ 3 - 10
chuanyi-admin/src/views/system/dict/index.vue

@@ -102,7 +102,6 @@
 
 <script>
 import { getAllDictType, editDictType, addDictType, delDictType } from '@/api/system/dictType.js'
-import qs from 'qs'
 export default {
   data() {
     return {
@@ -142,10 +141,7 @@ export default {
       // 控制批量删除按钮
       multiple: true,
       // 删除字典id集合
-      idsObj: {
-        ids: []
-
-      },
+      ids: [],
       // 自定义treeselect键名
       keyName: null
     }
@@ -186,7 +182,7 @@ export default {
     },
     /** 表格多选 */
     handleSelectionChange(val) {
-      this.idsObj.ids = val.map(item => item.id)
+      this.ids = val.map(item => item.id)
       this.multiple = !val.length
     },
     /** 删除按钮 */
@@ -222,10 +218,7 @@ export default {
     },
     /** 删除接口 */
     delDictType() {
-      console.log(this.idsObj.ids)
-      console.log(qs.stringify(this.idsObj, { indices: false }))
-      qs.stringify(this.idsObj, { indices: false })
-      delDictType(this.idsObj).then(res => {
+      delDictType(this.ids).then(res => {
         if (res.code === 200) {
           this.$message({
             type: 'success',