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