Files
smartDriveEEUniApp/unpackage/dist/build/mp-weixin/pages-subpackage/champion/components/material-tab.js
2026-04-17 07:35:37 +08:00

2 lines
12 KiB
JavaScript

"use strict";const t=require("../../../common/vendor.js"),e=require("../../../common/config.js");function i(){try{return t.index.getStorageSync("backend-tenant-id")||""}catch(e){return console.error("获取 tenantId 失败:",e),""}}const a={name:"MaterialTab",data:()=>({materialList:[],materialLoading:!1,materialTotal:0,materialPage:{current:1,size:10},materialQuery:{title:"",category:"基础知识库",industry:"",creator:"",status:""},showMaterialPopup:!1,materialForm:{title:"",category:"",industry:"",file:null},showEditMaterialPopup:!1,editMaterialForm:{id:"",title:"",category:"",industry:"",content:"",remark:""},contextMenuVisible:!1,contextMenuIndex:-1,contextMenuTop:0,contextMenuLeft:0,showContentPopup:!1,contentPopupTitle:"",contentPopupText:""}),mounted(){this.fetchMaterialList()},methods:{onMaterialSearch(){this.materialPage.current=1,this.fetchMaterialList({force:!0})},onMaterialRefresh(){this.materialPage.current=1,this.fetchMaterialList({force:!0})},onMaterialReachBottom(){this.materialLoading||this.materialList.length>=this.materialTotal||(this.materialPage.current+=1,this.fetchMaterialList())},async fetchMaterialList({force:a=!1}={}){var o,r,l,n,s,d,c,u,m;if(!this.materialLoading||a){this.materialLoading=!0;try{const h={current:this.materialPage.current,size:this.materialPage.size,category:"基础知识库"},p=null==(r=null==(o=this.materialQuery)?void 0:o.title)?void 0:r.trim(),M=null==(n=null==(l=this.materialQuery)?void 0:l.industry)?void 0:n.trim(),g=null==(d=null==(s=this.materialQuery)?void 0:s.creator)?void 0:d.trim(),y=null==(u=null==(c=this.materialQuery)?void 0:c.status)?void 0:u.trim();p&&(h.title=p),M&&(h.industry=M),g&&(h.creator=g),y&&(h.status=y);const x=Object.keys(h).map((t=>`${t}=${encodeURIComponent(h[t])}`)).join("&"),F=`${e.getApiUrl("/api/knowledgeBase/list")}?${x}`,f=i(),P={};f&&(P["X-Tenant-Id"]=f);const w=await t.index.request({url:F,method:"POST",header:P,timeout:1e4});if(200===w.statusCode&&w.data&&w.data.success){const t=Array.isArray(w.data.data)?w.data.data:[];1===this.materialPage.current||a?this.materialList=t:this.materialList=this.materialList.concat(t),this.materialTotal=Number(w.data.total)||0}else this.materialList=[],this.materialTotal=0,t.index.showToast({title:(null==(m=w.data)?void 0:m.message)||"获取素材列表失败",icon:"none"})}catch(h){console.error("获取素材列表失败:",h),t.index.showToast({title:"获取素材列表失败,请稍后重试",icon:"none"})}finally{this.materialLoading=!1}}},formatDateTime(t){if(!t)return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")} ${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}`},getContentPreview(t,e=30){if(!t)return"";const i=String(t).replace(/\s+/g," ").trim();return i?i.length>e?`${i.substring(0,e)}...`:i:""},showFullText(t,e){e&&(this.contentPopupTitle=t||"详情",this.contentPopupText=String(e),this.showContentPopup=!0)},closeContentPopup(){this.showContentPopup=!1,this.contentPopupTitle="",this.contentPopupText=""},showContextMenu(e,i,a){a&&a.stopPropagation&&a.stopPropagation();const o=t.index.getSystemInfoSync();let r=100,l=o.windowWidth-180;a&&(a.touches&&a.touches.length>0?(r=a.touches[0].clientY,l=a.touches[0].clientX-80):a.detail&&"number"==typeof a.detail.x?(r=a.detail.y,l=a.detail.x-80):void 0!==a.clientY&&(r=a.clientY,l=a.clientX-80)),l+160>o.windowWidth&&(l=o.windowWidth-180),l<0&&(l=10),this.contextMenuTop=r,this.contextMenuLeft=l,this.contextMenuIndex=i,this.contextMenuVisible=!0},closeContextMenu(){this.contextMenuVisible=!1,this.contextMenuIndex=-1},handleEditMaterial(t){this.closeContextMenu(),this.editMaterialForm={id:t.id,title:t.title||"",category:t.category||"",industry:t.industry||"",content:t.content||"",remark:t.remark||""},this.showEditMaterialPopup=!0},closeEditMaterialPopup(){this.showEditMaterialPopup=!1,this.editMaterialForm={id:"",title:"",category:"",industry:"",content:"",remark:""}},async submitEditMaterial(){var a,o;if(this.editMaterialForm.title&&this.editMaterialForm.title.trim())try{t.index.showLoading({title:"保存中..."});const r=i(),l={"Content-Type":"application/json"};r&&(l["X-Tenant-Id"]=r,this.editMaterialForm.tenantId||(this.editMaterialForm.tenantId=r));const n=await t.index.request({url:e.getApiUrl("/api/knowledgeBase/update"),method:"PUT",data:this.editMaterialForm,header:l,timeout:15e3});t.index.hideLoading(),200===n.statusCode&&n.data&&(n.data.success||200===n.data.code)?(t.index.showToast({title:(null==(a=n.data)?void 0:a.message)||"保存成功",icon:"success"}),this.closeEditMaterialPopup(),this.materialPage.current=1,this.fetchMaterialList({force:!0})):t.index.showToast({title:(null==(o=n.data)?void 0:o.message)||"保存失败",icon:"none"})}catch(r){t.index.hideLoading(),console.error("保存素材失败:",r),t.index.showToast({title:(null==r?void 0:r.message)||"保存失败,请重试",icon:"none"})}else t.index.showToast({title:"请输入知识标题",icon:"none"})},handleDeleteMaterial(a){this.closeContextMenu(),t.index.showModal({title:"提示",content:"确认删除该素材吗?",success:async o=>{var r,l;if(o.confirm)try{t.index.showLoading({title:"删除中..."});const o=i(),n={};o&&(n["X-Tenant-Id"]=o);const s=await t.index.request({url:e.getApiUrl(`/api/knowledgeBase/delete/${a.id}`),method:"DELETE",header:n,timeout:15e3});t.index.hideLoading(),200===s.statusCode&&s.data&&(s.data.success||200===s.data.code)?(t.index.showToast({title:(null==(r=s.data)?void 0:r.message)||"删除成功",icon:"success"}),this.materialPage.current=1,this.fetchMaterialList({force:!0})):t.index.showToast({title:(null==(l=s.data)?void 0:l.message)||"删除失败",icon:"none"})}catch(n){t.index.hideLoading(),console.error("删除素材失败:",n),t.index.showToast({title:(null==n?void 0:n.message)||"删除失败,请重试",icon:"none"})}}})},showAddMaterial(){this.showMaterialPopup=!0,this.materialForm={title:"",category:"基础知识库",industry:"汽车销售",file:null}},closeMaterialPopup(){this.showMaterialPopup=!1},chooseFile(){t.index.chooseImage({count:1,success:t=>{const e=t.tempFiles||[];if(e.length>0){const t=e[0];this.materialForm.file={name:t.name||"图片",path:t.path,size:t.size}}},fail:e=>{console.error("选择文件失败:",e),t.index.showToast({title:"选择文件失败",icon:"none"})}})},removeFile(){this.materialForm.file=null},async submitMaterial(){var a,o,r,l;if(this.materialForm.title&&this.materialForm.title.trim())try{t.index.showLoading({title:"提交中..."});const s=i();let d,c;if(this.materialForm.file){const i={title:this.materialForm.title.trim(),category:(null==(a=this.materialForm.category)?void 0:a.trim())||"",industry:(null==(o=this.materialForm.industry)?void 0:o.trim())||"",content:"-",fileName:this.materialForm.file.name||"file"};s&&(i.tenantId=s),d=await t.index.uploadFile({url:e.getApiUrl("/api/knowledgeBase/add"),filePath:this.materialForm.file.path,name:"file",formData:i,header:s?{"X-Tenant-Id":s}:{},timeout:15e3})}else{const i={title:this.materialForm.title.trim(),category:(null==(r=this.materialForm.category)?void 0:r.trim())||"",industry:(null==(l=this.materialForm.industry)?void 0:l.trim())||"",content:"-"};s&&(i.tenantId=s);const a={"Content-Type":"application/json"};s&&(a["X-Tenant-Id"]=s),d=await t.index.request({url:e.getApiUrl("/api/knowledgeBase/add"),method:"POST",data:i,header:a,timeout:15e3})}if(t.index.hideLoading(),this.materialForm.file)try{c="string"==typeof d.data?JSON.parse(d.data):d.data}catch(n){c=d.data}else c=d.data;200===d.statusCode&&c&&(c.success||200===c.code)?(t.index.showToast({title:(null==c?void 0:c.message)||"提交成功",icon:"success"}),this.closeMaterialPopup(),this.materialPage.current=1,this.fetchMaterialList({force:!0})):t.index.showToast({title:(null==c?void 0:c.message)||"提交失败",icon:"none"})}catch(s){t.index.hideLoading(),console.error("提交素材失败:",s),t.index.showToast({title:(null==s?void 0:s.message)||"提交失败,请重试",icon:"none"})}else t.index.showToast({title:"请输入知识标题",icon:"none"})}}};if(!Array){t.resolveComponent("uni-icons")()}Math;const o=t._export_sfc(a,[["render",function(e,i,a,o,r,l){return t.e({a:t.t(r.materialTotal),b:t.o(((...t)=>l.onMaterialSearch&&l.onMaterialSearch(...t)),"34"),c:r.materialQuery.title,d:t.o((t=>r.materialQuery.title=t.detail.value),"be"),e:t.o(((...t)=>l.onMaterialSearch&&l.onMaterialSearch(...t)),"4e"),f:r.materialQuery.industry,g:t.o((t=>r.materialQuery.industry=t.detail.value),"ec"),h:t.p({type:"refresh",size:"18",color:"#2A68FF"}),i:t.o(((...t)=>l.onMaterialRefresh&&l.onMaterialRefresh(...t)),"a7"),j:t.p({type:"plus",size:"18",color:"#2A68FF"}),k:t.o(((...t)=>l.showAddMaterial&&l.showAddMaterial(...t)),"a6"),l:t.f(r.materialList,((e,i,a)=>t.e({a:t.t((e.title||"知").charAt(0)),b:t.t(e.title||"未命名知识"),c:"a99b9c3b-2-"+a,d:t.o((t=>l.showContextMenu(e,i,t)),e.id||i),e:e.industry},e.industry?{f:t.t(e.industry)}:{},{g:e.content||e.detail},e.content||e.detail?{h:t.t(l.getContentPreview(e.content||e.detail,30)),i:t.o((t=>l.showFullText("详情",e.content||e.detail)),e.id||i)}:{},{j:e.remark},e.remark?{k:t.t(l.getContentPreview(e.remark,30)),l:t.o((t=>l.showFullText("提示词",e.remark)),e.id||i)}:{},{m:r.contextMenuVisible&&r.contextMenuIndex===i},r.contextMenuVisible&&r.contextMenuIndex===i?{n:t.o((t=>l.handleEditMaterial(e)),e.id||i),o:t.o((t=>l.handleDeleteMaterial(e)),e.id||i),p:r.contextMenuTop+"px",q:r.contextMenuLeft+"px",r:t.o((()=>{}),e.id||i)}:{},{s:e.id||i}))),m:t.p({type:"more-filled",size:"20",color:"#999"}),n:!r.materialLoading&&!r.materialList.length},(r.materialLoading||r.materialList.length,{}),{o:r.materialLoading&&r.materialList.length},(r.materialLoading&&r.materialList.length,{}),{p:t.o(((...t)=>l.onMaterialReachBottom&&l.onMaterialReachBottom(...t)),"76"),q:r.showMaterialPopup},r.showMaterialPopup?{r:t.o(((...t)=>l.closeMaterialPopup&&l.closeMaterialPopup(...t)),"af")}:{},{s:r.showMaterialPopup},r.showMaterialPopup?t.e({t:t.p({type:"close",size:"20",color:"#999"}),v:t.o(((...t)=>l.closeMaterialPopup&&l.closeMaterialPopup(...t)),"d1"),w:r.materialForm.title,x:t.o((t=>r.materialForm.title=t.detail.value),"c0"),y:r.materialForm.category,z:t.o((t=>r.materialForm.category=t.detail.value),"d0"),A:r.materialForm.industry,B:t.o((t=>r.materialForm.industry=t.detail.value),"7c"),C:r.materialForm.file},r.materialForm.file?{D:t.t(r.materialForm.file.name||"文件"),E:t.p({type:"close",size:"16",color:"#999"}),F:t.o(((...t)=>l.removeFile&&l.removeFile(...t)),"ed")}:{},{G:!r.materialForm.file},r.materialForm.file?{}:{H:t.p({type:"plus",size:"24",color:"#2A68FF"}),I:t.o(((...t)=>l.chooseFile&&l.chooseFile(...t)),"14")},{J:t.p({type:"close",size:"20",color:"#2A68FF"}),K:t.o(((...t)=>l.closeMaterialPopup&&l.closeMaterialPopup(...t)),"c2"),L:t.p({type:"checkmarkempty",size:"20",color:"#2A68FF"}),M:t.o(((...t)=>l.submitMaterial&&l.submitMaterial(...t)),"3a"),N:t.o((()=>{}),"71")}):{},{O:r.showEditMaterialPopup},r.showEditMaterialPopup?{P:t.o(((...t)=>l.closeEditMaterialPopup&&l.closeEditMaterialPopup(...t)),"ea")}:{},{Q:r.showEditMaterialPopup},r.showEditMaterialPopup?{R:t.p({type:"close",size:"20",color:"#999"}),S:t.o(((...t)=>l.closeEditMaterialPopup&&l.closeEditMaterialPopup(...t)),"e7"),T:r.editMaterialForm.title,U:t.o((t=>r.editMaterialForm.title=t.detail.value),"f8"),V:r.editMaterialForm.category,W:t.o((t=>r.editMaterialForm.category=t.detail.value),"1e"),X:r.editMaterialForm.industry,Y:t.o((t=>r.editMaterialForm.industry=t.detail.value),"eb"),Z:r.editMaterialForm.content,aa:t.o((t=>r.editMaterialForm.content=t.detail.value),"de"),ab:r.editMaterialForm.remark,ac:t.o((t=>r.editMaterialForm.remark=t.detail.value),"23"),ad:t.p({type:"close",size:"20",color:"#2A68FF"}),ae:t.o(((...t)=>l.closeEditMaterialPopup&&l.closeEditMaterialPopup(...t)),"5f"),af:t.p({type:"checkmarkempty",size:"20",color:"#2A68FF"}),ag:t.o(((...t)=>l.submitEditMaterial&&l.submitEditMaterial(...t)),"6b"),ah:t.o((()=>{}),"6d")}:{},{ai:r.contextMenuVisible},r.contextMenuVisible?{aj:t.o(((...t)=>l.closeContextMenu&&l.closeContextMenu(...t)),"e4")}:{},{ak:r.showContentPopup},r.showContentPopup?{al:t.o(((...t)=>l.closeContentPopup&&l.closeContentPopup(...t)),"a6")}:{},{am:r.showContentPopup},r.showContentPopup?{an:t.t(r.contentPopupTitle),ao:t.p({type:"close",size:"20",color:"#999"}),ap:t.o(((...t)=>l.closeContentPopup&&l.closeContentPopup(...t)),"80"),aq:t.t(r.contentPopupText),ar:t.o((()=>{}),"c9")}:{})}],["__scopeId","data-v-a99b9c3b"]]);wx.createComponent(o);