diff --git a/src/api/index.js b/src/api/index.js index 875b53d..4b82e93 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -458,6 +458,8 @@ export default { systemModelByTeacher: `nakadai/nakadai/model/reference/demo/systemModelByTeacher`, demoHiddenOpen: `nakadai/model/demo/hidden/batchOpen`, demoHiddenClose: `nakadai/model/demo/hidden/batchShutdown`, + teacherModelList: `nakadai/nakadai/model/reference/demo/teacherModelList`, + saveModel: `nakadai/nakadai/model/reference/demo/save`, // 教师评语 addComment: `evaluation/cevaluation/comment/addComment`, diff --git a/src/pages/expSystem/backstage/addModel.vue b/src/pages/expSystem/backstage/addModel.vue index ee122d5..4ba4b5d 100644 --- a/src/pages/expSystem/backstage/addModel.vue +++ b/src/pages/expSystem/backstage/addModel.vue @@ -54,6 +54,7 @@ export default { return { systemId: +this.$route.query.systemId, categoryId: +this.$route.query.categoryId, + founder: +this.$route.query.founder, id: +this.$route.query.id, postStatus: +this.$route.query.postStatus, isDetail: Boolean(this.$route.query.show), // 是否是查看 @@ -115,7 +116,7 @@ export default { }, // 获取分类 getType () { - this.$post(this.api.sourceModelClassification + '?founder=1').then(({ data }) => { + this.$post(this.api.sourceModelClassification + '?founder=' + (this.isDetail ? this.founder : 1)).then(({ data }) => { // 没有子级,删除children属性 const handleLeaf = list => { list.map(e => { @@ -131,7 +132,7 @@ export default { if (this.id) { this.getData() } else { - this.handleId(data, this.categoryId) + this.handleId(data[0].children, this.categoryId) } }).catch(res => { }) }, diff --git a/src/pages/expSystem/backstage/model.vue b/src/pages/expSystem/backstage/model.vue index 6f025f8..506462f 100644 --- a/src/pages/expSystem/backstage/model.vue +++ b/src/pages/expSystem/backstage/model.vue @@ -56,7 +56,7 @@ { - this.listData = res.data.records - this.total = res.data.total - }).catch(res => { }) - } else { - this.$post(this.api.referenceDemoList, { - modelName: this.keyword, - pageNum: this.page, - pageSize: this.pageSize, - categoryId: curNode.id, - founder: 1 - }).then(res => { - this.listData = res.data.records - this.total = res.data.total - }).catch(res => { }) + if (curNode) { + this.isTopLevel = !curNode.level + // 如果是首级,要调另一个接口 + if (this.isTopLevel) { + this.$post(this.api.teacherModelList, { + founder: 1, + modelName: this.keyword, + pageNum: this.page, + pageSize: this.pageSize, + systemId: this.systemId + }).then(res => { + this.listData = res.data.records + this.total = res.data.total + }).catch(res => { }) + } else { + this.$post(this.api.referenceDemoList, { + modelName: this.keyword, + pageNum: this.page, + pageSize: this.pageSize, + categoryId: curNode.id, + founder: 1 + }).then(res => { + this.listData = res.data.records + this.total = res.data.total + }).catch(res => { }) + } } }, getData () { diff --git a/src/pages/expSystem/backstage/modelType.vue b/src/pages/expSystem/backstage/modelType.vue index 7851080..d98b601 100644 --- a/src/pages/expSystem/backstage/modelType.vue +++ b/src/pages/expSystem/backstage/modelType.vue @@ -13,7 +13,6 @@ icon="el-icon-refresh" @click="syncModel">同步原始模型列表 添加 @@ -95,7 +94,8 @@ export default { categoryName: [ { required: true, message: "请输入分类名称", trigger: "blur" } ] - } + }, + promises: [] }; }, components: { @@ -147,21 +147,6 @@ export default { }).catch(err => { }) this.$emit('initData') }, - syncModelData () { - // 同步原始模型前删除原有数据 - this.$post(`${this.api.delModelInfoBySystemId}?systemId=${this.systemId}&founder=1`).then(res => { - this.$post(`${this.api.synchronizationMdelByOccupationlab}?systemId=${this.systemId}`).then(res => { - this.$router.push({ - path: 'backstage', - query: { - ...this.$route.query, - categoryId: '' - } - }) - this.getType() - }) - }).catch(() => { }) - }, syncModel () { if (this.orgList.length) { this.$confirm('同步后当前的组织架构将会被删除,是否继续?', '提示', { @@ -173,6 +158,65 @@ export default { this.syncModelData() } }, + // 同步数据 + async syncModelData () { + // 同步原始模型前删除原有数据 + await this.$post(`${this.api.delModelInfoBySystemId}?systemId=${this.systemId}&founder=1`) + /** + * 先调同步接口把老师端源模型里面的内置模型同步过来,这一步后端做。 + * 然后接口会返回“全部”这个分类的id,然后把本校分类及模型全部加到全部这个分类下 + */ + const { id } = await this.$post(`${this.api.synchronizationMdelByOccupationlab}?systemId=${this.systemId}`) + + const { data } = await this.$post(this.api.sourceModelClassification + '?founder=1') // 本校分类 + this.handleCatetory(data[0].children, id) + Promise.all(this.promises).then(() => { + this.getType() + this.$router.push({ + path: 'backstage', + query: { + ...this.$route.query, + categoryId: '' + } + }) + }).catch(e => { }) + }, + // 递归添加分类及模型 + handleCatetory (list, parentId) { + this.promises.push(...list.map(async e => { + // 新增分类 + const res = await this.$post(this.api.saveReferenceCategory, { + parentId, + categoryName: e.categoryName, + systemId: this.systemId, + level: e.level, + founder: 1 + }) + // 获取分类下的所有模型 + const { data } = await this.$post(this.api.InstitutionSourceModel, { + pageNum: 1, + pageSize: 10000, + systemId: this.systemId, + founder: 1, + categoryId: e.id + }) + // 新增完分类,获取到分类id后,再添加模型到新增的分类上 + data.records.map(async n => { + await this.$post(this.api.saveModel, { + categoryId: res.referenceCategoryId, + copyId: n.id, + modelName: n.modelName, + modelDemo: n.modelDemo, + postStatus: n.postStatus, + systemId: this.systemId, + founder: 1 + }) + }) + e.children && this.handleCatetory(e.children, res.referenceCategoryId) + })) + }, + + // 添加分类和模型 async addData (id) { // 查询源模型分类 diff --git a/src/pages/expSystem/backstage/sourceModel.vue b/src/pages/expSystem/backstage/sourceModel.vue index acfcf56..8fa6660 100644 --- a/src/pages/expSystem/backstage/sourceModel.vue +++ b/src/pages/expSystem/backstage/sourceModel.vue @@ -237,7 +237,7 @@ export default { }, // 查看 show (row) { - this.$router.push(`addModel?categoryId=${this.$refs.tree.$refs.tree.getCurrentKey()}&id=${row.id}&show=1`) + this.$router.push(`addModel?categoryId=${this.$refs.tree.$refs.tree.getCurrentKey()}&id=${row.id}&show=1&founder=${this.isSystem ? 0 : 1}`) }, // 编辑 edit (row) {