1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720 |
- <template>
- <div class="project-search">
- <div class="file-categories">
- <el-button type="primary" @click="createNewFolder">
- <i class="el-icon-plus"></i> 新建目录
- </el-button>
- <p>{{ $route.query.name }}</p>
- <el-tree
- :data="folders"
- :props="defaultProps"
- @node-click="handleNodeClick"
- ref="folderTree"
- :default-expanded-keys="['0']"
- node-key="id"
- highlight-current
- >
- <span class="custom-tree-node" slot-scope="{ node, data }">
- <span class="tree_title">
- <i class="el-icon-folder"></i>
- <span class="folder-name" :title="node.label">{{
- node.label
- }}</span>
- </span>
- <span v-if="data.id !== '001'" :class="getFileCountClass(data.id)"
- >{{ data.document_count }} files</span
- >
- <span
- class="folder-actions"
- v-if="data.id !== 0 && data.id !== '001'"
- >
- <el-tooltip
- class="item"
- effect="dark"
- content="编辑"
- placement="top"
- >
- <i class="el-icon-edit" @click.stop="editFolder(data)"></i>
- </el-tooltip>
- <el-tooltip
- class="item"
- effect="dark"
- content="删除"
- placement="top"
- >
- <i class="el-icon-delete" @click.stop="deleteFolder(data.id)"></i>
- </el-tooltip>
- </span>
- </span>
- </el-tree>
- </div>
- <div class="right">
- <dataSearch
- @bindSetQuery="setQuery"
- @refreshFolders="typeList"
- ></dataSearch>
- <!-- <dataList
- :queryForm="queryForm"
- :allowEdit="checkAuth('/document/update')"
- :allowDelete="checkAuth('/document/delete')"
- ></dataList> -->
- <div
- class="data-list"
- v-loading="loading"
- element-loading-text="加载中..."
- >
- <div class="batch-actions" style="margin: 10px 0">
- <el-dropdown
- @command="handleBatchCommand"
- :disabled="!selectedRows.length"
- >
- <el-button type="primary" style="color: #fff">
- 批量操作
- <i data-feather="chevron-down" class="el-icon--right icons"></i>
- </el-button>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item command="analysis">
- <i data-feather="play" class="icons"></i> 批量解析
- </el-dropdown-item>
- <el-dropdown-item command="modifyFolder">
- <i data-feather="folder" class="icons"></i> 批量修改目录
- </el-dropdown-item>
- <el-dropdown-item command="delete">
- <i data-feather="trash-2" class="icons"></i> 批量删除
- </el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- <el-button type="danger" @click="endAnalysis()">
- <i data-feather="stop-circle" class="icons"></i>
- 终止所有任务
- </el-button>
- </div>
- <div class="selection-control" v-if="selectedRows.length > 0">
- <el-alert
- type="info"
- show-icon
- :closable="false"
- style="margin-bottom: 10px"
- >
- <template v-if="!isAllDataSelected">
- <!-- <span>已选择 {{ selectedRows.length }} 项</span> -->
- <span
- type="text"
- style="cursor: pointer; color: #409eff; margin-left: 10px"
- @click="handleSelectAllData"
- >
- 选择全部{{ recordCount }}条数据
- </span>
- </template>
- <template v-else>
- <span>已选择全部{{ recordCount }}条数据</span>
- <span
- type="text"
- style="cursor: pointer; color: #409eff; margin-left: 10px"
- @click="handleCancelAllSelection"
- >
- 取消全选
- </span>
- </template>
- </el-alert>
- </div>
- <el-table
- ref="dataTable"
- :data="dataList"
- style="width: 100%; font-size: 12px"
- header-row-class-name="headerBg"
- empty-text="暂无数据"
- @selection-change="handleSelectionChange"
- @sort-change="handleSortChange"
- :row-key="getRowKey"
- >
- <el-table-column
- type="selection"
- width="55"
- :reserve-selection="true"
- ></el-table-column>
- <el-table-column prop="id" label="ID" align="center" width="80" />
- <el-table-column prop="name" label="文件名称" sortable width="350">
- <template #default="scope">
- <span>{{ scope.row.name }}</span>
- </template>
- </el-table-column>
- <el-table-column prop="type" label="文件类型" align="center" />
- <el-table-column prop="chunk_num" label="分块数" align="center" />
- <el-table-column
- prop="create_time"
- label="上传时间"
- align="center"
- sortable
- width="140"
- />
- <el-table-column prop="run" label="解析状态" align="center">
- <template #default="scope">
- <el-tooltip
- effect="dark"
- placement="top"
- :disabled="
- Number(scope.row.run) !== 1 && Number(scope.row.run) !== 4
- "
- >
- <template #content>
- <div style="padding: 5px">
- <div style="margin-top: 5px; font-size: 12px">
- {{ scope.row.progress_msg || "正在解析中..." }}
- </div>
- </div>
- </template>
- <div class="status-wrapper">
- <template v-if="Number(scope.row.run) === 1">
- <div class="progress-wrapper">
- <el-progress
- type="circle"
- :percentage="Math.floor(scope.row.progress) || 0"
- :width="30"
- :stroke-width="2"
- :format="percentFormat"
- ></el-progress
- ><!-- :status="getProgressStatus(scope.row.progress)" -->
- </div>
- </template>
- <template v-else>
- <el-tag :type="getStatusType(scope.row.run)" size="small">
- {{ getStatusText(scope.row.run) }}
- </el-tag>
- </template>
- </div>
- </el-tooltip>
- </template>
- </el-table-column>
- <el-table-column
- label="操作"
- align="center"
- fixed="right"
- width="180"
- >
- <template #default="scope">
- <div class="operations-container">
- <el-tooltip
- class="item"
- effect="dark"
- content="预览"
- placement="top"
- >
- <el-button
- type="text"
- size="small"
- circle
- icon="el-icon-view"
- v-if="checkAuth('/document/update')"
- style="font-size: 15px"
- @click="getName(scope.row)"
- ></el-button>
- </el-tooltip>
- <el-tooltip
- class="item"
- effect="dark"
- content="修改文件名"
- placement="top"
- >
- <el-button
- type="text"
- size="small"
- circle
- icon="el-icon-edit"
- v-if="checkAuth('/document/update')"
- style="font-size: 15px"
- @click="btnEdit(scope.row)"
- ></el-button>
- </el-tooltip>
- <el-popover
- placement="bottom"
- trigger="click"
- popper-class="operations-popover"
- >
- <template #reference>
- <el-button
- type="text"
- size="small"
- circle
- class="operation-button"
- style="font-size: 15px; margin-left: 10px"
- icon="el-icon-more"
- ></el-button>
- </template>
- <div class="additional-operations">
- <el-tooltip
- class="item"
- effect="dark"
- :content="
- scope.row.run == 1 || scope.row.run == 5
- ? `解析中`
- : '解析'
- "
- placement="top"
- >
- <el-button
- v-if="scope.row.run != 1 && scope.row.run != 5"
- type="text"
- icon="el-icon-caret-right"
- circle
- @click="analysis(scope.row)"
- style="font-size: 15px"
- >
- </el-button>
- <el-button
- v-else
- type="text"
- icon="el-icon-loading"
- circle
- :disabled="true"
- style="font-size: 15px"
- >
- </el-button>
- </el-tooltip>
- <el-tooltip
- class="item"
- effect="dark"
- content="解析方法"
- placement="top"
- >
- <el-button
- type="text"
- size="small"
- circle
- icon="el-icon-tickets"
- v-if="checkAuth('/document/update')"
- style="font-size: 15px"
- @click="Analytical(scope.row)"
- ></el-button>
- </el-tooltip>
- <el-tooltip
- class="item"
- effect="dark"
- content="下载"
- placement="top"
- >
- <el-button
- type="text"
- size="small"
- circle
- icon="el-icon-download"
- @click="btnDown(scope.row)"
- :loading="scope.row.downloading"
- style="font-size: 15px"
- ></el-button>
- </el-tooltip>
- <el-tooltip
- class="item"
- effect="dark"
- content="删除"
- placement="top"
- >
- <el-button
- type="text"
- size="small"
- circle
- icon="el-icon-delete"
- v-if="checkAuth('/document/delete')"
- @click="btnDelete(scope.row.id)"
- style="font-size: 15px"
- ></el-button>
- </el-tooltip>
- </div>
- </el-popover>
- </div>
- </template>
- </el-table-column>
- </el-table>
- <div class="page-info">
- <el-pagination
- :currentPage="queryForm.page"
- :page-size="queryForm.pageSize"
- :total="recordCount"
- :page-count="pageTotal"
- :page-sizes="[10, 20, 50, 100]"
- background
- layout="total,sizes, prev, pager, next"
- @current-change="ChangePage"
- @size-change="handleSizeChange"
- >
- </el-pagination>
- </div>
- <el-dialog
- title="修改名称"
- :visible.sync="dialogVisible"
- width="30%"
- :before-close="handleClose"
- >
- <el-form :model="wordForm" ref="wordRef" :rules="wordRules">
- <el-form-item label="文件名称:" prop="new_name">
- <el-input
- v-model="wordForm.new_name"
- placeholder="请输入文件名称"
- ></el-input>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="handleClose">取 消</el-button>
- <el-button type="primary" @click="submitBuck">确 定</el-button>
- </span>
- </el-dialog>
- <!-- 解析方法 -->
- <el-dialog
- title="解析方法"
- :visible.sync="anaDialogVisible"
- width="30%"
- :before-close="handleAnalClose"
- >
- <el-form
- :model="analForm"
- ref="analRef"
- label-position="top"
- :rules="analRules"
- >
- <el-form-item label="语言选择:" prop="language">
- <el-radio-group v-model="analForm.language">
- <el-radio label="zh">中文</el-radio>
- <el-radio label="en">英文</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="页码范围:" prop="new_name">
- <el-input-number
- v-model="analForm.start_page"
- controls-position="right"
- :min="1"
- ></el-input-number>
- <el-input-number
- v-model="analForm.end_page"
- controls-position="right"
- :min="1"
- style="margin-left: 10px"
- ></el-input-number>
- </el-form-item>
- <el-form-item label="块token数">
- <div class="block">
- <el-slider v-model="analForm.token_num" :max="2048" show-input>
- </el-slider>
- </div>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button type="primary" @click="handleAnalClose">取 消</el-button>
- <el-button type="primary" @click="submitAnal">确 定</el-button>
- </span>
- </el-dialog>
- <el-dialog
- title="新建目录"
- :visible.sync="newFolderDialogVisible"
- width="30%"
- >
- <el-form
- :model="newFolderForm"
- :rules="newFolderRules"
- ref="newFolderFormRef"
- >
- <el-form-item label="文件夹名称" prop="name">
- <el-input v-model="newFolderForm.name"></el-input>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button type="primary" @click="newFolderDialogVisible = false"
- >取 消</el-button
- >
- <el-button type="primary" @click="submitNewFolder">确 定</el-button>
- </span>
- </el-dialog>
- <!-- 批量修改目录 -->
- <el-dialog
- title="批量修改目录"
- :visible.sync="batchModifyFolderDialogVisible"
- width="30%"
- >
- <el-form
- :model="batchModifyFolderForm"
- :rules="batchModifyFolderRules"
- ref="batchModifyFolderFormRef"
- >
- <el-form-item label="选择目录" prop="folderId">
- <el-select
- v-model="batchModifyFolderForm.folderId"
- placeholder="请选择目录"
- >
- <el-option
- v-for="folder in folders.filter((f) => f.id !== 0)"
- :key="folder.id"
- :label="folder.name"
- :value="folder.id"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button
- type="primary"
- @click="batchModifyFolderDialogVisible = false"
- >取 消</el-button
- >
- <el-button type="primary" @click="submitBatchModifyFolder"
- >确 定</el-button
- >
- </span>
- </el-dialog>
- </div>
- </div>
- </div>
- </template>
-
- <script>
- import { mapGetters } from "vuex";
- import { dataSearch, dataList } from "./components";
- import {
- getBucketContents,
- deleteFile,
- nameGetUrl,
- renameFile,
- analysis,
- batchAnalysis,
- getRunStatus,
- insertType,
- updateType,
- selectTypeList,
- deleteType,
- Info,
- batchMove,
- selectType0,
- delDocumentList,
- getdocpro,
- analysisPro,
- resultTask,
- endClear,
- } from "@/api/knowledge";
- export default {
- components: {
- dataSearch,
- dataList,
- },
- computed: {
- ...mapGetters(["roleInfo", "authList"]),
- },
- data() {
- return {
- queryForm: {
- page: 1,
- pageSize: 10,
- bucket_id: "",
- doc_type_id: 0,
- },
- typeForm: {
- page: 1,
- pageSize: 9999,
- kb_id: "",
- },
- folders: [{ id: "001", name: "全部", document_count: 0 }],
- defaultProps: {
- children: "children",
- label: "name",
- },
- // dataList 组件的数据
- loading: false,
- dialogVisible: false,
- currentDataId: 0,
- recordCount: 0,
- pageTotal: 1,
- dataList: [],
- currentData: {},
- wordForm: {
- document_id: "",
- new_name: "",
- },
- wordRules: {
- new_name: [
- { required: true, message: "请输文件名称", trigger: "blur" },
- ],
- },
- anaDialogVisible: false,
- analForm: {
- start_page: 1,
- end_page: 10000,
- token_num: 0,
- language:'zh'
- },
- analRules: {},
- selectedRows: [],
- sortColumn: "",
- sortOrder: "",
- analysisStatusCheckers: {},
- newFolderDialogVisible: false,
- newFolderForm: {
- name: "",
- kb_id: "",
- status: 5,
- },
- newFolderRules: {
- name: [
- { required: true, message: "请输入文件夹名称", trigger: "blur" },
- ],
- },
- /* 批量修改目录 */
- batchModifyFolderDialogVisible: false,
- batchModifyFolderForm: {
- folderId: null,
- },
- batchModifyFolderRules: {
- folderId: [
- { required: true, message: "请选择目标目录", trigger: "change" },
- ],
- },
- selectedRows: [], // 已选择的行
- allSelectedRows: new Map(), // 存储所有选中的行
- isAllDataSelected: false, // 是否选中所有数据
- };
- },
- mounted() {
- this.queryForm.bucket_id = this.$route.query.id;
- this.typeForm.kb_id = this.$route.query.id;
- /* this.$nextTick(() => {
- this.initializeTree();
- }); */
- this.typeList();
- /* this.search(); */
- },
- beforeDestroy() {
- Object.values(this.analysisStatusCheckers).forEach(clearTimeout);
- },
- methods: {
- // 获取行的唯一标识
- getRowKey(row) {
- return row.id;
- },
- /* 功按钮 */
- handleBatchCommand(command) {
- switch (command) {
- case "analysis":
- this.batchAnalysis();
- break;
- case "modifyFolder":
- this.batchModifyFolder();
- break;
- case "delete":
- this.batchDelect();
- break;
- }
- },
- getProgressStatus(progress) {
- // el-progress 只接受 'success'/'exception'/'warning' 这几个值
- if (progress >= 100) {
- return "success";
- }
- // 如果进度小于100,返回undefined,使用默认样式
- return undefined;
- },
- /* 操作栏 */
- handleCommand(command, row) {
- switch (command) {
- case "analysis":
- this.analysis(row);
- break;
- case "analyticalMethod":
- this.Analytical(row);
- break;
- case "download":
- this.btnDown(row);
- break;
- case "delete":
- this.btnDelete(row.id);
- break;
- }
- },
- /* 状态展示 */
- getStatusType(status) {
- const statusMap = {
- 0: "info", // 未解析
- 1: "warning", // 解析中
- 3: "success", // 成功
- 4: "danger", // 失败
- 5: "info", // 待解析
- 6: "danger", // 文件异常
- };
- return statusMap[status] || "info";
- },
- getStatusText(status) {
- const statusMap = {
- 0: "未解析",
- 1: "解析中",
- 3: "解析成功",
- 4: "解析失败",
- 5: "待解析",
- 6: "文件异常",
- };
- return statusMap[status] || "未知状态";
- },
- /* 判断类名 */
- getFileCountClass(id) {
- const isSpecialFolder = id === 0 || id === "001";
- console.log(
- `ID: ${id}, Class: ${isSpecialFolder ? "file-counts" : "file-count"}`
- );
- return isSpecialFolder ? "file-counts" : "file-count";
- },
- /* 批量修改目录 */
- batchModifyFolder() {
- if (this.selectedRows.length === 0) {
- this.$message.warning("请选择要修改目录的文件");
- return;
- }
- this.batchModifyFolderDialogVisible = true;
- },
- submitBatchModifyFolder() {
- this.$refs.batchModifyFolderFormRef.validate((valid) => {
- if (valid) {
- const selectedIds = this.selectedRows.map((row) => row.id);
- console.log(selectedIds);
- batchMove({
- ids: JSON.stringify(selectedIds),
- doc_type_id: this.batchModifyFolderForm.folderId,
- })
- .then((res) => {
- if (res.status === 200) {
- this.$message.success("批量修改目录成功");
- this.batchModifyFolderDialogVisible = false;
- this.search(); // Refresh the document list
- this.typeList(); // Refresh the folder list
- this.clearSelection();
- } else {
- this.$message.error("批量修改目录失败");
- }
- })
- .catch((error) => {
- console.error("批量修改目录时出错:", error);
- this.$message.error("批量修改目录时出错");
- });
- }
- });
- },
- editFolder(folder) {
- this.$prompt("请输入新的文件夹名称", "编辑文件夹", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- inputValue: folder.name,
- inputValidator: (value) => {
- if (!value) {
- return "文件夹名称不能为空";
- }
- return true;
- },
- })
- .then(({ value }) => {
- if (value !== folder.name) {
- const updatedFolder = { ...folder, name: value };
- updateType(updatedFolder)
- .then((res) => {
- if (res.status === 200) {
- this.$message.success("更新文件夹成功");
- this.typeList(); // 刷新文件夹列表
- } else {
- this.$message.error("更新文件夹失败");
- }
- })
- .catch((error) => {
- console.error("更新文件夹时出错:", error);
- this.$message.error("更新文件夹时出错");
- });
- }
- })
- .catch(() => {
- // 用户取消操作,不做任何处理
- });
- },
- deleteFolder(folderId) {
- this.$confirm("确定要删除该文件夹吗?删除后无法恢复。", "警告", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- deleteType({ id: folderId })
- .then((res) => {
- if (res.status === 200) {
- this.$message.success("删除文件夹成功");
- this.typeList(); // 刷新文件夹列表
- } else {
- this.$message.error("删除文件夹失败");
- }
- })
- .catch((error) => {
- console.error("删除文件夹时出错:", error);
- this.$message.error("删除文件夹时出错");
- });
- })
- .catch(() => {
- // 用户取消删除操作,不做任何处理
- });
- },
- /* 目录初始化 */
- typeList() {
- this.loading = true;
- Promise.all([
- selectTypeList(this.typeForm),
- selectType0({ kb_id: this.typeForm.kb_id, type_id: 0 }),
- ])
- .then(([typeListRes, type0Res]) => {
- if (typeListRes.status === 200 && type0Res.status === 200) {
- const folderList = typeListRes.data.dataList.map((folder) => ({
- ...folder,
- id: folder.id === 0 ? "001" : folder.id.toString(),
- document_count: folder.document_count || 0,
- }));
- // Calculate total documents
- const totalDocuments = folderList.reduce(
- (sum, folder) => sum + folder.document_count,
- 0
- );
- // Get the count of "其他" documents from selectType0 response
- const otherFolderCount = type0Res.data || 0;
- this.folders = [
- {
- id: "001",
- name: "全部",
- document_count: totalDocuments + otherFolderCount,
- },
- ...folderList.filter(
- (folder) => folder.id !== "001" && folder.id !== 0
- ),
- {
- id: 0,
- name: "其他",
- document_count: otherFolderCount,
- },
- ];
- // 直接在这里执行一次性的初始化
- this.$nextTick(() => {
- if (this.$refs.folderTree) {
- this.$refs.folderTree.setCurrentKey("001");
- // 只在这里调用一次 search
- this.queryForm.doc_type_id = "";
- this.search();
- }
- });
- } else {
- this.$message.error("获取文件夹列表败");
- }
- })
- .catch((error) => {
- console.error("获取文件夹列表时出错:", error);
- this.$message.error("获取文件夹列表时出错");
- })
- .finally(() => {
- this.loading = false;
- });
- },
- /* initializeTree() {
- this.$nextTick(() => {
- if (this.$refs.folderTree) {
- this.$refs.folderTree.setCurrentKey(0);
- this.handleNodeClick(this.folders[0]);
- }
- });
- }, */
- createNewFolder() {
- this.newFolderDialogVisible = true;
- },
- /* 新增 */
- submitNewFolder() {
- this.$refs.newFolderFormRef.validate((valid) => {
- if (valid) {
- this.newFolderForm.kb_id = this.$route.query.id;
- insertType(this.newFolderForm).then((res) => {
- if (res.status === 200) {
- this.$message.success("创建文件夹成功");
- this.newFolderDialogVisible = false;
- this.$refs.newFolderFormRef.resetFields();
- this.typeList(); // Refresh folder list
- } else {
- this.$message.error("创建文件夹失败");
- }
- });
- }
- });
- },
- // 移除或简化 initializeTree 方法,因为相关逻辑已经到 typeList 中
- initializeTree() {
- // 可以保留这个方法但不执行 search
- this.$nextTick(() => {
- if (this.$refs.folderTree) {
- this.$refs.folderTree.setCurrentKey("001");
- }
- });
- },
- /* initializeTree() {
- this.$nextTick(() => {
- if (this.$refs.folderTree) {
- this.$refs.folderTree.setCurrentKey("001");
- this.handleNodeClick(this.folders[0]);
- }
- });
- }, */
- checkAuth(path) {
- if (this.roleInfo.is_admin === 1) {
- return true;
- }
- return this.authList.some(
- (auth) => auth.type === 999 && auth.path === path
- );
- },
- setQuery(e) {
- this.queryForm = { ...this.queryForm, ...e };
- this.search();
- },
- handleNodeClick(data) {
- this.queryForm.doc_type_id = data.id === "001" ? "" : data.id;
- this.queryForm.page = 1; // Reset to first page when changing folder
- this.search();
- },
- /*列表事件 */
- /* 排序 */
- handleSortChange({ prop, order }) {
- this.sortColumn = prop;
- this.sortOrder = order;
- this.sortData();
- },
- sortData() {
- const { sortColumn, sortOrder } = this;
- if (!sortColumn || !sortOrder) {
- this.search(); // Reset to original order
- return;
- }
- this.dataList.sort((a, b) => {
- let comparison = 0;
- if (sortColumn === "name") {
- comparison = a.name.localeCompare(b.name, "zh-CN");
- } else if (sortColumn === "create_time") {
- comparison = new Date(a.create_time) - new Date(b.create_time);
- }
- return sortOrder === "ascending" ? comparison : -comparison;
- });
- },
- /* 处理选择变化*/
- handleSelectionChange(selection) {
- if (!this.isAllDataSelected) {
- // 更新当前页选中状态
- this.dataList.forEach((row) => {
- if (selection.find((item) => item.id === row.id)) {
- this.allSelectedRows.set(row.id, row);
- } else {
- this.allSelectedRows.delete(row.id);
- }
- });
- this.selectedRows = Array.from(this.allSelectedRows.values());
- }
- },
- // 选择全部数据
- async handleSelectAllData() {
- try {
- // 构建查询参数,获取所有数据
- const params = {
- ...this.queryForm,
- page: 1,
- page_size: this.recordCount,
- };
- const response = await getBucketContents(params);
- if (response.status === 200) {
- const allData = response.data.documents;
- // 清空之前的选择
- this.allSelectedRows.clear();
- // 将所有数据添加到选中集合
- allData.forEach((item) => {
- this.allSelectedRows.set(item.id, item);
- });
- this.isAllDataSelected = true;
- this.selectedRows = allData;
- // 选中当前页显示的所有行
- this.$nextTick(() => {
- if (this.$refs.dataTable) {
- this.dataList.forEach((row) => {
- this.$refs.dataTable.toggleRowSelection(row, true);
- });
- }
- });
- this.$message.success(`已选中全部${this.recordCount}条数据`);
- }
- } catch (error) {
- console.error("获取全部数据失败:", error);
- this.$message.error("选择全部数据失败");
- }
- },
- // 取消全选
- handleCancelAllSelection() {
- this.clearSelection();
- this.isAllDataSelected = false;
- this.$message.info("已取消全部选择");
- },
- // 修改清除选择方法
- clearSelection() {
- if (this.$refs.dataTable) {
- this.$refs.dataTable.clearSelection();
- }
- this.selectedRows = [];
- this.allSelectedRows.clear();
- this.isAllDataSelected = false;
- },
- // 修改分页方法,保持选中状态
- ChangePage(e) {
- this.queryForm.page = e;
- this.search().then(() => {
- this.$nextTick(() => {
- if (this.$refs.dataTable) {
- this.dataList.forEach((row) => {
- if (this.isAllDataSelected || this.allSelectedRows.has(row.id)) {
- this.$refs.dataTable.toggleRowSelection(row, true);
- }
- });
- }
- });
- });
- },
- batchAnalysis() {
- const selectedIds = this.selectedRows.map((row) => row.id);
- if (selectedIds.length === 0) {
- this.$message.warning("请选择要解析的文件");
- return;
- }
- this.$confirm("确定要批量解析选中的文件吗?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- this.loading = true;
- analysisPro({
- document_ids: JSON.stringify(selectedIds),
- ocr_params: {
- language: this.analForm.language,
- max_retries: 3,
- timeout: [10, 180],
- },
- }) /* { ids: JSON.stringify(selectedIds) } */
- .then((res) => {
- if (res.status === 200) {
- this.$message.success("批量解析任务已提交");
- this.updateAnalysisStatus(selectedIds);
- this.clearSelection();
- } else {
- this.$message.error("批量解析请求失败");
- }
- })
- .catch((error) => {
- console.error("批量解析错误:", error);
- this.$message.error("批量解析过程中出错误");
- })
- .finally(() => {
- this.loading = false;
- });
- })
- .catch(() => {
- // 取消操作
- });
- },
- /* 批量删除 */
- batchDelect() {
- const selectedIds = this.selectedRows.map((row) => row.id);
- if (selectedIds.length === 0) {
- this.$message.warning("请选择要删除的文件");
- return;
- }
- this.$confirm("确定要批量删除选中的文件吗?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- this.loading = true;
- delDocumentList({ document_ids: JSON.stringify(selectedIds) })
- .then((res) => {
- if (res.status === 200) {
- this.$message.success("批量删除已完成");
- this.search();
- } else {
- this.$message.error("批量删除请求失败");
- }
- })
- .catch((error) => {
- /* console.error("批量删除错误:", error);
- this.$message.error("批量删除过程中出现错误"); */
- })
- .finally(() => {
- this.loading = false;
- });
- })
- .catch(() => {
- // 取消操作
- });
- },
- updateAnalysisStatus(ids) {
- this.dataList.forEach((row) => {
- if (ids.includes(row.id)) {
- row.run = 1; // 设置状态为"解析中"
- this.startAnalysisStatusChecker(row);
- }
- });
- },
- clearSelection() {
- this.$refs.dataTable.clearSelection();
- this.selectedRows = [];
- },
- /* 跳转页面 */
- getName(e) {
- /* this.$router.push({
- path: "/knowledge/category/infoList",
- query: { id: e.id, type: e.type },
- }); */
- let _this = this;
- let a = document.createElement("a");
- a.href = `#/infoList?id=${e.id}&type=${e.type.toLowerCase()}`; // 使用 hash
- a.target = "_blank";
- a.click();
- },
- /*终止 */
- endAnalysis() {
- endClear().then((res) => {
- if (res.status !== 200) return;
- this.search();
- });
- },
- /* 解析 */
- analysis(row) {
- if (row.run == 1 || row.run == 5) return;
- // Set the status to "解析中" (1) immediately
- this.$set(row, "run", 1);
- const analysisConfig = {
- document_ids: JSON.stringify([row.id]),
- start_page: row.start_page ?? 0, // 使用空值合并运算符
- end_page: row.end_page ?? 1000, // 使用空值合并运算符
- max_tokens: row.token_num,
- ocr_params: {
- language: this.analForm.language, //en,zh
- max_retries: 3,
- timeout: [10, 180],
- },
- };
- analysisPro(analysisConfig)
- .then((res) => {
- if (res.status === 200) {
- // Start checking the status immediately after successful API call
- setTimeout(() => {
- this.startAnalysisStatusChecker(row);
- });
- } else {
- this.$message.error("解析请求失败");
- this.$set(row, "run", 0);
- }
- })
- .catch((error) => {
- console.error("解析错误:", error);
- this.$message.error("解析过程中出现错误");
- this.$set(row, "run", 0);
- });
- },
- startAnalysisStatusChecker(row) {
- // Clear any existing checker for this row
- if (this.analysisStatusCheckers[row.id]) {
- clearTimeout(this.analysisStatusCheckers[row.id]);
- }
- /* 获取token数 */
- /* const checkStatus = () => {
- getdocpro({ document_id: row.id })
- .then((res) => {
- if (res.status === 200) {
- const newStatus = Number(res.data.status);
- const newProgress = Number(res.data.total_tasks);
- this.$set(row, "run", newStatus);
- this.$set(row, "progress", newProgress);
- if (newStatus === 3) {
- this.$message.success("解析成功");
- delete this.analysisStatusCheckers[row.id];
- // 在这里添加刷新列表的逻辑
- this.refreshCurrentList();
- } else if (newStatus === 4) {
- this.$message.error("解析失败");
- delete this.analysisStatusCheckers[row.id];
- } else if (newStatus === 1 || newStatus === 5) {
- // Continue checking
- this.analysisStatusCheckers[row.id] = setTimeout(
- checkStatus,
- 15000
- );
- }
- } else {
- this.$message.error("获取解析状态失败");
- delete this.analysisStatusCheckers[row.id];
- }
- })
- .catch((error) => {
- console.error("获取解析状态错误:", error);
- this.$message.error("获取解析状态时出现错误");
- delete this.analysisStatusCheckers[row.id];
- });
- }; */
- /* 监控任务 */
- const checkStatus = () => {
- resultTask(row.id)
- .then((res) => {
- if (res.status === 200) {
- const newStatus = Number(res.data.document_status);
- const newProgress = Number(res.data.progress);
- const newProgressMsg = res.data.progress_msg;
- this.$set(row, "run", newStatus);
- this.$set(row, "progress", newProgress);
- this.$set(row, "progress_msg", newProgressMsg);
- if (newStatus === 3) {
- this.$message.success("解析成功");
- delete this.analysisStatusCheckers[row.id];
- // 在这里添加刷新列表的逻辑
- this.refreshCurrentList();
- } else if (newStatus === 4) {
- this.$message.error("解析失败");
- delete this.analysisStatusCheckers[row.id];
- } else if (newStatus === 1 || newStatus === 5) {
- // Continue checking
- this.analysisStatusCheckers[row.id] = setTimeout(
- checkStatus,
- 15000
- );
- }
- } else {
- this.$message.error("获取解析状态失败");
- delete this.analysisStatusCheckers[row.id];
- }
- })
- .catch((error) => {
- console.error("获取解析状态错误:", error);
- this.$message.error("获取解析状态时出现错误");
- delete this.analysisStatusCheckers[row.id];
- });
- };
- // Start checking immediately
- checkStatus();
- },
- // 修改 refreshCurrentList 方法
- refreshCurrentList() {
- // 保存当前页码和每页显示数量
- const currentPage = this.queryForm.page;
- const currentPageSize = this.queryForm.pageSize;
- // 重新获取数据
- return this.search()
- .then(() => {
- // 恢复之前的页码和每页显示数量
- this.queryForm.page = currentPage;
- this.queryForm.pageSize = currentPageSize;
- })
- .catch((error) => {
- console.error("刷新列表时出错:", error);
- this.$message.error("刷新列表失败,请稍后重试");
- });
- },
- handleAnalClose() {
- this.anaDialogVisible = false;
- },
- /* 确认 */
- submitAnal() {
- this.dataList.map((el) => {
- if (this.analForm.id == el.id) {
- el.language=this.analForm.language
- el.start_page = this.analForm.start_page;
- el.end_page = this.analForm.end_page;
- el.token_num = this.analForm.token_num;
- }
- });
- this.anaDialogVisible = false;
- },
- /* 解析方法 */
- Analytical(e) {
- this.analForm.id = e.id;
- this.analForm.token_num = e.token_num;
- this.anaDialogVisible = true;
- },
- editWidth() {
- if (this.allowDelete && this.allowEdit) {
- return 200;
- }
- if (this.allowDelete || this.allowEdit) {
- return 120;
- }
- return 100;
- },
- onFocusVal(e) {
- let _this = this;
- _this.currentDataId = e.target.dataset.id;
- },
- onChangeVal(e) {
- let _this = this;
- let par = {
- id: _this.currentDataId,
- val: e,
- };
- },
- btnDelete(e) {
- let _this = this;
- let par = {
- document_id: e,
- };
- _this
- .$confirm("您是否确认删除该记录?", "提示", {
- confirmButtonText: "确认",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then((res) => {
- deleteFile(par).then((res) => {
- if (res.status !== 200) return;
- _this.$message.success(res.data);
- _this.search();
- });
- })
- .catch(() => {});
- },
- searchData() {
- let _this = this;
- _this.dialogVisible = false;
- _this.search();
- },
- /* 关闭 */
- handleClose(done) {
- done();
- },
- /* 修改文件名 */
- btnEdit(e) {
- this.wordForm.new_name = e.name;
- this.wordForm.document_id = e.id;
- this.dialogVisible = true;
- },
- /* 提交 */
- submitBuck() {
- this.$refs.wordRef.validate((valid) => {
- if (valid) {
- renameFile(this.wordForm).then((res) => {
- if (res.status !== 200) return;
- this.search();
- this.dialogVisible = false;
- this.wordForm = {
- new_name: "",
- document_id: "",
- };
- });
- } else {
- this.$message.error("请填写文档名称");
- }
- });
- },
- //下载
- btnDown(e) {
- // Set downloading flag for this specific row
- this.$set(e, "downloading", true);
- nameGetUrl({
- document_id: e.id,
- })
- .then((res) => {
- if (res.status !== 200) {
- this.$message.error("获取下载链接失败");
- return;
- }
- return fetch(res.data.url);
- })
- .then((response) => response.blob())
- .then((blob) => {
- const url = window.URL.createObjectURL(blob);
- const link = document.createElement("a");
- link.href = url;
- link.download = e.name;
- document.body.appendChild(link);
- link.click();
- setTimeout(() => {
- document.body.removeChild(link);
- window.URL.revokeObjectURL(url);
- }, 100);
- })
- .catch((error) => {
- console.error("下载出错:", error);
- this.$message.error("下载失败,请稍后重试");
- })
- .finally(() => {
- // Reset downloading flag when done
- this.$set(e, "downloading", false);
- });
- },
- handleClose() {
- let _this = this;
- _this.currentData = {};
- _this.dialogVisible = false;
- },
- //搜索
- search() {
- let _this = this;
- _this.loading = true;
- return new Promise((resolve, reject) => {
- getBucketContents(_this.queryForm)
- .then((res) => {
- if (res.status !== 200) {
- reject(new Error("Invalid response status"));
- return;
- }
- _this.dataList = res.data.documents.map((el) => ({
- ...el,
- token_num: 256,
- start_page: _this.analForm.start_page,
- end_page: _this.analForm.end_page,
- }));
- // 获取失败状态的文档的失败原因
- const failedDocs = _this.dataList.filter(
- (doc) => Number(doc.run) === 4
- );
- if (failedDocs.length > 0) {
- Promise.all(
- failedDocs.map((doc) =>
- resultTask(doc.id)
- .then((res) => {
- if (res.status === 200) {
- // 找到对应的文档并更新其 progress_msg
- const docIndex = _this.dataList.findIndex(
- (item) => item.id === doc.id
- );
- if (docIndex !== -1) {
- _this.$set(
- _this.dataList[docIndex],
- "progress_msg",
- res.data.progress_msg
- );
- }
- }
- })
- .catch((error) => {
- console.error(
- `获取文档 ${doc.id} 的失败原因时出错:`,
- error
- );
- })
- )
- );
- }
- _this.pageTotal = res.data.pagination.total_count;
- _this.recordCount = res.data.pagination.total_count;
- _this.queryForm.pageSize = res.data.pagination.total_size;
- _this.loading = false;
- // Initialize the analysis status for each row
- _this.dataList.forEach((row) => {
- if (row.run == 1 || row.run == 5) {
- _this.startAnalysisStatusChecker(row);
- }
- });
- resolve();
- })
- .catch((error) => {
- _this.loading = false;
- reject(error);
- });
- });
- },
- // 处理每页显示数量变化
- handleSizeChange(val) {
- this.queryForm.pageSize = val;
- this.queryForm.page = 1;
- this.search().then(() => {
- // 恢复选中状态
- this.$nextTick(() => {
- this.dataList.forEach((row) => {
- if (this.pageSelected.has(row.id)) {
- this.$refs.dataTable.toggleRowSelection(row, true);
- }
- });
- });
- });
- },
- // 添加格式化方法
- percentFormat(percentage) {
- return `${percentage}%`;
- },
- },
- };
- </script>
-
- <style lang="scss" scoped>
- .project-search {
- display: flex;
- height: calc(100vh - 100px); // 假设顶部导航栏高度为60px
- background-color: #f9fafb;
- .custom-tree-node {
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 8px 0;
- position: relative;
- .el-icon-folder {
- color: #409eff;
- margin-right: 8px;
- }
- .file-count {
- color: #909399;
- font-size: 12px;
- padding: 2px 6px;
- border-radius: 10px;
- transition: opacity 0.3s;
- }
- .file-counts {
- color: #909399;
- font-size: 12px;
- padding: 2px 6px;
- border-radius: 10px;
- transition: opacity 0.3s;
- }
- .folder-actions {
- position: absolute;
- right: 0;
- top: 50%;
- transform: translateY(-50%);
- display: none;
- padding-left: 10px;
- i {
- font-size: 16px;
- margin-left: 8px;
- color: #606266;
- cursor: pointer;
- &:hover {
- color: #409eff;
- }
- }
- }
- &:hover {
- .file-count {
- opacity: 0;
- }
- .folder-actions {
- display: inline-block;
- }
- }
- }
- .el-tree-node__content:hover {
- background-color: #f5f7fa;
- }
- .el-tree-node__content:hover {
- background-color: #f5f7fa;
- }
- .file-categories {
- flex: 0 0 280px;
- padding: 20px;
- background-color: #ffffff;
- box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
- overflow-y: auto;
- .el-button {
- width: 100%;
- margin-bottom: 20px;
- }
- .el-tree {
- background-color: transparent;
- }
- }
- .right {
- flex: 1;
- padding: 20px;
- overflow-y: auto;
- }
- .custom-tree-node {
- font-size: 14px;
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 8px 0;
- .el-icon-folder {
- color: #409eff;
- margin-right: 8px;
- }
- .file-count {
- color: #909399;
- font-size: 12px;
- background-color: #f0f2f5;
- padding: 2px 6px;
- border-radius: 10px;
- }
- .tree_title {
- display: flex;
- align-items: center;
- width: 140px;
- .folder-name {
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- max-width: calc(100% - 24px); // 减去图标的宽度
- }
- }
- }
- }
- .el-tree {
- margin-left: 10px;
- }
- ::v-deep .el-tree-node__expand-icon {
- display: none;
- }
- ::v-deep .el-tag {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- height: auto;
- padding: 5px 10px;
- }
- .batch-actions {
- display: flex;
- gap: 10px;
- .el-dropdown {
- /* margin-right: auto; */
- }
- .icons {
- width: 15px;
- height: 15px;
- vertical-align: middle;
- margin-right: 4px;
- }
- }
- ::v-deep .el-dropdown-menu__item {
- display: flex;
- align-items: center;
- padding: 8px 16px;
- .icons {
- width: 14px;
- height: 14px;
- margin-right: 8px;
- }
- }
- @import "./components/dataList.scss";
- .status-wrapper {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- transition: none !important;
- }
- .progress-wrapper {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- padding: 2px;
- transition: none !important;
- ::v-deep .el-progress {
- line-height: 1;
- transition: none !important;
- .el-progress__text {
- font-size: 12px !important;
- color: inherit;
- transition: none !important;
- }
- .el-progress-circle {
- margin: 0;
- transition: none !important;
- }
- // 禁用 SVG 动画
- svg {
- transition: none !important;
- }
- // 禁用进度条路径动画
- .el-progress-circle__track,
- .el-progress-circle__path {
- transition: none !important;
- }
- }
- }
- // 添加选择提示区域样式
- .selection-control {
- margin-bottom: 10px;
- .el-alert {
- padding: 8px 16px;
- }
- }
- </style>
-
|