|
|
@ -6,6 +6,7 @@
|
|
|
|
v-model="categoryIdString"
|
|
|
|
v-model="categoryIdString"
|
|
|
|
placeholder="请选择上级目录,默认为顶级目录"
|
|
|
|
placeholder="请选择上级目录,默认为顶级目录"
|
|
|
|
treeDefaultExpandAll
|
|
|
|
treeDefaultExpandAll
|
|
|
|
|
|
|
|
@change="handleChange"
|
|
|
|
>
|
|
|
|
>
|
|
|
|
</a-tree-select>
|
|
|
|
</a-tree-select>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
@ -23,26 +24,23 @@ export default {
|
|
|
|
type: Array,
|
|
|
|
type: Array,
|
|
|
|
required: false,
|
|
|
|
required: false,
|
|
|
|
default: () => []
|
|
|
|
default: () => []
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
root: {
|
|
|
|
categoryTreeData() {
|
|
|
|
type: Object,
|
|
|
|
return [
|
|
|
|
required: false,
|
|
|
|
{
|
|
|
|
default: () => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: 0,
|
|
|
|
id: 0,
|
|
|
|
title: '根目录',
|
|
|
|
title: '根目录',
|
|
|
|
value: '0',
|
|
|
|
value: '0',
|
|
|
|
pId: -1
|
|
|
|
pId: -1
|
|
|
|
},
|
|
|
|
|
|
|
|
...this.categories.map(category => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
id: category.id,
|
|
|
|
|
|
|
|
title: category.name,
|
|
|
|
|
|
|
|
value: category.id.toString(),
|
|
|
|
|
|
|
|
pId: category.parentId
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
|
|
categoryTreeData() {
|
|
|
|
|
|
|
|
return [this.root, ...this.convertDataToTree(this.categories)]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
categoryIdString: {
|
|
|
|
categoryIdString: {
|
|
|
|
get() {
|
|
|
|
get() {
|
|
|
@ -52,6 +50,52 @@ export default {
|
|
|
|
this.$emit('update:categoryId', value ? parseInt(value) : 0)
|
|
|
|
this.$emit('update:categoryId', value ? parseInt(value) : 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
handleChange() {
|
|
|
|
|
|
|
|
this.$emit('change')
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
convertDataToTree(categories) {
|
|
|
|
|
|
|
|
const hashMap = {}
|
|
|
|
|
|
|
|
const treeData = []
|
|
|
|
|
|
|
|
categories.forEach(
|
|
|
|
|
|
|
|
category =>
|
|
|
|
|
|
|
|
(hashMap[category.id] = {
|
|
|
|
|
|
|
|
...category,
|
|
|
|
|
|
|
|
title: category.name,
|
|
|
|
|
|
|
|
value: category.id.toString(),
|
|
|
|
|
|
|
|
pId: category.parentId,
|
|
|
|
|
|
|
|
children: []
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
categories.forEach(category => {
|
|
|
|
|
|
|
|
const current = hashMap[category.id]
|
|
|
|
|
|
|
|
if (category.parentId) {
|
|
|
|
|
|
|
|
hashMap[category.parentId].children.push(current)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
treeData.push(current)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set hasPassword field for tree node
|
|
|
|
|
|
|
|
const setHasPasswordField = (categories, hasPassword = false) => {
|
|
|
|
|
|
|
|
categories.forEach(category => {
|
|
|
|
|
|
|
|
category.hasPassword = !!category.password || hasPassword
|
|
|
|
|
|
|
|
if (category.hasPassword) {
|
|
|
|
|
|
|
|
category.title = `${category.title}(加密)`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object.hasOwn(category, 'postCount')) {
|
|
|
|
|
|
|
|
category.title = `${category.title} - ${category.postCount} 篇`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (category.children && category.children.length) {
|
|
|
|
|
|
|
|
setHasPasswordField(category.children, category.hasPassword)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setHasPasswordField(treeData)
|
|
|
|
|
|
|
|
return treeData
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|