index-Dh16T5Oz.js 6.6 KB

1
  1. import{f as B,t as F}from"./index-n2zj8JaK.js";import{_ as N,r as O,v as z,c as g,o as m,F as D,k as R,t as L,m as q,aG as A,L as W,g as G,e as b,D as H,h as C,i as M,j as T,E as V,f as E,H as J,n as j}from"./index-D7n5ZNak.js";import{a as Q}from"./index-dC5UiZEt.js";import{a as K}from"./document-Doy44Wja.js";class U{diff(e,n,t={}){let r;typeof t=="function"?(r=t,t={}):"callback"in t&&(r=t.callback);const i=this.castInput(e,t),h=this.castInput(n,t),_=this.removeEmpty(this.tokenize(i,t)),u=this.removeEmpty(this.tokenize(h,t));return this.diffWithOptionsObj(_,u,t,r)}diffWithOptionsObj(e,n,t,r){var i;const h=a=>{if(a=this.postProcess(a,t),r){setTimeout(function(){r(a)},0);return}else return a},_=n.length,u=e.length;let p=1,c=_+u;t.maxEditLength!=null&&(c=Math.min(c,t.maxEditLength));const d=(i=t.timeout)!==null&&i!==void 0?i:1/0,s=Date.now()+d,o=[{oldPos:-1,lastComponent:void 0}];let f=this.extractCommon(o[0],n,e,0,t);if(o[0].oldPos+1>=u&&f+1>=_)return h(this.buildValues(o[0].lastComponent,n,e));let w=-1/0,v=1/0;const l=()=>{for(let a=Math.max(w,-p);a<=Math.min(v,p);a+=2){let x;const y=o[a-1],k=o[a+1];y&&(o[a-1]=void 0);let S=!1;if(k){const $=k.oldPos-a;S=k&&0<=$&&$<_}const I=y&&y.oldPos+1<u;if(!S&&!I){o[a]=void 0;continue}if(!I||S&&y.oldPos<k.oldPos?x=this.addToPath(k,!0,!1,0,t):x=this.addToPath(y,!1,!0,1,t),f=this.extractCommon(x,n,e,a,t),x.oldPos+1>=u&&f+1>=_)return h(this.buildValues(x.lastComponent,n,e))||!0;o[a]=x,x.oldPos+1>=u&&(v=Math.min(v,a-1)),f+1>=_&&(w=Math.max(w,a+1))}p++};if(r)(function a(){setTimeout(function(){if(p>c||Date.now()>s)return r(void 0);l()||a()},0)})();else for(;p<=c&&Date.now()<=s;){const a=l();if(a)return a}}addToPath(e,n,t,r,i){const h=e.lastComponent;return h&&!i.oneChangePerToken&&h.added===n&&h.removed===t?{oldPos:e.oldPos+r,lastComponent:{count:h.count+1,added:n,removed:t,previousComponent:h.previousComponent}}:{oldPos:e.oldPos+r,lastComponent:{count:1,added:n,removed:t,previousComponent:h}}}extractCommon(e,n,t,r,i){const h=n.length,_=t.length;let u=e.oldPos,p=u-r,c=0;for(;p+1<h&&u+1<_&&this.equals(t[u+1],n[p+1],i);)p++,u++,c++,i.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return c&&!i.oneChangePerToken&&(e.lastComponent={count:c,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=u,p}equals(e,n,t){return t.comparator?t.comparator(e,n):e===n||!!t.ignoreCase&&e.toLowerCase()===n.toLowerCase()}removeEmpty(e){const n=[];for(let t=0;t<e.length;t++)e[t]&&n.push(e[t]);return n}castInput(e,n){return e}tokenize(e,n){return Array.from(e)}join(e){return e.join("")}postProcess(e,n){return e}get useLongestToken(){return!1}buildValues(e,n,t){const r=[];let i;for(;e;)r.push(e),i=e.previousComponent,delete e.previousComponent,e=i;r.reverse();const h=r.length;let _=0,u=0,p=0;for(;_<h;_++){const c=r[_];if(c.removed)c.value=this.join(t.slice(p,p+c.count)),p+=c.count;else{if(!c.added&&this.useLongestToken){let d=n.slice(u,u+c.count);d=d.map(function(s,o){const f=t[p+o];return f.length>s.length?f:s}),c.value=this.join(d)}else c.value=this.join(n.slice(u,u+c.count));u+=c.count,c.added||(p+=c.count)}}return r}}class X extends U{}const Y=new X;function Z(P,e,n){return Y.diff(P,e,n)}const ee={class:"diffText"},te={key:0,class:"diffText-removed"},ne={key:1,class:"diffText-added"},oe={key:2},se={__name:"diffText",props:{oldStr:{type:String,default:"",required:!0},newStr:{type:String,default:"",required:!0}},setup(P){const e=O([]),n=(t=[])=>{e.value=Z(A(P.oldStr),A(P.newStr))};return z(()=>{n()}),(t,r)=>(m(),g("div",ee,[(m(!0),g(D,null,R(q(e),i=>(m(),g("span",{key:i.value},[i.removed?(m(),g("del",te,L(i.value),1)):i.added?(m(),g("ins",ne,L(i.value),1)):(m(),g("span",oe,L(i.value),1))]))),128))]))}},ae=N(se,[["__scopeId","data-v-def401a6"]]),re={class:"proofreadView"},ie={class:"proofreadView-content"},ce={key:0,class:"proofreadView-content-card-loading"},de={class:"proofreadView-content-card-origin"},le={key:1},ue={class:"proofreadView-content-card-fixed"},fe={class:"proofreadView-content-card-text"},pe={class:"proofreadView-content-card-btns"},he=W({name:"ProofreadView"}),me=Object.assign(he,{setup(P){const{proxy:e}=G();let n=[];const t=O([]),r=d=>d?new Promise((s,o)=>{B(d).then(async f=>{if(f.status!==200)return o("接口异常");let w="";for await(const v of F({readableStream:f.body}))if(v&&v.data){const l=JSON.parse(v.data);l.answer===void 0||(w+=l.answer),l&&l.event==="workflow_finished"&&s(w),l&&l.event==="message_end"&&console.log("回答结束")}else o("解析异常")})}):reject("文本不存在"),i=(d=[])=>{const s=[];return d.forEach(o=>{const f=o.Range.Text.trim(),w={id:o.ParaID,text:f,status:"pendding",newText:null,taskFunc:v=>r(v)};s.push(w)}),s},h=async d=>{t.value=i(d);for(let s=0;s<t.value.length;s++){const o=t.value[s];try{o.status="loading",o.newText=await o.taskFunc(o.text),o.text===o.newText?o.status="noNeed":o.status="success"}catch(f){console.warn(f),o.status="fail"}}},_=(d,s)=>{const o=n[s],f=o.Range;console.log("curPara",o),f.Text=d.newText+"\r",f.Select()},u=d=>{Q(d.newText,()=>{e.$notify({title:"复制成功",type:"success",position:"bottom-right"})})},p=d=>{d.status="loading",r(d.text).then(s=>{d.newText=s,d.status="success"}).catch(()=>{d.status="fail"})},c=()=>{n=K(),console.log("handleProofread",n),h(n)};return(d,s)=>{const o=b("el-button"),f=b("el-card"),w=b("el-scrollbar"),v=H("loading");return m(),g("div",re,[s[4]||(s[4]=C("div",{class:"proofreadView-header"},"智能校对",-1)),C("div",ie,[M(w,{height:"calc(100vh - 76px)"},{default:T(()=>[C("div",{class:"proofreadView-content-btn",onClick:c},"全文校对"),(m(!0),g(D,null,R(q(t),(l,a)=>(m(),g(D,null,[l.text&&["loading","success","fail"].indexOf(l.status)>=0?(m(),V(f,{key:l.id,class:"proofreadView-content-card"},{default:T(()=>[l.status==="loading"?J((m(),g("div",ce,null,512)),[[v,!0]]):(m(),g(D,{key:1},[C("div",de,[l.status==="success"?(m(),V(ae,{key:0,class:"proofreadView-content-card-text",oldStr:l.text,newStr:l.newText},null,8,["oldStr","newStr"])):(m(),g("span",le,"校对失败"))]),C("div",ue,[s[0]||(s[0]=C("div",{class:"proofreadView-content-card-title"},"校对后:",-1)),C("div",fe,L(l.newText),1)]),C("div",pe,[l.status==="success"?(m(),V(o,{key:0,type:"primary",onClick:x=>_(l,a)},{default:T(()=>s[1]||(s[1]=[j(" 替换原文 ")])),_:2},1032,["onClick"])):E("",!0),l.status==="success"?(m(),V(o,{key:1,type:"primary",onClick:x=>u(l)},{default:T(()=>s[2]||(s[2]=[j(" 复制 ")])),_:2},1032,["onClick"])):E("",!0),M(o,{type:"warning",onClick:x=>p(l,a)},{default:T(()=>s[3]||(s[3]=[j("重新校对")])),_:2},1032,["onClick"])])],64))]),_:2},1024)):E("",!0)],64))),256))]),_:1})])])}}}),xe=N(me,[["__scopeId","data-v-186771d5"]]);export{xe as default};