Sfoglia il codice sorgente

分类管理完成

quwangxin 3 anni fa
parent
commit
d283a9ec1f

+ 1 - 3
src/enum/dict.js

@@ -1,6 +1,4 @@
 export default {
   类型用途: 'type_use',
-  条码分类: 'BARCODE',
-  资产类型: 'ASSECTSTYPE',
-  物品类型: 'classify'
+  分隔符: 'separate'
 };

+ 3 - 3
src/store/getters.js

@@ -13,9 +13,9 @@ export default {
     ) || {},
   // 根据字典enumName  和 dictCode 获取字典 值(名称
   getDictValue: (state) => (enumName, dictCode) => {
-    const obj = (state.dict[dictEnum[enumName]] || []).find(
-      (item) => item.dictCode === dictCode
-    );
+    const obj = (state.dict[dictEnum[enumName]] || []).find((item) => {
+      return item.dictCode === dictCode;
+    });
 
     return obj && obj.dictValue;
   }

+ 4 - 4
src/store/modules/dict.js

@@ -70,8 +70,8 @@ const actions = {
             const arr = Object.entries(item)[0] || [];
 
             return {
-              dictCode: arr[1],
-              dictValue: arr[0]
+              dictCode: arr[0],
+              dictValue: arr[1]
             };
           })
         });
@@ -92,8 +92,8 @@ const actions = {
           const arr = Object.entries(item);
 
           return {
-            dictCode: arr[1],
-            dictValue: arr[0]
+            dictCode: arr[0],
+            dictValue: arr[1]
           };
         })
       });

+ 4 - 1
src/utils/request.js

@@ -3,7 +3,7 @@
  */
 import axios from 'axios';
 import router from '@/router';
-import { MessageBox } from 'element-ui';
+import { MessageBox, Message } from 'element-ui';
 import { API_BASE_URL, TOKEN_HEADER_NAME, LAYOUT_PATH } from '@/config/setting';
 import { getToken, setToken } from './token-util';
 import { logout } from './page-tab-util';
