From 6008670bc89f2f83d05cbf94e1004275ced6da7a Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Mon, 5 Jun 2023 15:29:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/expSystem/backstage/addModel.vue | 7 +- src/pages/expSystem/backstage/model.vue | 163 ++++++++++---------- src/pages/expSystem/backstage/modelType.vue | 1 + src/pages/expSystem/list/index.vue | 2 +- 4 files changed, 90 insertions(+), 83 deletions(-) diff --git a/src/pages/expSystem/backstage/addModel.vue b/src/pages/expSystem/backstage/addModel.vue index e8e24ba..ee122d5 100644 --- a/src/pages/expSystem/backstage/addModel.vue +++ b/src/pages/expSystem/backstage/addModel.vue @@ -102,15 +102,16 @@ export default { }, // 处理id handleId (list, id, parentId = []) { - list.map(e => { + for (const e of list) { // 取得父级id跟子级id的集合 if (id === e.id) { - parentId.shift() // 全部的id要去掉 + // parentId.shift() // 全部的id要去掉 this.categoryIdCus = [...parentId, e.id] + break } else { e.children && this.handleId(e.children, id, [...parentId, e.id]) } - }) + } }, // 获取分类 getType () { diff --git a/src/pages/expSystem/backstage/model.vue b/src/pages/expSystem/backstage/model.vue index 6068b41..6f025f8 100644 --- a/src/pages/expSystem/backstage/model.vue +++ b/src/pages/expSystem/backstage/model.vue @@ -85,17 +85,26 @@ :visible.sync="modelVisible" width="500px" class="dialog" - :close-on-click-modal="false"> + :close-on-click-modal="false" + v-loading="modelLoading">
- + + +
暂无可导入的模型
@@ -124,7 +133,8 @@ export default { multipleSelection: [], modelVisible: false, modelLoading: false, - modelData: [], + schoolModels: [], + systemModels: [], submiting: false, timer: null }; @@ -195,83 +205,77 @@ export default { this.getData() }, // 导入模型 - add () { + async add () { if (!this.$refs.tree.orgList.length) return this.$message.error('请先添加模型分类') if (this.isTopLevel) return this.$message.error('请选择子分类进入导入模型') this.modelVisible = true this.modelLoading = true - // 获取模型列表,用以跟源模型列表作比对,重复的不再显示 - this.$post(this.api.getAllModelList, { - founder: 1, - pageNum: 1, - pageSize: 10000, - systemId: this.systemId, - isOpen: 0 - }).then(res => { - const modelList = res.data.records - // 本校分类及模型 - // 查询源模型分类 - this.$post(this.api.sourceModelClassification + '?founder=1').then(({ data }) => { - const promises = [] - const addType = list => { - list.map((e, i) => { - // 用promise储存以添加完后更新数据 - promises.push(new Promise((resolve, reject) => { - // 获取源模型列表 - this.$post(this.api.sysModelDemoList, { - pageNum: 1, - pageSize: 10000, - categoryId: e.id, - founder: 1, - postStatus: 1, - isOpen: 0, - ztOpen: 0 - }).then(res => { - const { records } = res.data - const modelChildren = [] - // 判重,重复的模型不再显示,通过模型的copyId和源模型的id作比对 - records.map(n => { - if (!modelList.find(e => e.copyId === n.id)) { - n.categoryName = n.modelName - modelChildren.push(n) - } - }) - // 如果有未导入的模型,则添加到子级,否则设置为disabled - if (modelChildren.length) { - e.children = [...e.children, ...modelChildren] - } else if (records.length) { - e.disabled = true - } - resolve() - }).catch(res => { - reject() - }) - })) - e.children && e.children.length && addType(e.children) - }) - } - addType(data) - // 筛选出disabled不为true的分类,因为没有模型的分类不需要展示 - const handleType = list => { - return list.filter((e, i) => { - return !e.disabled - }).map(e => { - if (e.children) { - e.children = handleType(e.children) + // 本校分类模型跟系统内置分类模型的接口不一样,分开处理 + // 查询源模型分类 + let { data } = await this.$post(this.api.sourceModelClassification + '?founder=1') + const promises = [] + const addType = (list, system = 0) => { + list.map((e, i) => { + // 用promise储存以添加完后更新数据 + promises.push(new Promise(async (resolve, reject) => { + try { + // 获取源模型列表 + const res = await this.$post(this.api[system ? 'sortReadingModelByTeacherSideSystem' : 'InstitutionSourceModel'], { + pageNum: 1, + pageSize: 10000, + categoryId: e.id, + founder: system ? 0 : 1, + postStatus: 1, + isOpen: 0, + ztOpen: 0 + }) + const { records } = res.data + const modelChildren = [] + // 判重,重复的模型不再显示,通过模型的copyId和源模型的id作比对 + records.map(n => { + n.categoryName = n.modelName + modelChildren.push(n) + }) + // 如果有未导入的模型,则添加到子级,否则设置为disabled + if (modelChildren.length) { + e.children = [...e.children, ...modelChildren] + } else if (records.length) { + e.disabled = true } - return e - }) - } - Promise.all(promises).then(_ => { - data = handleType(data) - this.modelData = (data.length && data[0].children && data[0].children.length) ? data : [] - this.modelLoading = false - }).catch(res => { }) - }).catch(res => { }) + resolve() + } catch (error) { + reject() + } + })) + e.children && e.children.length && addType(e.children, system) + }) + } + addType(data) + + // 系统内置模型 + const res = await this.$post(`${this.api.builtInClassificationByNakadai}?systemId=${this.systemId}`) + addType(res.data, 1) + + Promise.all(promises).then(_ => { + data = this.handleType(data) + const systemData = this.handleType(res.data) + this.schoolModels = (data.length && data[0].children && data[0].children.length) ? data : [] + this.systemModels = (systemData.length && systemData[0].children && systemData[0].children.length) ? systemData : [] + this.modelLoading = false }).catch(res => { }) }, - // 把删除了的分类去除 + // 筛选出disabled不为true的分类,因为没有模型的分类不需要展示 + handleType (list) { + return list.filter((e, i) => { + return !e.disabled + }).map(e => { + if (e.children) { + e.children = this.handleType(e.children) + } + return e + }) + }, // 查看模型 show (row) { @@ -323,9 +327,10 @@ export default { submit () { if (this.submiting) return false const data = [] - const systemId = this.systemId - if (this.$refs.model) { - const list = this.$refs.model.getCheckedNodes() // 获取选择的分类模型 + const { systemId } = this + const { schoolModel, systemModel } = this.$refs + if (schoolModel || systemModel) { + const list = [...schoolModel.getCheckedNodes(), ...systemModel.getCheckedNodes()] // 获取选择的分类模型 const categoryId = this.$refs.tree.$refs.tree.getCurrentKey() // 获取当前分类 if (!list.length) return this.$message.error('请选择模型') this.submiting = true @@ -334,7 +339,7 @@ export default { e.categoryId && data.push({ systemId, categoryId, - copyId: e.id + copyId: e.founder ? e.id : e.copyId // 系统模型取copyId,本校模型取id }) }) this.$post(this.api.saveReferenceDemo, data).then(res => { diff --git a/src/pages/expSystem/backstage/modelType.vue b/src/pages/expSystem/backstage/modelType.vue index bdf2693..7851080 100644 --- a/src/pages/expSystem/backstage/modelType.vue +++ b/src/pages/expSystem/backstage/modelType.vue @@ -13,6 +13,7 @@ icon="el-icon-refresh" @click="syncModel">同步原始模型列表 添加 diff --git a/src/pages/expSystem/list/index.vue b/src/pages/expSystem/list/index.vue index 30644cd..9f2e840 100644 --- a/src/pages/expSystem/list/index.vue +++ b/src/pages/expSystem/list/index.vue @@ -83,7 +83,7 @@ export default { systemType: "", systemSearch: "", searchTimer: null, - systemData: [{}], + systemData: [], totals: 0, systemBelongKeys: { 1: '外部产品',