diff --git a/src/utils/util.js b/src/utils/util.js
index 6ec26e0..eaf6311 100644
--- a/src/utils/util.js
+++ b/src/utils/util.js
@@ -86,6 +86,30 @@ export function listToTree(list, tree, parentId) {
return tree
}
+// 词典集合转树
+export function dictToTree(list, tree, parentId) {
+ list.forEach(item => {
+ if (item.parentid === parentId) {
+ let item_ = {};
+ item_.title = item.name;
+ item_.value = item.value;
+ item_.key = item.id;
+ const child = { ...item_, children: [] };
+
+ dictToTree(list, child.children, item.value);
+
+ if (child.children.length <= 0) {
+ delete child.children
+ }else{
+ child.selectable = false;
+ }
+
+ tree.push(child)
+ }
+ })
+ return tree
+}
+
//列表转🌲
// export function list2Tree(list, parentId) {
// let obj = []
diff --git a/src/views/course/CourseAdd.vue b/src/views/course/CourseAdd.vue
index 0e65736..373aa25 100644
--- a/src/views/course/CourseAdd.vue
+++ b/src/views/course/CourseAdd.vue
@@ -9,35 +9,27 @@
-
+
-
+
+
+
-
+
{{ dataValue }}分钟
@@ -91,14 +83,7 @@
-
+
上传
@@ -114,7 +99,7 @@
-
+
{{ item.name }}
@@ -132,6 +117,7 @@ import { courseAdd, getCourseDetails } from '@/api/course/course'
import storage from 'store'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import { dictionaryDropDown } from '@/api/sys/dictionaryItem'
+import { dictToTree } from '@/utils/util'
export default {
name: 'step1',
@@ -140,17 +126,17 @@ export default {
dataValue: 1,
form: {
coverPath: '',
- tags:[],
- courseTags:[]
+ tags: [],
+ courseTags: [],
},
url: '',
previewVisible: false,
fileList: [],
previewImage: [],
dictPerson: [],
- dictCourseType: [],
+ dictCourseType: [], // 课程类别
industry: [],
- dictCourseTag:[],
+ dictCourseTag: [],
}
},
components: {
@@ -161,21 +147,20 @@ export default {
this.dictionaryDropDown()
if (this.$route.query.id) {
getCourseDetails({ id: this.$route.query.id }).then((res) => {
- this.form = res.data;
- this.form.isRequired = this.form.isRequired + '';
+ this.form = res.data
+ this.form.isRequired = this.form.isRequired + ''
- this.form.tags = [];
- this.form.courseTags.forEach((item,index) => {
- this.form.tags.push(item.dictValue.toString());
- });
+ this.form.tags = []
+ this.form.courseTags.forEach((item, index) => {
+ this.form.tags.push(item.dictValue.toString())
+ })
})
}
},
methods: {
//显示页面上的数字
- onChange(dataValue) {
- },
+ onChange(dataValue) {},
save() {
courseAdd(this.form).then((res) => {
if (res.code == 200) {
@@ -194,17 +179,18 @@ export default {
})
// 课程类别
dictionaryDropDown({ dictionaryCode: '0006' }).then((res) => {
- this.dictCourseType = res.data
+ // 词典转树结构
+ this.dictCourseType = dictToTree(res.data, [], 0)
})
// 人员类型
dictionaryDropDown({ dictionaryCode: '0005' }).then((res) => {
this.dictPerson = res.data
})
// 标签项 默认选中的多选框
- dictionaryDropDown({dictionaryCode: '0008'}).then((res) => {
+ dictionaryDropDown({ dictionaryCode: '0008' }).then((res) => {
const tagList = res.data
- for ( let i = 0; i < tagList.length; i++) {
- tagList[i].value = tagList[i].value.toString()
+ for (let i = 0; i < tagList.length; i++) {
+ tagList[i].value = tagList[i].value.toString()
}
this.dictCourseTag = tagList
})
@@ -225,8 +211,7 @@ export default {
hreader[ACCESS_TOKEN] = storage.get(ACCESS_TOKEN)
return hreader
},
- onSuccess(file) {
- },
+ onSuccess(file) {},
handleCancel() {
this.previewVisible = false
},
@@ -246,7 +231,7 @@ export default {
//标签选择器
handleTagChange(value) {
- this.form.tags = value;
+ this.form.tags = value
},
},
}