"use strict"; const common_vendor = require("../../../common/vendor.js"); const common_config = require("../../../common/config.js"); function getTenantId() { try { return common_vendor.index.getStorageSync("backend-tenant-id") || ""; } catch (e) { common_vendor.index.__f__("error", "at pages/champion/components/material-tab.vue:262", "获取 tenantId 失败:", e); return ""; } } const _sfc_main = { name: "MaterialTab", data() { return { // 素材相关数据 materialList: [], materialLoading: false, materialTotal: 0, materialPage: { current: 1, size: 10 }, materialQuery: { title: "", category: "基础知识库", industry: "", creator: "", status: "" }, // 添加素材弹出框 showMaterialPopup: false, materialForm: { title: "", category: "", industry: "", file: null }, // 编辑素材弹出框 showEditMaterialPopup: false, editMaterialForm: { id: "", title: "", category: "", industry: "", content: "", remark: "" }, // 上下文菜单 contextMenuVisible: false, contextMenuIndex: -1, contextMenuTop: 0, contextMenuLeft: 0, // 内容详情弹出框 showContentPopup: false, contentPopupTitle: "", contentPopupText: "" }; }, mounted() { this.fetchMaterialList(); }, methods: { // 素材相关方法 onMaterialSearch() { this.materialPage.current = 1; this.fetchMaterialList({ force: true }); }, onMaterialRefresh() { this.materialPage.current = 1; this.fetchMaterialList({ force: true }); }, onMaterialReachBottom() { if (this.materialLoading) return; if (this.materialList.length >= this.materialTotal) return; this.materialPage.current += 1; this.fetchMaterialList(); }, async fetchMaterialList({ force = false } = {}) { var _a, _b, _c, _d, _e, _f, _g, _h, _i; if (this.materialLoading && !force) { return; } this.materialLoading = true; try { const queryParams = { current: this.materialPage.current, size: this.materialPage.size, category: "基础知识库" // 默认添加知识分类参数 }; const trimmedTitle = (_b = (_a = this.materialQuery) == null ? void 0 : _a.title) == null ? void 0 : _b.trim(); const trimmedIndustry = (_d = (_c = this.materialQuery) == null ? void 0 : _c.industry) == null ? void 0 : _d.trim(); const trimmedCreator = (_f = (_e = this.materialQuery) == null ? void 0 : _e.creator) == null ? void 0 : _f.trim(); const trimmedStatus = (_h = (_g = this.materialQuery) == null ? void 0 : _g.status) == null ? void 0 : _h.trim(); if (trimmedTitle) { queryParams.title = trimmedTitle; } if (trimmedIndustry) { queryParams.industry = trimmedIndustry; } if (trimmedCreator) { queryParams.creator = trimmedCreator; } if (trimmedStatus) { queryParams.status = trimmedStatus; } const queryString = Object.keys(queryParams).map((key) => `${key}=${encodeURIComponent(queryParams[key])}`).join("&"); const url = `${common_config.getApiUrl("/api/knowledgeBase/list")}?${queryString}`; const tenantId = getTenantId(); const headers = {}; if (tenantId) { headers["X-Tenant-Id"] = tenantId; } const res = await common_vendor.index.request({ url, method: "POST", header: headers, timeout: 1e4 }); if (res.statusCode === 200 && res.data && res.data.success) { const records = Array.isArray(res.data.data) ? res.data.data : []; if (this.materialPage.current === 1 || force) { this.materialList = records; } else { this.materialList = this.materialList.concat(records); } this.materialTotal = Number(res.data.total) || 0; } else { this.materialList = []; this.materialTotal = 0; common_vendor.index.showToast({ title: ((_i = res.data) == null ? void 0 : _i.message) || "获取素材列表失败", icon: "none" }); } } catch (error) { common_vendor.index.__f__("error", "at pages/champion/components/material-tab.vue:401", "获取素材列表失败:", error); common_vendor.index.showToast({ title: "获取素材列表失败,请稍后重试", icon: "none" }); } finally { this.materialLoading = false; } }, formatDateTime(value) { if (!value) { return ""; } const date = new Date(value); if (Number.isNaN(date.getTime())) { return ""; } const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, "0"); const day = String(date.getDate()).padStart(2, "0"); const hours = String(date.getHours()).padStart(2, "0"); const minutes = String(date.getMinutes()).padStart(2, "0"); const seconds = String(date.getSeconds()).padStart(2, "0"); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; }, getContentPreview(content, limit = 30) { if (!content) return ""; const text = String(content).replace(/\s+/g, " ").trim(); if (!text) return ""; return text.length > limit ? `${text.substring(0, limit)}...` : text; }, showFullText(title, content) { if (!content) return; this.contentPopupTitle = title || "详情"; this.contentPopupText = String(content); this.showContentPopup = true; }, closeContentPopup() { this.showContentPopup = false; this.contentPopupTitle = ""; this.contentPopupText = ""; }, showContextMenu(item, index, event) { if (event && event.stopPropagation) { event.stopPropagation(); } const systemInfo = common_vendor.index.getSystemInfoSync(); let top = 100; let left = systemInfo.windowWidth - 180; if (event) { if (event.touches && event.touches.length > 0) { top = event.touches[0].clientY; left = event.touches[0].clientX - 80; } else if (event.detail && typeof event.detail.x === "number") { top = event.detail.y; left = event.detail.x - 80; } else if (event.clientY !== void 0) { top = event.clientY; left = event.clientX - 80; } } if (left + 160 > systemInfo.windowWidth) { left = systemInfo.windowWidth - 180; } if (left < 0) { left = 10; } this.contextMenuTop = top; this.contextMenuLeft = left; this.contextMenuIndex = index; this.contextMenuVisible = true; }, closeContextMenu() { this.contextMenuVisible = false; this.contextMenuIndex = -1; }, handleEditMaterial(item) { this.closeContextMenu(); this.editMaterialForm = { id: item.id, title: item.title || "", category: item.category || "", industry: item.industry || "", content: item.content || "", remark: item.remark || "" }; this.showEditMaterialPopup = true; }, closeEditMaterialPopup() { this.showEditMaterialPopup = false; this.editMaterialForm = { id: "", title: "", category: "", industry: "", content: "", remark: "" }; }, async submitEditMaterial() { var _a, _b; if (!this.editMaterialForm.title || !this.editMaterialForm.title.trim()) { common_vendor.index.showToast({ title: "请输入知识标题", icon: "none" }); return; } try { common_vendor.index.showLoading({ title: "保存中..." }); const tenantId = getTenantId(); const headers = { "Content-Type": "application/json" }; if (tenantId) { headers["X-Tenant-Id"] = tenantId; if (!this.editMaterialForm.tenantId) { this.editMaterialForm.tenantId = tenantId; } } const res = await common_vendor.index.request({ url: common_config.getApiUrl("/api/knowledgeBase/update"), method: "PUT", data: this.editMaterialForm, header: headers, timeout: 15e3 }); common_vendor.index.hideLoading(); if (res.statusCode === 200 && res.data && (res.data.success || res.data.code === 200)) { common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "保存成功", icon: "success" }); this.closeEditMaterialPopup(); this.materialPage.current = 1; this.fetchMaterialList({ force: true }); } else { common_vendor.index.showToast({ title: ((_b = res.data) == null ? void 0 : _b.message) || "保存失败", icon: "none" }); } } catch (error) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/champion/components/material-tab.vue:567", "保存素材失败:", error); common_vendor.index.showToast({ title: (error == null ? void 0 : error.message) || "保存失败,请重试", icon: "none" }); } }, handleDeleteMaterial(item) { this.closeContextMenu(); common_vendor.index.showModal({ title: "提示", content: "确认删除该素材吗?", success: async (res) => { var _a, _b; if (res.confirm) { try { common_vendor.index.showLoading({ title: "删除中..." }); const tenantId = getTenantId(); const headers = {}; if (tenantId) { headers["X-Tenant-Id"] = tenantId; } const deleteRes = await common_vendor.index.request({ url: common_config.getApiUrl(`/api/knowledgeBase/delete/${item.id}`), method: "DELETE", header: headers, timeout: 15e3 }); common_vendor.index.hideLoading(); if (deleteRes.statusCode === 200 && deleteRes.data && (deleteRes.data.success || deleteRes.data.code === 200)) { common_vendor.index.showToast({ title: ((_a = deleteRes.data) == null ? void 0 : _a.message) || "删除成功", icon: "success" }); this.materialPage.current = 1; this.fetchMaterialList({ force: true }); } else { common_vendor.index.showToast({ title: ((_b = deleteRes.data) == null ? void 0 : _b.message) || "删除失败", icon: "none" }); } } catch (error) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/champion/components/material-tab.vue:618", "删除素材失败:", error); common_vendor.index.showToast({ title: (error == null ? void 0 : error.message) || "删除失败,请重试", icon: "none" }); } } } }); }, // 添加素材相关方法 showAddMaterial() { this.showMaterialPopup = true; this.materialForm = { title: "", category: "基础知识库", // 固定值,不可修改 industry: "汽车销售", // 默认值 file: null }; }, closeMaterialPopup() { this.showMaterialPopup = false; }, chooseFile() { common_vendor.index.chooseImage({ count: 1, success: (res) => { const tempFiles = res.tempFiles || []; if (tempFiles.length > 0) { const file = tempFiles[0]; this.materialForm.file = { name: file.name || "图片", path: file.path, size: file.size }; } }, fail: (err) => { common_vendor.index.__f__("error", "at pages/champion/components/material-tab.vue:685", "选择文件失败:", err); common_vendor.index.showToast({ title: "选择文件失败", icon: "none" }); } }); }, removeFile() { this.materialForm.file = null; }, async submitMaterial() { var _a, _b, _c, _d; if (!this.materialForm.title || !this.materialForm.title.trim()) { common_vendor.index.showToast({ title: "请输入知识标题", icon: "none" }); return; } try { common_vendor.index.showLoading({ title: "提交中..." }); const tenantId = getTenantId(); let res; if (this.materialForm.file) { const formData = { // 其他表单字段 "title": this.materialForm.title.trim(), "category": ((_a = this.materialForm.category) == null ? void 0 : _a.trim()) || "", "industry": ((_b = this.materialForm.industry) == null ? void 0 : _b.trim()) || "", "content": "-", "fileName": this.materialForm.file.name || "file" // 文件名 }; if (tenantId) { formData["tenantId"] = tenantId; } res = await common_vendor.index.uploadFile({ url: common_config.getApiUrl("/api/knowledgeBase/add"), filePath: this.materialForm.file.path, name: "file", // 文件字段名 formData, header: tenantId ? { "X-Tenant-Id": tenantId } : {}, timeout: 15e3 }); } else { const payload = { title: this.materialForm.title.trim(), category: ((_c = this.materialForm.category) == null ? void 0 : _c.trim()) || "", industry: ((_d = this.materialForm.industry) == null ? void 0 : _d.trim()) || "", content: "-" }; if (tenantId) { payload.tenantId = tenantId; } const headers = { "Content-Type": "application/json" }; if (tenantId) { headers["X-Tenant-Id"] = tenantId; } res = await common_vendor.index.request({ url: common_config.getApiUrl("/api/knowledgeBase/add"), method: "POST", data: payload, header: headers, timeout: 15e3 }); } common_vendor.index.hideLoading(); let result; if (this.materialForm.file) { try { result = typeof res.data === "string" ? JSON.parse(res.data) : res.data; } catch (e) { result = res.data; } } else { result = res.data; } if (res.statusCode === 200 && result && (result.success || result.code === 200)) { common_vendor.index.showToast({ title: (result == null ? void 0 : result.message) || "提交成功", icon: "success" }); this.closeMaterialPopup(); this.materialPage.current = 1; this.fetchMaterialList({ force: true }); } else { common_vendor.index.showToast({ title: (result == null ? void 0 : result.message) || "提交失败", icon: "none" }); } } catch (error) { common_vendor.index.hideLoading(); common_vendor.index.__f__("error", "at pages/champion/components/material-tab.vue:809", "提交素材失败:", error); common_vendor.index.showToast({ title: (error == null ? void 0 : error.message) || "提交失败,请重试", icon: "none" }); } } } }; if (!Array) { const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons"); _easycom_uni_icons2(); } const _easycom_uni_icons = () => "../../../uni_modules/uni-icons/components/uni-icons/uni-icons.js"; if (!Math) { _easycom_uni_icons(); } function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_vendor.t($data.materialTotal), b: common_vendor.o((...args) => $options.onMaterialSearch && $options.onMaterialSearch(...args)), c: $data.materialQuery.title, d: common_vendor.o(($event) => $data.materialQuery.title = $event.detail.value), e: common_vendor.o((...args) => $options.onMaterialSearch && $options.onMaterialSearch(...args)), f: $data.materialQuery.industry, g: common_vendor.o(($event) => $data.materialQuery.industry = $event.detail.value), h: common_vendor.p({ type: "refresh", size: "18", color: "#2A68FF" }), i: common_vendor.o((...args) => $options.onMaterialRefresh && $options.onMaterialRefresh(...args)), j: common_vendor.p({ type: "plus", size: "18", color: "#2A68FF" }), k: common_vendor.o((...args) => $options.showAddMaterial && $options.showAddMaterial(...args)), l: common_vendor.f($data.materialList, (item, index, i0) => { return common_vendor.e({ a: common_vendor.t((item.title || "知").charAt(0)), b: common_vendor.t(item.title || "未命名知识"), c: "34f6e844-2-" + i0, d: common_vendor.o(($event) => $options.showContextMenu(item, index, $event), item.id || index), e: item.industry }, item.industry ? { f: common_vendor.t(item.industry) } : {}, { g: item.content || item.detail }, item.content || item.detail ? { h: common_vendor.t($options.getContentPreview(item.content || item.detail, 30)), i: common_vendor.o(($event) => $options.showFullText("详情", item.content || item.detail), item.id || index) } : {}, { j: item.remark }, item.remark ? { k: common_vendor.t($options.getContentPreview(item.remark, 30)), l: common_vendor.o(($event) => $options.showFullText("提示词", item.remark), item.id || index) } : {}, { m: $data.contextMenuVisible && $data.contextMenuIndex === index }, $data.contextMenuVisible && $data.contextMenuIndex === index ? { n: common_vendor.o(($event) => $options.handleEditMaterial(item), item.id || index), o: common_vendor.o(($event) => $options.handleDeleteMaterial(item), item.id || index), p: $data.contextMenuTop + "px", q: $data.contextMenuLeft + "px", r: common_vendor.o(() => { }, item.id || index) } : {}, { s: item.id || index }); }), m: common_vendor.p({ type: "more-filled", size: "20", color: "#999" }), n: !$data.materialLoading && !$data.materialList.length }, !$data.materialLoading && !$data.materialList.length ? {} : {}, { o: $data.materialLoading && $data.materialList.length }, $data.materialLoading && $data.materialList.length ? {} : {}, { p: common_vendor.o((...args) => $options.onMaterialReachBottom && $options.onMaterialReachBottom(...args)), q: $data.showMaterialPopup }, $data.showMaterialPopup ? { r: common_vendor.o((...args) => $options.closeMaterialPopup && $options.closeMaterialPopup(...args)) } : {}, { s: $data.showMaterialPopup }, $data.showMaterialPopup ? common_vendor.e({ t: common_vendor.p({ type: "close", size: "20", color: "#999" }), v: common_vendor.o((...args) => $options.closeMaterialPopup && $options.closeMaterialPopup(...args)), w: $data.materialForm.title, x: common_vendor.o(($event) => $data.materialForm.title = $event.detail.value), y: $data.materialForm.category, z: common_vendor.o(($event) => $data.materialForm.category = $event.detail.value), A: $data.materialForm.industry, B: common_vendor.o(($event) => $data.materialForm.industry = $event.detail.value), C: $data.materialForm.file }, $data.materialForm.file ? { D: common_vendor.t($data.materialForm.file.name || "文件"), E: common_vendor.p({ type: "close", size: "16", color: "#999" }), F: common_vendor.o((...args) => $options.removeFile && $options.removeFile(...args)) } : {}, { G: !$data.materialForm.file }, !$data.materialForm.file ? { H: common_vendor.p({ type: "plus", size: "24", color: "#2A68FF" }), I: common_vendor.o((...args) => $options.chooseFile && $options.chooseFile(...args)) } : {}, { J: common_vendor.p({ type: "close", size: "20", color: "#2A68FF" }), K: common_vendor.o((...args) => $options.closeMaterialPopup && $options.closeMaterialPopup(...args)), L: common_vendor.p({ type: "checkmarkempty", size: "20", color: "#2A68FF" }), M: common_vendor.o((...args) => $options.submitMaterial && $options.submitMaterial(...args)), N: common_vendor.o(() => { }) }) : {}, { O: $data.showEditMaterialPopup }, $data.showEditMaterialPopup ? { P: common_vendor.o((...args) => $options.closeEditMaterialPopup && $options.closeEditMaterialPopup(...args)) } : {}, { Q: $data.showEditMaterialPopup }, $data.showEditMaterialPopup ? { R: common_vendor.p({ type: "close", size: "20", color: "#999" }), S: common_vendor.o((...args) => $options.closeEditMaterialPopup && $options.closeEditMaterialPopup(...args)), T: $data.editMaterialForm.title, U: common_vendor.o(($event) => $data.editMaterialForm.title = $event.detail.value), V: $data.editMaterialForm.category, W: common_vendor.o(($event) => $data.editMaterialForm.category = $event.detail.value), X: $data.editMaterialForm.industry, Y: common_vendor.o(($event) => $data.editMaterialForm.industry = $event.detail.value), Z: $data.editMaterialForm.content, aa: common_vendor.o(($event) => $data.editMaterialForm.content = $event.detail.value), ab: $data.editMaterialForm.remark, ac: common_vendor.o(($event) => $data.editMaterialForm.remark = $event.detail.value), ad: common_vendor.p({ type: "close", size: "20", color: "#2A68FF" }), ae: common_vendor.o((...args) => $options.closeEditMaterialPopup && $options.closeEditMaterialPopup(...args)), af: common_vendor.p({ type: "checkmarkempty", size: "20", color: "#2A68FF" }), ag: common_vendor.o((...args) => $options.submitEditMaterial && $options.submitEditMaterial(...args)), ah: common_vendor.o(() => { }) } : {}, { ai: $data.contextMenuVisible }, $data.contextMenuVisible ? { aj: common_vendor.o((...args) => $options.closeContextMenu && $options.closeContextMenu(...args)) } : {}, { ak: $data.showContentPopup }, $data.showContentPopup ? { al: common_vendor.o((...args) => $options.closeContentPopup && $options.closeContentPopup(...args)) } : {}, { am: $data.showContentPopup }, $data.showContentPopup ? { an: common_vendor.t($data.contentPopupTitle), ao: common_vendor.p({ type: "close", size: "20", color: "#999" }), ap: common_vendor.o((...args) => $options.closeContentPopup && $options.closeContentPopup(...args)), aq: common_vendor.t($data.contentPopupText), ar: common_vendor.o(() => { }) } : {}); } const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-34f6e844"]]); wx.createComponent(Component); //# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/champion/components/material-tab.js.map