@@ -44,6 +44,9 @@ service.interceptors.request.use(
 service.interceptors.response.use(
   (res) => {
     // token 自动续期
+    if (res.data.code == '-1' && res.config.showErrorToast !== false) {
+      Message.error(res.data.message);
+    }
     const token = res.headers[TOKEN_HEADER_NAME.toLowerCase()];
     if (token) {
       setToken(token);

+ 24 - 31
src/views/classifyManage/components/list-edit.vue

@@ -27,7 +27,7 @@
             placeholder="请输入"
           />
         </el-form-item>
-        <el-form-item label="类型用途:" prop="type" :key="data.id">
+        <el-form-item label="类型用途:" prop="type" :key="data && data.id + 1">
           <DictSelection dictName="类型用途" clearable v-model="formData.type">
           </DictSelection>
           <!-- <el-select
@@ -83,21 +83,8 @@
           />
         </el-form-item>
         <el-form-item label="与下层分隔:" prop="separate">
-          <el-select
-            class="w100"
-            clearable
-            type="textarea"
-            :maxlength="20"
-            v-model="formData.separate"
-            placeholder="请输入"
-          >
-            <el-option
-              v-for="item in splitList"
-              :key="item.code"
-              :label="item.label"
-              :value="item.code"
-            ></el-option>
-          </el-select>
+          <DictSelection dictName="分隔符" clearable v-model="formData.type">
+          </DictSelection>
         </el-form-item>
         <el-form-item label="本层排序:" prop="sort">
           <el-input
@@ -120,6 +107,7 @@
 
 <script>
   import { saveOrUpdate } from '@/api/classifyManage';
+  import dictMixins from '@/mixins/dictMixins';
 
   export default {
     props: {
@@ -129,6 +117,7 @@
         default: () => ({})
       }
     },
+    mixins: [dictMixins],
     data () {
       const defaultForm = {
         name: '',
@@ -144,18 +133,18 @@
         defaultForm,
         // 表单数据
         formData: { ...defaultForm },
-        typeList: [
-          { label: '产品分类', code: 3 },
-          { label: '摸具分类', code: 4 },
-          { label: '设备分类', code: 5 },
-          { label: '舟皿分类', code: 6 }
-        ],
-        splitList: [
-          { label: '无分隔符', code: '' },
-          { label: '-', code: '-' },
-          { label: '~', code: '~' },
-          { label: '/', code: '/' }
-        ],
+        // typeList: [
+        //   { label: '产品分类', code: 3 },
+        //   { label: '摸具分类', code: 4 },
+        //   { label: '设备分类', code: 5 },
+        //   { label: '舟皿分类', code: 6 }
+        // ],
+        // splitList: [
+        //   { label: '无分隔符', code: '' },
+        //   { label: '-', code: '-' },
+        //   { label: '~', code: '~' },
+        //   { label: '/', code: '/' }
+        // ],
         // 表单验证规则
         rules: {
           name: [
@@ -193,7 +182,6 @@
         let str = '';
         let codeStr = '';
         let node = this.curNode;
-        console.log(this.curNode);
         while (node?.data?.name) {
           str = node.data.name + '-' + str;
           codeStr = node.data.code + '-' + codeStr;
@@ -206,6 +194,7 @@
         );
       }
     },
+    created () {},
     methods: {
       open (data, parentData) {
         this.parentData = parentData;
@@ -221,10 +210,14 @@
           this.loading = true;
 
           const params = { ...this.formData };
-          if (this.parentData?.id) {
-            params.parentId = this.parentData?.id;
+          if (!this.data?.id && this.parentData?.id) {
+            params.parentId =
+              this.rootId == this.data?.id ? 0 : this.parentData.id;
             params.type = this.parentData.type;
           }
+          if (this.data?.id) {
+            params.id = this.data.id;
+          }
 
           saveOrUpdate(params)
             .then((msg) => {

+ 17 - 16
src/views/classifyManage/details.vue

@@ -46,6 +46,7 @@
               :data="treeData"
               :props="defaultProps"
               ref="treeRef"
+              :default-expanded-keys="current && current.id ? [current.id] : []"
               :highlight-current="true"
               node-key="id"
               @node-click="handleNodeClick"
@@ -77,7 +78,7 @@
                   <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
                     <el-form-item label="类型用途:">
                       <div class="ele-text-secondary">
-                        {{ current.type }}
+                        {{ getDictValue('类型用途', current.type + '') }}
                       </div>
                     </el-form-item>
                   </el-col>
@@ -145,6 +146,7 @@
 <script>
   import ListEdit from './components/list-edit.vue';
   import classifyManageEdit from './components/classifyManageEdit.vue';
+  import dictMixins from '@/mixins/dictMixins';
   import {
     getTreeByPid,
     getInfoById,
@@ -155,6 +157,7 @@
       classifyManageEdit,
       ListEdit
     },
+    mixins: [dictMixins],
     data () {
       return {
         loading: false,
@@ -182,35 +185,35 @@
         let codeStr = '';
         let node = this.curNode;
         while (node?.data?.name) {
-          str = node.data.name + node.data.separate + str;
-          codeStr = node.data.code + node.data.separate + codeStr;
+          str = node.data.name + '-' + str;
+          codeStr = node.data.code + '-' + codeStr;
           node = node?.parent;
         }
 
         return (
-          str.substring(0, str.length - 1) +
-          `(${codeStr.substring(0, codeStr.length - 1)})`
+          str.substring(str, str.length - 1) +
+          `(${codeStr.substring(str, str.length - 1)})`
         );
       }
     },
     created () {
+      this.requestDict('类型用途');
+      this.requestDict('分隔符');
       this.getTree().then(() => {
         this.$nextTick(() => {
           console.log(this.treeData[0]?.id);
           this.getDetail(this.treeData[0]?.id);
-          // this.$refs.treeRef.setCurrentKey(this.treeData[0]?.id);
-          // this.current = this.treeData[0];
-          // this.curNode = { data: this.current };
         });
       });
     },
     methods: {
-      reload (isEdit) {
+      async reload (isEdit) {
         if (isEdit) {
-          this.getDetail(this.current.id);
+          this.getTree().then(() => {
+            this.getDetail(this.current.id);
+          });
         } else {
           this.getTree();
-          0;
         }
       },
       handlOpen () {
@@ -225,10 +228,6 @@
             this.getTree().then(() => {
               this.$nextTick(() => {
                 this.getDetail(this.treeData[0]?.id);
-                // console.log(this.treeData[0]?.id);
-                // this.$refs.treeRef.setCurrentKey(this.treeData[0]?.id);
-                // this.current = this.treeData[0];
-                // this.curNode = { data: this.current };
               });
             });
             this.$message.success('删除成功!');
@@ -251,6 +250,9 @@
         this.loading = false;
         if (res.code == '0') {
           this.current = res.data;
+          this.$nextTick(() => {
+            this.$refs.treeRef.setCurrentKey(this.current.id);
+          });
         }
       },
       openEdit (isAdd = true) {
@@ -259,7 +261,6 @@
       handleNodeClick (data, node) {
         this.curNode = node;
         this.getDetail(data.id);
-        console.log(node);
       }
     }
   };

+ 20 - 2
src/views/classifyManage/index.vue

@@ -25,6 +25,17 @@
           >
             编辑
           </el-link>
+          <el-popconfirm
+            class="ele-action"
+            title="确定要删除此分类吗?"
+            @confirm="deleteCategory(row)"
+          >
+            <template v-slot:reference>
+              <el-link type="danger" :underline="false" icon="el-icon-delete">
+                删除
+              </el-link>
+            </template>
+          </el-popconfirm>
         </template>
       </ele-pro-table>
     </el-card>
@@ -35,7 +46,7 @@
 <script>
   import ListEdit from './components/list-edit.vue';
   import ClassifyManageSearch from './components/classifyManageSearch.vue';
-  import { getSubPage } from '@/api/classifyManage';
+  import { getSubPage, deleteCategory } from '@/api/classifyManage';
   export default {
     components: { ClassifyManageSearch, ListEdit },
     data () {
@@ -57,7 +68,7 @@
           {
             columnKey: 'action',
             label: '操作',
-            width: 120,
+            width: 150,
             align: 'center',
             slot: 'action',
             fixed: 'right'
@@ -81,6 +92,13 @@
       reload (params) {
         this.$refs.table.reload({ pageNum: 1, where: params });
       },
+      async deleteCategory ({ id }) {
+        const res = await deleteCategory(id);
+        if (res?.code == '0') {
+          this.$message.success('删除成功!');
+          this.$refs.table.reload();
+        }
+      },
       datasource ({ page, where, limit }) {
         return getSubPage({
           ...where,

+ 2 - 2
vue.config.js

@@ -18,8 +18,8 @@ module.exports = {
         // target: 'http://192.168.3.51:18086', // 跨域请求的地址
         // target: 'http://192.168.3.35:8080', // kang杨威
         // target: 'http://192.168.3.25:8080', // 黄峥嵘
-        // target: 'http://192.168.3.41:8080', // 何江鹏
-        target: 'http://192.168.3.33:8080', // 谢一平
+        target: 'http://192.168.3.41:8080', // 何江鹏
+        // target: 'http://192.168.3.33:8080', // 谢一平
 
         changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
         pathRewrite: {