|
@@ -20,9 +20,8 @@
|
|
|
>
|
|
|
<SvgIcon name="tag" size="14" class="mr-1" />
|
|
|
<span class="max-w-[5rem]" v-title>{{
|
|
|
- value
|
|
|
+ value?.length > 0
|
|
|
? value
|
|
|
- .split(',')
|
|
|
.map((v) => DictionaryStore.knowledgeTags.map.get(v) || v)
|
|
|
.join(',')
|
|
|
: '添加标签'
|
|
@@ -117,7 +116,10 @@
|
|
|
:show-submit="false"
|
|
|
:show-close="false"
|
|
|
>
|
|
|
- <div class="bm-form mb-[1rem] flex flex-wrap gap-2">
|
|
|
+ <div
|
|
|
+ class="bm-form mb-[1rem] flex flex-wrap gap-2"
|
|
|
+ v-loading="state.loading"
|
|
|
+ >
|
|
|
<template v-for="item in DictionaryStore.knowledgeTags.list">
|
|
|
<template v-if="item.__edit">
|
|
|
<div
|
|
@@ -166,15 +168,18 @@ import {
|
|
|
computed,
|
|
|
getCurrentInstance,
|
|
|
onBeforeMount,
|
|
|
+ onMounted,
|
|
|
reactive,
|
|
|
ref,
|
|
|
watch,
|
|
|
} from 'vue'
|
|
|
import { domRootHasAttr } from '@/utils/czr-util'
|
|
|
-import { useDialogStore, useDictionaryStore } from '@/stores'
|
|
|
+import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
|
|
|
import { Search } from '@element-plus/icons-vue'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
+import { tagsAdd, tagsDel, tagsEdit } from '@/api/modules/knowledge/tags'
|
|
|
|
|
|
+const AppStore = useAppStore()
|
|
|
const DictionaryStore = useDictionaryStore()
|
|
|
const DialogStore = useDialogStore()
|
|
|
const emit = defineEmits(['onChange'])
|
|
@@ -185,20 +190,44 @@ const props = defineProps({
|
|
|
})
|
|
|
const { proxy }: any = getCurrentInstance()
|
|
|
const state: any = reactive({
|
|
|
+ loading: false,
|
|
|
show: false,
|
|
|
text: '',
|
|
|
valueMap: new Map(),
|
|
|
showDialog: false,
|
|
|
+ init: false,
|
|
|
})
|
|
|
const onAdd = () => {
|
|
|
- state.text = ''
|
|
|
- ElMessage.success('创建标签成功!')
|
|
|
- DictionaryStore.initKnowledgeTags()
|
|
|
+ tagsAdd({
|
|
|
+ tenantId: AppStore.tenantInfo?.id,
|
|
|
+ name: state.text,
|
|
|
+ type: 'dataset',
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ state.text = ''
|
|
|
+ ElMessage.success('创建标签成功!')
|
|
|
+ })
|
|
|
+ .catch(({ message }: any) => {
|
|
|
+ ElMessage.error(message)
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ DictionaryStore.initKnowledgeTags(AppStore.tenantInfo?.id)
|
|
|
+ })
|
|
|
}
|
|
|
const onDel = (row) => {
|
|
|
const delHandle = () => {
|
|
|
- ElMessage.success('删除标签成功!')
|
|
|
- DictionaryStore.initKnowledgeTags()
|
|
|
+ state.loading = true
|
|
|
+ tagsDel(row.id)
|
|
|
+ .then(() => {
|
|
|
+ ElMessage.success('删除标签成功!')
|
|
|
+ })
|
|
|
+ .catch(({ message }: any) => {
|
|
|
+ ElMessage.error(message)
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ DictionaryStore.initKnowledgeTags(AppStore.tenantInfo?.id)
|
|
|
+ state.loading = false
|
|
|
+ })
|
|
|
}
|
|
|
if (row.total > 0) {
|
|
|
DialogStore.confirm({
|
|
@@ -216,8 +245,23 @@ const onEdit = (row) => {
|
|
|
if (!row.__value) {
|
|
|
row.__edit = false
|
|
|
} else {
|
|
|
- ElMessage.success('修改标签成功!')
|
|
|
- DictionaryStore.initKnowledgeTags()
|
|
|
+ state.loading = true
|
|
|
+ tagsEdit({
|
|
|
+ tenantId: AppStore.tenantInfo?.id,
|
|
|
+ id: String(row.id),
|
|
|
+ name: row.__value,
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ ElMessage.success('修改标签成功!')
|
|
|
+ })
|
|
|
+ .catch(({ message }: any) => {
|
|
|
+ row.__edit = false
|
|
|
+ ElMessage.error(message)
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ DictionaryStore.initKnowledgeTags(AppStore.tenantInfo?.id)
|
|
|
+ state.loading = false
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -229,12 +273,14 @@ const onMouseDown = (e) => {
|
|
|
watch(
|
|
|
() => state.show,
|
|
|
(n) => {
|
|
|
- if (n) {
|
|
|
- state.text = ''
|
|
|
- document.addEventListener('mousedown', onMouseDown)
|
|
|
- } else {
|
|
|
- document.removeEventListener('mousedown', onMouseDown)
|
|
|
- emit('onChange', Array.from(state.valueMap.keys()).join(','))
|
|
|
+ if (state.init) {
|
|
|
+ if (n) {
|
|
|
+ state.text = ''
|
|
|
+ document.addEventListener('mousedown', onMouseDown)
|
|
|
+ } else {
|
|
|
+ document.removeEventListener('mousedown', onMouseDown)
|
|
|
+ emit('onChange', Array.from(state.valueMap.keys()))
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
{ immediate: true },
|
|
@@ -244,7 +290,7 @@ watch(
|
|
|
(n) => {
|
|
|
const map = new Map()
|
|
|
if (n) {
|
|
|
- n.split(',').forEach((v) => {
|
|
|
+ n?.forEach((v) => {
|
|
|
map.set(v, v)
|
|
|
})
|
|
|
}
|
|
@@ -253,7 +299,10 @@ watch(
|
|
|
{ immediate: true },
|
|
|
)
|
|
|
onBeforeMount(() => {
|
|
|
- DictionaryStore.initKnowledgeTags()
|
|
|
+ DictionaryStore.initKnowledgeTags(AppStore.tenantInfo?.id)
|
|
|
+})
|
|
|
+onMounted(() => {
|
|
|
+ state.init = true
|
|
|
})
|
|
|
</script>
|
|
|
|