UnisKB/ui/src/views/document/index.vue

891 lines
32 KiB
Vue
Raw Normal View History

2023-11-07 11:04:59 +00:00
<template>
2025-01-14 11:28:30 +00:00
<LayoutContainer :header="$t('common.document')" class="document-main">
2023-11-07 11:04:59 +00:00
<div class="main-calc-height">
2023-11-10 03:36:04 +00:00
<div class="p-24">
2023-11-07 11:04:59 +00:00
<div class="flex-between">
2024-01-10 09:44:05 +00:00
<div>
<el-button
v-if="datasetDetail.type === '0'"
type="primary"
@click="router.push({ path: '/dataset/upload', query: { id: id } })"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.uploadDocument') }}</el-button
2024-01-19 08:03:17 +00:00
>
2025-01-14 11:28:30 +00:00
<el-button v-if="datasetDetail.type === '1'" type="primary" @click="importDoc">{{
$t('views.document.importDocument')
}}</el-button>
2024-01-19 08:03:17 +00:00
<el-button
@click="syncMulDocument"
:disabled="multipleSelection.length === 0"
v-if="datasetDetail.type === '1'"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.syncDocument') }}</el-button
2024-01-19 08:03:17 +00:00
>
<el-button @click="openDatasetDialog()" :disabled="multipleSelection.length === 0">
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.migration') }}
</el-button>
<el-button @click="batchRefresh" :disabled="multipleSelection.length === 0">
2025-01-14 11:28:30 +00:00
{{ $t('views.dataset.setting.vectorization') }}
</el-button>
<el-button @click="openGenerateDialog()" :disabled="multipleSelection.length === 0">
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.generateQuestion') }}
</el-button>
<el-button @click="openBatchEditDocument" :disabled="multipleSelection.length === 0">
2025-01-14 11:28:30 +00:00
{{ $t('common.setting') }}
</el-button>
<el-button @click="deleteMulDocument" :disabled="multipleSelection.length === 0">
2025-01-13 03:15:51 +00:00
{{ $t('common.delete') }}
</el-button>
2024-01-10 09:44:05 +00:00
</div>
2023-11-07 11:04:59 +00:00
<el-input
v-model="filterText"
2025-01-14 11:28:30 +00:00
:placeholder="$t('views.dataset.searchBar.placeholder')"
2023-11-07 11:04:59 +00:00
prefix-icon="Search"
class="w-240"
2023-11-10 09:18:00 +00:00
@change="getList"
clearable
2023-11-07 11:04:59 +00:00
/>
</div>
2023-11-09 10:52:06 +00:00
<app-table
2024-01-11 06:40:00 +00:00
ref="multipleTableRef"
2023-11-09 10:52:06 +00:00
class="mt-16"
2023-12-06 09:30:46 +00:00
:data="documentData"
2023-11-09 10:52:06 +00:00
:pagination-config="paginationConfig"
2024-01-10 09:44:05 +00:00
:quick-create="datasetDetail.type === '0'"
2023-11-09 10:52:06 +00:00
@sizeChange="handleSizeChange"
2023-12-06 09:30:46 +00:00
@changePage="getList"
2023-11-09 10:52:06 +00:00
@cell-mouse-enter="cellMouseEnter"
@cell-mouse-leave="cellMouseLeave"
2023-11-10 09:18:00 +00:00
@creatQuick="creatQuickHandle"
2023-11-10 11:05:52 +00:00
@row-click="rowClickHandle"
2024-01-11 06:40:00 +00:00
@selection-change="handleSelectionChange"
2023-11-10 03:36:04 +00:00
v-loading="loading"
2024-03-22 05:48:08 +00:00
:row-key="(row: any) => row.id"
:storeKey="storeKey"
2023-11-09 10:52:06 +00:00
>
2024-03-22 05:48:08 +00:00
<el-table-column type="selection" width="55" :reserve-selection="true" />
2025-01-14 11:28:30 +00:00
<el-table-column prop="name" :label="$t('views.document.table.name')" min-width="280">
2023-11-09 10:52:06 +00:00
<template #default="{ row }">
<ReadWrite
@change="editName($event, row.id)"
2023-11-09 10:52:06 +00:00
:data="row.name"
:showEditIcon="row.id === currentMouseId"
/>
</template>
</el-table-column>
2025-01-14 11:28:30 +00:00
<el-table-column
prop="char_length"
:label="$t('views.document.table.char_length')"
align="right"
>
2023-11-07 11:04:59 +00:00
<template #default="{ row }">
2023-12-05 11:21:13 +00:00
{{ numberFormat(row.char_length) }}
2023-11-07 11:04:59 +00:00
</template>
</el-table-column>
2025-01-14 11:28:30 +00:00
<el-table-column
prop="paragraph_count"
:label="$t('views.document.table.paragraph')"
align="right"
/>
<el-table-column
prop="status"
:label="$t('views.document.fileStatus.label')"
width="130"
>
2024-09-10 08:15:47 +00:00
<template #header>
<div>
2025-01-14 11:28:30 +00:00
<span>{{ $t('views.document.fileStatus.label') }}</span>
2024-09-10 08:15:47 +00:00
<el-dropdown trigger="click" @command="dropdownHandle">
<el-button
style="margin-top: 1px"
link
:type="filterMethod['status'] ? 'primary' : ''"
>
<el-icon><Filter /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu style="width: 100px">
<el-dropdown-item
:class="filterMethod['status'] ? '' : 'is-active'"
:command="beforeCommand('status', '')"
class="justify-center"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.table.all') }}</el-dropdown-item
2024-09-10 08:15:47 +00:00
>
<el-dropdown-item
:class="filterMethod['status'] === State.SUCCESS ? 'is-active' : ''"
2024-09-10 08:15:47 +00:00
class="justify-center"
:command="beforeCommand('status', State.SUCCESS)"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.fileStatus.SUCCESS') }}</el-dropdown-item
2024-09-10 08:15:47 +00:00
>
<el-dropdown-item
:class="filterMethod['status'] === State.FAILURE ? 'is-active' : ''"
2024-09-10 08:15:47 +00:00
class="justify-center"
:command="beforeCommand('status', State.FAILURE)"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.fileStatus.FAILURE') }}</el-dropdown-item
2024-09-10 08:15:47 +00:00
>
<el-dropdown-item
:class="
filterMethod['status'] === State.STARTED &&
filterMethod['task_type'] == TaskType.EMBEDDING
? 'is-active'
: ''
"
2024-09-10 08:15:47 +00:00
class="justify-center"
:command="beforeCommand('status', State.STARTED, TaskType.EMBEDDING)"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.fileStatus.EMBEDDING') }}</el-dropdown-item
2024-09-10 08:15:47 +00:00
>
<el-dropdown-item
:class="filterMethod['status'] === State.PENDING ? 'is-active' : ''"
2024-09-10 08:15:47 +00:00
class="justify-center"
:command="beforeCommand('status', State.PENDING)"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.fileStatus.PENDING') }}</el-dropdown-item
2024-09-10 08:15:47 +00:00
>
<el-dropdown-item
:class="
filterMethod['status'] === State.STARTED &&
filterMethod['task_type'] === TaskType.GENERATE_PROBLEM
? 'is-active'
: ''
"
class="justify-center"
:command="beforeCommand('status', State.STARTED, TaskType.GENERATE_PROBLEM)"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.fileStatus.GENERATE') }}</el-dropdown-item
>
2024-09-10 08:15:47 +00:00
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</template>
2023-11-09 10:52:06 +00:00
<template #default="{ row }">
2024-11-26 04:08:13 +00:00
<StatusVlue :status="row.status" :status-meta="row.status_meta"></StatusVlue>
2023-11-09 10:52:06 +00:00
</template>
2023-11-07 11:04:59 +00:00
</el-table-column>
2024-09-10 08:15:47 +00:00
<el-table-column width="130">
<template #header>
<div>
2025-01-14 11:28:30 +00:00
<span>{{ $t('views.document.enableStatus.label') }}</span>
2024-09-10 08:15:47 +00:00
<el-dropdown trigger="click" @command="dropdownHandle">
<el-button
style="margin-top: 1px"
link
:type="filterMethod['is_active'] ? 'primary' : ''"
>
<el-icon><Filter /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu style="width: 100px">
<el-dropdown-item
2024-09-20 09:45:49 +00:00
:class="filterMethod['is_active'] === '' ? 'is-active' : ''"
2024-09-10 08:15:47 +00:00
:command="beforeCommand('is_active', '')"
class="justify-center"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.table.all') }}</el-dropdown-item
2024-09-10 08:15:47 +00:00
>
<el-dropdown-item
:class="filterMethod['is_active'] === true ? 'is-active' : ''"
class="justify-center"
:command="beforeCommand('is_active', true)"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.enableStatus.enable') }}</el-dropdown-item
2024-09-10 08:15:47 +00:00
>
<el-dropdown-item
:class="filterMethod['is_active'] === false ? 'is-active' : ''"
class="justify-center"
:command="beforeCommand('is_active', false)"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.enableStatus.close') }}</el-dropdown-item
2024-09-10 08:15:47 +00:00
>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</template>
2023-11-07 11:04:59 +00:00
<template #default="{ row }">
2023-11-10 11:05:52 +00:00
<div @click.stop>
2023-12-05 11:21:13 +00:00
<el-switch
:loading="loading"
2023-12-05 11:21:13 +00:00
size="small"
v-model="row.is_active"
:before-change="() => changeState(row)"
2023-12-05 11:21:13 +00:00
/>
2023-11-10 11:05:52 +00:00
</div>
2023-11-07 11:04:59 +00:00
</template>
</el-table-column>
2024-04-26 10:35:46 +00:00
<el-table-column width="130">
<template #header>
<div>
2025-01-14 11:28:30 +00:00
<span>{{ $t('views.document.form.hit_handling_method.label') }}</span>
<el-dropdown trigger="click" @command="dropdownHandle">
2024-09-10 08:15:47 +00:00
<el-button
style="margin-top: 1px"
link
:type="filterMethod['hit_handling_method'] ? 'primary' : ''"
>
<el-icon><Filter /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu style="width: 100px">
<el-dropdown-item
2024-09-10 08:15:47 +00:00
:class="filterMethod['hit_handling_method'] ? '' : 'is-active'"
:command="beforeCommand('hit_handling_method', '')"
class="justify-center"
2025-01-14 11:28:30 +00:00
>{{ $t('views.document.table.all') }}</el-dropdown-item
>
<template v-for="(value, key) of hitHandlingMethod" :key="key">
<el-dropdown-item
2024-09-10 08:15:47 +00:00
:class="filterMethod['hit_handling_method'] === key ? 'is-active' : ''"
class="justify-center"
2024-09-10 08:15:47 +00:00
:command="beforeCommand('hit_handling_method', key)"
>{{ value }}</el-dropdown-item
>
</template>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</template>
<template #default="{ row }">
{{ hitHandlingMethod[row.hit_handling_method as keyof typeof hitHandlingMethod] }}
</template>
</el-table-column>
2025-01-13 03:15:51 +00:00
<el-table-column prop="create_time" :label="$t('common.createTime')" width="175">
2023-11-07 11:04:59 +00:00
<template #default="{ row }">
{{ datetimeFormat(row.create_time) }}
</template>
</el-table-column>
2025-01-14 11:28:30 +00:00
<el-table-column
prop="update_time"
:label="$t('views.document.table.updateTime')"
width="175"
>
2023-11-07 11:04:59 +00:00
<template #default="{ row }">
{{ datetimeFormat(row.update_time) }}
</template>
</el-table-column>
2025-01-13 03:15:51 +00:00
<el-table-column :label="$t('common.operation')" align="left" width="110" fixed="right">
2023-11-07 11:04:59 +00:00
<template #default="{ row }">
2024-01-10 09:44:05 +00:00
<div v-if="datasetDetail.type === '0'">
<span class="mr-4">
<el-tooltip
effect="dark"
v-if="
([State.STARTED, State.PENDING] as Array<string>).includes(
getTaskState(row.status, TaskType.EMBEDDING)
)
"
2025-01-14 11:28:30 +00:00
:content="$t('views.document.setting.cancelVectorization')"
placement="top"
>
<el-button
type="primary"
text
@click.stop="cancelTask(row, TaskType.EMBEDDING)"
>
<AppIcon iconName="app-close" style="font-size: 16px"></AppIcon>
</el-button>
</el-tooltip>
2025-01-14 11:28:30 +00:00
<el-tooltip
v-else
effect="dark"
:content="$t('views.dataset.setting.vectorization')"
placement="top"
>
2024-01-10 09:44:05 +00:00
<el-button type="primary" text @click.stop="refreshDocument(row)">
<AppIcon iconName="app-document-refresh" style="font-size: 16px"></AppIcon>
2024-01-10 09:44:05 +00:00
</el-button>
</el-tooltip>
</span>
2024-09-03 07:07:15 +00:00
<span class="mr-4">
2025-01-14 11:28:30 +00:00
<el-tooltip effect="dark" :content="$t('common.setting')" placement="top">
2024-09-03 07:07:15 +00:00
<el-button type="primary" text @click.stop="settingDoc(row)">
<el-icon><Setting /></el-icon>
</el-button>
</el-tooltip>
</span>
2024-04-26 10:35:46 +00:00
<span @click.stop>
<el-dropdown trigger="click">
2024-08-21 02:42:59 +00:00
<el-button text type="primary">
2024-04-26 10:35:46 +00:00
<el-icon><MoreFilled /></el-icon>
2024-01-10 09:44:05 +00:00
</el-button>
2024-04-26 10:35:46 +00:00
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-if="
([State.STARTED, State.PENDING] as Array<string>).includes(
getTaskState(row.status, TaskType.GENERATE_PROBLEM)
)
"
@click="cancelTask(row, TaskType.GENERATE_PROBLEM)"
>
<el-icon><Connection /></el-icon>
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.cancelGenerateQuestion') }}
</el-dropdown-item>
<el-dropdown-item v-else @click="openGenerateDialog(row)">
<el-icon><Connection /></el-icon>
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.generateQuestion') }}
</el-dropdown-item>
2024-04-26 10:35:46 +00:00
<el-dropdown-item @click="openDatasetDialog(row)">
<AppIcon iconName="app-migrate"></AppIcon>
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.migration') }}
</el-dropdown-item>
<el-dropdown-item @click="exportDocument(row)">
<AppIcon iconName="app-export"></AppIcon>
2025-01-14 11:28:30 +00:00
{{ $t('common.export') }}Excel
</el-dropdown-item>
<el-dropdown-item @click="exportDocumentZip(row)">
<AppIcon iconName="app-export"></AppIcon>
2025-01-14 11:28:30 +00:00
{{ $t('common.export') }}Zip
</el-dropdown-item>
2025-01-13 03:15:51 +00:00
<el-dropdown-item icon="Delete" @click.stop="deleteDocument(row)">{{
$t('common.delete')
}}</el-dropdown-item>
2024-04-26 10:35:46 +00:00
</el-dropdown-menu>
</template>
</el-dropdown>
2024-01-10 09:44:05 +00:00
</span>
</div>
<div v-if="datasetDetail.type === '1'">
2024-09-03 07:07:15 +00:00
<span class="mr-4">
2025-01-14 11:28:30 +00:00
<el-tooltip
effect="dark"
:content="$t('views.dataset.setting.sync')"
placement="top"
>
2024-09-03 07:07:15 +00:00
<el-button type="primary" text @click.stop="syncDocument(row)">
<el-icon><Refresh /></el-icon>
</el-button>
</el-tooltip>
</span>
<span class="mr-4">
2024-11-26 04:08:13 +00:00
<el-tooltip
effect="dark"
v-if="
([State.STARTED, State.PENDING] as Array<string>).includes(
getTaskState(row.status, TaskType.EMBEDDING)
)
"
2025-01-14 11:28:30 +00:00
:content="$t('views.document.setting.cancelVectorization')"
2024-11-26 04:08:13 +00:00
placement="top"
>
<el-button
type="primary"
text
@click.stop="cancelTask(row, TaskType.EMBEDDING)"
>
<AppIcon iconName="app-close" style="font-size: 16px"></AppIcon>
</el-button>
</el-tooltip>
2025-01-14 11:28:30 +00:00
<el-tooltip
effect="dark"
v-else
:content="$t('views.dataset.setting.vectorization')"
placement="top"
>
2024-09-03 07:07:15 +00:00
<el-button type="primary" text @click.stop="refreshDocument(row)">
<AppIcon iconName="app-document-refresh" style="font-size: 16px"></AppIcon>
</el-button>
</el-tooltip>
</span>
2024-01-10 09:44:05 +00:00
<span @click.stop>
<el-dropdown trigger="click">
2024-08-21 02:42:59 +00:00
<el-button text type="primary">
2024-01-10 09:44:05 +00:00
<el-icon><MoreFilled /></el-icon>
2024-01-19 06:59:51 +00:00
</el-button>
2024-01-10 09:44:05 +00:00
<template #dropdown>
<el-dropdown-menu>
2025-01-14 11:28:30 +00:00
<el-dropdown-item icon="Setting" @click="settingDoc(row)">{{
$t('common.setting')
}}</el-dropdown-item>
2024-11-26 04:08:13 +00:00
<el-dropdown-item
v-if="
([State.STARTED, State.PENDING] as Array<string>).includes(
getTaskState(row.status, TaskType.GENERATE_PROBLEM)
)
2024-11-26 04:08:13 +00:00
"
@click="cancelTask(row, TaskType.GENERATE_PROBLEM)"
>
<el-icon><Connection /></el-icon>
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.cancelGenerateQuestion') }}
2024-11-26 04:08:13 +00:00
</el-dropdown-item>
<el-dropdown-item v-else @click="openGenerateDialog(row)">
<el-icon><Connection /></el-icon>
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.generateQuestion') }}
</el-dropdown-item>
2024-04-26 10:35:46 +00:00
<el-dropdown-item @click="openDatasetDialog(row)">
<AppIcon iconName="app-migrate"></AppIcon>
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.migration') }}</el-dropdown-item
2024-04-26 10:35:46 +00:00
>
<el-dropdown-item @click="exportDocument(row)">
<AppIcon iconName="app-export"></AppIcon>
2025-01-14 11:28:30 +00:00
{{ $t('common.export') }}Excel
</el-dropdown-item>
<el-dropdown-item @click="exportDocumentZip(row)">
<AppIcon iconName="app-export"></AppIcon>
2025-01-14 11:28:30 +00:00
{{ $t('common.export') }}Zip
</el-dropdown-item>
2025-01-13 03:15:51 +00:00
<el-dropdown-item icon="Delete" @click.stop="deleteDocument(row)">{{
$t('common.delete')
}}</el-dropdown-item>
2024-01-10 09:44:05 +00:00
</el-dropdown-menu>
</template>
</el-dropdown>
</span>
</div>
2023-11-07 11:04:59 +00:00
</template>
</el-table-column>
2023-11-09 10:52:06 +00:00
</app-table>
2023-11-07 11:04:59 +00:00
</div>
2024-12-24 09:09:27 +00:00
2024-01-19 08:03:17 +00:00
<ImportDocumentDialog ref="ImportDocumentDialogRef" :title="title" @refresh="refresh" />
2024-01-25 07:08:25 +00:00
<SyncWebDialog ref="SyncWebDialogRef" @refresh="refresh" />
2024-04-26 10:35:46 +00:00
<!-- 选择知识库 -->
<SelectDatasetDialog ref="SelectDatasetDialogRef" @refresh="refreshMigrate" />
<GenerateRelatedDialog ref="GenerateRelatedDialogRef" @refresh="refresh" />
2023-11-07 11:04:59 +00:00
</div>
2024-12-24 09:09:27 +00:00
<div class="mul-operation w-full flex" v-if="multipleSelection.length !== 0">
<el-button :disabled="multipleSelection.length === 0" @click="cancelTaskHandle(1)">
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.cancelVectorization') }}
2024-12-24 09:09:27 +00:00
</el-button>
<el-button :disabled="multipleSelection.length === 0" @click="cancelTaskHandle(2)">
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.cancelGenerate') }}
2024-12-24 09:09:27 +00:00
</el-button>
<el-text type="info" class="secondary ml-24">
2025-01-14 11:28:30 +00:00
{{ $t('views.document.selected') }} {{ multipleSelection.length }}
{{ $t('views.document.items') }}
2024-12-24 09:09:27 +00:00
</el-text>
2025-01-14 11:28:30 +00:00
<el-button class="ml-16" type="primary" link @click="clearSelection">
{{ $t('common.clear') }}
</el-button>
2024-12-24 09:09:27 +00:00
</div>
<EmbeddingContentDialog ref="embeddingContentDialogRef"></EmbeddingContentDialog>
2023-11-07 11:04:59 +00:00
</LayoutContainer>
</template>
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, computed } from 'vue'
import { useRouter, useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from 'vue-router'
2024-01-11 06:40:00 +00:00
import { ElTable } from 'element-plus'
2023-11-22 10:37:08 +00:00
import documentApi from '@/api/document'
2024-01-19 08:03:17 +00:00
import ImportDocumentDialog from './component/ImportDocumentDialog.vue'
2024-01-25 07:08:25 +00:00
import SyncWebDialog from '@/views/dataset/component/SyncWebDialog.vue'
2024-04-26 10:35:46 +00:00
import SelectDatasetDialog from './component/SelectDatasetDialog.vue'
2023-12-05 11:21:13 +00:00
import { numberFormat } from '@/utils/utils'
2023-11-07 11:04:59 +00:00
import { datetimeFormat } from '@/utils/time'
import { hitHandlingMethod } from '@/enums/document'
2024-03-01 03:06:09 +00:00
import { MsgSuccess, MsgConfirm, MsgError } from '@/utils/message'
2024-01-10 09:44:05 +00:00
import useStore from '@/stores'
2024-11-26 04:08:13 +00:00
import StatusVlue from '@/views/document/component/Status.vue'
import GenerateRelatedDialog from '@/components/generate-related-dialog/index.vue'
import EmbeddingContentDialog from '@/views/document/component/EmbeddingContentDialog.vue'
2024-11-26 04:08:13 +00:00
import { TaskType, State } from '@/utils/status'
2025-01-14 11:28:30 +00:00
import { t } from '@/locales'
2023-11-07 11:04:59 +00:00
const router = useRouter()
const route = useRoute()
2023-11-10 09:18:00 +00:00
const {
params: { id } // id为datasetID
2023-11-10 09:18:00 +00:00
} = route as any
2023-11-09 10:52:06 +00:00
const { common, dataset, document } = useStore()
const storeKey = 'documents'
2024-11-26 05:29:46 +00:00
const getTaskState = (status: string, taskType: number) => {
2024-11-26 04:08:13 +00:00
const statusList = status.split('').reverse()
return taskType - 1 > statusList.length + 1 ? 'n' : statusList[taskType - 1]
}
2024-05-20 09:50:14 +00:00
onBeforeRouteUpdate(() => {
common.savePage(storeKey, null)
common.saveCondition(storeKey, null)
})
2024-05-20 09:50:14 +00:00
onBeforeRouteLeave((to: any) => {
if (to.name !== 'Paragraph') {
common.savePage(storeKey, null)
common.saveCondition(storeKey, null)
} else {
common.saveCondition(storeKey, {
filterText: filterText.value,
filterMethod: filterMethod.value
})
}
})
const beforePagination = computed(() => common.paginationConfig[storeKey])
const beforeSearch = computed(() => common.search[storeKey])
const embeddingContentDialogRef = ref<InstanceType<typeof EmbeddingContentDialog>>()
2024-01-25 07:08:25 +00:00
const SyncWebDialogRef = ref()
2023-11-07 11:04:59 +00:00
const loading = ref(false)
2023-12-20 02:57:43 +00:00
let interval: any
2023-11-07 11:04:59 +00:00
const filterText = ref('')
2024-09-10 08:15:47 +00:00
const filterMethod = ref<any>({})
2023-11-07 11:04:59 +00:00
const documentData = ref<any[]>([])
2023-11-09 10:52:06 +00:00
const currentMouseId = ref(null)
2024-01-10 09:44:05 +00:00
const datasetDetail = ref<any>({})
2023-11-09 10:52:06 +00:00
const paginationConfig = ref({
2023-12-06 09:30:46 +00:00
current_page: 1,
page_size: 10,
2023-11-09 10:52:06 +00:00
total: 0
})
2024-01-19 08:03:17 +00:00
const ImportDocumentDialogRef = ref()
2024-01-11 06:40:00 +00:00
const multipleTableRef = ref<InstanceType<typeof ElTable>>()
const multipleSelection = ref<any[]>([])
2024-01-19 08:03:17 +00:00
const title = ref('')
2024-04-26 10:35:46 +00:00
const SelectDatasetDialogRef = ref()
2024-12-24 09:09:27 +00:00
const exportDocument = (document: any) => {
documentApi.exportDocument(document.name, document.dataset_id, document.id, loading).then(() => {
2025-01-14 11:28:30 +00:00
MsgSuccess(t('common.exportSuccess'))
})
}
const exportDocumentZip = (document: any) => {
documentApi
.exportDocumentZip(document.name, document.dataset_id, document.id, loading)
.then(() => {
2025-01-14 11:28:30 +00:00
MsgSuccess(t('common.exportSuccess'))
})
}
2024-12-24 09:09:27 +00:00
function cancelTaskHandle(val: any) {
const arr: string[] = []
multipleSelection.value.map((v) => {
if (v) {
arr.push(v.id)
}
})
const obj = {
id_list: arr,
type: val
}
documentApi.batchCancelTask(id, obj, loading).then(() => {
2025-01-15 11:10:29 +00:00
MsgSuccess(t('views.document.tip.cancelSuccess'))
2024-12-24 09:09:27 +00:00
multipleTableRef.value?.clearSelection()
})
}
function clearSelection() {
multipleTableRef.value?.clearSelection()
}
2024-04-26 10:35:46 +00:00
function openDatasetDialog(row?: any) {
const arr: string[] = []
if (row) {
arr.push(row.id)
} else {
multipleSelection.value.map((v) => {
if (v) {
arr.push(v.id)
}
})
}
SelectDatasetDialogRef.value.open(arr)
}
2024-09-10 08:15:47 +00:00
function dropdownHandle(obj: any) {
filterMethod.value[obj.attr] = obj.command
if (obj.attr == 'status') {
filterMethod.value['task_type'] = obj.task_type
}
getList()
}
function beforeCommand(attr: string, val: any, task_type?: number) {
2024-09-10 08:15:47 +00:00
return {
attr: attr,
command: val,
task_type
2024-09-10 08:15:47 +00:00
}
}
2024-11-26 04:08:13 +00:00
const cancelTask = (row: any, task_type: number) => {
documentApi.cancelTask(row.dataset_id, row.id, { type: task_type }).then(() => {
2025-01-14 11:28:30 +00:00
MsgSuccess(t('views.document.tip.sendMessage'))
2024-11-26 04:08:13 +00:00
})
}
2024-01-25 07:08:25 +00:00
2024-01-19 08:03:17 +00:00
function importDoc() {
2025-01-14 11:28:30 +00:00
title.value = t('views.document.importDocument')
2024-01-19 08:03:17 +00:00
ImportDocumentDialogRef.value.open()
}
function settingDoc(row: any) {
2025-01-14 11:28:30 +00:00
title.value = t('common.setting')
2024-01-19 08:03:17 +00:00
ImportDocumentDialogRef.value.open(row)
}
2024-01-11 06:40:00 +00:00
const handleSelectionChange = (val: any[]) => {
multipleSelection.value = val
}
function openBatchEditDocument() {
2025-01-14 11:28:30 +00:00
title.value = t('common.setting')
const arr: string[] = multipleSelection.value.map((v) => v.id)
ImportDocumentDialogRef.value.open(null, arr)
}
2023-12-20 02:57:43 +00:00
/**
* 初始化轮询
*/
const initInterval = () => {
interval = setInterval(() => {
2024-01-24 02:38:48 +00:00
getList(true)
2023-12-20 02:57:43 +00:00
}, 6000)
}
/**
* 关闭轮询
*/
const closeInterval = () => {
if (interval) {
2023-12-14 02:47:51 +00:00
clearInterval(interval)
}
2023-12-20 02:57:43 +00:00
}
function syncDocument(row: any) {
if (row.meta?.source_url) {
2025-01-14 11:28:30 +00:00
MsgConfirm(t('views.document.sync.confirmTitle'), t('views.document.sync.confirmMessage1'), {
confirmButtonText: t('views.document.sync.label'),
confirmButtonClass: 'danger'
})
.then(() => {
documentApi.putDocumentSync(row.dataset_id, row.id).then(() => {
getList()
2024-01-19 08:03:17 +00:00
})
})
.catch(() => {})
2024-01-19 08:03:17 +00:00
} else {
2025-01-14 11:28:30 +00:00
MsgConfirm(t('common.tip'), t('views.document.sync.confirmMessage2'), {
2025-01-13 03:15:51 +00:00
confirmButtonText: t('common.confirm'),
type: 'warning'
})
.then(() => {})
.catch(() => {})
2024-01-19 08:03:17 +00:00
}
2023-12-14 02:47:51 +00:00
}
function refreshDocument(row: any) {
const embeddingDocument = (stateList: Array<string>) => {
return documentApi.putDocumentRefresh(row.dataset_id, row.id, stateList).then(() => {
getList()
})
}
embeddingContentDialogRef.value?.open(embeddingDocument)
}
2023-12-14 02:47:51 +00:00
function rowClickHandle(row: any, column: any) {
if (column && column.type === 'selection') {
return
}
2023-11-24 11:02:52 +00:00
router.push({ path: `/dataset/${id}/${row.id}` })
2023-11-10 11:05:52 +00:00
}
2023-11-22 03:05:06 +00:00
/*
快速创建空白文档
*/
2023-11-10 09:18:00 +00:00
function creatQuickHandle(val: string) {
loading.value = true
2023-12-18 09:58:56 +00:00
const obj = [{ name: val }]
document
.asyncPostDocument(id, obj)
.then(() => {
2023-11-10 09:18:00 +00:00
getList()
2025-01-13 03:15:51 +00:00
MsgSuccess(t('common.createSuccess'))
2023-11-10 09:18:00 +00:00
})
.catch(() => {
loading.value = false
})
}
2024-01-19 08:03:17 +00:00
function syncMulDocument() {
const arr: string[] = []
multipleSelection.value.map((v) => {
if (v) {
arr.push(v.id)
}
})
documentApi.delMulSyncDocument(id, arr, loading).then(() => {
2025-01-14 11:28:30 +00:00
MsgSuccess(t('views.document.sync.successMessage'))
2024-01-19 08:03:17 +00:00
getList()
})
}
2024-01-19 06:59:51 +00:00
function deleteMulDocument() {
2024-12-20 03:29:28 +00:00
MsgConfirm(
2025-01-14 11:28:30 +00:00
`${t('views.document.delete.confirmTitle1')} ${multipleSelection.value.length} ${t('views.document.delete.confirmTitle2')}`,
t('views.document.delete.confirmMessage'),
2024-12-20 03:29:28 +00:00
{
2025-01-13 03:15:51 +00:00
confirmButtonText: t('common.delete'),
2024-12-20 03:29:28 +00:00
confirmButtonClass: 'danger'
2024-01-19 06:59:51 +00:00
}
2024-12-20 03:29:28 +00:00
)
.then(() => {
const arr: string[] = []
multipleSelection.value.map((v) => {
if (v) {
arr.push(v.id)
}
})
documentApi.delMulDocument(id, arr, loading).then(() => {
2025-01-14 11:28:30 +00:00
MsgSuccess(t('views.document.delete.successMessage'))
2024-12-20 03:29:28 +00:00
multipleTableRef.value?.clearSelection()
getList()
})
})
.catch(() => {})
2024-01-19 06:59:51 +00:00
}
function batchRefresh() {
const arr: string[] = multipleSelection.value.map((v) => v.id)
const embeddingBatchDocument = (stateList: Array<string>) => {
documentApi.batchRefresh(id, arr, stateList, loading).then(() => {
2025-01-15 11:10:29 +00:00
MsgSuccess(t('views.document.tip.vectorizationSuccess'))
multipleTableRef.value?.clearSelection()
})
}
embeddingContentDialogRef.value?.open(embeddingBatchDocument)
}
2023-11-10 03:36:04 +00:00
function deleteDocument(row: any) {
MsgConfirm(
2025-01-14 11:28:30 +00:00
`${t('views.document.delete.confirmTitle3')} ${row.name} ?`,
`${t('views.document.delete.confirmMessage1')} ${row.paragraph_count} ${t('views.document.delete.confirmMessage2')}`,
2023-11-10 03:36:04 +00:00
{
2025-01-13 03:15:51 +00:00
confirmButtonText: t('common.delete'),
2023-11-10 03:36:04 +00:00
confirmButtonClass: 'danger'
}
)
.then(() => {
2024-01-19 06:59:51 +00:00
documentApi.delDocument(id, row.id, loading).then(() => {
2025-01-13 03:15:51 +00:00
MsgSuccess(t('common.deleteSuccess'))
2024-01-19 06:59:51 +00:00
getList()
})
2023-11-10 03:36:04 +00:00
})
.catch(() => {})
}
2023-11-22 03:05:06 +00:00
/*
更新名称或状态
*/
2023-12-05 11:21:13 +00:00
function updateData(documentId: string, data: any, msg: string) {
documentApi
.putDocument(id, documentId, data, loading)
.then((res) => {
const index = documentData.value.findIndex((v) => v.id === documentId)
documentData.value.splice(index, 1, res.data)
MsgSuccess(msg)
return true
})
.catch(() => {
return false
})
2023-11-10 03:36:04 +00:00
}
function changeState(row: any) {
2023-11-10 03:36:04 +00:00
const obj = {
is_active: !row.is_active
2023-11-10 03:36:04 +00:00
}
2025-01-14 11:28:30 +00:00
const str = !row.is_active ? t('common.status.enableSuccess') : t('common.status.disableSuccess')
2023-12-05 11:21:13 +00:00
currentMouseId.value && updateData(row.id, obj, str)
2023-11-10 03:36:04 +00:00
}
function editName(val: string, id: string) {
2024-03-01 03:06:09 +00:00
if (val) {
const obj = {
name: val
}
2025-01-14 11:28:30 +00:00
updateData(id, obj, t('common.modifySuccess'))
2024-03-01 03:06:09 +00:00
} else {
2025-01-14 11:28:30 +00:00
MsgError(t('views.document.tip.nameMessage'))
2023-11-10 03:36:04 +00:00
}
}
2023-11-09 10:52:06 +00:00
function cellMouseEnter(row: any) {
currentMouseId.value = row.id
}
function cellMouseLeave() {
currentMouseId.value = null
}
2023-12-05 06:27:50 +00:00
function handleSizeChange() {
paginationConfig.value.current_page = 1
getList()
2023-11-09 10:52:06 +00:00
}
2023-11-07 11:04:59 +00:00
2023-12-14 02:47:51 +00:00
function getList(bool?: boolean) {
const param = {
...(filterText.value && { name: filterText.value }),
2024-09-10 08:15:47 +00:00
...filterMethod.value
}
2023-11-22 10:37:08 +00:00
documentApi
.getDocument(id as string, paginationConfig.value, param, bool ? undefined : loading)
2023-11-07 11:04:59 +00:00
.then((res) => {
2023-12-06 09:30:46 +00:00
documentData.value = res.data.records
paginationConfig.value.total = res.data.total
2023-11-07 11:04:59 +00:00
})
}
2024-01-10 09:44:05 +00:00
function getDetail() {
2024-04-15 10:46:03 +00:00
dataset.asyncGetDatasetDetail(id, loading).then((res: any) => {
2024-01-10 09:44:05 +00:00
datasetDetail.value = res.data
})
}
function refreshMigrate() {
multipleTableRef.value?.clearSelection()
getList()
}
2024-01-19 08:03:17 +00:00
function refresh() {
paginationConfig.value.current_page = 1
2024-01-19 08:03:17 +00:00
getList()
}
const GenerateRelatedDialogRef = ref()
function openGenerateDialog(row?: any) {
const arr: string[] = []
if (row) {
arr.push(row.id)
} else {
multipleSelection.value.map((v) => {
if (v) {
arr.push(v.id)
}
})
}
GenerateRelatedDialogRef.value.open(arr, 'document')
}
2023-11-07 11:04:59 +00:00
onMounted(() => {
2024-01-10 09:44:05 +00:00
getDetail()
if (beforePagination.value) {
paginationConfig.value = beforePagination.value
}
if (beforeSearch.value) {
filterText.value = beforeSearch.value['filterText']
filterMethod.value = beforeSearch.value['filterMethod']
}
2023-11-07 11:04:59 +00:00
getList()
2023-12-20 02:57:43 +00:00
// 初始化定时任务
initInterval()
})
onBeforeUnmount(() => {
// 清除定时任务
closeInterval()
2023-11-07 11:04:59 +00:00
})
</script>
2024-12-24 09:09:27 +00:00
<style lang="scss" scoped>
.document-main {
box-sizing: border-box;
.mul-operation {
position: fixed;
margin-left: var(--sidebar-width);
bottom: 0;
right: 24px;
width: calc(100% - var(--sidebar-width) - 48px);
padding: 16px 24px;
box-sizing: border-box;
background: #ffffff;
z-index: 22;
box-shadow: 0px -2px 4px 0px rgba(31, 35, 41, 0.08);
}
}
</style>