|
@@ -87,6 +87,13 @@
|
|
|
</el-row>
|
|
|
<el-row :gutter="24">
|
|
|
<el-col :span="12">
|
|
|
+ <el-form-item label="文档/目录:" prop="">
|
|
|
+ <el-radio v-model="radio" label="1">目录</el-radio>
|
|
|
+ <el-radio v-model="radio" label="2">文档</el-radio>
|
|
|
+ </el-form-item>
|
|
|
+ <!-- --></el-col
|
|
|
+ >
|
|
|
+ <el-col :span="12" v-if="radio == '1'">
|
|
|
<el-form-item label="文档目录:" prop="document_directories">
|
|
|
<el-select
|
|
|
v-model="AIform.document_directories"
|
|
@@ -103,9 +110,11 @@
|
|
|
:value="dir.id"
|
|
|
:key="index"
|
|
|
></el-option>
|
|
|
- </el-select> </el-form-item
|
|
|
- ></el-col>
|
|
|
- <el-col :span="12">
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <!-- Show document selection for both cases -->
|
|
|
+ <el-col :span="12" v-else>
|
|
|
<el-form-item label="文 档:" prop="documents">
|
|
|
<el-select
|
|
|
v-model="AIform.documents"
|
|
@@ -115,6 +124,9 @@
|
|
|
:disabled="isDocumentSelectDisabled"
|
|
|
clearable
|
|
|
filterable
|
|
|
+ remote
|
|
|
+ :remote-method="remoteSearch"
|
|
|
+ :loading="loading"
|
|
|
@change="handleDocumentChange"
|
|
|
>
|
|
|
<el-option label="全部" value="all"></el-option>
|
|
@@ -527,17 +539,18 @@
|
|
|
</el-row>
|
|
|
<el-row :gutter="24">
|
|
|
<el-col :span="12">
|
|
|
+ <el-form-item label="文档/目录:" prop="">
|
|
|
+ <el-radio v-model="editForm.radio" label="1">目录</el-radio>
|
|
|
+ <el-radio v-model="editForm.radio" label="2">文档</el-radio>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12" v-if="editForm.radio == '1'">
|
|
|
<el-form-item label="文档目录:" prop="document_directories">
|
|
|
<el-select
|
|
|
v-model="editForm.document_directories"
|
|
|
placeholder="请选择文档目录"
|
|
|
style="width: 55%"
|
|
|
- :disabled="
|
|
|
- !(
|
|
|
- editForm.knowledge_base_names &&
|
|
|
- editForm.knowledge_base_names.length
|
|
|
- )
|
|
|
- "
|
|
|
+ :disabled="!editForm.knowledge_base_names.length"
|
|
|
@change="handleEditDirectoryChange"
|
|
|
clearable
|
|
|
filterable
|
|
@@ -551,16 +564,19 @@
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="12">
|
|
|
+ <el-col :span="12" v-else>
|
|
|
<el-form-item label="文 档:" prop="documents">
|
|
|
<el-select
|
|
|
v-model="editForm.documents"
|
|
|
multiple
|
|
|
placeholder="请选择文档"
|
|
|
style="width: 55%"
|
|
|
- :disabled="editForm.document_directories == ''"
|
|
|
+ :disabled="!editForm.knowledge_base_names.length"
|
|
|
clearable
|
|
|
filterable
|
|
|
+ remote
|
|
|
+ :remote-method="remoteEditSearch"
|
|
|
+ :loading="editLoading"
|
|
|
@change="handleEditDocumentChange"
|
|
|
>
|
|
|
<el-option label="全部" value="all"></el-option>
|
|
@@ -976,6 +992,16 @@
|
|
|
</el-row>
|
|
|
<el-row :gutter="24">
|
|
|
<el-col :span="12">
|
|
|
+ <el-form-item label="文档/目录:" prop="">
|
|
|
+ <el-radio v-model="viewForm.radio" label="1" disabled
|
|
|
+ >目录</el-radio
|
|
|
+ >
|
|
|
+ <el-radio v-model="viewForm.radio" label="2" disabled
|
|
|
+ >文档</el-radio
|
|
|
+ >
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12" v-if="viewForm.radio == '1'">
|
|
|
<el-form-item label="文档目录:" prop="document_directories">
|
|
|
<el-select
|
|
|
v-model="viewForm.document_directories"
|
|
@@ -995,7 +1021,7 @@
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="12">
|
|
|
+ <el-col :span="12" v-else>
|
|
|
<el-form-item label="文 档:" prop="documents">
|
|
|
<el-select
|
|
|
v-model="viewForm.documents"
|
|
@@ -1373,6 +1399,7 @@ import {
|
|
|
application_types,
|
|
|
set_default,
|
|
|
configurationInfo,
|
|
|
+ vague_search,
|
|
|
} from "@/api/knowledge";
|
|
|
export default {
|
|
|
/*组件参数 接收来自父组件的数据*/
|
|
@@ -1508,6 +1535,9 @@ export default {
|
|
|
application_type: "",
|
|
|
is_default: false,
|
|
|
generate_new_api_key: true,
|
|
|
+ radio: "1",
|
|
|
+ tempDocuments: [], // 用于临时存储文档数据
|
|
|
+ tempDirectories: [], // 用于临时存储目录数据
|
|
|
},
|
|
|
editDirectoryList: [],
|
|
|
editDocumentList: [],
|
|
@@ -1542,11 +1572,15 @@ export default {
|
|
|
is_default: false,
|
|
|
generate_new_api_key: true,
|
|
|
aiagent_icon: "",
|
|
|
+ radio: "1",
|
|
|
},
|
|
|
params: {
|
|
|
token: "",
|
|
|
},
|
|
|
uploadUrl: "",
|
|
|
+ radio: "1",
|
|
|
+ loading: false, // 添加loading状态
|
|
|
+ editLoading: false,
|
|
|
};
|
|
|
},
|
|
|
|
|
@@ -1573,15 +1607,46 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
isDocumentSelectDisabled() {
|
|
|
- return (
|
|
|
- !this.AIform.knowledge_base_names.length ||
|
|
|
- this.AIform.document_directories == ""
|
|
|
- );
|
|
|
+ // Modify the disabled logic based on radio selection
|
|
|
+ if (this.radio === "1") {
|
|
|
+ return (
|
|
|
+ !this.AIform.knowledge_base_names.length ||
|
|
|
+ this.AIform.document_directories == ""
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return !this.AIform.knowledge_base_names.length;
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
|
|
|
/*侦听器*/
|
|
|
- watch: {},
|
|
|
+ watch: {
|
|
|
+ "editForm.radio": {
|
|
|
+ handler(newVal, oldVal) {
|
|
|
+ if (newVal === "1") {
|
|
|
+ // 切换到目录模式
|
|
|
+ // 保存当前文档选择
|
|
|
+ this.editForm.tempDocuments = [...(this.editForm.documents || [])];
|
|
|
+ // 恢复之前的目录选择
|
|
|
+ if (this.editForm.tempDirectories.length > 0) {
|
|
|
+ this.editForm.document_directories = [
|
|
|
+ ...this.editForm.tempDirectories,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 切换到文档模式
|
|
|
+ // 保存当前目录选择
|
|
|
+ this.editForm.tempDirectories = [
|
|
|
+ ...(this.editForm.document_directories || []),
|
|
|
+ ];
|
|
|
+ // 恢复之前的文档选择
|
|
|
+ if (this.editForm.tempDocuments.length > 0) {
|
|
|
+ this.editForm.documents = [...this.editForm.tempDocuments];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
|
|
|
/*
|
|
|
* el 被新创建的 vm.$ el 替换,并挂载到实例上去之后调用该钩子。
|
|
@@ -1608,20 +1673,157 @@ export default {
|
|
|
|
|
|
/*组件方法*/
|
|
|
methods: {
|
|
|
+ // 编辑模式的远程搜索方法
|
|
|
+ remoteEditSearch(query) {
|
|
|
+ if (query !== "") {
|
|
|
+ this.editLoading = true;
|
|
|
+ // 构建搜索参数
|
|
|
+ const searchParams = {
|
|
|
+ kb_id: this.editForm.knowledge_base_names, // 当前选中的知识库ID
|
|
|
+ keyword: query, // 搜索关键词
|
|
|
+ limit: 10, // 限制返回数量
|
|
|
+ };
|
|
|
+
|
|
|
+ // 如果是目录模式且选择了目录,添加目录ID
|
|
|
+ if (this.editForm.radio === "1" && this.editForm.document_directories) {
|
|
|
+ searchParams.doc_type_id = this.editForm.document_directories;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用模糊搜索接口
|
|
|
+ vague_search(searchParams)
|
|
|
+ .then((response) => {
|
|
|
+ this.editDocumentList = response.data.items || [];
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("搜索文档失败:", error);
|
|
|
+ this.$message.error("搜索文档失败");
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.editLoading = false;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 当搜索词为空时,恢复原始文档列表
|
|
|
+ if (this.editForm.radio === "1") {
|
|
|
+ // 目录模式:加载选中目录的文档
|
|
|
+ if (this.editForm.document_directories) {
|
|
|
+ this.loadEditDocumentList(this.editForm.document_directories);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 文档模式:加载所有文档
|
|
|
+ if (this.editForm.knowledge_base_names.length > 0) {
|
|
|
+ this.loadAllEditDocuments(this.editForm.knowledge_base_names[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 添加加载所有文档的方法
|
|
|
+ loadAllEditDocuments(kbId) {
|
|
|
+ this.editLoading = true;
|
|
|
+ let queryForm = {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 9999,
|
|
|
+ bucket_id: kbId,
|
|
|
+ doc_type_id: "",
|
|
|
+ };
|
|
|
+
|
|
|
+ getBucketContents(queryForm)
|
|
|
+ .then((res) => {
|
|
|
+ this.editDocumentList = res.data.documents;
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.editLoading = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 远程搜索方法
|
|
|
+ remoteSearch(query) {
|
|
|
+ if (query !== "") {
|
|
|
+ this.loading = true;
|
|
|
+ // 构建搜索参数
|
|
|
+ const searchParams = {
|
|
|
+ kb_id: this.AIform.knowledge_base_names, // 当前选中的知识库ID
|
|
|
+ keyword: query, // 搜索关键词
|
|
|
+ limit: 10, // 限制返回数量
|
|
|
+ };
|
|
|
+
|
|
|
+ // 如果是目录模式且选择了目录,添加目录ID
|
|
|
+ if (this.radio === "1" && this.AIform.document_directories) {
|
|
|
+ searchParams.doc_type_id = this.AIform.document_directories;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用模糊搜索接口
|
|
|
+ vague_search(searchParams)
|
|
|
+ .then((response) => {
|
|
|
+ this.documentList = response.data.items || [];
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("搜索文档失败:", error);
|
|
|
+ this.$message.error("搜索文档失败");
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 当搜索词为空时,恢复原始文档列表
|
|
|
+ if (this.radio === "1") {
|
|
|
+ // 目录模式:加载选中目录的文档
|
|
|
+ if (this.AIform.document_directories) {
|
|
|
+ this.loadDocumentList(this.AIform.document_directories);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 文档模式:加载所有文档
|
|
|
+ if (this.AIform.knowledge_base_names.length > 0) {
|
|
|
+ this.loadAllDocuments(this.AIform.knowledge_base_names[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 修改加载所有文档的方法,添加loading状态
|
|
|
+ loadAllDocuments(kbId) {
|
|
|
+ this.loading = true;
|
|
|
+ let queryForm = {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 9999,
|
|
|
+ bucket_id: kbId,
|
|
|
+ doc_type_id: "",
|
|
|
+ };
|
|
|
+
|
|
|
+ getBucketContents(queryForm)
|
|
|
+ .then((res) => {
|
|
|
+ this.documentList = res.data.documents;
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
/* 编辑 */
|
|
|
/* 上传图标 */
|
|
|
onUploadEditSuccess(e) {
|
|
|
this.editForm.aiagent_icon = e.data.fileUrl;
|
|
|
},
|
|
|
+ // 修改文档选择处理方法
|
|
|
handleEditDocumentChange(selectedValues) {
|
|
|
if (selectedValues.includes("all")) {
|
|
|
// 如果选择了"全部",则清空其他选项
|
|
|
this.editForm.documents = ["all"];
|
|
|
} else {
|
|
|
- // 如果没有选择"全部",则限制最多选择10个文档
|
|
|
- if (selectedValues.length > 10) {
|
|
|
- this.editForm.documents = selectedValues.slice(0, 10);
|
|
|
+ // 获取当前选中的文档ID列表
|
|
|
+ const currentSelectedIds = new Set(selectedValues);
|
|
|
+
|
|
|
+ // 保留原有未删除的文档
|
|
|
+ const originalDocs = this.editForm.tempDocuments.filter(
|
|
|
+ (doc) => !doc.startsWith("temp_") && !currentSelectedIds.has(doc)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 合并原有文档和新选择的文档
|
|
|
+ const allDocs = [...originalDocs, ...selectedValues];
|
|
|
+
|
|
|
+ // 如果总数超过10个,保留最新的文档
|
|
|
+ if (allDocs.length > 10) {
|
|
|
+ this.editForm.documents = allDocs.slice(-10);
|
|
|
this.$message.warning("最多只能选择10个文档");
|
|
|
+ } else {
|
|
|
+ this.editForm.documents = allDocs;
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -1630,8 +1832,10 @@ export default {
|
|
|
this.$refs.editFormRef.validate(async (valid) => {
|
|
|
if (valid) {
|
|
|
try {
|
|
|
+ // 深拷贝表单数据
|
|
|
const convertedForm = { ...this.editForm };
|
|
|
- // 处理 role_permissions
|
|
|
+
|
|
|
+ // 处理 role_permissions 和 custom_variables
|
|
|
const parsedPermissions = this.validateAndParseJSON(
|
|
|
"role_permissions",
|
|
|
"角色权限格式无效"
|
|
@@ -1639,38 +1843,87 @@ export default {
|
|
|
if (!parsedPermissions) return;
|
|
|
convertedForm.role_permissions = parsedPermissions;
|
|
|
|
|
|
- // 处理 custom_variables
|
|
|
const parsedVariables = this.validateAndParseJSON(
|
|
|
"custom_variables",
|
|
|
"自定义变量格式无效"
|
|
|
);
|
|
|
if (!parsedVariables) return;
|
|
|
convertedForm.custom_variables = parsedVariables;
|
|
|
- // 转换知识库、文档目录和文档的ID为名称
|
|
|
- /* convertedForm.knowledge_base_names = this.safeGetNamesByIds(this.editForm.knowledge_base_names, this.kneList); */
|
|
|
- /* convertedForm.documents = this.safeGetNamesByIds(this.editForm.documents, this.editDocumentList); */
|
|
|
- // 处理文档选择
|
|
|
- if (
|
|
|
- convertedForm.documents.includes("all") ||
|
|
|
- convertedForm.documents.length === 0
|
|
|
- ) {
|
|
|
- convertedForm.documents = []; // 全选或未选择时传空数组给后台
|
|
|
+
|
|
|
+ // 根据 radio 值处理文档和目录数据
|
|
|
+ if (convertedForm.radio === "1") {
|
|
|
+ // 目录模式:只提交目录数据,清空文档数据
|
|
|
+ convertedForm.documents = [];
|
|
|
+ // 如果选择了目录,则使用新选择的目录
|
|
|
+ if (this.editForm.document_directories) {
|
|
|
+ convertedForm.document_directories = this.safeGetNamesByIds(
|
|
|
+ [this.editForm.document_directories],
|
|
|
+ this.editDirectoryList
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ // 如果没有选择新目录,保留原有目录
|
|
|
+ convertedForm.document_directories =
|
|
|
+ this.editForm.tempDirectories;
|
|
|
+ }
|
|
|
} else {
|
|
|
- convertedForm.documents = this.safeGetNamesByIds(
|
|
|
- convertedForm.documents,
|
|
|
- this.editDocumentList
|
|
|
- );
|
|
|
- }
|
|
|
- convertedForm.document_directories = this.safeGetNamesByIds(
|
|
|
- this.editForm.document_directories,
|
|
|
- this.editDirectoryList
|
|
|
- );
|
|
|
- if (convertedForm.document_directories.length === 0) {
|
|
|
- convertedForm.document_directories = ["全部"];
|
|
|
+ // 文档模式:只提交文档数据,清空目录数据
|
|
|
+ convertedForm.document_directories = [];
|
|
|
+
|
|
|
+ // 处理文档选择
|
|
|
+ if (convertedForm.documents.includes("all")) {
|
|
|
+ convertedForm.documents = ["全部"]; // 全选时传 "全部"
|
|
|
+ } else {
|
|
|
+ // 获取当前选中的文档ID列表
|
|
|
+ const currentSelectedIds = new Set(convertedForm.documents);
|
|
|
+
|
|
|
+ // 获取原有未删除的文档
|
|
|
+ const originalDocs = this.editForm.tempDocuments.filter(
|
|
|
+ (doc) =>
|
|
|
+ !doc.startsWith("temp_") && !currentSelectedIds.has(doc)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 合并原有文档和新选择的文档
|
|
|
+ const allSelectedDocs = new Set([
|
|
|
+ ...originalDocs,
|
|
|
+ ...convertedForm.documents,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 转换文档 ID 为名称
|
|
|
+ convertedForm.documents = Array.from(allSelectedDocs)
|
|
|
+ .map((docId) => {
|
|
|
+ // 如果是原有文档名称,直接使用
|
|
|
+ if (typeof docId === "string" && !docId.match(/^[0-9]+$/)) {
|
|
|
+ return docId;
|
|
|
+ }
|
|
|
+ // 否则查找文档名称
|
|
|
+ const doc = this.editDocumentList.find(
|
|
|
+ (d) => d.id === docId
|
|
|
+ );
|
|
|
+ return doc ? doc.name : null;
|
|
|
+ })
|
|
|
+ .filter((name) => name !== null); // 过滤掉未找到的文档
|
|
|
+
|
|
|
+ // 如果文档数量超过限制,保留前10个
|
|
|
+ if (convertedForm.documents.length > 10) {
|
|
|
+ convertedForm.documents = convertedForm.documents.slice(
|
|
|
+ 0,
|
|
|
+ 10
|
|
|
+ );
|
|
|
+ this.$message.warning(
|
|
|
+ "已超出最大文档数量限制,仅保留前10个文档"
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ // 删除不需要提交的临时数据和radio值
|
|
|
+ delete convertedForm.tempDocuments;
|
|
|
+ delete convertedForm.tempDirectories;
|
|
|
+ delete convertedForm.radio;
|
|
|
+
|
|
|
console.log("Converted form for edit:", convertedForm);
|
|
|
|
|
|
+ // 发送请求
|
|
|
const response = await axios.post(
|
|
|
`${process.env.VUE_APP_BASE_API}/chatbot/configuration/update/`,
|
|
|
convertedForm,
|
|
@@ -1685,9 +1938,7 @@ export default {
|
|
|
this.$message.success("应用更新成功");
|
|
|
this.$router.push({
|
|
|
path: "/knowledge/chatPage/index",
|
|
|
- }); //跳转到聊天应用页面
|
|
|
- /* this.editDialogVisible = false; */
|
|
|
- /* this.fetchApplicationList(); */
|
|
|
+ });
|
|
|
} else {
|
|
|
this.$message.error(response.data.message || "应用更新失败");
|
|
|
}
|
|
@@ -1702,19 +1953,26 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
handleEditKnowledgeBaseChange(val) {
|
|
|
- // 重置目录和文档选择
|
|
|
- this.editForm.document_directories = [];
|
|
|
- this.editForm.documents = [];
|
|
|
- this.editDocumentList = [];
|
|
|
- // 加载新选择的知识库对应的目录列表
|
|
|
- this.loadEditDirectoryList(val);
|
|
|
+ if (val && val.length > 0) {
|
|
|
+ // 只在有选择知识库时重置
|
|
|
+ if (this.editForm.radio === "1") {
|
|
|
+ this.editForm.document_directories = [];
|
|
|
+ this.editForm.documents = [];
|
|
|
+ } else {
|
|
|
+ this.editForm.documents = [];
|
|
|
+ // 加载初始文档列表
|
|
|
+ this.loadAllEditDocuments(val[0]);
|
|
|
+ }
|
|
|
+ this.editDocumentList = [];
|
|
|
+ this.loadEditDirectoryList(val);
|
|
|
+ }
|
|
|
},
|
|
|
handleEditDirectoryChange(val) {
|
|
|
- // 重置文档选择
|
|
|
- this.editForm.documents = [];
|
|
|
-
|
|
|
- // 加载选中目录对应的文档列表
|
|
|
- this.loadEditDocumentList(val);
|
|
|
+ if (this.editForm.radio === "1") {
|
|
|
+ // 只在目录模式下清空文档选择
|
|
|
+ this.editForm.documents = [];
|
|
|
+ this.loadEditDocumentList(val);
|
|
|
+ }
|
|
|
},
|
|
|
/* 知识库选择监听 */
|
|
|
async loadEditDirectoryList(val) {
|
|
@@ -1930,9 +2188,9 @@ export default {
|
|
|
this.AIform.document_directories,
|
|
|
this.directoryList
|
|
|
);
|
|
|
- if (convertedForm.document_directories.length === 0) {
|
|
|
+ /* if (convertedForm.document_directories.length === 0) {
|
|
|
convertedForm.document_directories = ["全部"];
|
|
|
- }
|
|
|
+ } */
|
|
|
|
|
|
console.log("Converted form:", convertedForm);
|
|
|
|
|
@@ -2059,17 +2317,23 @@ export default {
|
|
|
// 这里需要调用后端 API 来获取文档列表
|
|
|
this.loadDocumentList(val);
|
|
|
},
|
|
|
+ // 修改原有的加载文档列表方法,添加loading状态
|
|
|
loadDocumentList(val) {
|
|
|
- const id = this.directoryList.find((el) => el.id == val);
|
|
|
+ this.loading = true;
|
|
|
let queryForm = {
|
|
|
page: 1,
|
|
|
pageSize: 9999,
|
|
|
- bucket_id: val == "001" ? this.bucket_id : id.kb_id, //this.bucket_id,
|
|
|
- doc_type_id: val == "001" ? "" : val,
|
|
|
+ bucket_id: this.bucket_id,
|
|
|
+ doc_type_id: val === "001" ? "" : val,
|
|
|
};
|
|
|
- getBucketContents(queryForm).then((res) => {
|
|
|
- this.documentList = res.data.documents;
|
|
|
- });
|
|
|
+
|
|
|
+ getBucketContents(queryForm)
|
|
|
+ .then((res) => {
|
|
|
+ this.documentList = res.data.documents;
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
},
|
|
|
/* 获取列表 */
|
|
|
init() {
|
|
@@ -2095,24 +2359,67 @@ export default {
|
|
|
this.appTypeList = res.data.application_types;
|
|
|
});
|
|
|
},
|
|
|
- /* 编辑查看 */
|
|
|
+ /* 编辑 */
|
|
|
+ // 修改 initEdit 方法
|
|
|
async initEdit() {
|
|
|
- // 深拷贝以避免直接修改原对象
|
|
|
- this.editForm = JSON.parse(JSON.stringify(this.$route.query.card));
|
|
|
+ try {
|
|
|
+ // 深拷贝以避免直接修改原对象
|
|
|
+ this.editForm = JSON.parse(JSON.stringify(this.$route.query.card));
|
|
|
|
|
|
- // 处理 role_permissions 和 custom_variables
|
|
|
- this.handleJsonFields();
|
|
|
+ // 确保必要的属性都被初始化
|
|
|
+ this.editForm = {
|
|
|
+ ...this.editForm,
|
|
|
+ document_directories: this.editForm.document_directories || [],
|
|
|
+ documents: this.editForm.documents || [],
|
|
|
+ radio: "1", // 默认值
|
|
|
+ };
|
|
|
|
|
|
- // 并行加载知识库目录列表
|
|
|
- const directoryListPromise = this.loadEditDirectoryList(
|
|
|
- this.editForm.knowledge_base_names
|
|
|
- );
|
|
|
+ // 处理 role_permissions 和 custom_variables
|
|
|
+ this.handleJsonFields();
|
|
|
|
|
|
- // 等待目录列表加载完成
|
|
|
- await directoryListPromise;
|
|
|
+ // 设置 radio 的值
|
|
|
+ if (Array.isArray(this.editForm.document_directories)) {
|
|
|
+ if (this.editForm.document_directories.length === 0) {
|
|
|
+ this.editForm.radio = "2";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.editForm.radio = "2";
|
|
|
+ }
|
|
|
|
|
|
- // 处理目录和文档选择
|
|
|
- this.handleDirectoryAndDocumentSelection();
|
|
|
+ if (Array.isArray(this.editForm.documents)) {
|
|
|
+ if (
|
|
|
+ this.editForm.documents.length === 0 &&
|
|
|
+ this.editForm.radio !== "2"
|
|
|
+ ) {
|
|
|
+ this.editForm.radio = "1";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 初始化临时存储,保存原始数据
|
|
|
+ this.editForm.tempDocuments = Array.isArray(this.editForm.documents)
|
|
|
+ ? [...this.editForm.documents]
|
|
|
+ : [];
|
|
|
+ this.editForm.tempDirectories = Array.isArray(
|
|
|
+ this.editForm.document_directories
|
|
|
+ )
|
|
|
+ ? [...this.editForm.document_directories]
|
|
|
+ : [];
|
|
|
+ // 并行加载知识库目录列表
|
|
|
+ if (
|
|
|
+ this.editForm.knowledge_base_names &&
|
|
|
+ this.editForm.knowledge_base_names.length > 0
|
|
|
+ ) {
|
|
|
+ const directoryListPromise = this.loadEditDirectoryList(
|
|
|
+ this.editForm.knowledge_base_names
|
|
|
+ );
|
|
|
+ await directoryListPromise;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理目录和文档选择
|
|
|
+ await this.handleDirectoryAndDocumentSelection();
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error in initEdit:", error);
|
|
|
+ this.$message.error("初始化编辑表单时出错");
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
async handleDirectoryAndDocumentSelection() {
|
|
@@ -2191,69 +2498,97 @@ export default {
|
|
|
this.editForm.custom_variables = "";
|
|
|
}
|
|
|
},
|
|
|
- /* 查看 */
|
|
|
+ // 同样修改 initView 方法
|
|
|
initView() {
|
|
|
- // 根据 card 的数据填充 viewForm
|
|
|
- this.viewForm = JSON.parse(JSON.stringify(this.$route.query.card)); // 深拷贝以避免直接修改原对象
|
|
|
-
|
|
|
- // 处理 knowledge_base_names
|
|
|
- this.viewForm.knowledge_base_names =
|
|
|
- this.viewForm.knowledge_base_names.map((name) => {
|
|
|
- const kb = this.kneList.find((kb) => kb.name === name);
|
|
|
- return kb ? kb.id : name; // 如果找不到对应的知识库,保留原名称
|
|
|
- });
|
|
|
+ try {
|
|
|
+ // 根据 card 的数据填充 viewForm
|
|
|
+ this.viewForm = JSON.parse(JSON.stringify(this.$route.query.card));
|
|
|
|
|
|
- // 处理 role_permissions
|
|
|
- if (this.viewForm.role_permissions) {
|
|
|
- if (typeof this.viewForm.role_permissions !== "string") {
|
|
|
- try {
|
|
|
- this.viewForm.role_permissions = JSON.stringify(
|
|
|
- this.viewForm.role_permissions
|
|
|
- );
|
|
|
- } catch (error) {
|
|
|
- console.error("Error stringifying role_permissions:", error);
|
|
|
- this.viewForm.role_permissions = "";
|
|
|
+ // 确保必要的属性都被初始化
|
|
|
+ this.viewForm = {
|
|
|
+ ...this.viewForm,
|
|
|
+ document_directories: this.viewForm.document_directories || [],
|
|
|
+ documents: this.viewForm.documents || [],
|
|
|
+ radio: "1", // 默认值
|
|
|
+ };
|
|
|
+
|
|
|
+ // 设置 radio 的值
|
|
|
+ if (Array.isArray(this.viewForm.document_directories)) {
|
|
|
+ if (this.viewForm.document_directories.length === 0) {
|
|
|
+ this.viewForm.radio = "2";
|
|
|
}
|
|
|
+ } else {
|
|
|
+ this.viewForm.radio = "2";
|
|
|
}
|
|
|
- } else {
|
|
|
- this.viewForm.role_permissions = "";
|
|
|
- }
|
|
|
|
|
|
- // 处理 custom_variables
|
|
|
- if (this.viewForm.custom_variables) {
|
|
|
- this.viewForm.custom_variables = JSON.stringify(
|
|
|
- this.viewForm.custom_variables
|
|
|
- );
|
|
|
- } else {
|
|
|
- this.viewForm.custom_variables = "";
|
|
|
- }
|
|
|
+ if (Array.isArray(this.viewForm.documents)) {
|
|
|
+ if (
|
|
|
+ this.viewForm.documents.length === 0 &&
|
|
|
+ this.viewForm.radio !== "2"
|
|
|
+ ) {
|
|
|
+ this.viewForm.radio = "1";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 处理文档选择
|
|
|
- if (
|
|
|
- !this.viewForm.documents ||
|
|
|
- this.viewForm.documents.length === 0 ||
|
|
|
- this.viewForm.documents.includes("全部")
|
|
|
- ) {
|
|
|
- this.viewForm.documents = ["全部"];
|
|
|
- } else {
|
|
|
- // 将文档名称转换为ID(如果需要的话)
|
|
|
- this.viewForm.documents = this.viewForm.documents.map((docName) => {
|
|
|
- const doc = this.editDocumentList.find((d) => d.name === docName);
|
|
|
- return doc ? doc.id : docName;
|
|
|
- });
|
|
|
+ // 处理 knowledge_base_names
|
|
|
+ if (
|
|
|
+ this.viewForm.knowledge_base_names &&
|
|
|
+ Array.isArray(this.viewForm.knowledge_base_names)
|
|
|
+ ) {
|
|
|
+ this.viewForm.knowledge_base_names =
|
|
|
+ this.viewForm.knowledge_base_names.map((name) => {
|
|
|
+ const kb = this.kneList.find((kb) => kb.name === name);
|
|
|
+ return kb ? kb.id : name;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.viewForm.knowledge_base_names = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理 role_permissions 和 custom_variables
|
|
|
+ if (this.viewForm.role_permissions) {
|
|
|
+ if (typeof this.viewForm.role_permissions !== "string") {
|
|
|
+ try {
|
|
|
+ this.viewForm.role_permissions = JSON.stringify(
|
|
|
+ this.viewForm.role_permissions
|
|
|
+ );
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error stringifying role_permissions:", error);
|
|
|
+ this.viewForm.role_permissions = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.viewForm.role_permissions = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.viewForm.custom_variables) {
|
|
|
+ this.viewForm.custom_variables = JSON.stringify(
|
|
|
+ this.viewForm.custom_variables
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ this.viewForm.custom_variables = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理文档选择
|
|
|
+ if (
|
|
|
+ !this.viewForm.documents ||
|
|
|
+ !Array.isArray(this.viewForm.documents) ||
|
|
|
+ this.viewForm.documents.length === 0 ||
|
|
|
+ this.viewForm.documents.includes("全部")
|
|
|
+ ) {
|
|
|
+ this.viewForm.documents = ["全部"];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载知识库对应的目录列表
|
|
|
+ if (
|
|
|
+ this.viewForm.knowledge_base_names &&
|
|
|
+ this.viewForm.knowledge_base_names.length > 0
|
|
|
+ ) {
|
|
|
+ this.loadEditDirectoryList(this.viewForm.knowledge_base_names);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error in initView:", error);
|
|
|
+ this.$message.error("初始化查看表单时出错");
|
|
|
}
|
|
|
- /* // 处理文档选择
|
|
|
- if (this.editForm.documents.length === 0 || this.editForm.documents.includes('全部')) {
|
|
|
- this.editForm.documents = ['all'];
|
|
|
- } else {
|
|
|
- // 将文档名称转换为ID
|
|
|
- this.editForm.documents = this.editForm.documents.map(docName => {
|
|
|
- const doc = this.editDocumentList.find(d => d.name === docName);
|
|
|
- return doc ? doc.id : docName;
|
|
|
- });
|
|
|
- } */
|
|
|
- // 加载知识库对应的目录列表
|
|
|
- this.loadEditDirectoryList(this.viewForm.knowledge_base_names);
|
|
|
},
|
|
|
},
|
|
|
};
|