UnisKB/ui/src/views/problem/component/DetailProblemDrawer.vue

226 lines
6.0 KiB
Vue
Raw Normal View History

2025-05-30 06:34:24 +00:00
<template>
<el-drawer v-model="visible" size="60%" @close="closeHandle">
<template #header>
<h4>{{ $t('views.problem.detailProblem') }}</h4>
</template>
<div>
<el-scrollbar>
<div class="p-8">
<el-form label-position="top" v-loading="loading" @submit.prevent>
<el-form-item :label="$t('views.problem.title')">
<ReadWrite
@change="editName"
:data="currentContent"
2025-07-16 10:40:10 +00:00
:showEditIcon="permissionPrecise.problem_edit(id as string)"
2025-05-30 06:34:24 +00:00
:maxlength="256"
/>
</el-form-item>
<el-form-item :label="$t('views.problem.relateParagraph.title')">
<template v-for="(item, index) in paragraphList" :key="index">
<CardBox
:title="item.title || '-'"
2025-06-25 08:59:42 +00:00
class="cursor mb-8"
2025-05-30 06:34:24 +00:00
:showIcon="false"
2025-07-16 10:40:10 +00:00
@click.stop="permissionPrecise.doc_edit(id as string) && editParagraph(item)"
2025-06-25 08:59:42 +00:00
style="height: 210px"
2025-05-30 06:34:24 +00:00
>
2025-06-25 08:59:42 +00:00
<template #tag>
<el-tooltip
effect="dark"
:content="$t('views.problem.setting.cancelRelated')"
placement="top"
>
<el-button
type="primary"
text
@click.stop="disassociation(item)"
2025-08-01 02:59:37 +00:00
v-if="permissionPrecise.problem_relate(id as string)"
2025-07-16 10:40:10 +00:00
>
2025-06-25 08:59:42 +00:00
<AppIcon iconName="app-quxiaoguanlian"></AppIcon>
</el-button>
</el-tooltip>
2025-05-30 06:34:24 +00:00
</template>
2025-06-25 08:59:42 +00:00
<el-scrollbar height="110">
{{ item.content }}
</el-scrollbar>
2025-05-30 06:34:24 +00:00
<template #footer>
<div class="footer-content flex-between">
<el-text>
<el-icon>
<Document />
</el-icon>
{{ item?.document_name }}
</el-text>
</div>
</template>
</CardBox>
</template>
</el-form-item>
</el-form>
</div>
</el-scrollbar>
<ParagraphDialog
ref="ParagraphDialogRef"
:title="$t('views.paragraph.editParagraph')"
2025-06-25 08:59:42 +00:00
:apiType="apiType"
2025-05-30 06:34:24 +00:00
@refresh="refresh"
/>
<RelateProblemDialog ref="RelateProblemDialogRef" @refresh="refresh" />
</div>
<template #footer>
<div>
<el-button @click="relateProblem" v-if="permissionPrecise.doc_edit(id as string)">{{
2025-05-30 06:34:24 +00:00
$t('views.problem.relateParagraph.title')
}}</el-button>
<el-button @click="pre" :disabled="pre_disable || loading">{{
2025-06-11 11:15:17 +00:00
$t('views.chatLog.buttons.prev')
2025-05-30 06:34:24 +00:00
}}</el-button>
<el-button @click="next" :disabled="next_disable || loading">{{
2025-06-11 11:15:17 +00:00
$t('views.chatLog.buttons.next')
2025-05-30 06:34:24 +00:00
}}</el-button>
</div>
</template>
</el-drawer>
</template>
<script setup lang="ts">
import { ref, reactive, computed, watch } from 'vue'
import { useRoute } from 'vue-router'
import ParagraphDialog from '@/views/paragraph/component/ParagraphDialog.vue'
import RelateProblemDialog from './RelateProblemDialog.vue'
import { MsgSuccess, MsgConfirm, MsgError } from '@/utils/message'
2025-06-25 08:59:42 +00:00
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
2025-07-16 10:40:10 +00:00
import permissionMap from '@/permission'
2025-05-30 06:34:24 +00:00
import { t } from '@/locales'
const props = withDefaults(
defineProps<{
/**
* 当前的id
*/
currentId: string
currentContent: string
/**
* 下一条
*/
next: () => void
/**
* 上一条
*/
pre: () => void
pre_disable: boolean
next_disable: boolean
}>(),
2025-06-13 09:17:01 +00:00
{},
2025-05-30 06:34:24 +00:00
)
const emit = defineEmits(['update:currentId', 'update:currentContent', 'refresh'])
const route = useRoute()
const {
2025-06-13 09:17:01 +00:00
params: { id },
2025-05-30 06:34:24 +00:00
} = route
2025-06-25 08:59:42 +00:00
const apiType = computed(() => {
if (route.path.includes('shared')) {
return 'systemShare'
} else if (route.path.includes('resource-management')) {
return 'systemManage'
} else {
return 'workspace'
}
})
2025-07-16 10:40:10 +00:00
const permissionPrecise = computed(() => {
return permissionMap['knowledge'][apiType.value]
})
2025-05-30 06:34:24 +00:00
const RelateProblemDialogRef = ref()
const ParagraphDialogRef = ref()
const loading = ref(false)
const visible = ref(false)
const paragraphList = ref<any[]>([])
function disassociation(item: any) {
2025-06-25 08:59:42 +00:00
const obj = {
paragraph_id: item.id,
problem_id: props.currentId,
}
loadSharedApi({ type: 'paragraph', systemType: apiType.value })
.putDisassociationProblem(item.knowledge_id, item.document_id, obj, loading)
2025-05-30 06:34:24 +00:00
.then(() => {
getRecord()
})
}
function relateProblem() {
RelateProblemDialogRef.value.open([props.currentId])
}
function editParagraph(row: any) {
ParagraphDialogRef.value.open(row)
}
function editName(val: string) {
if (val) {
const obj = {
2025-06-13 09:17:01 +00:00
content: val,
2025-05-30 06:34:24 +00:00
}
2025-06-25 08:59:42 +00:00
loadSharedApi({ type: 'problem', systemType: apiType.value })
.putProblems(id as string, props.currentId, obj, loading)
.then(() => {
emit('update:currentContent', val)
MsgSuccess(t('common.modifySuccess'))
})
2025-05-30 06:34:24 +00:00
} else {
MsgError(t('views.problem.tip.errorMessage'))
}
}
function closeHandle() {
paragraphList.value = []
}
function getRecord() {
if (props.currentId && visible.value) {
2025-06-25 08:59:42 +00:00
loadSharedApi({ type: 'problem', systemType: apiType.value })
.getDetailProblems(id as string, props.currentId, loading)
.then((res: any) => {
paragraphList.value = res.data
})
2025-05-30 06:34:24 +00:00
}
}
function refresh() {
getRecord()
}
watch(
() => props.currentId,
() => {
paragraphList.value = []
getRecord()
2025-06-13 09:17:01 +00:00
},
2025-05-30 06:34:24 +00:00
)
watch(visible, (bool) => {
if (!bool) {
emit('update:currentId', '')
emit('update:currentContent', '')
emit('refresh')
}
})
const open = () => {
getRecord()
visible.value = true
}
defineExpose({
2025-06-13 09:17:01 +00:00
open,
2025-05-30 06:34:24 +00:00
})
</script>
<style lang="scss"></style>