UnisKB/ui/src/views/paragraph/component/ParagraphDialog.vue

174 lines
5.0 KiB
Vue
Raw Normal View History

2025-05-30 06:34:24 +00:00
<template>
<el-dialog
:title="title"
v-model="dialogVisible"
width="80%"
class="paragraph-dialog"
destroy-on-close
:close-on-click-modal="false"
:close-on-press-escape="false"
2025-06-19 13:32:14 +00:00
@click.stop
2025-05-30 06:34:24 +00:00
>
<el-row v-loading="loading">
<el-col :span="18">
<el-scrollbar height="500" wrap-class="paragraph-scrollbar">
<div class="p-24" style="padding-bottom: 8px">
2025-07-07 08:20:32 +00:00
<div style="position: absolute; right: 20px; top: 20px">
2025-06-19 13:32:14 +00:00
<el-button text @click="isEdit = true" v-if="paragraphId && !isEdit">
<AppIcon iconName="app-edit"></AppIcon>
2025-05-30 06:34:24 +00:00
</el-button>
</div>
2025-07-07 08:20:32 +00:00
<ParagraphForm
ref="paragraphFormRef"
:data="detail"
:isEdit="isEdit"
:knowledge-id="id"
2025-07-07 08:20:32 +00:00
/>
2025-05-30 06:34:24 +00:00
</div>
</el-scrollbar>
2025-06-19 13:32:14 +00:00
<div class="text-right p-24 pt-0" v-if="paragraphId && isEdit">
2025-06-19 12:32:02 +00:00
<el-button @click.prevent="cancelEdit"> {{ $t('common.cancel') }} </el-button>
2025-05-30 06:34:24 +00:00
<el-button type="primary" :disabled="loading" @click="handleDebounceClick">
2025-06-19 12:32:02 +00:00
{{ $t('common.save') }}
2025-05-30 06:34:24 +00:00
</el-button>
</div>
</el-col>
<el-col :span="6" class="border-l" style="width: 300px">
<!-- 关联问题 -->
<ProblemComponent
2025-08-05 09:31:49 +00:00
v-if="permissionPrecise.problem_read(id)"
2025-06-19 13:32:14 +00:00
:paragraphId="paragraphId"
2025-05-30 06:34:24 +00:00
:docId="document_id"
:knowledgeId="id"
2025-06-25 08:59:42 +00:00
:apiType="apiType"
2025-05-30 06:34:24 +00:00
ref="ProblemRef"
/>
</el-col>
</el-row>
2025-06-19 13:32:14 +00:00
<template #footer v-if="!paragraphId">
2025-05-30 06:34:24 +00:00
<span class="dialog-footer">
2025-06-19 12:32:02 +00:00
<el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button>
2025-05-30 06:34:24 +00:00
<el-button :disabled="loading" type="primary" @click="handleDebounceClick">
2025-06-19 12:32:02 +00:00
{{ $t('common.submit') }}
2025-05-30 06:34:24 +00:00
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
2025-08-05 03:45:42 +00:00
import { ref, watch, nextTick, computed } from 'vue'
2025-05-30 06:34:24 +00:00
import { useRoute } from 'vue-router'
import { cloneDeep, debounce } from 'lodash'
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
import ProblemComponent from '@/views/paragraph/component/ProblemComponent.vue'
2025-06-25 08:59:42 +00:00
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
2025-08-05 03:45:42 +00:00
import permissionMap from '@/permission'
2025-06-25 08:59:42 +00:00
const props = defineProps<{
2025-08-19 10:51:09 +00:00
title: string
2025-06-25 08:59:42 +00:00
apiType: 'systemShare' | 'workspace' | 'systemManage'
}>()
2025-05-30 06:34:24 +00:00
const route = useRoute()
const {
2025-06-19 12:32:02 +00:00
params: { id, documentId },
2025-05-30 06:34:24 +00:00
} = route as any
2025-08-05 03:45:42 +00:00
const permissionPrecise = computed(() => {
2025-08-05 09:31:49 +00:00
return permissionMap['knowledge'][props.apiType]
2025-08-05 03:45:42 +00:00
})
2025-05-30 06:34:24 +00:00
const emit = defineEmits(['refresh'])
const ProblemRef = ref()
const paragraphFormRef = ref<any>()
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
2025-06-19 13:32:14 +00:00
const paragraphId = ref('')
2025-05-30 06:34:24 +00:00
const detail = ref<any>({})
const isEdit = ref(false)
const document_id = ref('')
const dataset_id = ref('')
const cloneData = ref(null)
2025-06-19 13:32:14 +00:00
const position = ref(null)
2025-05-30 06:34:24 +00:00
watch(dialogVisible, (bool) => {
if (!bool) {
2025-06-19 13:32:14 +00:00
paragraphId.value = ''
2025-05-30 06:34:24 +00:00
detail.value = {}
isEdit.value = false
document_id.value = ''
dataset_id.value = ''
cloneData.value = null
}
})
const cancelEdit = () => {
isEdit.value = false
detail.value = cloneDeep(cloneData.value)
}
2025-06-19 13:32:14 +00:00
const open = (data: any, str: any) => {
if (data && !str) {
2025-05-30 06:34:24 +00:00
detail.value.title = data.title
detail.value.content = data.content
cloneData.value = cloneDeep(detail.value)
2025-06-19 13:32:14 +00:00
paragraphId.value = data.id
2025-05-30 06:34:24 +00:00
document_id.value = data.document_id
dataset_id.value = data.dataset_id || id
} else {
isEdit.value = true
2025-06-19 13:32:14 +00:00
if (str === 'add') {
position.value = data.position
}
2025-05-30 06:34:24 +00:00
}
dialogVisible.value = true
}
const submitHandle = async () => {
if (await paragraphFormRef.value?.validate()) {
loading.value = true
2025-06-19 13:32:14 +00:00
if (paragraphId.value) {
2025-06-25 08:59:42 +00:00
loadSharedApi({ type: 'paragraph', systemType: props.apiType })
.putParagraph(
2025-05-30 06:34:24 +00:00
dataset_id.value,
documentId || document_id.value,
2025-06-19 13:32:14 +00:00
paragraphId.value,
2025-05-30 06:34:24 +00:00
paragraphFormRef.value?.form,
2025-06-19 12:32:02 +00:00
loading,
2025-05-30 06:34:24 +00:00
)
.then((res: any) => {
isEdit.value = false
emit('refresh', res.data)
})
} else {
const obj =
ProblemRef.value.problemList.length > 0
? {
2025-06-19 13:32:14 +00:00
position: String(position.value) ? position.value : null,
2025-05-30 06:34:24 +00:00
problem_list: ProblemRef.value.problemList,
2025-06-19 12:32:02 +00:00
...paragraphFormRef.value?.form,
2025-05-30 06:34:24 +00:00
}
2025-06-19 13:32:14 +00:00
: {
position: String(position.value) ? position.value : null,
...paragraphFormRef.value?.form,
}
2025-06-25 08:59:42 +00:00
loadSharedApi({ type: 'paragraph', systemType: props.apiType })
.postParagraph(id, documentId, obj, loading)
.then(() => {
dialogVisible.value = false
emit('refresh')
})
2025-05-30 06:34:24 +00:00
}
}
}
const handleDebounceClick = debounce(() => {
submitHandle()
}, 200)
2025-07-16 08:24:46 +00:00
defineExpose({ open, dialogVisible })
2025-05-30 06:34:24 +00:00
</script>
<style lang="scss" scoped></style>