增加rag服务
This commit is contained in:
@@ -94,6 +94,7 @@ import { TabPaneName } from "element-plus";
|
||||
import { MessageTypeLabels } from "@/enums/MessageTypeEnum";
|
||||
import { formatTimeToSeconds } from "@/utils/format";
|
||||
import { MessagePageQuery, WebMessage } from "@/api/message";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
import { useUserStore } from "@/store";
|
||||
|
||||
const userStore = useUserStore();
|
||||
@@ -124,6 +125,7 @@ const queryParams = reactive<MessagePageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "account:messages:pageSize");
|
||||
|
||||
function stateText(status: number) {
|
||||
if (status == 0) return "未读";
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
<script lang="ts" setup>
|
||||
import IntegralAPI, { IntegralPageQuery, IntegralPageUserVO } from "@/api/integral";
|
||||
import { formatTimeToMinutes } from "@/utils/format";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
|
||||
const loading = ref(false);
|
||||
const total = ref(0);
|
||||
@@ -89,6 +90,7 @@ const queryParams = reactive<IntegralPageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "account:notes:statement:pageSize");
|
||||
|
||||
const detailList = ref<IntegralPageUserVO[]>([]);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<template #tip>
|
||||
<div class="el-upload__tip">
|
||||
格式为*.xlsx / *.xls,文件不超过一个
|
||||
<el-link type="primary" icon="download" :underline="false" @click="handleDownloadTemplate">
|
||||
<el-link type="primary" icon="download" underline="never" @click="handleDownloadTemplate">
|
||||
下载模板
|
||||
</el-link>
|
||||
</div>
|
||||
|
||||
@@ -92,12 +92,14 @@ import UserAPI, { DrawPageVO } from "@/api/user";
|
||||
import { formatTimeToMinutes } from "@/utils/format";
|
||||
import Editor from "@/components/WangEditor/index.vue";
|
||||
import { rgb2Hex, rgbFind } from "@/enums/MessageTypeEnum";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
|
||||
const loading = ref(false);
|
||||
const queryParams = reactive<PageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "website:audition:draw:pageSize");
|
||||
const total = ref(0);
|
||||
const drawList = ref<DrawPageVO[]>();
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ import { DocumentType } from "@/enums/DocumentTypeEnum";
|
||||
import { BASE_NAME_URL } from "@/utils/baseurls";
|
||||
import Editor from "@/components/WangEditor/index.vue";
|
||||
import { rgb2Hex, rgbFind } from "@/enums/MessageTypeEnum";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
|
||||
const audFormRef = ref();
|
||||
const queryFormRef = ref();
|
||||
@@ -151,6 +152,7 @@ const queryParams = reactive<RealNameInfoPageQuery>({
|
||||
|
||||
isName: 3,
|
||||
});
|
||||
usePageSize(queryParams, "website:audition:realname:pageSize");
|
||||
|
||||
const realnameList = ref<RealNameInfo[]>();
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ import MessageAPI from "@/api/message";
|
||||
import { ElForm, FormRules, TabPaneName } from "element-plus";
|
||||
import { MessageTypeLabels, rgb2Hex, rgbFind } from "@/enums/MessageTypeEnum";
|
||||
import { formatTimeToSeconds } from "@/utils/format";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
import { MessagePageQuery, WebMessage } from "@/api/message";
|
||||
import Editor from "@/components/WangEditor/index.vue";
|
||||
|
||||
@@ -197,6 +198,7 @@ const queryParams = reactive<MessagePageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "website:notices:pageSize");
|
||||
|
||||
function handleRead(msg: WebMessage) {
|
||||
ElMessageBox({
|
||||
|
||||
@@ -53,6 +53,14 @@
|
||||
<el-icon :size="16"><CloseBold /></el-icon>
|
||||
无效
|
||||
</el-button>
|
||||
<el-button type="primary" :disabled="ids.length === 0" @click="handleVectorOp(1)">
|
||||
<el-icon :size="16"><Refresh /></el-icon>
|
||||
加入问题库
|
||||
</el-button>
|
||||
<el-button type="warning" :disabled="ids.length === 0" @click="handleVectorOp(0)">
|
||||
<el-icon :size="16"><Delete /></el-icon>
|
||||
移出问题库
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" :data="qnaList" @selection-change="handleSelectionChange" stripe border>
|
||||
@@ -88,6 +96,20 @@
|
||||
<el-text :type="stateType(scope.row.state)">{{ stateText(scope.row.state) }}</el-text>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="置信度" align="center" prop="confidence" width="90">
|
||||
<template #default="scope">
|
||||
<el-tag :type="confidenceType(scope.row.confidence)">
|
||||
{{ confidenceText(scope.row.confidence) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="已入库" align="center" prop="embedded" width="80">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.embedded === 1 ? 'success' : 'info'">
|
||||
{{ scope.row.embedded === 1 ? "是" : "否" }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="提交时间" align="center" prop="editTime" width="180">
|
||||
<template #default="scope">
|
||||
{{ formatTimeToMinutes(scope.row.editTime) }}
|
||||
@@ -98,7 +120,7 @@
|
||||
{{ formatTimeToMinutes(scope.row.answerTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" fixed="right" width="100">
|
||||
<el-table-column label="操作" align="center" fixed="right" width="120">
|
||||
<template #default="scope">
|
||||
<el-button type="success" link size="small" @click="handleOpenDialog(scope.row)">
|
||||
<el-icon :size="14"><EditPen /></el-icon>
|
||||
@@ -199,6 +221,9 @@ defineOptions({
|
||||
import HelperAPI, { FullQnA, QnAPageQuery, UpdateQnA } from "@/api/helper";
|
||||
import { ColoredType, innerTypes } from "@/enums/SoftwareEnum";
|
||||
import { formatTimeToMinutes } from "@/utils/format";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
import { ElMessageBox } from "element-plus";
|
||||
import { EditPen, Plus, SemiSelect, CloseBold, Refresh, Delete } from "@element-plus/icons-vue";
|
||||
|
||||
const queryFormRef = ref();
|
||||
const qnaFormRef = ref();
|
||||
@@ -211,6 +236,7 @@ const queryParams = reactive<QnAPageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "website:question:pageSize");
|
||||
const optionHide = "display: none";
|
||||
function optionShow(value: number) {
|
||||
if (value == 5 || value == 7) return optionHide;
|
||||
@@ -229,7 +255,7 @@ watch(queryTypes, (types) => {
|
||||
// console.log(queryParams.typeIds);
|
||||
});
|
||||
|
||||
const qnaList = ref<FullQnA[]>();
|
||||
const qnaList = ref<FullQnA[]>([]);
|
||||
|
||||
// 弹窗
|
||||
const dialog = reactive({
|
||||
@@ -314,6 +340,18 @@ function stateType(state: number) {
|
||||
}
|
||||
}
|
||||
|
||||
function confidenceText(confidence: number | undefined | null) {
|
||||
if (confidence == null) return "";
|
||||
return (confidence / 100).toFixed(2);
|
||||
}
|
||||
|
||||
function confidenceType(confidence: number | undefined | null) {
|
||||
if (confidence == null) return "info";
|
||||
if (confidence >= 9000) return "success";
|
||||
if (confidence >= 6000) return "warning";
|
||||
return "danger";
|
||||
}
|
||||
|
||||
function userText(nickname: string | undefined, userName: string | undefined) {
|
||||
if (nickname) return nickname;
|
||||
if (userName) return userName;
|
||||
@@ -471,6 +509,45 @@ function handleState(state: number) {
|
||||
);
|
||||
}
|
||||
|
||||
/** 向量库操作:入库/移出 */
|
||||
async function handleVectorOp(embedded: number) {
|
||||
if (ids.value.length === 0) {
|
||||
ElMessage.warning("请勾选问题");
|
||||
return;
|
||||
}
|
||||
|
||||
const action = embedded === 1 ? "加入" : "移出";
|
||||
const actionType = embedded === 1 ? "info" : "warning";
|
||||
|
||||
// 预过滤:仅处理当前 embedded 状态相反的记录
|
||||
const targetIds = qnaList.value
|
||||
.filter((item) => ids.value.includes(item.helpId!) && item.embedded !== embedded)
|
||||
.map((item) => item.helpId);
|
||||
|
||||
if (targetIds.length === 0) {
|
||||
ElMessage.info(embedded === 1 ? "选中问题均已在库中" : "选中问题均未入库");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定将选中的 ${targetIds.length} 个问题${action}问题库吗?`, `${action}问题库`, {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: actionType,
|
||||
});
|
||||
|
||||
loading.value = true;
|
||||
const res = await HelperAPI.updateVector(targetIds.join(","), embedded);
|
||||
const successCount = res?.successIds?.length || 0;
|
||||
ElMessage.success(`${action}成功 ${successCount} 条`);
|
||||
handleQuery(); // 刷新列表
|
||||
} catch (error) {
|
||||
ElMessage.error(`${action}失败`);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
handleQuery();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,559 @@
|
||||
<template>
|
||||
<div class="rag-knowledge-container">
|
||||
<!-- 页面标题 -->
|
||||
<div class="page-header">
|
||||
<h2 class="page-title">知识库管理</h2>
|
||||
<el-button type="primary" @click="uploadDialogVisible = true">
|
||||
<el-icon :size="16"><Upload /></el-icon>
|
||||
上传文档
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 统计卡片 -->
|
||||
<!-- <el-row :gutter="20" class="stats-row" v-if="stats">
|
||||
<el-col :span="6">
|
||||
<el-card shadow="never" class="stat-card">
|
||||
<div class="stat-value">{{ stats.chunkCount }}</div>
|
||||
<div class="stat-label">文档分块数</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="never" class="stat-card">
|
||||
<div class="stat-value">{{ stats.docCount }}</div>
|
||||
<div class="stat-label">文档数量</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="never" class="stat-card">
|
||||
<div class="stat-value">{{ formatDate(stats.lastUpdate) }}</div>
|
||||
<div class="stat-label">最后更新</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="never" class="stat-card">
|
||||
<el-button link @click="fetchStats" :loading="statsLoading" size="small">
|
||||
<el-icon :size="14"><Refresh /></el-icon>
|
||||
刷新统计
|
||||
</el-button>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row> -->
|
||||
|
||||
<!-- 上传文档对话框 -->
|
||||
<el-dialog
|
||||
v-model="uploadDialogVisible"
|
||||
title="上传文档到知识库"
|
||||
width="600px"
|
||||
:before-close="handleUploadDialogClose"
|
||||
destroy-on-close
|
||||
>
|
||||
<el-form ref="uploadFormRef" :model="uploadForm" :rules="uploadRules" label-width="100px">
|
||||
<el-form-item label="选择文件" prop="file">
|
||||
<el-upload
|
||||
class="upload-demo"
|
||||
drag
|
||||
:action="uploadUrl"
|
||||
:headers="uploadHeaders"
|
||||
:data="uploadData"
|
||||
:on-success="handleUploadSuccess"
|
||||
:on-error="handleUploadError"
|
||||
:on-progress="handleUploadProgress"
|
||||
:on-change="handleFileChange"
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
:on-exceed="handleExceed"
|
||||
:file-list="fileListForUpload"
|
||||
accept=".txt,.md"
|
||||
>
|
||||
<i-ep-upload class="el-icon--upload" />
|
||||
<div class="el-upload__text">
|
||||
将文件拖到此处,或<em>点击上传</em>
|
||||
</div>
|
||||
<div class="el-upload__tip" slot="tip">
|
||||
仅支持 TXT、MD 格式,单文件不超过 50MB
|
||||
</div>
|
||||
</el-upload>
|
||||
<div v-if="uploadProgress > 0 && uploadProgress < 100" class="upload-progress">
|
||||
<el-progress :percentage="uploadProgress" :stroke-width="12" status="success" />
|
||||
<div class="progress-text">{{ uploadStatusText }}</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="帮助类型" prop="helpTypeId">
|
||||
<el-select v-model="uploadFormTypes" multiple placeholder="请选择帮助类型" clearable style="width: 100%" collapse-tags>
|
||||
<span v-for="(item, index) in helpTypes" :key="item.value" :style="optionShow(item.value)">
|
||||
<el-option :label="item.label" :value="helpTypes[index]">
|
||||
<div class="flex items-center">
|
||||
<el-tag :color="item.color" style="margin-right: 8px" size="small" />
|
||||
<span :style="{ color: item.color }">{{ item.label }}</span>
|
||||
</div>
|
||||
</el-option>
|
||||
</span>
|
||||
<template #tag>
|
||||
<el-tag v-for="item in uploadFormTypes" :key="item.value" :color="item.color" />
|
||||
</template>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="文件分类" prop="category">
|
||||
<el-radio-group v-model="uploadForm.category">
|
||||
<el-radio :value="0">手册·说明</el-radio>
|
||||
<el-radio :value="1">FAQ</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="uploadDialogVisible = false">取消</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="uploading"
|
||||
:disabled="!uploadForm.file || !uploadForm.helpTypeId"
|
||||
@click="submitUpload"
|
||||
>
|
||||
确定上传
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 已上传文件列表 -->
|
||||
<el-card shadow="never" class="file-list-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>已上传文件列表</span>
|
||||
<el-button link @click="fetchFiles" :loading="filesLoading" size="small">
|
||||
<el-icon :size="14"><Refresh /></el-icon>
|
||||
刷新
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="filesLoading" :data="fileList" stripe border style="width: 100%">
|
||||
<el-table-column label="ID" prop="fileId" width="80" />
|
||||
<el-table-column label="文件名" prop="fileName" width="280" show-overflow-tooltip />
|
||||
<el-table-column label="帮助类型" prop="helpTypeId" width="200">
|
||||
<template #default="scope">
|
||||
<el-tooltip
|
||||
v-for="item in getHelpTypes(scope.row.helpTypeId)"
|
||||
:key="item.value"
|
||||
class="box-item"
|
||||
effect="dark"
|
||||
:content="item.label"
|
||||
placement="top"
|
||||
>
|
||||
<el-tag :color="item.color" class="ml-1" />
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="分类" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.fileCategory === 1 ? 'warning' : 'info'">
|
||||
{{ scope.row.fileCategory === 1 ? 'FAQ' : '手册' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="上传时间" prop="uploadTime" width="180">
|
||||
<template #default="scope">
|
||||
{{ formatDateTime(scope.row.uploadTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="分块数" prop="chunkCount" width="100" align="center" />
|
||||
<el-table-column label="状态" width="120" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag type="success">已完成</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="120" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
type="danger"
|
||||
size="small"
|
||||
link
|
||||
@click="handleDeleteFile(scope.row as KBFileRecord)"
|
||||
:disabled="deletingFileId === String(scope.row.fileId)"
|
||||
>
|
||||
<el-icon :size="14"><Delete /></el-icon>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div v-if="fileList.length === 0 && !filesLoading" class="empty-state">
|
||||
<i-ep-folder-opened class="empty-icon" />
|
||||
<p>暂无上传文档</p>
|
||||
<p class="empty-hint">点击"上传文档"按钮开始构建知识库</p>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Upload, Refresh, Delete } from "@element-plus/icons-vue";
|
||||
import { KBAPI, KBFileRecord } from "@/api/rag";
|
||||
import { helpTypes, ColoredType } from "@/enums/HelpTypeEnum";
|
||||
import { useUserStoreHook } from "@/store/modules/user";
|
||||
|
||||
const userStore = useUserStoreHook();
|
||||
|
||||
// 响应式状态
|
||||
const fileList = ref<KBFileRecord[]>([]);
|
||||
const filesLoading = ref(false);
|
||||
const uploadDialogVisible = ref(false);
|
||||
const uploading = ref(false);
|
||||
const uploadProgress = ref(0);
|
||||
const uploadStatusText = ref("");
|
||||
const deletingFileId = ref<string | null>(null);
|
||||
|
||||
// 表单
|
||||
const uploadFormRef = ref();
|
||||
const uploadForm = reactive({
|
||||
file: null as File | null,
|
||||
helpTypeId: "" as string,
|
||||
category: 0 as number,
|
||||
});
|
||||
|
||||
const uploadFormTypes = ref<ColoredType[]>([]);
|
||||
|
||||
function optionShow(_value: number): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
watch(uploadFormTypes, (types) => {
|
||||
const tIds = types.map((item) => item.value);
|
||||
if (tIds.length > 0) uploadForm.helpTypeId = tIds.join(",");
|
||||
else uploadForm.helpTypeId = "";
|
||||
});
|
||||
|
||||
const uploadRules = reactive({
|
||||
file: [{ required: true, message: "请选择文件", trigger: "change" }],
|
||||
helpTypeId: [{ required: true, message: "请选择帮助类型", trigger: "change" }],
|
||||
});
|
||||
|
||||
// 上传配置
|
||||
const uploadUrl = computed(() => `${import.meta.env.VITE_APP_BASE_API}/api/v1/rag/kb/upload`);
|
||||
const uploadHeaders = computed(() => ({
|
||||
Authorization: `Bearer ${userStore.sessionToken}`,
|
||||
}));
|
||||
const uploadData = computed(() => ({
|
||||
helpTypeId: uploadForm.helpTypeId,
|
||||
category: uploadForm.category,
|
||||
}));
|
||||
|
||||
// 文件列表(用于 el-upload)
|
||||
const fileListForUpload = ref<Array<{ name: string; url?: string }>>([]);
|
||||
|
||||
const ALLOWED_EXTENSIONS = [".txt", ".md"];
|
||||
const MAX_FILE_SIZE = 50 * 1024 * 1024;
|
||||
|
||||
function validateFile(file: File): string | null {
|
||||
const ext = file.name.substring(file.name.lastIndexOf(".")).toLowerCase();
|
||||
if (!ALLOWED_EXTENSIONS.includes(ext)) return "仅支持 TXT、MD 格式";
|
||||
if (file.size > MAX_FILE_SIZE) return "文件大小不能超过 50MB";
|
||||
return null;
|
||||
}
|
||||
|
||||
// 方法
|
||||
async function fetchStats() {
|
||||
try {
|
||||
await KBAPI.getStats();
|
||||
} catch {
|
||||
ElMessage.error("获取统计信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchFiles() {
|
||||
filesLoading.value = true;
|
||||
try {
|
||||
const resp = await KBAPI.getFiles();
|
||||
fileList.value = (resp as any)?.files ?? [];
|
||||
} catch (error) {
|
||||
ElMessage.error("获取文件列表失败");
|
||||
} finally {
|
||||
filesLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleFileChange(file: any, _fileList: any) {
|
||||
// :on-change 在 auto-upload=false 下可靠触发,用于捕获所选文件
|
||||
const raw = file?.raw as File | undefined;
|
||||
if (!raw) {
|
||||
uploadForm.file = null;
|
||||
return;
|
||||
}
|
||||
const error = validateFile(raw);
|
||||
if (error) {
|
||||
ElMessage.error(error);
|
||||
uploadForm.file = null;
|
||||
fileListForUpload.value = [];
|
||||
return;
|
||||
}
|
||||
uploadForm.file = raw;
|
||||
fileListForUpload.value = [{ name: raw.name }];
|
||||
}
|
||||
|
||||
function handleUploadProgress(event: any, file: any) {
|
||||
uploadProgress.value = Math.round((event.loaded / event.total) * 100);
|
||||
uploadStatusText.value = `上传中... ${uploadProgress.value}%`;
|
||||
}
|
||||
|
||||
function handleUploadSuccess(response: any, file: any, fileList: any) {
|
||||
uploadProgress.value = 100;
|
||||
uploadStatusText.value = "上传完成,正在处理...";
|
||||
fileListForUpload.value = [];
|
||||
ElMessage.success("文件上传成功,后台正在解析和向量化...");
|
||||
fetchStats();
|
||||
fetchFiles();
|
||||
}
|
||||
|
||||
function handleUploadError(err: any, file: any, fileList: any) {
|
||||
uploadProgress.value = 0;
|
||||
uploadStatusText.value = "";
|
||||
ElMessage.error("上传失败:" + (err.message || "未知错误"));
|
||||
}
|
||||
|
||||
function handleExceed(files: any, fileList: any) {
|
||||
ElMessage.warning("每次只能上传一个文件");
|
||||
}
|
||||
|
||||
async function submitUpload() {
|
||||
const form = uploadFormRef.value as any;
|
||||
form.validate(async (valid: boolean) => {
|
||||
if (!valid) return;
|
||||
|
||||
// 真实提交路径校验(before-upload 在 auto-upload=false 下不触发)
|
||||
const file = uploadForm.file;
|
||||
if (!file) {
|
||||
ElMessage.error("请选择文件");
|
||||
return;
|
||||
}
|
||||
const error = validateFile(file);
|
||||
if (error) {
|
||||
ElMessage.error(error);
|
||||
return;
|
||||
}
|
||||
|
||||
uploading.value = true;
|
||||
uploadProgress.value = 0;
|
||||
uploadStatusText.value = "准备上传...";
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("helpTypeId", uploadForm.helpTypeId);
|
||||
formData.append("category", String(uploadForm.category));
|
||||
|
||||
await requestUpload(formData);
|
||||
ElMessage.success("上传成功,后台正在处理...");
|
||||
uploadDialogVisible.value = false;
|
||||
resetUploadForm();
|
||||
fetchStats();
|
||||
fetchFiles();
|
||||
} catch (error: any) {
|
||||
ElMessage.error(error?.message || "上传失败");
|
||||
} finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function requestUpload(formData: FormData) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", uploadUrl.value);
|
||||
xhr.setRequestHeader("Authorization", uploadHeaders.value.Authorization);
|
||||
|
||||
xhr.upload.onprogress = (event) => {
|
||||
if (event.lengthComputable) {
|
||||
uploadProgress.value = Math.round((event.loaded / event.total) * 100);
|
||||
uploadStatusText.value = `上传中... ${uploadProgress.value}%`;
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onload = () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
// Java 网关统一返回 Result{code, data, msg};失败时 data 为 null,错误在 msg
|
||||
try {
|
||||
const body = JSON.parse(xhr.responseText);
|
||||
if (body && body.code && body.code !== "00000") {
|
||||
reject(new Error(body.msg || "上传失败"));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// 响应非 JSON,忽略
|
||||
}
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`HTTP ${xhr.status}`));
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = () => reject(new Error("网络错误"));
|
||||
xhr.send(formData);
|
||||
});
|
||||
}
|
||||
|
||||
function handleUploadDialogClose(done: () => void) {
|
||||
if (uploading.value) {
|
||||
ElMessage.warning("正在上传中,请稍候...");
|
||||
return;
|
||||
}
|
||||
resetUploadForm();
|
||||
done();
|
||||
}
|
||||
|
||||
function resetUploadForm() {
|
||||
uploadForm.file = null;
|
||||
uploadForm.helpTypeId = "";
|
||||
uploadForm.category = 0;
|
||||
uploadFormTypes.value = [];
|
||||
fileListForUpload.value = [];
|
||||
uploadProgress.value = 0;
|
||||
uploadStatusText.value = "";
|
||||
const form = uploadFormRef.value as any;
|
||||
form?.clearValidate?.();
|
||||
}
|
||||
|
||||
async function handleDeleteFile(file: KBFileRecord) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要删除文件 "${file.fileName}" 吗?此操作不可恢复。`,
|
||||
"确认删除",
|
||||
{ confirmButtonText: "删除", cancelButtonText: "取消", type: "warning" }
|
||||
);
|
||||
|
||||
deletingFileId.value = String(file.fileId);
|
||||
await KBAPI.deleteFile(file.fileId);
|
||||
ElMessage.success("删除成功");
|
||||
fetchFiles();
|
||||
} catch (error) {
|
||||
// 用户取消或请求失败
|
||||
if (error !== false) {
|
||||
ElMessage.error("删除失败");
|
||||
}
|
||||
} finally {
|
||||
deletingFileId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getHelpTypes(ids?: string): ColoredType[] {
|
||||
const types: ColoredType[] = [];
|
||||
if (ids) {
|
||||
const lst = ids.split(",");
|
||||
for (const idStr of lst) {
|
||||
const id = Number(idStr);
|
||||
const found = helpTypes.find((t) => t.value === id);
|
||||
if (found) types.push(found);
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
function toDate(value: string | number): Date {
|
||||
if (!value) return new Date();
|
||||
const num = typeof value === "number" ? value : Number(value);
|
||||
if (!Number.isNaN(num) && num > 0) {
|
||||
// Unix timestamp in seconds (< 1e12) vs milliseconds (>= 1e12)
|
||||
return new Date(num < 1e12 ? num * 1000 : num);
|
||||
}
|
||||
return new Date(value);
|
||||
}
|
||||
|
||||
function formatDateTime(dateStr: string): string {
|
||||
if (!dateStr) return "-";
|
||||
return toDate(dateStr).toLocaleString("zh-CN");
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
fetchFiles();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.rag-knowledge-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
|
||||
.page-title {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.stats-row {
|
||||
margin-bottom: 20px;
|
||||
|
||||
.stat-card {
|
||||
text-align: center;
|
||||
padding: 16px 0;
|
||||
|
||||
.stat-value {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: var(--el-color-primary);
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-top: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.upload-progress {
|
||||
margin-top: 12px;
|
||||
|
||||
.progress-text {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.file-list-card {
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--el-text-color-placeholder);
|
||||
|
||||
.empty-icon {
|
||||
font-size: 48px;
|
||||
margin-bottom: 16px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
font-size: 13px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -91,6 +91,7 @@
|
||||
<script lang="ts" setup>
|
||||
import IntegralAPI, { IntegralPageQuery, IntegralPageAdminVO } from "@/api/integral";
|
||||
import { formatTimeToMinutes } from "@/utils/format";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
|
||||
const loading = ref(false);
|
||||
const total = ref(0);
|
||||
@@ -98,6 +99,7 @@ const queryParams = reactive<IntegralPageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "website:statement:notes:pageSize");
|
||||
|
||||
const detailList = ref<IntegralPageAdminVO[]>([]);
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
<script lang="ts" setup>
|
||||
import OrderAPI, { OrderPageQuery, OrderPageVO } from "@/api/order";
|
||||
import { formatTimeToSeconds } from "@/utils/format";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
|
||||
const loading = ref(false);
|
||||
const total = ref(0);
|
||||
@@ -112,6 +113,7 @@ const queryParams = reactive<OrderPageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "website:statement:orders:pageSize");
|
||||
|
||||
const detailList = ref<OrderPageVO[]>([]);
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import StatisticsAPI, { StatisticsPageQuery, StatisticsVO, StatisticsBO } from "@/api/statistics";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
import { ThemeEnum } from "@/enums/ThemeEnum";
|
||||
import { useSettingsStore } from "@/store/modules/settings";
|
||||
import { dateToNumber, dayToWeek } from "@/utils/format";
|
||||
@@ -78,6 +79,7 @@ const queryParams = reactive<StatisticsPageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "website:statistics:pageSize");
|
||||
|
||||
const queryRange = ref();
|
||||
|
||||
|
||||
@@ -164,6 +164,7 @@
|
||||
<script setup lang="ts">
|
||||
import StyleAPI, { StylePageQuery, StyleStatistic, StyleUpdate, StyleVO } from "@/api/style";
|
||||
import { formatDate } from "@/utils/format";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
|
||||
const collapseOpen = ref(0);
|
||||
const stat = ref<StyleStatistic>();
|
||||
@@ -180,6 +181,7 @@ const queryParams = reactive<StylePageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "website:styles:pageSize");
|
||||
|
||||
const tsTypes = [
|
||||
{
|
||||
|
||||
@@ -304,6 +304,7 @@ import SoftwareAPI, { FullVersion, VersionPageQuery } from "@/api/software";
|
||||
import { BASE_SOFTWARE_URL } from "@/utils/baseurls";
|
||||
import { formatTimeToMinutes } from "@/utils/format";
|
||||
import { innerTypes, softwareTypes } from "@/enums/SoftwareEnum";
|
||||
import { usePageSize } from "@/composables/usePageSize";
|
||||
import { genFileId, UploadFile, UploadInstance, UploadProps, UploadRawFile, UploadUserFile } from "element-plus";
|
||||
|
||||
const queryFormRef = ref();
|
||||
@@ -317,6 +318,7 @@ const queryParams = reactive<VersionPageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
usePageSize(queryParams, "website:swVersions:pageSize");
|
||||
|
||||
const versionList = ref<FullVersion[]>([]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user