vue-ops-chat 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import{openBlock as e,createElementBlock as t,createCommentVNode as s,Fragment as i,renderList as a,mergeProps as n,resolveComponent as o,normalizeStyle as r,createElementVNode as l,createVNode as c,toDisplayString as d,withDirectives as h,vShow as m,createBlock as g,Transition as u,withCtx as p,withModifiers as v,renderSlot as f,withKeys as w,vModelText as I,normalizeClass as x,TransitionGroup as C}from"vue";function b(e){return e?e.version&&e.version.startsWith?e.version.startsWith("3.")?3:2:e._createVNode||e.constructor&&"App"===e.constructor.name?3:(e.util&&e.set,2):2}const y=new class{constructor(){this.certificate="",this.isAuthenticated=!1}setCertificate(e){this.certificate=e||"",this.isAuthenticated=!!this.certificate,this.certificate?localStorage.setItem("chat_certificate",this.certificate):localStorage.removeItem("chat_certificate")}getCertificate(){return this.certificate||(this.certificate=localStorage.getItem("chat_certificate")||"",this.isAuthenticated=!!this.certificate),this.certificate}clearCertificate(){this.certificate="",this.isAuthenticated=!1,localStorage.removeItem("chat_certificate")}isAuth(){return this.isAuthenticated}},M={certificate:{type:String,required:!0},userName:{type:String,required:!0,default:""},domain:{type:String,default:"https://css.tineco.com"},width:{type:[String,Number],default:400},height:{type:[String,Number],default:550},assistantTitleProp:{type:String,default:"智能助手"},welcomeMessage:{type:String,default:""},showUnreadBadge:{type:Boolean,default:!0},maxImageCount:{type:Number,default:9},maxImageSize:{type:Number,default:5}},L=M.domain.default;function k(e=L){return e.startsWith("http")||(e=`https://${e}`),e.replace(/\/$/,"")}async function S(e,t,s=[]){const i={message:e,userName:t,fileUrls:s};return await async function(e,t,s=""){try{const i={"Content-Type":"application/json"},a=s||y.getCertificate();a&&(i.Certificate=a);const n=`${k()}${e}`,o=await fetch(n,{method:"POST",headers:i,body:JSON.stringify(t)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const r=await o.json();return"S"===r.code?{success:!0,data:r}:{success:!1,error:r.msg||"请求失败",data:r}}catch(e){return console.error("API调用失败:",e),{success:!1,error:e.message||"网络错误"}}}("/gateway/baseServer/asmApiCoral/asmMaintenance",i)}async function z(e){const t=new FormData;t.append("file",e),t.append("bucket","CSS-01");try{const e=k(),s=await fetch(`${e}/gateway/fileServer/v4/upload/single`,{method:"POST",body:t});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);const i=await s.json();return"S"===i.code&&!0===i.success?{success:!0,data:i.data}:{success:!1,error:i.msg||"上传失败",data:i}}catch(e){return console.error("文件上传失败:",e),{success:!1,error:e.message||"网络错误"}}}const $={user:{viewBox:"0 0 24 24",paths:[{d:"M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z",fill:"currentColor"}]},aiAvatar:{viewBox:"0 0 24 24",paths:[{d:"M12 2C12 2 9 3.5 7 5.5C5 7.5 3.5 10 3.5 10C3.5 10 5 12.5 7 14.5C9 16.5 12 18 12 18C12 18 15 16.5 17 14.5C19 12.5 20.5 10 20.5 10C20.5 10 19 7.5 17 5.5C15 3.5 12 2 12 2Z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"},{d:"M12 4L13 2.5M12 4L11 2.5M16 6L17.5 5M16 6L15 4.5M20 10L21.5 9M20 10L19 11.5M16 14L17.5 15.5M16 14L15 12.5M12 16L13 17.5M12 16L11 17.5M8 14L6.5 15.5M8 14L9 12.5M4 10L2.5 9M4 10L5 11.5M8 6L6.5 5M8 6L9 4.5",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round"},{d:"M9 10H7M17 10H15M12 7V5",stroke:"#60a5fa",strokeWidth:"1.5",strokeLinecap:"round"}],circles:[{cx:"12",cy:"10",r:"2.5",fill:"#60a5fa",stroke:"white",strokeWidth:"1"},{cx:"7",cy:"10",r:"1",fill:"#4ade80"},{cx:"17",cy:"10",r:"1",fill:"#4ade80"},{cx:"12",cy:"5",r:"1",fill:"#fbbf24"}],lines:[{x1:"12",y1:"2",x2:"12",y2:"4",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"12",y1:"16",x2:"12",y2:"18",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"6",y1:"10",x2:"4",y2:"10",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"20",y1:"10",x2:"18",y2:"10",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"}]},close:{viewBox:"0 0 24 24",paths:[{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"}]},minimize:{viewBox:"0 0 24 24",paths:[{d:"M19 13H5V11H19V13Z",fill:"currentColor"}]},send:{viewBox:"0 0 24 24",paths:[{d:"M2 21L23 12L2 3V10L17 12L2 14V21Z",fill:"currentColor"}]},upload:{viewBox:"0 0 24 24",paths:[{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6m4-3h6m0 0v6m0-6L13 13",fill:"currentColor"}]},uploadImage:{viewBox:"0 0 24 24",paths:[{d:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"},{d:"M12 13a3 3 0 100-6 3 3 0 000 6z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}]},aiAssistant:{viewBox:"0 0 24 24",paths:[{d:"M12 6C14.21 6 16 7.79 16 10C16 12.21 14.21 14 12 14C9.79 14 8 12.21 8 10C8 7.79 9.79 6 12 6Z",fill:"currentColor"},{d:"M9 10H7M17 10H15M12 7V5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"},{d:"M12 16C9.33 16 4 17.34 4 20V22H20V20C20 17.34 14.67 16 12 16Z",fill:"currentColor"}],circles:[{cx:"7",cy:"10",r:"1",fill:"#4ade80"},{cx:"17",cy:"10",r:"1",fill:"#4ade80"},{cx:"12",cy:"5",r:"1",fill:"#fbbf24"}]},remove:{viewBox:"0 0 24 24",paths:[{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"}]},prev:{viewBox:"0 0 24 24",paths:[{d:"M15.41 7.41L14 6L8 12L14 18L15.41 16.59L10.83 12L15.41 7.41Z",fill:"currentColor"}]},next:{viewBox:"0 0 24 24",paths:[{d:"M8.59 7.41L10 6L16 12L10 18L8.59 16.59L13.17 12L8.59 7.41Z",fill:"currentColor"}]},zoomIn:{viewBox:"0 0 24 24",paths:[{d:"M12 18a6 6 0 1 0 0-12 6 6 0 0 0 0 12z",fill:"none",stroke:"currentColor",strokeWidth:"2"},{d:"M20 20l-3.5-3.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"},{d:"M12 9v6M9 12h6",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}]},zoomOut:{viewBox:"0 0 24 24",paths:[{d:"M12 16a4 4 0 1 0 0-8 4 4 0 0 0 0 8z",fill:"none",stroke:"currentColor",strokeWidth:"2"},{d:"M19 19l-3-3",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"},{d:"M10 12h4",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}]},fullscreen:{viewBox:"0 0 24 24",paths:[{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}]}};var B={name:"SvgIcon",props:{name:{type:String,required:!0,validator:e=>Object.keys($).includes(e)},size:{type:[Number,String],default:24}},computed:{iconConfig(){return $[this.name]||$.user},viewBox(){return this.iconConfig.viewBox||"0 0 24 24"},paths(){return this.iconConfig.paths||[]},circles(){return this.iconConfig.circles||[]},lines(){return this.iconConfig.lines||[]}}};const _=["viewBox"];B.render=function(o,r,l,c,d,h){return e(),t("svg",{viewBox:h.viewBox,fill:"none",xmlns:"http://www.w3.org/2000/svg"},[s(" 渲染路径 "),(e(!0),t(i,null,a(h.paths,(s,i)=>(e(),t("path",n({key:`path-${i}`},{ref_for:!0},s),null,16))),128)),s(" 渲染圆形 "),(e(!0),t(i,null,a(h.circles,(s,i)=>(e(),t("circle",n({key:`circle-${i}`},{ref_for:!0},s),null,16))),128)),s(" 渲染线条 "),(e(!0),t(i,null,a(h.lines,(s,i)=>(e(),t("line",n({key:`line-${i}`},{ref_for:!0},s),null,16))),128))],8,_)},B.__file="src/components/AgentAssistant/Icons/SvgIcon.vue";var A={name:"FloatingTrigger",components:{SvgIcon:B},props:{unreadCount:{type:Number,default:0},showBadge:{type:Boolean,default:!0}},data:()=>({isHovered:!1,isDragging:!1,hasDragged:!1,startX:0,startY:0,position:{bottom:30,right:30}}),computed:{triggerStyle(){return{bottom:this.position.bottom+"px",right:this.position.right+"px"}}},methods:{startDrag(e){this.isDragging=!0,this.hasDragged=!1,this.startX=e.clientX,this.startY=e.clientY,document.addEventListener("mousemove",this.onDrag),document.addEventListener("mouseup",this.stopDrag)},onDrag(e){if(!this.isDragging)return;const t=e.clientX-this.startX,s=e.clientY-this.startY;(Math.abs(t)>3||Math.abs(s)>3)&&(this.hasDragged=!0);const i=window.innerWidth,a=window.innerHeight;this.position.right=Math.max(10,Math.min(i-64-10,this.position.right-t)),this.position.bottom=Math.max(10,Math.min(a-64-10,this.position.bottom-s)),this.startX=e.clientX,this.startY=e.clientY},stopDrag(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDrag),document.removeEventListener("mouseup",this.stopDrag)},handleClick(){this.hasDragged||this.$emit("toggle"),this.hasDragged=!1}}};const D={class:"ops-icon-wrapper"},P={key:0,class:"ops-unread-badge"},W={class:"ops-tooltip"};A.render=function(i,a,n,g,u,p){const v=o("SvgIcon");return e(),t("div",{class:"ops-floating-trigger",style:r(p.triggerStyle),onMousedown:a[0]||(a[0]=(...e)=>p.startDrag&&p.startDrag(...e)),onClick:a[1]||(a[1]=(...e)=>p.handleClick&&p.handleClick(...e)),onMouseenter:a[2]||(a[2]=e=>u.isHovered=!0),onMouseleave:a[3]||(a[3]=e=>u.isHovered=!1)},[l("div",D,[c(v,{name:"aiAssistant",class:"ops-ai-icon"}),n.unreadCount>0&&n.showBadge?(e(),t("div",P,d(n.unreadCount),1)):s("v-if",!0)]),h(l("div",W,"智能助手",512),[[m,u.isHovered]])],36)},A.__scopeId="data-v-415d7a2c",A.__file="src/components/AgentAssistant/FloatingTrigger.vue";var T={name:"ChatModal",components:{SvgIcon:B},props:{visible:{type:Boolean,default:!1},width:{type:[String,Number],default:380},height:{type:[String,Number],default:520},assistantTitle:{type:String,default:"智能助手"},placeholder:{type:String,default:"输入消息..."},maxLength:{type:Number,default:500},disabled:{type:Boolean,default:!1},sending:{type:Boolean,default:!1},initialValue:{type:String,default:""}},data(){return{inputText:this.initialValue,isDragging:!1,isResizing:!1,startX:0,startY:0,startWidth:0,startHeight:0,position:{left:window.innerWidth-parseInt(this.width)-30,top:window.innerHeight-parseInt(this.height)-100}}},computed:{calculatedWidth(){return"number"==typeof this.width?this.width+"px":this.width},calculatedHeight(){return"number"==typeof this.height?this.height+"px":this.height},sendDisabled(){return!this.inputText.trim()&&!this.$slots["image-preview"]||this.disabled||this.sending}},watch:{initialValue(e){this.inputText=e},width(e){this.position.left=window.innerWidth-parseInt(this.calculatedWidth)-30},height(e){this.position.top=window.innerHeight-parseInt(this.calculatedHeight)-100}},methods:{startDrag(e){this.isDragging=!0,this.startX=e.clientX-this.position.left,this.startY=e.clientY-this.position.top,document.addEventListener("mousemove",this.onDrag),document.addEventListener("mouseup",this.stopDrag)},onDrag(e){if(!this.isDragging)return;const t=window.innerWidth,s=window.innerHeight,i=parseInt(this.calculatedWidth),a=parseInt(this.calculatedHeight);let n=e.clientX-this.startX,o=e.clientY-this.startY;n=Math.max(10,Math.min(t-i-10,n)),o=Math.max(10,Math.min(s-a-10,o)),this.position.left=n,this.position.top=o},stopDrag(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDrag),document.removeEventListener("mouseup",this.stopDrag)},startResize(e){e.preventDefault(),this.isResizing=!0,this.startX=e.clientX,this.startY=e.clientY,this.startWidth=parseInt(this.calculatedWidth),this.startHeight=parseInt(this.calculatedHeight),document.addEventListener("mousemove",this.onResize),document.addEventListener("mouseup",this.stopResize)},onResize(e){if(!this.isResizing)return;const t=e.clientX-this.startX,s=e.clientY-this.startY,i=this.startWidth/this.startHeight;let a=this.startWidth+t,n=this.startHeight+s;Math.abs(t)>Math.abs(s)?n=a/i:a=n*i;const o=window.innerWidth-20,r=window.innerHeight-20;a=Math.max(300,Math.min(o,a)),n=Math.max(400,Math.min(r,n)),this.$emit("resize",{width:a,height:n})},stopResize(){this.isResizing=!1,document.removeEventListener("mousemove",this.onResize),document.removeEventListener("mouseup",this.stopResize)},handleSend(){this.sendDisabled||(this.$emit("send",this.inputText),this.inputText="")},focus(){const e=this.$el.querySelector(".message-input");e&&e.focus()},async handlePaste(e){try{const t=e.clipboardData.items;for(let s=0;s<t.length;s++){const i=t[s];if(-1!==i.type.indexOf("image")){e.preventDefault();const t=i.getAsFile();if(t){const e={file:t,name:t.name||`pasted-image-${Date.now()}.png`,size:t.size,url:""},s=new FileReader;return s.onload=t=>{e.url=t.target.result,this.$emit("files-pasted",[e])},void s.readAsDataURL(t)}}}}catch(e){console.error("粘贴处理失败:",e)}}}};const H={class:"ops-chat-container"},E={class:"ops-header-info"},V={class:"ops-avatar"},R={class:"ops-header-text"},N={class:"ops-assistant-name"},Z={class:"ops-header-actions"},F={class:"ops-chat-messages",ref:"messagesContainer"},U={class:"ops-chat-input-area"},X={class:"ops-input-container"},Y=["placeholder","maxlength","disabled"],O={class:"ops-input-actions"},q={class:"ops-char-count"},j=["disabled"],J={key:1,class:"ops-loading-spinner"};T.render=function(i,a,n,m,C,b){const y=o("SvgIcon");return e(),g(u,{name:"ops-slide-fade"},{default:p(()=>[n.visible?(e(),t("div",{key:0,class:"ops-chat-modal",style:r({width:b.calculatedWidth,height:b.calculatedHeight,left:C.position.left+"px",top:C.position.top+"px"})},[l("div",H,[s(" 头部 "),l("div",{class:"ops-chat-header",onMousedown:a[2]||(a[2]=(...e)=>b.startDrag&&b.startDrag(...e))},[l("div",E,[l("div",V,[c(y,{name:"user",class:"ops-avatar-icon"})]),l("div",R,[l("h3",N,d(n.assistantTitle),1),a[9]||(a[9]=l("span",{class:"ops-status ops-online"},"在线",-1))])]),l("div",Z,[l("button",{class:"ops-minimize-btn",onClick:a[0]||(a[0]=v(e=>i.$emit("minimize"),["stop"]))},[c(y,{name:"minimize",class:"ops-action-icon"})]),l("button",{class:"ops-close-btn",onClick:a[1]||(a[1]=v(e=>i.$emit("close"),["stop"]))},[c(y,{name:"close",class:"ops-action-icon"})])])],32),s(" 右下角调整大小手柄 "),l("div",{class:"ops-resize-handle",onMousedown:a[3]||(a[3]=(...e)=>b.startResize&&b.startResize(...e))},null,32),s(" 消息区域 "),l("div",F,[f(i.$slots,"welcome"),f(i.$slots,"messages")],512),s(" 输入区域 "),l("div",U,[f(i.$slots,"image-preview"),l("div",X,[h(l("textarea",{"onUpdate:modelValue":a[4]||(a[4]=e=>C.inputText=e),onKeydown:a[5]||(a[5]=w(v((...e)=>b.handleSend&&b.handleSend(...e),["exact","prevent"]),["enter"])),onInput:a[6]||(a[6]=e=>i.$emit("input-change",e)),onPaste:a[7]||(a[7]=(...e)=>b.handlePaste&&b.handlePaste(...e)),placeholder:n.placeholder,class:"ops-message-input",rows:"1",maxlength:n.maxLength,disabled:n.disabled},null,40,Y),[[I,C.inputText]]),l("div",O,[f(i.$slots,"upload-button"),l("span",q,d(C.inputText.length)+"/"+d(n.maxLength),1),l("button",{onClick:a[8]||(a[8]=(...e)=>b.handleSend&&b.handleSend(...e)),class:x(["ops-send-button",{"ops-loading":n.sending}]),disabled:b.sendDisabled},[f(i.$slots,"send-icon",{},()=>[n.sending?(e(),t("div",J)):(e(),g(y,{key:0,name:"send",class:"ops-send-icon"}))])],10,j)])])])])],4)):s("v-if",!0)]),_:3})},T.__scopeId="data-v-36f7e58f",T.__file="src/components/AgentAssistant/ChatModal.vue";var K={name:"WelcomeMessage",components:{SvgIcon:B},props:{title:{type:String,default:"您好!我是您的智能助手"},message:{type:String,default:"您好!我是智能助手,请问有什么可以帮助您的吗?"}}};const G={class:"ops-welcome-message"},Q={class:"ops-welcome-text"};K.render=function(s,i,a,n,o,r){return e(),t("div",G,[i[0]||(i[0]=l("div",{class:"ops-welcome-avatar"},[l("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[l("path",{d:"M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z",fill:"currentColor"})])],-1)),l("div",Q,[l("h4",null,d(a.title),1),l("p",null,d(a.message),1)])])},K.__scopeId="data-v-2f1ef74a",K.__file="src/components/AgentAssistant/WelcomeMessage.vue";var ee={name:"MessageImages",props:{images:{type:Array,default:()=>[]}},methods:{previewImage(e){this.$emit("preview",e)}}};const te={class:"ops-message-images"},se=["src","alt","onClick"],ie={key:0,class:"ops-upload-error-overlay"};ee.render=function(n,o,r,c,d,h){return e(),t("div",te,[(e(!0),t(i,null,a(r.images,(i,a)=>(e(),t("div",{key:a,class:x(["ops-message-image-item",{"ops-upload-failed":!1===i.uploadSuccess}])},[l("img",{src:i.url,alt:i.name,class:"ops-message-image",onClick:e=>h.previewImage(i.url)},null,8,se),s(" 上传失败的提示 "),!1===i.uploadSuccess?(e(),t("div",ie,[...o[0]||(o[0]=[l("span",{class:"ops-error-text"},"上传失败",-1)])])):s("v-if",!0)],2))),128))])},ee.__scopeId="data-v-c687e28e",ee.__file="src/components/AgentAssistant/MessageImages.vue";var ae={name:"MessageBubble",components:{MessageImages:ee,SvgIcon:B},props:{message:{type:Object,required:!0,validator:e=>e.sender&&e.timestamp&&void 0!==e.content}},methods:{handleImagePreview(e){this.$emit("preview-image",e)}}};const ne={key:0,class:"ops-message-avatar ops-assistant-avatar"},oe={class:"ops-message-avatar ops-user-avatar"},re={class:"ops-message-content"},le={class:"ops-message-text"};ae.render=function(a,n,r,h,m,u){const p=o("SvgIcon"),v=o("MessageImages");return e(),t("div",{class:x(["ops-message-bubble","ops-"+r.message.sender])},[s(" 助手头像 "),"assistant"===r.message.sender?(e(),t("div",ne,[c(p,{name:"user"})])):(e(),t(i,{key:1},[s(" 用户头像 "),l("div",oe,[c(p,{name:"user"})])],2112)),l("div",re,[l("div",le,d(r.message.content),1),s(" 图片展示 "),r.message.images&&r.message.images.length>0?(e(),g(v,{key:0,images:r.message.images,onPreview:u.handleImagePreview},null,8,["images","onPreview"])):s("v-if",!0)])],2)},ae.__scopeId="data-v-0927d266",ae.__file="src/components/AgentAssistant/MessageBubble.vue";var ce={name:"MessageList",components:{MessageBubble:ae},props:{messages:{type:Array,default:()=>[]}},methods:{handleImagePreview(e){this.$emit("preview-image",e)},scrollToBottom(){this.$nextTick(()=>{const e=this.$refs.messageList;e&&(e.scrollTop=e.scrollHeight)})}}};const de={class:"ops-message-list",ref:"messageList"};ce.render=function(s,n,r,l,d,h){const m=o("MessageBubble");return e(),t("div",de,[c(C,{name:"ops-message-fade",tag:"div",class:"ops-transition-group"},{default:p(()=>[(e(!0),t(i,null,a(r.messages,(t,s)=>(e(),g(m,{key:t.id||s,message:t,onPreviewImage:h.handleImagePreview},null,8,["message","onPreviewImage"]))),128))]),_:1})],512)},ce.__scopeId="data-v-4f7fdfc2",ce.__file="src/components/AgentAssistant/MessageList.vue";var he={name:"ImagePreview",components:{SvgIcon:B},props:{images:{type:Array,default:()=>[]},disabled:{type:Boolean,default:!1}},methods:{removeImage(e){this.$emit("remove",e)}}};const me={key:0,class:"ops-image-preview-container"},ge=["src","alt"],ue=["onClick","disabled"];he.render=function(n,r,d,h,m,g){const u=o("SvgIcon");return d.images.length>0?(e(),t("div",me,[(e(!0),t(i,null,a(d.images,(s,i)=>(e(),t("div",{key:i,class:"ops-image-preview-item"},[l("img",{src:s.url,alt:s.name,class:"ops-preview-image"},null,8,ge),l("button",{class:"ops-remove-image-btn",onClick:e=>g.removeImage(i),type:"button",disabled:d.disabled},[c(u,{name:"close",class:"ops-remove-icon"})],8,ue)]))),128))])):s("v-if",!0)},he.__scopeId="data-v-28f9b383",he.__file="src/components/AgentAssistant/ImagePreview.vue";var pe={name:"UploadButton",components:{SvgIcon:B},props:{disabled:{type:Boolean,default:!1},isLoading:{type:Boolean,default:!1},maxImageCount:{type:Number,default:3},maxImageSize:{type:Number,default:5},currentImageCount:{type:Number,default:0}},methods:{handleFileChange(e){const t=Array.from(e.target.files);if(0===t.length)return;const s=this.maxImageCount-this.currentImageCount;if(s<=0)return void this.$emit("error",`最多只能上传${this.maxImageCount}张图片`);const i=t.slice(0,s),a=[];for(let e of i){if(!e.type.startsWith("image/")){this.$emit("error","请选择图片文件");continue}const t=1024*this.maxImageSize*1024;e.size>t?this.$emit("error",`图片 ${e.name} 太大,请选择小于${this.maxImageSize}MB的图片`):a.push(e)}const n=a.slice(0,s);n.length>0&&this.processFiles(n),e.target.value=""},processFiles(e){const t=[];e.forEach(e=>{t.push({url:"",name:e.name,file:e,size:e.size})}),this.$emit("files-selected",t)},reset(){this.$refs.fileInput&&(this.$refs.fileInput.value="")}}};const ve=["multiple","disabled"];pe.render=function(s,i,a,n,r,d){const h=o("SvgIcon");return e(),t("label",{class:x(["ops-upload-button",{"ops-disabled":a.disabled||a.isLoading}])},[l("input",{type:"file",accept:"image/*",multiple:a.maxImageCount>1,onChange:i[0]||(i[0]=(...e)=>d.handleFileChange&&d.handleFileChange(...e)),ref:"fileInput",disabled:a.disabled||a.isLoading,class:"ops-file-input"},null,40,ve),c(h,{name:"uploadImage",class:"ops-upload-icon"})],2)},pe.__scopeId="data-v-724f2729",pe.__file="src/components/AgentAssistant/UploadButton.vue";var fe={name:"ImagePreviewModal",components:{SvgIcon:B},props:{visible:{type:Boolean,default:!1},images:{type:Array,default:()=>[]},initialIndex:{type:Number,default:0}},data(){return{currentIndex:this.initialIndex,scale:1,minScale:.1,maxScale:5,step:.1}},computed:{currentImageUrl(){if(0===this.images.length)return"";const e=this.images[this.currentIndex];return e?.url||""},imageName(){if(0===this.images.length)return"";const e=this.images[this.currentIndex];return e?.name||"未命名图片"},showPrevButton(){return this.currentIndex>0},showNextButton(){return this.currentIndex<this.images.length-1},canZoomIn(){return this.scale<this.maxScale},canZoomOut(){return this.scale>this.minScale}},watch:{visible(e){e?(this.currentIndex=this.initialIndex,document.body.style.overflow="hidden"):document.body.style.overflow=""},initialIndex(e){this.currentIndex=e}},methods:{closeModal(){this.$emit("close")},handleBackdropClick(){this.closeModal()},prevImage(){this.currentIndex>0&&(this.currentIndex--,this.$emit("image-change",this.currentIndex))},nextImage(){this.currentIndex<this.images.length-1&&(this.currentIndex++,this.$emit("image-change",this.currentIndex))},selectImage(e){e>=0&&e<this.images.length&&(this.currentIndex=e,this.$emit("image-change",this.currentIndex))},onImageLoad(){this.$emit("image-load",{index:this.currentIndex,url:this.currentImageUrl})},onImageError(){this.$emit("image-error",{index:this.currentIndex,url:this.currentImageUrl})},zoomIn(){this.canZoomIn&&(this.scale=Math.min(this.scale+this.step,this.maxScale))},zoomOut(){this.canZoomOut&&(this.scale=Math.max(this.scale-this.step,this.minScale))},resetZoom(){this.scale=1},fitScreen(){this.scale=1}}};const we={class:"ops-image-container"},Ie=["src","alt"],xe={key:0,class:"ops-image-counter"},Ce={class:"ops-zoom-controls"},be=["disabled"],ye=["disabled"];fe.render=function(i,a,n,r,h,m){const f=o("SvgIcon");return e(),g(u,{name:"ops-modal-fade"},{default:p(()=>[n.visible?(e(),t("div",{key:0,class:"ops-image-preview-overlay",onClick:a[9]||(a[9]=(...e)=>m.handleBackdropClick&&m.handleBackdropClick(...e))},[s(" 关闭按钮 "),l("button",{class:"ops-close-btn",onClick:a[0]||(a[0]=(...e)=>m.closeModal&&m.closeModal(...e))},[c(f,{name:"close",class:"ops-close-icon"})]),s(" 图片显示区域 "),l("div",we,[n.images.length>1&&m.showPrevButton?(e(),t("button",{key:0,class:"ops-nav-btn ops-prev-btn",onClick:a[1]||(a[1]=v((...e)=>m.prevImage&&m.prevImage(...e),["stop"]))},[c(f,{name:"prev",class:"ops-nav-icon"})])):s("v-if",!0),l("img",{src:m.currentImageUrl,alt:m.imageName,class:"ops-preview-image",onLoad:a[2]||(a[2]=(...e)=>m.onImageLoad&&m.onImageLoad(...e)),onError:a[3]||(a[3]=(...e)=>m.onImageError&&m.onImageError(...e))},null,40,Ie),n.images.length>1&&m.showNextButton?(e(),t("button",{key:1,class:"ops-nav-btn ops-next-btn",onClick:a[4]||(a[4]=v((...e)=>m.nextImage&&m.nextImage(...e),["stop"]))},[c(f,{name:"next",class:"ops-nav-icon"})])):s("v-if",!0)]),s(" 图片计数器 "),n.images.length>1?(e(),t("div",xe,d(h.currentIndex+1)+" / "+d(n.images.length),1)):s("v-if",!0),s(" 缩放控制按钮 "),l("div",Ce,[l("button",{class:"ops-zoom-btn",disabled:!m.canZoomOut,onClick:a[5]||(a[5]=v((...e)=>m.zoomOut&&m.zoomOut(...e),["stop"])),title:"缩小"},[c(f,{name:"zoomOut",class:"ops-zoom-icon"})],8,be),l("button",{class:"ops-zoom-btn",onClick:a[6]||(a[6]=v((...e)=>m.resetZoom&&m.resetZoom(...e),["stop"])),title:"1:1"},d(Math.round(100*h.scale))+"% ",1),l("button",{class:"ops-zoom-btn",disabled:!m.canZoomIn,onClick:a[7]||(a[7]=v((...e)=>m.zoomIn&&m.zoomIn(...e),["stop"])),title:"放大"},[c(f,{name:"zoomIn",class:"ops-zoom-icon"})],8,ye),l("button",{class:"ops-zoom-btn",onClick:a[8]||(a[8]=v((...e)=>m.fitScreen&&m.fitScreen(...e),["stop"])),title:"适应屏幕"},[c(f,{name:"fullscreen",class:"ops-zoom-icon"})])])])):s("v-if",!0)]),_:1})},fe.__scopeId="data-v-76b5889a",fe.__file="src/components/AgentAssistant/ImagePreviewModal.vue";var Me={name:"AgentAssistant",components:{FloatingTrigger:A,ChatModal:T,WelcomeMessage:K,MessageList:ce,ImagePreview:he,UploadButton:pe,ImagePreviewModal:fe},props:M,data(){return{showChatBox:!1,inputText:"",messages:[],isLoading:!1,unreadCount:0,isMinimized:!1,previewImages:[],uploadedImages:[],modalWidth:this.width,modalHeight:this.height,showImagePreview:!1,previewImagesData:[],previewImageIndex:0}},watch:{certificate:{handler(e){e&&y.setCertificate(e)},immediate:!0},width:{handler(e){this.modalWidth=e},immediate:!0},height:{handler(e){this.modalHeight=e},immediate:!0}},computed:{welcomeTitle:()=>"您好!我是您的智能助手",welcomeContent(){return this.welcomeMessage||"您好!我是智能助手,请问有什么可以帮助您的吗?"},assistantTitle(){return this.assistantTitleProp||"智能助手"}},methods:{toggleChatBox(){this.showChatBox=!this.showChatBox,this.isMinimized=!1,this.showChatBox&&(this.unreadCount=0,0===this.messages.length&&this.addMessage("assistant",this.welcomeContent),this.$nextTick(()=>{this.focusInput()}))},handleResize(e){this.modalWidth=e.width,this.modalHeight=e.height},minimizeChat(){this.isMinimized=!0,this.showChatBox=!1},handleSendMessage(e){if(!e.trim()&&0===this.previewImages.length||this.isLoading)return;const t=[...this.previewImages],s=e||"";this.addMessage("user",s,t),this.isLoading=!0;const i=this.addMessage("assistant","正在深度思考您的问题...",[]);this.callApi(e,t,i.id),this.inputText="",this.clearImages()},async callApi(e,t=null,s=null){try{const i=(t||this.previewImages).filter(e=>!0===e.uploadSuccess).map(e=>e.url),a=await S(e,this.userName,i);if(a.success){const e=a.data.data.choices[0].message.content;s?this.updateMessage(s,e):this.addMessage("assistant",e)}else s?this.updateMessage(s,a.error||"服务异常,请稍后再试。"):this.addMessage("assistant",a.error||"服务异常,请稍后再试。")}catch(e){console.error("API调用失败:",e),s?this.updateMessage(s,"网络错误或服务异常,请稍后再试。"):this.addMessage("assistant","网络错误或服务异常,请稍后再试。")}finally{this.isLoading=!1}},updateMessage(e,t){const s=this.messages.findIndex(t=>t.id===e);-1!==s&&(this.messages[s].content=t,this.messages[s].timestamp=new Date)},addMessage(e,t,s=[]){const i={id:Date.now()+Math.random(),sender:e,content:t||"",images:s,timestamp:new Date};return this.messages.push(i),"assistant"!==e||this.showChatBox||this.unreadCount++,this.$nextTick(()=>{this.$refs.messageList&&this.$refs.messageList.scrollToBottom()}),i},scrollToBottom(){this.$refs.chatModal?.$refs.messagesContainer?.scrollTo({top:this.$refs.chatModal.$refs.messagesContainer.scrollHeight,behavior:"smooth"})},focusInput(){this.$refs.chatModal?.focus()},handleInput(){this.autoResizeTextarea()},autoResizeTextarea(){},async handleFilesSelected(e){const t=this.maxImageCount-this.previewImages.length;if(t<=0)return void this.handleUploadError(`最多只能上传${this.maxImageCount}张图片`);const s=e.slice(0,t);for(let e of s){if(this.previewImages.length>=this.maxImageCount){this.handleUploadError(`最多只能上传${this.maxImageCount}张图片`);break}try{this.isLoading=!0;const t=await z(e.file);if(t.success){const s={url:t.data.accessPath,name:e.name,size:e.size,uploadSuccess:!0};this.previewImages.push(s)}else{const s={url:e.url,name:e.name,size:e.size,uploadSuccess:!1,error:t.error};this.previewImages.push(s),this.handleUploadError(`图片 ${e.name} 上传失败: ${t.error}`)}}catch(t){console.error("文件上传异常:",t);const s={url:e.url,name:e.name,size:e.size,uploadSuccess:!1,error:"上传异常"};this.previewImages.push(s),this.handleUploadError(`图片 ${e.name} 上传异常: ${t.message}`)}finally{this.isLoading=!1}}},handleUploadError(e){alert(e)},removeImage(e){this.previewImages.splice(e,1)},clearImages(){this.previewImages=[],this.uploadedImages=[],this.$refs.uploadButton&&this.$refs.uploadButton.reset()},previewImage(e){const t=[];this.messages.forEach(e=>{e.images&&e.images.length>0&&e.images.forEach((s,i)=>{t.push({url:s.url,name:s.name||`图片_${t.length+1}`,messageId:e.id,imageIndex:i})})});const s=t.findIndex(t=>t.url===e);-1!==s&&(this.previewImagesData=t,this.previewImageIndex=s,this.showImagePreview=!0)},closeImagePreview(){this.showImagePreview=!1,this.previewImagesData=[],this.previewImageIndex=0},handleImageChange(e){this.previewImageIndex=e},handleImageLoad(e){console.log("图片加载完成:",e)},handleImageError(e){console.error("图片加载失败:",e)}}};const Le={class:"agent-assistant"};Me.render=function(i,a,n,r,l,d){const h=o("FloatingTrigger"),m=o("WelcomeMessage"),u=o("MessageList"),v=o("ImagePreview"),f=o("UploadButton"),w=o("ChatModal"),I=o("ImagePreviewModal");return e(),t("div",Le,[s(" 浮动触发器 "),l.showChatBox?s("v-if",!0):(e(),g(h,{key:0,"unread-count":l.unreadCount,"show-badge":i.showUnreadBadge,onToggle:d.toggleChatBox},null,8,["unread-count","show-badge","onToggle"])),s(" 聊天弹窗 "),c(w,{visible:l.showChatBox,width:l.modalWidth,height:l.modalHeight,"assistant-title":d.assistantTitle,sending:l.isLoading,"initial-value":l.inputText,placeholder:"输入消息...","max-length":500,disabled:l.isLoading,onClose:d.toggleChatBox,onMinimize:d.minimizeChat,onSend:d.handleSendMessage,onInputChange:d.handleInput,onFilesPasted:d.handleFilesSelected,onResize:d.handleResize,ref:"chatModal"},{welcome:p(()=>[0===l.messages.length?(e(),g(m,{key:0,title:d.welcomeTitle,message:d.welcomeContent},null,8,["title","message"])):s("v-if",!0)]),messages:p(()=>[c(u,{messages:l.messages,onPreviewImage:d.previewImage,ref:"messageList"},null,8,["messages","onPreviewImage"])]),"image-preview":p(()=>[c(v,{images:l.previewImages,disabled:l.isLoading,onRemove:d.removeImage},null,8,["images","disabled","onRemove"])]),"upload-button":p(()=>[c(f,{disabled:l.isLoading,"is-loading":l.isLoading,"max-image-count":i.maxImageCount,"max-image-size":i.maxImageSize,"current-image-count":l.previewImages.length,onFilesSelected:d.handleFilesSelected,onError:d.handleUploadError,ref:"uploadButton"},null,8,["disabled","is-loading","max-image-count","max-image-size","current-image-count","onFilesSelected","onError"])]),_:1},8,["visible","width","height","assistant-title","sending","initial-value","disabled","onClose","onMinimize","onSend","onInputChange","onFilesPasted","onResize"]),s(" 图片预览模态框 "),c(I,{visible:l.showImagePreview,images:l.previewImagesData,"initial-index":l.previewImageIndex,onClose:d.closeImagePreview,onImageChange:d.handleImageChange,onImageLoad:d.handleImageLoad,onImageError:d.handleImageError},null,8,["visible","images","initial-index","onClose","onImageChange","onImageLoad","onImageError"])])},Me.__scopeId="data-v-5a317acc",Me.__file="src/components/AgentAssistant/index.vue";const ke={install(e,t={}){const s=b(e),i=3===s,a=e;!function(e,t,s){3===b(e)?e.config.globalProperties[t]=s:e.prototype[t]=s}(e,"$myPlugin",{log:e=>console.log(`[CrossPlugin] ${e}`),getVersion:()=>`Vue${s} + Plugin@1.0.0`}),a.component("AgentAssistant",Me);let n;if(a.directive("color",{bind:(e,t)=>e.style.color=t.value,mounted:(e,t)=>e.style.color=t.value,update:(e,t)=>e.style.color=t.value,updated:(e,t)=>e.style.color=t.value}),i)try{if("undefined"!=typeof require){const{reactive:e}=require("vue");n=e({count:0})}else if("undefined"!=typeof window&&window.Vue){const{reactive:e}=window.Vue;n=e({count:0})}else n={count:0}}catch(e){n={count:0}}else try{n=e.observable({count:0})}catch(e){n={count:0}}ke.state=n}};"undefined"!=typeof window&&window.Vue&&window.Vue.use(ke);export{ke as default};
1
+ import{openBlock as e,createElementBlock as t,createCommentVNode as s,Fragment as i,renderList as a,mergeProps as n,resolveComponent as o,normalizeStyle as r,createElementVNode as l,createVNode as c,toDisplayString as d,withDirectives as h,vShow as m,createBlock as g,Transition as u,withCtx as p,withModifiers as v,renderSlot as f,withKeys as w,vModelText as I,normalizeClass as x,TransitionGroup as C}from"vue";function b(e){return e?e.version&&e.version.startsWith?e.version.startsWith("3.")?3:2:e._createVNode||e.constructor&&"App"===e.constructor.name?3:(e.util&&e.set,2):2}const y=new class{constructor(){this.certificate="",this.isAuthenticated=!1}setCertificate(e){this.certificate=e||"",this.isAuthenticated=!!this.certificate,this.certificate?localStorage.setItem("chat_certificate",this.certificate):localStorage.removeItem("chat_certificate")}getCertificate(){return this.certificate||(this.certificate=localStorage.getItem("chat_certificate")||"",this.isAuthenticated=!!this.certificate),this.certificate}clearCertificate(){this.certificate="",this.isAuthenticated=!1,localStorage.removeItem("chat_certificate")}isAuth(){return this.isAuthenticated}},M={certificate:{type:String,required:!0},userName:{type:String,required:!0,default:""},domain:{type:String,default:"https://css.tineco.com"},width:{type:[String,Number],default:400},height:{type:[String,Number],default:550},assistantTitleProp:{type:String,default:"智能助手"},welcomeMessage:{type:String,default:""},showUnreadBadge:{type:Boolean,default:!0},maxImageCount:{type:Number,default:9},maxImageSize:{type:Number,default:5}},L=M.domain.default;function k(e=L){return e.startsWith("http")||(e=`https://${e}`),e.replace(/\/$/,"")}async function S(e,t,s=[],i){const a={message:e,userName:t,fileUrls:s};return await async function(e,t,s="",i=""){try{const a={"Content-Type":"application/json"},n=i||y.getCertificate();n&&(a.Certificate=n);const o=`${k(s)}${e}`,r=await fetch(o,{method:"POST",headers:a,body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const l=await r.json();return"S"===l.code?{success:!0,data:l}:{success:!1,error:l.msg||"请求失败",data:l}}catch(e){return console.error("API调用失败:",e),{success:!1,error:e.message||"网络错误"}}}("/gateway/baseServer/asmApiCoral/asmMaintenance",a,i)}async function z(e,t){const s=new FormData;s.append("file",e),s.append("bucket","CSS-01");try{const e=k(t),i=await fetch(`${e}/gateway/fileServer/v4/upload/single`,{method:"POST",body:s});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);const a=await i.json();return"S"===a.code&&!0===a.success?{success:!0,data:a.data}:{success:!1,error:a.msg||"上传失败",data:a}}catch(e){return console.error("文件上传失败:",e),{success:!1,error:e.message||"网络错误"}}}const $={user:{viewBox:"0 0 24 24",paths:[{d:"M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z",fill:"currentColor"}]},aiAvatar:{viewBox:"0 0 24 24",paths:[{d:"M12 2C12 2 9 3.5 7 5.5C5 7.5 3.5 10 3.5 10C3.5 10 5 12.5 7 14.5C9 16.5 12 18 12 18C12 18 15 16.5 17 14.5C19 12.5 20.5 10 20.5 10C20.5 10 19 7.5 17 5.5C15 3.5 12 2 12 2Z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"},{d:"M12 4L13 2.5M12 4L11 2.5M16 6L17.5 5M16 6L15 4.5M20 10L21.5 9M20 10L19 11.5M16 14L17.5 15.5M16 14L15 12.5M12 16L13 17.5M12 16L11 17.5M8 14L6.5 15.5M8 14L9 12.5M4 10L2.5 9M4 10L5 11.5M8 6L6.5 5M8 6L9 4.5",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round"},{d:"M9 10H7M17 10H15M12 7V5",stroke:"#60a5fa",strokeWidth:"1.5",strokeLinecap:"round"}],circles:[{cx:"12",cy:"10",r:"2.5",fill:"#60a5fa",stroke:"white",strokeWidth:"1"},{cx:"7",cy:"10",r:"1",fill:"#4ade80"},{cx:"17",cy:"10",r:"1",fill:"#4ade80"},{cx:"12",cy:"5",r:"1",fill:"#fbbf24"}],lines:[{x1:"12",y1:"2",x2:"12",y2:"4",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"12",y1:"16",x2:"12",y2:"18",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"6",y1:"10",x2:"4",y2:"10",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"20",y1:"10",x2:"18",y2:"10",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"}]},close:{viewBox:"0 0 24 24",paths:[{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"}]},minimize:{viewBox:"0 0 24 24",paths:[{d:"M19 13H5V11H19V13Z",fill:"currentColor"}]},send:{viewBox:"0 0 24 24",paths:[{d:"M2 21L23 12L2 3V10L17 12L2 14V21Z",fill:"currentColor"}]},upload:{viewBox:"0 0 24 24",paths:[{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6m4-3h6m0 0v6m0-6L13 13",fill:"currentColor"}]},uploadImage:{viewBox:"0 0 24 24",paths:[{d:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"},{d:"M12 13a3 3 0 100-6 3 3 0 000 6z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}]},aiAssistant:{viewBox:"0 0 24 24",paths:[{d:"M12 6C14.21 6 16 7.79 16 10C16 12.21 14.21 14 12 14C9.79 14 8 12.21 8 10C8 7.79 9.79 6 12 6Z",fill:"currentColor"},{d:"M9 10H7M17 10H15M12 7V5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"},{d:"M12 16C9.33 16 4 17.34 4 20V22H20V20C20 17.34 14.67 16 12 16Z",fill:"currentColor"}],circles:[{cx:"7",cy:"10",r:"1",fill:"#4ade80"},{cx:"17",cy:"10",r:"1",fill:"#4ade80"},{cx:"12",cy:"5",r:"1",fill:"#fbbf24"}]},remove:{viewBox:"0 0 24 24",paths:[{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"}]},prev:{viewBox:"0 0 24 24",paths:[{d:"M15.41 7.41L14 6L8 12L14 18L15.41 16.59L10.83 12L15.41 7.41Z",fill:"currentColor"}]},next:{viewBox:"0 0 24 24",paths:[{d:"M8.59 7.41L10 6L16 12L10 18L8.59 16.59L13.17 12L8.59 7.41Z",fill:"currentColor"}]},zoomIn:{viewBox:"0 0 24 24",paths:[{d:"M12 18a6 6 0 1 0 0-12 6 6 0 0 0 0 12z",fill:"none",stroke:"currentColor",strokeWidth:"2"},{d:"M20 20l-3.5-3.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"},{d:"M12 9v6M9 12h6",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}]},zoomOut:{viewBox:"0 0 24 24",paths:[{d:"M12 16a4 4 0 1 0 0-8 4 4 0 0 0 0 8z",fill:"none",stroke:"currentColor",strokeWidth:"2"},{d:"M19 19l-3-3",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"},{d:"M10 12h4",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}]},fullscreen:{viewBox:"0 0 24 24",paths:[{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}]}};var B={name:"SvgIcon",props:{name:{type:String,required:!0,validator:e=>Object.keys($).includes(e)},size:{type:[Number,String],default:24}},computed:{iconConfig(){return $[this.name]||$.user},viewBox(){return this.iconConfig.viewBox||"0 0 24 24"},paths(){return this.iconConfig.paths||[]},circles(){return this.iconConfig.circles||[]},lines(){return this.iconConfig.lines||[]}}};const _=["viewBox"];B.render=function(o,r,l,c,d,h){return e(),t("svg",{viewBox:h.viewBox,fill:"none",xmlns:"http://www.w3.org/2000/svg"},[s(" 渲染路径 "),(e(!0),t(i,null,a(h.paths,(s,i)=>(e(),t("path",n({key:`path-${i}`},{ref_for:!0},s),null,16))),128)),s(" 渲染圆形 "),(e(!0),t(i,null,a(h.circles,(s,i)=>(e(),t("circle",n({key:`circle-${i}`},{ref_for:!0},s),null,16))),128)),s(" 渲染线条 "),(e(!0),t(i,null,a(h.lines,(s,i)=>(e(),t("line",n({key:`line-${i}`},{ref_for:!0},s),null,16))),128))],8,_)},B.__file="src/components/AgentAssistant/Icons/SvgIcon.vue";var A={name:"FloatingTrigger",components:{SvgIcon:B},props:{unreadCount:{type:Number,default:0},showBadge:{type:Boolean,default:!0}},data:()=>({isHovered:!1,isDragging:!1,hasDragged:!1,startX:0,startY:0,position:{bottom:30,right:30}}),computed:{triggerStyle(){return{bottom:this.position.bottom+"px",right:this.position.right+"px"}}},methods:{startDrag(e){this.isDragging=!0,this.hasDragged=!1,this.startX=e.clientX,this.startY=e.clientY,document.addEventListener("mousemove",this.onDrag),document.addEventListener("mouseup",this.stopDrag)},onDrag(e){if(!this.isDragging)return;const t=e.clientX-this.startX,s=e.clientY-this.startY;(Math.abs(t)>3||Math.abs(s)>3)&&(this.hasDragged=!0);const i=window.innerWidth,a=window.innerHeight;this.position.right=Math.max(10,Math.min(i-64-10,this.position.right-t)),this.position.bottom=Math.max(10,Math.min(a-64-10,this.position.bottom-s)),this.startX=e.clientX,this.startY=e.clientY},stopDrag(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDrag),document.removeEventListener("mouseup",this.stopDrag)},handleClick(){this.hasDragged||this.$emit("toggle"),this.hasDragged=!1}}};const D={class:"ops-icon-wrapper"},P={key:0,class:"ops-unread-badge"},W={class:"ops-tooltip"};A.render=function(i,a,n,g,u,p){const v=o("SvgIcon");return e(),t("div",{class:"ops-floating-trigger",style:r(p.triggerStyle),onMousedown:a[0]||(a[0]=(...e)=>p.startDrag&&p.startDrag(...e)),onClick:a[1]||(a[1]=(...e)=>p.handleClick&&p.handleClick(...e)),onMouseenter:a[2]||(a[2]=e=>u.isHovered=!0),onMouseleave:a[3]||(a[3]=e=>u.isHovered=!1)},[l("div",D,[c(v,{name:"aiAssistant",class:"ops-ai-icon"}),n.unreadCount>0&&n.showBadge?(e(),t("div",P,d(n.unreadCount),1)):s("v-if",!0)]),h(l("div",W,"智能助手",512),[[m,u.isHovered]])],36)},A.__scopeId="data-v-415d7a2c",A.__file="src/components/AgentAssistant/FloatingTrigger.vue";var T={name:"ChatModal",components:{SvgIcon:B},props:{visible:{type:Boolean,default:!1},width:{type:[String,Number],default:380},height:{type:[String,Number],default:520},assistantTitle:{type:String,default:"智能助手"},placeholder:{type:String,default:"输入消息..."},maxLength:{type:Number,default:500},disabled:{type:Boolean,default:!1},sending:{type:Boolean,default:!1},initialValue:{type:String,default:""}},data(){return{inputText:this.initialValue,isDragging:!1,isResizing:!1,startX:0,startY:0,startWidth:0,startHeight:0,position:{left:window.innerWidth-parseInt(this.width)-30,top:window.innerHeight-parseInt(this.height)-100}}},computed:{calculatedWidth(){return"number"==typeof this.width?this.width+"px":this.width},calculatedHeight(){return"number"==typeof this.height?this.height+"px":this.height},sendDisabled(){return!this.inputText.trim()&&!this.$slots["image-preview"]||this.disabled||this.sending}},watch:{initialValue(e){this.inputText=e},width(e){this.position.left=window.innerWidth-parseInt(this.calculatedWidth)-30},height(e){this.position.top=window.innerHeight-parseInt(this.calculatedHeight)-100}},methods:{startDrag(e){this.isDragging=!0,this.startX=e.clientX-this.position.left,this.startY=e.clientY-this.position.top,document.addEventListener("mousemove",this.onDrag),document.addEventListener("mouseup",this.stopDrag)},onDrag(e){if(!this.isDragging)return;const t=window.innerWidth,s=window.innerHeight,i=parseInt(this.calculatedWidth),a=parseInt(this.calculatedHeight);let n=e.clientX-this.startX,o=e.clientY-this.startY;n=Math.max(10,Math.min(t-i-10,n)),o=Math.max(10,Math.min(s-a-10,o)),this.position.left=n,this.position.top=o},stopDrag(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDrag),document.removeEventListener("mouseup",this.stopDrag)},startResize(e){e.preventDefault(),this.isResizing=!0,this.startX=e.clientX,this.startY=e.clientY,this.startWidth=parseInt(this.calculatedWidth),this.startHeight=parseInt(this.calculatedHeight),document.addEventListener("mousemove",this.onResize),document.addEventListener("mouseup",this.stopResize)},onResize(e){if(!this.isResizing)return;const t=e.clientX-this.startX,s=e.clientY-this.startY,i=this.startWidth/this.startHeight;let a=this.startWidth+t,n=this.startHeight+s;Math.abs(t)>Math.abs(s)?n=a/i:a=n*i;const o=window.innerWidth-20,r=window.innerHeight-20;a=Math.max(300,Math.min(o,a)),n=Math.max(400,Math.min(r,n)),this.$emit("resize",{width:a,height:n})},stopResize(){this.isResizing=!1,document.removeEventListener("mousemove",this.onResize),document.removeEventListener("mouseup",this.stopResize)},handleSend(){this.sendDisabled||(this.$emit("send",this.inputText),this.inputText="")},focus(){const e=this.$el.querySelector(".message-input");e&&e.focus()},async handlePaste(e){try{const t=e.clipboardData.items;for(let s=0;s<t.length;s++){const i=t[s];if(-1!==i.type.indexOf("image")){e.preventDefault();const t=i.getAsFile();if(t){const e={file:t,name:t.name||`pasted-image-${Date.now()}.png`,size:t.size,url:""},s=new FileReader;return s.onload=t=>{e.url=t.target.result,this.$emit("files-pasted",[e])},void s.readAsDataURL(t)}}}}catch(e){console.error("粘贴处理失败:",e)}}}};const H={class:"ops-chat-container"},E={class:"ops-header-info"},V={class:"ops-avatar"},R={class:"ops-header-text"},N={class:"ops-assistant-name"},Z={class:"ops-header-actions"},F={class:"ops-chat-messages",ref:"messagesContainer"},U={class:"ops-chat-input-area"},X={class:"ops-input-container"},Y=["placeholder","maxlength","disabled"],O={class:"ops-input-actions"},q={class:"ops-char-count"},j=["disabled"],J={key:1,class:"ops-loading-spinner"};T.render=function(i,a,n,m,C,b){const y=o("SvgIcon");return e(),g(u,{name:"ops-slide-fade"},{default:p(()=>[n.visible?(e(),t("div",{key:0,class:"ops-chat-modal",style:r({width:b.calculatedWidth,height:b.calculatedHeight,left:C.position.left+"px",top:C.position.top+"px"})},[l("div",H,[s(" 头部 "),l("div",{class:"ops-chat-header",onMousedown:a[2]||(a[2]=(...e)=>b.startDrag&&b.startDrag(...e))},[l("div",E,[l("div",V,[c(y,{name:"user",class:"ops-avatar-icon"})]),l("div",R,[l("h3",N,d(n.assistantTitle),1),a[9]||(a[9]=l("span",{class:"ops-status ops-online"},"在线",-1))])]),l("div",Z,[l("button",{class:"ops-minimize-btn",onClick:a[0]||(a[0]=v(e=>i.$emit("minimize"),["stop"]))},[c(y,{name:"minimize",class:"ops-action-icon"})]),l("button",{class:"ops-close-btn",onClick:a[1]||(a[1]=v(e=>i.$emit("close"),["stop"]))},[c(y,{name:"close",class:"ops-action-icon"})])])],32),s(" 右下角调整大小手柄 "),l("div",{class:"ops-resize-handle",onMousedown:a[3]||(a[3]=(...e)=>b.startResize&&b.startResize(...e))},null,32),s(" 消息区域 "),l("div",F,[f(i.$slots,"welcome"),f(i.$slots,"messages")],512),s(" 输入区域 "),l("div",U,[f(i.$slots,"image-preview"),l("div",X,[h(l("textarea",{"onUpdate:modelValue":a[4]||(a[4]=e=>C.inputText=e),onKeydown:a[5]||(a[5]=w(v((...e)=>b.handleSend&&b.handleSend(...e),["exact","prevent"]),["enter"])),onInput:a[6]||(a[6]=e=>i.$emit("input-change",e)),onPaste:a[7]||(a[7]=(...e)=>b.handlePaste&&b.handlePaste(...e)),placeholder:n.placeholder,class:"ops-message-input",rows:"1",maxlength:n.maxLength,disabled:n.disabled},null,40,Y),[[I,C.inputText]]),l("div",O,[f(i.$slots,"upload-button"),l("span",q,d(C.inputText.length)+"/"+d(n.maxLength),1),l("button",{onClick:a[8]||(a[8]=(...e)=>b.handleSend&&b.handleSend(...e)),class:x(["ops-send-button",{"ops-loading":n.sending}]),disabled:b.sendDisabled},[f(i.$slots,"send-icon",{},()=>[n.sending?(e(),t("div",J)):(e(),g(y,{key:0,name:"send",class:"ops-send-icon"}))])],10,j)])])])])],4)):s("v-if",!0)]),_:3})},T.__scopeId="data-v-36f7e58f",T.__file="src/components/AgentAssistant/ChatModal.vue";var K={name:"WelcomeMessage",components:{SvgIcon:B},props:{title:{type:String,default:"您好!我是您的智能助手"},message:{type:String,default:"您好!我是智能助手,请问有什么可以帮助您的吗?"}}};const G={class:"ops-welcome-message"},Q={class:"ops-welcome-text"};K.render=function(s,i,a,n,o,r){return e(),t("div",G,[i[0]||(i[0]=l("div",{class:"ops-welcome-avatar"},[l("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[l("path",{d:"M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z",fill:"currentColor"})])],-1)),l("div",Q,[l("h4",null,d(a.title),1),l("p",null,d(a.message),1)])])},K.__scopeId="data-v-2f1ef74a",K.__file="src/components/AgentAssistant/WelcomeMessage.vue";var ee={name:"MessageImages",props:{images:{type:Array,default:()=>[]}},methods:{previewImage(e){this.$emit("preview",e)}}};const te={class:"ops-message-images"},se=["src","alt","onClick"],ie={key:0,class:"ops-upload-error-overlay"};ee.render=function(n,o,r,c,d,h){return e(),t("div",te,[(e(!0),t(i,null,a(r.images,(i,a)=>(e(),t("div",{key:a,class:x(["ops-message-image-item",{"ops-upload-failed":!1===i.uploadSuccess}])},[l("img",{src:i.url,alt:i.name,class:"ops-message-image",onClick:e=>h.previewImage(i.url)},null,8,se),s(" 上传失败的提示 "),!1===i.uploadSuccess?(e(),t("div",ie,[...o[0]||(o[0]=[l("span",{class:"ops-error-text"},"上传失败",-1)])])):s("v-if",!0)],2))),128))])},ee.__scopeId="data-v-c687e28e",ee.__file="src/components/AgentAssistant/MessageImages.vue";var ae={name:"MessageBubble",components:{MessageImages:ee,SvgIcon:B},props:{message:{type:Object,required:!0,validator:e=>e.sender&&e.timestamp&&void 0!==e.content}},methods:{handleImagePreview(e){this.$emit("preview-image",e)}}};const ne={key:0,class:"ops-message-avatar ops-assistant-avatar"},oe={class:"ops-message-avatar ops-user-avatar"},re={class:"ops-message-content"},le={class:"ops-message-text"};ae.render=function(a,n,r,h,m,u){const p=o("SvgIcon"),v=o("MessageImages");return e(),t("div",{class:x(["ops-message-bubble","ops-"+r.message.sender])},[s(" 助手头像 "),"assistant"===r.message.sender?(e(),t("div",ne,[c(p,{name:"user"})])):(e(),t(i,{key:1},[s(" 用户头像 "),l("div",oe,[c(p,{name:"user"})])],2112)),l("div",re,[l("div",le,d(r.message.content),1),s(" 图片展示 "),r.message.images&&r.message.images.length>0?(e(),g(v,{key:0,images:r.message.images,onPreview:u.handleImagePreview},null,8,["images","onPreview"])):s("v-if",!0)])],2)},ae.__scopeId="data-v-0927d266",ae.__file="src/components/AgentAssistant/MessageBubble.vue";var ce={name:"MessageList",components:{MessageBubble:ae},props:{messages:{type:Array,default:()=>[]}},methods:{handleImagePreview(e){this.$emit("preview-image",e)},scrollToBottom(){this.$nextTick(()=>{const e=this.$refs.messageList;e&&(e.scrollTop=e.scrollHeight)})}}};const de={class:"ops-message-list",ref:"messageList"};ce.render=function(s,n,r,l,d,h){const m=o("MessageBubble");return e(),t("div",de,[c(C,{name:"ops-message-fade",tag:"div",class:"ops-transition-group"},{default:p(()=>[(e(!0),t(i,null,a(r.messages,(t,s)=>(e(),g(m,{key:t.id||s,message:t,onPreviewImage:h.handleImagePreview},null,8,["message","onPreviewImage"]))),128))]),_:1})],512)},ce.__scopeId="data-v-4f7fdfc2",ce.__file="src/components/AgentAssistant/MessageList.vue";var he={name:"ImagePreview",components:{SvgIcon:B},props:{images:{type:Array,default:()=>[]},disabled:{type:Boolean,default:!1}},methods:{removeImage(e){this.$emit("remove",e)}}};const me={key:0,class:"ops-image-preview-container"},ge=["src","alt"],ue=["onClick","disabled"];he.render=function(n,r,d,h,m,g){const u=o("SvgIcon");return d.images.length>0?(e(),t("div",me,[(e(!0),t(i,null,a(d.images,(s,i)=>(e(),t("div",{key:i,class:"ops-image-preview-item"},[l("img",{src:s.url,alt:s.name,class:"ops-preview-image"},null,8,ge),l("button",{class:"ops-remove-image-btn",onClick:e=>g.removeImage(i),type:"button",disabled:d.disabled},[c(u,{name:"close",class:"ops-remove-icon"})],8,ue)]))),128))])):s("v-if",!0)},he.__scopeId="data-v-28f9b383",he.__file="src/components/AgentAssistant/ImagePreview.vue";var pe={name:"UploadButton",components:{SvgIcon:B},props:{disabled:{type:Boolean,default:!1},isLoading:{type:Boolean,default:!1},maxImageCount:{type:Number,default:3},maxImageSize:{type:Number,default:5},currentImageCount:{type:Number,default:0}},methods:{handleFileChange(e){const t=Array.from(e.target.files);if(0===t.length)return;const s=this.maxImageCount-this.currentImageCount;if(s<=0)return void this.$emit("error",`最多只能上传${this.maxImageCount}张图片`);const i=t.slice(0,s),a=[];for(let e of i){if(!e.type.startsWith("image/")){this.$emit("error","请选择图片文件");continue}const t=1024*this.maxImageSize*1024;e.size>t?this.$emit("error",`图片 ${e.name} 太大,请选择小于${this.maxImageSize}MB的图片`):a.push(e)}const n=a.slice(0,s);n.length>0&&this.processFiles(n),e.target.value=""},processFiles(e){const t=[];e.forEach(e=>{t.push({url:"",name:e.name,file:e,size:e.size})}),this.$emit("files-selected",t)},reset(){this.$refs.fileInput&&(this.$refs.fileInput.value="")}}};const ve=["multiple","disabled"];pe.render=function(s,i,a,n,r,d){const h=o("SvgIcon");return e(),t("label",{class:x(["ops-upload-button",{"ops-disabled":a.disabled||a.isLoading}])},[l("input",{type:"file",accept:"image/*",multiple:a.maxImageCount>1,onChange:i[0]||(i[0]=(...e)=>d.handleFileChange&&d.handleFileChange(...e)),ref:"fileInput",disabled:a.disabled||a.isLoading,class:"ops-file-input"},null,40,ve),c(h,{name:"uploadImage",class:"ops-upload-icon"})],2)},pe.__scopeId="data-v-724f2729",pe.__file="src/components/AgentAssistant/UploadButton.vue";var fe={name:"ImagePreviewModal",components:{SvgIcon:B},props:{visible:{type:Boolean,default:!1},images:{type:Array,default:()=>[]},initialIndex:{type:Number,default:0}},data(){return{currentIndex:this.initialIndex,scale:1,minScale:.1,maxScale:5,step:.1}},computed:{currentImageUrl(){if(0===this.images.length)return"";const e=this.images[this.currentIndex];return e?.url||""},imageName(){if(0===this.images.length)return"";const e=this.images[this.currentIndex];return e?.name||"未命名图片"},showPrevButton(){return this.currentIndex>0},showNextButton(){return this.currentIndex<this.images.length-1},canZoomIn(){return this.scale<this.maxScale},canZoomOut(){return this.scale>this.minScale}},watch:{visible(e){e?(this.currentIndex=this.initialIndex,document.body.style.overflow="hidden"):document.body.style.overflow=""},initialIndex(e){this.currentIndex=e}},methods:{closeModal(){this.$emit("close")},handleBackdropClick(){this.closeModal()},prevImage(){this.currentIndex>0&&(this.currentIndex--,this.$emit("image-change",this.currentIndex))},nextImage(){this.currentIndex<this.images.length-1&&(this.currentIndex++,this.$emit("image-change",this.currentIndex))},selectImage(e){e>=0&&e<this.images.length&&(this.currentIndex=e,this.$emit("image-change",this.currentIndex))},onImageLoad(){this.$emit("image-load",{index:this.currentIndex,url:this.currentImageUrl})},onImageError(){this.$emit("image-error",{index:this.currentIndex,url:this.currentImageUrl})},zoomIn(){this.canZoomIn&&(this.scale=Math.min(this.scale+this.step,this.maxScale))},zoomOut(){this.canZoomOut&&(this.scale=Math.max(this.scale-this.step,this.minScale))},resetZoom(){this.scale=1},fitScreen(){this.scale=1}}};const we={class:"ops-image-container"},Ie=["src","alt"],xe={key:0,class:"ops-image-counter"},Ce={class:"ops-zoom-controls"},be=["disabled"],ye=["disabled"];fe.render=function(i,a,n,r,h,m){const f=o("SvgIcon");return e(),g(u,{name:"ops-modal-fade"},{default:p(()=>[n.visible?(e(),t("div",{key:0,class:"ops-image-preview-overlay",onClick:a[9]||(a[9]=(...e)=>m.handleBackdropClick&&m.handleBackdropClick(...e))},[s(" 关闭按钮 "),l("button",{class:"ops-close-btn",onClick:a[0]||(a[0]=(...e)=>m.closeModal&&m.closeModal(...e))},[c(f,{name:"close",class:"ops-close-icon"})]),s(" 图片显示区域 "),l("div",we,[n.images.length>1&&m.showPrevButton?(e(),t("button",{key:0,class:"ops-nav-btn ops-prev-btn",onClick:a[1]||(a[1]=v((...e)=>m.prevImage&&m.prevImage(...e),["stop"]))},[c(f,{name:"prev",class:"ops-nav-icon"})])):s("v-if",!0),l("img",{src:m.currentImageUrl,alt:m.imageName,class:"ops-preview-image",onLoad:a[2]||(a[2]=(...e)=>m.onImageLoad&&m.onImageLoad(...e)),onError:a[3]||(a[3]=(...e)=>m.onImageError&&m.onImageError(...e))},null,40,Ie),n.images.length>1&&m.showNextButton?(e(),t("button",{key:1,class:"ops-nav-btn ops-next-btn",onClick:a[4]||(a[4]=v((...e)=>m.nextImage&&m.nextImage(...e),["stop"]))},[c(f,{name:"next",class:"ops-nav-icon"})])):s("v-if",!0)]),s(" 图片计数器 "),n.images.length>1?(e(),t("div",xe,d(h.currentIndex+1)+" / "+d(n.images.length),1)):s("v-if",!0),s(" 缩放控制按钮 "),l("div",Ce,[l("button",{class:"ops-zoom-btn",disabled:!m.canZoomOut,onClick:a[5]||(a[5]=v((...e)=>m.zoomOut&&m.zoomOut(...e),["stop"])),title:"缩小"},[c(f,{name:"zoomOut",class:"ops-zoom-icon"})],8,be),l("button",{class:"ops-zoom-btn",onClick:a[6]||(a[6]=v((...e)=>m.resetZoom&&m.resetZoom(...e),["stop"])),title:"1:1"},d(Math.round(100*h.scale))+"% ",1),l("button",{class:"ops-zoom-btn",disabled:!m.canZoomIn,onClick:a[7]||(a[7]=v((...e)=>m.zoomIn&&m.zoomIn(...e),["stop"])),title:"放大"},[c(f,{name:"zoomIn",class:"ops-zoom-icon"})],8,ye),l("button",{class:"ops-zoom-btn",onClick:a[8]||(a[8]=v((...e)=>m.fitScreen&&m.fitScreen(...e),["stop"])),title:"适应屏幕"},[c(f,{name:"fullscreen",class:"ops-zoom-icon"})])])])):s("v-if",!0)]),_:1})},fe.__scopeId="data-v-76b5889a",fe.__file="src/components/AgentAssistant/ImagePreviewModal.vue";var Me={name:"AgentAssistant",components:{FloatingTrigger:A,ChatModal:T,WelcomeMessage:K,MessageList:ce,ImagePreview:he,UploadButton:pe,ImagePreviewModal:fe},props:M,data(){return{showChatBox:!1,inputText:"",messages:[],isLoading:!1,unreadCount:0,isMinimized:!1,previewImages:[],uploadedImages:[],modalWidth:this.width,modalHeight:this.height,showImagePreview:!1,previewImagesData:[],previewImageIndex:0}},watch:{certificate:{handler(e){e&&y.setCertificate(e)},immediate:!0},width:{handler(e){this.modalWidth=e},immediate:!0},height:{handler(e){this.modalHeight=e},immediate:!0}},computed:{welcomeTitle:()=>"您好!我是您的智能助手",welcomeContent(){return this.welcomeMessage||"您好!我是智能助手,请问有什么可以帮助您的吗?"},assistantTitle(){return this.assistantTitleProp||"智能助手"}},methods:{toggleChatBox(){this.showChatBox=!this.showChatBox,this.isMinimized=!1,this.showChatBox&&(this.unreadCount=0,0===this.messages.length&&this.addMessage("assistant",this.welcomeContent),this.$nextTick(()=>{this.focusInput()}))},handleResize(e){this.modalWidth=e.width,this.modalHeight=e.height},minimizeChat(){this.isMinimized=!0,this.showChatBox=!1},handleSendMessage(e){if(!e.trim()&&0===this.previewImages.length||this.isLoading)return;const t=[...this.previewImages],s=e||"";this.addMessage("user",s,t),this.isLoading=!0;const i=this.addMessage("assistant","正在深度思考您的问题...",[]);this.callApi(e,t,i.id),this.inputText="",this.clearImages()},async callApi(e,t=null,s=null){try{const i=(t||this.previewImages).filter(e=>!0===e.uploadSuccess).map(e=>e.url),a=await S(e,this.userName,i,this.domain);if(a.success){const e=a.data.data.choices[0].message.content;s?this.updateMessage(s,e):this.addMessage("assistant",e)}else s?this.updateMessage(s,a.error||"服务异常,请稍后再试。"):this.addMessage("assistant",a.error||"服务异常,请稍后再试。")}catch(e){console.error("API调用失败:",e),s?this.updateMessage(s,"网络错误或服务异常,请稍后再试。"):this.addMessage("assistant","网络错误或服务异常,请稍后再试。")}finally{this.isLoading=!1}},updateMessage(e,t){const s=this.messages.findIndex(t=>t.id===e);-1!==s&&(this.messages[s].content=t,this.messages[s].timestamp=new Date)},addMessage(e,t,s=[]){const i={id:Date.now()+Math.random(),sender:e,content:t||"",images:s,timestamp:new Date};return this.messages.push(i),"assistant"!==e||this.showChatBox||this.unreadCount++,this.$nextTick(()=>{this.$refs.messageList&&this.$refs.messageList.scrollToBottom()}),i},scrollToBottom(){this.$refs.chatModal?.$refs.messagesContainer?.scrollTo({top:this.$refs.chatModal.$refs.messagesContainer.scrollHeight,behavior:"smooth"})},focusInput(){this.$refs.chatModal?.focus()},handleInput(){this.autoResizeTextarea()},autoResizeTextarea(){},async handleFilesSelected(e){const t=this.maxImageCount-this.previewImages.length;if(t<=0)return void this.handleUploadError(`最多只能上传${this.maxImageCount}张图片`);const s=e.slice(0,t);for(let e of s){if(this.previewImages.length>=this.maxImageCount){this.handleUploadError(`最多只能上传${this.maxImageCount}张图片`);break}try{this.isLoading=!0;const t=await z(e.file,this.domain);if(t.success){const s={url:t.data.accessPath,name:e.name,size:e.size,uploadSuccess:!0};this.previewImages.push(s)}else{const s={url:e.url,name:e.name,size:e.size,uploadSuccess:!1,error:t.error};this.previewImages.push(s),this.handleUploadError(`图片 ${e.name} 上传失败: ${t.error}`)}}catch(t){console.error("文件上传异常:",t);const s={url:e.url,name:e.name,size:e.size,uploadSuccess:!1,error:"上传异常"};this.previewImages.push(s),this.handleUploadError(`图片 ${e.name} 上传异常: ${t.message}`)}finally{this.isLoading=!1}}},handleUploadError(e){alert(e)},removeImage(e){this.previewImages.splice(e,1)},clearImages(){this.previewImages=[],this.uploadedImages=[],this.$refs.uploadButton&&this.$refs.uploadButton.reset()},previewImage(e){const t=[];this.messages.forEach(e=>{e.images&&e.images.length>0&&e.images.forEach((s,i)=>{t.push({url:s.url,name:s.name||`图片_${t.length+1}`,messageId:e.id,imageIndex:i})})});const s=t.findIndex(t=>t.url===e);-1!==s&&(this.previewImagesData=t,this.previewImageIndex=s,this.showImagePreview=!0)},closeImagePreview(){this.showImagePreview=!1,this.previewImagesData=[],this.previewImageIndex=0},handleImageChange(e){this.previewImageIndex=e},handleImageLoad(e){console.log("图片加载完成:",e)},handleImageError(e){console.error("图片加载失败:",e)}}};const Le={class:"agent-assistant"};Me.render=function(i,a,n,r,l,d){const h=o("FloatingTrigger"),m=o("WelcomeMessage"),u=o("MessageList"),v=o("ImagePreview"),f=o("UploadButton"),w=o("ChatModal"),I=o("ImagePreviewModal");return e(),t("div",Le,[s(" 浮动触发器 "),l.showChatBox?s("v-if",!0):(e(),g(h,{key:0,"unread-count":l.unreadCount,"show-badge":i.showUnreadBadge,onToggle:d.toggleChatBox},null,8,["unread-count","show-badge","onToggle"])),s(" 聊天弹窗 "),c(w,{visible:l.showChatBox,width:l.modalWidth,height:l.modalHeight,"assistant-title":d.assistantTitle,sending:l.isLoading,"initial-value":l.inputText,placeholder:"输入消息...","max-length":500,disabled:l.isLoading,onClose:d.toggleChatBox,onMinimize:d.minimizeChat,onSend:d.handleSendMessage,onInputChange:d.handleInput,onFilesPasted:d.handleFilesSelected,onResize:d.handleResize,ref:"chatModal"},{welcome:p(()=>[0===l.messages.length?(e(),g(m,{key:0,title:d.welcomeTitle,message:d.welcomeContent},null,8,["title","message"])):s("v-if",!0)]),messages:p(()=>[c(u,{messages:l.messages,onPreviewImage:d.previewImage,ref:"messageList"},null,8,["messages","onPreviewImage"])]),"image-preview":p(()=>[c(v,{images:l.previewImages,disabled:l.isLoading,onRemove:d.removeImage},null,8,["images","disabled","onRemove"])]),"upload-button":p(()=>[c(f,{disabled:l.isLoading,"is-loading":l.isLoading,"max-image-count":i.maxImageCount,"max-image-size":i.maxImageSize,"current-image-count":l.previewImages.length,onFilesSelected:d.handleFilesSelected,onError:d.handleUploadError,ref:"uploadButton"},null,8,["disabled","is-loading","max-image-count","max-image-size","current-image-count","onFilesSelected","onError"])]),_:1},8,["visible","width","height","assistant-title","sending","initial-value","disabled","onClose","onMinimize","onSend","onInputChange","onFilesPasted","onResize"]),s(" 图片预览模态框 "),c(I,{visible:l.showImagePreview,images:l.previewImagesData,"initial-index":l.previewImageIndex,onClose:d.closeImagePreview,onImageChange:d.handleImageChange,onImageLoad:d.handleImageLoad,onImageError:d.handleImageError},null,8,["visible","images","initial-index","onClose","onImageChange","onImageLoad","onImageError"])])},Me.__scopeId="data-v-5a317acc",Me.__file="src/components/AgentAssistant/index.vue";const ke={install(e,t={}){const s=b(e),i=3===s,a=e;!function(e,t,s){3===b(e)?e.config.globalProperties[t]=s:e.prototype[t]=s}(e,"$myPlugin",{log:e=>console.log(`[CrossPlugin] ${e}`),getVersion:()=>`Vue${s} + Plugin@1.0.0`}),a.component("AgentAssistant",Me);let n;if(a.directive("color",{bind:(e,t)=>e.style.color=t.value,mounted:(e,t)=>e.style.color=t.value,update:(e,t)=>e.style.color=t.value,updated:(e,t)=>e.style.color=t.value}),i)try{if("undefined"!=typeof require){const{reactive:e}=require("vue");n=e({count:0})}else if("undefined"!=typeof window&&window.Vue){const{reactive:e}=window.Vue;n=e({count:0})}else n={count:0}}catch(e){n={count:0}}else try{n=e.observable({count:0})}catch(e){n={count:0}}ke.state=n}};"undefined"!=typeof window&&window.Vue&&window.Vue.use(ke);export{ke as default};
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).CrossPlugin=t(e.Vue)}(this,function(e){"use strict";function t(e){return e?e.version&&e.version.startsWith?e.version.startsWith("3.")?3:2:e._createVNode||e.constructor&&"App"===e.constructor.name?3:(e.util&&e.set,2):2}const s=new class{constructor(){this.certificate="",this.isAuthenticated=!1}setCertificate(e){this.certificate=e||"",this.isAuthenticated=!!this.certificate,this.certificate?localStorage.setItem("chat_certificate",this.certificate):localStorage.removeItem("chat_certificate")}getCertificate(){return this.certificate||(this.certificate=localStorage.getItem("chat_certificate")||"",this.isAuthenticated=!!this.certificate),this.certificate}clearCertificate(){this.certificate="",this.isAuthenticated=!1,localStorage.removeItem("chat_certificate")}isAuth(){return this.isAuthenticated}},o={certificate:{type:String,required:!0},userName:{type:String,required:!0,default:""},domain:{type:String,default:"https://css.tineco.com"},width:{type:[String,Number],default:400},height:{type:[String,Number],default:550},assistantTitleProp:{type:String,default:"智能助手"},welcomeMessage:{type:String,default:""},showUnreadBadge:{type:Boolean,default:!0},maxImageCount:{type:Number,default:9},maxImageSize:{type:Number,default:5}},a=o.domain.default;function i(e=a){return e.startsWith("http")||(e=`https://${e}`),e.replace(/\/$/,"")}async function n(e,t,o=[]){const a={message:e,userName:t,fileUrls:o};return await async function(e,t,o=""){try{const a={"Content-Type":"application/json"},n=o||s.getCertificate();n&&(a.Certificate=n);const r=`${i()}${e}`,l=await fetch(r,{method:"POST",headers:a,body:JSON.stringify(t)});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const c=await l.json();return"S"===c.code?{success:!0,data:c}:{success:!1,error:c.msg||"请求失败",data:c}}catch(e){return console.error("API调用失败:",e),{success:!1,error:e.message||"网络错误"}}}("/gateway/baseServer/asmApiCoral/asmMaintenance",a)}async function r(e){const t=new FormData;t.append("file",e),t.append("bucket","CSS-01");try{const e=i(),s=await fetch(`${e}/gateway/fileServer/v4/upload/single`,{method:"POST",body:t});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);const o=await s.json();return"S"===o.code&&!0===o.success?{success:!0,data:o.data}:{success:!1,error:o.msg||"上传失败",data:o}}catch(e){return console.error("文件上传失败:",e),{success:!1,error:e.message||"网络错误"}}}const l={user:{viewBox:"0 0 24 24",paths:[{d:"M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z",fill:"currentColor"}]},aiAvatar:{viewBox:"0 0 24 24",paths:[{d:"M12 2C12 2 9 3.5 7 5.5C5 7.5 3.5 10 3.5 10C3.5 10 5 12.5 7 14.5C9 16.5 12 18 12 18C12 18 15 16.5 17 14.5C19 12.5 20.5 10 20.5 10C20.5 10 19 7.5 17 5.5C15 3.5 12 2 12 2Z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"},{d:"M12 4L13 2.5M12 4L11 2.5M16 6L17.5 5M16 6L15 4.5M20 10L21.5 9M20 10L19 11.5M16 14L17.5 15.5M16 14L15 12.5M12 16L13 17.5M12 16L11 17.5M8 14L6.5 15.5M8 14L9 12.5M4 10L2.5 9M4 10L5 11.5M8 6L6.5 5M8 6L9 4.5",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round"},{d:"M9 10H7M17 10H15M12 7V5",stroke:"#60a5fa",strokeWidth:"1.5",strokeLinecap:"round"}],circles:[{cx:"12",cy:"10",r:"2.5",fill:"#60a5fa",stroke:"white",strokeWidth:"1"},{cx:"7",cy:"10",r:"1",fill:"#4ade80"},{cx:"17",cy:"10",r:"1",fill:"#4ade80"},{cx:"12",cy:"5",r:"1",fill:"#fbbf24"}],lines:[{x1:"12",y1:"2",x2:"12",y2:"4",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"12",y1:"16",x2:"12",y2:"18",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"6",y1:"10",x2:"4",y2:"10",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"20",y1:"10",x2:"18",y2:"10",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"}]},close:{viewBox:"0 0 24 24",paths:[{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"}]},minimize:{viewBox:"0 0 24 24",paths:[{d:"M19 13H5V11H19V13Z",fill:"currentColor"}]},send:{viewBox:"0 0 24 24",paths:[{d:"M2 21L23 12L2 3V10L17 12L2 14V21Z",fill:"currentColor"}]},upload:{viewBox:"0 0 24 24",paths:[{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6m4-3h6m0 0v6m0-6L13 13",fill:"currentColor"}]},uploadImage:{viewBox:"0 0 24 24",paths:[{d:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"},{d:"M12 13a3 3 0 100-6 3 3 0 000 6z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}]},aiAssistant:{viewBox:"0 0 24 24",paths:[{d:"M12 6C14.21 6 16 7.79 16 10C16 12.21 14.21 14 12 14C9.79 14 8 12.21 8 10C8 7.79 9.79 6 12 6Z",fill:"currentColor"},{d:"M9 10H7M17 10H15M12 7V5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"},{d:"M12 16C9.33 16 4 17.34 4 20V22H20V20C20 17.34 14.67 16 12 16Z",fill:"currentColor"}],circles:[{cx:"7",cy:"10",r:"1",fill:"#4ade80"},{cx:"17",cy:"10",r:"1",fill:"#4ade80"},{cx:"12",cy:"5",r:"1",fill:"#fbbf24"}]},remove:{viewBox:"0 0 24 24",paths:[{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"}]},prev:{viewBox:"0 0 24 24",paths:[{d:"M15.41 7.41L14 6L8 12L14 18L15.41 16.59L10.83 12L15.41 7.41Z",fill:"currentColor"}]},next:{viewBox:"0 0 24 24",paths:[{d:"M8.59 7.41L10 6L16 12L10 18L8.59 16.59L13.17 12L8.59 7.41Z",fill:"currentColor"}]},zoomIn:{viewBox:"0 0 24 24",paths:[{d:"M12 18a6 6 0 1 0 0-12 6 6 0 0 0 0 12z",fill:"none",stroke:"currentColor",strokeWidth:"2"},{d:"M20 20l-3.5-3.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"},{d:"M12 9v6M9 12h6",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}]},zoomOut:{viewBox:"0 0 24 24",paths:[{d:"M12 16a4 4 0 1 0 0-8 4 4 0 0 0 0 8z",fill:"none",stroke:"currentColor",strokeWidth:"2"},{d:"M19 19l-3-3",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"},{d:"M10 12h4",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}]},fullscreen:{viewBox:"0 0 24 24",paths:[{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}]}};var c={name:"SvgIcon",props:{name:{type:String,required:!0,validator:e=>Object.keys(l).includes(e)},size:{type:[Number,String],default:24}},computed:{iconConfig(){return l[this.name]||l.user},viewBox(){return this.iconConfig.viewBox||"0 0 24 24"},paths(){return this.iconConfig.paths||[]},circles(){return this.iconConfig.circles||[]},lines(){return this.iconConfig.lines||[]}}};const d=["viewBox"];c.render=function(t,s,o,a,i,n){return e.openBlock(),e.createElementBlock("svg",{viewBox:n.viewBox,fill:"none",xmlns:"http://www.w3.org/2000/svg"},[e.createCommentVNode(" 渲染路径 "),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.paths,(t,s)=>(e.openBlock(),e.createElementBlock("path",e.mergeProps({key:`path-${s}`},{ref_for:!0},t),null,16))),128)),e.createCommentVNode(" 渲染圆形 "),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.circles,(t,s)=>(e.openBlock(),e.createElementBlock("circle",e.mergeProps({key:`circle-${s}`},{ref_for:!0},t),null,16))),128)),e.createCommentVNode(" 渲染线条 "),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.lines,(t,s)=>(e.openBlock(),e.createElementBlock("line",e.mergeProps({key:`line-${s}`},{ref_for:!0},t),null,16))),128))],8,d)},c.__file="src/components/AgentAssistant/Icons/SvgIcon.vue";var m={name:"FloatingTrigger",components:{SvgIcon:c},props:{unreadCount:{type:Number,default:0},showBadge:{type:Boolean,default:!0}},data:()=>({isHovered:!1,isDragging:!1,hasDragged:!1,startX:0,startY:0,position:{bottom:30,right:30}}),computed:{triggerStyle(){return{bottom:this.position.bottom+"px",right:this.position.right+"px"}}},methods:{startDrag(e){this.isDragging=!0,this.hasDragged=!1,this.startX=e.clientX,this.startY=e.clientY,document.addEventListener("mousemove",this.onDrag),document.addEventListener("mouseup",this.stopDrag)},onDrag(e){if(!this.isDragging)return;const t=e.clientX-this.startX,s=e.clientY-this.startY;(Math.abs(t)>3||Math.abs(s)>3)&&(this.hasDragged=!0);const o=window.innerWidth,a=window.innerHeight;this.position.right=Math.max(10,Math.min(o-64-10,this.position.right-t)),this.position.bottom=Math.max(10,Math.min(a-64-10,this.position.bottom-s)),this.startX=e.clientX,this.startY=e.clientY},stopDrag(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDrag),document.removeEventListener("mouseup",this.stopDrag)},handleClick(){this.hasDragged||this.$emit("toggle"),this.hasDragged=!1}}};const h={class:"ops-icon-wrapper"},g={key:0,class:"ops-unread-badge"},u={class:"ops-tooltip"};m.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return e.openBlock(),e.createElementBlock("div",{class:"ops-floating-trigger",style:e.normalizeStyle(n.triggerStyle),onMousedown:s[0]||(s[0]=(...e)=>n.startDrag&&n.startDrag(...e)),onClick:s[1]||(s[1]=(...e)=>n.handleClick&&n.handleClick(...e)),onMouseenter:s[2]||(s[2]=e=>i.isHovered=!0),onMouseleave:s[3]||(s[3]=e=>i.isHovered=!1)},[e.createElementVNode("div",h,[e.createVNode(r,{name:"aiAssistant",class:"ops-ai-icon"}),o.unreadCount>0&&o.showBadge?(e.openBlock(),e.createElementBlock("div",g,e.toDisplayString(o.unreadCount),1)):e.createCommentVNode("v-if",!0)]),e.withDirectives(e.createElementVNode("div",u,"智能助手",512),[[e.vShow,i.isHovered]])],36)},m.__scopeId="data-v-415d7a2c",m.__file="src/components/AgentAssistant/FloatingTrigger.vue";var p={name:"ChatModal",components:{SvgIcon:c},props:{visible:{type:Boolean,default:!1},width:{type:[String,Number],default:380},height:{type:[String,Number],default:520},assistantTitle:{type:String,default:"智能助手"},placeholder:{type:String,default:"输入消息..."},maxLength:{type:Number,default:500},disabled:{type:Boolean,default:!1},sending:{type:Boolean,default:!1},initialValue:{type:String,default:""}},data(){return{inputText:this.initialValue,isDragging:!1,isResizing:!1,startX:0,startY:0,startWidth:0,startHeight:0,position:{left:window.innerWidth-parseInt(this.width)-30,top:window.innerHeight-parseInt(this.height)-100}}},computed:{calculatedWidth(){return"number"==typeof this.width?this.width+"px":this.width},calculatedHeight(){return"number"==typeof this.height?this.height+"px":this.height},sendDisabled(){return!this.inputText.trim()&&!this.$slots["image-preview"]||this.disabled||this.sending}},watch:{initialValue(e){this.inputText=e},width(e){this.position.left=window.innerWidth-parseInt(this.calculatedWidth)-30},height(e){this.position.top=window.innerHeight-parseInt(this.calculatedHeight)-100}},methods:{startDrag(e){this.isDragging=!0,this.startX=e.clientX-this.position.left,this.startY=e.clientY-this.position.top,document.addEventListener("mousemove",this.onDrag),document.addEventListener("mouseup",this.stopDrag)},onDrag(e){if(!this.isDragging)return;const t=window.innerWidth,s=window.innerHeight,o=parseInt(this.calculatedWidth),a=parseInt(this.calculatedHeight);let i=e.clientX-this.startX,n=e.clientY-this.startY;i=Math.max(10,Math.min(t-o-10,i)),n=Math.max(10,Math.min(s-a-10,n)),this.position.left=i,this.position.top=n},stopDrag(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDrag),document.removeEventListener("mouseup",this.stopDrag)},startResize(e){e.preventDefault(),this.isResizing=!0,this.startX=e.clientX,this.startY=e.clientY,this.startWidth=parseInt(this.calculatedWidth),this.startHeight=parseInt(this.calculatedHeight),document.addEventListener("mousemove",this.onResize),document.addEventListener("mouseup",this.stopResize)},onResize(e){if(!this.isResizing)return;const t=e.clientX-this.startX,s=e.clientY-this.startY,o=this.startWidth/this.startHeight;let a=this.startWidth+t,i=this.startHeight+s;Math.abs(t)>Math.abs(s)?i=a/o:a=i*o;const n=window.innerWidth-20,r=window.innerHeight-20;a=Math.max(300,Math.min(n,a)),i=Math.max(400,Math.min(r,i)),this.$emit("resize",{width:a,height:i})},stopResize(){this.isResizing=!1,document.removeEventListener("mousemove",this.onResize),document.removeEventListener("mouseup",this.stopResize)},handleSend(){this.sendDisabled||(this.$emit("send",this.inputText),this.inputText="")},focus(){const e=this.$el.querySelector(".message-input");e&&e.focus()},async handlePaste(e){try{const t=e.clipboardData.items;for(let s=0;s<t.length;s++){const o=t[s];if(-1!==o.type.indexOf("image")){e.preventDefault();const t=o.getAsFile();if(t){const e={file:t,name:t.name||`pasted-image-${Date.now()}.png`,size:t.size,url:""},s=new FileReader;return s.onload=t=>{e.url=t.target.result,this.$emit("files-pasted",[e])},void s.readAsDataURL(t)}}}}catch(e){console.error("粘贴处理失败:",e)}}}};const v={class:"ops-chat-container"},f={class:"ops-header-info"},w={class:"ops-avatar"},C={class:"ops-header-text"},I={class:"ops-assistant-name"},k={class:"ops-header-actions"},x={class:"ops-chat-messages",ref:"messagesContainer"},y={class:"ops-chat-input-area"},B={class:"ops-input-container"},b=["placeholder","maxlength","disabled"],M={class:"ops-input-actions"},L={class:"ops-char-count"},V=["disabled"],N={key:1,class:"ops-loading-spinner"};p.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return e.openBlock(),e.createBlock(e.Transition,{name:"ops-slide-fade"},{default:e.withCtx(()=>[o.visible?(e.openBlock(),e.createElementBlock("div",{key:0,class:"ops-chat-modal",style:e.normalizeStyle({width:n.calculatedWidth,height:n.calculatedHeight,left:i.position.left+"px",top:i.position.top+"px"})},[e.createElementVNode("div",v,[e.createCommentVNode(" 头部 "),e.createElementVNode("div",{class:"ops-chat-header",onMousedown:s[2]||(s[2]=(...e)=>n.startDrag&&n.startDrag(...e))},[e.createElementVNode("div",f,[e.createElementVNode("div",w,[e.createVNode(r,{name:"user",class:"ops-avatar-icon"})]),e.createElementVNode("div",C,[e.createElementVNode("h3",I,e.toDisplayString(o.assistantTitle),1),s[9]||(s[9]=e.createElementVNode("span",{class:"ops-status ops-online"},"在线",-1))])]),e.createElementVNode("div",k,[e.createElementVNode("button",{class:"ops-minimize-btn",onClick:s[0]||(s[0]=e.withModifiers(e=>t.$emit("minimize"),["stop"]))},[e.createVNode(r,{name:"minimize",class:"ops-action-icon"})]),e.createElementVNode("button",{class:"ops-close-btn",onClick:s[1]||(s[1]=e.withModifiers(e=>t.$emit("close"),["stop"]))},[e.createVNode(r,{name:"close",class:"ops-action-icon"})])])],32),e.createCommentVNode(" 右下角调整大小手柄 "),e.createElementVNode("div",{class:"ops-resize-handle",onMousedown:s[3]||(s[3]=(...e)=>n.startResize&&n.startResize(...e))},null,32),e.createCommentVNode(" 消息区域 "),e.createElementVNode("div",x,[e.renderSlot(t.$slots,"welcome"),e.renderSlot(t.$slots,"messages")],512),e.createCommentVNode(" 输入区域 "),e.createElementVNode("div",y,[e.renderSlot(t.$slots,"image-preview"),e.createElementVNode("div",B,[e.withDirectives(e.createElementVNode("textarea",{"onUpdate:modelValue":s[4]||(s[4]=e=>i.inputText=e),onKeydown:s[5]||(s[5]=e.withKeys(e.withModifiers((...e)=>n.handleSend&&n.handleSend(...e),["exact","prevent"]),["enter"])),onInput:s[6]||(s[6]=e=>t.$emit("input-change",e)),onPaste:s[7]||(s[7]=(...e)=>n.handlePaste&&n.handlePaste(...e)),placeholder:o.placeholder,class:"ops-message-input",rows:"1",maxlength:o.maxLength,disabled:o.disabled},null,40,b),[[e.vModelText,i.inputText]]),e.createElementVNode("div",M,[e.renderSlot(t.$slots,"upload-button"),e.createElementVNode("span",L,e.toDisplayString(i.inputText.length)+"/"+e.toDisplayString(o.maxLength),1),e.createElementVNode("button",{onClick:s[8]||(s[8]=(...e)=>n.handleSend&&n.handleSend(...e)),class:e.normalizeClass(["ops-send-button",{"ops-loading":o.sending}]),disabled:n.sendDisabled},[e.renderSlot(t.$slots,"send-icon",{},()=>[o.sending?(e.openBlock(),e.createElementBlock("div",N)):(e.openBlock(),e.createBlock(r,{key:0,name:"send",class:"ops-send-icon"}))])],10,V)])])])])],4)):e.createCommentVNode("v-if",!0)]),_:3})},p.__scopeId="data-v-36f7e58f",p.__file="src/components/AgentAssistant/ChatModal.vue";var E={name:"WelcomeMessage",components:{SvgIcon:c},props:{title:{type:String,default:"您好!我是您的智能助手"},message:{type:String,default:"您好!我是智能助手,请问有什么可以帮助您的吗?"}}};const S={class:"ops-welcome-message"},z={class:"ops-welcome-text"};E.render=function(t,s,o,a,i,n){return e.openBlock(),e.createElementBlock("div",S,[s[0]||(s[0]=e.createElementVNode("div",{class:"ops-welcome-avatar"},[e.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[e.createElementVNode("path",{d:"M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z",fill:"currentColor"})])],-1)),e.createElementVNode("div",z,[e.createElementVNode("h4",null,e.toDisplayString(o.title),1),e.createElementVNode("p",null,e.toDisplayString(o.message),1)])])},E.__scopeId="data-v-2f1ef74a",E.__file="src/components/AgentAssistant/WelcomeMessage.vue";var $={name:"MessageImages",props:{images:{type:Array,default:()=>[]}},methods:{previewImage(e){this.$emit("preview",e)}}};const D={class:"ops-message-images"},_=["src","alt","onClick"],P={key:0,class:"ops-upload-error-overlay"};$.render=function(t,s,o,a,i,n){return e.openBlock(),e.createElementBlock("div",D,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.images,(t,o)=>(e.openBlock(),e.createElementBlock("div",{key:o,class:e.normalizeClass(["ops-message-image-item",{"ops-upload-failed":!1===t.uploadSuccess}])},[e.createElementVNode("img",{src:t.url,alt:t.name,class:"ops-message-image",onClick:e=>n.previewImage(t.url)},null,8,_),e.createCommentVNode(" 上传失败的提示 "),!1===t.uploadSuccess?(e.openBlock(),e.createElementBlock("div",P,[...s[0]||(s[0]=[e.createElementVNode("span",{class:"ops-error-text"},"上传失败",-1)])])):e.createCommentVNode("v-if",!0)],2))),128))])},$.__scopeId="data-v-c687e28e",$.__file="src/components/AgentAssistant/MessageImages.vue";var A={name:"MessageBubble",components:{MessageImages:$,SvgIcon:c},props:{message:{type:Object,required:!0,validator:e=>e.sender&&e.timestamp&&void 0!==e.content}},methods:{handleImagePreview(e){this.$emit("preview-image",e)}}};const T={key:0,class:"ops-message-avatar ops-assistant-avatar"},W={class:"ops-message-avatar ops-user-avatar"},H={class:"ops-message-content"},F={class:"ops-message-text"};A.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon"),l=e.resolveComponent("MessageImages");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["ops-message-bubble","ops-"+o.message.sender])},[e.createCommentVNode(" 助手头像 "),"assistant"===o.message.sender?(e.openBlock(),e.createElementBlock("div",T,[e.createVNode(r,{name:"user"})])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createCommentVNode(" 用户头像 "),e.createElementVNode("div",W,[e.createVNode(r,{name:"user"})])],2112)),e.createElementVNode("div",H,[e.createElementVNode("div",F,e.toDisplayString(o.message.content),1),e.createCommentVNode(" 图片展示 "),o.message.images&&o.message.images.length>0?(e.openBlock(),e.createBlock(l,{key:0,images:o.message.images,onPreview:n.handleImagePreview},null,8,["images","onPreview"])):e.createCommentVNode("v-if",!0)])],2)},A.__scopeId="data-v-0927d266",A.__file="src/components/AgentAssistant/MessageBubble.vue";var R={name:"MessageList",components:{MessageBubble:A},props:{messages:{type:Array,default:()=>[]}},methods:{handleImagePreview(e){this.$emit("preview-image",e)},scrollToBottom(){this.$nextTick(()=>{const e=this.$refs.messageList;e&&(e.scrollTop=e.scrollHeight)})}}};const Z={class:"ops-message-list",ref:"messageList"};R.render=function(t,s,o,a,i,n){const r=e.resolveComponent("MessageBubble");return e.openBlock(),e.createElementBlock("div",Z,[e.createVNode(e.TransitionGroup,{name:"ops-message-fade",tag:"div",class:"ops-transition-group"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.messages,(t,s)=>(e.openBlock(),e.createBlock(r,{key:t.id||s,message:t,onPreviewImage:n.handleImagePreview},null,8,["message","onPreviewImage"]))),128))]),_:1})],512)},R.__scopeId="data-v-4f7fdfc2",R.__file="src/components/AgentAssistant/MessageList.vue";var U={name:"ImagePreview",components:{SvgIcon:c},props:{images:{type:Array,default:()=>[]},disabled:{type:Boolean,default:!1}},methods:{removeImage(e){this.$emit("remove",e)}}};const X={key:0,class:"ops-image-preview-container"},Y=["src","alt"],O=["onClick","disabled"];U.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return o.images.length>0?(e.openBlock(),e.createElementBlock("div",X,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.images,(t,s)=>(e.openBlock(),e.createElementBlock("div",{key:s,class:"ops-image-preview-item"},[e.createElementVNode("img",{src:t.url,alt:t.name,class:"ops-preview-image"},null,8,Y),e.createElementVNode("button",{class:"ops-remove-image-btn",onClick:e=>n.removeImage(s),type:"button",disabled:o.disabled},[e.createVNode(r,{name:"close",class:"ops-remove-icon"})],8,O)]))),128))])):e.createCommentVNode("v-if",!0)},U.__scopeId="data-v-28f9b383",U.__file="src/components/AgentAssistant/ImagePreview.vue";var q={name:"UploadButton",components:{SvgIcon:c},props:{disabled:{type:Boolean,default:!1},isLoading:{type:Boolean,default:!1},maxImageCount:{type:Number,default:3},maxImageSize:{type:Number,default:5},currentImageCount:{type:Number,default:0}},methods:{handleFileChange(e){const t=Array.from(e.target.files);if(0===t.length)return;const s=this.maxImageCount-this.currentImageCount;if(s<=0)return void this.$emit("error",`最多只能上传${this.maxImageCount}张图片`);const o=t.slice(0,s),a=[];for(let e of o){if(!e.type.startsWith("image/")){this.$emit("error","请选择图片文件");continue}const t=1024*this.maxImageSize*1024;e.size>t?this.$emit("error",`图片 ${e.name} 太大,请选择小于${this.maxImageSize}MB的图片`):a.push(e)}const i=a.slice(0,s);i.length>0&&this.processFiles(i),e.target.value=""},processFiles(e){const t=[];e.forEach(e=>{t.push({url:"",name:e.name,file:e,size:e.size})}),this.$emit("files-selected",t)},reset(){this.$refs.fileInput&&(this.$refs.fileInput.value="")}}};const j=["multiple","disabled"];q.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return e.openBlock(),e.createElementBlock("label",{class:e.normalizeClass(["ops-upload-button",{"ops-disabled":o.disabled||o.isLoading}])},[e.createElementVNode("input",{type:"file",accept:"image/*",multiple:o.maxImageCount>1,onChange:s[0]||(s[0]=(...e)=>n.handleFileChange&&n.handleFileChange(...e)),ref:"fileInput",disabled:o.disabled||o.isLoading,class:"ops-file-input"},null,40,j),e.createVNode(r,{name:"uploadImage",class:"ops-upload-icon"})],2)},q.__scopeId="data-v-724f2729",q.__file="src/components/AgentAssistant/UploadButton.vue";var K={name:"ImagePreviewModal",components:{SvgIcon:c},props:{visible:{type:Boolean,default:!1},images:{type:Array,default:()=>[]},initialIndex:{type:Number,default:0}},data(){return{currentIndex:this.initialIndex,scale:1,minScale:.1,maxScale:5,step:.1}},computed:{currentImageUrl(){if(0===this.images.length)return"";const e=this.images[this.currentIndex];return e?.url||""},imageName(){if(0===this.images.length)return"";const e=this.images[this.currentIndex];return e?.name||"未命名图片"},showPrevButton(){return this.currentIndex>0},showNextButton(){return this.currentIndex<this.images.length-1},canZoomIn(){return this.scale<this.maxScale},canZoomOut(){return this.scale>this.minScale}},watch:{visible(e){e?(this.currentIndex=this.initialIndex,document.body.style.overflow="hidden"):document.body.style.overflow=""},initialIndex(e){this.currentIndex=e}},methods:{closeModal(){this.$emit("close")},handleBackdropClick(){this.closeModal()},prevImage(){this.currentIndex>0&&(this.currentIndex--,this.$emit("image-change",this.currentIndex))},nextImage(){this.currentIndex<this.images.length-1&&(this.currentIndex++,this.$emit("image-change",this.currentIndex))},selectImage(e){e>=0&&e<this.images.length&&(this.currentIndex=e,this.$emit("image-change",this.currentIndex))},onImageLoad(){this.$emit("image-load",{index:this.currentIndex,url:this.currentImageUrl})},onImageError(){this.$emit("image-error",{index:this.currentIndex,url:this.currentImageUrl})},zoomIn(){this.canZoomIn&&(this.scale=Math.min(this.scale+this.step,this.maxScale))},zoomOut(){this.canZoomOut&&(this.scale=Math.max(this.scale-this.step,this.minScale))},resetZoom(){this.scale=1},fitScreen(){this.scale=1}}};const G={class:"ops-image-container"},J=["src","alt"],Q={key:0,class:"ops-image-counter"},ee={class:"ops-zoom-controls"},te=["disabled"],se=["disabled"];K.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return e.openBlock(),e.createBlock(e.Transition,{name:"ops-modal-fade"},{default:e.withCtx(()=>[o.visible?(e.openBlock(),e.createElementBlock("div",{key:0,class:"ops-image-preview-overlay",onClick:s[9]||(s[9]=(...e)=>n.handleBackdropClick&&n.handleBackdropClick(...e))},[e.createCommentVNode(" 关闭按钮 "),e.createElementVNode("button",{class:"ops-close-btn",onClick:s[0]||(s[0]=(...e)=>n.closeModal&&n.closeModal(...e))},[e.createVNode(r,{name:"close",class:"ops-close-icon"})]),e.createCommentVNode(" 图片显示区域 "),e.createElementVNode("div",G,[o.images.length>1&&n.showPrevButton?(e.openBlock(),e.createElementBlock("button",{key:0,class:"ops-nav-btn ops-prev-btn",onClick:s[1]||(s[1]=e.withModifiers((...e)=>n.prevImage&&n.prevImage(...e),["stop"]))},[e.createVNode(r,{name:"prev",class:"ops-nav-icon"})])):e.createCommentVNode("v-if",!0),e.createElementVNode("img",{src:n.currentImageUrl,alt:n.imageName,class:"ops-preview-image",onLoad:s[2]||(s[2]=(...e)=>n.onImageLoad&&n.onImageLoad(...e)),onError:s[3]||(s[3]=(...e)=>n.onImageError&&n.onImageError(...e))},null,40,J),o.images.length>1&&n.showNextButton?(e.openBlock(),e.createElementBlock("button",{key:1,class:"ops-nav-btn ops-next-btn",onClick:s[4]||(s[4]=e.withModifiers((...e)=>n.nextImage&&n.nextImage(...e),["stop"]))},[e.createVNode(r,{name:"next",class:"ops-nav-icon"})])):e.createCommentVNode("v-if",!0)]),e.createCommentVNode(" 图片计数器 "),o.images.length>1?(e.openBlock(),e.createElementBlock("div",Q,e.toDisplayString(i.currentIndex+1)+" / "+e.toDisplayString(o.images.length),1)):e.createCommentVNode("v-if",!0),e.createCommentVNode(" 缩放控制按钮 "),e.createElementVNode("div",ee,[e.createElementVNode("button",{class:"ops-zoom-btn",disabled:!n.canZoomOut,onClick:s[5]||(s[5]=e.withModifiers((...e)=>n.zoomOut&&n.zoomOut(...e),["stop"])),title:"缩小"},[e.createVNode(r,{name:"zoomOut",class:"ops-zoom-icon"})],8,te),e.createElementVNode("button",{class:"ops-zoom-btn",onClick:s[6]||(s[6]=e.withModifiers((...e)=>n.resetZoom&&n.resetZoom(...e),["stop"])),title:"1:1"},e.toDisplayString(Math.round(100*i.scale))+"% ",1),e.createElementVNode("button",{class:"ops-zoom-btn",disabled:!n.canZoomIn,onClick:s[7]||(s[7]=e.withModifiers((...e)=>n.zoomIn&&n.zoomIn(...e),["stop"])),title:"放大"},[e.createVNode(r,{name:"zoomIn",class:"ops-zoom-icon"})],8,se),e.createElementVNode("button",{class:"ops-zoom-btn",onClick:s[8]||(s[8]=e.withModifiers((...e)=>n.fitScreen&&n.fitScreen(...e),["stop"])),title:"适应屏幕"},[e.createVNode(r,{name:"fullscreen",class:"ops-zoom-icon"})])])])):e.createCommentVNode("v-if",!0)]),_:1})},K.__scopeId="data-v-76b5889a",K.__file="src/components/AgentAssistant/ImagePreviewModal.vue";var oe={name:"AgentAssistant",components:{FloatingTrigger:m,ChatModal:p,WelcomeMessage:E,MessageList:R,ImagePreview:U,UploadButton:q,ImagePreviewModal:K},props:o,data(){return{showChatBox:!1,inputText:"",messages:[],isLoading:!1,unreadCount:0,isMinimized:!1,previewImages:[],uploadedImages:[],modalWidth:this.width,modalHeight:this.height,showImagePreview:!1,previewImagesData:[],previewImageIndex:0}},watch:{certificate:{handler(e){e&&s.setCertificate(e)},immediate:!0},width:{handler(e){this.modalWidth=e},immediate:!0},height:{handler(e){this.modalHeight=e},immediate:!0}},computed:{welcomeTitle:()=>"您好!我是您的智能助手",welcomeContent(){return this.welcomeMessage||"您好!我是智能助手,请问有什么可以帮助您的吗?"},assistantTitle(){return this.assistantTitleProp||"智能助手"}},methods:{toggleChatBox(){this.showChatBox=!this.showChatBox,this.isMinimized=!1,this.showChatBox&&(this.unreadCount=0,0===this.messages.length&&this.addMessage("assistant",this.welcomeContent),this.$nextTick(()=>{this.focusInput()}))},handleResize(e){this.modalWidth=e.width,this.modalHeight=e.height},minimizeChat(){this.isMinimized=!0,this.showChatBox=!1},handleSendMessage(e){if(!e.trim()&&0===this.previewImages.length||this.isLoading)return;const t=[...this.previewImages],s=e||"";this.addMessage("user",s,t),this.isLoading=!0;const o=this.addMessage("assistant","正在深度思考您的问题...",[]);this.callApi(e,t,o.id),this.inputText="",this.clearImages()},async callApi(e,t=null,s=null){try{const o=(t||this.previewImages).filter(e=>!0===e.uploadSuccess).map(e=>e.url),a=await n(e,this.userName,o);if(a.success){const e=a.data.data.choices[0].message.content;s?this.updateMessage(s,e):this.addMessage("assistant",e)}else s?this.updateMessage(s,a.error||"服务异常,请稍后再试。"):this.addMessage("assistant",a.error||"服务异常,请稍后再试。")}catch(e){console.error("API调用失败:",e),s?this.updateMessage(s,"网络错误或服务异常,请稍后再试。"):this.addMessage("assistant","网络错误或服务异常,请稍后再试。")}finally{this.isLoading=!1}},updateMessage(e,t){const s=this.messages.findIndex(t=>t.id===e);-1!==s&&(this.messages[s].content=t,this.messages[s].timestamp=new Date)},addMessage(e,t,s=[]){const o={id:Date.now()+Math.random(),sender:e,content:t||"",images:s,timestamp:new Date};return this.messages.push(o),"assistant"!==e||this.showChatBox||this.unreadCount++,this.$nextTick(()=>{this.$refs.messageList&&this.$refs.messageList.scrollToBottom()}),o},scrollToBottom(){this.$refs.chatModal?.$refs.messagesContainer?.scrollTo({top:this.$refs.chatModal.$refs.messagesContainer.scrollHeight,behavior:"smooth"})},focusInput(){this.$refs.chatModal?.focus()},handleInput(){this.autoResizeTextarea()},autoResizeTextarea(){},async handleFilesSelected(e){const t=this.maxImageCount-this.previewImages.length;if(t<=0)return void this.handleUploadError(`最多只能上传${this.maxImageCount}张图片`);const s=e.slice(0,t);for(let e of s){if(this.previewImages.length>=this.maxImageCount){this.handleUploadError(`最多只能上传${this.maxImageCount}张图片`);break}try{this.isLoading=!0;const t=await r(e.file);if(t.success){const s={url:t.data.accessPath,name:e.name,size:e.size,uploadSuccess:!0};this.previewImages.push(s)}else{const s={url:e.url,name:e.name,size:e.size,uploadSuccess:!1,error:t.error};this.previewImages.push(s),this.handleUploadError(`图片 ${e.name} 上传失败: ${t.error}`)}}catch(t){console.error("文件上传异常:",t);const s={url:e.url,name:e.name,size:e.size,uploadSuccess:!1,error:"上传异常"};this.previewImages.push(s),this.handleUploadError(`图片 ${e.name} 上传异常: ${t.message}`)}finally{this.isLoading=!1}}},handleUploadError(e){alert(e)},removeImage(e){this.previewImages.splice(e,1)},clearImages(){this.previewImages=[],this.uploadedImages=[],this.$refs.uploadButton&&this.$refs.uploadButton.reset()},previewImage(e){const t=[];this.messages.forEach(e=>{e.images&&e.images.length>0&&e.images.forEach((s,o)=>{t.push({url:s.url,name:s.name||`图片_${t.length+1}`,messageId:e.id,imageIndex:o})})});const s=t.findIndex(t=>t.url===e);-1!==s&&(this.previewImagesData=t,this.previewImageIndex=s,this.showImagePreview=!0)},closeImagePreview(){this.showImagePreview=!1,this.previewImagesData=[],this.previewImageIndex=0},handleImageChange(e){this.previewImageIndex=e},handleImageLoad(e){console.log("图片加载完成:",e)},handleImageError(e){console.error("图片加载失败:",e)}}};const ae={class:"agent-assistant"};oe.render=function(t,s,o,a,i,n){const r=e.resolveComponent("FloatingTrigger"),l=e.resolveComponent("WelcomeMessage"),c=e.resolveComponent("MessageList"),d=e.resolveComponent("ImagePreview"),m=e.resolveComponent("UploadButton"),h=e.resolveComponent("ChatModal"),g=e.resolveComponent("ImagePreviewModal");return e.openBlock(),e.createElementBlock("div",ae,[e.createCommentVNode(" 浮动触发器 "),i.showChatBox?e.createCommentVNode("v-if",!0):(e.openBlock(),e.createBlock(r,{key:0,"unread-count":i.unreadCount,"show-badge":t.showUnreadBadge,onToggle:n.toggleChatBox},null,8,["unread-count","show-badge","onToggle"])),e.createCommentVNode(" 聊天弹窗 "),e.createVNode(h,{visible:i.showChatBox,width:i.modalWidth,height:i.modalHeight,"assistant-title":n.assistantTitle,sending:i.isLoading,"initial-value":i.inputText,placeholder:"输入消息...","max-length":500,disabled:i.isLoading,onClose:n.toggleChatBox,onMinimize:n.minimizeChat,onSend:n.handleSendMessage,onInputChange:n.handleInput,onFilesPasted:n.handleFilesSelected,onResize:n.handleResize,ref:"chatModal"},{welcome:e.withCtx(()=>[0===i.messages.length?(e.openBlock(),e.createBlock(l,{key:0,title:n.welcomeTitle,message:n.welcomeContent},null,8,["title","message"])):e.createCommentVNode("v-if",!0)]),messages:e.withCtx(()=>[e.createVNode(c,{messages:i.messages,onPreviewImage:n.previewImage,ref:"messageList"},null,8,["messages","onPreviewImage"])]),"image-preview":e.withCtx(()=>[e.createVNode(d,{images:i.previewImages,disabled:i.isLoading,onRemove:n.removeImage},null,8,["images","disabled","onRemove"])]),"upload-button":e.withCtx(()=>[e.createVNode(m,{disabled:i.isLoading,"is-loading":i.isLoading,"max-image-count":t.maxImageCount,"max-image-size":t.maxImageSize,"current-image-count":i.previewImages.length,onFilesSelected:n.handleFilesSelected,onError:n.handleUploadError,ref:"uploadButton"},null,8,["disabled","is-loading","max-image-count","max-image-size","current-image-count","onFilesSelected","onError"])]),_:1},8,["visible","width","height","assistant-title","sending","initial-value","disabled","onClose","onMinimize","onSend","onInputChange","onFilesPasted","onResize"]),e.createCommentVNode(" 图片预览模态框 "),e.createVNode(g,{visible:i.showImagePreview,images:i.previewImagesData,"initial-index":i.previewImageIndex,onClose:n.closeImagePreview,onImageChange:n.handleImageChange,onImageLoad:n.handleImageLoad,onImageError:n.handleImageError},null,8,["visible","images","initial-index","onClose","onImageChange","onImageLoad","onImageError"])])},oe.__scopeId="data-v-5a317acc",oe.__file="src/components/AgentAssistant/index.vue";const ie={install(e,s={}){const o=t(e),a=3===o,i=e;!function(e,s,o){3===t(e)?e.config.globalProperties[s]=o:e.prototype[s]=o}(e,"$myPlugin",{log:e=>console.log(`[CrossPlugin] ${e}`),getVersion:()=>`Vue${o} + Plugin@1.0.0`}),i.component("AgentAssistant",oe);let n;if(i.directive("color",{bind:(e,t)=>e.style.color=t.value,mounted:(e,t)=>e.style.color=t.value,update:(e,t)=>e.style.color=t.value,updated:(e,t)=>e.style.color=t.value}),a)try{if("undefined"!=typeof require){const{reactive:e}=require("vue");n=e({count:0})}else if("undefined"!=typeof window&&window.Vue){const{reactive:e}=window.Vue;n=e({count:0})}else n={count:0}}catch(e){n={count:0}}else try{n=e.observable({count:0})}catch(e){n={count:0}}ie.state=n}};return"undefined"!=typeof window&&window.Vue&&window.Vue.use(ie),ie});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).CrossPlugin=t(e.Vue)}(this,function(e){"use strict";function t(e){return e?e.version&&e.version.startsWith?e.version.startsWith("3.")?3:2:e._createVNode||e.constructor&&"App"===e.constructor.name?3:(e.util&&e.set,2):2}const s=new class{constructor(){this.certificate="",this.isAuthenticated=!1}setCertificate(e){this.certificate=e||"",this.isAuthenticated=!!this.certificate,this.certificate?localStorage.setItem("chat_certificate",this.certificate):localStorage.removeItem("chat_certificate")}getCertificate(){return this.certificate||(this.certificate=localStorage.getItem("chat_certificate")||"",this.isAuthenticated=!!this.certificate),this.certificate}clearCertificate(){this.certificate="",this.isAuthenticated=!1,localStorage.removeItem("chat_certificate")}isAuth(){return this.isAuthenticated}},o={certificate:{type:String,required:!0},userName:{type:String,required:!0,default:""},domain:{type:String,default:"https://css.tineco.com"},width:{type:[String,Number],default:400},height:{type:[String,Number],default:550},assistantTitleProp:{type:String,default:"智能助手"},welcomeMessage:{type:String,default:""},showUnreadBadge:{type:Boolean,default:!0},maxImageCount:{type:Number,default:9},maxImageSize:{type:Number,default:5}},a=o.domain.default;function i(e=a){return e.startsWith("http")||(e=`https://${e}`),e.replace(/\/$/,"")}async function n(e,t,o=[],a){const n={message:e,userName:t,fileUrls:o};return await async function(e,t,o="",a=""){try{const n={"Content-Type":"application/json"},r=a||s.getCertificate();r&&(n.Certificate=r);const l=`${i(o)}${e}`,c=await fetch(l,{method:"POST",headers:n,body:JSON.stringify(t)});if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);const d=await c.json();return"S"===d.code?{success:!0,data:d}:{success:!1,error:d.msg||"请求失败",data:d}}catch(e){return console.error("API调用失败:",e),{success:!1,error:e.message||"网络错误"}}}("/gateway/baseServer/asmApiCoral/asmMaintenance",n,a)}async function r(e,t){const s=new FormData;s.append("file",e),s.append("bucket","CSS-01");try{const e=i(t),o=await fetch(`${e}/gateway/fileServer/v4/upload/single`,{method:"POST",body:s});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const a=await o.json();return"S"===a.code&&!0===a.success?{success:!0,data:a.data}:{success:!1,error:a.msg||"上传失败",data:a}}catch(e){return console.error("文件上传失败:",e),{success:!1,error:e.message||"网络错误"}}}const l={user:{viewBox:"0 0 24 24",paths:[{d:"M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z",fill:"currentColor"}]},aiAvatar:{viewBox:"0 0 24 24",paths:[{d:"M12 2C12 2 9 3.5 7 5.5C5 7.5 3.5 10 3.5 10C3.5 10 5 12.5 7 14.5C9 16.5 12 18 12 18C12 18 15 16.5 17 14.5C19 12.5 20.5 10 20.5 10C20.5 10 19 7.5 17 5.5C15 3.5 12 2 12 2Z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"},{d:"M12 4L13 2.5M12 4L11 2.5M16 6L17.5 5M16 6L15 4.5M20 10L21.5 9M20 10L19 11.5M16 14L17.5 15.5M16 14L15 12.5M12 16L13 17.5M12 16L11 17.5M8 14L6.5 15.5M8 14L9 12.5M4 10L2.5 9M4 10L5 11.5M8 6L6.5 5M8 6L9 4.5",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round"},{d:"M9 10H7M17 10H15M12 7V5",stroke:"#60a5fa",strokeWidth:"1.5",strokeLinecap:"round"}],circles:[{cx:"12",cy:"10",r:"2.5",fill:"#60a5fa",stroke:"white",strokeWidth:"1"},{cx:"7",cy:"10",r:"1",fill:"#4ade80"},{cx:"17",cy:"10",r:"1",fill:"#4ade80"},{cx:"12",cy:"5",r:"1",fill:"#fbbf24"}],lines:[{x1:"12",y1:"2",x2:"12",y2:"4",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"12",y1:"16",x2:"12",y2:"18",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"6",y1:"10",x2:"4",y2:"10",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"},{x1:"20",y1:"10",x2:"18",y2:"10",stroke:"#fbbf24",strokeWidth:"1",strokeLinecap:"round",opacity:"0.7"}]},close:{viewBox:"0 0 24 24",paths:[{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"}]},minimize:{viewBox:"0 0 24 24",paths:[{d:"M19 13H5V11H19V13Z",fill:"currentColor"}]},send:{viewBox:"0 0 24 24",paths:[{d:"M2 21L23 12L2 3V10L17 12L2 14V21Z",fill:"currentColor"}]},upload:{viewBox:"0 0 24 24",paths:[{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6m4-3h6m0 0v6m0-6L13 13",fill:"currentColor"}]},uploadImage:{viewBox:"0 0 24 24",paths:[{d:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"},{d:"M12 13a3 3 0 100-6 3 3 0 000 6z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}]},aiAssistant:{viewBox:"0 0 24 24",paths:[{d:"M12 6C14.21 6 16 7.79 16 10C16 12.21 14.21 14 12 14C9.79 14 8 12.21 8 10C8 7.79 9.79 6 12 6Z",fill:"currentColor"},{d:"M9 10H7M17 10H15M12 7V5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"},{d:"M12 16C9.33 16 4 17.34 4 20V22H20V20C20 17.34 14.67 16 12 16Z",fill:"currentColor"}],circles:[{cx:"7",cy:"10",r:"1",fill:"#4ade80"},{cx:"17",cy:"10",r:"1",fill:"#4ade80"},{cx:"12",cy:"5",r:"1",fill:"#fbbf24"}]},remove:{viewBox:"0 0 24 24",paths:[{d:"M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",fill:"currentColor"}]},prev:{viewBox:"0 0 24 24",paths:[{d:"M15.41 7.41L14 6L8 12L14 18L15.41 16.59L10.83 12L15.41 7.41Z",fill:"currentColor"}]},next:{viewBox:"0 0 24 24",paths:[{d:"M8.59 7.41L10 6L16 12L10 18L8.59 16.59L13.17 12L8.59 7.41Z",fill:"currentColor"}]},zoomIn:{viewBox:"0 0 24 24",paths:[{d:"M12 18a6 6 0 1 0 0-12 6 6 0 0 0 0 12z",fill:"none",stroke:"currentColor",strokeWidth:"2"},{d:"M20 20l-3.5-3.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"},{d:"M12 9v6M9 12h6",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}]},zoomOut:{viewBox:"0 0 24 24",paths:[{d:"M12 16a4 4 0 1 0 0-8 4 4 0 0 0 0 8z",fill:"none",stroke:"currentColor",strokeWidth:"2"},{d:"M19 19l-3-3",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"},{d:"M10 12h4",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"}]},fullscreen:{viewBox:"0 0 24 24",paths:[{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}]}};var c={name:"SvgIcon",props:{name:{type:String,required:!0,validator:e=>Object.keys(l).includes(e)},size:{type:[Number,String],default:24}},computed:{iconConfig(){return l[this.name]||l.user},viewBox(){return this.iconConfig.viewBox||"0 0 24 24"},paths(){return this.iconConfig.paths||[]},circles(){return this.iconConfig.circles||[]},lines(){return this.iconConfig.lines||[]}}};const d=["viewBox"];c.render=function(t,s,o,a,i,n){return e.openBlock(),e.createElementBlock("svg",{viewBox:n.viewBox,fill:"none",xmlns:"http://www.w3.org/2000/svg"},[e.createCommentVNode(" 渲染路径 "),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.paths,(t,s)=>(e.openBlock(),e.createElementBlock("path",e.mergeProps({key:`path-${s}`},{ref_for:!0},t),null,16))),128)),e.createCommentVNode(" 渲染圆形 "),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.circles,(t,s)=>(e.openBlock(),e.createElementBlock("circle",e.mergeProps({key:`circle-${s}`},{ref_for:!0},t),null,16))),128)),e.createCommentVNode(" 渲染线条 "),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.lines,(t,s)=>(e.openBlock(),e.createElementBlock("line",e.mergeProps({key:`line-${s}`},{ref_for:!0},t),null,16))),128))],8,d)},c.__file="src/components/AgentAssistant/Icons/SvgIcon.vue";var m={name:"FloatingTrigger",components:{SvgIcon:c},props:{unreadCount:{type:Number,default:0},showBadge:{type:Boolean,default:!0}},data:()=>({isHovered:!1,isDragging:!1,hasDragged:!1,startX:0,startY:0,position:{bottom:30,right:30}}),computed:{triggerStyle(){return{bottom:this.position.bottom+"px",right:this.position.right+"px"}}},methods:{startDrag(e){this.isDragging=!0,this.hasDragged=!1,this.startX=e.clientX,this.startY=e.clientY,document.addEventListener("mousemove",this.onDrag),document.addEventListener("mouseup",this.stopDrag)},onDrag(e){if(!this.isDragging)return;const t=e.clientX-this.startX,s=e.clientY-this.startY;(Math.abs(t)>3||Math.abs(s)>3)&&(this.hasDragged=!0);const o=window.innerWidth,a=window.innerHeight;this.position.right=Math.max(10,Math.min(o-64-10,this.position.right-t)),this.position.bottom=Math.max(10,Math.min(a-64-10,this.position.bottom-s)),this.startX=e.clientX,this.startY=e.clientY},stopDrag(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDrag),document.removeEventListener("mouseup",this.stopDrag)},handleClick(){this.hasDragged||this.$emit("toggle"),this.hasDragged=!1}}};const h={class:"ops-icon-wrapper"},g={key:0,class:"ops-unread-badge"},u={class:"ops-tooltip"};m.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return e.openBlock(),e.createElementBlock("div",{class:"ops-floating-trigger",style:e.normalizeStyle(n.triggerStyle),onMousedown:s[0]||(s[0]=(...e)=>n.startDrag&&n.startDrag(...e)),onClick:s[1]||(s[1]=(...e)=>n.handleClick&&n.handleClick(...e)),onMouseenter:s[2]||(s[2]=e=>i.isHovered=!0),onMouseleave:s[3]||(s[3]=e=>i.isHovered=!1)},[e.createElementVNode("div",h,[e.createVNode(r,{name:"aiAssistant",class:"ops-ai-icon"}),o.unreadCount>0&&o.showBadge?(e.openBlock(),e.createElementBlock("div",g,e.toDisplayString(o.unreadCount),1)):e.createCommentVNode("v-if",!0)]),e.withDirectives(e.createElementVNode("div",u,"智能助手",512),[[e.vShow,i.isHovered]])],36)},m.__scopeId="data-v-415d7a2c",m.__file="src/components/AgentAssistant/FloatingTrigger.vue";var p={name:"ChatModal",components:{SvgIcon:c},props:{visible:{type:Boolean,default:!1},width:{type:[String,Number],default:380},height:{type:[String,Number],default:520},assistantTitle:{type:String,default:"智能助手"},placeholder:{type:String,default:"输入消息..."},maxLength:{type:Number,default:500},disabled:{type:Boolean,default:!1},sending:{type:Boolean,default:!1},initialValue:{type:String,default:""}},data(){return{inputText:this.initialValue,isDragging:!1,isResizing:!1,startX:0,startY:0,startWidth:0,startHeight:0,position:{left:window.innerWidth-parseInt(this.width)-30,top:window.innerHeight-parseInt(this.height)-100}}},computed:{calculatedWidth(){return"number"==typeof this.width?this.width+"px":this.width},calculatedHeight(){return"number"==typeof this.height?this.height+"px":this.height},sendDisabled(){return!this.inputText.trim()&&!this.$slots["image-preview"]||this.disabled||this.sending}},watch:{initialValue(e){this.inputText=e},width(e){this.position.left=window.innerWidth-parseInt(this.calculatedWidth)-30},height(e){this.position.top=window.innerHeight-parseInt(this.calculatedHeight)-100}},methods:{startDrag(e){this.isDragging=!0,this.startX=e.clientX-this.position.left,this.startY=e.clientY-this.position.top,document.addEventListener("mousemove",this.onDrag),document.addEventListener("mouseup",this.stopDrag)},onDrag(e){if(!this.isDragging)return;const t=window.innerWidth,s=window.innerHeight,o=parseInt(this.calculatedWidth),a=parseInt(this.calculatedHeight);let i=e.clientX-this.startX,n=e.clientY-this.startY;i=Math.max(10,Math.min(t-o-10,i)),n=Math.max(10,Math.min(s-a-10,n)),this.position.left=i,this.position.top=n},stopDrag(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDrag),document.removeEventListener("mouseup",this.stopDrag)},startResize(e){e.preventDefault(),this.isResizing=!0,this.startX=e.clientX,this.startY=e.clientY,this.startWidth=parseInt(this.calculatedWidth),this.startHeight=parseInt(this.calculatedHeight),document.addEventListener("mousemove",this.onResize),document.addEventListener("mouseup",this.stopResize)},onResize(e){if(!this.isResizing)return;const t=e.clientX-this.startX,s=e.clientY-this.startY,o=this.startWidth/this.startHeight;let a=this.startWidth+t,i=this.startHeight+s;Math.abs(t)>Math.abs(s)?i=a/o:a=i*o;const n=window.innerWidth-20,r=window.innerHeight-20;a=Math.max(300,Math.min(n,a)),i=Math.max(400,Math.min(r,i)),this.$emit("resize",{width:a,height:i})},stopResize(){this.isResizing=!1,document.removeEventListener("mousemove",this.onResize),document.removeEventListener("mouseup",this.stopResize)},handleSend(){this.sendDisabled||(this.$emit("send",this.inputText),this.inputText="")},focus(){const e=this.$el.querySelector(".message-input");e&&e.focus()},async handlePaste(e){try{const t=e.clipboardData.items;for(let s=0;s<t.length;s++){const o=t[s];if(-1!==o.type.indexOf("image")){e.preventDefault();const t=o.getAsFile();if(t){const e={file:t,name:t.name||`pasted-image-${Date.now()}.png`,size:t.size,url:""},s=new FileReader;return s.onload=t=>{e.url=t.target.result,this.$emit("files-pasted",[e])},void s.readAsDataURL(t)}}}}catch(e){console.error("粘贴处理失败:",e)}}}};const v={class:"ops-chat-container"},f={class:"ops-header-info"},w={class:"ops-avatar"},C={class:"ops-header-text"},I={class:"ops-assistant-name"},k={class:"ops-header-actions"},x={class:"ops-chat-messages",ref:"messagesContainer"},y={class:"ops-chat-input-area"},B={class:"ops-input-container"},b=["placeholder","maxlength","disabled"],M={class:"ops-input-actions"},L={class:"ops-char-count"},V=["disabled"],N={key:1,class:"ops-loading-spinner"};p.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return e.openBlock(),e.createBlock(e.Transition,{name:"ops-slide-fade"},{default:e.withCtx(()=>[o.visible?(e.openBlock(),e.createElementBlock("div",{key:0,class:"ops-chat-modal",style:e.normalizeStyle({width:n.calculatedWidth,height:n.calculatedHeight,left:i.position.left+"px",top:i.position.top+"px"})},[e.createElementVNode("div",v,[e.createCommentVNode(" 头部 "),e.createElementVNode("div",{class:"ops-chat-header",onMousedown:s[2]||(s[2]=(...e)=>n.startDrag&&n.startDrag(...e))},[e.createElementVNode("div",f,[e.createElementVNode("div",w,[e.createVNode(r,{name:"user",class:"ops-avatar-icon"})]),e.createElementVNode("div",C,[e.createElementVNode("h3",I,e.toDisplayString(o.assistantTitle),1),s[9]||(s[9]=e.createElementVNode("span",{class:"ops-status ops-online"},"在线",-1))])]),e.createElementVNode("div",k,[e.createElementVNode("button",{class:"ops-minimize-btn",onClick:s[0]||(s[0]=e.withModifiers(e=>t.$emit("minimize"),["stop"]))},[e.createVNode(r,{name:"minimize",class:"ops-action-icon"})]),e.createElementVNode("button",{class:"ops-close-btn",onClick:s[1]||(s[1]=e.withModifiers(e=>t.$emit("close"),["stop"]))},[e.createVNode(r,{name:"close",class:"ops-action-icon"})])])],32),e.createCommentVNode(" 右下角调整大小手柄 "),e.createElementVNode("div",{class:"ops-resize-handle",onMousedown:s[3]||(s[3]=(...e)=>n.startResize&&n.startResize(...e))},null,32),e.createCommentVNode(" 消息区域 "),e.createElementVNode("div",x,[e.renderSlot(t.$slots,"welcome"),e.renderSlot(t.$slots,"messages")],512),e.createCommentVNode(" 输入区域 "),e.createElementVNode("div",y,[e.renderSlot(t.$slots,"image-preview"),e.createElementVNode("div",B,[e.withDirectives(e.createElementVNode("textarea",{"onUpdate:modelValue":s[4]||(s[4]=e=>i.inputText=e),onKeydown:s[5]||(s[5]=e.withKeys(e.withModifiers((...e)=>n.handleSend&&n.handleSend(...e),["exact","prevent"]),["enter"])),onInput:s[6]||(s[6]=e=>t.$emit("input-change",e)),onPaste:s[7]||(s[7]=(...e)=>n.handlePaste&&n.handlePaste(...e)),placeholder:o.placeholder,class:"ops-message-input",rows:"1",maxlength:o.maxLength,disabled:o.disabled},null,40,b),[[e.vModelText,i.inputText]]),e.createElementVNode("div",M,[e.renderSlot(t.$slots,"upload-button"),e.createElementVNode("span",L,e.toDisplayString(i.inputText.length)+"/"+e.toDisplayString(o.maxLength),1),e.createElementVNode("button",{onClick:s[8]||(s[8]=(...e)=>n.handleSend&&n.handleSend(...e)),class:e.normalizeClass(["ops-send-button",{"ops-loading":o.sending}]),disabled:n.sendDisabled},[e.renderSlot(t.$slots,"send-icon",{},()=>[o.sending?(e.openBlock(),e.createElementBlock("div",N)):(e.openBlock(),e.createBlock(r,{key:0,name:"send",class:"ops-send-icon"}))])],10,V)])])])])],4)):e.createCommentVNode("v-if",!0)]),_:3})},p.__scopeId="data-v-36f7e58f",p.__file="src/components/AgentAssistant/ChatModal.vue";var E={name:"WelcomeMessage",components:{SvgIcon:c},props:{title:{type:String,default:"您好!我是您的智能助手"},message:{type:String,default:"您好!我是智能助手,请问有什么可以帮助您的吗?"}}};const S={class:"ops-welcome-message"},z={class:"ops-welcome-text"};E.render=function(t,s,o,a,i,n){return e.openBlock(),e.createElementBlock("div",S,[s[0]||(s[0]=e.createElementVNode("div",{class:"ops-welcome-avatar"},[e.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[e.createElementVNode("path",{d:"M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z",fill:"currentColor"})])],-1)),e.createElementVNode("div",z,[e.createElementVNode("h4",null,e.toDisplayString(o.title),1),e.createElementVNode("p",null,e.toDisplayString(o.message),1)])])},E.__scopeId="data-v-2f1ef74a",E.__file="src/components/AgentAssistant/WelcomeMessage.vue";var $={name:"MessageImages",props:{images:{type:Array,default:()=>[]}},methods:{previewImage(e){this.$emit("preview",e)}}};const D={class:"ops-message-images"},_=["src","alt","onClick"],P={key:0,class:"ops-upload-error-overlay"};$.render=function(t,s,o,a,i,n){return e.openBlock(),e.createElementBlock("div",D,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.images,(t,o)=>(e.openBlock(),e.createElementBlock("div",{key:o,class:e.normalizeClass(["ops-message-image-item",{"ops-upload-failed":!1===t.uploadSuccess}])},[e.createElementVNode("img",{src:t.url,alt:t.name,class:"ops-message-image",onClick:e=>n.previewImage(t.url)},null,8,_),e.createCommentVNode(" 上传失败的提示 "),!1===t.uploadSuccess?(e.openBlock(),e.createElementBlock("div",P,[...s[0]||(s[0]=[e.createElementVNode("span",{class:"ops-error-text"},"上传失败",-1)])])):e.createCommentVNode("v-if",!0)],2))),128))])},$.__scopeId="data-v-c687e28e",$.__file="src/components/AgentAssistant/MessageImages.vue";var A={name:"MessageBubble",components:{MessageImages:$,SvgIcon:c},props:{message:{type:Object,required:!0,validator:e=>e.sender&&e.timestamp&&void 0!==e.content}},methods:{handleImagePreview(e){this.$emit("preview-image",e)}}};const T={key:0,class:"ops-message-avatar ops-assistant-avatar"},W={class:"ops-message-avatar ops-user-avatar"},H={class:"ops-message-content"},F={class:"ops-message-text"};A.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon"),l=e.resolveComponent("MessageImages");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["ops-message-bubble","ops-"+o.message.sender])},[e.createCommentVNode(" 助手头像 "),"assistant"===o.message.sender?(e.openBlock(),e.createElementBlock("div",T,[e.createVNode(r,{name:"user"})])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createCommentVNode(" 用户头像 "),e.createElementVNode("div",W,[e.createVNode(r,{name:"user"})])],2112)),e.createElementVNode("div",H,[e.createElementVNode("div",F,e.toDisplayString(o.message.content),1),e.createCommentVNode(" 图片展示 "),o.message.images&&o.message.images.length>0?(e.openBlock(),e.createBlock(l,{key:0,images:o.message.images,onPreview:n.handleImagePreview},null,8,["images","onPreview"])):e.createCommentVNode("v-if",!0)])],2)},A.__scopeId="data-v-0927d266",A.__file="src/components/AgentAssistant/MessageBubble.vue";var R={name:"MessageList",components:{MessageBubble:A},props:{messages:{type:Array,default:()=>[]}},methods:{handleImagePreview(e){this.$emit("preview-image",e)},scrollToBottom(){this.$nextTick(()=>{const e=this.$refs.messageList;e&&(e.scrollTop=e.scrollHeight)})}}};const Z={class:"ops-message-list",ref:"messageList"};R.render=function(t,s,o,a,i,n){const r=e.resolveComponent("MessageBubble");return e.openBlock(),e.createElementBlock("div",Z,[e.createVNode(e.TransitionGroup,{name:"ops-message-fade",tag:"div",class:"ops-transition-group"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.messages,(t,s)=>(e.openBlock(),e.createBlock(r,{key:t.id||s,message:t,onPreviewImage:n.handleImagePreview},null,8,["message","onPreviewImage"]))),128))]),_:1})],512)},R.__scopeId="data-v-4f7fdfc2",R.__file="src/components/AgentAssistant/MessageList.vue";var U={name:"ImagePreview",components:{SvgIcon:c},props:{images:{type:Array,default:()=>[]},disabled:{type:Boolean,default:!1}},methods:{removeImage(e){this.$emit("remove",e)}}};const X={key:0,class:"ops-image-preview-container"},Y=["src","alt"],O=["onClick","disabled"];U.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return o.images.length>0?(e.openBlock(),e.createElementBlock("div",X,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.images,(t,s)=>(e.openBlock(),e.createElementBlock("div",{key:s,class:"ops-image-preview-item"},[e.createElementVNode("img",{src:t.url,alt:t.name,class:"ops-preview-image"},null,8,Y),e.createElementVNode("button",{class:"ops-remove-image-btn",onClick:e=>n.removeImage(s),type:"button",disabled:o.disabled},[e.createVNode(r,{name:"close",class:"ops-remove-icon"})],8,O)]))),128))])):e.createCommentVNode("v-if",!0)},U.__scopeId="data-v-28f9b383",U.__file="src/components/AgentAssistant/ImagePreview.vue";var q={name:"UploadButton",components:{SvgIcon:c},props:{disabled:{type:Boolean,default:!1},isLoading:{type:Boolean,default:!1},maxImageCount:{type:Number,default:3},maxImageSize:{type:Number,default:5},currentImageCount:{type:Number,default:0}},methods:{handleFileChange(e){const t=Array.from(e.target.files);if(0===t.length)return;const s=this.maxImageCount-this.currentImageCount;if(s<=0)return void this.$emit("error",`最多只能上传${this.maxImageCount}张图片`);const o=t.slice(0,s),a=[];for(let e of o){if(!e.type.startsWith("image/")){this.$emit("error","请选择图片文件");continue}const t=1024*this.maxImageSize*1024;e.size>t?this.$emit("error",`图片 ${e.name} 太大,请选择小于${this.maxImageSize}MB的图片`):a.push(e)}const i=a.slice(0,s);i.length>0&&this.processFiles(i),e.target.value=""},processFiles(e){const t=[];e.forEach(e=>{t.push({url:"",name:e.name,file:e,size:e.size})}),this.$emit("files-selected",t)},reset(){this.$refs.fileInput&&(this.$refs.fileInput.value="")}}};const j=["multiple","disabled"];q.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return e.openBlock(),e.createElementBlock("label",{class:e.normalizeClass(["ops-upload-button",{"ops-disabled":o.disabled||o.isLoading}])},[e.createElementVNode("input",{type:"file",accept:"image/*",multiple:o.maxImageCount>1,onChange:s[0]||(s[0]=(...e)=>n.handleFileChange&&n.handleFileChange(...e)),ref:"fileInput",disabled:o.disabled||o.isLoading,class:"ops-file-input"},null,40,j),e.createVNode(r,{name:"uploadImage",class:"ops-upload-icon"})],2)},q.__scopeId="data-v-724f2729",q.__file="src/components/AgentAssistant/UploadButton.vue";var K={name:"ImagePreviewModal",components:{SvgIcon:c},props:{visible:{type:Boolean,default:!1},images:{type:Array,default:()=>[]},initialIndex:{type:Number,default:0}},data(){return{currentIndex:this.initialIndex,scale:1,minScale:.1,maxScale:5,step:.1}},computed:{currentImageUrl(){if(0===this.images.length)return"";const e=this.images[this.currentIndex];return e?.url||""},imageName(){if(0===this.images.length)return"";const e=this.images[this.currentIndex];return e?.name||"未命名图片"},showPrevButton(){return this.currentIndex>0},showNextButton(){return this.currentIndex<this.images.length-1},canZoomIn(){return this.scale<this.maxScale},canZoomOut(){return this.scale>this.minScale}},watch:{visible(e){e?(this.currentIndex=this.initialIndex,document.body.style.overflow="hidden"):document.body.style.overflow=""},initialIndex(e){this.currentIndex=e}},methods:{closeModal(){this.$emit("close")},handleBackdropClick(){this.closeModal()},prevImage(){this.currentIndex>0&&(this.currentIndex--,this.$emit("image-change",this.currentIndex))},nextImage(){this.currentIndex<this.images.length-1&&(this.currentIndex++,this.$emit("image-change",this.currentIndex))},selectImage(e){e>=0&&e<this.images.length&&(this.currentIndex=e,this.$emit("image-change",this.currentIndex))},onImageLoad(){this.$emit("image-load",{index:this.currentIndex,url:this.currentImageUrl})},onImageError(){this.$emit("image-error",{index:this.currentIndex,url:this.currentImageUrl})},zoomIn(){this.canZoomIn&&(this.scale=Math.min(this.scale+this.step,this.maxScale))},zoomOut(){this.canZoomOut&&(this.scale=Math.max(this.scale-this.step,this.minScale))},resetZoom(){this.scale=1},fitScreen(){this.scale=1}}};const G={class:"ops-image-container"},J=["src","alt"],Q={key:0,class:"ops-image-counter"},ee={class:"ops-zoom-controls"},te=["disabled"],se=["disabled"];K.render=function(t,s,o,a,i,n){const r=e.resolveComponent("SvgIcon");return e.openBlock(),e.createBlock(e.Transition,{name:"ops-modal-fade"},{default:e.withCtx(()=>[o.visible?(e.openBlock(),e.createElementBlock("div",{key:0,class:"ops-image-preview-overlay",onClick:s[9]||(s[9]=(...e)=>n.handleBackdropClick&&n.handleBackdropClick(...e))},[e.createCommentVNode(" 关闭按钮 "),e.createElementVNode("button",{class:"ops-close-btn",onClick:s[0]||(s[0]=(...e)=>n.closeModal&&n.closeModal(...e))},[e.createVNode(r,{name:"close",class:"ops-close-icon"})]),e.createCommentVNode(" 图片显示区域 "),e.createElementVNode("div",G,[o.images.length>1&&n.showPrevButton?(e.openBlock(),e.createElementBlock("button",{key:0,class:"ops-nav-btn ops-prev-btn",onClick:s[1]||(s[1]=e.withModifiers((...e)=>n.prevImage&&n.prevImage(...e),["stop"]))},[e.createVNode(r,{name:"prev",class:"ops-nav-icon"})])):e.createCommentVNode("v-if",!0),e.createElementVNode("img",{src:n.currentImageUrl,alt:n.imageName,class:"ops-preview-image",onLoad:s[2]||(s[2]=(...e)=>n.onImageLoad&&n.onImageLoad(...e)),onError:s[3]||(s[3]=(...e)=>n.onImageError&&n.onImageError(...e))},null,40,J),o.images.length>1&&n.showNextButton?(e.openBlock(),e.createElementBlock("button",{key:1,class:"ops-nav-btn ops-next-btn",onClick:s[4]||(s[4]=e.withModifiers((...e)=>n.nextImage&&n.nextImage(...e),["stop"]))},[e.createVNode(r,{name:"next",class:"ops-nav-icon"})])):e.createCommentVNode("v-if",!0)]),e.createCommentVNode(" 图片计数器 "),o.images.length>1?(e.openBlock(),e.createElementBlock("div",Q,e.toDisplayString(i.currentIndex+1)+" / "+e.toDisplayString(o.images.length),1)):e.createCommentVNode("v-if",!0),e.createCommentVNode(" 缩放控制按钮 "),e.createElementVNode("div",ee,[e.createElementVNode("button",{class:"ops-zoom-btn",disabled:!n.canZoomOut,onClick:s[5]||(s[5]=e.withModifiers((...e)=>n.zoomOut&&n.zoomOut(...e),["stop"])),title:"缩小"},[e.createVNode(r,{name:"zoomOut",class:"ops-zoom-icon"})],8,te),e.createElementVNode("button",{class:"ops-zoom-btn",onClick:s[6]||(s[6]=e.withModifiers((...e)=>n.resetZoom&&n.resetZoom(...e),["stop"])),title:"1:1"},e.toDisplayString(Math.round(100*i.scale))+"% ",1),e.createElementVNode("button",{class:"ops-zoom-btn",disabled:!n.canZoomIn,onClick:s[7]||(s[7]=e.withModifiers((...e)=>n.zoomIn&&n.zoomIn(...e),["stop"])),title:"放大"},[e.createVNode(r,{name:"zoomIn",class:"ops-zoom-icon"})],8,se),e.createElementVNode("button",{class:"ops-zoom-btn",onClick:s[8]||(s[8]=e.withModifiers((...e)=>n.fitScreen&&n.fitScreen(...e),["stop"])),title:"适应屏幕"},[e.createVNode(r,{name:"fullscreen",class:"ops-zoom-icon"})])])])):e.createCommentVNode("v-if",!0)]),_:1})},K.__scopeId="data-v-76b5889a",K.__file="src/components/AgentAssistant/ImagePreviewModal.vue";var oe={name:"AgentAssistant",components:{FloatingTrigger:m,ChatModal:p,WelcomeMessage:E,MessageList:R,ImagePreview:U,UploadButton:q,ImagePreviewModal:K},props:o,data(){return{showChatBox:!1,inputText:"",messages:[],isLoading:!1,unreadCount:0,isMinimized:!1,previewImages:[],uploadedImages:[],modalWidth:this.width,modalHeight:this.height,showImagePreview:!1,previewImagesData:[],previewImageIndex:0}},watch:{certificate:{handler(e){e&&s.setCertificate(e)},immediate:!0},width:{handler(e){this.modalWidth=e},immediate:!0},height:{handler(e){this.modalHeight=e},immediate:!0}},computed:{welcomeTitle:()=>"您好!我是您的智能助手",welcomeContent(){return this.welcomeMessage||"您好!我是智能助手,请问有什么可以帮助您的吗?"},assistantTitle(){return this.assistantTitleProp||"智能助手"}},methods:{toggleChatBox(){this.showChatBox=!this.showChatBox,this.isMinimized=!1,this.showChatBox&&(this.unreadCount=0,0===this.messages.length&&this.addMessage("assistant",this.welcomeContent),this.$nextTick(()=>{this.focusInput()}))},handleResize(e){this.modalWidth=e.width,this.modalHeight=e.height},minimizeChat(){this.isMinimized=!0,this.showChatBox=!1},handleSendMessage(e){if(!e.trim()&&0===this.previewImages.length||this.isLoading)return;const t=[...this.previewImages],s=e||"";this.addMessage("user",s,t),this.isLoading=!0;const o=this.addMessage("assistant","正在深度思考您的问题...",[]);this.callApi(e,t,o.id),this.inputText="",this.clearImages()},async callApi(e,t=null,s=null){try{const o=(t||this.previewImages).filter(e=>!0===e.uploadSuccess).map(e=>e.url),a=await n(e,this.userName,o,this.domain);if(a.success){const e=a.data.data.choices[0].message.content;s?this.updateMessage(s,e):this.addMessage("assistant",e)}else s?this.updateMessage(s,a.error||"服务异常,请稍后再试。"):this.addMessage("assistant",a.error||"服务异常,请稍后再试。")}catch(e){console.error("API调用失败:",e),s?this.updateMessage(s,"网络错误或服务异常,请稍后再试。"):this.addMessage("assistant","网络错误或服务异常,请稍后再试。")}finally{this.isLoading=!1}},updateMessage(e,t){const s=this.messages.findIndex(t=>t.id===e);-1!==s&&(this.messages[s].content=t,this.messages[s].timestamp=new Date)},addMessage(e,t,s=[]){const o={id:Date.now()+Math.random(),sender:e,content:t||"",images:s,timestamp:new Date};return this.messages.push(o),"assistant"!==e||this.showChatBox||this.unreadCount++,this.$nextTick(()=>{this.$refs.messageList&&this.$refs.messageList.scrollToBottom()}),o},scrollToBottom(){this.$refs.chatModal?.$refs.messagesContainer?.scrollTo({top:this.$refs.chatModal.$refs.messagesContainer.scrollHeight,behavior:"smooth"})},focusInput(){this.$refs.chatModal?.focus()},handleInput(){this.autoResizeTextarea()},autoResizeTextarea(){},async handleFilesSelected(e){const t=this.maxImageCount-this.previewImages.length;if(t<=0)return void this.handleUploadError(`最多只能上传${this.maxImageCount}张图片`);const s=e.slice(0,t);for(let e of s){if(this.previewImages.length>=this.maxImageCount){this.handleUploadError(`最多只能上传${this.maxImageCount}张图片`);break}try{this.isLoading=!0;const t=await r(e.file,this.domain);if(t.success){const s={url:t.data.accessPath,name:e.name,size:e.size,uploadSuccess:!0};this.previewImages.push(s)}else{const s={url:e.url,name:e.name,size:e.size,uploadSuccess:!1,error:t.error};this.previewImages.push(s),this.handleUploadError(`图片 ${e.name} 上传失败: ${t.error}`)}}catch(t){console.error("文件上传异常:",t);const s={url:e.url,name:e.name,size:e.size,uploadSuccess:!1,error:"上传异常"};this.previewImages.push(s),this.handleUploadError(`图片 ${e.name} 上传异常: ${t.message}`)}finally{this.isLoading=!1}}},handleUploadError(e){alert(e)},removeImage(e){this.previewImages.splice(e,1)},clearImages(){this.previewImages=[],this.uploadedImages=[],this.$refs.uploadButton&&this.$refs.uploadButton.reset()},previewImage(e){const t=[];this.messages.forEach(e=>{e.images&&e.images.length>0&&e.images.forEach((s,o)=>{t.push({url:s.url,name:s.name||`图片_${t.length+1}`,messageId:e.id,imageIndex:o})})});const s=t.findIndex(t=>t.url===e);-1!==s&&(this.previewImagesData=t,this.previewImageIndex=s,this.showImagePreview=!0)},closeImagePreview(){this.showImagePreview=!1,this.previewImagesData=[],this.previewImageIndex=0},handleImageChange(e){this.previewImageIndex=e},handleImageLoad(e){console.log("图片加载完成:",e)},handleImageError(e){console.error("图片加载失败:",e)}}};const ae={class:"agent-assistant"};oe.render=function(t,s,o,a,i,n){const r=e.resolveComponent("FloatingTrigger"),l=e.resolveComponent("WelcomeMessage"),c=e.resolveComponent("MessageList"),d=e.resolveComponent("ImagePreview"),m=e.resolveComponent("UploadButton"),h=e.resolveComponent("ChatModal"),g=e.resolveComponent("ImagePreviewModal");return e.openBlock(),e.createElementBlock("div",ae,[e.createCommentVNode(" 浮动触发器 "),i.showChatBox?e.createCommentVNode("v-if",!0):(e.openBlock(),e.createBlock(r,{key:0,"unread-count":i.unreadCount,"show-badge":t.showUnreadBadge,onToggle:n.toggleChatBox},null,8,["unread-count","show-badge","onToggle"])),e.createCommentVNode(" 聊天弹窗 "),e.createVNode(h,{visible:i.showChatBox,width:i.modalWidth,height:i.modalHeight,"assistant-title":n.assistantTitle,sending:i.isLoading,"initial-value":i.inputText,placeholder:"输入消息...","max-length":500,disabled:i.isLoading,onClose:n.toggleChatBox,onMinimize:n.minimizeChat,onSend:n.handleSendMessage,onInputChange:n.handleInput,onFilesPasted:n.handleFilesSelected,onResize:n.handleResize,ref:"chatModal"},{welcome:e.withCtx(()=>[0===i.messages.length?(e.openBlock(),e.createBlock(l,{key:0,title:n.welcomeTitle,message:n.welcomeContent},null,8,["title","message"])):e.createCommentVNode("v-if",!0)]),messages:e.withCtx(()=>[e.createVNode(c,{messages:i.messages,onPreviewImage:n.previewImage,ref:"messageList"},null,8,["messages","onPreviewImage"])]),"image-preview":e.withCtx(()=>[e.createVNode(d,{images:i.previewImages,disabled:i.isLoading,onRemove:n.removeImage},null,8,["images","disabled","onRemove"])]),"upload-button":e.withCtx(()=>[e.createVNode(m,{disabled:i.isLoading,"is-loading":i.isLoading,"max-image-count":t.maxImageCount,"max-image-size":t.maxImageSize,"current-image-count":i.previewImages.length,onFilesSelected:n.handleFilesSelected,onError:n.handleUploadError,ref:"uploadButton"},null,8,["disabled","is-loading","max-image-count","max-image-size","current-image-count","onFilesSelected","onError"])]),_:1},8,["visible","width","height","assistant-title","sending","initial-value","disabled","onClose","onMinimize","onSend","onInputChange","onFilesPasted","onResize"]),e.createCommentVNode(" 图片预览模态框 "),e.createVNode(g,{visible:i.showImagePreview,images:i.previewImagesData,"initial-index":i.previewImageIndex,onClose:n.closeImagePreview,onImageChange:n.handleImageChange,onImageLoad:n.handleImageLoad,onImageError:n.handleImageError},null,8,["visible","images","initial-index","onClose","onImageChange","onImageLoad","onImageError"])])},oe.__scopeId="data-v-5a317acc",oe.__file="src/components/AgentAssistant/index.vue";const ie={install(e,s={}){const o=t(e),a=3===o,i=e;!function(e,s,o){3===t(e)?e.config.globalProperties[s]=o:e.prototype[s]=o}(e,"$myPlugin",{log:e=>console.log(`[CrossPlugin] ${e}`),getVersion:()=>`Vue${o} + Plugin@1.0.0`}),i.component("AgentAssistant",oe);let n;if(i.directive("color",{bind:(e,t)=>e.style.color=t.value,mounted:(e,t)=>e.style.color=t.value,update:(e,t)=>e.style.color=t.value,updated:(e,t)=>e.style.color=t.value}),a)try{if("undefined"!=typeof require){const{reactive:e}=require("vue");n=e({count:0})}else if("undefined"!=typeof window&&window.Vue){const{reactive:e}=window.Vue;n=e({count:0})}else n={count:0}}catch(e){n={count:0}}else try{n=e.observable({count:0})}catch(e){n={count:0}}ie.state=n}};return"undefined"!=typeof window&&window.Vue&&window.Vue.use(ie),ie});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-ops-chat",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "兼容 Vue2/Vue3 的插件(基于 Webpack/Vue CLI)",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "src/index.js",
package/src/api/chat.js CHANGED
@@ -2,40 +2,42 @@
2
2
  * 聊天相关API接口
3
3
  */
4
4
 
5
- import { post } from './service';
6
- import { getBaseUrl, CHAT_API_URL, UPLOAD_URL_API } from './urls';
7
-
8
- /**
9
- * 发送聊天消息
10
- * @param {string} message - 消息内容
11
- * @param {string} userName - 用户名
12
- * @param {Array} fileUrls - 图片URL数组
13
- * @returns {Promise<any>} API响应结果
14
- */
15
- export async function sendChatMessage(message, userName, fileUrls = []) {
16
- const requestData = {
17
- message,
18
- userName,
19
- fileUrls // 改为数组形式支持多图片
20
- };
21
- return await post(CHAT_API_URL, requestData);
22
- }
23
-
24
- /**
25
- * 上传图片
26
- * @param {File} file - 要上传的文件
27
- * @returns {Promise<any>} 上传结果
28
- */
29
- export async function uploadImage(file) {
30
- const formData = new FormData();
31
- formData.append('file', file);
32
- formData.append('bucket', 'CSS-01');
33
-
34
- try {
35
- const baseUrl = getBaseUrl();
36
- const response = await fetch(`${baseUrl}${UPLOAD_URL_API}`, {
37
- method: 'POST',
38
- body: formData
5
+ import { post } from './service';
6
+ import { getBaseUrl, CHAT_API_URL, UPLOAD_URL_API } from './urls';
7
+
8
+ /**
9
+ * 发送聊天消息
10
+ * @param {string} message - 消息内容
11
+ * @param {string} userName - 用户名
12
+ * @param {Array} fileUrls - 图片URL数组
13
+ * @param {string} domain - 域名配置
14
+ * @returns {Promise<any>} API响应结果
15
+ */
16
+ export async function sendChatMessage(message, userName, fileUrls = [], domain) {
17
+ const requestData = {
18
+ message,
19
+ userName,
20
+ fileUrls // 改为数组形式支持多图片
21
+ };
22
+ return await post(CHAT_API_URL, requestData, domain);
23
+ }
24
+
25
+ /**
26
+ * 上传图片
27
+ * @param {File} file - 要上传的文件
28
+ * @param {string} domain - 域名配置
29
+ * @returns {Promise<any>} 上传结果
30
+ */
31
+ export async function uploadImage(file, domain) {
32
+ const formData = new FormData();
33
+ formData.append('file', file);
34
+ formData.append('bucket', 'CSS-01');
35
+
36
+ try {
37
+ const baseUrl = getBaseUrl(domain);
38
+ const response = await fetch(`${baseUrl}${UPLOAD_URL_API}`, {
39
+ method: 'POST',
40
+ body: formData
39
41
  });
40
42
 
41
43
  if (!response.ok) {
@@ -10,10 +10,11 @@ import { getBaseUrl } from './urls';
10
10
  * 发送POST请求
11
11
  * @param {string} endpoint - API端点路径
12
12
  * @param {Object} data - 请求数据
13
+ * @param {string} domain - 域名配置(可选)
13
14
  * @param {string} certificate - 身份认证证书(可选)
14
15
  * @returns {Promise<any>} 请求结果
15
16
  */
16
- export async function post(endpoint, data, certificate = '') {
17
+ export async function post(endpoint, data, domain = '', certificate = '') {
17
18
  try {
18
19
  const headers = {
19
20
  'Content-Type': 'application/json'
@@ -26,7 +27,7 @@ export async function post(endpoint, data, certificate = '') {
26
27
  }
27
28
 
28
29
  // 构建完整URL
29
- const baseUrl = getBaseUrl();
30
+ const baseUrl = getBaseUrl(domain);
30
31
  const fullUrl = `${baseUrl}${endpoint}`;
31
32
 
32
33
  const response = await fetch(fullUrl, {
package/src/api/urls.js CHANGED
@@ -1,3 +1,10 @@
1
+ /*
2
+ * @Author: hui.chenn
3
+ * @Description:
4
+ * @Date: 2026-02-05 10:00:56
5
+ * @LastEditTime: 2026-02-09 14:01:48
6
+ * @LastEditors: hui.chenn
7
+ */
1
8
  /**
2
9
  * API端点URL管理
3
10
  * 统一管理所有API端点URL和方法
@@ -236,7 +236,7 @@ export default {
236
236
  .filter(img => img.uploadSuccess === true)
237
237
  .map(img => img.url);
238
238
 
239
- const response = await sendChatMessage(userInput, this.userName, fileUrls);
239
+ const response = await sendChatMessage(userInput, this.userName, fileUrls, this.domain);
240
240
 
241
241
  if (response.success) {
242
242
  const botResponse = response.data.data.choices[0].message.content;
@@ -368,7 +368,7 @@ export default {
368
368
 
369
369
  try {
370
370
  this.isLoading = true;
371
- const uploadResult = await uploadImage(fileObj.file);
371
+ const uploadResult = await uploadImage(fileObj.file, this.domain);
372
372
 
373
373
  if (uploadResult.success) {
374
374
  // 上传成功,保存上传后的图片信息