Przeglądaj źródła

fix: 调整使用工厂组件的方式

wuzh 4 dni temu
rodzic
commit
622e4d4504

+ 10 - 0
src/api/factoryModel/index.js

@@ -36,6 +36,16 @@ export async function getFactoryarea(params) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+// 获取所有工厂
+export async function getFactoryList() {
+  const res = await request.get(`/main/factoryarea/getFactoryList`);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
 // 删除
 export async function deletefactoryarea(params) {
   const res = await request.get(`/main/factoryarea/delete/${params}`);

+ 9 - 14
src/components/CommomSelect/factory-select.vue

@@ -12,13 +12,13 @@
       v-for="item in dictList"
       :key="item.id"
       :label="item.name"
-      :value="item.id"
+      :value="String(item.id)"
     ></el-option>
   </el-select>
 </template>
 
 <script>
-  import route from '@/api/technology/route';
+  import { getFactoryList } from '@/api/factoryModel';
   export default {
     model: {
       prop: 'value',
@@ -34,39 +34,34 @@
         default: true
       }
     },
-    data () {
+    data() {
       return {
         dictList: []
       };
     },
     computed: {
       selectVal: {
-        set (val) {
+        set(val) {
           this.$emit(
             'selfChange',
             val,
-            this.dictList.find((i) => i.id === val)
+            this.dictList.find((i) => String(i.id) === String(val))
           );
           this.$emit('updateVal', val);
         },
-        get () {
+        get() {
           return this.value;
         }
       }
     },
-    created () {
+    created() {
       if (this.init) {
         this.getList();
       }
     },
     methods: {
-      async getList () {
-        const res = await route.Flist({
-          pageNum: 1,
-          size: -1,
-          type: 1
-        });
-        this.dictList = res.list;
+      async getList() {
+        this.dictList = (await getFactoryList()) || [];
       }
     }
   };

+ 12 - 3
src/views/system/externalClient/components/external-client-edit.vue

@@ -170,11 +170,19 @@
       }
     },
     methods: {
+      normalizeFactoriesId(value) {
+        return value === null || value === undefined || value === ''
+          ? ''
+          : String(value);
+      },
       async initForm() {
         this.isUpdate = Boolean(this.data && this.data.id);
         this.form = {
           ...defaultForm,
-          ...(this.data || {})
+          ...(this.data || {}),
+          factoriesId: this.normalizeFactoriesId(
+            this.data && this.data.factoriesId
+          )
         };
         if (!this.isUpdate) {
           return;
@@ -184,7 +192,8 @@
           const detail = await getExternalClient(this.data.id);
           this.form = {
             ...defaultForm,
-            ...detail
+            ...detail,
+            factoriesId: this.normalizeFactoriesId(detail && detail.factoriesId)
           };
         } catch (error) {
           this.$message.error(error.message || '获取客户端详情失败');
@@ -216,7 +225,7 @@
             systemName: this.form.systemName,
             systemCode: this.form.systemCode,
             factoriesId: this.form.factoriesId
-              ? Number(this.form.factoriesId)
+              ? String(this.form.factoriesId)
               : undefined,
             effectiveTime: this.form.effectiveTime || undefined,
             expireTime: this.form.expireTime || undefined,

+ 21 - 1
src/views/system/externalClient/index.vue

@@ -30,6 +30,9 @@
             {{ Number(row.status) === 1 ? '启用' : '禁用' }}
           </el-tag>
         </template>
+        <template v-slot:factoriesId="{ row }">
+          {{ getFactoryName(row.factoriesId) }}
+        </template>
         <template v-slot:action="{ row }">
           <el-link
             v-if="row.clientId"
@@ -134,6 +137,7 @@
   import tabMixins from '@/mixins/tableColumnsMixin';
   import ExternalClientSearch from './components/external-client-search.vue';
   import ExternalClientEdit from './components/external-client-edit.vue';
+  import { getFactoryList } from '@/api/factoryModel';
   import {
     pageExternalClients,
     setExternalClientStatus,
@@ -234,10 +238,26 @@
         pageSize: this.$store.state.tablePageSize,
         cacheKeyUrl: 'external-client-management',
         secretVisible: false,
-        clientSecret: ''
+        clientSecret: '',
+        factoryList: []
       };
     },
+    created() {
+      this.loadFactoryList();
+    },
     methods: {
+      async loadFactoryList() {
+        this.factoryList = (await getFactoryList()) || [];
+      },
+      getFactoryName(id) {
+        if (!id) {
+          return '全部工厂';
+        }
+        const factory = this.factoryList.find(
+          (item) => String(item.id) === String(id)
+        );
+        return factory ? factory.name : id;
+      },
       datasource({ page, limit, where, order }) {
         return pageExternalClients({
           ...where,