数据可视化大屏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
4.8KB

  1. import{$b as v,A as O,H as b,J as C,Jc as m,Wc as u,Z as p,a as y,ha as l,ja as g,ka as A,la as c,m as d,o as w,p as S,qc as T,tc as x,za as I}from"./chunk-VDRVUQCF.js";var U={store_key:"_token",token_invalid_redirect:!0,token_exp_offset:10,token_send_key:"token",token_send_template:"${token}",token_send_place:"header",login_url:"/login",refreshTime:3e3,refreshOffset:6e3};function E(e){return e.merge("auth",U)}function j(){return new h}var h=class{get(t){return JSON.parse(localStorage.getItem(t)||"{}")||{}}set(t,i){return localStorage.setItem(t,JSON.stringify(i)),!0}remove(t){localStorage.removeItem(t)}},D=new g("AUTH_STORE_TOKEN",{providedIn:"root",factory:j});function L(){return new F(c(u))}var F=(()=>{let t=class t{constructor(n){this.store=c(D),this.refresh$=new w,this.change$=new S(null),this._referrer={},this._options=E(n)}get refresh(){return this.builderRefresh(),this.refresh$.pipe(p())}get login_url(){return this._options.login_url}get referrer(){return this._referrer}get options(){return this._options}set(n){let r=this.store.set(this._options.store_key,n);return this.change$.next(n),r}get(n){let r=this.store.get(this._options.store_key);return n?Object.assign(new n,r):r}clear(n={onlyToken:!1}){let r=null;n.onlyToken===!0?(r=this.get(),r.token="",this.set(r)):this.store.remove(this._options.store_key),this.change$.next(r)}change(){return this.change$.pipe(p())}builderRefresh(){let{refreshTime:n,refreshOffset:r}=this._options;this.cleanRefresh(),this.interval$=b(n).pipe(O(()=>{let o=this.get(),s=o.expired||o.exp||0;if(s<=0)return null;let a=new Date().valueOf()+r;return s<=a?o:null}),C(o=>o!=null)).subscribe(o=>this.refresh$.next(o))}cleanRefresh(){this.interval$&&!this.interval$.closed&&this.interval$.unsubscribe()}ngOnDestroy(){this.cleanRefresh()}};t.\u0275fac=function(r){return new(r||t)(A(u))},t.\u0275prov=l({token:t,factory:t.\u0275fac});let e=t;return e})(),f=new g("DA_SERVICE_TOKEN",{providedIn:"root",factory:L}),_="_delonAuthSocialType",k="_delonAuthSocialCallbackByHref",te=(()=>{let t=class t{constructor(){this.tokenService=c(f),this.doc=c(v),this.router=c(m),this._win=null}login(n,r="/",o={}){if(o=y({type:"window",windowFeatures:"location=yes,height=570,width=520,scrollbars=yes,status=yes"},o),localStorage.setItem(_,o.type),localStorage.setItem(k,r),o.type==="href"){this.doc.location.href=n;return}return this._win=window.open(n,"_blank",o.windowFeatures),this._winTime=setInterval(()=>{if(this._win&&this._win.closed){this.ngOnDestroy();let s=this.tokenService.get();s&&!s.token&&(s=null),s&&this.tokenService.set(s),this.observer.next(s),this.observer.complete()}},100),new d(s=>{this.observer=s})}callback(n){if(!n&&this.router.url.indexOf("?")===-1)throw new Error("url muse contain a ?");let r={token:""};if(typeof n=="string"){let a=n.split("?")[1].split("#")[0];r=this.router.parseUrl(`./?${a}`).queryParams}else r=n;if(!r||!r.token)throw new Error("invalide token data");this.tokenService.set(r);let o=localStorage.getItem(k)||"/";localStorage.removeItem(k);let s=localStorage.getItem(_);return localStorage.removeItem(_),s==="window"?window.close():this.router.navigateByUrl(o),r}ngOnDestroy(){clearInterval(this._winTime),this._winTime=null}};t.\u0275fac=function(r){return new(r||t)},t.\u0275prov=l({token:t,factory:t.\u0275fac});let e=t;return e})();function N(e){return e!=null&&typeof e.token=="string"&&e.token.length>0}function R(e,t){let i=c(m),n=c(f),r=c(v);n.referrer.url=t||i.url,e.token_invalid_redirect===!0&&setTimeout(()=>{/^https?:\/\//g.test(e.login_url)?r.location.href=e.login_url:i.navigate([e.login_url])})}var J=new T(()=>!1);function H(e,t){if(e.context.get(J))return!0;if(Array.isArray(t.ignores)){for(let i of t.ignores)if(i.test(e.url))return!0}return!1}function P(e,t){return R(t),new d(i=>{let n="",r=new x({url:e.url,headers:e.headers,status:401,statusText:n});i.error(r)})}var $=(()=>{let t=class t{constructor(){this.srv=c(f)}process(n){let r=N(this.srv.get());return r||R(this.srv.options,n),r}};t.\u0275fac=function(r){return new(r||t)},t.\u0275prov=l({token:t,factory:t.\u0275fac,providedIn:"root"});let e=t;return e})(),re=(e,t)=>c($).process(t.url),ne=(e,t)=>c($).process(t.url);function B(e,t,i){let{token_send_template:n,token_send_key:r}=i,o=n.replace(/\$\{([\w]+)\}/g,(s,a)=>t[a]);switch(i.token_send_place){case"header":let s={};s[r]=o,e=e.clone({setHeaders:s});break;case"body":let a=e.body||{};a[r]=o,e=e.clone({body:a});break;case"url":e=e.clone({params:e.params.append(r,o)});break}return e}var oe=(e,t)=>{let i=E(c(u));if(H(e,i))return t(e);let n=c(f).get();return N(n)?t(B(e,n,i)):P(e,i)};var M=function(e){return e[e.Store=0]="Store",e}(M||{});function K(e,t){return{\u0275kind:e,\u0275providers:t}}function se(e){return I([(e??W()).\u0275providers])}function W(){return K(M.Store,[{provide:D,useClass:h}])}export{f as a,te as b,J as c,re as d,ne as e,oe as f,se as g};