adtec-hnyzfc-core-package 1.5.9 → 1.6.0
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/src/api/DocumentApi.d.ts +7 -1
- package/dist/src/api/DocumentApi.js +1 -1
- package/dist/src/components/upload/AttachmentPreview.vue.js +1 -1
- package/dist/src/components/upload/OfficePreview.vue.d.ts +9 -0
- package/dist/src/components/upload/OfficePreview.vue.js +2 -2
- package/dist/src/utils/AxiosConfig.js +1 -1
- package/dist/src/utils/request.d.ts +6 -0
- package/dist/src/utils/request.js +1 -1
- package/dist/styles/element-ui.css +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,13 @@ declare const _default: {
|
|
|
18
18
|
delSysUploadFiles(ids: string[]): Promise<Record<string, string>>;
|
|
19
19
|
/** 公开注册:将附件 createBy 绑定为注册手机号 */
|
|
20
20
|
updateFilesCreateBy(ids: string[], createBy: string): Promise<Record<string, string>>;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* 创建仅供当前浏览器内嵌使用的短期预览会话。
|
|
23
|
+
*
|
|
24
|
+
* skipGlobalLoading:预览区自己有加载层(OfficePreview 的 overlay + 预览页内层 loading),
|
|
25
|
+
* 会话创建不应再点亮整页 loading,也不应被 createDialogHooks 计入「抽屉/弹窗 loading」——
|
|
26
|
+
* 否则在抽屉里打开附件预览时,会出现抽屉 loading 与预览 loading 同时转圈。
|
|
27
|
+
*/
|
|
22
28
|
createPreviewSession(id: string): Promise<{
|
|
23
29
|
url: string;
|
|
24
30
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"../utils/request.js";import
|
|
1
|
+
import o from"../utils/request.js";import s from"../utils/AxiosConfig.js";import"axios";import"../utils/uuid.js";import"uuid";import"../utils/encrypt.js";import"jsencrypt";import"../utils/behaviorTrack.js";import"crypto-js/enc-base64";import"crypto-js/enc-utf8";import"../utils/behaviorContext.js";import"../utils/dateTime.js";import"element-plus";import"../utils/frontendBus.js";import"../utils/globalLoading.js";import"vue";import"../utils/workflowTaskContext.js";import"../config/GlobalLoadingConfig.js";const i="/api/doc/",n=e=>{if(!e)return;const t=/filename\*=(?:UTF-8|utf-8)''([^;]+)/i.exec(e);if(t?.[1])try{return decodeURIComponent(t[1].trim())}catch{}return/filename="?([^";]+)"?/i.exec(e)?.[1]?.trim()},b={getUpLoadFilesVoById(e){return o.get(i+"getUpLoadFilesVoById/"+e)},getFileAccessAddress(e){return o.get(i+"getFileAccessAddress",{id:e})},async createRichTextImageUrl(e){const{url:t}=await this.createPreviewSession(e),r=/\/preview\/fileView\/([^/]+)\//.exec(t||"");if(!r?.[1])throw new Error("预览会话创建失败");return`${i}preview/fileView/${encodeURIComponent(r[1])}/image`},getUpLoadFilesByBussinessIds(e,t){const r=t===void 0?i+"getUpLoadFilesByBussinessIds":i+"getUpLoadFilesByBussinessIds/"+t;return o.post(r,e)},delSysUploadFile(e){return o.get(i+"delSysUploadFile/"+e)},getBusinessDocuments(e,t){return o.get(i+"getBusinessDocuments/"+e+"/"+t)},fileStatusConfirmation(e){return o.post(i+"fileStatusConfirmation",e)},delSysUploadFiles(e){return o.post(i+"delSysUploadFiles",e)},updateFilesCreateBy(e,t){return o.post(i+"updateFilesCreateBy",{ids:e,createBy:t})},createPreviewSession(e){return o.postWithOptions(i+"preview/session/"+e,void 0,{skipGlobalLoading:!0})},async downloadFile(e,t){const r=await s({url:i+"preview/download/"+e+(t?"?format="+t:""),method:"get",responseType:"blob"});return{blob:r.data,fileName:n(r.headers?.["content-disposition"])}}};export{b as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineComponent as F,ref as s,watch as P,openBlock as
|
|
1
|
+
import{defineComponent as F,ref as s,watch as P,openBlock as h,createElementBlock as R,normalizeClass as T,unref as f,createBlock as w,withCtx as A,renderSlot as D}from"vue";import{ElEmpty as I}from"element-plus";import N from"../../utils/FrameworkUtils.js";import x from"../../hooks/usePreviewFullscreen.js";import C from"./OfficePreview.vue.js";import{_ as E}from"../../../chunks/_plugin-vue_export-helper-DlAUqK2U.js";import"xlsx-js-style";import"crypto-js/enc-base64";import"crypto-js/enc-utf8";import"../../api/DocumentApi.js";import"../../utils/request.js";import"../../utils/AxiosConfig.js";import"axios";import"../../utils/uuid.js";import"uuid";import"../../utils/encrypt.js";import"jsencrypt";import"../../utils/behaviorTrack.js";import"../../utils/behaviorContext.js";import"../../utils/dateTime.js";import"../../utils/frontendBus.js";import"../../utils/globalLoading.js";import"../../utils/workflowTaskContext.js";import"../../config/GlobalLoadingConfig.js";import"../../utils/fileDownload.js";import"../../utils/officePreviewUtil.js";import"./OfficePreviewHeaderBar.vue.js";import"@element-plus/icons-vue";const L=F({__name:"AttachmentPreview",props:{fileId:{default:""},fileName:{default:""},fileType:{default:""},title:{default:""},showHeader:{type:Boolean,default:!0},showSearch:{type:Boolean,default:!0},showZoom:{type:Boolean,default:!0},showDownload:{type:Boolean,default:!1},showRefresh:{type:Boolean,default:!1},showFullscreen:{type:Boolean,default:!1},attachmentLost:{type:Boolean,default:!1},emptyDescription:{default:"暂无附件"},lostDescription:{default:"附件已丢失或无权访问"},refreshAttachment:{type:Function,default:void 0}},emits:["loaded","error","download","refresh","change","update:fileId","update:fileName","update:fileType"],setup(t,{expose:v,emit:y}){const l=t,r=y,i=s(l.fileId||""),d=s(l.fileName||""),m=s(l.fileType||""),u=s(!1),n=s(null);P(()=>[l.fileId,l.fileName,l.fileType],([e,o,a])=>{i.value=e||"",d.value=o||"",m.value=a||""});const{previewContainerRef:g,isPreviewFullscreen:p,togglePreviewFullscreen:B}=x(),k=e=>{const o=e.id!==i.value;return i.value=e.id,d.value=e.name||"",m.value=e.type||"",r("update:fileId",e.id),r("update:fileName",e.name||""),r("update:fileType",e.type||""),r("change",e),o},c=async()=>{r("refresh");const e=l.refreshAttachment;if(e){u.value=!0;try{const o=await e();if(o?.id&&k(o))return;n.value?.reloadPreview()}catch(o){N.messageError(o)}finally{u.value=!1}}};return v({reload:()=>n.value?.reloadPreview(),download:e=>n.value?.download(e),refreshAttachment:c,isFullscreen:p}),(e,o)=>(h(),R("div",{ref_key:"previewContainerRef",ref:g,class:T(["attachment-preview",{"preview-fullscreen-fallback":f(p)}])},[i.value?(h(),w(C,{key:0,ref_key:"previewRef",ref:n,"file-id":i.value,"file-name":d.value,"file-type":m.value,title:t.title,"show-header":t.showHeader,"show-search":t.showSearch,"show-zoom":t.showZoom,"show-download":t.showDownload,"show-refresh":t.showRefresh,"show-fullscreen":t.showFullscreen,fullscreen:f(p),"refresh-loading":u.value,"defer-refresh":!!t.refreshAttachment,"attachment-lost":t.attachmentLost,"lost-description":t.lostDescription,onLoaded:o[0]||(o[0]=a=>r("loaded")),onError:o[1]||(o[1]=a=>r("error",a)),onRefresh:c,onDownload:o[2]||(o[2]=a=>r("download",a)),onToggleFullscreen:f(B)},null,8,["file-id","file-name","file-type","title","show-header","show-search","show-zoom","show-download","show-refresh","show-fullscreen","fullscreen","refresh-loading","defer-refresh","attachment-lost","lost-description","onToggleFullscreen"])):(h(),w(f(I),{key:1,description:t.emptyDescription},{default:A(()=>[D(e.$slots,"empty",{},void 0,!0)]),_:3},8,["description"]))],2))}}),ne=E(L,[["__scopeId","data-v-8ee24fdd"]]);export{ne as default};
|
|
@@ -16,6 +16,14 @@ type __VLS_Props = {
|
|
|
16
16
|
fullscreen?: boolean;
|
|
17
17
|
downloadLoading?: boolean;
|
|
18
18
|
refreshLoading?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 刷新由调用方接管:点击刷新只对外发 `refresh` 通知,不在这里立即重载预览。
|
|
21
|
+
*
|
|
22
|
+
* 用于调用方需要"先重新取/重新生成附件、再重载"的场景(AttachmentPreview 配置了
|
|
23
|
+
* refresh-attachment 时会打开它)。否则一次点击会创建两个预览会话——先加载旧内容、
|
|
24
|
+
* 再加载新内容,既闪屏,又可能因为两次会话解析出的水印不同而看到"先没水印、后有水印"。
|
|
25
|
+
*/
|
|
26
|
+
deferRefresh?: boolean;
|
|
19
27
|
lostDescription?: string;
|
|
20
28
|
attachmentLost?: boolean;
|
|
21
29
|
};
|
|
@@ -61,6 +69,7 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
|
61
69
|
fileId: string;
|
|
62
70
|
fileType: string;
|
|
63
71
|
showHeader: boolean;
|
|
72
|
+
deferRefresh: boolean;
|
|
64
73
|
lostDescription: string;
|
|
65
74
|
attachmentLost: boolean;
|
|
66
75
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defineComponent as
|
|
2
|
-
切换时淡出过渡,避免 spinner 相位/进度条状态差异造成的跳动 `),I("div",
|
|
1
|
+
import{defineComponent as Me,useModel as Ie,ref as c,computed as m,watch as ee,nextTick as Le,onMounted as Re,onBeforeUnmount as Pe,openBlock as B,createElementBlock as W,normalizeClass as Oe,createBlock as A,unref as O,createCommentVNode as M,createElementVNode as I,createVNode as Te,Transition as ze,withCtx as H,normalizeStyle as be,createTextVNode as ke,mergeModels as te}from"vue";import{ElEmpty as Ze,ElButton as De,ElMessage as $}from"element-plus";import Ve from"../../api/DocumentApi.js";import We from"../../utils/FrameworkUtils.js";import Ae from"../../utils/fileDownload.js";import{resolveOfficeFileExt as He,canExportPdf as $e,MAX_RICH_PREVIEW_ZOOM as oe,MIN_OFFICE_ZOOM as ae,clampRichPreviewZoom as re,OFFICE_ZOOM_STEP as le}from"../../utils/officePreviewUtil.js";import qe from"./OfficePreviewHeaderBar.vue.js";import{_ as _e}from"../../../chunks/_plugin-vue_export-helper-DlAUqK2U.js";import"../../utils/request.js";import"../../utils/AxiosConfig.js";import"axios";import"../../utils/uuid.js";import"uuid";import"../../utils/encrypt.js";import"jsencrypt";import"../../utils/behaviorTrack.js";import"crypto-js/enc-base64";import"crypto-js/enc-utf8";import"../../utils/behaviorContext.js";import"../../utils/dateTime.js";import"../../utils/frontendBus.js";import"../../utils/globalLoading.js";import"../../utils/workflowTaskContext.js";import"../../config/GlobalLoadingConfig.js";import"xlsx-js-style";import"@element-plus/icons-vue";const Ue={class:"fileview-frame-wrap"},Xe={key:0,class:"preview-loading-overlay"},Qe=["src","title"],je=Me({__name:"OfficePreview",props:te({url:{default:""},fileId:{default:""},fileName:{default:""},fileType:{default:""},title:{default:""},showHeader:{type:Boolean,default:!0},showSearch:{type:Boolean,default:!0},showPageNav:{type:Boolean,default:!1},showZoom:{type:Boolean,default:!0},showDownload:{type:Boolean,default:!1},showRefresh:{type:Boolean,default:!1},showFullscreen:{type:Boolean,default:!1},showClose:{type:Boolean,default:!1},fullscreen:{type:Boolean,default:!1},downloadLoading:{type:Boolean,default:!1},refreshLoading:{type:Boolean,default:!1},deferRefresh:{type:Boolean,default:!1},lostDescription:{default:"附件已丢失或无权访问"},attachmentLost:{type:Boolean,default:!1}},{scale:{default:1},scaleModifiers:{}}),emits:te(["loaded","error","download","refresh","toggle-fullscreen","close"],["update:scale"]),setup(s,{expose:ne,emit:se}){const o=s,n=Ie(s,"scale"),v=se,g=c(""),x=c(null),E=c(!1),h=c(!1),L=c(""),d=c(""),S=c(-1),C=c(0),F=c(!1),u=c(!1),T=c(!1);let R=0;const ie=new Set(["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","html","htm","xml","json","md"]),ce=m(()=>L.value||o.lostDescription),q=m(()=>o.title||o.fileName),_=m(()=>He(o.fileType,o.fileName,o.url)),U=m(()=>o.showSearch&&!h.value&&ie.has(_.value)),de=m(()=>o.showZoom&&!h.value),ue=m(()=>o.showDownload&&$e(_.value)),fe=m(()=>o.downloadLoading||T.value),me=m(()=>u.value&&n.value!==1),ve=m(()=>{if(!me.value)return;const t=n.value;return{position:"absolute",top:"0",left:"0",width:`${100/t}%`,height:`${100/t}%`,transform:`scale(${t})`,transformOrigin:"top left"}}),z=t=>{x.value?.contentWindow?.postMessage({source:"adtec-office-preview",type:"command",...t},"*")},b=()=>{try{return x.value?.contentWindow||null}catch{return null}},k=t=>{const e=Number(t?.total||0);C.value=e,S.value=e>0?Number(t?.index||0):-1,e===0&&d.value&&$.warning("未找到匹配内容")},he=t=>{const e=t?.adtecFileViewAdapter;if(e?.zoom)try{return e.zoom(n.value),!0}catch{}try{const a=t?.document?.documentElement;if(a){const l=Math.max(ae,Math.min(oe,n.value));return a.style.zoom=String(l),a.style.width=`${100/l}%`,a.style.height=`${100/l}%`,!0}}catch{}return!1},N=()=>{!u.value&&he(b())||z({command:"zoom",scale:n.value})},X=()=>{n.value=re(n.value+le),N()},Q=()=>{n.value=re(n.value-le),N()},j=()=>{n.value=1,N()};let i={query:"",matches:[],index:-1};const we=(t,e)=>{const a=[],l=t.body;if(!l)return a;const r=e.toLocaleLowerCase(),w=t.createTreeWalker(l,NodeFilter.SHOW_TEXT,{acceptNode:f=>{const y=f.parentElement;return!y||!f.nodeValue||!f.nodeValue.trim()||y.closest("script, style, noscript, input, textarea, #wm_div_id")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}});let p=w.nextNode();for(;p;){const f=p.nodeValue?.toLocaleLowerCase()||"";let y=f.indexOf(r);for(;y!==-1;)a.push({node:p,start:y,end:y+e.length}),y=f.indexOf(r,y+Math.max(1,e.length));p=w.nextNode()}return a},pe=(t,e,a)=>{const l=t?.document;if(!l?.body)return null;(a==="first"||i.query!==e)&&(i={query:e,matches:we(l,e),index:-1});const r=i.matches.length;if(r===0)return{total:0,index:-1};a==="prev"?i.index=(i.index-1+r)%r:i.index=(i.index+1)%r;const w=i.matches[i.index];try{const p=l.createRange();p.setStart(w.node,w.start),p.setEnd(w.node,w.end);const f=t?.getSelection?.();f?.removeAllRanges(),f?.addRange(p),w.node.parentElement?.scrollIntoView({block:"center",behavior:"smooth"})}catch{}return{total:r,index:i.index}},Z=t=>{const e=d.value;if(!e)return;const a=b(),l=a?.adtecFileViewAdapter;if(l?.search)try{const r=l.search(e,t);r&&typeof r.then=="function"?r.then(k):k(r);return}catch{}if(!u.value){const r=pe(a,e,t);if(r){k(r);return}}z({command:"search",query:e,direction:t})},ye=()=>{i={query:"",matches:[],index:-1};const t=b(),e=t?.adtecFileViewAdapter;if(e?.clearSearch)try{e.clearSearch();return}catch{}if(!u.value)try{t?.getSelection?.()?.removeAllRanges()}catch{}z({command:"clear-search"})},ge=t=>{const e=t.trim();if(d.value=e,S.value=-1,C.value=0,!e){J();return}if(u.value){$.warning("当前预览服务不支持内容搜索,请下载后查看");return}Z("first")},J=()=>{d.value="",S.value=-1,C.value=0,ye()},xe=()=>{d.value&&Z("prev")},Ee=()=>{d.value&&Z("next")},G=t=>{if(!(t.source!==x.value?.contentWindow||t.data?.source!=="adtec-fileview")){if(t.data.type==="ready"){F.value=!0,u.value=!1,N();return}if(t.data.type==="search-result"){const e=Number(t.data.total||0);C.value=e,S.value=e>0?Number(t.data.index||0):-1,e===0&&d.value&&$.warning("未找到匹配内容")}}},P=new Set,Se=()=>{const t=x.value;if(!t)return null;try{const e=t.contentWindow;if(e?.parent&&e.parent!==e)return e.parent}catch{}return null},D=()=>{[window,Se()].forEach(e=>{if(!(!e||P.has(e)))try{e.addEventListener("message",G),P.add(e)}catch{}})},Ce=()=>{P.forEach(t=>{try{t.removeEventListener("message",G)}catch{}}),P.clear()},K=async()=>{const t=++R;if(g.value="",E.value=!1,h.value=!1,L.value="",n.value=1,d.value="",S.value=-1,C.value=0,F.value=!1,u.value=!1,o.attachmentLost){h.value=!0,v("error");return}E.value=!0;try{if(o.fileId){const e=await Ve.createPreviewSession(o.fileId);if(t!==R)return;g.value=e.url;return}if(o.url.startsWith("/api/doc/preview/fileView/")){g.value=o.url;return}throw new Error("为保护附件地址,旧版文件直链已停止预览,请使用附件 ID 打开")}catch(e){if(t!==R)return;E.value=!1,h.value=!0,L.value=e?.msg||e?.message||"文件预览失败,请下载后查看",v("error",e)}},Y=()=>{K()},Fe=()=>{v("refresh"),!o.deferRefresh&&Y()},V=async(t="original")=>{if(v("download",t),!!o.fileId){T.value=!0;try{await Ae(o.fileId,o.fileName,t)}catch(e){We.messageError(e)}finally{T.value=!1}}},Be=()=>{E.value=!1,D();const t=x.value?.contentWindow;if(t&&!F.value)try{t.adtecPreviewBridge&&(F.value=!0,u.value=!1)}catch{}F.value||window.setTimeout(()=>{F.value||(u.value=!0)},1500),N(),v("loaded")},Ne=t=>{E.value=!1,h.value=!0,L.value="文件预览服务暂不可用,请稍后重试或下载后查看",v("error",t)};return ee(()=>[o.fileId,o.url,o.attachmentLost],()=>void K(),{immediate:!0}),ee(g,t=>{t&&Le(()=>D())}),Re(()=>D()),Pe(()=>{R++,Ce()}),ne({reloadPreview:Y,zoomIn:X,zoomOut:Q,resetZoom:j,download:V}),(t,e)=>(B(),W("div",{class:Oe(["office-preview-root",{"is-fullscreen":s.fullscreen}])},[s.showHeader?(B(),A(qe,{key:0,title:q.value,"title-only":!U.value,zoom:n.value,"search-query":d.value,"search-index":S.value,"search-total":C.value,"show-search":U.value,"show-page-nav":!1,"show-zoom":de.value,"show-download":s.showDownload,"pdf-export":ue.value,"show-refresh":s.showRefresh,"show-fullscreen":s.showFullscreen,"show-close":s.showClose,fullscreen:s.fullscreen,"download-loading":fe.value,"refresh-loading":s.refreshLoading,"min-zoom":O(ae),"max-zoom":O(oe),onZoomIn:X,onZoomOut:Q,onZoomReset:j,onSearch:ge,onSearchClear:J,onSearchPrev:xe,onSearchNext:Ee,onDownload:V,onRefresh:Fe,onToggleFullscreen:e[0]||(e[0]=a=>v("toggle-fullscreen")),onClose:e[1]||(e[1]=a=>v("close"))},null,8,["title","title-only","zoom","search-query","search-index","search-total","show-search","show-zoom","show-download","pdf-export","show-refresh","show-fullscreen","show-close","fullscreen","download-loading","refresh-loading","min-zoom","max-zoom"])):M("v-if",!0),M(` 外层加载层与预览页内层样式完全一致(spinner + 正在加载文件... + 进度条),
|
|
2
|
+
切换时淡出过渡,避免 spinner 相位/进度条状态差异造成的跳动 `),I("div",Ue,[Te(ze,{name:"preview-loading-fade"},{default:H(()=>[E.value?(B(),W("div",Xe,[...e[3]||(e[3]=[I("div",{class:"preview-loading-spinner"},null,-1),I("div",{class:"preview-loading-text"},"正在加载文件...",-1),I("div",{class:"preview-loading-progress"},[I("div",{class:"preview-loading-bar is-indeterminate"})],-1)])])):M("v-if",!0)]),_:1}),g.value&&!h.value?(B(),W("iframe",{key:g.value,ref_key:"previewFrameRef",ref:x,class:"fileview-frame",style:be(ve.value),src:g.value,title:q.value||"文件预览",referrerpolicy:"same-origin",onLoad:Be,onError:Ne},null,44,Qe)):h.value?(B(),A(O(Ze),{key:1,description:ce.value},{default:H(()=>[s.showDownload?(B(),A(O(De),{key:0,type:"primary",onClick:e[2]||(e[2]=a=>V())},{default:H(()=>[...e[4]||(e[4]=[ke(" 下载文件 ",-1)])]),_:1})):M("v-if",!0)]),_:1},8,["description"])):M("v-if",!0)])],2))}}),St=_e(je,[["__scopeId","data-v-d048ae89"]]);export{St as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import y from"axios";import{createUuid as f}from"./uuid.js";import S from"./encrypt.js";import{getCurrentMenu as v,getBehaviorParentId as A,reportApiCall as h}from"./behaviorTrack.js";import{buildRequestContext as P}from"./behaviorContext.js";import{ElMessage as I}from"element-plus";import{frontendBus as C}from"./frontendBus.js";import{notifyGlobalLoading as w}from"./globalLoading.js";import{getWorkflowTaskContext as q}from"./workflowTaskContext.js";import{getGlobalLoadingIgnoredPaths as x}from"../config/GlobalLoadingConfig.js";import"uuid";import"jsencrypt";import"crypto-js/enc-base64";import"crypto-js/enc-utf8";import"./dateTime.js";import"vue";let n=!1;const T=()=>{C.emit("loginAgain")};let d=[];const i=y.create({timeout:6e4,validateStatus(e){return e>=200&&e<500}}),k=e=>{const a=String(e?.url||"").split(/[?#]/,1)[0];return!x().includes(a)},c=e=>{if(!k(e))return;const a=e?.__globalLoadingId;a&&(w({phase:"finish",id:a}),delete e.__globalLoadingId)},p=e=>{if(!k(e))return;const a=f();e.__globalLoadingId=a,w({phase:"start",id:a})};function L(e){const a=e.skipAuthorization?"":sessionStorage.getItem("Authorization");if(e.headers.sessionId=e.skipAuthorization?"":sessionStorage.getItem("sessionId"),e.headers.Authorization=a,!e.debounceKey){const u=e.method==="get"?e.params:e.data;try{e.debounceKey=typeof u=="string"?u:JSON.stringify(u??"")}catch{e.debounceKey=String(u??"")}}const t=e.menuId||v()?.id,s=e.behaviorContext||P(e.behavior);e.behaviorContext=s,e.headers["X-Menu-Id"]=t||"",e.headers["X-Behavior-Id"]=s?.pageViewId||t&&A(t)||"",e.headers["X-Behavior-Page-Id"]=s?.pageViewId||"",e.headers["X-Behavior-Action-Id"]=s?.actionId||"",e.headers["X-Behavior-Request-Id"]=s?.requestId||"",e.headers["X-Behavior-Association"]=s?.associationMode||"PAGE_ONLY";const o=q();e.headers["X-Workflow-Task-Id"]=o.taskId||"",e.headers["X-Workflow-Business-Id"]=o.businessId||"",e.headers["X-Workflow-Proc-Ins-Id"]=o.procInsId||"";const r=sessionStorage.getItem("timeDifference"),l=f(),m=new Date().getTime(),b={timeDifference:r,guid:l,localTime:m};e.headers.replayToken=S.encrypt(JSON.stringify(b))}const g=new Map;i.interceptors.request.use(e=>{if(L(e),e.isAntiShake){const a=e.antiShakeTime,t=`${e.method}-${e.url}-${e.debounceKey}`,s=g.get(t);return s&&s(),new Promise(o=>{const r=setTimeout(()=>{clearTimeout(r),p(e),o(e)},a);g.set(t,()=>{clearTimeout(r)})})}else return p(e),e},e=>(c(e?.config),Promise.resolve(e)));i.interceptors.response.use(async e=>{const{status:a,data:t,config:s}=e;if(c(s),a===200){if(t.code==="0")return Promise.resolve(e);if(t.code=="10508")n=!0;else if(t.code=="10401"&&s.url!=="/api/system/login/refreshToken"&&sessionStorage.getItem("Authorization")&&sessionStorage.getItem("refreshToken")){if(n)return new Promise(o=>{d.push({fn:()=>{o(i(s))},url:s.url})});{n=!0;const o=sessionStorage.getItem("refreshToken"),r=await i.post("/api/system/login/refreshToken",{rToken:o});if(r.data.code==="0"){sessionStorage.setItem("Authorization",r.data.data.token),sessionStorage.setItem("refreshToken",r.data.data.refreshToken);const l=i(s);return d.forEach(m=>{m.fn()}),n=!1,d=[],l}else throw n=!1,d=[],I.warning({showClose:!0,message:"用户信息已过期,请重新登录",grouping:!0}),T(),{code:"10508",msg:"用户信息已过期,请重新登录",url:s.url,config:s}}}else return Promise.resolve(e)}return Promise.resolve(e)},e=>(c(e?.config||e?.response?.config),Promise.reject(e)));const V=e=>{const a=Date.now();return i(e).then(t=>{const s=t.config||e;if(t.status===500)throw{code:t.status+"",msg:t.status+t.statusText,url:e.url,status:t.status,config:s};if(t.status!==200)throw{code:t.status+"",msg:t.status+t.statusText,url:e.url,status:t.status,config:s};if(e.responseType==="blob")return h({config:s,status:t.status,costTime:Date.now()-a}),t;{const o=t.data;if(o.code==="0")return h({config:s,status:t.status,code:o.code,costTime:Date.now()-a}),o.data;throw o.code=="10508"?(I.warning({showClose:!0,message:"用户信息已过期,请重新登录",grouping:!0}),T(),{code:o.code,msg:o.msg,url:e.url,config:s}):{code:o.code,msg:o.msg,url:e.url,status:t.status,config:s}}}).catch(t=>{const s=t?.config||t?.response?.config||e;throw h({config:s,status:t?.status||t?.response?.status,code:t?.code,error:t,costTime:Date.now()-a}),t.msg?t:{code:t.response?.status?t.response.status+"":t.code||"500",msg:t.message||"请求失败",url:e.url}})};export{V as default};
|
|
1
|
+
import y from"axios";import{createUuid as f}from"./uuid.js";import S from"./encrypt.js";import{getCurrentMenu as v,getBehaviorParentId as A,reportApiCall as h}from"./behaviorTrack.js";import{buildRequestContext as P}from"./behaviorContext.js";import{ElMessage as I}from"element-plus";import{frontendBus as C}from"./frontendBus.js";import{notifyGlobalLoading as w}from"./globalLoading.js";import{getWorkflowTaskContext as q}from"./workflowTaskContext.js";import{getGlobalLoadingIgnoredPaths as x}from"../config/GlobalLoadingConfig.js";import"uuid";import"jsencrypt";import"crypto-js/enc-base64";import"crypto-js/enc-utf8";import"./dateTime.js";import"vue";let n=!1;const T=()=>{C.emit("loginAgain")};let d=[];const i=y.create({timeout:6e4,validateStatus(e){return e>=200&&e<500}}),k=e=>{if(e?.skipGlobalLoading===!0)return!1;const a=String(e?.url||"").split(/[?#]/,1)[0];return!x().includes(a)},c=e=>{if(!k(e))return;const a=e?.__globalLoadingId;a&&(w({phase:"finish",id:a}),delete e.__globalLoadingId)},p=e=>{if(!k(e))return;const a=f();e.__globalLoadingId=a,w({phase:"start",id:a})};function L(e){const a=e.skipAuthorization?"":sessionStorage.getItem("Authorization");if(e.headers.sessionId=e.skipAuthorization?"":sessionStorage.getItem("sessionId"),e.headers.Authorization=a,!e.debounceKey){const u=e.method==="get"?e.params:e.data;try{e.debounceKey=typeof u=="string"?u:JSON.stringify(u??"")}catch{e.debounceKey=String(u??"")}}const t=e.menuId||v()?.id,s=e.behaviorContext||P(e.behavior);e.behaviorContext=s,e.headers["X-Menu-Id"]=t||"",e.headers["X-Behavior-Id"]=s?.pageViewId||t&&A(t)||"",e.headers["X-Behavior-Page-Id"]=s?.pageViewId||"",e.headers["X-Behavior-Action-Id"]=s?.actionId||"",e.headers["X-Behavior-Request-Id"]=s?.requestId||"",e.headers["X-Behavior-Association"]=s?.associationMode||"PAGE_ONLY";const o=q();e.headers["X-Workflow-Task-Id"]=o.taskId||"",e.headers["X-Workflow-Business-Id"]=o.businessId||"",e.headers["X-Workflow-Proc-Ins-Id"]=o.procInsId||"";const r=sessionStorage.getItem("timeDifference"),l=f(),m=new Date().getTime(),b={timeDifference:r,guid:l,localTime:m};e.headers.replayToken=S.encrypt(JSON.stringify(b))}const g=new Map;i.interceptors.request.use(e=>{if(L(e),e.isAntiShake){const a=e.antiShakeTime,t=`${e.method}-${e.url}-${e.debounceKey}`,s=g.get(t);return s&&s(),new Promise(o=>{const r=setTimeout(()=>{clearTimeout(r),p(e),o(e)},a);g.set(t,()=>{clearTimeout(r)})})}else return p(e),e},e=>(c(e?.config),Promise.resolve(e)));i.interceptors.response.use(async e=>{const{status:a,data:t,config:s}=e;if(c(s),a===200){if(t.code==="0")return Promise.resolve(e);if(t.code=="10508")n=!0;else if(t.code=="10401"&&s.url!=="/api/system/login/refreshToken"&&sessionStorage.getItem("Authorization")&&sessionStorage.getItem("refreshToken")){if(n)return new Promise(o=>{d.push({fn:()=>{o(i(s))},url:s.url})});{n=!0;const o=sessionStorage.getItem("refreshToken"),r=await i.post("/api/system/login/refreshToken",{rToken:o});if(r.data.code==="0"){sessionStorage.setItem("Authorization",r.data.data.token),sessionStorage.setItem("refreshToken",r.data.data.refreshToken);const l=i(s);return d.forEach(m=>{m.fn()}),n=!1,d=[],l}else throw n=!1,d=[],I.warning({showClose:!0,message:"用户信息已过期,请重新登录",grouping:!0}),T(),{code:"10508",msg:"用户信息已过期,请重新登录",url:s.url,config:s}}}else return Promise.resolve(e)}return Promise.resolve(e)},e=>(c(e?.config||e?.response?.config),Promise.reject(e)));const V=e=>{const a=Date.now();return i(e).then(t=>{const s=t.config||e;if(t.status===500)throw{code:t.status+"",msg:t.status+t.statusText,url:e.url,status:t.status,config:s};if(t.status!==200)throw{code:t.status+"",msg:t.status+t.statusText,url:e.url,status:t.status,config:s};if(e.responseType==="blob")return h({config:s,status:t.status,costTime:Date.now()-a}),t;{const o=t.data;if(o.code==="0")return h({config:s,status:t.status,code:o.code,costTime:Date.now()-a}),o.data;throw o.code=="10508"?(I.warning({showClose:!0,message:"用户信息已过期,请重新登录",grouping:!0}),T(),{code:o.code,msg:o.msg,url:e.url,config:s}):{code:o.code,msg:o.msg,url:e.url,status:t.status,config:s}}}).catch(t=>{const s=t?.config||t?.response?.config||e;throw h({config:s,status:t?.status||t?.response?.status,code:t?.code,error:t,costTime:Date.now()-a}),t.msg?t:{code:t.response?.status?t.response.status+"":t.code||"500",msg:t.message||"请求失败",url:e.url}})};export{V as default};
|
|
@@ -7,6 +7,12 @@ export interface RequestOptions {
|
|
|
7
7
|
logSuccess?: boolean;
|
|
8
8
|
};
|
|
9
9
|
skipBehavior?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 跳过全局/弹窗请求 loading。
|
|
12
|
+
* 适用于自身已有加载态的内部请求(如附件预览会话:预览区自己有加载层),
|
|
13
|
+
* 避免它们点亮整页 loading 或弹窗/抽屉级 loading。
|
|
14
|
+
*/
|
|
15
|
+
skipGlobalLoading?: boolean;
|
|
10
16
|
}
|
|
11
17
|
declare const _default: {
|
|
12
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"./AxiosConfig.js";import"axios";import"./uuid.js";import"uuid";import"./encrypt.js";import"jsencrypt";import"./behaviorTrack.js";import"crypto-js/enc-base64";import"crypto-js/enc-utf8";import"./behaviorContext.js";import"./dateTime.js";import"element-plus";import"./frontendBus.js";import"./globalLoading.js";import"vue";import"./workflowTaskContext.js";import"../config/GlobalLoadingConfig.js";const A={get(e,i,t=!1,a=500,m){return r({url:e,method:"get",params:this.trimObjectSpaces(i),isAntiShake:t,antiShakeTime:a,menuId:m})},post(e,i,t=!1,a=500,m){return r({url:e,method:"post",data:this.trimObjectSpaces(i),isAntiShake:t,antiShakeTime:a,menuId:m})},getWithOptions(e,i,t={}){return r({url:e,method:"get",params:this.trimObjectSpaces(i),isAntiShake:t.isAntiShake||!1,antiShakeTime:t.antiShakeTime||500,menuId:t.menuId,behavior:t.behavior,skipBehavior:t.skipBehavior})},postWithOptions(e,i,t={}){return r({url:e,method:"post",data:this.trimObjectSpaces(i),isAntiShake:t.isAntiShake||!1,antiShakeTime:t.antiShakeTime||500,menuId:t.menuId,behavior:t.behavior,skipBehavior:t.skipBehavior})},trimObjectSpaces(e){if(typeof e!="object"||e===null)return e;for(const i in e)if(e.hasOwnProperty(i)){const t=e[i];typeof t=="string"?e[i]=t.trim():typeof t=="object"&&this.trimObjectSpaces(t)}return e}};export{A as default};
|
|
1
|
+
import r from"./AxiosConfig.js";import"axios";import"./uuid.js";import"uuid";import"./encrypt.js";import"jsencrypt";import"./behaviorTrack.js";import"crypto-js/enc-base64";import"crypto-js/enc-utf8";import"./behaviorContext.js";import"./dateTime.js";import"element-plus";import"./frontendBus.js";import"./globalLoading.js";import"vue";import"./workflowTaskContext.js";import"../config/GlobalLoadingConfig.js";const A={get(e,i,t=!1,a=500,m){return r({url:e,method:"get",params:this.trimObjectSpaces(i),isAntiShake:t,antiShakeTime:a,menuId:m})},post(e,i,t=!1,a=500,m){return r({url:e,method:"post",data:this.trimObjectSpaces(i),isAntiShake:t,antiShakeTime:a,menuId:m})},getWithOptions(e,i,t={}){return r({url:e,method:"get",params:this.trimObjectSpaces(i),isAntiShake:t.isAntiShake||!1,antiShakeTime:t.antiShakeTime||500,menuId:t.menuId,behavior:t.behavior,skipBehavior:t.skipBehavior,skipGlobalLoading:t.skipGlobalLoading})},postWithOptions(e,i,t={}){return r({url:e,method:"post",data:this.trimObjectSpaces(i),isAntiShake:t.isAntiShake||!1,antiShakeTime:t.antiShakeTime||500,menuId:t.menuId,behavior:t.behavior,skipBehavior:t.skipBehavior,skipGlobalLoading:t.skipGlobalLoading})},trimObjectSpaces(e){if(typeof e!="object"||e===null)return e;for(const i in e)if(e.hasOwnProperty(i)){const t=e[i];typeof t=="string"?e[i]=t.trim():typeof t=="object"&&this.trimObjectSpaces(t)}return e}};export{A as default};
|