123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- <template>
- <div class="bm-main-box">
- <div class="flex items-center">
- <div class="bm-main-box-title">文档</div>
- </div>
- <template v-if="!state.stage.show">
- <CzrContent
- v-model:tableHead="state.query.tableHead"
- @handleReset="onReset"
- @handleSearch="onSearch"
- v-model:full="state.query.isFull"
- >
- <template #tableTitle>
- <div class="flex gap-[var(--czr-gap)]">
- <CzrButton
- type="add"
- title="添加文件"
- @click="
- $router.push({
- name: '18e6009c-a72c-4359-864b-e7725fccca69',
- params: {
- id: ID,
- },
- })
- "
- />
- <CzrButton
- type="add"
- title="添加分段"
- @click="() => (state.detail.show = true)"
- />
- <CzrButton title="迁移" icon="move" @click="onKnowledge()" />
- <CzrButton title="归档" icon="cloud" />
- <CzrButton
- type="del"
- title="删除"
- icon="czr_del"
- @click="onDel()"
- />
- </div>
- </template>
- <template #buttons>
- <div class="flex items-center gap-[var(--czr-gap)]">
- <CzrForm
- class="bm-filter"
- label-width="0px"
- @handleEnter="onSearch"
- >
- <CzrFormColumn
- width="6.68rem"
- class="__czr-table-form-column"
- :span="24"
- label-width="0px"
- v-model:param="state.query.form.p1"
- link="select"
- :options="[]"
- placeholder="审核状态"
- />
- <CzrFormColumn
- width="15.63rem"
- class="__czr-table-form-column"
- :span="24"
- label-width="0px"
- v-model:param="state.text"
- placeholder="按文档名称搜索"
- :prefix-icon="Search"
- />
- </CzrForm>
- </div>
- </template>
- <template #table>
- <CzrTable
- v-loading="state.query.loading"
- ref="ref_cusTable"
- :data="state.query.result.data"
- :head="state.query.head"
- :total="state.query.result.total"
- :page="state.query.page.pageNum"
- :pageSize="state.query.page.pageSize"
- @handlePage="onPage"
- v-model:selected="state.query.selected"
- >
- <template #name-column-value="{ scope }">
- <div class="flex justify-center">
- <template v-if="scope.row.indexingStatus === 'completed'">
- <CzrButton
- type="table"
- :title="scope.row.name"
- @click="onStage(scope.row)"
- />
- </template>
- <template v-else>
- {{ scope.row.name }}
- </template>
- </div>
- </template>
- <template #caozuo-column-value="{ scope }">
- <div class="__czr-table-operations">
- <template v-if="scope.row.indexingStatus === 'archived'">
- <CzrButton
- type="table"
- title="撤销归档"
- @click="onUnArchive(scope.row)"
- />
- </template>
- <template v-if="scope.row.indexingStatus === 'completed'">
- <CzrButton
- type="table"
- title="归档"
- @click="onArchive(scope.row)"
- />
- </template>
- <CzrButton
- type="table"
- title="重命名"
- @click="onRename(scope.row)"
- />
- <CzrButton
- type="table"
- title="迁移"
- @click="onKnowledge(scope.row)"
- />
- <CzrButton type="table-del" @click="onDel(scope.row)" />
- </div>
- </template>
- </CzrTable>
- </template>
- </CzrContent>
- <detailCom
- v-model:show="state.detail.show"
- :transfer="state.detail.transfer"
- @refresh="onSearch"
- />
- <renameCom
- v-model:show="state.rename.show"
- :transfer="state.rename.transfer"
- @refresh="onSearch"
- />
- <knowledgeSelectCom
- v-model:show="state.knowledgeSelect.show"
- :transfer="state.knowledgeSelect.transfer"
- @refresh="onSearch"
- />
- </template>
- <template v-else>
- <stageIndexCom
- v-model:show="state.stage.show"
- :document="state.stage.document"
- />
- </template>
- </div>
- </template>
- <script setup lang="ts">
- import {
- computed,
- getCurrentInstance,
- inject,
- onMounted,
- reactive,
- ref,
- watch,
- } from 'vue'
- import { Search } from '@element-plus/icons-vue'
- import { debounce } from 'lodash'
- import { useDialogStore, useDictionaryStore } from '@/stores'
- import { ElMessage } from 'element-plus'
- import detailCom from './detail.vue'
- import renameCom from './rename.vue'
- import knowledgeSelectCom from './knowledge-select.vue'
- import stageIndexCom from './stage-index.vue'
- import {
- documentArchive,
- documentDocsDelete,
- documentGetDocumentsByPage,
- documentNoArchive,
- } from '@/api/modules/knowledge/document'
- const DialogStore = useDialogStore()
- const DictionaryStore = useDictionaryStore()
- const emit = defineEmits([])
- const props = defineProps({
- knowledge: <any>{},
- })
- const { proxy }: any = getCurrentInstance()
- const ID = inject('ID')
- const state: any = reactive({
- text: '',
- query: {
- init: false,
- loading: false,
- head: [
- { value: 'name', label: '文件名称', show: true, width: 200 },
- { value: 'wordCount', label: '字符数', show: true, width: 100 },
- {
- value: 'indexingStatus',
- label: '状态',
- show: true,
- width: 100,
- dictList: computed(() => DictionaryStore.indexingStatusList),
- },
- { value: 'p1', label: '召回次数(无)', show: true },
- {
- value: 'isUse',
- label: '启用/停用',
- show: true,
- width: 100,
- dictList: computed(() => DictionaryStore.documentUseList),
- },
- { value: 'checkStatus', label: '审核状态', show: true, width: 100 },
- { value: 'p1', label: '关联应用(无)', show: true },
- {
- value: 'createTime',
- label: '创建时间',
- show: true,
- width: 180,
- datetime: true,
- },
- {
- value: 'updateTime',
- label: '更新时间',
- show: true,
- width: 180,
- datetime: true,
- },
- {
- value: 'caozuo',
- label: '操作',
- show: true,
- width: 300,
- fixed: 'right',
- popover: false,
- },
- ],
- page: {
- pageNum: 1,
- pageSize: 20,
- },
- form: {},
- formReal: {},
- result: {
- total: 0,
- data: [],
- },
- selected: [],
- },
- detail: {
- show: false,
- transfer: {
- ID: ID,
- },
- },
- rename: {
- show: false,
- transfer: {},
- },
- knowledgeSelect: {
- show: false,
- transfer: {},
- },
- stage: {
- show: false,
- document: {},
- },
- })
- const setText = debounce((v) => {
- state.query.form.name = v
- }, 1000)
- watch(
- () => state.text,
- (n) => {
- setText(n)
- },
- )
- watch(
- () => state.query.form,
- (n) => {
- if (state.query.init) {
- onSearch()
- }
- },
- { deep: true },
- )
- const onPage = (pageNum, pageSize) => {
- setTimeout(() => {
- state.query.init = true
- }, 100)
- state.query.page = {
- pageNum: pageNum,
- pageSize: pageSize,
- }
- const params = {
- datasetId: ID,
- page: state.query.page.pageNum,
- size: state.query.page.pageSize,
- }
- // 添加表单参数
- for (const [k, v] of Object.entries(state.query.formReal)) {
- if (proxy.$czrUtil.isValue(v)) {
- params[k] = v
- }
- }
- state.query.loading = true
- documentGetDocumentsByPage(params)
- .then(({ data }: any) => {
- state.query.result.total = data.totalElements
- state.query.result.data = data.content
- })
- .catch(() => {})
- .finally(() => {
- state.query.loading = false
- })
- }
- const onSearch = () => {
- state.query.selected = []
- state.query.formReal = JSON.parse(JSON.stringify(state.query.form))
- onPage(1, state.query.page.pageSize)
- }
- const onReset = () => {
- state.query.page = {
- pageNum: 1,
- pageSize: 20,
- }
- state.query.form = {}
- onSearch()
- }
- const onDel = (row: any = null) => {
- if (row) {
- DialogStore.confirm({
- title: '删除确认',
- content: `是否删除文档:${row.name}?<br/>此文档下的${row.p1 ? row.p1 + '个' : ''}分段都会被删除,请谨慎操作。`,
- onSubmit: () => {
- documentDocsDelete([row.id])
- .then(() => {
- ElMessage.success('删除成功!')
- })
- .catch(() => {})
- .finally(() => {
- onSearch()
- })
- },
- })
- } else {
- if (state.query.selected.length === 0) {
- ElMessage.warning('请至少选择一条记录!')
- return
- }
- DialogStore.confirm({
- title: '删除确认',
- content: `是否批量删除${state.query.selected.length}个文档?<br/>所选文档中的分段会跟随删除,请谨慎操作。`,
- onSubmit: () => {
- documentDocsDelete(state.query.selected.map((v) => v.id))
- .then(() => {
- ElMessage.success('删除成功!')
- })
- .catch(() => {})
- .finally(() => {
- onSearch()
- })
- },
- })
- }
- }
- const onArchive = (row: any = null) => {
- if (row) {
- DialogStore.confirm({
- title: '归档确认',
- content: `是否归档文档:${row.name}?<br/>归档后的数据就只能查看或删除,无法重新编辑,请谨慎操作。`,
- onSubmit: () => {
- documentArchive([row.id])
- .then(() => {
- ElMessage.success('归档成功!')
- })
- .catch(() => {})
- .finally(() => {
- onSearch()
- })
- },
- })
- } else {
- if (state.query.selected.length === 0) {
- ElMessage.warning('请至少选择一条记录!')
- return
- }
- DialogStore.confirm({
- title: '归档确认',
- content: `是否批量删除${state.query.selected.length}个文档?<br/>归档后的数据就只能查看或删除,无法重新编辑,请谨慎操作。`,
- onSubmit: () => {
- documentArchive(state.query.selected.map((v) => v.id))
- .then(() => {
- ElMessage.success('归档成功!')
- })
- .catch(() => {})
- .finally(() => {
- onSearch()
- })
- },
- })
- }
- }
- const onUnArchive = (row: any = null) => {
- DialogStore.confirm({
- title: '撤销归档确认',
- content: `是否撤销归档:${row.name}?<br/>撤销归档后的数据,可重新编辑,请谨慎操作。`,
- onSubmit: () => {
- documentNoArchive([row.id])
- .then(() => {
- ElMessage.success('撤销归档成功!')
- })
- .catch(() => {})
- .finally(() => {
- onSearch()
- })
- },
- })
- }
- const onRename = (row) => {
- state.rename.transfer = {
- id: row.id,
- name: JSON.parse(JSON.stringify(row.name)),
- }
- state.rename.show = true
- }
- const onKnowledge = (row: any = null) => {
- if (row) {
- state.knowledgeSelect.transfer = {
- row: JSON.parse(JSON.stringify(row)),
- type: 'text',
- }
- state.knowledgeSelect.show = true
- } else {
- if (state.query.selected.length === 0) {
- ElMessage.warning('请至少选择一条记录!')
- return
- }
- state.knowledgeSelect.transfer = {
- list: [...state.query.selected],
- type: 'text',
- }
- state.knowledgeSelect.show = true
- }
- }
- const onStage = (row) => {
- state.stage.document = JSON.parse(JSON.stringify(row))
- state.stage.show = true
- }
- onMounted(() => {
- initDictionary()
- onReset()
- })
- const initDictionary = () => {
- DictionaryStore.initDict('document_use')
- DictionaryStore.initDict('indexing_status')
- }
- </script>
- <style lang="scss" scoped>
- .knowledge {
- width: 100%;
- height: 11.81rem;
- background-image: url('@/assets/images/knowledge-item-bg.png');
- background-repeat: no-repeat;
- background-size: 100% 100%;
- padding: 1rem 1.5rem;
- }
- </style>
|