@kevisual/kv-login 0.1.4 → 0.1.14
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/assets/index-CyXnpqtU.js +469 -0
- package/dist/index.html +127 -0
- package/package.json +9 -7
- package/src/main.ts +6 -1
- package/src/modules/login-handle.ts +33 -14
- package/src/modules/query.ts +8 -3
- package/src/pages/kv-login.ts +45 -9
- package/dist/app.d.ts +0 -115
- package/dist/app.js +0 -6518
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&n(i)}).observe(document,{childList:!0,subtree:!0});function t(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(s){if(s.ep)return;s.ep=!0;const o=t(s);fetch(s.href,o)}})();const et=globalThis,lt=r=>r,ge=et.trustedTypes,ht=ge?ge.createPolicy("lit-html",{createHTML:r=>r}):void 0,sn="$lit$",V=`lit$${Math.random().toFixed(9).slice(2)}$`,rn="?"+V,_n=`<${rn}>`,Q=document,oe=()=>Q.createComment(""),ie=r=>r===null||typeof r!="object"&&typeof r!="function",tt=Array.isArray,Rn=r=>tt(r)||typeof r?.[Symbol.iterator]=="function",Ce=`[
|
|
2
|
+
\f\r]`,se=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,dt=/-->/g,ft=/>/g,O=RegExp(`>|${Ce}(?:([^\\s"'>=/]+)(${Ce}*=${Ce}*(?:[^
|
|
3
|
+
\f\r"'\`<>=]|("|')|))|$)`,"g"),gt=/'/g,mt=/"/g,on=/^(?:script|style|textarea|title)$/i,In=r=>(e,...t)=>({_$litType$:r,strings:e,values:t}),D=In(1),ee=Symbol.for("lit-noChange"),I=Symbol.for("lit-nothing"),pt=new WeakMap,K=Q.createTreeWalker(Q,129);function an(r,e){if(!tt(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return ht!==void 0?ht.createHTML(e):e}const Dn=(r,e)=>{const t=r.length-1,n=[];let s,o=e===2?"<svg>":e===3?"<math>":"",i=se;for(let c=0;c<t;c++){const a=r[c];let u,l,h=-1,m=0;for(;m<a.length&&(i.lastIndex=m,l=i.exec(a),l!==null);)m=i.lastIndex,i===se?l[1]==="!--"?i=dt:l[1]!==void 0?i=ft:l[2]!==void 0?(on.test(l[2])&&(s=RegExp("</"+l[2],"g")),i=O):l[3]!==void 0&&(i=O):i===O?l[0]===">"?(i=s??se,h=-1):l[1]===void 0?h=-2:(h=i.lastIndex-l[2].length,u=l[1],i=l[3]===void 0?O:l[3]==='"'?mt:gt):i===mt||i===gt?i=O:i===dt||i===ft?i=se:(i=O,s=void 0);const g=i===O&&r[c+1].startsWith("/>")?" ":"";o+=i===se?a+_n:h>=0?(n.push(u),a.slice(0,h)+sn+a.slice(h)+V+g):a+V+(h===-2?c:g)}return[an(r,o+(r[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),n]};class ae{constructor({strings:e,_$litType$:t},n){let s;this.parts=[];let o=0,i=0;const c=e.length-1,a=this.parts,[u,l]=Dn(e,t);if(this.el=ae.createElement(u,n),K.currentNode=this.el.content,t===2||t===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(s=K.nextNode())!==null&&a.length<c;){if(s.nodeType===1){if(s.hasAttributes())for(const h of s.getAttributeNames())if(h.endsWith(sn)){const m=l[i++],g=s.getAttribute(h).split(V),d=/([.?@])?(.*)/.exec(m);a.push({type:1,index:o,name:d[2],strings:g,ctor:d[1]==="."?Un:d[1]==="?"?qn:d[1]==="@"?Pn:ye}),s.removeAttribute(h)}else h.startsWith(V)&&(a.push({type:6,index:o}),s.removeAttribute(h));if(on.test(s.tagName)){const h=s.textContent.split(V),m=h.length-1;if(m>0){s.textContent=ge?ge.emptyScript:"";for(let g=0;g<m;g++)s.append(h[g],oe()),K.nextNode(),a.push({type:2,index:++o});s.append(h[m],oe())}}}else if(s.nodeType===8)if(s.data===rn)a.push({type:2,index:o});else{let h=-1;for(;(h=s.data.indexOf(V,h+1))!==-1;)a.push({type:7,index:o}),h+=V.length-1}o++}}static createElement(e,t){const n=Q.createElement("template");return n.innerHTML=e,n}}function te(r,e,t=r,n){if(e===ee)return e;let s=n!==void 0?t._$Co?.[n]:t._$Cl;const o=ie(e)?void 0:e._$litDirective$;return s?.constructor!==o&&(s?._$AO?.(!1),o===void 0?s=void 0:(s=new o(r),s._$AT(r,t,n)),n!==void 0?(t._$Co??=[])[n]=s:t._$Cl=s),s!==void 0&&(e=te(r,s._$AS(r,e.values),s,n)),e}class Mn{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:n}=this._$AD,s=(e?.creationScope??Q).importNode(t,!0);K.currentNode=s;let o=K.nextNode(),i=0,c=0,a=n[0];for(;a!==void 0;){if(i===a.index){let u;a.type===2?u=new ue(o,o.nextSibling,this,e):a.type===1?u=new a.ctor(o,a.name,a.strings,this,e):a.type===6&&(u=new Bn(o,this,e)),this._$AV.push(u),a=n[++c]}i!==a?.index&&(o=K.nextNode(),i++)}return K.currentNode=Q,s}p(e){let t=0;for(const n of this._$AV)n!==void 0&&(n.strings!==void 0?(n._$AI(e,n,t),t+=n.strings.length-2):n._$AI(e[t])),t++}}class ue{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,t,n,s){this.type=2,this._$AH=I,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=n,this.options=s,this._$Cv=s?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&e?.nodeType===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=te(this,e,t),ie(e)?e===I||e==null||e===""?(this._$AH!==I&&this._$AR(),this._$AH=I):e!==this._$AH&&e!==ee&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Rn(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==I&&ie(this._$AH)?this._$AA.nextSibling.data=e:this.T(Q.createTextNode(e)),this._$AH=e}$(e){const{values:t,_$litType$:n}=e,s=typeof n=="number"?this._$AC(e):(n.el===void 0&&(n.el=ae.createElement(an(n.h,n.h[0]),this.options)),n);if(this._$AH?._$AD===s)this._$AH.p(t);else{const o=new Mn(s,this),i=o.u(this.options);o.p(t),this.T(i),this._$AH=o}}_$AC(e){let t=pt.get(e.strings);return t===void 0&&pt.set(e.strings,t=new ae(e)),t}k(e){tt(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let n,s=0;for(const o of e)s===t.length?t.push(n=new ue(this.O(oe()),this.O(oe()),this,this.options)):n=t[s],n._$AI(o),s++;s<t.length&&(this._$AR(n&&n._$AB.nextSibling,s),t.length=s)}_$AR(e=this._$AA.nextSibling,t){for(this._$AP?.(!1,!0,t);e!==this._$AB;){const n=lt(e).nextSibling;lt(e).remove(),e=n}}setConnected(e){this._$AM===void 0&&(this._$Cv=e,this._$AP?.(e))}}class ye{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,n,s,o){this.type=1,this._$AH=I,this._$AN=void 0,this.element=e,this.name=t,this._$AM=s,this.options=o,n.length>2||n[0]!==""||n[1]!==""?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=I}_$AI(e,t=this,n,s){const o=this.strings;let i=!1;if(o===void 0)e=te(this,e,t,0),i=!ie(e)||e!==this._$AH&&e!==ee,i&&(this._$AH=e);else{const c=e;let a,u;for(e=o[0],a=0;a<o.length-1;a++)u=te(this,c[n+a],t,a),u===ee&&(u=this._$AH[a]),i||=!ie(u)||u!==this._$AH[a],u===I?e=I:e!==I&&(e+=(u??"")+o[a+1]),this._$AH[a]=u}i&&!s&&this.j(e)}j(e){e===I?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class Un extends ye{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===I?void 0:e}}class qn extends ye{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==I)}}class Pn extends ye{constructor(e,t,n,s,o){super(e,t,n,s,o),this.type=5}_$AI(e,t=this){if((e=te(this,e,t,0)??I)===ee)return;const n=this._$AH,s=e===I&&n!==I||e.capture!==n.capture||e.once!==n.once||e.passive!==n.passive,o=e!==I&&(n===I||s);s&&this.element.removeEventListener(this.name,this,n),o&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,e):this._$AH.handleEvent(e)}}class Bn{constructor(e,t,n){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=n}get _$AU(){return this._$AM._$AU}_$AI(e){te(this,e)}}const Nn=et.litHtmlPolyfillSupport;Nn?.(ae,ue),(et.litHtmlVersions??=[]).push("3.3.2");const cn=(r,e,t)=>{const n=e;let s=n._$litPart$;return s===void 0&&(n._$litPart$=s=new ue(e.insertBefore(oe(),null),null,void 0,{})),s._$AI(r),s};const $n={CHILD:2},Fn=r=>(...e)=>({_$litDirective$:r,values:e});class zn{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,t,n){this._$Ct=e,this._$AM=t,this._$Ci=n}_$AS(e,t){return this.update(e,t)}update(e,t){return this.render(...t)}}class Ze extends zn{constructor(e){if(super(e),this.it=I,e.type!==$n.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===I||e==null)return this._t=void 0,this.it=e;if(e===ee)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;const t=[e];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}}Ze.directiveName="unsafeHTML",Ze.resultType=1;const wt=Fn(Ze);var jn=r=>r?["text/","xml","html","javascript","css","csv","plain","x-www-form-urlencoded","md","json"].some(t=>r.includes(t)):!1,yt=async(r={},e)=>{const t=new AbortController,n=t.signal,s=r.isPostFile||!1,o=r.timeout||6e4*3,i=setTimeout(()=>{t.abort()},o);let c=e?.method||r?.method||"POST",a={...r?.headers,...e?.headers},u="",l;r?.url?.startsWith("http")?l=new URL(r.url):(u=globalThis?.location?.origin||"http://localhost:51515",l=new URL(r?.url||"",u));const h=c==="GET",m=l.searchParams;if(h){let d=new URLSearchParams({...Object.fromEntries(m),...r?.params,...r?.body});l.search=d.toString()}else{const d={...Object.fromEntries(m),...r.params},w=new URLSearchParams(d);if(typeof r.body=="object"&&r.body!==null){let f=r.body||{};!d.path&&f?.path&&(w.set("path",f.path),f?.key&&w.set("key",f.key))}l.search=w.toString()}let g;return h?g=void 0:s?g=r.body:r.body&&typeof r.body=="object"&&!(r.body instanceof FormData)&&(a={"Content-Type":"application/json",...a},g=JSON.stringify(r.body)),fetch(l,{method:c.toUpperCase(),signal:n,body:g,...e,headers:a}).then(async d=>{const w=d.headers.get("Content-Type"),f=w&&w.includes("application/json"),y=d.ok;if(f){const v=await d.json();return v?.code?v:{code:y?200:d.status,status:d.status,data:v}}else return jn(w)?{code:y?200:d.status,status:d.status,data:await d.text()}:{code:y?200:d.status,status:d.status,data:"非文本非JSON响应, 请手动处理response。",response:d}}).catch(d=>d.name==="AbortError"?{code:408,message:"请求超时"}:{code:500,message:d.message||"网络错误"}).finally(()=>{clearTimeout(i)})},he=({code:r,message:e})=>({code:r||500,message:e||"请求错误"});let nt=class{adapter;baseURL;url;beforeRequest;afterResponse;headers;timeout;stop;qws;tokenName;storage;token;constructor(e){this.adapter=e?.adapter||yt,this.tokenName=e?.tokenName||"token",this.storage=e?.storage||globalThis?.localStorage;const t=e?.isClient?"/client/router":"/api/router";if(this.url=e?.url||t,this.url.startsWith("http")){const n=new URL(this.url);this.baseURL=n.origin}this.baseURL=e?.baseURL||this.baseURL,this.headers=e?.headers||{"Content-Type":"application/json"},this.timeout=e?.timeout||6e4*3,e?.beforeRequest?this.beforeRequest=e.beforeRequest:this.beforeRequest=async n=>{const s=this.token||this.storage?.getItem?.(this.tokenName);return s&&(n.headers={...n.headers,Authorization:`Bearer ${s}`}),n}}setQueryWs(e){this.qws=e}setStop(e){this.stop=e}async get(e,t){return this.post(e,t)}async post(e,t){const n=t?.url||this.url,{headers:s,adapter:o,beforeRequest:i,afterResponse:c,timeout:a,...u}=t||{},l={...this.headers,...s},h=o||this.adapter,m=i||this.beforeRequest,g=c||this.afterResponse,d=a||this.timeout,w={url:n,headers:l,body:e,timeout:d,...u};if(!w.url.startsWith("http")&&this.baseURL){const y=new URL(this.baseURL||globalThis?.location?.origin).origin;w.url=y+w.url}try{if(m&&await m(w)===!1)return he({code:500,message:"请求取消",req:w})}catch(y){return console.error("request beforeFn error",y,w),he({code:500,message:"请求在请求前处理时发生错误"})}if(this.stop&&!t?.noStop){const y=this;if(!await new Promise(p=>{let k=0;const _=setInterval(()=>{y.stop||(clearInterval(_),p(!0)),k++,k>5&&(console.error("等待请求失败:",w.url,k),clearInterval(_),p(!1))},1e3)}))return he({code:500,message:"请求取消,可能是因为用户未登录或者token过期"})}return h(w).then(async y=>{try{return g?await g(y,{req:w,res:y,fetch:o}):y}catch(v){return console.error("请求在响应后处理时发生错误",v,w),he({code:500,message:"请求在响应后处理时发生错误"})}})}before(e){this.beforeRequest=e}after(e){this.afterResponse=e}async fetchText(e,t){let n={...t};typeof e=="string"&&!n.url&&(n.url=e),typeof e=="object"&&(n={...e,...n});const s=await yt({method:"GET",...n,headers:{...this.headers,...n?.headers||{}}});return s&&!s.code?{code:200,data:s}:s}},Hn=class{query;queryDefine;constructor(e){e?.clientQuery?this.query=e.clientQuery:this.query=e?.query,e.queryDefine&&(this.queryDefine=e.queryDefine,this.queryDefine.query=this.query)}get chain(){return this.queryDefine.queryChain}post(e,t){return this.query.post(e,t)}get(e,t){return this.query.get(e,t)}};var Wn=r=>r?["text/","xml","html","javascript","css","csv","plain","x-www-form-urlencoded","md","json"].some(t=>r.includes(t)):!1,vt=async(r={},e)=>{const t=new AbortController,n=t.signal,s=r.isPostFile||!1,o=r.timeout||6e4*3,i=setTimeout(()=>{t.abort()},o);let c=e?.method||r?.method||"POST",a={...r?.headers,...e?.headers},u="",l;r?.url?.startsWith("http")?l=new URL(r.url):(u=globalThis?.location?.origin||"http://localhost:51515",l=new URL(r?.url||"",u));const h=c==="GET",m=l.searchParams;if(h){let d=new URLSearchParams({...Object.fromEntries(m),...r?.params,...r?.body});l.search=d.toString()}else{const d={...Object.fromEntries(m),...r.params},w=new URLSearchParams(d);if(typeof r.body=="object"&&r.body!==null){let f=r.body||{};!d.path&&f?.path&&(w.set("path",f.path),f?.key&&w.set("key",f.key))}l.search=w.toString()}let g;return h?g=void 0:s?g=r.body:r.body&&typeof r.body=="object"&&!(r.body instanceof FormData)&&(a={"Content-Type":"application/json",...a},g=JSON.stringify(r.body)),fetch(l,{method:c.toUpperCase(),signal:n,body:g,...e,headers:a}).then(async d=>{const w=d.headers.get("Content-Type"),f=w&&w.includes("application/json"),y=d.ok;if(f){const v=await d.json();return v?.code?v:{code:y?200:d.status,status:d.status,data:v}}else return Wn(w)?{code:y?200:d.status,status:d.status,data:await d.text()}:{code:y?200:d.status,status:d.status,data:"非文本非JSON响应, 请手动处理response。",response:d}}).catch(d=>d.name==="AbortError"?{code:408,message:"请求超时"}:{code:500,message:d.message||"网络错误"}).finally(()=>{clearTimeout(i)})},de=({code:r,message:e})=>({code:r||500,message:e||"请求错误"});class Vn{adapter;baseURL;url;beforeRequest;afterResponse;headers;timeout;stop;qws;tokenName;storage;token;constructor(e){this.adapter=e?.adapter||vt,this.tokenName=e?.tokenName||"token",this.storage=e?.storage||globalThis?.localStorage;const t=e?.isClient?"/client/router":"/api/router";if(this.url=e?.url||t,this.url.startsWith("http")){const n=new URL(this.url);this.baseURL=n.origin}this.baseURL=e?.baseURL||this.baseURL,this.headers=e?.headers||{"Content-Type":"application/json"},this.timeout=e?.timeout||6e4*3,e?.beforeRequest?this.beforeRequest=e.beforeRequest:this.beforeRequest=async n=>{const s=this.token||this.storage?.getItem?.(this.tokenName);return s&&(n.headers={...n.headers,Authorization:`Bearer ${s}`}),n}}setQueryWs(e){this.qws=e}setStop(e){this.stop=e}async get(e,t){return this.post(e,t)}async post(e,t){const n=t?.url||this.url,{headers:s,adapter:o,beforeRequest:i,afterResponse:c,timeout:a,...u}=t||{},l={...this.headers,...s},h=o||this.adapter,m=i||this.beforeRequest,g=c||this.afterResponse,d=a||this.timeout,w={url:n,headers:l,body:e,timeout:d,...u};if(!w.url.startsWith("http")&&this.baseURL){const y=new URL(this.baseURL||globalThis?.location?.origin).origin;w.url=y+w.url}try{if(m&&await m(w)===!1)return de({code:500,message:"请求取消",req:w})}catch(y){return console.error("request beforeFn error",y,w),de({code:500,message:"请求在请求前处理时发生错误"})}if(this.stop&&!t?.noStop){const y=this;if(!await new Promise(p=>{let k=0;const _=setInterval(()=>{y.stop||(clearInterval(_),p(!0)),k++,k>5&&(console.error("等待请求失败:",w.url,k),clearInterval(_),p(!1))},1e3)}))return de({code:500,message:"请求取消,可能是因为用户未登录或者token过期"})}return h(w).then(async y=>{try{return g?await g(y,{req:w,res:y,fetch:o}):y}catch(v){return console.error("请求在响应后处理时发生错误",v,w),de({code:500,message:"请求在响应后处理时发生错误"})}})}before(e){this.beforeRequest=e}after(e){this.afterResponse=e}async fetchText(e,t){let n={...t};typeof e=="string"&&!n.url&&(n.url=e),typeof e=="object"&&(n={...e,...n});const s=await vt({method:"GET",...n,headers:{...this.headers,...n?.headers||{}}});return s&&!s.code?{code:200,data:s}:s}}class On{query;queryDefine;constructor(e){e?.clientQuery?this.query=e.clientQuery:this.query=e?.query,e.queryDefine&&(this.queryDefine=e.queryDefine,this.queryDefine.query=this.query)}get chain(){return this.queryDefine.queryChain}post(e,t){return this.query.post(e,t)}get(e,t){return this.query.get(e,t)}}let Kn=class{cache;name;cacheData;constructor(e){if(!e.cache)throw new Error("cache is required");this.cache=e.cache,this.cacheData={loginUsers:[],user:void 0,id:void 0,accessToken:void 0,refreshToken:void 0},this.name=e.name}async setValue(e){return await this.cache.set(this.name,e),this.cacheData=e,e}async delValue(){await this.cache.del(),this.cacheData={loginUsers:[],user:void 0,id:void 0,accessToken:void 0,refreshToken:void 0}}getValue(){return this.cache.get(this.name)}async init(){const e={loginUsers:[],user:void 0,id:void 0,accessToken:void 0,refreshToken:void 0,accessTokenExpiresIn:void 0,createdAt:void 0};if(this.cache.init)try{const t=await this.cache.init();this.cacheData=t||e}catch(t){console.log("cacheInit error",t)}else this.cacheData=await this.getValue()||e;return this.cacheData}async setLoginUser(e){this.cacheData.loginUsers.find(n=>n.id===e.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(n=>n?.id&&n.id!==e.id)),this.cacheData.loginUsers.push(e),this.cacheData.user=e.user,this.cacheData.id=e.id,this.cacheData.accessToken=e.accessToken,this.cacheData.refreshToken=e.refreshToken,this.cacheData.accessTokenExpiresIn=e.accessTokenExpiresIn,this.cacheData.createdAt=e.createdAt,await this.setValue(this.cacheData)}getCurrentUser(){const e=this.cacheData;return Promise.resolve(e.user)}getCurrentUserList(){return Promise.resolve(this.cacheData.loginUsers.filter(e=>e?.id))}getRefreshToken(){const e=this.cacheData;return Promise.resolve(e.refreshToken||"")}getAccessToken(){const e=this.cacheData;return Promise.resolve(e.accessToken||"")}getIsExpired(){const e=this.cacheData;if(!e.accessToken)return Promise.resolve(!0);if(!e.createdAt||!e.accessTokenExpiresIn)return Promise.resolve(!1);const t=Date.now(),n=e.createdAt+e.accessTokenExpiresIn*1e3;return Promise.resolve(t>=n)}async clearCurrentUser(){const e=await this.getCurrentUser();this.cacheData.loginUsers.find(n=>n.id===e.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(n=>n?.id&&n.id!==e.id)),this.cacheData.user=void 0,this.cacheData.id=void 0,this.cacheData.accessToken=void 0,this.cacheData.refreshToken=void 0,this.cacheData.accessTokenExpiresIn=void 0,this.cacheData.createdAt=void 0,await this.setValue(this.cacheData)}async clearAll(){this.cacheData.loginUsers=[],this.cacheData.user=void 0,this.cacheData.id=void 0,this.cacheData.accessToken=void 0,this.cacheData.refreshToken=void 0,this.cacheData.accessTokenExpiresIn=void 0,this.cacheData.createdAt=void 0,await this.setValue(this.cacheData)}};function Qn(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Ee={exports:{}},kt;function Gn(){return kt||(kt=1,(function(r){var e=Object.prototype.hasOwnProperty,t="~";function n(){}Object.create&&(n.prototype=Object.create(null),new n().__proto__||(t=!1));function s(a,u,l){this.fn=a,this.context=u,this.once=l||!1}function o(a,u,l,h,m){if(typeof l!="function")throw new TypeError("The listener must be a function");var g=new s(l,h||a,m),d=t?t+u:u;return a._events[d]?a._events[d].fn?a._events[d]=[a._events[d],g]:a._events[d].push(g):(a._events[d]=g,a._eventsCount++),a}function i(a,u){--a._eventsCount===0?a._events=new n:delete a._events[u]}function c(){this._events=new n,this._eventsCount=0}c.prototype.eventNames=function(){var u=[],l,h;if(this._eventsCount===0)return u;for(h in l=this._events)e.call(l,h)&&u.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(l)):u},c.prototype.listeners=function(u){var l=t?t+u:u,h=this._events[l];if(!h)return[];if(h.fn)return[h.fn];for(var m=0,g=h.length,d=new Array(g);m<g;m++)d[m]=h[m].fn;return d},c.prototype.listenerCount=function(u){var l=t?t+u:u,h=this._events[l];return h?h.fn?1:h.length:0},c.prototype.emit=function(u,l,h,m,g,d){var w=t?t+u:u;if(!this._events[w])return!1;var f=this._events[w],y=arguments.length,v,p;if(f.fn){switch(f.once&&this.removeListener(u,f.fn,void 0,!0),y){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,l),!0;case 3:return f.fn.call(f.context,l,h),!0;case 4:return f.fn.call(f.context,l,h,m),!0;case 5:return f.fn.call(f.context,l,h,m,g),!0;case 6:return f.fn.call(f.context,l,h,m,g,d),!0}for(p=1,v=new Array(y-1);p<y;p++)v[p-1]=arguments[p];f.fn.apply(f.context,v)}else{var k=f.length,_;for(p=0;p<k;p++)switch(f[p].once&&this.removeListener(u,f[p].fn,void 0,!0),y){case 1:f[p].fn.call(f[p].context);break;case 2:f[p].fn.call(f[p].context,l);break;case 3:f[p].fn.call(f[p].context,l,h);break;case 4:f[p].fn.call(f[p].context,l,h,m);break;default:if(!v)for(_=1,v=new Array(y-1);_<y;_++)v[_-1]=arguments[_];f[p].fn.apply(f[p].context,v)}}return!0},c.prototype.on=function(u,l,h){return o(this,u,l,h,!1)},c.prototype.once=function(u,l,h){return o(this,u,l,h,!0)},c.prototype.removeListener=function(u,l,h,m){var g=t?t+u:u;if(!this._events[g])return this;if(!l)return i(this,g),this;var d=this._events[g];if(d.fn)d.fn===l&&(!m||d.once)&&(!h||d.context===h)&&i(this,g);else{for(var w=0,f=[],y=d.length;w<y;w++)(d[w].fn!==l||m&&!d[w].once||h&&d[w].context!==h)&&f.push(d[w]);f.length?this._events[g]=f.length===1?f[0]:f:i(this,g)}return this},c.prototype.removeAllListeners=function(u){var l;return u?(l=t?t+u:u,this._events[l]&&i(this,l)):(this._events=new n,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=t,c.EventEmitter=c,r.exports=c})(Ee)),Ee.exports}var Jn=Gn(),Yn=Qn(Jn),bt=r=>{const e=r.timeout||3e5,t=r.interval||1e3,n=r?.checkSuccess||(()=>!0),s=r.signal;return new Promise(async(o,i)=>{let c,a=setTimeout(()=>{clearTimeout(c),o({code:500,message:"timeout"})},e);const u=r.fn||(()=>!0),l=async()=>{if(s?.aborted)return clearInterval(c),clearTimeout(a),o({code:499,message:"operation cancelled"});const h=await u();n(h)?(clearInterval(c),clearTimeout(a),o({code:200,data:h})):setTimeout(()=>{l()},t)};s&&s.addEventListener("abort",()=>{clearInterval(c),clearTimeout(a),o({code:499,message:"operation cancelled"})}),l()})};let Xn=class{modules=new Map;event;loading;static reRunFn=bt;timeout=300*1e3;constructor(){this.event=new Yn,this.loading=!1}listenKey(e,t){const n=t?.timeout??this.timeout;return new Promise(s=>{const o=setTimeout(()=>{this.event.removeListener(e,i),s({code:500,message:"timeout"})},n),i=c=>{if(clearTimeout(o),c)return s({code:500,message:c});const a=this.modules.get(e);a?.loadSuccessClear&&this.remove(e),s({code:200,data:a?.modules})};this.event.once(e,i)})}async hasLoaded(e,t){if(!e)return{code:404,message:"key is required"};if(!this.modules.has(e)){const o=t?.isExist??!0,i=t?.timeout??this.timeout;return o?await this.listenKey(e,{timeout:i}):{code:404}}const s=this.modules.get(e);return s?.status==="loaded"?{code:200,data:s.modules}:s?.status==="loading"?await this.listenKey(e,{timeout:t?.timeout??this.timeout}):s?.status==="error"?{code:500,message:"load error"}:s?.status==="cancel"?{code:499,message:"operation cancelled"}:{code:404}}async loadFn(e,t){const n=t.key;if(!n)return{code:404,message:"key is required"};const s={key:t.key,status:"loading",loading:!0,loadSuccessClear:t.loadSuccessClear??!0};let o="";try{const i=t.isReRun??!1;let c;if(!i)this.modules.set(n,s),c=await e();else{s.controller=new AbortController;const a=s.controller.signal;this.modules.set(n,s);const u=await bt({timeout:t.timeout,interval:t.interval,checkSuccess:t.checkSuccess,fn:e,signal:a});if(s.controller=null,u.code===499)return s.status="cancel",{code:499,message:"operation cancelled"};if(u.code!==200)throw new Error(u.message);c=u.data}return s.modules=c,s.status="loaded",{code:200,data:c}}catch(i){return o=i.message,s.status="error",{code:500,message:i}}finally{s.loading=!1,this.modules.set(t.key,s),o?this.event.emit(t.key,o):this.event.emit(t.key)}}async load(e,t){this.loading=!0;const n=t.key;if(!n)return{code:404,message:"key is required"};if(t?.force&&this.remove(n),this.modules.has(n))return await this.hasLoaded(n);if(typeof e=="function")return this.loadFn(e,t);console.error("loadContent is not a function and not has loaded")}remove(e){this.modules.has(e)&&(this.checkRemoveController(e),this.modules.delete(e))}emitLoaded(e){this.checkRemoveController(e),this.event.emit(e)}setModule(e,t,n){const s={key:e,status:"loaded",loading:!1,modules:t||{},...n};return this.modules.set(e,s),this.emitLoaded(e),s}cancel(e){this.checkRemoveController(e)}checkRemoveController(e){const t=this.modules.get(e);t?.controller&&(t.controller?.abort?.(),delete t.controller,this.modules.set(e,t))}},Zn=class extends On{cacheStore;isBrowser;load;storage;onLoad;constructor(e){if(super({query:e?.query||new Vn}),this.cacheStore=new Kn({name:"login",cache:e?.cache}),this.isBrowser=e?.isBrowser??!0,this.init(),this.onLoad=e?.onLoad,this.storage=e?.storage||globalThis?.localStorage,!this.storage)throw new Error("storage is required")}setQuery(e){this.query=e}async init(){await this.cacheStore.init(),this.load=!0,this.onLoad?.()}async post(e,t){try{return this.query.post({path:"user",...e},t)}catch(n){return console.log("error",n),{code:400}}}async login(e){const t=await this.post({key:"login",...e});if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o})}return t}async loginByCode(e){const t=await this.post({path:"sms",key:"login",data:e});if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o})}return t}async setLoginToken(e){const{accessToken:t,refreshToken:n,accessTokenExpiresIn:s}=e;this.storage.setItem("token",t||""),await this.beforeSetLoginUser({accessToken:t,refreshToken:n,accessTokenExpiresIn:s})}async loginByWechat(e){const t=await this.post({path:"wx",key:"open-login",code:e.code});if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o})}return t}async loginByCnb(e){const t=await this.post({path:"user",key:"cnb-login",payload:{data:e}});if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o})}return t}async checkWechat({onSuccess:e,onError:t}){const n=new URL(window.location.href),s=n.searchParams.get("code"),o=n.searchParams.get("state");if(s&&o){const i=await this.loginByWechat({code:s});i.code===200?e?.(i.data):t?.(i)}}async beforeSetLoginUser(e){const{accessToken:t,refreshToken:n,check401:s,accessTokenExpiresIn:o}=e;if(t&&n){const i=await this.getMe(t,s);if(i.code===200){const c=i.data;c?this.cacheStore.setLoginUser({user:c,id:c.id,accessToken:t,refreshToken:n,accessTokenExpiresIn:o,createdAt:Date.now()}):console.error("登录失败")}return i}return{code:400,message:"登录失败"}}async refreshLoginUser(e){const t=await this.queryRefreshToken(e);if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o,check401:!1})}return t}async queryRefreshToken(e){const t=e?.refreshToken;let n=e?.accessToken;const s=t||await this.cacheStore.getRefreshToken();let o={};return n&&(o.accessToken=n),s&&(o.refreshToken=s),s?this.post({key:"refreshToken",data:o},{afterResponse:async(i,c)=>i}):(await this.cacheStore.clearCurrentUser(),{code:401,message:"请先登录",data:{}})}async afterCheck401ToRefreshToken(e,t,n){const s=this;if(e?.code===401){const o=await s.cacheStore.getRefreshToken();if(o){const i=await s.queryRefreshToken({refreshToken:o});if(i.code===200){const{accessToken:c,refreshToken:a,accessTokenExpiresIn:u}=i?.data||{};if(s.storage.setItem("token",c||""),await s.beforeSetLoginUser({accessToken:c,refreshToken:a,accessTokenExpiresIn:u,check401:!1}),n&&t&&t.req&&t.req.url&&t.fetch){await new Promise(d=>setTimeout(d,1500));const l=t.req?.url,h=t.req?.body,m=t.req?.headers;return await t.fetch(l,{method:"POST",body:h,headers:{...m,Authorization:`Bearer ${c}`}})}}else s.storage.removeItem("token"),await s.cacheStore.clearCurrentUser();return i}}return e}async run401Action(e,t,n){const s=this,o=n?.refetch??!1;if(e?.code===401){if(s.query.stop===!0)return{code:500,success:!1,message:"refresh token loading..."};s.query.stop=!0;const i=await s.afterCheck401ToRefreshToken(e,t,o);return s.query.stop=!1,n?.afterCheck?.(i),i.code===401&&n?.afterAlso401?.(i),i}else return e}async getMe(e,t=!0){const n=e||this.storage.getItem("token"),s=this;return s.post({key:"me"},{beforeRequest:async o=>(o.headers&&(o.headers.Authorization=`Bearer ${n}`),n?o:!1),afterResponse:async(o,i)=>o?.code===401&&t&&!e?await s.afterCheck401ToRefreshToken(o,i):o})}async checkLocalUser(){const e=await this.cacheStore.getCurrentUser();return e||null}async checkLocalToken(){return!!this.storage.getItem("token")}async checkTokenValid(){const e=this.storage.getItem("token");if(!e)return null;if(await this.cacheStore.getIsExpired()){const n=await this.refreshLoginUser();return n.code===200&&n.data?.accessToken||null}return e}async getToken(){return this.storage.getItem("token")||""}async beforeRequest(e={}){const t=this.storage.getItem("token");return t&&(e.headers={...e.headers,Authorization:`Bearer ${t}`}),e}async postSwitchUser(e){return this.post({key:"switchCheck",data:{username:e}})}async switchUser(e){const n=(await this.cacheStore.getCurrentUserList()).find(o=>o.user.username===e);if(n)return this.storage.setItem("token",n.accessToken||""),await this.beforeSetLoginUser({accessToken:n.accessToken,refreshToken:n.refreshToken,accessTokenExpiresIn:n.accessTokenExpiresIn}),{code:200,data:{accessToken:n.accessToken,refreshToken:n.refreshToken,accessTokenExpiresIn:n.accessTokenExpiresIn},success:!0,message:"切换用户成功"};const s=await this.postSwitchUser(e);if(s.code===200){const{accessToken:o,refreshToken:i,accessTokenExpiresIn:c}=s?.data||{};this.storage.setItem("token",o||""),await this.beforeSetLoginUser({accessToken:o,refreshToken:i,accessTokenExpiresIn:c})}return s}async logout(){this.storage.removeItem("token");const t=(await this.cacheStore.getCurrentUserList()).map(n=>n?.accessToken).filter(Boolean);return this.cacheStore.delValue(),this.post({key:"logout",data:{tokens:t}})}async hasUser(e){const t=this;return this.post({path:"org",key:"hasUser",data:{username:e}},{afterResponse:async(n,s)=>n?.code===401?await t.afterCheck401ToRefreshToken(n,s,!0):n})}async checkLoginStatus(e){const t=await this.post({path:"user",key:"checkLoginStatus",loginToken:e});if(t.code===200){const{accessTokenExpiresIn:n,accessToken:s,refreshToken:o}=t.data;return this.storage.setItem("token",s||""),await this.beforeSetLoginUser({accessToken:s,refreshToken:o,accessTokenExpiresIn:n}),t}return!1}loginWithWeb(e,{MD5:t,jsonwebtoken:n}){const s=Math.random().toString(36).substring(2,15),o=Date.now(),i="xiao"+s;let c="";t&&(c=t(`${i}${o}`).toString());let a="";return n?a=n.sign({randomId:s,timestamp:o,sign:c},i,{expiresIn:600}):a=i,{url:`${e}/api/router?path=user&key=webLogin&p&loginToken=${a}&sign=${c}&randomId=${s}`,token:a,tokenSecret:i}}async pollLoginStatus(e){const t=e.token,n=new Xn;n.load(async()=>{const o=await this.checkLoginStatus(t);return o.code===500&&n.cancel("check-login-status"),o},{key:"check-login-status",isReRun:!0,checkSuccess:o=>o?.code===200});const s=await n.hasLoaded("check-login-status",{timeout:180*1e3});if(s.code===200&&s.data?.code===200)try{return console.log("网页登录成功"),!0}catch(o){return console.log("登录失败",o),!1}return console.log("登录失败",s),!1}};function M(r){return new Promise((e,t)=>{r.oncomplete=r.onsuccess=()=>e(r.result),r.onabort=r.onerror=()=>t(r.error)})}function un(r,e){let t;const n=()=>{if(t)return t;const s=indexedDB.open(r);return s.onupgradeneeded=()=>s.result.createObjectStore(e),t=M(s),t.then(o=>{o.onclose=()=>t=void 0},()=>{}),t};return(s,o)=>n().then(i=>o(i.transaction(e,s).objectStore(e)))}var Ae;function B(){return Ae||(Ae=un("keyval-store","keyval")),Ae}function es(r,e=B()){return e("readonly",t=>M(t.get(r)))}function ts(r,e,t=B()){return t("readwrite",n=>(n.put(e,r),M(n.transaction)))}function ns(r,e=B()){return e("readwrite",t=>(r.forEach(n=>t.put(n[1],n[0])),M(t.transaction)))}function ss(r,e=B()){return e("readonly",t=>Promise.all(r.map(n=>M(t.get(n)))))}function rs(r,e,t=B()){return t("readwrite",n=>new Promise((s,o)=>{n.get(r).onsuccess=function(){try{n.put(e(this.result),r),s(M(n.transaction))}catch(i){o(i)}}}))}function os(r,e=B()){return e("readwrite",t=>(t.delete(r),M(t.transaction)))}function is(r,e=B()){return e("readwrite",t=>(r.forEach(n=>t.delete(n)),M(t.transaction)))}function as(r=B()){return r("readwrite",e=>(e.clear(),M(e.transaction)))}function st(r,e){return r.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},M(r.transaction)}function cs(r=B()){return r("readonly",e=>{if(e.getAllKeys)return M(e.getAllKeys());const t=[];return st(e,n=>t.push(n.key)).then(()=>t)})}function us(r=B()){return r("readonly",e=>{if(e.getAll)return M(e.getAll());const t=[];return st(e,n=>t.push(n.value)).then(()=>t)})}function ls(r=B()){return r("readonly",e=>{if(e.getAll&&e.getAllKeys)return Promise.all([M(e.getAllKeys()),M(e.getAll())]).then(([n,s])=>n.map((o,i)=>[o,s[i]]));const t=[];return r("readonly",n=>st(n,s=>t.push([s.key,s.value])).then(()=>t))})}let hs=class{store;constructor(e){this.store=un(e?.dbName||"default-db",e?.storeName||"cache-store")}async get(e){return es(e,this.store)}async set(e,t){return ts(e,t,this.store)}async del(e){return os(e,this.store)}async clear(){return as(this.store)}async keys(){return cs(this.store)}async values(){return us(this.store)}async entries(){return ls(this.store)}async update(e,t){return rs(e,t,this.store)}async setMany(e){return ns(e,this.store)}async getMany(e){return ss(e,this.store)}async delMany(e){return is(e,this.store)}};class ds extends hs{constructor(e){super(e)}async getData(e){return(await this.get(e)).data}async setData(e,t){return this.set(e,t)}async getCheckData(e){const t=await this.get(e);return t.expireTime&&t.expireTime<Date.now()?(await super.del(e),null):t.data}async setCheckData(e,t,n){const o=Date.now()+(n?.expireTime||1e3*60*60*24*10),i={data:t,updatedAt:n?.updatedAt||Date.now(),expireTime:o};return await this.set(e,i),t}async checkNew(e,t){const n=await this.get(e);if(!n)return!0;if(!t?.updatedAt)return!1;const s=new Date(t.updatedAt).getTime();return isNaN(s)?!1:s>n.updatedAt}async delCheckData(e){return this.del(e)}}let fs=class extends ds{key;constructor(e){const{key:t,...n}=e||{};super(n),this.key=t||"my-cache"}async getData(){return super.getCheckData(this.key)}async setData(e,t){super.setCheckData(this.key,e,t)}async del(){await super.del(this.key)}},gs=class extends Zn{constructor(e){super({...e,cache:new fs({key:"login"})})}};const ms=new nt({}),rt=new gs({query:ms,isBrowser:!0,onLoad:()=>{console.log("加载完成")}}),q=rt;class ps extends HTMLElement{constructor(){super(),this.timer=null,this.options={type:"success",message:"",duration:2e3,closable:!0}}connectedCallback(){this.render()}setOptions(e){this.options={...this.options,...e},this.render()}render(){const{type:e,message:t,closable:n}=this.options,o=D`
|
|
4
|
+
<style>
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
margin-bottom: 12px;
|
|
8
|
+
animation: slideIn 0.3s ease-out;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.message-container {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
gap: 8px;
|
|
15
|
+
padding: 12px 16px;
|
|
16
|
+
border-radius: 6px;
|
|
17
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
18
|
+
background: white;
|
|
19
|
+
position: relative;
|
|
20
|
+
min-width: 300px;
|
|
21
|
+
max-width: 500px;
|
|
22
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
23
|
+
font-size: 14px;
|
|
24
|
+
line-height: 1.4;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.message-container.success {
|
|
28
|
+
border-left: 4px solid #52c41a;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.message-container.error {
|
|
32
|
+
border-left: 4px solid #ff4d4f;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.message-container.loading {
|
|
36
|
+
border-left: 4px solid #1890ff;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.message-icon {
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
width: 16px;
|
|
44
|
+
height: 16px;
|
|
45
|
+
flex-shrink: 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.success .message-icon {
|
|
49
|
+
color: #52c41a;
|
|
50
|
+
font-weight: bold;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.error .message-icon {
|
|
54
|
+
color: #ff4d4f;
|
|
55
|
+
font-weight: bold;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.loading .message-icon {
|
|
59
|
+
color: #1890ff;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.loading-spinner {
|
|
63
|
+
width: 14px;
|
|
64
|
+
height: 14px;
|
|
65
|
+
border: 2px solid #f3f3f3;
|
|
66
|
+
border-top: 2px solid #1890ff;
|
|
67
|
+
border-radius: 50%;
|
|
68
|
+
animation: spin 1s linear infinite;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.message-content {
|
|
72
|
+
flex: 1;
|
|
73
|
+
color: #333;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.message-close {
|
|
77
|
+
display: flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
width: 16px;
|
|
81
|
+
height: 16px;
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
color: #999;
|
|
84
|
+
background: none;
|
|
85
|
+
border: none;
|
|
86
|
+
font-size: 12px;
|
|
87
|
+
border-radius: 50%;
|
|
88
|
+
transition: all 0.2s;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.message-close:hover {
|
|
92
|
+
color: #666;
|
|
93
|
+
background: #f0f0f0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@keyframes slideIn {
|
|
97
|
+
from {
|
|
98
|
+
transform: translateX(100%);
|
|
99
|
+
opacity: 0;
|
|
100
|
+
}
|
|
101
|
+
to {
|
|
102
|
+
transform: translateX(0);
|
|
103
|
+
opacity: 1;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@keyframes slideOut {
|
|
108
|
+
from {
|
|
109
|
+
transform: translateX(0);
|
|
110
|
+
opacity: 1;
|
|
111
|
+
}
|
|
112
|
+
to {
|
|
113
|
+
transform: translateX(100%);
|
|
114
|
+
opacity: 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@keyframes spin {
|
|
119
|
+
0% { transform: rotate(0deg); }
|
|
120
|
+
100% { transform: rotate(360deg); }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.removing {
|
|
124
|
+
animation: slideOut 0.3s ease-out forwards;
|
|
125
|
+
}
|
|
126
|
+
</style>
|
|
127
|
+
|
|
128
|
+
<div class="message-container ${e}">
|
|
129
|
+
<div class="message-icon">
|
|
130
|
+
${(()=>{switch(e){case"success":return"✓";case"error":return"✕";case"loading":return D`<div class="loading-spinner"></div>`;default:return""}})()}
|
|
131
|
+
</div>
|
|
132
|
+
<div class="message-content">${t}</div>
|
|
133
|
+
${n?D`
|
|
134
|
+
<button class="message-close" @click=${()=>this.remove()}>×</button>
|
|
135
|
+
`:""}
|
|
136
|
+
</div>
|
|
137
|
+
`;cn(o,this),e!=="loading"&&this.options.duration&&this.options.duration>0&&this.setTimer()}setTimer(){this.timer&&clearTimeout(this.timer),this.timer=window.setTimeout(()=>{this.remove()},this.options.duration)}remove(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.classList.add("removing"),setTimeout(()=>{this.parentNode&&this.parentNode.removeChild(this)},300)}disconnectedCallback(){this.timer&&(clearTimeout(this.timer),this.timer=null)}}customElements.define("kv-message",ps);class Z{constructor(){this.container=null,this.defaultPosition="center"}static getInstance(){return Z.instance||(Z.instance=new Z),Z.instance}setDefaultPosition(e){this.defaultPosition=e}getContainer(e){const t=e||this.defaultPosition;return this.container||(this.container=document.getElementById("messages"),this.container||(this.container=document.createElement("div"),this.container.id="messages",t==="center"?this.container.style.cssText=`
|
|
138
|
+
position: fixed;
|
|
139
|
+
top: 20px;
|
|
140
|
+
left: 50%;
|
|
141
|
+
transform: translateX(-50%);
|
|
142
|
+
z-index: 9999;
|
|
143
|
+
display: flex;
|
|
144
|
+
gap: 8px;
|
|
145
|
+
flex-direction: column;
|
|
146
|
+
align-items: center;
|
|
147
|
+
pointer-events: none;
|
|
148
|
+
`:this.container.style.cssText=`
|
|
149
|
+
position: fixed;
|
|
150
|
+
top: 20px;
|
|
151
|
+
right: 20px;
|
|
152
|
+
z-index: 9999;
|
|
153
|
+
display: flex;
|
|
154
|
+
gap: 8px;
|
|
155
|
+
flex-direction: column;
|
|
156
|
+
align-items: flex-end;
|
|
157
|
+
pointer-events: none;
|
|
158
|
+
`,document.body.appendChild(this.container))),this.container}show(e){const t=this.getContainer(e.position),n=document.createElement("kv-message");return n.setOptions(e),n.style.cssText="pointer-events: auto;",t.appendChild(n),n}success(e,t){return this.show({type:"success",message:e,duration:t?.duration||2e3,position:t?.position,closable:t?.closable})}error(e,t){return this.show({type:"error",message:e,duration:t?.duration||3e3,position:t?.position,closable:t?.closable})}loading(e,t){return this.show({type:"loading",message:e,duration:0,position:t?.position,closable:t?.closable})}remove(e){e.remove()}clear(){this.getContainer().querySelectorAll("kv-message").forEach(n=>{n.remove()})}}const ln=()=>Z.getInstance();window.createMessage=ln;let ws=class{constructor(){this.events=new Map}on(e,t){this.events.has(e)||this.events.set(e,new Set),this.events.get(e).add(t)}off(e,t){this.events.has(e)&&(t?(this.events.get(e).delete(t),this.events.get(e).size===0&&this.events.delete(e)):this.events.delete(e))}emit(e){const{type:t}=e;if(!this.events.has(t))return;this.events.get(t).forEach(s=>{try{s(e)}catch(o){console.error(`Error in event handler for type "${t}":`,o)}})}emitSimple(e,t){this.emit({type:e,data:t})}clear(){this.events.clear()}listenerCount(e){return this.events.get(e)?.size||0}eventNames(){return Array.from(this.events.keys())}hasListeners(e){return this.events.has(e)&&this.events.get(e).size>0}once(e,t){const n=s=>{t(s),this.off(e,n)};this.on(e,n)}};const hn=new ws,ys=r=>hn.emit(r);class vs{constructor(e){if(!e.cache)throw new Error("cache is required");this.cache=e.cache,this.cacheData={loginUsers:[],user:void 0,id:void 0,accessToken:void 0,refreshToken:void 0},this.name=e.name}async setValue(e){return await this.cache.set(this.name,e),this.cacheData=e,e}async delValue(){await this.cache.del(),this.cacheData={loginUsers:[],user:void 0,id:void 0,accessToken:void 0,refreshToken:void 0}}getValue(){return this.cache.get(this.name)}async init(){const e={loginUsers:[],user:void 0,id:void 0,accessToken:void 0,refreshToken:void 0,accessTokenExpiresIn:void 0,createdAt:void 0};if(this.cache.init)try{const t=await this.cache.init();this.cacheData=t||e}catch(t){console.log("cacheInit error",t)}else this.cacheData=await this.getValue()||e;return this.cacheData}async setLoginUser(e){this.cacheData.loginUsers.find(n=>n.id===e.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(n=>n?.id&&n.id!==e.id)),this.cacheData.loginUsers.push(e),this.cacheData.user=e.user,this.cacheData.id=e.id,this.cacheData.accessToken=e.accessToken,this.cacheData.refreshToken=e.refreshToken,this.cacheData.accessTokenExpiresIn=e.accessTokenExpiresIn,this.cacheData.createdAt=e.createdAt,await this.setValue(this.cacheData)}getCurrentUser(){const e=this.cacheData;return Promise.resolve(e.user)}getCurrentUserList(){return Promise.resolve(this.cacheData.loginUsers.filter(e=>e?.id))}getRefreshToken(){const e=this.cacheData;return Promise.resolve(e.refreshToken||"")}getAccessToken(){const e=this.cacheData;return Promise.resolve(e.accessToken||"")}getIsExpired(){const e=this.cacheData;if(!e.accessToken)return Promise.resolve(!0);if(!e.createdAt||!e.accessTokenExpiresIn)return Promise.resolve(!1);const t=Date.now(),n=e.createdAt+e.accessTokenExpiresIn*1e3;return Promise.resolve(t>=n)}async clearCurrentUser(){const e=await this.getCurrentUser();this.cacheData.loginUsers.find(n=>n.id===e.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(n=>n?.id&&n.id!==e.id)),this.cacheData.user=void 0,this.cacheData.id=void 0,this.cacheData.accessToken=void 0,this.cacheData.refreshToken=void 0,this.cacheData.accessTokenExpiresIn=void 0,this.cacheData.createdAt=void 0,await this.setValue(this.cacheData)}async clearAll(){this.cacheData.loginUsers=[],this.cacheData.user=void 0,this.cacheData.id=void 0,this.cacheData.accessToken=void 0,this.cacheData.refreshToken=void 0,this.cacheData.accessTokenExpiresIn=void 0,this.cacheData.createdAt=void 0,await this.setValue(this.cacheData)}}function ks(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var xe={exports:{}},Tt;function bs(){return Tt||(Tt=1,(function(r){var e=Object.prototype.hasOwnProperty,t="~";function n(){}Object.create&&(n.prototype=Object.create(null),new n().__proto__||(t=!1));function s(a,u,l){this.fn=a,this.context=u,this.once=l||!1}function o(a,u,l,h,m){if(typeof l!="function")throw new TypeError("The listener must be a function");var g=new s(l,h||a,m),d=t?t+u:u;return a._events[d]?a._events[d].fn?a._events[d]=[a._events[d],g]:a._events[d].push(g):(a._events[d]=g,a._eventsCount++),a}function i(a,u){--a._eventsCount===0?a._events=new n:delete a._events[u]}function c(){this._events=new n,this._eventsCount=0}c.prototype.eventNames=function(){var u=[],l,h;if(this._eventsCount===0)return u;for(h in l=this._events)e.call(l,h)&&u.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(l)):u},c.prototype.listeners=function(u){var l=t?t+u:u,h=this._events[l];if(!h)return[];if(h.fn)return[h.fn];for(var m=0,g=h.length,d=new Array(g);m<g;m++)d[m]=h[m].fn;return d},c.prototype.listenerCount=function(u){var l=t?t+u:u,h=this._events[l];return h?h.fn?1:h.length:0},c.prototype.emit=function(u,l,h,m,g,d){var w=t?t+u:u;if(!this._events[w])return!1;var f=this._events[w],y=arguments.length,v,p;if(f.fn){switch(f.once&&this.removeListener(u,f.fn,void 0,!0),y){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,l),!0;case 3:return f.fn.call(f.context,l,h),!0;case 4:return f.fn.call(f.context,l,h,m),!0;case 5:return f.fn.call(f.context,l,h,m,g),!0;case 6:return f.fn.call(f.context,l,h,m,g,d),!0}for(p=1,v=new Array(y-1);p<y;p++)v[p-1]=arguments[p];f.fn.apply(f.context,v)}else{var k=f.length,_;for(p=0;p<k;p++)switch(f[p].once&&this.removeListener(u,f[p].fn,void 0,!0),y){case 1:f[p].fn.call(f[p].context);break;case 2:f[p].fn.call(f[p].context,l);break;case 3:f[p].fn.call(f[p].context,l,h);break;case 4:f[p].fn.call(f[p].context,l,h,m);break;default:if(!v)for(_=1,v=new Array(y-1);_<y;_++)v[_-1]=arguments[_];f[p].fn.apply(f[p].context,v)}}return!0},c.prototype.on=function(u,l,h){return o(this,u,l,h,!1)},c.prototype.once=function(u,l,h){return o(this,u,l,h,!0)},c.prototype.removeListener=function(u,l,h,m){var g=t?t+u:u;if(!this._events[g])return this;if(!l)return i(this,g),this;var d=this._events[g];if(d.fn)d.fn===l&&(!m||d.once)&&(!h||d.context===h)&&i(this,g);else{for(var w=0,f=[],y=d.length;w<y;w++)(d[w].fn!==l||m&&!d[w].once||h&&d[w].context!==h)&&f.push(d[w]);f.length?this._events[g]=f.length===1?f[0]:f:i(this,g)}return this},c.prototype.removeAllListeners=function(u){var l;return u?(l=t?t+u:u,this._events[l]&&i(this,l)):(this._events=new n,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=t,c.EventEmitter=c,r.exports=c})(xe)),xe.exports}var Ts=bs(),Cs=ks(Ts);const Ct=r=>{const e=r.timeout||3e5,t=r.interval||1e3,n=r?.checkSuccess||(()=>!0),s=r.signal;return new Promise(async(o,i)=>{let c,a=setTimeout(()=>{clearTimeout(c),o({code:500,message:"timeout"})},e);const u=r.fn||(()=>!0),l=async()=>{if(s?.aborted)return clearInterval(c),clearTimeout(a),o({code:499,message:"operation cancelled"});const h=await u();n(h)?(clearInterval(c),clearTimeout(a),o({code:200,data:h})):setTimeout(()=>{l()},t)};s&&s.addEventListener("abort",()=>{clearInterval(c),clearTimeout(a),o({code:499,message:"operation cancelled"})}),l()})};let Es=class{modules=new Map;event;loading;static reRunFn=Ct;timeout=300*1e3;constructor(){this.event=new Cs,this.loading=!1}listenKey(e,t){const n=t?.timeout??this.timeout;return new Promise(s=>{const o=setTimeout(()=>{this.event.removeListener(e,i),s({code:500,message:"timeout"})},n),i=c=>{if(clearTimeout(o),c)return s({code:500,message:c});const a=this.modules.get(e);a?.loadSuccessClear&&this.remove(e),s({code:200,data:a?.modules})};this.event.once(e,i)})}async hasLoaded(e,t){if(!e)return{code:404,message:"key is required"};if(!this.modules.has(e)){const o=t?.isExist??!0,i=t?.timeout??this.timeout;return o?await this.listenKey(e,{timeout:i}):{code:404}}const s=this.modules.get(e);return s?.status==="loaded"?{code:200,data:s.modules}:s?.status==="loading"?await this.listenKey(e,{timeout:t?.timeout??this.timeout}):s?.status==="error"?{code:500,message:"load error"}:s?.status==="cancel"?{code:499,message:"operation cancelled"}:{code:404}}async loadFn(e,t){const n=t.key;if(!n)return{code:404,message:"key is required"};const s={key:t.key,status:"loading",loading:!0,loadSuccessClear:t.loadSuccessClear??!0};let o="";try{const i=t.isReRun??!1;let c;if(!i)this.modules.set(n,s),c=await e();else{s.controller=new AbortController;const a=s.controller.signal;this.modules.set(n,s);const u=await Ct({timeout:t.timeout,interval:t.interval,checkSuccess:t.checkSuccess,fn:e,signal:a});if(s.controller=null,u.code===499)return s.status="cancel",{code:499,message:"operation cancelled"};if(u.code!==200)throw new Error(u.message);c=u.data}return s.modules=c,s.status="loaded",{code:200,data:c}}catch(i){return o=i.message,s.status="error",{code:500,message:i}}finally{s.loading=!1,this.modules.set(t.key,s),o?this.event.emit(t.key,o):this.event.emit(t.key)}}async load(e,t){this.loading=!0;const n=t.key;if(!n)return{code:404,message:"key is required"};if(t?.force&&this.remove(n),this.modules.has(n))return await this.hasLoaded(n);if(typeof e=="function")return this.loadFn(e,t);console.error("loadContent is not a function and not has loaded")}remove(e){this.modules.has(e)&&(this.checkRemoveController(e),this.modules.delete(e))}emitLoaded(e){this.checkRemoveController(e),this.event.emit(e)}setModule(e,t,n){const s={key:e,status:"loaded",loading:!1,modules:t||{},...n};return this.modules.set(e,s),this.emitLoaded(e),s}cancel(e){this.checkRemoveController(e)}checkRemoveController(e){const t=this.modules.get(e);t?.controller&&(t.controller?.abort?.(),delete t.controller,this.modules.set(e,t))}};class As extends Hn{constructor(e){if(super({query:e?.query||new nt}),this.cacheStore=new vs({name:"login",cache:e?.cache}),this.isBrowser=e?.isBrowser??!0,this.init(),this.onLoad=e?.onLoad,this.storage=e?.storage||globalThis?.localStorage,!this.storage)throw new Error("storage is required")}setQuery(e){this.query=e}async init(){await this.cacheStore.init(),this.load=!0,this.onLoad?.()}async post(e,t){try{return this.query.post({path:"user",...e},t)}catch(n){return console.log("error",n),{code:400}}}async login(e){const t=await this.post({key:"login",...e});if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o})}return t}async loginByCode(e){const t=await this.post({path:"sms",key:"login",data:e});if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o})}return t}async setLoginToken(e){const{accessToken:t,refreshToken:n,accessTokenExpiresIn:s}=e;this.storage.setItem("token",t||""),await this.beforeSetLoginUser({accessToken:t,refreshToken:n,accessTokenExpiresIn:s})}async loginByWechat(e){const t=await this.post({path:"wx",key:"open-login",code:e.code});if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o})}return t}async loginByCnb(e){const t=await this.post({path:"user",key:"cnb-login",payload:{data:e}});if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o})}return t}async checkWechat({onSuccess:e,onError:t}){const n=new URL(window.location.href),s=n.searchParams.get("code"),o=n.searchParams.get("state");if(s&&o){const i=await this.loginByWechat({code:s});i.code===200?e?.(i.data):t?.(i)}}async beforeSetLoginUser(e){const{accessToken:t,refreshToken:n,check401:s,accessTokenExpiresIn:o}=e;if(t&&n){const i=await this.getMe(t,s);if(i.code===200){const c=i.data;c?this.cacheStore.setLoginUser({user:c,id:c.id,accessToken:t,refreshToken:n,accessTokenExpiresIn:o,createdAt:Date.now()}):console.error("登录失败")}return i}return{code:400,message:"登录失败"}}async refreshLoginUser(e){const t=await this.queryRefreshToken(e);if(t.code===200){const{accessToken:n,refreshToken:s,accessTokenExpiresIn:o}=t?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:s,accessTokenExpiresIn:o,check401:!1})}return t}async queryRefreshToken(e){const t=e?.refreshToken;let n=e?.accessToken;const s=t||await this.cacheStore.getRefreshToken();let o={};return n&&(o.accessToken=n),s&&(o.refreshToken=s),s?this.post({key:"refreshToken",data:o},{afterResponse:async(i,c)=>i}):(await this.cacheStore.clearCurrentUser(),{code:401,message:"请先登录",data:{}})}async afterCheck401ToRefreshToken(e,t,n){const s=this;if(e?.code===401){const o=await s.cacheStore.getRefreshToken();if(o){const i=await s.queryRefreshToken({refreshToken:o});if(i.code===200){const{accessToken:c,refreshToken:a,accessTokenExpiresIn:u}=i?.data||{};if(s.storage.setItem("token",c||""),await s.beforeSetLoginUser({accessToken:c,refreshToken:a,accessTokenExpiresIn:u,check401:!1}),n&&t&&t.req&&t.req.url&&t.fetch){await new Promise(d=>setTimeout(d,1500));const l=t.req?.url,h=t.req?.body,m=t.req?.headers;return await t.fetch(l,{method:"POST",body:h,headers:{...m,Authorization:`Bearer ${c}`}})}}else s.storage.removeItem("token"),await s.cacheStore.clearCurrentUser();return i}}return e}async run401Action(e,t,n){const s=this,o=n?.refetch??!1;if(e?.code===401){if(s.query.stop===!0)return{code:500,success:!1,message:"refresh token loading..."};s.query.stop=!0;const i=await s.afterCheck401ToRefreshToken(e,t,o);return s.query.stop=!1,n?.afterCheck?.(i),i.code===401&&n?.afterAlso401?.(i),i}else return e}async getMe(e,t=!0){const n=e||this.storage.getItem("token"),s=this;return s.post({key:"me"},{beforeRequest:async o=>(o.headers&&(o.headers.Authorization=`Bearer ${n}`),n?o:!1),afterResponse:async(o,i)=>o?.code===401&&t&&!e?await s.afterCheck401ToRefreshToken(o,i):o})}async checkLocalUser(){const e=await this.cacheStore.getCurrentUser();return e||null}async checkLocalToken(){return!!this.storage.getItem("token")}async checkTokenValid(){const e=this.storage.getItem("token");if(!e)return null;if(await this.cacheStore.getIsExpired()){const n=await this.refreshLoginUser();return n.code===200&&n.data?.accessToken||null}return e}async getToken(){return this.storage.getItem("token")||""}async beforeRequest(e={}){const t=this.storage.getItem("token");return t&&(e.headers={...e.headers,Authorization:`Bearer ${t}`}),e}async postSwitchUser(e){return this.post({key:"switchCheck",data:{username:e}})}async switchUser(e){const n=(await this.cacheStore.getCurrentUserList()).find(o=>o.user.username===e);if(n)return this.storage.setItem("token",n.accessToken||""),await this.beforeSetLoginUser({accessToken:n.accessToken,refreshToken:n.refreshToken,accessTokenExpiresIn:n.accessTokenExpiresIn}),{code:200,data:{accessToken:n.accessToken,refreshToken:n.refreshToken,accessTokenExpiresIn:n.accessTokenExpiresIn},success:!0,message:"切换用户成功"};const s=await this.postSwitchUser(e);if(s.code===200){const{accessToken:o,refreshToken:i,accessTokenExpiresIn:c}=s?.data||{};this.storage.setItem("token",o||""),await this.beforeSetLoginUser({accessToken:o,refreshToken:i,accessTokenExpiresIn:c})}return s}async logout(){this.storage.removeItem("token");const t=(await this.cacheStore.getCurrentUserList()).map(n=>n?.accessToken).filter(Boolean);return this.cacheStore.delValue(),this.post({key:"logout",data:{tokens:t}})}async hasUser(e){const t=this;return this.post({path:"org",key:"hasUser",data:{username:e}},{afterResponse:async(n,s)=>n?.code===401?await t.afterCheck401ToRefreshToken(n,s,!0):n})}async checkLoginStatus(e){const t=await this.post({path:"user",key:"checkLoginStatus",loginToken:e});if(t.code===200){const{accessTokenExpiresIn:n,accessToken:s,refreshToken:o}=t.data;return this.storage.setItem("token",s||""),await this.beforeSetLoginUser({accessToken:s,refreshToken:o,accessTokenExpiresIn:n}),t}return!1}loginWithWeb(e,{MD5:t,jsonwebtoken:n}){const s=Math.random().toString(36).substring(2,15),o=Date.now(),i="xiao"+s;let c="";t&&(c=t(`${i}${o}`).toString());let a="";return n?a=n.sign({randomId:s,timestamp:o,sign:c},i,{expiresIn:600}):a=i,{url:`${e}/api/router?path=user&key=webLogin&p&loginToken=${a}&sign=${c}&randomId=${s}`,token:a,tokenSecret:i}}async pollLoginStatus(e){const t=e.token,n=new Es;n.load(async()=>{const o=await this.checkLoginStatus(t);return o.code===500&&n.cancel("check-login-status"),o},{key:"check-login-status",isReRun:!0,checkSuccess:o=>o?.code===200});const s=await n.hasLoaded("check-login-status",{timeout:180*1e3});if(s.code===200&&s.data?.code===200)try{return console.log("网页登录成功"),!0}catch(o){return console.log("登录失败",o),!1}return console.log("登录失败",s),!1}}function U(r){return new Promise((e,t)=>{r.oncomplete=r.onsuccess=()=>e(r.result),r.onabort=r.onerror=()=>t(r.error)})}function dn(r,e){let t;const n=()=>{if(t)return t;const s=indexedDB.open(r);return s.onupgradeneeded=()=>s.result.createObjectStore(e),t=U(s),t.then(o=>{o.onclose=()=>t=void 0},()=>{}),t};return(s,o)=>n().then(i=>o(i.transaction(e,s).objectStore(e)))}let Le;function N(){return Le||(Le=dn("keyval-store","keyval")),Le}function xs(r,e=N()){return e("readonly",t=>U(t.get(r)))}function Ls(r,e,t=N()){return t("readwrite",n=>(n.put(e,r),U(n.transaction)))}function Ss(r,e=N()){return e("readwrite",t=>(r.forEach(n=>t.put(n[1],n[0])),U(t.transaction)))}function _s(r,e=N()){return e("readonly",t=>Promise.all(r.map(n=>U(t.get(n)))))}function Rs(r,e,t=N()){return t("readwrite",n=>new Promise((s,o)=>{n.get(r).onsuccess=function(){try{n.put(e(this.result),r),s(U(n.transaction))}catch(i){o(i)}}}))}function Is(r,e=N()){return e("readwrite",t=>(t.delete(r),U(t.transaction)))}function Ds(r,e=N()){return e("readwrite",t=>(r.forEach(n=>t.delete(n)),U(t.transaction)))}function Ms(r=N()){return r("readwrite",e=>(e.clear(),U(e.transaction)))}function ot(r,e){return r.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},U(r.transaction)}function Us(r=N()){return r("readonly",e=>{if(e.getAllKeys)return U(e.getAllKeys());const t=[];return ot(e,n=>t.push(n.key)).then(()=>t)})}function qs(r=N()){return r("readonly",e=>{if(e.getAll)return U(e.getAll());const t=[];return ot(e,n=>t.push(n.value)).then(()=>t)})}function Ps(r=N()){return r("readonly",e=>{if(e.getAll&&e.getAllKeys)return Promise.all([U(e.getAllKeys()),U(e.getAll())]).then(([n,s])=>n.map((o,i)=>[o,s[i]]));const t=[];return r("readonly",n=>ot(n,s=>t.push([s.key,s.value])).then(()=>t))})}class Bs{store;constructor(e){this.store=dn(e?.dbName||"default-db",e?.storeName||"cache-store")}async get(e){return xs(e,this.store)}async set(e,t){return Ls(e,t,this.store)}async del(e){return Is(e,this.store)}async clear(){return Ms(this.store)}async keys(){return Us(this.store)}async values(){return qs(this.store)}async entries(){return Ps(this.store)}async update(e,t){return Rs(e,t,this.store)}async setMany(e){return Ss(e,this.store)}async getMany(e){return _s(e,this.store)}async delMany(e){return Ds(e,this.store)}}class Ns extends Bs{constructor(e){super(e)}async getData(e){return(await this.get(e)).data}async setData(e,t){return this.set(e,t)}async getCheckData(e){const t=await this.get(e);return t.expireTime&&t.expireTime<Date.now()?(await super.del(e),null):t.data}async setCheckData(e,t,n){const o=Date.now()+(n?.expireTime||1e3*60*60*24*10),i={data:t,updatedAt:n?.updatedAt||Date.now(),expireTime:o};return await this.set(e,i),t}async checkNew(e,t){const n=await this.get(e);if(!n)return!0;if(!t?.updatedAt)return!1;const s=new Date(t.updatedAt).getTime();return isNaN(s)?!1:s>n.updatedAt}async delCheckData(e){return this.del(e)}}class $s extends Ns{key;constructor(e){const{key:t,...n}=e||{};super(n),this.key=t||"my-cache"}async getData(){return super.getCheckData(this.key)}async setData(e,t){super.setCheckData(this.key,e,t)}async del(){await super.del(this.key)}}class Fs extends As{constructor(e){super({...e,cache:new $s({key:"login"})})}}const P=ln(),fn=()=>{const r=window.location.href,t=new URL(r).searchParams.get("redirect");if(t){setTimeout(()=>{const n=decodeURIComponent(t);window.open(n,"_self")},2e3);return}},ce=()=>{ys({type:"login-success",data:{}}),setTimeout(()=>{gn()},2e3)},zs=async r=>{const{loginMethod:e,data:t}=r;switch(e){case"password":await Hs(t);break;case"phone":await Ws(t);break;case"wechat-mp":await Os(t);break;case"wechat":await Vs(t);break;case"web":await js();break;default:console.warn("未知的登录方式:",e)}},js=async r=>{const e=new URL("https://kevisual.cn/api/router"),t=new nt({url:"https://kevisual.cn/api/router"}),n=new Fs({query:t}),s=n.loginWithWeb(e.origin,{});console.log("打开网页登录:",s),window.open(s.url,"_blank"),await n.pollLoginStatus(s)?ce():P.error("网页登录失败,请重试")},Hs=async r=>{console.log("使用用户名密码登录:",r);let e=!0;if(await q.checkLocalToken()&&(await q.checkLocalUser())?.username===r?.username&&(await q.getMe()).code===200&&(e=!1,console.log("已登录,跳过登录步骤"),P.success("已登录")),!e){ce();return}localStorage.removeItem("token");const n=await q.login({username:r.username,password:r.password});n.code===200?(console.log("登录成功"),P.success("登录成功"),ce()):P.error(`登录失败: ${n.message}`)},Ws=async r=>{console.log("使用手机号登录:",r)},Vs=async r=>{console.log("使用微信登录:",r)},Os=async r=>{console.log("使用微信公众号登录:",r)},gn=()=>{const r=new URL(window.location.href);r.searchParams.delete("code"),r.searchParams.delete("state"),r.searchParams.delete("user-check"),r.searchParams.delete("redirect"),window.history.replaceState({},document.title,r.toString())},Ks=async()=>{const r=new URL(window.location.href),e=r.searchParams.get("code");if(r.searchParams.get("state")?.includes?.("-")||!e)return;const n=await q.loginByWechat({code:e});n.code===200?(P.success("登录成功"),ce()):(P.error(n.message||"登录失败"),gn())},Qs=async()=>{const r=new URL(window.location.href),e=r.searchParams.get("state"),[t,n]=e?e.split("-"):[null,null];if(console.log("检查微信公众号登录流程:",t,n,e),t==="1")Ys();else if(t==="2"){const s=r.searchParams.get("code"),o=await q.post({path:"wx",key:"mplogin",state:n,code:s});o.code===200?P.success("登录成功"):P.error(o.message||"登录失败"),mn()}},Gs=async()=>{const r="user-check",e=new URL(location.href),t=e.searchParams.get("redirect"),n=t?decodeURIComponent(t):"",s=e.searchParams.get(r);if(t&&s&&(await q.getMe()).code===200){P.success("登录插件中...");const i=await q.cacheStore.getAccessToken(),c=new URL(n);return c.searchParams.set("token",i+""),setTimeout(()=>{window.open(c.toString(),"_blank")},2e3),{code:200,data:{redirectUrl:n}}}return{code:400,data:{redirectUrl:""}}},Js=()=>{const r=navigator.userAgent.toLowerCase();return/micromessenger/i.test(r)},mn=(r=2e3)=>{if(!Js()){setTimeout(()=>{window.close()},r);return}window.WeixinJSBridge?setTimeout(()=>{window.WeixinJSBridge.call("closeWindow")},r):setTimeout(()=>{window.close()},r)},Ys=async()=>{const r="https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect",e=En,t=new URL(window.location.href),n=t.searchParams.get("state");let[s,o]=n?n.split("-"):[null,null];const i=new URL(t.pathname,t.origin);o="2-"+o;const c=encodeURIComponent(i.toString());document.body.innerHTML="<p>正在准备跳转到微信公众号授权页面...</p>";const a="snsapi_userinfo";if(!o){alert("Invalid state. Please try again later."),mn();return}const u=r.replace("APPID",e).replace("REDIRECT_URI",c).replace("SCOPE",a).replace("STATE",o);setTimeout(()=>{window.location.href=u},100)};setTimeout(()=>{Qs()},100);const Xs=async()=>{const r=await q.post({path:"wx",key:"get-qrcode-ticket"});return r.code!==200?(P.error("获取二维码失败"),null):r?.data},Zs=r=>{let e=!0;const t=async()=>{const o=await q.post({path:"wx",key:"check-qrcode-login",payload:{ticket:r}});o.code===200?(P.success("登录成功"),clearTimeout(n),ce()):(o.code===401?console.log("等待扫码登录..."):console.log("扫码登录状态:",o),e&&setTimeout(t,2e3))},n=setTimeout(t,2e3);return()=>{console.log("停止检测扫码登录状态"),clearTimeout(n),e=!1}},Et=async r=>{let e=r?.redirect_uri;const{appid:t}=r||{};e||(e=window.location.href);const n=new URL(e);if(n.searchParams.delete("code"),n.searchParams.delete("state"),e=n.toString(),console.log("redirect_uri",e),!t){console.error("appid is not cant be empty");return}const s=new WxLogin({self_redirect:!1,id:"weixinLogin",appid:t,scope:"snsapi_login",redirect_uri:encodeURIComponent(e),state:Math.ceil(Math.random()*1e3),stylelite:!0,href:"data:text/css;base64,LmltcG93ZXJCb3ggLnFyY29kZSB7d2lkdGg6IDIwMHB4O30NCi5pbXBvd2VyQm94IC50aXRsZSB7ZGlzcGxheTogbm9uZTt9DQouaW1wb3dlckJveCAuaW5mbyB7d2lkdGg6IDIwMHB4O30NCi5zdGF0dXNfaWNvbiB7ZGlzcGxheTogbm9uZX0NCi5pbXBvd2VyQm94IC5zdGF0dXMge3RleHQtYWxpZ246IGNlbnRlcjt9"}),o=document.querySelector("#weixinLogin");if(o){const i=o.querySelector("iframe");i&&(i.style.height="300px")}return s};function er(r){const e=document.createElement("script");if(e.type="text/javascript",e.src="//res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js",e.id="weixinLogin-js",document.getElementById("weixinLogin-js")){Et(r);return}const t=document.body.appendChild(e);t.onload=function(){Et(r)}}function tr(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var X={},Se,At;function nr(){return At||(At=1,Se=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Se}var _e={},W={},xt;function G(){if(xt)return W;xt=1;let r;const e=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return W.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17},W.getSymbolTotalCodewords=function(n){return e[n]},W.getBCHDigit=function(t){let n=0;for(;t!==0;)n++,t>>>=1;return n},W.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');r=n},W.isKanjiModeEnabled=function(){return typeof r<"u"},W.toSJIS=function(n){return r(n)},W}var Re={},Lt;function it(){return Lt||(Lt=1,(function(r){r.L={bit:1},r.M={bit:0},r.Q={bit:3},r.H={bit:2};function e(t){if(typeof t!="string")throw new Error("Param is not a string");switch(t.toLowerCase()){case"l":case"low":return r.L;case"m":case"medium":return r.M;case"q":case"quartile":return r.Q;case"h":case"high":return r.H;default:throw new Error("Unknown EC Level: "+t)}}r.isValid=function(n){return n&&typeof n.bit<"u"&&n.bit>=0&&n.bit<4},r.from=function(n,s){if(r.isValid(n))return n;try{return e(n)}catch{return s}}})(Re)),Re}var Ie,St;function sr(){if(St)return Ie;St=1;function r(){this.buffer=[],this.length=0}return r.prototype={get:function(e){const t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)===1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},Ie=r,Ie}var De,_t;function rr(){if(_t)return De;_t=1;function r(e){if(!e||e<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}return r.prototype.set=function(e,t,n,s){const o=e*this.size+t;this.data[o]=n,s&&(this.reservedBit[o]=!0)},r.prototype.get=function(e,t){return this.data[e*this.size+t]},r.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},r.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},De=r,De}var Me={},Rt;function or(){return Rt||(Rt=1,(function(r){const e=G().getSymbolSize;r.getRowColCoords=function(n){if(n===1)return[];const s=Math.floor(n/7)+2,o=e(n),i=o===145?26:Math.ceil((o-13)/(2*s-2))*2,c=[o-7];for(let a=1;a<s-1;a++)c[a]=c[a-1]-i;return c.push(6),c.reverse()},r.getPositions=function(n){const s=[],o=r.getRowColCoords(n),i=o.length;for(let c=0;c<i;c++)for(let a=0;a<i;a++)c===0&&a===0||c===0&&a===i-1||c===i-1&&a===0||s.push([o[c],o[a]]);return s}})(Me)),Me}var Ue={},It;function ir(){if(It)return Ue;It=1;const r=G().getSymbolSize,e=7;return Ue.getPositions=function(n){const s=r(n);return[[0,0],[s-e,0],[0,s-e]]},Ue}var qe={},Dt;function ar(){return Dt||(Dt=1,(function(r){r.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const e={N1:3,N2:3,N3:40,N4:10};r.isValid=function(s){return s!=null&&s!==""&&!isNaN(s)&&s>=0&&s<=7},r.from=function(s){return r.isValid(s)?parseInt(s,10):void 0},r.getPenaltyN1=function(s){const o=s.size;let i=0,c=0,a=0,u=null,l=null;for(let h=0;h<o;h++){c=a=0,u=l=null;for(let m=0;m<o;m++){let g=s.get(h,m);g===u?c++:(c>=5&&(i+=e.N1+(c-5)),u=g,c=1),g=s.get(m,h),g===l?a++:(a>=5&&(i+=e.N1+(a-5)),l=g,a=1)}c>=5&&(i+=e.N1+(c-5)),a>=5&&(i+=e.N1+(a-5))}return i},r.getPenaltyN2=function(s){const o=s.size;let i=0;for(let c=0;c<o-1;c++)for(let a=0;a<o-1;a++){const u=s.get(c,a)+s.get(c,a+1)+s.get(c+1,a)+s.get(c+1,a+1);(u===4||u===0)&&i++}return i*e.N2},r.getPenaltyN3=function(s){const o=s.size;let i=0,c=0,a=0;for(let u=0;u<o;u++){c=a=0;for(let l=0;l<o;l++)c=c<<1&2047|s.get(u,l),l>=10&&(c===1488||c===93)&&i++,a=a<<1&2047|s.get(l,u),l>=10&&(a===1488||a===93)&&i++}return i*e.N3},r.getPenaltyN4=function(s){let o=0;const i=s.data.length;for(let a=0;a<i;a++)o+=s.data[a];return Math.abs(Math.ceil(o*100/i/5)-10)*e.N4};function t(n,s,o){switch(n){case r.Patterns.PATTERN000:return(s+o)%2===0;case r.Patterns.PATTERN001:return s%2===0;case r.Patterns.PATTERN010:return o%3===0;case r.Patterns.PATTERN011:return(s+o)%3===0;case r.Patterns.PATTERN100:return(Math.floor(s/2)+Math.floor(o/3))%2===0;case r.Patterns.PATTERN101:return s*o%2+s*o%3===0;case r.Patterns.PATTERN110:return(s*o%2+s*o%3)%2===0;case r.Patterns.PATTERN111:return(s*o%3+(s+o)%2)%2===0;default:throw new Error("bad maskPattern:"+n)}}r.applyMask=function(s,o){const i=o.size;for(let c=0;c<i;c++)for(let a=0;a<i;a++)o.isReserved(a,c)||o.xor(a,c,t(s,a,c))},r.getBestMask=function(s,o){const i=Object.keys(r.Patterns).length;let c=0,a=1/0;for(let u=0;u<i;u++){o(u),r.applyMask(u,s);const l=r.getPenaltyN1(s)+r.getPenaltyN2(s)+r.getPenaltyN3(s)+r.getPenaltyN4(s);r.applyMask(u,s),l<a&&(a=l,c=u)}return c}})(qe)),qe}var fe={},Mt;function pn(){if(Mt)return fe;Mt=1;const r=it(),e=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],t=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return fe.getBlocksCount=function(s,o){switch(o){case r.L:return e[(s-1)*4+0];case r.M:return e[(s-1)*4+1];case r.Q:return e[(s-1)*4+2];case r.H:return e[(s-1)*4+3];default:return}},fe.getTotalCodewordsCount=function(s,o){switch(o){case r.L:return t[(s-1)*4+0];case r.M:return t[(s-1)*4+1];case r.Q:return t[(s-1)*4+2];case r.H:return t[(s-1)*4+3];default:return}},fe}var Pe={},re={},Ut;function cr(){if(Ut)return re;Ut=1;const r=new Uint8Array(512),e=new Uint8Array(256);return(function(){let n=1;for(let s=0;s<255;s++)r[s]=n,e[n]=s,n<<=1,n&256&&(n^=285);for(let s=255;s<512;s++)r[s]=r[s-255]})(),re.log=function(n){if(n<1)throw new Error("log("+n+")");return e[n]},re.exp=function(n){return r[n]},re.mul=function(n,s){return n===0||s===0?0:r[e[n]+e[s]]},re}var qt;function ur(){return qt||(qt=1,(function(r){const e=cr();r.mul=function(n,s){const o=new Uint8Array(n.length+s.length-1);for(let i=0;i<n.length;i++)for(let c=0;c<s.length;c++)o[i+c]^=e.mul(n[i],s[c]);return o},r.mod=function(n,s){let o=new Uint8Array(n);for(;o.length-s.length>=0;){const i=o[0];for(let a=0;a<s.length;a++)o[a]^=e.mul(s[a],i);let c=0;for(;c<o.length&&o[c]===0;)c++;o=o.slice(c)}return o},r.generateECPolynomial=function(n){let s=new Uint8Array([1]);for(let o=0;o<n;o++)s=r.mul(s,new Uint8Array([1,e.exp(o)]));return s}})(Pe)),Pe}var Be,Pt;function lr(){if(Pt)return Be;Pt=1;const r=ur();function e(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}return e.prototype.initialize=function(n){this.degree=n,this.genPoly=r.generateECPolynomial(this.degree)},e.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const s=new Uint8Array(n.length+this.degree);s.set(n);const o=r.mod(s,this.genPoly),i=this.degree-o.length;if(i>0){const c=new Uint8Array(this.degree);return c.set(o,i),c}return o},Be=e,Be}var Ne={},$e={},Fe={},Bt;function wn(){return Bt||(Bt=1,Fe.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}),Fe}var $={},Nt;function yn(){if(Nt)return $;Nt=1;const r="[0-9]+",e="[A-Z $%*+\\-./:]+";let t="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";t=t.replace(/u/g,"\\u");const n="(?:(?![A-Z0-9 $%*+\\-./:]|"+t+`)(?:.|[\r
|
|
159
|
+
]))+`;$.KANJI=new RegExp(t,"g"),$.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),$.BYTE=new RegExp(n,"g"),$.NUMERIC=new RegExp(r,"g"),$.ALPHANUMERIC=new RegExp(e,"g");const s=new RegExp("^"+t+"$"),o=new RegExp("^"+r+"$"),i=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return $.testKanji=function(a){return s.test(a)},$.testNumeric=function(a){return o.test(a)},$.testAlphanumeric=function(a){return i.test(a)},$}var $t;function J(){return $t||($t=1,(function(r){const e=wn(),t=yn();r.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},r.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},r.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},r.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},r.MIXED={bit:-1},r.getCharCountIndicator=function(o,i){if(!o.ccBits)throw new Error("Invalid mode: "+o);if(!e.isValid(i))throw new Error("Invalid version: "+i);return i>=1&&i<10?o.ccBits[0]:i<27?o.ccBits[1]:o.ccBits[2]},r.getBestModeForData=function(o){return t.testNumeric(o)?r.NUMERIC:t.testAlphanumeric(o)?r.ALPHANUMERIC:t.testKanji(o)?r.KANJI:r.BYTE},r.toString=function(o){if(o&&o.id)return o.id;throw new Error("Invalid mode")},r.isValid=function(o){return o&&o.bit&&o.ccBits};function n(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"numeric":return r.NUMERIC;case"alphanumeric":return r.ALPHANUMERIC;case"kanji":return r.KANJI;case"byte":return r.BYTE;default:throw new Error("Unknown mode: "+s)}}r.from=function(o,i){if(r.isValid(o))return o;try{return n(o)}catch{return i}}})($e)),$e}var Ft;function hr(){return Ft||(Ft=1,(function(r){const e=G(),t=pn(),n=it(),s=J(),o=wn(),i=7973,c=e.getBCHDigit(i);function a(m,g,d){for(let w=1;w<=40;w++)if(g<=r.getCapacity(w,d,m))return w}function u(m,g){return s.getCharCountIndicator(m,g)+4}function l(m,g){let d=0;return m.forEach(function(w){const f=u(w.mode,g);d+=f+w.getBitsLength()}),d}function h(m,g){for(let d=1;d<=40;d++)if(l(m,d)<=r.getCapacity(d,g,s.MIXED))return d}r.from=function(g,d){return o.isValid(g)?parseInt(g,10):d},r.getCapacity=function(g,d,w){if(!o.isValid(g))throw new Error("Invalid QR Code version");typeof w>"u"&&(w=s.BYTE);const f=e.getSymbolTotalCodewords(g),y=t.getTotalCodewordsCount(g,d),v=(f-y)*8;if(w===s.MIXED)return v;const p=v-u(w,g);switch(w){case s.NUMERIC:return Math.floor(p/10*3);case s.ALPHANUMERIC:return Math.floor(p/11*2);case s.KANJI:return Math.floor(p/13);case s.BYTE:default:return Math.floor(p/8)}},r.getBestVersionForData=function(g,d){let w;const f=n.from(d,n.M);if(Array.isArray(g)){if(g.length>1)return h(g,f);if(g.length===0)return 1;w=g[0]}else w=g;return a(w.mode,w.getLength(),f)},r.getEncodedBits=function(g){if(!o.isValid(g)||g<7)throw new Error("Invalid QR Code version");let d=g<<12;for(;e.getBCHDigit(d)-c>=0;)d^=i<<e.getBCHDigit(d)-c;return g<<12|d}})(Ne)),Ne}var ze={},zt;function dr(){if(zt)return ze;zt=1;const r=G(),e=1335,t=21522,n=r.getBCHDigit(e);return ze.getEncodedBits=function(o,i){const c=o.bit<<3|i;let a=c<<10;for(;r.getBCHDigit(a)-n>=0;)a^=e<<r.getBCHDigit(a)-n;return(c<<10|a)^t},ze}var je={},He,jt;function fr(){if(jt)return He;jt=1;const r=J();function e(t){this.mode=r.NUMERIC,this.data=t.toString()}return e.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)},e.prototype.getLength=function(){return this.data.length},e.prototype.getBitsLength=function(){return e.getBitsLength(this.data.length)},e.prototype.write=function(n){let s,o,i;for(s=0;s+3<=this.data.length;s+=3)o=this.data.substr(s,3),i=parseInt(o,10),n.put(i,10);const c=this.data.length-s;c>0&&(o=this.data.substr(s),i=parseInt(o,10),n.put(i,c*3+1))},He=e,He}var We,Ht;function gr(){if(Ht)return We;Ht=1;const r=J(),e=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function t(n){this.mode=r.ALPHANUMERIC,this.data=n}return t.getBitsLength=function(s){return 11*Math.floor(s/2)+6*(s%2)},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(s){let o;for(o=0;o+2<=this.data.length;o+=2){let i=e.indexOf(this.data[o])*45;i+=e.indexOf(this.data[o+1]),s.put(i,11)}this.data.length%2&&s.put(e.indexOf(this.data[o]),6)},We=t,We}var Ve,Wt;function mr(){if(Wt)return Ve;Wt=1;const r=J();function e(t){this.mode=r.BYTE,typeof t=="string"?this.data=new TextEncoder().encode(t):this.data=new Uint8Array(t)}return e.getBitsLength=function(n){return n*8},e.prototype.getLength=function(){return this.data.length},e.prototype.getBitsLength=function(){return e.getBitsLength(this.data.length)},e.prototype.write=function(t){for(let n=0,s=this.data.length;n<s;n++)t.put(this.data[n],8)},Ve=e,Ve}var Oe,Vt;function pr(){if(Vt)return Oe;Vt=1;const r=J(),e=G();function t(n){this.mode=r.KANJI,this.data=n}return t.getBitsLength=function(s){return s*13},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(n){let s;for(s=0;s<this.data.length;s++){let o=e.toSJIS(this.data[s]);if(o>=33088&&o<=40956)o-=33088;else if(o>=57408&&o<=60351)o-=49472;else throw new Error("Invalid SJIS character: "+this.data[s]+`
|
|
160
|
+
Make sure your charset is UTF-8`);o=(o>>>8&255)*192+(o&255),n.put(o,13)}},Oe=t,Oe}var Ke={exports:{}},Ot;function wr(){return Ot||(Ot=1,(function(r){var e={single_source_shortest_paths:function(t,n,s){var o={},i={};i[n]=0;var c=e.PriorityQueue.make();c.push(n,0);for(var a,u,l,h,m,g,d,w,f;!c.empty();){a=c.pop(),u=a.value,h=a.cost,m=t[u]||{};for(l in m)m.hasOwnProperty(l)&&(g=m[l],d=h+g,w=i[l],f=typeof i[l]>"u",(f||w>d)&&(i[l]=d,c.push(l,d),o[l]=u))}if(typeof s<"u"&&typeof i[s]>"u"){var y=["Could not find a path from ",n," to ",s,"."].join("");throw new Error(y)}return o},extract_shortest_path_from_predecessor_list:function(t,n){for(var s=[],o=n;o;)s.push(o),t[o],o=t[o];return s.reverse(),s},find_path:function(t,n,s){var o=e.single_source_shortest_paths(t,n,s);return e.extract_shortest_path_from_predecessor_list(o,s)},PriorityQueue:{make:function(t){var n=e.PriorityQueue,s={},o;t=t||{};for(o in n)n.hasOwnProperty(o)&&(s[o]=n[o]);return s.queue=[],s.sorter=t.sorter||n.default_sorter,s},default_sorter:function(t,n){return t.cost-n.cost},push:function(t,n){var s={value:t,cost:n};this.queue.push(s),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};r.exports=e})(Ke)),Ke.exports}var Kt;function yr(){return Kt||(Kt=1,(function(r){const e=J(),t=fr(),n=gr(),s=mr(),o=pr(),i=yn(),c=G(),a=wr();function u(y){return unescape(encodeURIComponent(y)).length}function l(y,v,p){const k=[];let _;for(;(_=y.exec(p))!==null;)k.push({data:_[0],index:_.index,mode:v,length:_[0].length});return k}function h(y){const v=l(i.NUMERIC,e.NUMERIC,y),p=l(i.ALPHANUMERIC,e.ALPHANUMERIC,y);let k,_;return c.isKanjiModeEnabled()?(k=l(i.BYTE,e.BYTE,y),_=l(i.KANJI,e.KANJI,y)):(k=l(i.BYTE_KANJI,e.BYTE,y),_=[]),v.concat(p,k,_).sort(function(x,A){return x.index-A.index}).map(function(x){return{data:x.data,mode:x.mode,length:x.length}})}function m(y,v){switch(v){case e.NUMERIC:return t.getBitsLength(y);case e.ALPHANUMERIC:return n.getBitsLength(y);case e.KANJI:return o.getBitsLength(y);case e.BYTE:return s.getBitsLength(y)}}function g(y){return y.reduce(function(v,p){const k=v.length-1>=0?v[v.length-1]:null;return k&&k.mode===p.mode?(v[v.length-1].data+=p.data,v):(v.push(p),v)},[])}function d(y){const v=[];for(let p=0;p<y.length;p++){const k=y[p];switch(k.mode){case e.NUMERIC:v.push([k,{data:k.data,mode:e.ALPHANUMERIC,length:k.length},{data:k.data,mode:e.BYTE,length:k.length}]);break;case e.ALPHANUMERIC:v.push([k,{data:k.data,mode:e.BYTE,length:k.length}]);break;case e.KANJI:v.push([k,{data:k.data,mode:e.BYTE,length:u(k.data)}]);break;case e.BYTE:v.push([{data:k.data,mode:e.BYTE,length:u(k.data)}])}}return v}function w(y,v){const p={},k={start:{}};let _=["start"];for(let T=0;T<y.length;T++){const x=y[T],A=[];for(let b=0;b<x.length;b++){const S=x[b],C=""+T+b;A.push(C),p[C]={node:S,lastCount:0},k[C]={};for(let L=0;L<_.length;L++){const E=_[L];p[E]&&p[E].node.mode===S.mode?(k[E][C]=m(p[E].lastCount+S.length,S.mode)-m(p[E].lastCount,S.mode),p[E].lastCount+=S.length):(p[E]&&(p[E].lastCount=S.length),k[E][C]=m(S.length,S.mode)+4+e.getCharCountIndicator(S.mode,v))}}_=A}for(let T=0;T<_.length;T++)k[_[T]].end=0;return{map:k,table:p}}function f(y,v){let p;const k=e.getBestModeForData(y);if(p=e.from(v,k),p!==e.BYTE&&p.bit<k.bit)throw new Error('"'+y+'" cannot be encoded with mode '+e.toString(p)+`.
|
|
161
|
+
Suggested mode is: `+e.toString(k));switch(p===e.KANJI&&!c.isKanjiModeEnabled()&&(p=e.BYTE),p){case e.NUMERIC:return new t(y);case e.ALPHANUMERIC:return new n(y);case e.KANJI:return new o(y);case e.BYTE:return new s(y)}}r.fromArray=function(v){return v.reduce(function(p,k){return typeof k=="string"?p.push(f(k,null)):k.data&&p.push(f(k.data,k.mode)),p},[])},r.fromString=function(v,p){const k=h(v,c.isKanjiModeEnabled()),_=d(k),T=w(_,p),x=a.find_path(T.map,"start","end"),A=[];for(let b=1;b<x.length-1;b++)A.push(T.table[x[b]].node);return r.fromArray(g(A))},r.rawSplit=function(v){return r.fromArray(h(v,c.isKanjiModeEnabled()))}})(je)),je}var Qt;function vr(){if(Qt)return _e;Qt=1;const r=G(),e=it(),t=sr(),n=rr(),s=or(),o=ir(),i=ar(),c=pn(),a=lr(),u=hr(),l=dr(),h=J(),m=yr();function g(T,x){const A=T.size,b=o.getPositions(x);for(let S=0;S<b.length;S++){const C=b[S][0],L=b[S][1];for(let E=-1;E<=7;E++)if(!(C+E<=-1||A<=C+E))for(let R=-1;R<=7;R++)L+R<=-1||A<=L+R||(E>=0&&E<=6&&(R===0||R===6)||R>=0&&R<=6&&(E===0||E===6)||E>=2&&E<=4&&R>=2&&R<=4?T.set(C+E,L+R,!0,!0):T.set(C+E,L+R,!1,!0))}}function d(T){const x=T.size;for(let A=8;A<x-8;A++){const b=A%2===0;T.set(A,6,b,!0),T.set(6,A,b,!0)}}function w(T,x){const A=s.getPositions(x);for(let b=0;b<A.length;b++){const S=A[b][0],C=A[b][1];for(let L=-2;L<=2;L++)for(let E=-2;E<=2;E++)L===-2||L===2||E===-2||E===2||L===0&&E===0?T.set(S+L,C+E,!0,!0):T.set(S+L,C+E,!1,!0)}}function f(T,x){const A=T.size,b=u.getEncodedBits(x);let S,C,L;for(let E=0;E<18;E++)S=Math.floor(E/3),C=E%3+A-8-3,L=(b>>E&1)===1,T.set(S,C,L,!0),T.set(C,S,L,!0)}function y(T,x,A){const b=T.size,S=l.getEncodedBits(x,A);let C,L;for(C=0;C<15;C++)L=(S>>C&1)===1,C<6?T.set(C,8,L,!0):C<8?T.set(C+1,8,L,!0):T.set(b-15+C,8,L,!0),C<8?T.set(8,b-C-1,L,!0):C<9?T.set(8,15-C-1+1,L,!0):T.set(8,15-C-1,L,!0);T.set(b-8,8,1,!0)}function v(T,x){const A=T.size;let b=-1,S=A-1,C=7,L=0;for(let E=A-1;E>0;E-=2)for(E===6&&E--;;){for(let R=0;R<2;R++)if(!T.isReserved(S,E-R)){let H=!1;L<x.length&&(H=(x[L]>>>C&1)===1),T.set(S,E-R,H),C--,C===-1&&(L++,C=7)}if(S+=b,S<0||A<=S){S-=b,b=-b;break}}}function p(T,x,A){const b=new t;A.forEach(function(R){b.put(R.mode.bit,4),b.put(R.getLength(),h.getCharCountIndicator(R.mode,T)),R.write(b)});const S=r.getSymbolTotalCodewords(T),C=c.getTotalCodewordsCount(T,x),L=(S-C)*8;for(b.getLengthInBits()+4<=L&&b.put(0,4);b.getLengthInBits()%8!==0;)b.putBit(0);const E=(L-b.getLengthInBits())/8;for(let R=0;R<E;R++)b.put(R%2?17:236,8);return k(b,T,x)}function k(T,x,A){const b=r.getSymbolTotalCodewords(x),S=c.getTotalCodewordsCount(x,A),C=b-S,L=c.getBlocksCount(x,A),E=b%L,R=L-E,H=Math.floor(b/L),ne=Math.floor(C/L),xn=ne+1,at=H-ne,Ln=new a(at);let ve=0;const le=new Array(L),ct=new Array(L);let ke=0;const Sn=new Uint8Array(T.buffer);for(let Y=0;Y<L;Y++){const Te=Y<R?ne:xn;le[Y]=Sn.slice(ve,ve+Te),ct[Y]=Ln.encode(le[Y]),ve+=Te,ke=Math.max(ke,Te)}const be=new Uint8Array(b);let ut=0,F,z;for(F=0;F<ke;F++)for(z=0;z<L;z++)F<le[z].length&&(be[ut++]=le[z][F]);for(F=0;F<at;F++)for(z=0;z<L;z++)be[ut++]=ct[z][F];return be}function _(T,x,A,b){let S;if(Array.isArray(T))S=m.fromArray(T);else if(typeof T=="string"){let H=x;if(!H){const ne=m.rawSplit(T);H=u.getBestVersionForData(ne,A)}S=m.fromString(T,H||40)}else throw new Error("Invalid data");const C=u.getBestVersionForData(S,A);if(!C)throw new Error("The amount of data is too big to be stored in a QR Code");if(!x)x=C;else if(x<C)throw new Error(`
|
|
162
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
163
|
+
Minimum version required to store current data is: `+C+`.
|
|
164
|
+
`);const L=p(x,A,S),E=r.getSymbolSize(x),R=new n(E);return g(R,x),d(R),w(R,x),y(R,A,0),x>=7&&f(R,x),v(R,L),isNaN(b)&&(b=i.getBestMask(R,y.bind(null,R,A))),i.applyMask(b,R),y(R,A,b),{modules:R,version:x,errorCorrectionLevel:A,maskPattern:b,segments:S}}return _e.create=function(x,A){if(typeof x>"u"||x==="")throw new Error("No input text");let b=e.M,S,C;return typeof A<"u"&&(b=e.from(A.errorCorrectionLevel,e.M),S=u.from(A.version),C=i.from(A.maskPattern),A.toSJISFunc&&r.setToSJISFunction(A.toSJISFunc)),_(x,S,b,C)},_e}var Qe={},Ge={},Gt;function vn(){return Gt||(Gt=1,(function(r){function e(t){if(typeof t=="number"&&(t=t.toString()),typeof t!="string")throw new Error("Color should be defined as hex string");let n=t.slice().replace("#","").split("");if(n.length<3||n.length===5||n.length>8)throw new Error("Invalid hex color: "+t);(n.length===3||n.length===4)&&(n=Array.prototype.concat.apply([],n.map(function(o){return[o,o]}))),n.length===6&&n.push("F","F");const s=parseInt(n.join(""),16);return{r:s>>24&255,g:s>>16&255,b:s>>8&255,a:s&255,hex:"#"+n.slice(0,6).join("")}}r.getOptions=function(n){n||(n={}),n.color||(n.color={});const s=typeof n.margin>"u"||n.margin===null||n.margin<0?4:n.margin,o=n.width&&n.width>=21?n.width:void 0,i=n.scale||4;return{width:o,scale:o?4:i,margin:s,color:{dark:e(n.color.dark||"#000000ff"),light:e(n.color.light||"#ffffffff")},type:n.type,rendererOpts:n.rendererOpts||{}}},r.getScale=function(n,s){return s.width&&s.width>=n+s.margin*2?s.width/(n+s.margin*2):s.scale},r.getImageWidth=function(n,s){const o=r.getScale(n,s);return Math.floor((n+s.margin*2)*o)},r.qrToImageData=function(n,s,o){const i=s.modules.size,c=s.modules.data,a=r.getScale(i,o),u=Math.floor((i+o.margin*2)*a),l=o.margin*a,h=[o.color.light,o.color.dark];for(let m=0;m<u;m++)for(let g=0;g<u;g++){let d=(m*u+g)*4,w=o.color.light;if(m>=l&&g>=l&&m<u-l&&g<u-l){const f=Math.floor((m-l)/a),y=Math.floor((g-l)/a);w=h[c[f*i+y]?1:0]}n[d++]=w.r,n[d++]=w.g,n[d++]=w.b,n[d]=w.a}}})(Ge)),Ge}var Jt;function kr(){return Jt||(Jt=1,(function(r){const e=vn();function t(s,o,i){s.clearRect(0,0,o.width,o.height),o.style||(o.style={}),o.height=i,o.width=i,o.style.height=i+"px",o.style.width=i+"px"}function n(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}r.render=function(o,i,c){let a=c,u=i;typeof a>"u"&&(!i||!i.getContext)&&(a=i,i=void 0),i||(u=n()),a=e.getOptions(a);const l=e.getImageWidth(o.modules.size,a),h=u.getContext("2d"),m=h.createImageData(l,l);return e.qrToImageData(m.data,o,a),t(h,u,l),h.putImageData(m,0,0),u},r.renderToDataURL=function(o,i,c){let a=c;typeof a>"u"&&(!i||!i.getContext)&&(a=i,i=void 0),a||(a={});const u=r.render(o,i,a),l=a.type||"image/png",h=a.rendererOpts||{};return u.toDataURL(l,h.quality)}})(Qe)),Qe}var Je={},Yt;function br(){if(Yt)return Je;Yt=1;const r=vn();function e(s,o){const i=s.a/255,c=o+'="'+s.hex+'"';return i<1?c+" "+o+'-opacity="'+i.toFixed(2).slice(1)+'"':c}function t(s,o,i){let c=s+o;return typeof i<"u"&&(c+=" "+i),c}function n(s,o,i){let c="",a=0,u=!1,l=0;for(let h=0;h<s.length;h++){const m=Math.floor(h%o),g=Math.floor(h/o);!m&&!u&&(u=!0),s[h]?(l++,h>0&&m>0&&s[h-1]||(c+=u?t("M",m+i,.5+g+i):t("m",a,0),a=0,u=!1),m+1<o&&s[h+1]||(c+=t("h",l),l=0)):a++}return c}return Je.render=function(o,i,c){const a=r.getOptions(i),u=o.modules.size,l=o.modules.data,h=u+a.margin*2,m=a.color.light.a?"<path "+e(a.color.light,"fill")+' d="M0 0h'+h+"v"+h+'H0z"/>':"",g="<path "+e(a.color.dark,"stroke")+' d="'+n(l,u,a.margin)+'"/>',d='viewBox="0 0 '+h+" "+h+'"',f='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+d+' shape-rendering="crispEdges">'+m+g+`</svg>
|
|
165
|
+
`;return typeof c=="function"&&c(null,f),f},Je}var Xt;function Tr(){if(Xt)return X;Xt=1;const r=nr(),e=vr(),t=kr(),n=br();function s(o,i,c,a,u){const l=[].slice.call(arguments,1),h=l.length,m=typeof l[h-1]=="function";if(!m&&!r())throw new Error("Callback required as last argument");if(m){if(h<2)throw new Error("Too few arguments provided");h===2?(u=c,c=i,i=a=void 0):h===3&&(i.getContext&&typeof u>"u"?(u=a,a=void 0):(u=a,a=c,c=i,i=void 0))}else{if(h<1)throw new Error("Too few arguments provided");return h===1?(c=i,i=a=void 0):h===2&&!i.getContext&&(a=c,c=i,i=void 0),new Promise(function(g,d){try{const w=e.create(c,a);g(o(w,i,a))}catch(w){d(w)}})}try{const g=e.create(c,a);u(null,o(g,i,a))}catch(g){u(g)}}return X.create=e.create,X.toCanvas=s.bind(null,t.render),X.toDataURL=s.bind(null,t.renderToDataURL),X.toString=s.bind(null,function(o,i,c){return n.render(o,c)}),X}var Cr=Tr();const Er=tr(Cr),Ar=r=>{var e={errorCorrectionLevel:"H",type:"image/jpeg",margin:1,width:300};let t=null;const n=async a=>{const u=new URL(window.location.href),l=new URL(u.pathname,u.origin);l.searchParams.set("state","1-"+a),console.log("生成登录二维码链接:",l.toString());var h=r||document.getElementById("qrcode");await Er.toDataURL(h,l.toString(),e)},s=async a=>{const u=await fetch(`/api/router?path=wx&key=checkLogin&state=${a}`).then(l=>l.json());if(u.code===200){console.log(u);const l=u.data;l&&(localStorage.setItem("token",l.accessToken),await q.setLoginToken(l)),c(),setTimeout(()=>{fn()},1e3)}else t=setTimeout(()=>{s(a),console.log("继续检测登录状态")},2e3)},o=Math.random().toString(36).substring(2,15);n(o),s(o);const i=setInterval(()=>{const a=Math.random().toString(36).substring(2,15);clearTimeout(t),n(a),s(a),console.log("更新二维码")},9e4),c=()=>{clearTimeout(t),clearInterval(i),console.log("停止检测登录状态")};return{createQrcode:n,clear:c}};function xr(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Ye={exports:{}},Zt;function Lr(){return Zt||(Zt=1,(function(r){var e=Object.prototype.hasOwnProperty,t="~";function n(){}Object.create&&(n.prototype=Object.create(null),new n().__proto__||(t=!1));function s(a,u,l){this.fn=a,this.context=u,this.once=l||!1}function o(a,u,l,h,m){if(typeof l!="function")throw new TypeError("The listener must be a function");var g=new s(l,h||a,m),d=t?t+u:u;return a._events[d]?a._events[d].fn?a._events[d]=[a._events[d],g]:a._events[d].push(g):(a._events[d]=g,a._eventsCount++),a}function i(a,u){--a._eventsCount===0?a._events=new n:delete a._events[u]}function c(){this._events=new n,this._eventsCount=0}c.prototype.eventNames=function(){var u=[],l,h;if(this._eventsCount===0)return u;for(h in l=this._events)e.call(l,h)&&u.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(l)):u},c.prototype.listeners=function(u){var l=t?t+u:u,h=this._events[l];if(!h)return[];if(h.fn)return[h.fn];for(var m=0,g=h.length,d=new Array(g);m<g;m++)d[m]=h[m].fn;return d},c.prototype.listenerCount=function(u){var l=t?t+u:u,h=this._events[l];return h?h.fn?1:h.length:0},c.prototype.emit=function(u,l,h,m,g,d){var w=t?t+u:u;if(!this._events[w])return!1;var f=this._events[w],y=arguments.length,v,p;if(f.fn){switch(f.once&&this.removeListener(u,f.fn,void 0,!0),y){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,l),!0;case 3:return f.fn.call(f.context,l,h),!0;case 4:return f.fn.call(f.context,l,h,m),!0;case 5:return f.fn.call(f.context,l,h,m,g),!0;case 6:return f.fn.call(f.context,l,h,m,g,d),!0}for(p=1,v=new Array(y-1);p<y;p++)v[p-1]=arguments[p];f.fn.apply(f.context,v)}else{var k=f.length,_;for(p=0;p<k;p++)switch(f[p].once&&this.removeListener(u,f[p].fn,void 0,!0),y){case 1:f[p].fn.call(f[p].context);break;case 2:f[p].fn.call(f[p].context,l);break;case 3:f[p].fn.call(f[p].context,l,h);break;case 4:f[p].fn.call(f[p].context,l,h,m);break;default:if(!v)for(_=1,v=new Array(y-1);_<y;_++)v[_-1]=arguments[_];f[p].fn.apply(f[p].context,v)}}return!0},c.prototype.on=function(u,l,h){return o(this,u,l,h,!1)},c.prototype.once=function(u,l,h){return o(this,u,l,h,!0)},c.prototype.removeListener=function(u,l,h,m){var g=t?t+u:u;if(!this._events[g])return this;if(!l)return i(this,g),this;var d=this._events[g];if(d.fn)d.fn===l&&(!m||d.once)&&(!h||d.context===h)&&i(this,g);else{for(var w=0,f=[],y=d.length;w<y;w++)(d[w].fn!==l||m&&!d[w].once||h&&d[w].context!==h)&&f.push(d[w]);f.length?this._events[g]=f.length===1?f[0]:f:i(this,g)}return this},c.prototype.removeAllListeners=function(u){var l;return u?(l=t?t+u:u,this._events[l]&&i(this,l)):(this._events=new n,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=t,c.EventEmitter=c,r.exports=c})(Ye)),Ye.exports}var Sr=Lr(),_r=xr(Sr),en=r=>{const e=r.timeout||3e5,t=r.interval||1e3,n=r?.checkSuccess||(()=>!0),s=r.signal;return new Promise(async(o,i)=>{let c,a=setTimeout(()=>{clearTimeout(c),o({code:500,message:"timeout"})},e);const u=r.fn||(()=>!0),l=async()=>{if(s?.aborted)return clearInterval(c),clearTimeout(a),o({code:499,message:"operation cancelled"});const h=await u();n(h)?(clearInterval(c),clearTimeout(a),o({code:200,data:h})):setTimeout(()=>{l()},t)};s&&s.addEventListener("abort",()=>{clearInterval(c),clearTimeout(a),o({code:499,message:"operation cancelled"})}),l()})};class kn{modules=new Map;event;loading;static reRunFn=en;timeout=300*1e3;constructor(){this.event=new _r,this.loading=!1}listenKey(e,t){const n=t?.timeout??this.timeout;return new Promise(s=>{const o=setTimeout(()=>{this.event.removeListener(e,i),s({code:500,message:"timeout"})},n),i=c=>{if(clearTimeout(o),c)return s({code:500,message:c});const a=this.modules.get(e);a?.loadSuccessClear&&this.remove(e),s({code:200,data:a?.modules})};this.event.once(e,i)})}async hasLoaded(e,t){if(!e)return{code:404,message:"key is required"};if(!this.modules.has(e)){const o=t?.isExist??!0,i=t?.timeout??this.timeout;return o?await this.listenKey(e,{timeout:i}):{code:404}}const s=this.modules.get(e);return s?.status==="loaded"?{code:200,data:s.modules}:s?.status==="loading"?await this.listenKey(e,{timeout:t?.timeout??this.timeout}):s?.status==="error"?{code:500,message:"load error"}:s?.status==="cancel"?{code:499,message:"operation cancelled"}:{code:404}}async loadFn(e,t){const n=t.key;if(!n)return{code:404,message:"key is required"};const s={key:t.key,status:"loading",loading:!0,loadSuccessClear:t.loadSuccessClear??!0};let o="";try{const i=t.isReRun??!1;let c;if(!i)this.modules.set(n,s),c=await e();else{s.controller=new AbortController;const a=s.controller.signal;this.modules.set(n,s);const u=await en({timeout:t.timeout,interval:t.interval,checkSuccess:t.checkSuccess,fn:e,signal:a});if(s.controller=null,u.code===499)return s.status="cancel",{code:499,message:"operation cancelled"};if(u.code!==200)throw new Error(u.message);c=u.data}return s.modules=c,s.status="loaded",{code:200,data:c}}catch(i){return o=i.message,s.status="error",{code:500,message:i}}finally{s.loading=!1,this.modules.set(t.key,s),o?this.event.emit(t.key,o):this.event.emit(t.key)}}async load(e,t){this.loading=!0;const n=t.key;if(!n)return{code:404,message:"key is required"};if(t?.force&&this.remove(n),this.modules.has(n))return await this.hasLoaded(n);if(typeof e=="function")return this.loadFn(e,t);console.error("loadContent is not a function and not has loaded")}remove(e){this.modules.has(e)&&(this.checkRemoveController(e),this.modules.delete(e))}emitLoaded(e){this.checkRemoveController(e),this.event.emit(e)}setModule(e,t,n){const s={key:e,status:"loaded",loading:!1,modules:t||{},...n};return this.modules.set(e,s),this.emitLoaded(e),s}cancel(e){this.checkRemoveController(e)}checkRemoveController(e){const t=this.modules.get(e);t?.controller&&(t.controller?.abort?.(),delete t.controller,this.modules.set(e,t))}}var j=globalThis||window||self,bn=(r,e="config",t)=>{const n=j[e],s=n||r;return n||(s?j[e]=s:j[e]={}),j[e]},me=(r,e,t="config",n={})=>{const s=bn({},t);if(r&&typeof s[r]<"u")return s[r];if(r&&e){if(typeof e!="function"&&(s[r]=e),typeof e=="function"){const o=e();if(o instanceof Promise)return o.then(i=>(s[r]=i,i));s[r]=o}return s[r]}if(r){const o=new kn,i=async()=>s[r],c=n.timeout||300*1e3;return(async()=>(await o.load(i,{key:r,isReRun:!0,checkSuccess:()=>s[r],timeout:c,interval:1e3})).code!==200?(console.error("load key error"),null):s[r])()}return console.error("key is empty "),null},Tn=(r,e="config",t)=>{const n=bn({},e),s=t?.timeout;if(r&&delete n[r],t?.getNew&&t.init)return me(r,t.init,e,{timeout:s});if(t?.getNew)return me(r,null,e,{timeout:s})},pe=(r,e,t)=>t?.isNew?Tn(r,"context",{getNew:!0,init:e,...t}):me(r,e,"context",t),tn=pe,nn=(r,e,t)=>t?.isNew?Tn(r,"config",{getNew:!0,init:e,...t}):me(r,e,"config",t);class we{static isInit=!1;static init(e){if(we.isInit)return;const{load:t=!0,page:n=!1}=e||{};we.isInit=!0,j.useConfigKey=nn,j.useContextKey=pe,j.use=tn,j.webEnv={useConfigKey:nn,useContextKey:pe,use:tn},t&&(j.Load=kn)}}we.init();const Rr=(r=6)=>"id-"+Math.random().toString(36).slice(2,r+2),Cn=pe("login-emitter",hn),En="wxff97d569b1db16b6",Ir='<svg t="1764510467010" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1958" width="32" height="32"><path d="M615.904 388.48c8.8 0 17.536 0.64 26.176 1.6-23.52-109.536-140.608-190.912-274.272-190.912C218.4 199.2 96 301.056 96 430.4c0 74.656 40.736 135.936 108.768 183.488l-27.2 81.792 95.04-47.648c33.984 6.72 61.28 13.632 95.2 13.632 8.544 0 16.992-0.416 25.376-1.088a202.496 202.496 0 0 1-8.384-56.96c0-118.752 101.984-215.136 231.104-215.136zM469.76 314.784c20.48 0 34.016 13.472 34.016 33.92 0 20.352-13.536 34.016-34.016 34.016-20.384 0-40.832-13.664-40.832-34.016 0-20.448 20.448-33.92 40.832-33.92zM279.52 382.72c-20.384 0-40.928-13.664-40.928-34.016 0-20.448 20.544-33.92 40.928-33.92 20.352 0 33.92 13.472 33.92 33.92 0 20.384-13.568 34.016-33.92 34.016z" fill="" p-id="1959"></path><path d="M864 600.352c0-108.672-108.736-197.28-230.88-197.28-129.344 0-231.2 88.576-231.2 197.28 0 108.864 101.856 197.248 231.2 197.248 27.072 0 54.368-6.816 81.568-13.632l74.56 40.8-20.448-67.904C823.328 715.936 864 661.664 864 600.352z m-305.856-34.016c-13.536 0-27.2-13.44-27.2-27.2 0-13.568 13.664-27.2 27.2-27.2 20.576 0 34.016 13.632 34.016 27.2 0 13.76-13.44 27.2-34.016 27.2z m149.536 0c-13.44 0-27.008-13.44-27.008-27.2 0-13.568 13.568-27.2 27.008-27.2 20.352 0 34.016 13.632 34.016 27.2 0 13.76-13.664 27.2-34.016 27.2z" fill="" p-id="1960"></path></svg>',Dr='<svg t="1764511395617" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3882" width="32" height="32"><path d="M256 259.584c-29.184 0-51.2 14.848-51.2 44.032s29.184 44.032 51.2 44.032c29.184 0 44.032-14.848 44.032-44.032s-22.016-44.032-44.032-44.032zM541.184 303.616c0-29.184-14.848-44.032-44.032-44.032-29.184 0-51.2 14.848-51.2 44.032s29.184 44.032 51.2 44.032c29.696 0 44.032-22.016 44.032-44.032zM614.4 508.416c-14.848 0-36.352 14.848-36.352 36.352 0 14.848 14.848 36.352 36.352 36.352 29.184 0 44.032-14.848 44.032-36.352 0-14.336-14.848-36.352-44.032-36.352z" p-id="3883"></path><path d="M1024 625.152c0-138.752-124.416-256-285.184-270.848-29.184-153.6-189.952-263.168-373.248-263.168C160.768 91.648 0 230.4 0 406.016c0 95.232 44.032 175.616 138.752 241.152L109.568 742.4c0 7.168 0 14.848 7.168 22.016h14.848l117.248-58.368h14.848c36.352 7.168 66.048 14.848 109.568 14.848 14.848 0 44.032-7.168 44.032-7.168C460.8 822.784 578.048 896 716.8 896c36.352 0 73.216-7.168 102.4-14.848l87.552 51.2h14.848c7.168-7.168 7.168-7.168 7.168-14.848l-22.016-87.552c80.896-58.368 117.248-131.584 117.248-204.8z m-621.568 51.2h-36.352c-36.352 0-66.048-7.168-95.232-14.848l-22.016-7.168h-7.168L153.6 698.368l22.016-66.048c0-7.168 0-14.848-7.168-14.848C80.384 559.616 36.352 486.4 36.352 398.848 36.352 245.248 182.784 128 358.4 128c160.768 0 300.032 95.232 329.216 226.816-168.448 0-300.032 117.248-300.032 263.168 7.168 22.016 14.848 44.032 14.848 58.368z m467.968 132.096c-7.168 7.168-7.168 7.168-7.168 14.848l14.848 51.2L819.2 844.8h-14.848c-29.184 7.168-66.048 14.848-95.232 14.848-146.432 0-270.848-102.4-270.848-226.816 0-131.584 124.416-233.984 270.848-233.984s270.848 102.4 270.848 226.816c0 65.536-36.352 123.904-109.568 182.784z" p-id="3884"></path><path d="M804.352 508.416c-14.848 0-36.352 14.848-36.352 36.352 0 14.848 14.848 36.352 36.352 36.352 29.184 0 44.032-14.848 44.032-36.352 0-14.336-14.336-36.352-44.032-36.352z" p-id="3885"></path></svg>',Mr='<svg t="1764511425462" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5097" width="32" height="32"><path d="M820.409449 797.228346q0 25.19685-10.07874 46.866142t-27.716535 38.299213-41.322835 26.204724-50.897638 9.574803l-357.795276 0q-27.212598 0-50.897638-9.574803t-41.322835-26.204724-27.716535-38.299213-10.07874-46.866142l0-675.275591q0-25.19685 10.07874-47.370079t27.716535-38.80315 41.322835-26.204724 50.897638-9.574803l357.795276 0q27.212598 0 50.897638 9.574803t41.322835 26.204724 27.716535 38.80315 10.07874 47.370079l0 675.275591zM738.771654 170.330709l-455.559055 0 0 577.511811 455.559055 0 0-577.511811zM510.992126 776.062992q-21.165354 0-36.787402 15.11811t-15.622047 37.291339q0 21.165354 15.622047 36.787402t36.787402 15.622047q22.173228 0 37.291339-15.622047t15.11811-36.787402q0-22.173228-15.11811-37.291339t-37.291339-15.11811zM591.622047 84.661417q0-8.062992-5.03937-12.598425t-11.086614-4.535433l-128 0q-5.03937 0-10.582677 4.535433t-5.543307 12.598425 5.03937 12.598425 11.086614 4.535433l128 0q6.047244 0 11.086614-4.535433t5.03937-12.598425z" p-id="5098"></path></svg>',Ur='<svg t="1764511500570" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10511" width="32" height="32"><path d="M768.9216 422.72768 372.06016 422.72768C378.88 365.21984 329.37984 131.42016 512.2048 125.72672c173.83424-6.59456 146.78016 213.34016 146.78016 213.34016l85.13536 0.57344c0 0 24.73984-294.4-231.91552-295.8336C232.09984 58.01984 297.82016 377.18016 289.28 422.72768c1.98656 0 4.56704 0 7.29088 0-55.88992 0-101.21216 45.34272-101.21216 101.21216l0 337.38752c0 55.88992 45.34272 101.21216 101.21216 101.21216l472.35072 0c55.88992 0 101.21216-45.34272 101.21216-101.21216L870.13376 523.93984C870.13376 468.0704 824.79104 422.72768 768.9216 422.72768zM566.4768 717.02528l0 76.84096c0 18.57536-15.1552 33.73056-33.73056 33.73056-18.57536 0-33.73056-15.1552-33.73056-33.73056l0-76.84096c-20.09088-11.69408-33.73056-33.21856-33.73056-58.12224 0-37.2736 30.208-67.4816 67.4816-67.4816 37.2736 0 67.4816 30.208 67.4816 67.4816C600.22784 683.80672 586.58816 705.3312 566.4768 717.02528z" fill="#272636" p-id="10512"></path></svg>',qr='<svg t="1764511538113" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="11994" width="32" height="32"><path d="M512 85.333333C264.533333 85.333333 64 285.866667 64 533.333333s200.533333 448 448 448 448-200.533333 448-448S759.466667 85.333333 512 85.333333z m0 810.666667c-200.533333 0-362.666667-162.133333-362.666667-362.666667S311.466667 170.666667 512 170.666667s362.666667 162.133333 362.666667 362.666667-162.133333 362.666667-362.666667 362.666667z" p-id="11995"></path><path d="M512 298.666667c-119.466667 0-216.533333 97.066667-216.533333 216.533333s97.066667 216.533333 216.533333 216.533333 216.533333-97.066667 216.533333-216.533333-97.066667-216.533333-216.533333-216.533333z m0 362.666666c-80.853333 0-146.133333-65.28-146.133333-146.133333s65.28-146.133333 146.133333-146.133333 146.133333 65.28 146.133333 146.133333-65.28 146.133333-146.133333 146.133333z" p-id="11996"></path></svg>',Xe={pwd:Ur,web:qr,phone:Mr,wxmpSvg:Ir,wxOpenSvg:Dr},An=[{id:"wechat",name:"微信登录",icon:"wxmpSvg",appid:"wx9378885c8390e09b"},{id:"password",name:"密码登录",icon:"pwd"},{id:"web",name:"网页登录",icon:"web"},{id:"wechat-mp",name:"微信公众号",icon:"wxOpenSvg",appid:En},{id:"wechat-mp-ticket",name:"微信公众号",icon:"wxOpenSvg"},{id:"phone",name:"手机号登录",icon:"phone"}],Pr=()=>{let r=window.location.host,e=[];const t=r.includes("cnb.run");switch((r.includes("localhost")||r.endsWith("51515"))&&(r="localhost"),t&&(r="cnb.run"),r){case"kevisual.xiongxiao.me":e=["password","wechat-mp"];break;case"kevisual.cn":e=["password","wechat-mp-ticket","wechat"];break;case"localhost":e=["password","web"];break;case"cnb.run":e=["password","web"];break;default:e=["password","web","phone","wechat","wechat-mp","wechat-mp-ticket"];break}return An.filter(s=>e.includes(s.id))},Br=r=>An.find(e=>e.id===r);class Nr extends HTMLElement{constructor(){super(),this.selectedMethod="password",this.loginMethods=[],this.#e=null}setLoginMethods(e){this.loginMethods=e,this.render()}connectedCallback(){this.attachShadow({mode:"open"}),this.bindEvents(),Ks();const e=this.getAttribute("method");let t=this.id;t||(t=Rr(6),this.id=t);let n=!1;if(e){const s=e?e.split(","):[];if(s.length>0){let o=[];for(const i of s){const c=Br(i);c?.id&&o.push(c)}o.length>0&&(n=!0,this.loginMethods=o,this.selectedMethod=o[0].id)}}n||(this.loginMethods=Pr(),this.selectedMethod=this.loginMethods[0].id),this.render()}#e;selectLoginMethod(e){this.selectedMethod=e,this.render(),this.#e&&(this.#e(),this.#e=null)}getMethodData(e){return this.loginMethods.find(t=>t.id===e)}bindEvents(){this.shadowRoot&&(this.shadowRoot.addEventListener("click",e=>{const n=e.target.closest(".login-method");if(n){const s=n.getAttribute("data-method");s&&this.selectLoginMethod(s)}}),this.shadowRoot.addEventListener("submit",e=>{const t=e.target;t&&t.id==="loginForm"&&(e.preventDefault(),this.handleLogin())}),Cn.on("login-success",()=>{console.log("收到登录成功事件,处理后续逻辑")}))}handleLogin(){const e=this.getFormData();zs({loginMethod:this.selectedMethod,data:e}),this.dispatchEvent(new CustomEvent("login",{detail:{method:this.selectedMethod,data:e},bubbles:!0}))}getFormData(){if(!this.shadowRoot)return{};switch(this.selectedMethod){case"password":const e=this.shadowRoot.querySelector("#username"),t=this.shadowRoot.querySelector("#password");return{username:e?.value||"",password:t?.value||""};case"web":return{};case"phone":const n=this.shadowRoot.querySelector("#phone"),s=this.shadowRoot.querySelector("#code");return{phone:n?.value||"",code:s?.value||""};case"wechat":return{wechatCode:"mock_wechat_code"};case"wechat-mp":return{wechatMpCode:"mock_wechat_mp_code"};default:return{}}}renderPasswordForm(){return D`
|
|
166
|
+
<form id="loginForm" class="login-form">
|
|
167
|
+
<div class="form-group">
|
|
168
|
+
<input
|
|
169
|
+
type="text"
|
|
170
|
+
id="username"
|
|
171
|
+
name="username"
|
|
172
|
+
placeholder="请输入用户名"
|
|
173
|
+
autocomplete="username"
|
|
174
|
+
required
|
|
175
|
+
/>
|
|
176
|
+
</div>
|
|
177
|
+
<div class="form-group">
|
|
178
|
+
<input
|
|
179
|
+
type="password"
|
|
180
|
+
id="password"
|
|
181
|
+
name="password"
|
|
182
|
+
placeholder="请输入密码"
|
|
183
|
+
autocomplete="current-password"
|
|
184
|
+
required
|
|
185
|
+
/>
|
|
186
|
+
</div>
|
|
187
|
+
<button type="submit" class="login-button">登录</button>
|
|
188
|
+
</form>
|
|
189
|
+
`}renderWebForm(){return D`
|
|
190
|
+
<div class="web-login">
|
|
191
|
+
<button type="button" class="refresh-button" @click=${this.handleLogin.bind(this)}>点击登录</button>
|
|
192
|
+
<slot></slot>
|
|
193
|
+
</div>
|
|
194
|
+
`}renderPhoneForm(){return D`
|
|
195
|
+
<form id="loginForm" class="login-form">
|
|
196
|
+
<div class="form-group">
|
|
197
|
+
<input
|
|
198
|
+
type="tel"
|
|
199
|
+
id="phone"
|
|
200
|
+
name="phone"
|
|
201
|
+
placeholder="请输入手机号"
|
|
202
|
+
pattern="[0-9]{11}"
|
|
203
|
+
autocomplete="tel"
|
|
204
|
+
required
|
|
205
|
+
/>
|
|
206
|
+
</div>
|
|
207
|
+
<div class="form-group code-group">
|
|
208
|
+
<input
|
|
209
|
+
type="text"
|
|
210
|
+
id="code"
|
|
211
|
+
name="code"
|
|
212
|
+
placeholder="请输入验证码"
|
|
213
|
+
autocomplete="one-time-code"
|
|
214
|
+
required
|
|
215
|
+
/>
|
|
216
|
+
<button type="button" class="code-button" @click=${this.sendVerificationCode}>获取验证码</button>
|
|
217
|
+
</div>
|
|
218
|
+
<button type="submit" class="login-button">登录</button>
|
|
219
|
+
</form>
|
|
220
|
+
`}renderWechatForm(){let e=document.querySelector("#weixinLogin");if(!e){e=document.createElement("div"),e.id="weixinLogin";const t=this.id;document.querySelector(`#${t}`).appendChild(e)}return D`
|
|
221
|
+
<div class="wechat-login">
|
|
222
|
+
<slot></slot>
|
|
223
|
+
</div>
|
|
224
|
+
`}renderWechatMpForm(){const e=this;return setTimeout(()=>{const t=e.shadowRoot.querySelector("#qrcode"),{clear:n}=Ar(t);e.#e=n},0),D`
|
|
225
|
+
<div class="wechat-login">
|
|
226
|
+
<div class="qr-container">
|
|
227
|
+
<div class="qr-placeholder">
|
|
228
|
+
<canvas id='qrcode' width='300' height='300'></canvas>
|
|
229
|
+
<p class="qr-desc">请使用微信扫描二维码登录</p>
|
|
230
|
+
</div>
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
`}renderWechatMpTicketForm(){const e=this;return setTimeout(async()=>{const t=await Xs();if(!t)return;const n=e.shadowRoot.querySelector(".qrcode");if(t.url){n.src=t.url;const s=Zs(t.ticket);e.#e=s}},0),D`
|
|
234
|
+
<div class="wechat-login">
|
|
235
|
+
<div class="qr-container">
|
|
236
|
+
<div class="qr-placeholder">
|
|
237
|
+
<img class="qrcode" width="300" height="300" data-appid="" data-size="200" data-ticket=""></img>
|
|
238
|
+
<p class="qr-desc">请使用微信扫描二维码登录</p>
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
`}sendVerificationCode(){console.log("发送验证码")}refreshQR(){console.log("刷新二维码")}renderLoginForm(){const e=this.getMethodData(this.selectedMethod);switch(this.selectedMethod){case"password":return this.renderPasswordForm();case"web":return this.renderWebForm();case"phone":return this.renderPhoneForm();case"wechat":return er({appid:e?.appid||""}),this.renderWechatForm();case"wechat-mp":return this.renderWechatMpForm();case"wechat-mp-ticket":return this.renderWechatMpTicketForm();default:return this.renderPasswordForm()}}render(){if(!this.shadowRoot)return;const e=n=>typeof n=="string"&&!Xe[n]?D`<span class="method-icon-emoji">${n}</span>`:typeof n=="string"&&Xe[n]?D`<span class="method-icon-svg">${wt(Xe[n])}</span>`:typeof n=="string"&&(n.includes("<svg")||n.includes("<?xml"))?D`<span class="method-icon-svg">${wt(n)}</span>`:D`<span class="method-icon-emoji">${n}</span>`,t=D`
|
|
243
|
+
<style>
|
|
244
|
+
:host {
|
|
245
|
+
display: block;
|
|
246
|
+
width: 100%;
|
|
247
|
+
min-width: 400px;
|
|
248
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.login-sidebar {
|
|
252
|
+
background: white;
|
|
253
|
+
border-radius: 12px;
|
|
254
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
|
255
|
+
overflow: hidden;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.login-methods {
|
|
259
|
+
display: flex;
|
|
260
|
+
background: #f5f5f5;
|
|
261
|
+
border-bottom: 1px solid #000000;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.login-method {
|
|
265
|
+
flex: 1;
|
|
266
|
+
padding: 16px 8px;
|
|
267
|
+
border: none;
|
|
268
|
+
background: none;
|
|
269
|
+
cursor: pointer;
|
|
270
|
+
display: flex;
|
|
271
|
+
flex-direction: column;
|
|
272
|
+
align-items: center;
|
|
273
|
+
gap: 4px;
|
|
274
|
+
transition: all 0.3s ease;
|
|
275
|
+
position: relative;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.login-method:hover {
|
|
279
|
+
background: #d0d0d0;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.login-method.active {
|
|
283
|
+
background: white;
|
|
284
|
+
color: #000000;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.login-method.active::after {
|
|
288
|
+
content: '';
|
|
289
|
+
position: absolute;
|
|
290
|
+
bottom: 0;
|
|
291
|
+
left: 0;
|
|
292
|
+
right: 0;
|
|
293
|
+
height: 2px;
|
|
294
|
+
background: #000000;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.method-icon {
|
|
298
|
+
font-size: 20px;
|
|
299
|
+
display: flex;
|
|
300
|
+
align-items: center;
|
|
301
|
+
justify-content: center;
|
|
302
|
+
width: 24px;
|
|
303
|
+
height: 24px;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.method-icon-emoji {
|
|
307
|
+
font-size: 20px;
|
|
308
|
+
line-height: 1;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
.method-icon-svg {
|
|
312
|
+
display: flex;
|
|
313
|
+
align-items: center;
|
|
314
|
+
justify-content: center;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.method-icon-svg svg {
|
|
318
|
+
width: 32px;
|
|
319
|
+
height: 32px;
|
|
320
|
+
display: block;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.method-name {
|
|
324
|
+
font-size: 12px;
|
|
325
|
+
font-weight: 500;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.login-content {
|
|
329
|
+
padding: 32px 24px;
|
|
330
|
+
}
|
|
331
|
+
.impowerBox .qrcode {
|
|
332
|
+
width: 200px !important;
|
|
333
|
+
}
|
|
334
|
+
.login-form {
|
|
335
|
+
display: flex;
|
|
336
|
+
flex-direction: column;
|
|
337
|
+
gap: 16px;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.form-group {
|
|
341
|
+
position: relative;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.form-group input {
|
|
345
|
+
width: 100%;
|
|
346
|
+
padding: 12px 16px;
|
|
347
|
+
border: 2px solid #cccccc;
|
|
348
|
+
border-radius: 8px;
|
|
349
|
+
font-size: 14px;
|
|
350
|
+
transition: border-color 0.3s ease;
|
|
351
|
+
box-sizing: border-box;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.form-group input:focus {
|
|
355
|
+
outline: none;
|
|
356
|
+
border-color: #000000;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.code-group {
|
|
360
|
+
display: flex;
|
|
361
|
+
gap: 12px;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.code-group input {
|
|
365
|
+
flex: 1;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.code-button {
|
|
369
|
+
padding: 0 16px;
|
|
370
|
+
background: #6c757d;
|
|
371
|
+
color: white;
|
|
372
|
+
border: none;
|
|
373
|
+
border-radius: 8px;
|
|
374
|
+
font-size: 14px;
|
|
375
|
+
cursor: pointer;
|
|
376
|
+
white-space: nowrap;
|
|
377
|
+
transition: background-color 0.3s ease;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.code-button:hover {
|
|
381
|
+
background: #5a6268;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.login-button {
|
|
385
|
+
padding: 12px;
|
|
386
|
+
background: #000000;
|
|
387
|
+
color: white;
|
|
388
|
+
border: none;
|
|
389
|
+
border-radius: 8px;
|
|
390
|
+
font-size: 16px;
|
|
391
|
+
font-weight: 500;
|
|
392
|
+
cursor: pointer;
|
|
393
|
+
transition: background-color 0.3s ease;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.login-button:hover {
|
|
397
|
+
background: #333333;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
.wechat-login {
|
|
401
|
+
display: flex;
|
|
402
|
+
flex-direction: column;
|
|
403
|
+
align-items: center;
|
|
404
|
+
gap: 20px;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
.qr-container {
|
|
408
|
+
width: 340px;
|
|
409
|
+
height: 340px;
|
|
410
|
+
border: 2px solid #000000;
|
|
411
|
+
border-radius: 8px;
|
|
412
|
+
display: flex;
|
|
413
|
+
align-items: center;
|
|
414
|
+
justify-content: center;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.qr-placeholder {
|
|
418
|
+
text-align: center;
|
|
419
|
+
color: #333333;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
.qr-icon {
|
|
423
|
+
font-size: 48px;
|
|
424
|
+
margin-bottom: 8px;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.qr-desc {
|
|
428
|
+
font-size: 12px;
|
|
429
|
+
margin-top: 4px;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
.refresh-button {
|
|
433
|
+
padding: 8px 16px;
|
|
434
|
+
background: #6c757d;
|
|
435
|
+
color: white;
|
|
436
|
+
border: none;
|
|
437
|
+
border-radius: 6px;
|
|
438
|
+
font-size: 14px;
|
|
439
|
+
cursor: pointer;
|
|
440
|
+
transition: background-color 0.3s ease;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.refresh-button:hover {
|
|
444
|
+
background: #5a6268;
|
|
445
|
+
}
|
|
446
|
+
.method-icon svg {
|
|
447
|
+
width: 24px;
|
|
448
|
+
height: 24px;
|
|
449
|
+
}
|
|
450
|
+
</style>
|
|
451
|
+
|
|
452
|
+
<div class="login-sidebar">
|
|
453
|
+
<div class="login-methods">
|
|
454
|
+
${this.loginMethods.map(n=>D`
|
|
455
|
+
<button
|
|
456
|
+
class="login-method ${this.selectedMethod===n.id?"active":""}"
|
|
457
|
+
data-method="${n.id}"
|
|
458
|
+
>
|
|
459
|
+
${e(n.icon)}
|
|
460
|
+
<span class="method-name">${n.name}</span>
|
|
461
|
+
</button>
|
|
462
|
+
`)}
|
|
463
|
+
</div>
|
|
464
|
+
|
|
465
|
+
<div class="login-content">
|
|
466
|
+
${this.renderLoginForm()}
|
|
467
|
+
</div>
|
|
468
|
+
</div>
|
|
469
|
+
`;cn(t,this.shadowRoot)}}customElements.define("kv-login",Nr);Cn.once("login-success",async r=>{const e=await Gs();if(e.code===400)if(e.data.redirectUrl)window.open(e.data.redirectUrl,"_self");else{const t=await rt.getMe();console.log("用户信息:",t),window.open("/root/home/","_self")}else fn()});const $r=async()=>{const r=await rt.getToken();console.log("获取token:",r)};setTimeout(()=>{$r()},2e3);
|