@kevisual/kv-login 0.0.4 → 0.0.5

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.
@@ -1,6 +1,6 @@
1
- (function(K){typeof define=="function"&&define.amd?define(K):K()})((function(){"use strict";const K=globalThis,ce=K.trustedTypes,Je=ce?ce.createPolicy("lit-html",{createHTML:t=>t}):void 0,Ke="$lit$",F=`lit$${Math.random().toFixed(9).slice(2)}$`,Qe="?"+F,en=`<${Qe}>`,j=document,ee=()=>j.createComment(""),te=t=>t===null||typeof t!="object"&&typeof t!="function",de=Array.isArray,tn=t=>de(t)||typeof t?.[Symbol.iterator]=="function",fe=`[
2
- \f\r]`,ne=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Ge=/-->/g,Ye=/>/g,V=RegExp(`>|${fe}(?:([^\\s"'>=/]+)(${fe}*=${fe}*(?:[^
3
- \f\r"'\`<>=]|("|')|))|$)`,"g"),Xe=/'/g,Ze=/"/g,et=/^(?:script|style|textarea|title)$/i,nn=t=>(e,...r)=>({_$litType$:t,strings:e,values:r}),L=nn(1),Q=Symbol.for("lit-noChange"),M=Symbol.for("lit-nothing"),tt=new WeakMap,W=j.createTreeWalker(j,129);function nt(t,e){if(!de(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return Je!==void 0?Je.createHTML(e):e}const rn=(t,e)=>{const r=t.length-1,n=[];let o,s=e===2?"<svg>":e===3?"<math>":"",i=ne;for(let c=0;c<r;c++){const a=t[c];let l,u,h=-1,f=0;for(;f<a.length&&(i.lastIndex=f,u=i.exec(a),u!==null);)f=i.lastIndex,i===ne?u[1]==="!--"?i=Ge:u[1]!==void 0?i=Ye:u[2]!==void 0?(et.test(u[2])&&(o=RegExp("</"+u[2],"g")),i=V):u[3]!==void 0&&(i=V):i===V?u[0]===">"?(i=o??ne,h=-1):u[1]===void 0?h=-2:(h=i.lastIndex-u[2].length,l=u[1],i=u[3]===void 0?V:u[3]==='"'?Ze:Xe):i===Ze||i===Xe?i=V:i===Ge||i===Ye?i=ne:(i=V,o=void 0);const d=i===V&&t[c+1].startsWith("/>")?" ":"";s+=i===ne?a+en:h>=0?(n.push(l),a.slice(0,h)+Ke+a.slice(h)+F+d):a+F+(h===-2?c:d)}return[nt(t,s+(t[r]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),n]};class re{constructor({strings:e,_$litType$:r},n){let o;this.parts=[];let s=0,i=0;const c=e.length-1,a=this.parts,[l,u]=rn(e,r);if(this.el=re.createElement(l,n),W.currentNode=this.el.content,r===2||r===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(o=W.nextNode())!==null&&a.length<c;){if(o.nodeType===1){if(o.hasAttributes())for(const h of o.getAttributeNames())if(h.endsWith(Ke)){const f=u[i++],d=o.getAttribute(h).split(F),w=/([.?@])?(.*)/.exec(f);a.push({type:1,index:s,name:w[2],strings:d,ctor:w[1]==="."?sn:w[1]==="?"?an:w[1]==="@"?cn:le}),o.removeAttribute(h)}else h.startsWith(F)&&(a.push({type:6,index:s}),o.removeAttribute(h));if(et.test(o.tagName)){const h=o.textContent.split(F),f=h.length-1;if(f>0){o.textContent=ce?ce.emptyScript:"";for(let d=0;d<f;d++)o.append(h[d],ee()),W.nextNode(),a.push({type:2,index:++s});o.append(h[f],ee())}}}else if(o.nodeType===8)if(o.data===Qe)a.push({type:2,index:s});else{let h=-1;for(;(h=o.data.indexOf(F,h+1))!==-1;)a.push({type:7,index:s}),h+=F.length-1}s++}}static createElement(e,r){const n=j.createElement("template");return n.innerHTML=e,n}}function G(t,e,r=t,n){if(e===Q)return e;let o=n!==void 0?r._$Co?.[n]:r._$Cl;const s=te(e)?void 0:e._$litDirective$;return o?.constructor!==s&&(o?._$AO?.(!1),s===void 0?o=void 0:(o=new s(t),o._$AT(t,r,n)),n!==void 0?(r._$Co??=[])[n]=o:r._$Cl=o),o!==void 0&&(e=G(t,o._$AS(t,e.values),o,n)),e}class on{constructor(e,r){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=r}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:r},parts:n}=this._$AD,o=(e?.creationScope??j).importNode(r,!0);W.currentNode=o;let s=W.nextNode(),i=0,c=0,a=n[0];for(;a!==void 0;){if(i===a.index){let l;a.type===2?l=new oe(s,s.nextSibling,this,e):a.type===1?l=new a.ctor(s,a.name,a.strings,this,e):a.type===6&&(l=new ln(s,this,e)),this._$AV.push(l),a=n[++c]}i!==a?.index&&(s=W.nextNode(),i++)}return W.currentNode=j,o}p(e){let r=0;for(const n of this._$AV)n!==void 0&&(n.strings!==void 0?(n._$AI(e,n,r),r+=n.strings.length-2):n._$AI(e[r])),r++}}class oe{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,r,n,o){this.type=2,this._$AH=M,this._$AN=void 0,this._$AA=e,this._$AB=r,this._$AM=n,this.options=o,this._$Cv=o?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode;const r=this._$AM;return r!==void 0&&e?.nodeType===11&&(e=r.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,r=this){e=G(this,e,r),te(e)?e===M||e==null||e===""?(this._$AH!==M&&this._$AR(),this._$AH=M):e!==this._$AH&&e!==Q&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):tn(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!==M&&te(this._$AH)?this._$AA.nextSibling.data=e:this.T(j.createTextNode(e)),this._$AH=e}$(e){const{values:r,_$litType$:n}=e,o=typeof n=="number"?this._$AC(e):(n.el===void 0&&(n.el=re.createElement(nt(n.h,n.h[0]),this.options)),n);if(this._$AH?._$AD===o)this._$AH.p(r);else{const s=new on(o,this),i=s.u(this.options);s.p(r),this.T(i),this._$AH=s}}_$AC(e){let r=tt.get(e.strings);return r===void 0&&tt.set(e.strings,r=new re(e)),r}k(e){de(this._$AH)||(this._$AH=[],this._$AR());const r=this._$AH;let n,o=0;for(const s of e)o===r.length?r.push(n=new oe(this.O(ee()),this.O(ee()),this,this.options)):n=r[o],n._$AI(s),o++;o<r.length&&(this._$AR(n&&n._$AB.nextSibling,o),r.length=o)}_$AR(e=this._$AA.nextSibling,r){for(this._$AP?.(!1,!0,r);e!==this._$AB;){const n=e.nextSibling;e.remove(),e=n}}setConnected(e){this._$AM===void 0&&(this._$Cv=e,this._$AP?.(e))}}class le{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,r,n,o,s){this.type=1,this._$AH=M,this._$AN=void 0,this.element=e,this.name=r,this._$AM=o,this.options=s,n.length>2||n[0]!==""||n[1]!==""?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=M}_$AI(e,r=this,n,o){const s=this.strings;let i=!1;if(s===void 0)e=G(this,e,r,0),i=!te(e)||e!==this._$AH&&e!==Q,i&&(this._$AH=e);else{const c=e;let a,l;for(e=s[0],a=0;a<s.length-1;a++)l=G(this,c[n+a],r,a),l===Q&&(l=this._$AH[a]),i||=!te(l)||l!==this._$AH[a],l===M?e=M:e!==M&&(e+=(l??"")+s[a+1]),this._$AH[a]=l}i&&!o&&this.j(e)}j(e){e===M?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class sn extends le{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===M?void 0:e}}class an extends le{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==M)}}class cn extends le{constructor(e,r,n,o,s){super(e,r,n,o,s),this.type=5}_$AI(e,r=this){if((e=G(this,e,r,0)??M)===Q)return;const n=this._$AH,o=e===M&&n!==M||e.capture!==n.capture||e.once!==n.once||e.passive!==n.passive,s=e!==M&&(n===M||o);o&&this.element.removeEventListener(this.name,this,n),s&&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 ln{constructor(e,r,n){this.element=e,this.type=6,this._$AN=void 0,this._$AM=r,this.options=n}get _$AU(){return this._$AM._$AU}_$AI(e){G(this,e)}}const un=K.litHtmlPolyfillSupport;un?.(re,oe),(K.litHtmlVersions??=[]).push("3.3.1");const rt=(t,e,r)=>{const n=e;let o=n._$litPart$;return o===void 0&&(n._$litPart$=o=new oe(e.insertBefore(ee(),null),null,void 0,{})),o._$AI(t),o};const hn={CHILD:2},dn=t=>(...e)=>({_$litDirective$:t,values:e});class fn{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,r,n){this._$Ct=e,this._$AM=r,this._$Ci=n}_$AS(e,r){return this.update(e,r)}update(e,r){return this.render(...r)}}class ge extends fn{constructor(e){if(super(e),this.it=M,e.type!==hn.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===M||e==null)return this._t=void 0,this.it=e;if(e===Q)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 r=[e];return r.raw=r,this._t={_$litType$:this.constructor.resultType,strings:r,values:[]}}}ge.directiveName="unsafeHTML",ge.resultType=1;const ot=dn(ge),gn=t=>t?["text/","xml","html","javascript","css","csv","plain","x-www-form-urlencoded"].some(r=>t.includes(r)):!1,st=async(t={},e)=>{const r=new AbortController,n=r.signal,o=t.isBlob||!1,s=t.isText||!1,i=t.isPostFile||!1,c=t.timeout||6e4*3,a=setTimeout(()=>{r.abort()},c);let l=e?.method||t?.method||"POST",u={...t?.headers,...e?.headers},h="",f;t?.url?.startsWith("http")?f=new URL(t.url):(h=window?.location?.origin||"http://localhost:51015",f=new URL(t.url,h));const d=l==="GET";d&&(f.search=new URLSearchParams(t.body).toString());let w;return d?w=void 0:i?w=t.body:(u={"Content-Type":"application/json",...u},w=JSON.stringify(t.body)),fetch(f,{method:l.toUpperCase(),signal:n,body:w,...e,headers:u}).then(async p=>{const B=p.headers.get("Content-Type");return o?await p.blob():B&&B.includes("application/json")&&!s?await p.json():gn(B)?{code:200,status:p.status,data:await p.text()}:p}).catch(p=>(p.name==="AbortError"&&console.log("Request timed out and was aborted"),console.error(p),{code:500})).finally(()=>{clearTimeout(a)})},it=t=>(t.success=t.code===200,t.showError=e=>{!t.success&&!t.noMsg&&e?.()},t),pe=({code:t,message:e})=>({code:t||500,success:!1,message:e||"api request error",showError:n=>{},noMsg:!0});class at{adapter;url;beforeRequest;afterResponse;headers;timeout;stop;qws;constructor(e){this.adapter=e?.adapter||st,this.url=e?.url||"/api/router",this.headers=e?.headers||{"Content-Type":"application/json"},this.timeout=e?.timeout||6e4*3}setQueryWs(e){this.qws=e}setStop(e){this.stop=e}async get(e,r){return this.post(e,r)}async post(e,r){const n=r?.url||this.url,{headers:o,adapter:s,beforeRequest:i,afterResponse:c,timeout:a,...l}=r||{},u={...this.headers,...o},h=s||this.adapter,f=i||this.beforeRequest,d=c||this.afterResponse,w=a||this.timeout,p={url:n,headers:u,body:e,timeout:w,...l};try{if(f&&await f(p)===!1)return pe({code:500,message:"request is cancel",req:p})}catch(B){return console.error("request beforeFn error",B,p),pe({code:500,message:"api request beforeFn error"})}if(this.stop&&!r?.noStop){const B=this;await new Promise(A=>{let R=0;const k=setInterval(()=>{B.stop||(clearInterval(k),A(!0)),R++,R>30&&console.error("request stop: timeout",p.url,R)},1e3)})}return h(p).then(async B=>{try{return it(B),d?await d(B,{req:p,res:B,fetch:s}):B}catch(A){return console.error("request afterFn error",A,p),pe({code:500,message:"api request afterFn error"})}})}before(e){this.beforeRequest=e}after(e){this.afterResponse=e}async fetchText(e,r){let n={...r};typeof e=="string"&&!n.url&&(n.url=e),typeof e=="object"&&(n={...e,...n});const o=await st({method:"GET",...n,headers:{...this.headers,...n?.headers||{}}});return it(o)}}class pn{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,r){return this.query.post(e,r)}get(e,r){return this.query.get(e,r)}}const ct=t=>(t.success=t.code===200,t.showError=e=>{!t.success&&!t.noMsg&&e?.()},t);function $(t){return new Promise((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)})}function lt(t,e){const r=indexedDB.open(t);r.onupgradeneeded=()=>r.result.createObjectStore(e);const n=$(r);return(o,s)=>n.then(i=>s(i.transaction(e,o).objectStore(e)))}let me;function I(){return me||(me=lt("keyval-store","keyval")),me}function ut(t,e=I()){return e("readonly",r=>$(r.get(t)))}function ht(t,e,r=I()){return r("readwrite",n=>(n.put(e,t),$(n.transaction)))}function mn(t,e=I()){return e("readwrite",r=>(t.forEach(n=>r.put(n[1],n[0])),$(r.transaction)))}function wn(t,e=I()){return e("readonly",r=>Promise.all(t.map(n=>$(r.get(n)))))}function yn(t,e,r=I()){return r("readwrite",n=>new Promise((o,s)=>{n.get(t).onsuccess=function(){try{n.put(e(this.result),t),o($(n.transaction))}catch(i){s(i)}}}))}function dt(t,e=I()){return e("readwrite",r=>(r.delete(t),$(r.transaction)))}function bn(t,e=I()){return e("readwrite",r=>(t.forEach(n=>r.delete(n)),$(r.transaction)))}function ft(t=I()){return t("readwrite",e=>(e.clear(),$(e.transaction)))}function we(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},$(t.transaction)}function vn(t=I()){return t("readonly",e=>{if(e.getAllKeys)return $(e.getAllKeys());const r=[];return we(e,n=>r.push(n.key)).then(()=>r)})}function An(t=I()){return t("readonly",e=>{if(e.getAll)return $(e.getAll());const r=[];return we(e,n=>r.push(n.value)).then(()=>r)})}function Cn(t=I()){return t("readonly",e=>{if(e.getAll&&e.getAllKeys)return Promise.all([$(e.getAllKeys()),$(e.getAll())]).then(([n,o])=>n.map((s,i)=>[s,o[i]]));const r=[];return t("readonly",n=>we(n,o=>r.push([o.key,o.value])).then(()=>r))})}var Tn=Object.freeze({__proto__:null,clear:ft,createStore:lt,del:dt,delMany:bn,entries:Cn,get:ut,getMany:wn,keys:vn,promisifyRequest:$,set:ht,setMany:mn,update:yn,values:An});class kn{storage;data=null;constructor(){this.storage=Tn}async get(e){const r=await ut(e);return this.data=r,r}async set(e,r){this.data=r,await ht(e,r)}async del(e){this.data=null,await dt(e)}async clear(){await ft()}}class En extends kn{name;updatedAt;constructor(e){super(),this.name=e||"my-cache"}async getData(){const e=await super.get(this.name);return this.updatedAt=e.updatedAt,e.expireTime&&e.expireTime<Date.now()?(await super.del(this.name),{}):e.data}async setData(e,r){const o=Date.now()+(r?.expireTime||1e3*60*60*24*10),s={data:e,updatedAt:r?.updatedAt||Date.now(),expireTime:o};await super.set(this.name,s),this.updatedAt=s.updatedAt}async del(){await super.del(this.name)}}var _n=class{cache;name;cacheData;constructor(t){if(!t.cache)throw new Error("cache is required");this.cache=t.cache,this.cacheData={loginUsers:[],user:void 0,id:void 0,accessToken:void 0,refreshToken:void 0},this.name=t.name}async setValue(t){return await this.cache.set(this.name,t),this.cacheData=t,t}async delValue(){await this.cache.del()}getValue(){return this.cache.get(this.name)}async init(){const t={loginUsers:[],user:null,id:null,accessToken:null,refreshToken:null};if(this.cache.init)try{const e=await this.cache.init();this.cacheData=e||t}catch(e){console.log("cacheInit error",e)}else this.cacheData=await this.getValue()||t}async setLoginUser(t){this.cacheData.loginUsers.find(r=>r.id===t.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(r=>r?.id&&r.id!==t.id)),this.cacheData.loginUsers.push(t),this.cacheData.user=t.user,this.cacheData.id=t.id,this.cacheData.accessToken=t.accessToken,this.cacheData.refreshToken=t.refreshToken,await this.setValue(this.cacheData)}getCurrentUser(){const t=this.cacheData;return Promise.resolve(t.user)}getCurrentUserList(){return Promise.resolve(this.cacheData.loginUsers.filter(t=>t?.id))}getRefreshToken(){const t=this.cacheData;return Promise.resolve(t.refreshToken||"")}getAccessToken(){const t=this.cacheData;return Promise.resolve(t.accessToken||"")}async clearCurrentUser(){const t=await this.getCurrentUser();this.cacheData.loginUsers.find(r=>r.id===t.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(r=>r?.id&&r.id!==t.id)),this.cacheData.user=void 0,this.cacheData.id=void 0,this.cacheData.accessToken=void 0,this.cacheData.refreshToken=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,await this.setValue(this.cacheData)}},Sn=class extends pn{cacheStore;isBrowser;load;storage;onLoad;constructor(t){super({query:t?.query||new at}),this.cacheStore=new _n({name:"login",cache:t.cache}),this.isBrowser=t?.isBrowser??!0,this.init(),this.onLoad=t?.onLoad,this.storage=t?.storage||localStorage}setQuery(t){this.query=t}async init(){await this.cacheStore.init(),this.load=!0,this.onLoad?.()}async post(t,e){try{return this.query.post({path:"user",...t},e)}catch(r){return console.log("error",r),{code:400}}}async login(t){const e=await this.post({key:"login",...t});if(e.code===200){const{accessToken:r,refreshToken:n}=e?.data||{};this.storage.setItem("token",r||""),await this.beforeSetLoginUser({accessToken:r,refreshToken:n})}return e}async loginByCode(t){const e=await this.post({path:"sms",key:"login",data:t});if(e.code===200){const{accessToken:r,refreshToken:n}=e?.data||{};this.storage.setItem("token",r||""),await this.beforeSetLoginUser({accessToken:r,refreshToken:n})}return e}async setLoginToken(t){const{accessToken:e,refreshToken:r}=t;this.storage.setItem("token",e||""),await this.beforeSetLoginUser({accessToken:e,refreshToken:r})}async loginByWechat(t){const e=await this.post({path:"wx",key:"open-login",code:t.code});if(e.code===200){const{accessToken:r,refreshToken:n}=e?.data||{};this.storage.setItem("token",r||""),await this.beforeSetLoginUser({accessToken:r,refreshToken:n})}return e}async checkWechat({onSuccess:t,onError:e}){const r=new URL(window.location.href),n=r.searchParams.get("code"),o=r.searchParams.get("state");if(n&&o){const s=await this.loginByWechat({code:n});s.code===200?t?.(s.data):e?.(s)}}async beforeSetLoginUser({accessToken:t,refreshToken:e,check401:r}){if(t&&e){const n=await this.getMe(t,r);if(n.code===200){const o=n.data;o?this.cacheStore.setLoginUser({user:o,id:o.id,accessToken:t,refreshToken:e}):console.error("登录失败")}}}async queryRefreshToken(t){const e=t||this.cacheStore.getRefreshToken();let r={refreshToken:e};return e?this.post({key:"refreshToken",data:r},{afterResponse:async(n,o)=>(ct(n),n)}):(await this.cacheStore.clearCurrentUser(),{code:401,message:"请先登录",data:{}})}async afterCheck401ToRefreshToken(t,e,r){const n=this;if(t?.code===401){const o=await n.cacheStore.getRefreshToken();if(o){const s=await n.queryRefreshToken(o);if(s.code===200){const{accessToken:i,refreshToken:c}=s?.data||{};if(n.storage.setItem("token",i||""),await n.beforeSetLoginUser({accessToken:i,refreshToken:c,check401:!1}),r&&e&&e.req&&e.req.url&&e.fetch){await new Promise(f=>setTimeout(f,1500));const a=e.req?.url,l=e.req?.body,u=e.req?.headers,h=await e.fetch(a,{method:"POST",body:l,headers:{...u,Authorization:`Bearer ${i}`}});return ct(h),h}}else n.storage.removeItem("token"),await n.cacheStore.clearCurrentUser();return s}}return t}async run401Action(t,e,r){const n=this,o=r?.refetch??!1;if(t?.code===401){if(n.query.stop===!0)return{code:500,success:!1,message:"refresh token loading..."};n.query.stop=!0;const s=await n.afterCheck401ToRefreshToken(t,e,o);return n.query.stop=!1,r?.afterCheck?.(s),s.code===401&&r?.afterAlso401?.(s),s}else return t}async getMe(t,e=!0){const r=t||this.storage.getItem("token"),n=this;return n.post({key:"me"},{beforeRequest:async o=>(o.headers&&(o.headers.Authorization=`Bearer ${r}`),o),afterResponse:async(o,s)=>o?.code===401&&e&&!t?await n.afterCheck401ToRefreshToken(o,s):o})}async checkLocalUser(){const t=await this.cacheStore.getCurrentUser();return t||null}async checkLocalToken(){return!!this.storage.getItem("token")}async postSwitchUser(t){return this.post({key:"switchCheck",data:{username:t}})}async switchUser(t){const r=(await this.cacheStore.getCurrentUserList()).find(o=>o.user.username===t);if(r)return this.storage.setItem("token",r.accessToken||""),await this.beforeSetLoginUser({accessToken:r.accessToken,refreshToken:r.refreshToken}),{code:200,data:{accessToken:r.accessToken,refreshToken:r.refreshToken},success:!0,message:"切换用户成功"};const n=await this.postSwitchUser(t);if(n.code===200){const{accessToken:o,refreshToken:s}=n?.data||{};this.storage.setItem("token",o||""),await this.beforeSetLoginUser({accessToken:o,refreshToken:s})}return n}async logout(){this.storage.removeItem("token");const e=(await this.cacheStore.getCurrentUserList()).map(r=>r?.accessToken).filter(Boolean);return this.cacheStore.delValue(),this.post({key:"logout",data:{tokens:e}})}async hasUser(t){const e=this;return this.post({path:"org",key:"hasUser",data:{username:t}},{afterResponse:async(r,n)=>r?.code===401?await e.afterCheck401ToRefreshToken(r,n,!0):r})}async checkLoginStatus(t){const e=await this.post({path:"user",key:"checkLoginStatus",loginToken:t});if(e.code===200){const r=e.data?.accessToken;return this.storage.setItem("token",r||""),await this.beforeSetLoginUser({accessToken:r,refreshToken:e.data?.refreshToken}),e}return!1}loginWithWeb(t,{MD5:e,jsonwebtoken:r}){const n=Math.random().toString(36).substring(2,15),o=Date.now(),s="xiao"+n,i=e(`${s}${o}`).toString(),c=r.sign({randomId:n,timestamp:o,sign:i},s,{expiresIn:600});return{url:`${t}/api/router?path=user&key=webLogin&p&loginToken=${c}&sign=${i}&randomId=${n}`,token:c,tokenSecret:s}}},Rn=class extends Sn{constructor(t){super({...t,cache:new En("login")})}};const Bn=new at,q=new Rn({query:Bn});class Mn extends HTMLElement{options;timer=null;constructor(){super(),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:r,closable:n}=this.options,s=L`
1
+ (function(Q){typeof define=="function"&&define.amd?define(Q):Q()})((function(){"use strict";const Q=globalThis,le=Q.trustedTypes,Xe=le?le.createPolicy("lit-html",{createHTML:n=>n}):void 0,Ze="$lit$",z=`lit$${Math.random().toFixed(9).slice(2)}$`,et="?"+z,fn=`<${et}>`,V=document,te=()=>V.createComment(""),ne=n=>n===null||typeof n!="object"&&typeof n!="function",pe=Array.isArray,gn=n=>pe(n)||typeof n?.[Symbol.iterator]=="function",we=`[
2
+ \f\r]`,re=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,tt=/-->/g,nt=/>/g,O=RegExp(`>|${we}(?:([^\\s"'>=/]+)(${we}*=${we}*(?:[^
3
+ \f\r"'\`<>=]|("|')|))|$)`,"g"),rt=/'/g,ot=/"/g,st=/^(?:script|style|textarea|title)$/i,mn=n=>(e,...t)=>({_$litType$:n,strings:e,values:t}),I=mn(1),G=Symbol.for("lit-noChange"),B=Symbol.for("lit-nothing"),it=new WeakMap,W=V.createTreeWalker(V,129);function at(n,e){if(!pe(n)||!n.hasOwnProperty("raw"))throw Error("invalid template strings array");return Xe!==void 0?Xe.createHTML(e):e}const pn=(n,e)=>{const t=n.length-1,r=[];let o,s=e===2?"<svg>":e===3?"<math>":"",i=re;for(let c=0;c<t;c++){const a=n[c];let l,u,h=-1,f=0;for(;f<a.length&&(i.lastIndex=f,u=i.exec(a),u!==null);)f=i.lastIndex,i===re?u[1]==="!--"?i=tt:u[1]!==void 0?i=nt:u[2]!==void 0?(st.test(u[2])&&(o=RegExp("</"+u[2],"g")),i=O):u[3]!==void 0&&(i=O):i===O?u[0]===">"?(i=o??re,h=-1):u[1]===void 0?h=-2:(h=i.lastIndex-u[2].length,l=u[1],i=u[3]===void 0?O:u[3]==='"'?ot:rt):i===ot||i===rt?i=O:i===tt||i===nt?i=re:(i=O,o=void 0);const d=i===O&&n[c+1].startsWith("/>")?" ":"";s+=i===re?a+fn:h>=0?(r.push(l),a.slice(0,h)+Ze+a.slice(h)+z+d):a+z+(h===-2?c:d)}return[at(n,s+(n[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),r]};class oe{constructor({strings:e,_$litType$:t},r){let o;this.parts=[];let s=0,i=0;const c=e.length-1,a=this.parts,[l,u]=pn(e,t);if(this.el=oe.createElement(l,r),W.currentNode=this.el.content,t===2||t===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(o=W.nextNode())!==null&&a.length<c;){if(o.nodeType===1){if(o.hasAttributes())for(const h of o.getAttributeNames())if(h.endsWith(Ze)){const f=u[i++],d=o.getAttribute(h).split(z),g=/([.?@])?(.*)/.exec(f);a.push({type:1,index:s,name:g[2],strings:d,ctor:g[1]==="."?yn:g[1]==="?"?vn:g[1]==="@"?bn:ue}),o.removeAttribute(h)}else h.startsWith(z)&&(a.push({type:6,index:s}),o.removeAttribute(h));if(st.test(o.tagName)){const h=o.textContent.split(z),f=h.length-1;if(f>0){o.textContent=le?le.emptyScript:"";for(let d=0;d<f;d++)o.append(h[d],te()),W.nextNode(),a.push({type:2,index:++s});o.append(h[f],te())}}}else if(o.nodeType===8)if(o.data===et)a.push({type:2,index:s});else{let h=-1;for(;(h=o.data.indexOf(z,h+1))!==-1;)a.push({type:7,index:s}),h+=z.length-1}s++}}static createElement(e,t){const r=V.createElement("template");return r.innerHTML=e,r}}function Y(n,e,t=n,r){if(e===G)return e;let o=r!==void 0?t._$Co?.[r]:t._$Cl;const s=ne(e)?void 0:e._$litDirective$;return o?.constructor!==s&&(o?._$AO?.(!1),s===void 0?o=void 0:(o=new s(n),o._$AT(n,t,r)),r!==void 0?(t._$Co??=[])[r]=o:t._$Cl=o),o!==void 0&&(e=Y(n,o._$AS(n,e.values),o,r)),e}class wn{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:r}=this._$AD,o=(e?.creationScope??V).importNode(t,!0);W.currentNode=o;let s=W.nextNode(),i=0,c=0,a=r[0];for(;a!==void 0;){if(i===a.index){let l;a.type===2?l=new se(s,s.nextSibling,this,e):a.type===1?l=new a.ctor(s,a.name,a.strings,this,e):a.type===6&&(l=new Cn(s,this,e)),this._$AV.push(l),a=r[++c]}i!==a?.index&&(s=W.nextNode(),i++)}return W.currentNode=V,o}p(e){let t=0;for(const r of this._$AV)r!==void 0&&(r.strings!==void 0?(r._$AI(e,r,t),t+=r.strings.length-2):r._$AI(e[t])),t++}}class se{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,t,r,o){this.type=2,this._$AH=B,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=r,this.options=o,this._$Cv=o?.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=Y(this,e,t),ne(e)?e===B||e==null||e===""?(this._$AH!==B&&this._$AR(),this._$AH=B):e!==this._$AH&&e!==G&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):gn(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!==B&&ne(this._$AH)?this._$AA.nextSibling.data=e:this.T(V.createTextNode(e)),this._$AH=e}$(e){const{values:t,_$litType$:r}=e,o=typeof r=="number"?this._$AC(e):(r.el===void 0&&(r.el=oe.createElement(at(r.h,r.h[0]),this.options)),r);if(this._$AH?._$AD===o)this._$AH.p(t);else{const s=new wn(o,this),i=s.u(this.options);s.p(t),this.T(i),this._$AH=s}}_$AC(e){let t=it.get(e.strings);return t===void 0&&it.set(e.strings,t=new oe(e)),t}k(e){pe(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let r,o=0;for(const s of e)o===t.length?t.push(r=new se(this.O(te()),this.O(te()),this,this.options)):r=t[o],r._$AI(s),o++;o<t.length&&(this._$AR(r&&r._$AB.nextSibling,o),t.length=o)}_$AR(e=this._$AA.nextSibling,t){for(this._$AP?.(!1,!0,t);e!==this._$AB;){const r=e.nextSibling;e.remove(),e=r}}setConnected(e){this._$AM===void 0&&(this._$Cv=e,this._$AP?.(e))}}class ue{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,r,o,s){this.type=1,this._$AH=B,this._$AN=void 0,this.element=e,this.name=t,this._$AM=o,this.options=s,r.length>2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=B}_$AI(e,t=this,r,o){const s=this.strings;let i=!1;if(s===void 0)e=Y(this,e,t,0),i=!ne(e)||e!==this._$AH&&e!==G,i&&(this._$AH=e);else{const c=e;let a,l;for(e=s[0],a=0;a<s.length-1;a++)l=Y(this,c[r+a],t,a),l===G&&(l=this._$AH[a]),i||=!ne(l)||l!==this._$AH[a],l===B?e=B:e!==B&&(e+=(l??"")+s[a+1]),this._$AH[a]=l}i&&!o&&this.j(e)}j(e){e===B?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class yn extends ue{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===B?void 0:e}}class vn extends ue{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==B)}}class bn extends ue{constructor(e,t,r,o,s){super(e,t,r,o,s),this.type=5}_$AI(e,t=this){if((e=Y(this,e,t,0)??B)===G)return;const r=this._$AH,o=e===B&&r!==B||e.capture!==r.capture||e.once!==r.once||e.passive!==r.passive,s=e!==B&&(r===B||o);o&&this.element.removeEventListener(this.name,this,r),s&&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 Cn{constructor(e,t,r){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=r}get _$AU(){return this._$AM._$AU}_$AI(e){Y(this,e)}}const An=Q.litHtmlPolyfillSupport;An?.(oe,se),(Q.litHtmlVersions??=[]).push("3.3.1");const ct=(n,e,t)=>{const r=e;let o=r._$litPart$;return o===void 0&&(r._$litPart$=o=new se(e.insertBefore(te(),null),null,void 0,{})),o._$AI(n),o};const Tn={CHILD:2},En=n=>(...e)=>({_$litDirective$:n,values:e});class _n{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,t,r){this._$Ct=e,this._$AM=t,this._$Ci=r}_$AS(e,t){return this.update(e,t)}update(e,t){return this.render(...t)}}class ye extends _n{constructor(e){if(super(e),this.it=B,e.type!==Tn.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===B||e==null)return this._t=void 0,this.it=e;if(e===G)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:[]}}}ye.directiveName="unsafeHTML",ye.resultType=1;const lt=En(ye),kn=n=>n?["text/","xml","html","javascript","css","csv","plain","x-www-form-urlencoded"].some(t=>n.includes(t)):!1,ut=async(n={},e)=>{const t=new AbortController,r=t.signal,o=n.isBlob||!1,s=n.isText||!1,i=n.isPostFile||!1,c=n.timeout||6e4*3,a=setTimeout(()=>{t.abort()},c);let l=e?.method||n?.method||"POST",u={...n?.headers,...e?.headers},h="",f;n?.url?.startsWith("http")?f=new URL(n.url):(h=window?.location?.origin||"http://localhost:51015",f=new URL(n.url,h));const d=l==="GET";d&&(f.search=new URLSearchParams(n.body).toString());let g;return d?g=void 0:i?g=n.body:(u={"Content-Type":"application/json",...u},g=JSON.stringify(n.body)),fetch(f,{method:l.toUpperCase(),signal:r,body:g,...e,headers:u}).then(async p=>{const m=p.headers.get("Content-Type");return o?await p.blob():m&&m.includes("application/json")&&!s?await p.json():kn(m)?{code:200,status:p.status,data:await p.text()}:p}).catch(p=>(p.name==="AbortError"&&console.log("Request timed out and was aborted"),console.error(p),{code:500})).finally(()=>{clearTimeout(a)})},ht=n=>(n.success=n.code===200,n.showError=e=>{!n.success&&!n.noMsg&&e?.()},n),ve=({code:n,message:e})=>({code:n||500,success:!1,message:e||"api request error",showError:r=>{},noMsg:!0});class dt{adapter;url;beforeRequest;afterResponse;headers;timeout;stop;qws;constructor(e){this.adapter=e?.adapter||ut,this.url=e?.url||"/api/router",this.headers=e?.headers||{"Content-Type":"application/json"},this.timeout=e?.timeout||6e4*3}setQueryWs(e){this.qws=e}setStop(e){this.stop=e}async get(e,t){return this.post(e,t)}async post(e,t){const r=t?.url||this.url,{headers:o,adapter:s,beforeRequest:i,afterResponse:c,timeout:a,...l}=t||{},u={...this.headers,...o},h=s||this.adapter,f=i||this.beforeRequest,d=c||this.afterResponse,g=a||this.timeout,p={url:r,headers:u,body:e,timeout:g,...l};try{if(f&&await f(p)===!1)return ve({code:500,message:"request is cancel",req:p})}catch(m){return console.error("request beforeFn error",m,p),ve({code:500,message:"api request beforeFn error"})}if(this.stop&&!t?.noStop){const m=this;await new Promise(y=>{let E=0;const w=setInterval(()=>{m.stop||(clearInterval(w),y(!0)),E++,E>30&&console.error("request stop: timeout",p.url,E)},1e3)})}return h(p).then(async m=>{try{return ht(m),d?await d(m,{req:p,res:m,fetch:s}):m}catch(y){return console.error("request afterFn error",y,p),ve({code:500,message:"api request afterFn error"})}})}before(e){this.beforeRequest=e}after(e){this.afterResponse=e}async fetchText(e,t){let r={...t};typeof e=="string"&&!r.url&&(r.url=e),typeof e=="object"&&(r={...e,...r});const o=await ut({method:"GET",...r,headers:{...this.headers,...r?.headers||{}}});return ht(o)}}class xn{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)}}const ft=n=>(n.success=n.code===200,n.showError=e=>{!n.success&&!n.noMsg&&e?.()},n);function L(n){return new Promise((e,t)=>{n.oncomplete=n.onsuccess=()=>e(n.result),n.onabort=n.onerror=()=>t(n.error)})}function gt(n,e){const t=indexedDB.open(n);t.onupgradeneeded=()=>t.result.createObjectStore(e);const r=L(t);return(o,s)=>r.then(i=>s(i.transaction(e,o).objectStore(e)))}let be;function $(){return be||(be=gt("keyval-store","keyval")),be}function mt(n,e=$()){return e("readonly",t=>L(t.get(n)))}function pt(n,e,t=$()){return t("readwrite",r=>(r.put(e,n),L(r.transaction)))}function Rn(n,e=$()){return e("readwrite",t=>(n.forEach(r=>t.put(r[1],r[0])),L(t.transaction)))}function Sn(n,e=$()){return e("readonly",t=>Promise.all(n.map(r=>L(t.get(r)))))}function Mn(n,e,t=$()){return t("readwrite",r=>new Promise((o,s)=>{r.get(n).onsuccess=function(){try{r.put(e(this.result),n),o(L(r.transaction))}catch(i){s(i)}}}))}function wt(n,e=$()){return e("readwrite",t=>(t.delete(n),L(t.transaction)))}function Bn(n,e=$()){return e("readwrite",t=>(n.forEach(r=>t.delete(r)),L(t.transaction)))}function yt(n=$()){return n("readwrite",e=>(e.clear(),L(e.transaction)))}function Ce(n,e){return n.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},L(n.transaction)}function Ln(n=$()){return n("readonly",e=>{if(e.getAllKeys)return L(e.getAllKeys());const t=[];return Ce(e,r=>t.push(r.key)).then(()=>t)})}function In(n=$()){return n("readonly",e=>{if(e.getAll)return L(e.getAll());const t=[];return Ce(e,r=>t.push(r.value)).then(()=>t)})}function $n(n=$()){return n("readonly",e=>{if(e.getAll&&e.getAllKeys)return Promise.all([L(e.getAllKeys()),L(e.getAll())]).then(([r,o])=>r.map((s,i)=>[s,o[i]]));const t=[];return n("readonly",r=>Ce(r,o=>t.push([o.key,o.value])).then(()=>t))})}var Pn=Object.freeze({__proto__:null,clear:yt,createStore:gt,del:wt,delMany:Bn,entries:$n,get:mt,getMany:Sn,keys:Ln,promisifyRequest:L,set:pt,setMany:Rn,update:Mn,values:In});class qn{storage;data=null;constructor(){this.storage=Pn}async get(e){const t=await mt(e);return this.data=t,t}async set(e,t){this.data=t,await pt(e,t)}async del(e){this.data=null,await wt(e)}async clear(){await yt()}}class Nn extends qn{name;updatedAt;constructor(e){super(),this.name=e||"my-cache"}async getData(){const e=await super.get(this.name);return this.updatedAt=e.updatedAt,e.expireTime&&e.expireTime<Date.now()?(await super.del(this.name),{}):e.data}async setData(e,t){const o=Date.now()+(t?.expireTime||1e3*60*60*24*10),s={data:e,updatedAt:t?.updatedAt||Date.now(),expireTime:o};await super.set(this.name,s),this.updatedAt=s.updatedAt}async del(){await super.del(this.name)}}var Dn=class{cache;name;cacheData;constructor(n){if(!n.cache)throw new Error("cache is required");this.cache=n.cache,this.cacheData={loginUsers:[],user:void 0,id:void 0,accessToken:void 0,refreshToken:void 0},this.name=n.name}async setValue(n){return await this.cache.set(this.name,n),this.cacheData=n,n}async delValue(){await this.cache.del()}getValue(){return this.cache.get(this.name)}async init(){const n={loginUsers:[],user:null,id:null,accessToken:null,refreshToken:null};if(this.cache.init)try{const e=await this.cache.init();this.cacheData=e||n}catch(e){console.log("cacheInit error",e)}else this.cacheData=await this.getValue()||n}async setLoginUser(n){this.cacheData.loginUsers.find(t=>t.id===n.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(t=>t?.id&&t.id!==n.id)),this.cacheData.loginUsers.push(n),this.cacheData.user=n.user,this.cacheData.id=n.id,this.cacheData.accessToken=n.accessToken,this.cacheData.refreshToken=n.refreshToken,await this.setValue(this.cacheData)}getCurrentUser(){const n=this.cacheData;return Promise.resolve(n.user)}getCurrentUserList(){return Promise.resolve(this.cacheData.loginUsers.filter(n=>n?.id))}getRefreshToken(){const n=this.cacheData;return Promise.resolve(n.refreshToken||"")}getAccessToken(){const n=this.cacheData;return Promise.resolve(n.accessToken||"")}async clearCurrentUser(){const n=await this.getCurrentUser();this.cacheData.loginUsers.find(t=>t.id===n.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(t=>t?.id&&t.id!==n.id)),this.cacheData.user=void 0,this.cacheData.id=void 0,this.cacheData.accessToken=void 0,this.cacheData.refreshToken=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,await this.setValue(this.cacheData)}},Un=class extends xn{cacheStore;isBrowser;load;storage;onLoad;constructor(n){super({query:n?.query||new dt}),this.cacheStore=new Dn({name:"login",cache:n.cache}),this.isBrowser=n?.isBrowser??!0,this.init(),this.onLoad=n?.onLoad,this.storage=n?.storage||localStorage}setQuery(n){this.query=n}async init(){await this.cacheStore.init(),this.load=!0,this.onLoad?.()}async post(n,e){try{return this.query.post({path:"user",...n},e)}catch(t){return console.log("error",t),{code:400}}}async login(n){const e=await this.post({key:"login",...n});if(e.code===200){const{accessToken:t,refreshToken:r}=e?.data||{};this.storage.setItem("token",t||""),await this.beforeSetLoginUser({accessToken:t,refreshToken:r})}return e}async loginByCode(n){const e=await this.post({path:"sms",key:"login",data:n});if(e.code===200){const{accessToken:t,refreshToken:r}=e?.data||{};this.storage.setItem("token",t||""),await this.beforeSetLoginUser({accessToken:t,refreshToken:r})}return e}async setLoginToken(n){const{accessToken:e,refreshToken:t}=n;this.storage.setItem("token",e||""),await this.beforeSetLoginUser({accessToken:e,refreshToken:t})}async loginByWechat(n){const e=await this.post({path:"wx",key:"open-login",code:n.code});if(e.code===200){const{accessToken:t,refreshToken:r}=e?.data||{};this.storage.setItem("token",t||""),await this.beforeSetLoginUser({accessToken:t,refreshToken:r})}return e}async checkWechat({onSuccess:n,onError:e}){const t=new URL(window.location.href),r=t.searchParams.get("code"),o=t.searchParams.get("state");if(r&&o){const s=await this.loginByWechat({code:r});s.code===200?n?.(s.data):e?.(s)}}async beforeSetLoginUser({accessToken:n,refreshToken:e,check401:t}){if(n&&e){const r=await this.getMe(n,t);if(r.code===200){const o=r.data;o?this.cacheStore.setLoginUser({user:o,id:o.id,accessToken:n,refreshToken:e}):console.error("登录失败")}}}async queryRefreshToken(n){const e=n||this.cacheStore.getRefreshToken();let t={refreshToken:e};return e?this.post({key:"refreshToken",data:t},{afterResponse:async(r,o)=>(ft(r),r)}):(await this.cacheStore.clearCurrentUser(),{code:401,message:"请先登录",data:{}})}async afterCheck401ToRefreshToken(n,e,t){const r=this;if(n?.code===401){const o=await r.cacheStore.getRefreshToken();if(o){const s=await r.queryRefreshToken(o);if(s.code===200){const{accessToken:i,refreshToken:c}=s?.data||{};if(r.storage.setItem("token",i||""),await r.beforeSetLoginUser({accessToken:i,refreshToken:c,check401:!1}),t&&e&&e.req&&e.req.url&&e.fetch){await new Promise(f=>setTimeout(f,1500));const a=e.req?.url,l=e.req?.body,u=e.req?.headers,h=await e.fetch(a,{method:"POST",body:l,headers:{...u,Authorization:`Bearer ${i}`}});return ft(h),h}}else r.storage.removeItem("token"),await r.cacheStore.clearCurrentUser();return s}}return n}async run401Action(n,e,t){const r=this,o=t?.refetch??!1;if(n?.code===401){if(r.query.stop===!0)return{code:500,success:!1,message:"refresh token loading..."};r.query.stop=!0;const s=await r.afterCheck401ToRefreshToken(n,e,o);return r.query.stop=!1,t?.afterCheck?.(s),s.code===401&&t?.afterAlso401?.(s),s}else return n}async getMe(n,e=!0){const t=n||this.storage.getItem("token"),r=this;return r.post({key:"me"},{beforeRequest:async o=>(o.headers&&(o.headers.Authorization=`Bearer ${t}`),o),afterResponse:async(o,s)=>o?.code===401&&e&&!n?await r.afterCheck401ToRefreshToken(o,s):o})}async checkLocalUser(){const n=await this.cacheStore.getCurrentUser();return n||null}async checkLocalToken(){return!!this.storage.getItem("token")}async postSwitchUser(n){return this.post({key:"switchCheck",data:{username:n}})}async switchUser(n){const t=(await this.cacheStore.getCurrentUserList()).find(o=>o.user.username===n);if(t)return this.storage.setItem("token",t.accessToken||""),await this.beforeSetLoginUser({accessToken:t.accessToken,refreshToken:t.refreshToken}),{code:200,data:{accessToken:t.accessToken,refreshToken:t.refreshToken},success:!0,message:"切换用户成功"};const r=await this.postSwitchUser(n);if(r.code===200){const{accessToken:o,refreshToken:s}=r?.data||{};this.storage.setItem("token",o||""),await this.beforeSetLoginUser({accessToken:o,refreshToken:s})}return r}async logout(){this.storage.removeItem("token");const e=(await this.cacheStore.getCurrentUserList()).map(t=>t?.accessToken).filter(Boolean);return this.cacheStore.delValue(),this.post({key:"logout",data:{tokens:e}})}async hasUser(n){const e=this;return this.post({path:"org",key:"hasUser",data:{username:n}},{afterResponse:async(t,r)=>t?.code===401?await e.afterCheck401ToRefreshToken(t,r,!0):t})}async checkLoginStatus(n){const e=await this.post({path:"user",key:"checkLoginStatus",loginToken:n});if(e.code===200){const t=e.data?.accessToken;return this.storage.setItem("token",t||""),await this.beforeSetLoginUser({accessToken:t,refreshToken:e.data?.refreshToken}),e}return!1}loginWithWeb(n,{MD5:e,jsonwebtoken:t}){const r=Math.random().toString(36).substring(2,15),o=Date.now(),s="xiao"+r,i=e(`${s}${o}`).toString(),c=t.sign({randomId:r,timestamp:o,sign:i},s,{expiresIn:600});return{url:`${n}/api/router?path=user&key=webLogin&p&loginToken=${c}&sign=${i}&randomId=${r}`,token:c,tokenSecret:s}}},Fn=class extends Un{constructor(n){super({...n,cache:new Nn("login")})}};const zn=new dt,q=new Fn({query:zn});class Hn extends HTMLElement{options;timer=null;constructor(){super(),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:r}=this.options,s=I`
4
4
  <style>
5
5
  :host {
6
6
  display: block;
@@ -127,14 +127,14 @@
127
127
 
128
128
  <div class="message-container ${e}">
129
129
  <div class="message-icon">
130
- ${(()=>{switch(e){case"success":return"✓";case"error":return"✕";case"loading":return L`<div class="loading-spinner"></div>`;default:return""}})()}
130
+ ${(()=>{switch(e){case"success":return"✓";case"error":return"✕";case"loading":return I`<div class="loading-spinner"></div>`;default:return""}})()}
131
131
  </div>
132
- <div class="message-content">${r}</div>
133
- ${n?L`
132
+ <div class="message-content">${t}</div>
133
+ ${r?I`
134
134
  <button class="message-close" @click=${()=>this.remove()}>&times;</button>
135
135
  `:""}
136
136
  </div>
137
- `;rt(s,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",Mn);class Y{static instance;container=null;defaultPosition="center";static getInstance(){return Y.instance||(Y.instance=new Y),Y.instance}setDefaultPosition(e){this.defaultPosition=e}getContainer(e){const r=e||this.defaultPosition;return this.container||(this.container=document.getElementById("messages"),this.container||(this.container=document.createElement("div"),this.container.id="messages",r==="center"?this.container.style.cssText=`
137
+ `;ct(s,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",Hn);class X{static instance;container=null;defaultPosition="center";static getInstance(){return X.instance||(X.instance=new X),X.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
138
  position: fixed;
139
139
  top: 20px;
140
140
  left: 50%;
@@ -155,14 +155,14 @@
155
155
  flex-direction: column;
156
156
  align-items: flex-end;
157
157
  pointer-events: none;
158
- `,document.body.appendChild(this.container))),this.container}show(e){const r=this.getContainer(e.position),n=document.createElement("kv-message");return n.setOptions(e),n.style.cssText="pointer-events: auto;",r.appendChild(n),n}success(e,r){return this.show({type:"success",message:e,duration:r?.duration||2e3,position:r?.position,closable:r?.closable})}error(e,r){return this.show({type:"error",message:e,duration:r?.duration||3e3,position:r?.position,closable:r?.closable})}loading(e,r){return this.show({type:"loading",message:e,duration:0,position:r?.position,closable:r?.closable})}remove(e){e.remove()}clear(){this.getContainer().querySelectorAll("kv-message").forEach(n=>{n.remove()})}}const gt=()=>Y.getInstance();window.createMessage=gt;const D=gt(),se=()=>{console.log("重定向到首页");const t=window.location.href,r=new URL(t).searchParams.get("redirect");if(r){const n=decodeURIComponent(r);window.open(n,"_self")}else window.open("/root/home","_self")},xn=async t=>{const{loginMethod:e,data:r}=t;switch(e){case"password":await $n(r);break;case"phone":await Ln(r);break;case"wechat-mp":await Pn(r);break;case"wechat":await In(r);break;default:console.warn("未知的登录方式:",e)}},$n=async t=>{console.log("使用用户名密码登录:",t);let e=!0;if(await q.checkLocalToken()&&(await q.checkLocalUser())?.username===t?.username&&(await q.getMe()).code===200&&(e=!1,console.log("已登录,跳过登录步骤"),D.success("已登录")),!e){se();return}const n=await q.login({username:t.username,password:t.password});n.code===200?(console.log("登录成功"),D.success("登录成功"),se()):D.error(`登录失败: ${n.message}`)},Ln=async t=>{console.log("使用手机号登录:",t)},In=async t=>{console.log("使用微信登录:",t)},Pn=async t=>{console.log("使用微信公众号登录:",t)},qn=()=>{const t=new URL(window.location.href);t.searchParams.delete("code"),t.searchParams.delete("state"),window.history.replaceState({},document.title,t.toString())},Dn=async()=>{const t=new URL(window.location.href),e=t.searchParams.get("code");if(t.searchParams.get("state")?.includes?.("-")||!e)return;const n=await q.loginByWechat({code:e});n.code===200?(D.success("登录成功"),se()):(D.error(n.message||"登录失败"),qn())},Nn=async()=>{const t=new URL(window.location.href),e=t.searchParams.get("state"),[r,n]=e?e.split("-"):[null,null];if(console.log("检查微信公众号登录流程:",r,n,e),r==="1")Fn();else if(r==="2"){const o=t.searchParams.get("code"),s=await q.post({path:"wx",key:"mplogin",state:n,code:o});s.code===200?D.success("登录成功"):D.error(s.message||"登录失败"),pt()}},Un=()=>{const t=navigator.userAgent.toLowerCase();return/micromessenger/i.test(t)},pt=(t=2e3)=>{if(!Un()){setTimeout(()=>{window.close()},t);return}window.WeixinJSBridge?setTimeout(()=>{window.WeixinJSBridge.call("closeWindow")},t):setTimeout(()=>{window.close()},t)},Fn=async()=>{const t="https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect",e=Qt,r=new URL(window.location.href),n=r.searchParams.get("state");let[o,s]=n?n.split("-"):[null,null];const i=new URL(r.pathname,r.origin);s="2-"+s;const c=encodeURIComponent(i.toString());document.body.innerHTML="<p>正在准备跳转到微信公众号授权页面...</p>";const a="snsapi_userinfo";if(!s){alert("Invalid state. Please try again later."),pt();return}const l=t.replace("APPID",e).replace("REDIRECT_URI",c).replace("SCOPE",a).replace("STATE",s);setTimeout(()=>{window.location.href=l},100)};setTimeout(()=>{Nn()},100);const zn=async()=>{const t=await q.post({path:"wx",key:"get-qrcode-ticket"});return t.code!==200?(D.error("获取二维码失败"),null):t?.data},Hn=t=>{let e=!0;const r=async()=>{const s=await q.post({path:"wx",key:"check-qrcode-login",payload:{ticket:t}});s.code===200?(D.success("登录成功"),clearTimeout(n),se()):(s.code===401?console.log("等待扫码登录..."):console.log("扫码登录状态:",s),e&&setTimeout(r,2e3))},n=setTimeout(r,2e3);return()=>{console.log("停止检测扫码登录状态"),clearTimeout(n),e=!1}},mt=async t=>{let e=t?.redirect_uri;const{appid:r}=t||{};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),!r){console.error("appid is not cant be empty");return}const o=new WxLogin({self_redirect:!1,id:"weixinLogin",appid:r,scope:"snsapi_login",redirect_uri:encodeURIComponent(e),state:Math.ceil(Math.random()*1e3),stylelite:!0,href:"data:text/css;base64,LmltcG93ZXJCb3ggLnFyY29kZSB7d2lkdGg6IDIwMHB4O30NCi5pbXBvd2VyQm94IC50aXRsZSB7ZGlzcGxheTogbm9uZTt9DQouaW1wb3dlckJveCAuaW5mbyB7d2lkdGg6IDIwMHB4O30NCi5zdGF0dXNfaWNvbiB7ZGlzcGxheTogbm9uZX0NCi5pbXBvd2VyQm94IC5zdGF0dXMge3RleHQtYWxpZ246IGNlbnRlcjt9"}),s=document.querySelector("#weixinLogin");if(s){const i=s.querySelector("iframe");i&&(i.style.height="300px")}return o};function jn(t){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")){mt(t);return}const r=document.body.appendChild(e);r.onload=function(){mt(t)}}function Vn(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var X={},ye,wt;function Wn(){return wt||(wt=1,ye=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),ye}var be={},z={},yt;function O(){if(yt)return z;yt=1;let t;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 z.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},z.getSymbolTotalCodewords=function(n){return e[n]},z.getBCHDigit=function(r){let n=0;for(;r!==0;)n++,r>>>=1;return n},z.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');t=n},z.isKanjiModeEnabled=function(){return typeof t<"u"},z.toSJIS=function(n){return t(n)},z}var ve={},bt;function Ae(){return bt||(bt=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function e(r){if(typeof r!="string")throw new Error("Param is not a string");switch(r.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+r)}}t.isValid=function(n){return n&&typeof n.bit<"u"&&n.bit>=0&&n.bit<4},t.from=function(n,o){if(t.isValid(n))return n;try{return e(n)}catch{return o}}})(ve)),ve}var Ce,vt;function On(){if(vt)return Ce;vt=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(e){const r=Math.floor(e/8);return(this.buffer[r]>>>7-e%8&1)===1},put:function(e,r){for(let n=0;n<r;n++)this.putBit((e>>>r-n-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const r=Math.floor(this.length/8);this.buffer.length<=r&&this.buffer.push(0),e&&(this.buffer[r]|=128>>>this.length%8),this.length++}},Ce=t,Ce}var Te,At;function Jn(){if(At)return Te;At=1;function t(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 t.prototype.set=function(e,r,n,o){const s=e*this.size+r;this.data[s]=n,o&&(this.reservedBit[s]=!0)},t.prototype.get=function(e,r){return this.data[e*this.size+r]},t.prototype.xor=function(e,r,n){this.data[e*this.size+r]^=n},t.prototype.isReserved=function(e,r){return this.reservedBit[e*this.size+r]},Te=t,Te}var ke={},Ct;function Kn(){return Ct||(Ct=1,(function(t){const e=O().getSymbolSize;t.getRowColCoords=function(n){if(n===1)return[];const o=Math.floor(n/7)+2,s=e(n),i=s===145?26:Math.ceil((s-13)/(2*o-2))*2,c=[s-7];for(let a=1;a<o-1;a++)c[a]=c[a-1]-i;return c.push(6),c.reverse()},t.getPositions=function(n){const o=[],s=t.getRowColCoords(n),i=s.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||o.push([s[c],s[a]]);return o}})(ke)),ke}var Ee={},Tt;function Qn(){if(Tt)return Ee;Tt=1;const t=O().getSymbolSize,e=7;return Ee.getPositions=function(n){const o=t(n);return[[0,0],[o-e,0],[0,o-e]]},Ee}var _e={},kt;function Gn(){return kt||(kt=1,(function(t){t.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};t.isValid=function(o){return o!=null&&o!==""&&!isNaN(o)&&o>=0&&o<=7},t.from=function(o){return t.isValid(o)?parseInt(o,10):void 0},t.getPenaltyN1=function(o){const s=o.size;let i=0,c=0,a=0,l=null,u=null;for(let h=0;h<s;h++){c=a=0,l=u=null;for(let f=0;f<s;f++){let d=o.get(h,f);d===l?c++:(c>=5&&(i+=e.N1+(c-5)),l=d,c=1),d=o.get(f,h),d===u?a++:(a>=5&&(i+=e.N1+(a-5)),u=d,a=1)}c>=5&&(i+=e.N1+(c-5)),a>=5&&(i+=e.N1+(a-5))}return i},t.getPenaltyN2=function(o){const s=o.size;let i=0;for(let c=0;c<s-1;c++)for(let a=0;a<s-1;a++){const l=o.get(c,a)+o.get(c,a+1)+o.get(c+1,a)+o.get(c+1,a+1);(l===4||l===0)&&i++}return i*e.N2},t.getPenaltyN3=function(o){const s=o.size;let i=0,c=0,a=0;for(let l=0;l<s;l++){c=a=0;for(let u=0;u<s;u++)c=c<<1&2047|o.get(l,u),u>=10&&(c===1488||c===93)&&i++,a=a<<1&2047|o.get(u,l),u>=10&&(a===1488||a===93)&&i++}return i*e.N3},t.getPenaltyN4=function(o){let s=0;const i=o.data.length;for(let a=0;a<i;a++)s+=o.data[a];return Math.abs(Math.ceil(s*100/i/5)-10)*e.N4};function r(n,o,s){switch(n){case t.Patterns.PATTERN000:return(o+s)%2===0;case t.Patterns.PATTERN001:return o%2===0;case t.Patterns.PATTERN010:return s%3===0;case t.Patterns.PATTERN011:return(o+s)%3===0;case t.Patterns.PATTERN100:return(Math.floor(o/2)+Math.floor(s/3))%2===0;case t.Patterns.PATTERN101:return o*s%2+o*s%3===0;case t.Patterns.PATTERN110:return(o*s%2+o*s%3)%2===0;case t.Patterns.PATTERN111:return(o*s%3+(o+s)%2)%2===0;default:throw new Error("bad maskPattern:"+n)}}t.applyMask=function(o,s){const i=s.size;for(let c=0;c<i;c++)for(let a=0;a<i;a++)s.isReserved(a,c)||s.xor(a,c,r(o,a,c))},t.getBestMask=function(o,s){const i=Object.keys(t.Patterns).length;let c=0,a=1/0;for(let l=0;l<i;l++){s(l),t.applyMask(l,o);const u=t.getPenaltyN1(o)+t.getPenaltyN2(o)+t.getPenaltyN3(o)+t.getPenaltyN4(o);t.applyMask(l,o),u<a&&(a=u,c=l)}return c}})(_e)),_e}var ue={},Et;function _t(){if(Et)return ue;Et=1;const t=Ae(),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],r=[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 ue.getBlocksCount=function(o,s){switch(s){case t.L:return e[(o-1)*4+0];case t.M:return e[(o-1)*4+1];case t.Q:return e[(o-1)*4+2];case t.H:return e[(o-1)*4+3];default:return}},ue.getTotalCodewordsCount=function(o,s){switch(s){case t.L:return r[(o-1)*4+0];case t.M:return r[(o-1)*4+1];case t.Q:return r[(o-1)*4+2];case t.H:return r[(o-1)*4+3];default:return}},ue}var Se={},ie={},St;function Yn(){if(St)return ie;St=1;const t=new Uint8Array(512),e=new Uint8Array(256);return(function(){let n=1;for(let o=0;o<255;o++)t[o]=n,e[n]=o,n<<=1,n&256&&(n^=285);for(let o=255;o<512;o++)t[o]=t[o-255]})(),ie.log=function(n){if(n<1)throw new Error("log("+n+")");return e[n]},ie.exp=function(n){return t[n]},ie.mul=function(n,o){return n===0||o===0?0:t[e[n]+e[o]]},ie}var Rt;function Xn(){return Rt||(Rt=1,(function(t){const e=Yn();t.mul=function(n,o){const s=new Uint8Array(n.length+o.length-1);for(let i=0;i<n.length;i++)for(let c=0;c<o.length;c++)s[i+c]^=e.mul(n[i],o[c]);return s},t.mod=function(n,o){let s=new Uint8Array(n);for(;s.length-o.length>=0;){const i=s[0];for(let a=0;a<o.length;a++)s[a]^=e.mul(o[a],i);let c=0;for(;c<s.length&&s[c]===0;)c++;s=s.slice(c)}return s},t.generateECPolynomial=function(n){let o=new Uint8Array([1]);for(let s=0;s<n;s++)o=t.mul(o,new Uint8Array([1,e.exp(s)]));return o}})(Se)),Se}var Re,Bt;function Zn(){if(Bt)return Re;Bt=1;const t=Xn();function e(r){this.genPoly=void 0,this.degree=r,this.degree&&this.initialize(this.degree)}return e.prototype.initialize=function(n){this.degree=n,this.genPoly=t.generateECPolynomial(this.degree)},e.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const o=new Uint8Array(n.length+this.degree);o.set(n);const s=t.mod(o,this.genPoly),i=this.degree-s.length;if(i>0){const c=new Uint8Array(this.degree);return c.set(s,i),c}return s},Re=e,Re}var Be={},Me={},xe={},Mt;function xt(){return Mt||(Mt=1,xe.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}),xe}var P={},$t;function Lt(){if($t)return P;$t=1;const t="[0-9]+",e="[A-Z $%*+\\-./:]+";let r="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";r=r.replace(/u/g,"\\u");const n="(?:(?![A-Z0-9 $%*+\\-./:]|"+r+`)(?:.|[\r
159
- ]))+`;P.KANJI=new RegExp(r,"g"),P.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),P.BYTE=new RegExp(n,"g"),P.NUMERIC=new RegExp(t,"g"),P.ALPHANUMERIC=new RegExp(e,"g");const o=new RegExp("^"+r+"$"),s=new RegExp("^"+t+"$"),i=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return P.testKanji=function(a){return o.test(a)},P.testNumeric=function(a){return s.test(a)},P.testAlphanumeric=function(a){return i.test(a)},P}var It;function J(){return It||(It=1,(function(t){const e=xt(),r=Lt();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(s,i){if(!s.ccBits)throw new Error("Invalid mode: "+s);if(!e.isValid(i))throw new Error("Invalid version: "+i);return i>=1&&i<10?s.ccBits[0]:i<27?s.ccBits[1]:s.ccBits[2]},t.getBestModeForData=function(s){return r.testNumeric(s)?t.NUMERIC:r.testAlphanumeric(s)?t.ALPHANUMERIC:r.testKanji(s)?t.KANJI:t.BYTE},t.toString=function(s){if(s&&s.id)return s.id;throw new Error("Invalid mode")},t.isValid=function(s){return s&&s.bit&&s.ccBits};function n(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+o)}}t.from=function(s,i){if(t.isValid(s))return s;try{return n(s)}catch{return i}}})(Me)),Me}var Pt;function er(){return Pt||(Pt=1,(function(t){const e=O(),r=_t(),n=Ae(),o=J(),s=xt(),i=7973,c=e.getBCHDigit(i);function a(f,d,w){for(let p=1;p<=40;p++)if(d<=t.getCapacity(p,w,f))return p}function l(f,d){return o.getCharCountIndicator(f,d)+4}function u(f,d){let w=0;return f.forEach(function(p){const B=l(p.mode,d);w+=B+p.getBitsLength()}),w}function h(f,d){for(let w=1;w<=40;w++)if(u(f,w)<=t.getCapacity(w,d,o.MIXED))return w}t.from=function(d,w){return s.isValid(d)?parseInt(d,10):w},t.getCapacity=function(d,w,p){if(!s.isValid(d))throw new Error("Invalid QR Code version");typeof p>"u"&&(p=o.BYTE);const B=e.getSymbolTotalCodewords(d),A=r.getTotalCodewordsCount(d,w),R=(B-A)*8;if(p===o.MIXED)return R;const k=R-l(p,d);switch(p){case o.NUMERIC:return Math.floor(k/10*3);case o.ALPHANUMERIC:return Math.floor(k/11*2);case o.KANJI:return Math.floor(k/13);case o.BYTE:default:return Math.floor(k/8)}},t.getBestVersionForData=function(d,w){let p;const B=n.from(w,n.M);if(Array.isArray(d)){if(d.length>1)return h(d,B);if(d.length===0)return 1;p=d[0]}else p=d;return a(p.mode,p.getLength(),B)},t.getEncodedBits=function(d){if(!s.isValid(d)||d<7)throw new Error("Invalid QR Code version");let w=d<<12;for(;e.getBCHDigit(w)-c>=0;)w^=i<<e.getBCHDigit(w)-c;return d<<12|w}})(Be)),Be}var $e={},qt;function tr(){if(qt)return $e;qt=1;const t=O(),e=1335,r=21522,n=t.getBCHDigit(e);return $e.getEncodedBits=function(s,i){const c=s.bit<<3|i;let a=c<<10;for(;t.getBCHDigit(a)-n>=0;)a^=e<<t.getBCHDigit(a)-n;return(c<<10|a)^r},$e}var Le={},Ie,Dt;function nr(){if(Dt)return Ie;Dt=1;const t=J();function e(r){this.mode=t.NUMERIC,this.data=r.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 o,s,i;for(o=0;o+3<=this.data.length;o+=3)s=this.data.substr(o,3),i=parseInt(s,10),n.put(i,10);const c=this.data.length-o;c>0&&(s=this.data.substr(o),i=parseInt(s,10),n.put(i,c*3+1))},Ie=e,Ie}var Pe,Nt;function rr(){if(Nt)return Pe;Nt=1;const t=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 r(n){this.mode=t.ALPHANUMERIC,this.data=n}return r.getBitsLength=function(o){return 11*Math.floor(o/2)+6*(o%2)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(o){let s;for(s=0;s+2<=this.data.length;s+=2){let i=e.indexOf(this.data[s])*45;i+=e.indexOf(this.data[s+1]),o.put(i,11)}this.data.length%2&&o.put(e.indexOf(this.data[s]),6)},Pe=r,Pe}var qe,Ut;function or(){if(Ut)return qe;Ut=1;const t=J();function e(r){this.mode=t.BYTE,typeof r=="string"?this.data=new TextEncoder().encode(r):this.data=new Uint8Array(r)}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(r){for(let n=0,o=this.data.length;n<o;n++)r.put(this.data[n],8)},qe=e,qe}var De,Ft;function sr(){if(Ft)return De;Ft=1;const t=J(),e=O();function r(n){this.mode=t.KANJI,this.data=n}return r.getBitsLength=function(o){return o*13},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(n){let o;for(o=0;o<this.data.length;o++){let s=e.toSJIS(this.data[o]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[o]+`
160
- Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),n.put(s,13)}},De=r,De}var Ne={exports:{}},zt;function ir(){return zt||(zt=1,(function(t){var e={single_source_shortest_paths:function(r,n,o){var s={},i={};i[n]=0;var c=e.PriorityQueue.make();c.push(n,0);for(var a,l,u,h,f,d,w,p,B;!c.empty();){a=c.pop(),l=a.value,h=a.cost,f=r[l]||{};for(u in f)f.hasOwnProperty(u)&&(d=f[u],w=h+d,p=i[u],B=typeof i[u]>"u",(B||p>w)&&(i[u]=w,c.push(u,w),s[u]=l))}if(typeof o<"u"&&typeof i[o]>"u"){var A=["Could not find a path from ",n," to ",o,"."].join("");throw new Error(A)}return s},extract_shortest_path_from_predecessor_list:function(r,n){for(var o=[],s=n;s;)o.push(s),r[s],s=r[s];return o.reverse(),o},find_path:function(r,n,o){var s=e.single_source_shortest_paths(r,n,o);return e.extract_shortest_path_from_predecessor_list(s,o)},PriorityQueue:{make:function(r){var n=e.PriorityQueue,o={},s;r=r||{};for(s in n)n.hasOwnProperty(s)&&(o[s]=n[s]);return o.queue=[],o.sorter=r.sorter||n.default_sorter,o},default_sorter:function(r,n){return r.cost-n.cost},push:function(r,n){var o={value:r,cost:n};this.queue.push(o),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=e})(Ne)),Ne.exports}var Ht;function ar(){return Ht||(Ht=1,(function(t){const e=J(),r=nr(),n=rr(),o=or(),s=sr(),i=Lt(),c=O(),a=ir();function l(A){return unescape(encodeURIComponent(A)).length}function u(A,R,k){const E=[];let x;for(;(x=A.exec(k))!==null;)E.push({data:x[0],index:x.index,mode:R,length:x[0].length});return E}function h(A){const R=u(i.NUMERIC,e.NUMERIC,A),k=u(i.ALPHANUMERIC,e.ALPHANUMERIC,A);let E,x;return c.isKanjiModeEnabled()?(E=u(i.BYTE,e.BYTE,A),x=u(i.KANJI,e.KANJI,A)):(E=u(i.BYTE_KANJI,e.BYTE,A),x=[]),R.concat(k,E,x).sort(function(C,v){return C.index-v.index}).map(function(C){return{data:C.data,mode:C.mode,length:C.length}})}function f(A,R){switch(R){case e.NUMERIC:return r.getBitsLength(A);case e.ALPHANUMERIC:return n.getBitsLength(A);case e.KANJI:return s.getBitsLength(A);case e.BYTE:return o.getBitsLength(A)}}function d(A){return A.reduce(function(R,k){const E=R.length-1>=0?R[R.length-1]:null;return E&&E.mode===k.mode?(R[R.length-1].data+=k.data,R):(R.push(k),R)},[])}function w(A){const R=[];for(let k=0;k<A.length;k++){const E=A[k];switch(E.mode){case e.NUMERIC:R.push([E,{data:E.data,mode:e.ALPHANUMERIC,length:E.length},{data:E.data,mode:e.BYTE,length:E.length}]);break;case e.ALPHANUMERIC:R.push([E,{data:E.data,mode:e.BYTE,length:E.length}]);break;case e.KANJI:R.push([E,{data:E.data,mode:e.BYTE,length:l(E.data)}]);break;case e.BYTE:R.push([{data:E.data,mode:e.BYTE,length:l(E.data)}])}}return R}function p(A,R){const k={},E={start:{}};let x=["start"];for(let m=0;m<A.length;m++){const C=A[m],v=[];for(let g=0;g<C.length;g++){const _=C[g],y=""+m+g;v.push(y),k[y]={node:_,lastCount:0},E[y]={};for(let T=0;T<x.length;T++){const b=x[T];k[b]&&k[b].node.mode===_.mode?(E[b][y]=f(k[b].lastCount+_.length,_.mode)-f(k[b].lastCount,_.mode),k[b].lastCount+=_.length):(k[b]&&(k[b].lastCount=_.length),E[b][y]=f(_.length,_.mode)+4+e.getCharCountIndicator(_.mode,R))}}x=v}for(let m=0;m<x.length;m++)E[x[m]].end=0;return{map:E,table:k}}function B(A,R){let k;const E=e.getBestModeForData(A);if(k=e.from(R,E),k!==e.BYTE&&k.bit<E.bit)throw new Error('"'+A+'" cannot be encoded with mode '+e.toString(k)+`.
161
- Suggested mode is: `+e.toString(E));switch(k===e.KANJI&&!c.isKanjiModeEnabled()&&(k=e.BYTE),k){case e.NUMERIC:return new r(A);case e.ALPHANUMERIC:return new n(A);case e.KANJI:return new s(A);case e.BYTE:return new o(A)}}t.fromArray=function(R){return R.reduce(function(k,E){return typeof E=="string"?k.push(B(E,null)):E.data&&k.push(B(E.data,E.mode)),k},[])},t.fromString=function(R,k){const E=h(R,c.isKanjiModeEnabled()),x=w(E),m=p(x,k),C=a.find_path(m.map,"start","end"),v=[];for(let g=1;g<C.length-1;g++)v.push(m.table[C[g]].node);return t.fromArray(d(v))},t.rawSplit=function(R){return t.fromArray(h(R,c.isKanjiModeEnabled()))}})(Le)),Le}var jt;function cr(){if(jt)return be;jt=1;const t=O(),e=Ae(),r=On(),n=Jn(),o=Kn(),s=Qn(),i=Gn(),c=_t(),a=Zn(),l=er(),u=tr(),h=J(),f=ar();function d(m,C){const v=m.size,g=s.getPositions(C);for(let _=0;_<g.length;_++){const y=g[_][0],T=g[_][1];for(let b=-1;b<=7;b++)if(!(y+b<=-1||v<=y+b))for(let S=-1;S<=7;S++)T+S<=-1||v<=T+S||(b>=0&&b<=6&&(S===0||S===6)||S>=0&&S<=6&&(b===0||b===6)||b>=2&&b<=4&&S>=2&&S<=4?m.set(y+b,T+S,!0,!0):m.set(y+b,T+S,!1,!0))}}function w(m){const C=m.size;for(let v=8;v<C-8;v++){const g=v%2===0;m.set(v,6,g,!0),m.set(6,v,g,!0)}}function p(m,C){const v=o.getPositions(C);for(let g=0;g<v.length;g++){const _=v[g][0],y=v[g][1];for(let T=-2;T<=2;T++)for(let b=-2;b<=2;b++)T===-2||T===2||b===-2||b===2||T===0&&b===0?m.set(_+T,y+b,!0,!0):m.set(_+T,y+b,!1,!0)}}function B(m,C){const v=m.size,g=l.getEncodedBits(C);let _,y,T;for(let b=0;b<18;b++)_=Math.floor(b/3),y=b%3+v-8-3,T=(g>>b&1)===1,m.set(_,y,T,!0),m.set(y,_,T,!0)}function A(m,C,v){const g=m.size,_=u.getEncodedBits(C,v);let y,T;for(y=0;y<15;y++)T=(_>>y&1)===1,y<6?m.set(y,8,T,!0):y<8?m.set(y+1,8,T,!0):m.set(g-15+y,8,T,!0),y<8?m.set(8,g-y-1,T,!0):y<9?m.set(8,15-y-1+1,T,!0):m.set(8,15-y-1,T,!0);m.set(g-8,8,1,!0)}function R(m,C){const v=m.size;let g=-1,_=v-1,y=7,T=0;for(let b=v-1;b>0;b-=2)for(b===6&&b--;;){for(let S=0;S<2;S++)if(!m.isReserved(_,b-S)){let H=!1;T<C.length&&(H=(C[T]>>>y&1)===1),m.set(_,b-S,H),y--,y===-1&&(T++,y=7)}if(_+=g,_<0||v<=_){_-=g,g=-g;break}}}function k(m,C,v){const g=new r;v.forEach(function(S){g.put(S.mode.bit,4),g.put(S.getLength(),h.getCharCountIndicator(S.mode,m)),S.write(g)});const _=t.getSymbolTotalCodewords(m),y=c.getTotalCodewordsCount(m,C),T=(_-y)*8;for(g.getLengthInBits()+4<=T&&g.put(0,4);g.getLengthInBits()%8!==0;)g.putBit(0);const b=(T-g.getLengthInBits())/8;for(let S=0;S<b;S++)g.put(S%2?17:236,8);return E(g,m,C)}function E(m,C,v){const g=t.getSymbolTotalCodewords(C),_=c.getTotalCodewordsCount(C,v),y=g-_,T=c.getBlocksCount(C,v),b=g%T,S=T-b,H=Math.floor(g/T),ae=Math.floor(y/T),wr=ae+1,Yt=H-ae,yr=new a(Yt);let je=0;const he=new Array(T),Xt=new Array(T);let Ve=0;const br=new Uint8Array(m.buffer);for(let Z=0;Z<T;Z++){const Oe=Z<S?ae:wr;he[Z]=br.slice(je,je+Oe),Xt[Z]=yr.encode(he[Z]),je+=Oe,Ve=Math.max(Ve,Oe)}const We=new Uint8Array(g);let Zt=0,N,U;for(N=0;N<Ve;N++)for(U=0;U<T;U++)N<he[U].length&&(We[Zt++]=he[U][N]);for(N=0;N<Yt;N++)for(U=0;U<T;U++)We[Zt++]=Xt[U][N];return We}function x(m,C,v,g){let _;if(Array.isArray(m))_=f.fromArray(m);else if(typeof m=="string"){let H=C;if(!H){const ae=f.rawSplit(m);H=l.getBestVersionForData(ae,v)}_=f.fromString(m,H||40)}else throw new Error("Invalid data");const y=l.getBestVersionForData(_,v);if(!y)throw new Error("The amount of data is too big to be stored in a QR Code");if(!C)C=y;else if(C<y)throw new Error(`
158
+ `,document.body.appendChild(this.container))),this.container}show(e){const t=this.getContainer(e.position),r=document.createElement("kv-message");return r.setOptions(e),r.style.cssText="pointer-events: auto;",t.appendChild(r),r}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(r=>{r.remove()})}}const vt=()=>X.getInstance();window.createMessage=vt;let jn=class{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(o=>{try{o(e)}catch(s){console.error(`Error in event handler for type "${t}":`,s)}})}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 r=o=>{t(o),this.off(e,r)};this.on(e,r)}};const bt=new jn,Vn=n=>bt.emit(n),N=vt(),ie=()=>{const n=window.location.href,t=new URL(n).searchParams.get("redirect");if(t){const r=decodeURIComponent(t);window.open(r,"_self")}Vn({type:"login-success",data:{}})},On=async n=>{const{loginMethod:e,data:t}=n;switch(e){case"password":await Wn(t);break;case"phone":await Kn(t);break;case"wechat-mp":await Qn(t);break;case"wechat":await Jn(t);break;default:console.warn("未知的登录方式:",e)}},Wn=async n=>{console.log("使用用户名密码登录:",n);let e=!0;if(await q.checkLocalToken()&&(await q.checkLocalUser())?.username===n?.username&&(await q.getMe()).code===200&&(e=!1,console.log("已登录,跳过登录步骤"),N.success("已登录")),!e){ie();return}const r=await q.login({username:n.username,password:n.password});r.code===200?(console.log("登录成功"),N.success("登录成功"),ie()):N.error(`登录失败: ${r.message}`)},Kn=async n=>{console.log("使用手机号登录:",n)},Jn=async n=>{console.log("使用微信登录:",n)},Qn=async n=>{console.log("使用微信公众号登录:",n)},Gn=()=>{const n=new URL(window.location.href);n.searchParams.delete("code"),n.searchParams.delete("state"),window.history.replaceState({},document.title,n.toString())},Yn=async()=>{const n=new URL(window.location.href),e=n.searchParams.get("code");if(n.searchParams.get("state")?.includes?.("-")||!e)return;const r=await q.loginByWechat({code:e});r.code===200?(N.success("登录成功"),ie()):(N.error(r.message||"登录失败"),Gn())},Xn=async()=>{const n=new URL(window.location.href),e=n.searchParams.get("state"),[t,r]=e?e.split("-"):[null,null];if(console.log("检查微信公众号登录流程:",t,r,e),t==="1")er();else if(t==="2"){const o=n.searchParams.get("code"),s=await q.post({path:"wx",key:"mplogin",state:r,code:o});s.code===200?N.success("登录成功"):N.error(s.message||"登录失败"),Ct()}},Zn=()=>{const n=navigator.userAgent.toLowerCase();return/micromessenger/i.test(n)},Ct=(n=2e3)=>{if(!Zn()){setTimeout(()=>{window.close()},n);return}window.WeixinJSBridge?setTimeout(()=>{window.WeixinJSBridge.call("closeWindow")},n):setTimeout(()=>{window.close()},n)},er=async()=>{const n="https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect",e=ln,t=new URL(window.location.href),r=t.searchParams.get("state");let[o,s]=r?r.split("-"):[null,null];const i=new URL(t.pathname,t.origin);s="2-"+s;const c=encodeURIComponent(i.toString());document.body.innerHTML="<p>正在准备跳转到微信公众号授权页面...</p>";const a="snsapi_userinfo";if(!s){alert("Invalid state. Please try again later."),Ct();return}const l=n.replace("APPID",e).replace("REDIRECT_URI",c).replace("SCOPE",a).replace("STATE",s);setTimeout(()=>{window.location.href=l},100)};setTimeout(()=>{Xn()},100);const tr=async()=>{const n=await q.post({path:"wx",key:"get-qrcode-ticket"});return n.code!==200?(N.error("获取二维码失败"),null):n?.data},nr=n=>{let e=!0;const t=async()=>{const s=await q.post({path:"wx",key:"check-qrcode-login",payload:{ticket:n}});s.code===200?(N.success("登录成功"),clearTimeout(r),ie()):(s.code===401?console.log("等待扫码登录..."):console.log("扫码登录状态:",s),e&&setTimeout(t,2e3))},r=setTimeout(t,2e3);return()=>{console.log("停止检测扫码登录状态"),clearTimeout(r),e=!1}},At=async n=>{let e=n?.redirect_uri;const{appid:t}=n||{};e||(e=window.location.href);const r=new URL(e);if(r.searchParams.delete("code"),r.searchParams.delete("state"),e=r.toString(),console.log("redirect_uri",e),!t){console.error("appid is not cant be empty");return}const o=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"}),s=document.querySelector("#weixinLogin");if(s){const i=s.querySelector("iframe");i&&(i.style.height="300px")}return o};function rr(n){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")){At(n);return}const t=document.body.appendChild(e);t.onload=function(){At(n)}}function or(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Z={},Ae,Tt;function sr(){return Tt||(Tt=1,Ae=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Ae}var Te={},H={},Et;function K(){if(Et)return H;Et=1;let n;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 H.getSymbolSize=function(r){if(!r)throw new Error('"version" cannot be null or undefined');if(r<1||r>40)throw new Error('"version" should be in range from 1 to 40');return r*4+17},H.getSymbolTotalCodewords=function(r){return e[r]},H.getBCHDigit=function(t){let r=0;for(;t!==0;)r++,t>>>=1;return r},H.setToSJISFunction=function(r){if(typeof r!="function")throw new Error('"toSJISFunc" is not a valid function.');n=r},H.isKanjiModeEnabled=function(){return typeof n<"u"},H.toSJIS=function(r){return n(r)},H}var Ee={},_t;function _e(){return _t||(_t=1,(function(n){n.L={bit:1},n.M={bit:0},n.Q={bit:3},n.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 n.L;case"m":case"medium":return n.M;case"q":case"quartile":return n.Q;case"h":case"high":return n.H;default:throw new Error("Unknown EC Level: "+t)}}n.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},n.from=function(r,o){if(n.isValid(r))return r;try{return e(r)}catch{return o}}})(Ee)),Ee}var ke,kt;function ir(){if(kt)return ke;kt=1;function n(){this.buffer=[],this.length=0}return n.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 r=0;r<t;r++)this.putBit((e>>>t-r-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++}},ke=n,ke}var xe,xt;function ar(){if(xt)return xe;xt=1;function n(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 n.prototype.set=function(e,t,r,o){const s=e*this.size+t;this.data[s]=r,o&&(this.reservedBit[s]=!0)},n.prototype.get=function(e,t){return this.data[e*this.size+t]},n.prototype.xor=function(e,t,r){this.data[e*this.size+t]^=r},n.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},xe=n,xe}var Re={},Rt;function cr(){return Rt||(Rt=1,(function(n){const e=K().getSymbolSize;n.getRowColCoords=function(r){if(r===1)return[];const o=Math.floor(r/7)+2,s=e(r),i=s===145?26:Math.ceil((s-13)/(2*o-2))*2,c=[s-7];for(let a=1;a<o-1;a++)c[a]=c[a-1]-i;return c.push(6),c.reverse()},n.getPositions=function(r){const o=[],s=n.getRowColCoords(r),i=s.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||o.push([s[c],s[a]]);return o}})(Re)),Re}var Se={},St;function lr(){if(St)return Se;St=1;const n=K().getSymbolSize,e=7;return Se.getPositions=function(r){const o=n(r);return[[0,0],[o-e,0],[0,o-e]]},Se}var Me={},Mt;function ur(){return Mt||(Mt=1,(function(n){n.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};n.isValid=function(o){return o!=null&&o!==""&&!isNaN(o)&&o>=0&&o<=7},n.from=function(o){return n.isValid(o)?parseInt(o,10):void 0},n.getPenaltyN1=function(o){const s=o.size;let i=0,c=0,a=0,l=null,u=null;for(let h=0;h<s;h++){c=a=0,l=u=null;for(let f=0;f<s;f++){let d=o.get(h,f);d===l?c++:(c>=5&&(i+=e.N1+(c-5)),l=d,c=1),d=o.get(f,h),d===u?a++:(a>=5&&(i+=e.N1+(a-5)),u=d,a=1)}c>=5&&(i+=e.N1+(c-5)),a>=5&&(i+=e.N1+(a-5))}return i},n.getPenaltyN2=function(o){const s=o.size;let i=0;for(let c=0;c<s-1;c++)for(let a=0;a<s-1;a++){const l=o.get(c,a)+o.get(c,a+1)+o.get(c+1,a)+o.get(c+1,a+1);(l===4||l===0)&&i++}return i*e.N2},n.getPenaltyN3=function(o){const s=o.size;let i=0,c=0,a=0;for(let l=0;l<s;l++){c=a=0;for(let u=0;u<s;u++)c=c<<1&2047|o.get(l,u),u>=10&&(c===1488||c===93)&&i++,a=a<<1&2047|o.get(u,l),u>=10&&(a===1488||a===93)&&i++}return i*e.N3},n.getPenaltyN4=function(o){let s=0;const i=o.data.length;for(let a=0;a<i;a++)s+=o.data[a];return Math.abs(Math.ceil(s*100/i/5)-10)*e.N4};function t(r,o,s){switch(r){case n.Patterns.PATTERN000:return(o+s)%2===0;case n.Patterns.PATTERN001:return o%2===0;case n.Patterns.PATTERN010:return s%3===0;case n.Patterns.PATTERN011:return(o+s)%3===0;case n.Patterns.PATTERN100:return(Math.floor(o/2)+Math.floor(s/3))%2===0;case n.Patterns.PATTERN101:return o*s%2+o*s%3===0;case n.Patterns.PATTERN110:return(o*s%2+o*s%3)%2===0;case n.Patterns.PATTERN111:return(o*s%3+(o+s)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}n.applyMask=function(o,s){const i=s.size;for(let c=0;c<i;c++)for(let a=0;a<i;a++)s.isReserved(a,c)||s.xor(a,c,t(o,a,c))},n.getBestMask=function(o,s){const i=Object.keys(n.Patterns).length;let c=0,a=1/0;for(let l=0;l<i;l++){s(l),n.applyMask(l,o);const u=n.getPenaltyN1(o)+n.getPenaltyN2(o)+n.getPenaltyN3(o)+n.getPenaltyN4(o);n.applyMask(l,o),u<a&&(a=u,c=l)}return c}})(Me)),Me}var he={},Bt;function Lt(){if(Bt)return he;Bt=1;const n=_e(),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 he.getBlocksCount=function(o,s){switch(s){case n.L:return e[(o-1)*4+0];case n.M:return e[(o-1)*4+1];case n.Q:return e[(o-1)*4+2];case n.H:return e[(o-1)*4+3];default:return}},he.getTotalCodewordsCount=function(o,s){switch(s){case n.L:return t[(o-1)*4+0];case n.M:return t[(o-1)*4+1];case n.Q:return t[(o-1)*4+2];case n.H:return t[(o-1)*4+3];default:return}},he}var Be={},ae={},It;function hr(){if(It)return ae;It=1;const n=new Uint8Array(512),e=new Uint8Array(256);return(function(){let r=1;for(let o=0;o<255;o++)n[o]=r,e[r]=o,r<<=1,r&256&&(r^=285);for(let o=255;o<512;o++)n[o]=n[o-255]})(),ae.log=function(r){if(r<1)throw new Error("log("+r+")");return e[r]},ae.exp=function(r){return n[r]},ae.mul=function(r,o){return r===0||o===0?0:n[e[r]+e[o]]},ae}var $t;function dr(){return $t||($t=1,(function(n){const e=hr();n.mul=function(r,o){const s=new Uint8Array(r.length+o.length-1);for(let i=0;i<r.length;i++)for(let c=0;c<o.length;c++)s[i+c]^=e.mul(r[i],o[c]);return s},n.mod=function(r,o){let s=new Uint8Array(r);for(;s.length-o.length>=0;){const i=s[0];for(let a=0;a<o.length;a++)s[a]^=e.mul(o[a],i);let c=0;for(;c<s.length&&s[c]===0;)c++;s=s.slice(c)}return s},n.generateECPolynomial=function(r){let o=new Uint8Array([1]);for(let s=0;s<r;s++)o=n.mul(o,new Uint8Array([1,e.exp(s)]));return o}})(Be)),Be}var Le,Pt;function fr(){if(Pt)return Le;Pt=1;const n=dr();function e(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}return e.prototype.initialize=function(r){this.degree=r,this.genPoly=n.generateECPolynomial(this.degree)},e.prototype.encode=function(r){if(!this.genPoly)throw new Error("Encoder not initialized");const o=new Uint8Array(r.length+this.degree);o.set(r);const s=n.mod(o,this.genPoly),i=this.degree-s.length;if(i>0){const c=new Uint8Array(this.degree);return c.set(s,i),c}return s},Le=e,Le}var Ie={},$e={},Pe={},qt;function Nt(){return qt||(qt=1,Pe.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}),Pe}var P={},Dt;function Ut(){if(Dt)return P;Dt=1;const n="[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 r="(?:(?![A-Z0-9 $%*+\\-./:]|"+t+`)(?:.|[\r
159
+ ]))+`;P.KANJI=new RegExp(t,"g"),P.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),P.BYTE=new RegExp(r,"g"),P.NUMERIC=new RegExp(n,"g"),P.ALPHANUMERIC=new RegExp(e,"g");const o=new RegExp("^"+t+"$"),s=new RegExp("^"+n+"$"),i=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return P.testKanji=function(a){return o.test(a)},P.testNumeric=function(a){return s.test(a)},P.testAlphanumeric=function(a){return i.test(a)},P}var Ft;function J(){return Ft||(Ft=1,(function(n){const e=Nt(),t=Ut();n.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},n.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},n.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},n.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},n.MIXED={bit:-1},n.getCharCountIndicator=function(s,i){if(!s.ccBits)throw new Error("Invalid mode: "+s);if(!e.isValid(i))throw new Error("Invalid version: "+i);return i>=1&&i<10?s.ccBits[0]:i<27?s.ccBits[1]:s.ccBits[2]},n.getBestModeForData=function(s){return t.testNumeric(s)?n.NUMERIC:t.testAlphanumeric(s)?n.ALPHANUMERIC:t.testKanji(s)?n.KANJI:n.BYTE},n.toString=function(s){if(s&&s.id)return s.id;throw new Error("Invalid mode")},n.isValid=function(s){return s&&s.bit&&s.ccBits};function r(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"numeric":return n.NUMERIC;case"alphanumeric":return n.ALPHANUMERIC;case"kanji":return n.KANJI;case"byte":return n.BYTE;default:throw new Error("Unknown mode: "+o)}}n.from=function(s,i){if(n.isValid(s))return s;try{return r(s)}catch{return i}}})($e)),$e}var zt;function gr(){return zt||(zt=1,(function(n){const e=K(),t=Lt(),r=_e(),o=J(),s=Nt(),i=7973,c=e.getBCHDigit(i);function a(f,d,g){for(let p=1;p<=40;p++)if(d<=n.getCapacity(p,g,f))return p}function l(f,d){return o.getCharCountIndicator(f,d)+4}function u(f,d){let g=0;return f.forEach(function(p){const m=l(p.mode,d);g+=m+p.getBitsLength()}),g}function h(f,d){for(let g=1;g<=40;g++)if(u(f,g)<=n.getCapacity(g,d,o.MIXED))return g}n.from=function(d,g){return s.isValid(d)?parseInt(d,10):g},n.getCapacity=function(d,g,p){if(!s.isValid(d))throw new Error("Invalid QR Code version");typeof p>"u"&&(p=o.BYTE);const m=e.getSymbolTotalCodewords(d),y=t.getTotalCodewordsCount(d,g),E=(m-y)*8;if(p===o.MIXED)return E;const w=E-l(p,d);switch(p){case o.NUMERIC:return Math.floor(w/10*3);case o.ALPHANUMERIC:return Math.floor(w/11*2);case o.KANJI:return Math.floor(w/13);case o.BYTE:default:return Math.floor(w/8)}},n.getBestVersionForData=function(d,g){let p;const m=r.from(g,r.M);if(Array.isArray(d)){if(d.length>1)return h(d,m);if(d.length===0)return 1;p=d[0]}else p=d;return a(p.mode,p.getLength(),m)},n.getEncodedBits=function(d){if(!s.isValid(d)||d<7)throw new Error("Invalid QR Code version");let g=d<<12;for(;e.getBCHDigit(g)-c>=0;)g^=i<<e.getBCHDigit(g)-c;return d<<12|g}})(Ie)),Ie}var qe={},Ht;function mr(){if(Ht)return qe;Ht=1;const n=K(),e=1335,t=21522,r=n.getBCHDigit(e);return qe.getEncodedBits=function(s,i){const c=s.bit<<3|i;let a=c<<10;for(;n.getBCHDigit(a)-r>=0;)a^=e<<n.getBCHDigit(a)-r;return(c<<10|a)^t},qe}var Ne={},De,jt;function pr(){if(jt)return De;jt=1;const n=J();function e(t){this.mode=n.NUMERIC,this.data=t.toString()}return e.getBitsLength=function(r){return 10*Math.floor(r/3)+(r%3?r%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(r){let o,s,i;for(o=0;o+3<=this.data.length;o+=3)s=this.data.substr(o,3),i=parseInt(s,10),r.put(i,10);const c=this.data.length-o;c>0&&(s=this.data.substr(o),i=parseInt(s,10),r.put(i,c*3+1))},De=e,De}var Ue,Vt;function wr(){if(Vt)return Ue;Vt=1;const n=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(r){this.mode=n.ALPHANUMERIC,this.data=r}return t.getBitsLength=function(o){return 11*Math.floor(o/2)+6*(o%2)},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(o){let s;for(s=0;s+2<=this.data.length;s+=2){let i=e.indexOf(this.data[s])*45;i+=e.indexOf(this.data[s+1]),o.put(i,11)}this.data.length%2&&o.put(e.indexOf(this.data[s]),6)},Ue=t,Ue}var Fe,Ot;function yr(){if(Ot)return Fe;Ot=1;const n=J();function e(t){this.mode=n.BYTE,typeof t=="string"?this.data=new TextEncoder().encode(t):this.data=new Uint8Array(t)}return e.getBitsLength=function(r){return r*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 r=0,o=this.data.length;r<o;r++)t.put(this.data[r],8)},Fe=e,Fe}var ze,Wt;function vr(){if(Wt)return ze;Wt=1;const n=J(),e=K();function t(r){this.mode=n.KANJI,this.data=r}return t.getBitsLength=function(o){return o*13},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(r){let o;for(o=0;o<this.data.length;o++){let s=e.toSJIS(this.data[o]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[o]+`
160
+ Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),r.put(s,13)}},ze=t,ze}var He={exports:{}},Kt;function br(){return Kt||(Kt=1,(function(n){var e={single_source_shortest_paths:function(t,r,o){var s={},i={};i[r]=0;var c=e.PriorityQueue.make();c.push(r,0);for(var a,l,u,h,f,d,g,p,m;!c.empty();){a=c.pop(),l=a.value,h=a.cost,f=t[l]||{};for(u in f)f.hasOwnProperty(u)&&(d=f[u],g=h+d,p=i[u],m=typeof i[u]>"u",(m||p>g)&&(i[u]=g,c.push(u,g),s[u]=l))}if(typeof o<"u"&&typeof i[o]>"u"){var y=["Could not find a path from ",r," to ",o,"."].join("");throw new Error(y)}return s},extract_shortest_path_from_predecessor_list:function(t,r){for(var o=[],s=r;s;)o.push(s),t[s],s=t[s];return o.reverse(),o},find_path:function(t,r,o){var s=e.single_source_shortest_paths(t,r,o);return e.extract_shortest_path_from_predecessor_list(s,o)},PriorityQueue:{make:function(t){var r=e.PriorityQueue,o={},s;t=t||{};for(s in r)r.hasOwnProperty(s)&&(o[s]=r[s]);return o.queue=[],o.sorter=t.sorter||r.default_sorter,o},default_sorter:function(t,r){return t.cost-r.cost},push:function(t,r){var o={value:t,cost:r};this.queue.push(o),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};n.exports=e})(He)),He.exports}var Jt;function Cr(){return Jt||(Jt=1,(function(n){const e=J(),t=pr(),r=wr(),o=yr(),s=vr(),i=Ut(),c=K(),a=br();function l(y){return unescape(encodeURIComponent(y)).length}function u(y,E,w){const x=[];let M;for(;(M=y.exec(w))!==null;)x.push({data:M[0],index:M.index,mode:E,length:M[0].length});return x}function h(y){const E=u(i.NUMERIC,e.NUMERIC,y),w=u(i.ALPHANUMERIC,e.ALPHANUMERIC,y);let x,M;return c.isKanjiModeEnabled()?(x=u(i.BYTE,e.BYTE,y),M=u(i.KANJI,e.KANJI,y)):(x=u(i.BYTE_KANJI,e.BYTE,y),M=[]),E.concat(w,x,M).sort(function(_,T){return _.index-T.index}).map(function(_){return{data:_.data,mode:_.mode,length:_.length}})}function f(y,E){switch(E){case e.NUMERIC:return t.getBitsLength(y);case e.ALPHANUMERIC:return r.getBitsLength(y);case e.KANJI:return s.getBitsLength(y);case e.BYTE:return o.getBitsLength(y)}}function d(y){return y.reduce(function(E,w){const x=E.length-1>=0?E[E.length-1]:null;return x&&x.mode===w.mode?(E[E.length-1].data+=w.data,E):(E.push(w),E)},[])}function g(y){const E=[];for(let w=0;w<y.length;w++){const x=y[w];switch(x.mode){case e.NUMERIC:E.push([x,{data:x.data,mode:e.ALPHANUMERIC,length:x.length},{data:x.data,mode:e.BYTE,length:x.length}]);break;case e.ALPHANUMERIC:E.push([x,{data:x.data,mode:e.BYTE,length:x.length}]);break;case e.KANJI:E.push([x,{data:x.data,mode:e.BYTE,length:l(x.data)}]);break;case e.BYTE:E.push([{data:x.data,mode:e.BYTE,length:l(x.data)}])}}return E}function p(y,E){const w={},x={start:{}};let M=["start"];for(let b=0;b<y.length;b++){const _=y[b],T=[];for(let v=0;v<_.length;v++){const R=_[v],C=""+b+v;T.push(C),w[C]={node:R,lastCount:0},x[C]={};for(let k=0;k<M.length;k++){const A=M[k];w[A]&&w[A].node.mode===R.mode?(x[A][C]=f(w[A].lastCount+R.length,R.mode)-f(w[A].lastCount,R.mode),w[A].lastCount+=R.length):(w[A]&&(w[A].lastCount=R.length),x[A][C]=f(R.length,R.mode)+4+e.getCharCountIndicator(R.mode,E))}}M=T}for(let b=0;b<M.length;b++)x[M[b]].end=0;return{map:x,table:w}}function m(y,E){let w;const x=e.getBestModeForData(y);if(w=e.from(E,x),w!==e.BYTE&&w.bit<x.bit)throw new Error('"'+y+'" cannot be encoded with mode '+e.toString(w)+`.
161
+ Suggested mode is: `+e.toString(x));switch(w===e.KANJI&&!c.isKanjiModeEnabled()&&(w=e.BYTE),w){case e.NUMERIC:return new t(y);case e.ALPHANUMERIC:return new r(y);case e.KANJI:return new s(y);case e.BYTE:return new o(y)}}n.fromArray=function(E){return E.reduce(function(w,x){return typeof x=="string"?w.push(m(x,null)):x.data&&w.push(m(x.data,x.mode)),w},[])},n.fromString=function(E,w){const x=h(E,c.isKanjiModeEnabled()),M=g(x),b=p(M,w),_=a.find_path(b.map,"start","end"),T=[];for(let v=1;v<_.length-1;v++)T.push(b.table[_[v]].node);return n.fromArray(d(T))},n.rawSplit=function(E){return n.fromArray(h(E,c.isKanjiModeEnabled()))}})(Ne)),Ne}var Qt;function Ar(){if(Qt)return Te;Qt=1;const n=K(),e=_e(),t=ir(),r=ar(),o=cr(),s=lr(),i=ur(),c=Lt(),a=fr(),l=gr(),u=mr(),h=J(),f=Cr();function d(b,_){const T=b.size,v=s.getPositions(_);for(let R=0;R<v.length;R++){const C=v[R][0],k=v[R][1];for(let A=-1;A<=7;A++)if(!(C+A<=-1||T<=C+A))for(let S=-1;S<=7;S++)k+S<=-1||T<=k+S||(A>=0&&A<=6&&(S===0||S===6)||S>=0&&S<=6&&(A===0||A===6)||A>=2&&A<=4&&S>=2&&S<=4?b.set(C+A,k+S,!0,!0):b.set(C+A,k+S,!1,!0))}}function g(b){const _=b.size;for(let T=8;T<_-8;T++){const v=T%2===0;b.set(T,6,v,!0),b.set(6,T,v,!0)}}function p(b,_){const T=o.getPositions(_);for(let v=0;v<T.length;v++){const R=T[v][0],C=T[v][1];for(let k=-2;k<=2;k++)for(let A=-2;A<=2;A++)k===-2||k===2||A===-2||A===2||k===0&&A===0?b.set(R+k,C+A,!0,!0):b.set(R+k,C+A,!1,!0)}}function m(b,_){const T=b.size,v=l.getEncodedBits(_);let R,C,k;for(let A=0;A<18;A++)R=Math.floor(A/3),C=A%3+T-8-3,k=(v>>A&1)===1,b.set(R,C,k,!0),b.set(C,R,k,!0)}function y(b,_,T){const v=b.size,R=u.getEncodedBits(_,T);let C,k;for(C=0;C<15;C++)k=(R>>C&1)===1,C<6?b.set(C,8,k,!0):C<8?b.set(C+1,8,k,!0):b.set(v-15+C,8,k,!0),C<8?b.set(8,v-C-1,k,!0):C<9?b.set(8,15-C-1+1,k,!0):b.set(8,15-C-1,k,!0);b.set(v-8,8,1,!0)}function E(b,_){const T=b.size;let v=-1,R=T-1,C=7,k=0;for(let A=T-1;A>0;A-=2)for(A===6&&A--;;){for(let S=0;S<2;S++)if(!b.isReserved(R,A-S)){let j=!1;k<_.length&&(j=(_[k]>>>C&1)===1),b.set(R,A-S,j),C--,C===-1&&(k++,C=7)}if(R+=v,R<0||T<=R){R-=v,v=-v;break}}}function w(b,_,T){const v=new t;T.forEach(function(S){v.put(S.mode.bit,4),v.put(S.getLength(),h.getCharCountIndicator(S.mode,b)),S.write(v)});const R=n.getSymbolTotalCodewords(b),C=c.getTotalCodewordsCount(b,_),k=(R-C)*8;for(v.getLengthInBits()+4<=k&&v.put(0,4);v.getLengthInBits()%8!==0;)v.putBit(0);const A=(k-v.getLengthInBits())/8;for(let S=0;S<A;S++)v.put(S%2?17:236,8);return x(v,b,_)}function x(b,_,T){const v=n.getSymbolTotalCodewords(_),R=c.getTotalCodewordsCount(_,T),C=v-R,k=c.getBlocksCount(_,T),A=v%k,S=k-A,j=Math.floor(v/k),ce=Math.floor(C/k),Nr=ce+1,un=j-ce,Dr=new a(un);let Je=0;const me=new Array(k),hn=new Array(k);let Qe=0;const Ur=new Uint8Array(b.buffer);for(let ee=0;ee<k;ee++){const Ye=ee<S?ce:Nr;me[ee]=Ur.slice(Je,Je+Ye),hn[ee]=Dr.encode(me[ee]),Je+=Ye,Qe=Math.max(Qe,Ye)}const Ge=new Uint8Array(v);let dn=0,U,F;for(U=0;U<Qe;U++)for(F=0;F<k;F++)U<me[F].length&&(Ge[dn++]=me[F][U]);for(U=0;U<un;U++)for(F=0;F<k;F++)Ge[dn++]=hn[F][U];return Ge}function M(b,_,T,v){let R;if(Array.isArray(b))R=f.fromArray(b);else if(typeof b=="string"){let j=_;if(!j){const ce=f.rawSplit(b);j=l.getBestVersionForData(ce,T)}R=f.fromString(b,j||40)}else throw new Error("Invalid data");const C=l.getBestVersionForData(R,T);if(!C)throw new Error("The amount of data is too big to be stored in a QR Code");if(!_)_=C;else if(_<C)throw new Error(`
162
162
  The chosen QR Code version cannot contain this amount of data.
163
- Minimum version required to store current data is: `+y+`.
164
- `);const T=k(C,v,_),b=t.getSymbolSize(C),S=new n(b);return d(S,C),w(S),p(S,C),A(S,v,0),C>=7&&B(S,C),R(S,T),isNaN(g)&&(g=i.getBestMask(S,A.bind(null,S,v))),i.applyMask(g,S),A(S,v,g),{modules:S,version:C,errorCorrectionLevel:v,maskPattern:g,segments:_}}return be.create=function(C,v){if(typeof C>"u"||C==="")throw new Error("No input text");let g=e.M,_,y;return typeof v<"u"&&(g=e.from(v.errorCorrectionLevel,e.M),_=l.from(v.version),y=i.from(v.maskPattern),v.toSJISFunc&&t.setToSJISFunction(v.toSJISFunc)),x(C,_,g,y)},be}var Ue={},Fe={},Vt;function Wt(){return Vt||(Vt=1,(function(t){function e(r){if(typeof r=="number"&&(r=r.toString()),typeof r!="string")throw new Error("Color should be defined as hex string");let n=r.slice().replace("#","").split("");if(n.length<3||n.length===5||n.length>8)throw new Error("Invalid hex color: "+r);(n.length===3||n.length===4)&&(n=Array.prototype.concat.apply([],n.map(function(s){return[s,s]}))),n.length===6&&n.push("F","F");const o=parseInt(n.join(""),16);return{r:o>>24&255,g:o>>16&255,b:o>>8&255,a:o&255,hex:"#"+n.slice(0,6).join("")}}t.getOptions=function(n){n||(n={}),n.color||(n.color={});const o=typeof n.margin>"u"||n.margin===null||n.margin<0?4:n.margin,s=n.width&&n.width>=21?n.width:void 0,i=n.scale||4;return{width:s,scale:s?4:i,margin:o,color:{dark:e(n.color.dark||"#000000ff"),light:e(n.color.light||"#ffffffff")},type:n.type,rendererOpts:n.rendererOpts||{}}},t.getScale=function(n,o){return o.width&&o.width>=n+o.margin*2?o.width/(n+o.margin*2):o.scale},t.getImageWidth=function(n,o){const s=t.getScale(n,o);return Math.floor((n+o.margin*2)*s)},t.qrToImageData=function(n,o,s){const i=o.modules.size,c=o.modules.data,a=t.getScale(i,s),l=Math.floor((i+s.margin*2)*a),u=s.margin*a,h=[s.color.light,s.color.dark];for(let f=0;f<l;f++)for(let d=0;d<l;d++){let w=(f*l+d)*4,p=s.color.light;if(f>=u&&d>=u&&f<l-u&&d<l-u){const B=Math.floor((f-u)/a),A=Math.floor((d-u)/a);p=h[c[B*i+A]?1:0]}n[w++]=p.r,n[w++]=p.g,n[w++]=p.b,n[w]=p.a}}})(Fe)),Fe}var Ot;function lr(){return Ot||(Ot=1,(function(t){const e=Wt();function r(o,s,i){o.clearRect(0,0,s.width,s.height),s.style||(s.style={}),s.height=i,s.width=i,s.style.height=i+"px",s.style.width=i+"px"}function n(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(s,i,c){let a=c,l=i;typeof a>"u"&&(!i||!i.getContext)&&(a=i,i=void 0),i||(l=n()),a=e.getOptions(a);const u=e.getImageWidth(s.modules.size,a),h=l.getContext("2d"),f=h.createImageData(u,u);return e.qrToImageData(f.data,s,a),r(h,l,u),h.putImageData(f,0,0),l},t.renderToDataURL=function(s,i,c){let a=c;typeof a>"u"&&(!i||!i.getContext)&&(a=i,i=void 0),a||(a={});const l=t.render(s,i,a),u=a.type||"image/png",h=a.rendererOpts||{};return l.toDataURL(u,h.quality)}})(Ue)),Ue}var ze={},Jt;function ur(){if(Jt)return ze;Jt=1;const t=Wt();function e(o,s){const i=o.a/255,c=s+'="'+o.hex+'"';return i<1?c+" "+s+'-opacity="'+i.toFixed(2).slice(1)+'"':c}function r(o,s,i){let c=o+s;return typeof i<"u"&&(c+=" "+i),c}function n(o,s,i){let c="",a=0,l=!1,u=0;for(let h=0;h<o.length;h++){const f=Math.floor(h%s),d=Math.floor(h/s);!f&&!l&&(l=!0),o[h]?(u++,h>0&&f>0&&o[h-1]||(c+=l?r("M",f+i,.5+d+i):r("m",a,0),a=0,l=!1),f+1<s&&o[h+1]||(c+=r("h",u),u=0)):a++}return c}return ze.render=function(s,i,c){const a=t.getOptions(i),l=s.modules.size,u=s.modules.data,h=l+a.margin*2,f=a.color.light.a?"<path "+e(a.color.light,"fill")+' d="M0 0h'+h+"v"+h+'H0z"/>':"",d="<path "+e(a.color.dark,"stroke")+' d="'+n(u,l,a.margin)+'"/>',w='viewBox="0 0 '+h+" "+h+'"',B='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+w+' shape-rendering="crispEdges">'+f+d+`</svg>
165
- `;return typeof c=="function"&&c(null,B),B},ze}var Kt;function hr(){if(Kt)return X;Kt=1;const t=Wn(),e=cr(),r=lr(),n=ur();function o(s,i,c,a,l){const u=[].slice.call(arguments,1),h=u.length,f=typeof u[h-1]=="function";if(!f&&!t())throw new Error("Callback required as last argument");if(f){if(h<2)throw new Error("Too few arguments provided");h===2?(l=c,c=i,i=a=void 0):h===3&&(i.getContext&&typeof l>"u"?(l=a,a=void 0):(l=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(d,w){try{const p=e.create(c,a);d(s(p,i,a))}catch(p){w(p)}})}try{const d=e.create(c,a);l(null,s(d,i,a))}catch(d){l(d)}}return X.create=e.create,X.toCanvas=o.bind(null,r.render),X.toDataURL=o.bind(null,r.renderToDataURL),X.toString=o.bind(null,function(s,i,c){return n.render(s,c)}),X}var dr=hr();const fr=Vn(dr),gr=t=>{var e={errorCorrectionLevel:"H",type:"image/jpeg",margin:1,width:300};let r=null;const n=async a=>{const l=new URL(window.location.href),u=new URL(l.pathname,l.origin);u.searchParams.set("state","1-"+a),console.log("生成登录二维码链接:",u.toString());var h=t||document.getElementById("qrcode");await fr.toDataURL(h,u.toString(),e)},o=async a=>{const l=await fetch(`/api/router?path=wx&key=checkLogin&state=${a}`).then(u=>u.json());if(l.code===200){console.log(l);const u=l.data;u&&(localStorage.setItem("token",u.accessToken),await q.setLoginToken(u)),c(),setTimeout(()=>{se()},1e3)}else r=setTimeout(()=>{o(a),console.log("继续检测登录状态")},2e3)},s=Math.random().toString(36).substring(2,15);n(s),o(s);const i=setInterval(()=>{const a=Math.random().toString(36).substring(2,15);clearTimeout(r),n(a),o(a),console.log("更新二维码")},9e4),c=()=>{clearTimeout(r),clearInterval(i),console.log("停止检测登录状态")};return{createQrcode:n,clear:c}},Qt="wxff97d569b1db16b6",He={pwd:'<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>',phone:'<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>',wxmpSvg:'<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>',wxOpenSvg:'<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>'},pr=[{id:"password",name:"密码登录",icon:"pwd"},{id:"wechat",name:"微信登录",icon:"wxmpSvg",appid:"wx9378885c8390e09b"},{id:"wechat-mp",name:"微信公众号",icon:"wxOpenSvg",appid:Qt},{id:"wechat-mp-ticket",name:"微信公众号",icon:"wxOpenSvg"},{id:"phone",name:"手机号登录",icon:"phone"}],Gt=()=>{const t=window.location.hostname;let e=[];switch(t){case"kevisual.xiongxiao.me":e=["password","wechat-mp"];break;case"kevisual.cn":e=["password","wechat","wechat-mp-ticket"];break;default:e=["password","phone","wechat","wechat-mp","wechat-mp-ticket"];break}return pr.filter(r=>e.includes(r.id))};console.log("可用登录方式:",Gt().map(t=>t.name).join(", "));class mr extends HTMLElement{selectedMethod="password";loginMethods=Gt();setLoginMethods(e){this.loginMethods=e,this.render()}constructor(){super()}connectedCallback(){this.attachShadow({mode:"open"}),this.render(),this.bindEvents(),Dn()}#e=null;selectLoginMethod(e){this.selectedMethod=e,this.render(),this.#e&&(this.#e(),this.#e=null)}getMethodData(e){return this.loginMethods.find(r=>r.id===e)}bindEvents(){this.shadowRoot&&(this.shadowRoot.addEventListener("click",e=>{const n=e.target.closest(".login-method");if(n){const o=n.getAttribute("data-method");o&&this.selectLoginMethod(o)}}),this.shadowRoot.addEventListener("submit",e=>{const r=e.target;r&&r.id==="loginForm"&&(e.preventDefault(),this.handleLogin())}))}handleLogin(){const e=this.getFormData();xn({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"),r=this.shadowRoot.querySelector("#password");return{username:e?.value||"",password:r?.value||""};case"phone":const n=this.shadowRoot.querySelector("#phone"),o=this.shadowRoot.querySelector("#code");return{phone:n?.value||"",code:o?.value||""};case"wechat":return{wechatCode:"mock_wechat_code"};case"wechat-mp":return{wechatMpCode:"mock_wechat_mp_code"};default:return{}}}renderPasswordForm(){return L`
163
+ Minimum version required to store current data is: `+C+`.
164
+ `);const k=w(_,T,R),A=n.getSymbolSize(_),S=new r(A);return d(S,_),g(S),p(S,_),y(S,T,0),_>=7&&m(S,_),E(S,k),isNaN(v)&&(v=i.getBestMask(S,y.bind(null,S,T))),i.applyMask(v,S),y(S,T,v),{modules:S,version:_,errorCorrectionLevel:T,maskPattern:v,segments:R}}return Te.create=function(_,T){if(typeof _>"u"||_==="")throw new Error("No input text");let v=e.M,R,C;return typeof T<"u"&&(v=e.from(T.errorCorrectionLevel,e.M),R=l.from(T.version),C=i.from(T.maskPattern),T.toSJISFunc&&n.setToSJISFunction(T.toSJISFunc)),M(_,R,v,C)},Te}var je={},Ve={},Gt;function Yt(){return Gt||(Gt=1,(function(n){function e(t){if(typeof t=="number"&&(t=t.toString()),typeof t!="string")throw new Error("Color should be defined as hex string");let r=t.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+t);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(s){return[s,s]}))),r.length===6&&r.push("F","F");const o=parseInt(r.join(""),16);return{r:o>>24&255,g:o>>16&255,b:o>>8&255,a:o&255,hex:"#"+r.slice(0,6).join("")}}n.getOptions=function(r){r||(r={}),r.color||(r.color={});const o=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,s=r.width&&r.width>=21?r.width:void 0,i=r.scale||4;return{width:s,scale:s?4:i,margin:o,color:{dark:e(r.color.dark||"#000000ff"),light:e(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},n.getScale=function(r,o){return o.width&&o.width>=r+o.margin*2?o.width/(r+o.margin*2):o.scale},n.getImageWidth=function(r,o){const s=n.getScale(r,o);return Math.floor((r+o.margin*2)*s)},n.qrToImageData=function(r,o,s){const i=o.modules.size,c=o.modules.data,a=n.getScale(i,s),l=Math.floor((i+s.margin*2)*a),u=s.margin*a,h=[s.color.light,s.color.dark];for(let f=0;f<l;f++)for(let d=0;d<l;d++){let g=(f*l+d)*4,p=s.color.light;if(f>=u&&d>=u&&f<l-u&&d<l-u){const m=Math.floor((f-u)/a),y=Math.floor((d-u)/a);p=h[c[m*i+y]?1:0]}r[g++]=p.r,r[g++]=p.g,r[g++]=p.b,r[g]=p.a}}})(Ve)),Ve}var Xt;function Tr(){return Xt||(Xt=1,(function(n){const e=Yt();function t(o,s,i){o.clearRect(0,0,s.width,s.height),s.style||(s.style={}),s.height=i,s.width=i,s.style.height=i+"px",s.style.width=i+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}n.render=function(s,i,c){let a=c,l=i;typeof a>"u"&&(!i||!i.getContext)&&(a=i,i=void 0),i||(l=r()),a=e.getOptions(a);const u=e.getImageWidth(s.modules.size,a),h=l.getContext("2d"),f=h.createImageData(u,u);return e.qrToImageData(f.data,s,a),t(h,l,u),h.putImageData(f,0,0),l},n.renderToDataURL=function(s,i,c){let a=c;typeof a>"u"&&(!i||!i.getContext)&&(a=i,i=void 0),a||(a={});const l=n.render(s,i,a),u=a.type||"image/png",h=a.rendererOpts||{};return l.toDataURL(u,h.quality)}})(je)),je}var Oe={},Zt;function Er(){if(Zt)return Oe;Zt=1;const n=Yt();function e(o,s){const i=o.a/255,c=s+'="'+o.hex+'"';return i<1?c+" "+s+'-opacity="'+i.toFixed(2).slice(1)+'"':c}function t(o,s,i){let c=o+s;return typeof i<"u"&&(c+=" "+i),c}function r(o,s,i){let c="",a=0,l=!1,u=0;for(let h=0;h<o.length;h++){const f=Math.floor(h%s),d=Math.floor(h/s);!f&&!l&&(l=!0),o[h]?(u++,h>0&&f>0&&o[h-1]||(c+=l?t("M",f+i,.5+d+i):t("m",a,0),a=0,l=!1),f+1<s&&o[h+1]||(c+=t("h",u),u=0)):a++}return c}return Oe.render=function(s,i,c){const a=n.getOptions(i),l=s.modules.size,u=s.modules.data,h=l+a.margin*2,f=a.color.light.a?"<path "+e(a.color.light,"fill")+' d="M0 0h'+h+"v"+h+'H0z"/>':"",d="<path "+e(a.color.dark,"stroke")+' d="'+r(u,l,a.margin)+'"/>',g='viewBox="0 0 '+h+" "+h+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+g+' shape-rendering="crispEdges">'+f+d+`</svg>
165
+ `;return typeof c=="function"&&c(null,m),m},Oe}var en;function _r(){if(en)return Z;en=1;const n=sr(),e=Ar(),t=Tr(),r=Er();function o(s,i,c,a,l){const u=[].slice.call(arguments,1),h=u.length,f=typeof u[h-1]=="function";if(!f&&!n())throw new Error("Callback required as last argument");if(f){if(h<2)throw new Error("Too few arguments provided");h===2?(l=c,c=i,i=a=void 0):h===3&&(i.getContext&&typeof l>"u"?(l=a,a=void 0):(l=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(d,g){try{const p=e.create(c,a);d(s(p,i,a))}catch(p){g(p)}})}try{const d=e.create(c,a);l(null,s(d,i,a))}catch(d){l(d)}}return Z.create=e.create,Z.toCanvas=o.bind(null,t.render),Z.toDataURL=o.bind(null,t.renderToDataURL),Z.toString=o.bind(null,function(s,i,c){return r.render(s,c)}),Z}var kr=_r();const xr=or(kr),Rr=n=>{var e={errorCorrectionLevel:"H",type:"image/jpeg",margin:1,width:300};let t=null;const r=async a=>{const l=new URL(window.location.href),u=new URL(l.pathname,l.origin);u.searchParams.set("state","1-"+a),console.log("生成登录二维码链接:",u.toString());var h=n||document.getElementById("qrcode");await xr.toDataURL(h,u.toString(),e)},o=async a=>{const l=await fetch(`/api/router?path=wx&key=checkLogin&state=${a}`).then(u=>u.json());if(l.code===200){console.log(l);const u=l.data;u&&(localStorage.setItem("token",u.accessToken),await q.setLoginToken(u)),c(),setTimeout(()=>{ie()},1e3)}else t=setTimeout(()=>{o(a),console.log("继续检测登录状态")},2e3)},s=Math.random().toString(36).substring(2,15);r(s),o(s);const i=setInterval(()=>{const a=Math.random().toString(36).substring(2,15);clearTimeout(t),r(a),o(a),console.log("更新二维码")},9e4),c=()=>{clearTimeout(t),clearInterval(i),console.log("停止检测登录状态")};return{createQrcode:r,clear:c}};function Sr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var We={exports:{}},tn;function Mr(){return tn||(tn=1,(function(n){var e=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function o(a,l,u){this.fn=a,this.context=l,this.once=u||!1}function s(a,l,u,h,f){if(typeof u!="function")throw new TypeError("The listener must be a function");var d=new o(u,h||a,f),g=t?t+l:l;return a._events[g]?a._events[g].fn?a._events[g]=[a._events[g],d]:a._events[g].push(d):(a._events[g]=d,a._eventsCount++),a}function i(a,l){--a._eventsCount===0?a._events=new r:delete a._events[l]}function c(){this._events=new r,this._eventsCount=0}c.prototype.eventNames=function(){var l=[],u,h;if(this._eventsCount===0)return l;for(h in u=this._events)e.call(u,h)&&l.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(u)):l},c.prototype.listeners=function(l){var u=t?t+l:l,h=this._events[u];if(!h)return[];if(h.fn)return[h.fn];for(var f=0,d=h.length,g=new Array(d);f<d;f++)g[f]=h[f].fn;return g},c.prototype.listenerCount=function(l){var u=t?t+l:l,h=this._events[u];return h?h.fn?1:h.length:0},c.prototype.emit=function(l,u,h,f,d,g){var p=t?t+l:l;if(!this._events[p])return!1;var m=this._events[p],y=arguments.length,E,w;if(m.fn){switch(m.once&&this.removeListener(l,m.fn,void 0,!0),y){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,u),!0;case 3:return m.fn.call(m.context,u,h),!0;case 4:return m.fn.call(m.context,u,h,f),!0;case 5:return m.fn.call(m.context,u,h,f,d),!0;case 6:return m.fn.call(m.context,u,h,f,d,g),!0}for(w=1,E=new Array(y-1);w<y;w++)E[w-1]=arguments[w];m.fn.apply(m.context,E)}else{var x=m.length,M;for(w=0;w<x;w++)switch(m[w].once&&this.removeListener(l,m[w].fn,void 0,!0),y){case 1:m[w].fn.call(m[w].context);break;case 2:m[w].fn.call(m[w].context,u);break;case 3:m[w].fn.call(m[w].context,u,h);break;case 4:m[w].fn.call(m[w].context,u,h,f);break;default:if(!E)for(M=1,E=new Array(y-1);M<y;M++)E[M-1]=arguments[M];m[w].fn.apply(m[w].context,E)}}return!0},c.prototype.on=function(l,u,h){return s(this,l,u,h,!1)},c.prototype.once=function(l,u,h){return s(this,l,u,h,!0)},c.prototype.removeListener=function(l,u,h,f){var d=t?t+l:l;if(!this._events[d])return this;if(!u)return i(this,d),this;var g=this._events[d];if(g.fn)g.fn===u&&(!f||g.once)&&(!h||g.context===h)&&i(this,d);else{for(var p=0,m=[],y=g.length;p<y;p++)(g[p].fn!==u||f&&!g[p].once||h&&g[p].context!==h)&&m.push(g[p]);m.length?this._events[d]=m.length===1?m[0]:m:i(this,d)}return this},c.prototype.removeAllListeners=function(l){var u;return l?(u=t?t+l:l,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=t,c.EventEmitter=c,n.exports=c})(We)),We.exports}var Br=Mr(),Lr=Sr(Br),nn=n=>{const e=n.timeout||3e5,t=n.interval||1e3,r=n?.checkSuccess||(()=>!0),o=n.signal;return new Promise(async(s,i)=>{let c,a=setTimeout(()=>{clearTimeout(c),s({code:500,message:"timeout"})},e);const l=n.fn||(()=>!0),u=async()=>{if(o?.aborted)return clearInterval(c),clearTimeout(a),s({code:499,message:"operation cancelled"});const h=await l();r(h)?(clearInterval(c),clearTimeout(a),s({code:200,data:h})):setTimeout(()=>{u()},t)};o&&o.addEventListener("abort",()=>{clearInterval(c),clearTimeout(a),s({code:499,message:"operation cancelled"})}),u()})};class rn{modules=new Map;event;loading;static reRunFn=nn;timeout=300*1e3;constructor(){this.event=new Lr,this.loading=!1}listenKey(e,t){const r=t?.timeout??this.timeout;return new Promise(o=>{const s=setTimeout(()=>{this.event.removeListener(e,i),o({code:500,message:"timeout"})},r),i=c=>{if(clearTimeout(s),c)return o({code:500,message:c});const a=this.modules.get(e);a?.loadSuccessClear&&this.remove(e),o({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 s=t?.isExist??!0,i=t?.timeout??this.timeout;return s?await this.listenKey(e,{timeout:i}):{code:404}}const o=this.modules.get(e);return o?.status==="loaded"?{code:200,data:o.modules}:o?.status==="loading"?await this.listenKey(e,{timeout:t?.timeout??this.timeout}):o?.status==="error"?{code:500,message:"load error"}:o?.status==="cancel"?{code:499,message:"operation cancelled"}:{code:404}}async loadFn(e,t){const r=t.key;if(!r)return{code:404,message:"key is required"};const o={key:t.key,status:"loading",loading:!0,loadSuccessClear:t.loadSuccessClear??!0};let s="";try{const i=t.isReRun??!1;let c;if(!i)this.modules.set(r,o),c=await e();else{o.controller=new AbortController;const a=o.controller.signal;this.modules.set(r,o);const l=await nn({timeout:t.timeout,interval:t.interval,checkSuccess:t.checkSuccess,fn:e,signal:a});if(o.controller=null,l.code===499)return o.status="cancel",{code:499,message:"operation cancelled"};if(l.code!==200)throw new Error(l.message);c=l.data}return o.modules=c,o.status="loaded",{code:200,data:c}}catch(i){return s=i.message,o.status="error",{code:500,message:i}}finally{o.loading=!1,this.modules.set(t.key,o),s?this.event.emit(t.key,s):this.event.emit(t.key)}}async load(e,t){this.loading=!0;const r=t.key;if(!r)return{code:404,message:"key is required"};if(t?.force&&this.remove(r),this.modules.has(r))return await this.hasLoaded(r);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,r){const o={key:e,status:"loaded",loading:!1,modules:t||{},...r};return this.modules.set(e,o),this.emitLoaded(e),o}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 D=globalThis||window||self,on=(n,e="config",t)=>{const r=D[e],o=r||n;return r||(o?D[e]=o:D[e]={}),D[e]},de=(n,e,t="config")=>{const r=on({},t);if(n&&typeof r[n]<"u")return r[n];if(n&&e){if(typeof e!="function"&&(r[n]=e),typeof e=="function"){const o=e();if(o instanceof Promise)return o.then(s=>(r[n]=s,s));r[n]=o}return r[n]}if(n){const o=new rn,s=async()=>r[n];return(async()=>(await o.load(s,{key:n,isReRun:!0,checkSuccess:()=>r[n],timeout:3e5,interval:1e3})).code!==200?(console.error("load key error"),null):r[n])()}return console.error("key is empty "),null},sn=(n,e="config",t)=>{const r=on({},e);if(n&&delete r[n],t?.getNew&&t.init)return de(n,t.init,e);if(t?.getNew)return de(n,null,e)},fe=(n,e,t)=>t?sn(n,"context",{getNew:!0,init:e}):de(n,e,"context"),an=fe,cn=(n,e,t)=>t?sn(n,"config",{getNew:!0,init:e}):de(n,e,"config");class ge{static isInit=!1;static init(e){if(ge.isInit)return;const{load:t=!0,page:r=!1}=e||{};ge.isInit=!0,D.useConfigKey=cn,D.useContextKey=fe,D.use=an,D.webEnv={useConfigKey:cn,useContextKey:fe,use:an},t&&(D.Load=rn)}}ge.init();const Ir=fe("login-emitter",bt),ln="wxff97d569b1db16b6",Ke={pwd:'<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>',phone:'<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>',wxmpSvg:'<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>',wxOpenSvg:'<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>'},$r=[{id:"password",name:"密码登录",icon:"pwd"},{id:"wechat",name:"微信登录",icon:"wxmpSvg",appid:"wx9378885c8390e09b"},{id:"wechat-mp",name:"微信公众号",icon:"wxOpenSvg",appid:ln},{id:"wechat-mp-ticket",name:"微信公众号",icon:"wxOpenSvg"},{id:"phone",name:"手机号登录",icon:"phone"}],Pr=()=>{const n=window.location.hostname;let e=[];switch(n){case"kevisual.xiongxiao.me":e=["password","wechat-mp"];break;case"kevisual.cn":e=["password","wechat","wechat-mp-ticket"];break;default:e=["password","phone","wechat","wechat-mp","wechat-mp-ticket"];break}return $r.filter(t=>e.includes(t.id))};class qr extends HTMLElement{selectedMethod="password";loginMethods=Pr();setLoginMethods(e){this.loginMethods=e,this.render()}constructor(){super()}connectedCallback(){this.attachShadow({mode:"open"}),this.render(),this.bindEvents(),Yn()}#e=null;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 r=e.target.closest(".login-method");if(r){const o=r.getAttribute("data-method");o&&this.selectLoginMethod(o)}}),this.shadowRoot.addEventListener("submit",e=>{const t=e.target;t&&t.id==="loginForm"&&(e.preventDefault(),this.handleLogin())}),Ir.on("login-success",()=>{console.log("收到登录成功事件,处理后续逻辑")}))}handleLogin(){const e=this.getFormData();On({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"phone":const r=this.shadowRoot.querySelector("#phone"),o=this.shadowRoot.querySelector("#code");return{phone:r?.value||"",code:o?.value||""};case"wechat":return{wechatCode:"mock_wechat_code"};case"wechat-mp":return{wechatMpCode:"mock_wechat_mp_code"};default:return{}}}renderPasswordForm(){return I`
166
166
  <form id="loginForm" class="login-form">
167
167
  <div class="form-group">
168
168
  <input
@@ -186,7 +186,7 @@ Minimum version required to store current data is: `+y+`.
186
186
  </div>
187
187
  <button type="submit" class="login-button">登录</button>
188
188
  </form>
189
- `}renderPhoneForm(){return L`
189
+ `}renderPhoneForm(){return I`
190
190
  <form id="loginForm" class="login-form">
191
191
  <div class="form-group">
192
192
  <input
@@ -212,11 +212,11 @@ Minimum version required to store current data is: `+y+`.
212
212
  </div>
213
213
  <button type="submit" class="login-button">登录</button>
214
214
  </form>
215
- `}renderWechatForm(){return L`
215
+ `}renderWechatForm(){return I`
216
216
  <div class="wechat-login">
217
217
  <slot></slot>
218
218
  </div>
219
- `}renderWechatMpForm(){const e=this;return setTimeout(()=>{const r=e.shadowRoot.querySelector("#qrcode"),{clear:n}=gr(r);e.#e=n},0),L`
219
+ `}renderWechatMpForm(){const e=this;return setTimeout(()=>{const t=e.shadowRoot.querySelector("#qrcode"),{clear:r}=Rr(t);e.#e=r},0),I`
220
220
  <div class="wechat-login">
221
221
  <div class="qr-container">
222
222
  <div class="qr-placeholder">
@@ -225,7 +225,7 @@ Minimum version required to store current data is: `+y+`.
225
225
  </div>
226
226
  </div>
227
227
  </div>
228
- `}renderWechatMpTicketForm(){const e=this;return setTimeout(async()=>{const r=await zn();if(!r)return;const n=e.shadowRoot.querySelector(".qrcode");if(r.url){n.src=r.url;const o=Hn(r.ticket);e.#e=o}},0),L`
228
+ `}renderWechatMpTicketForm(){const e=this;return setTimeout(async()=>{const t=await tr();if(!t)return;const r=e.shadowRoot.querySelector(".qrcode");if(t.url){r.src=t.url;const o=nr(t.ticket);e.#e=o}},0),I`
229
229
  <div class="wechat-login">
230
230
  <div class="qr-container">
231
231
  <div class="qr-placeholder">
@@ -234,7 +234,7 @@ Minimum version required to store current data is: `+y+`.
234
234
  </div>
235
235
  </div>
236
236
  </div>
237
- `}sendVerificationCode(){console.log("发送验证码")}refreshQR(){console.log("刷新二维码")}renderLoginForm(){const e=this.getMethodData(this.selectedMethod);switch(this.selectedMethod){case"password":return this.renderPasswordForm();case"phone":return this.renderPhoneForm();case"wechat":return jn({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"&&!He[n]?L`<span class="method-icon-emoji">${n}</span>`:typeof n=="string"&&He[n]?L`<span class="method-icon-svg">${ot(He[n])}</span>`:typeof n=="string"&&(n.includes("<svg")||n.includes("<?xml"))?L`<span class="method-icon-svg">${ot(n)}</span>`:L`<span class="method-icon-emoji">${n}</span>`,r=L`
237
+ `}sendVerificationCode(){console.log("发送验证码")}refreshQR(){console.log("刷新二维码")}renderLoginForm(){const e=this.getMethodData(this.selectedMethod);switch(this.selectedMethod){case"password":return this.renderPasswordForm();case"phone":return this.renderPhoneForm();case"wechat":return rr({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=r=>typeof r=="string"&&!Ke[r]?I`<span class="method-icon-emoji">${r}</span>`:typeof r=="string"&&Ke[r]?I`<span class="method-icon-svg">${lt(Ke[r])}</span>`:typeof r=="string"&&(r.includes("<svg")||r.includes("<?xml"))?I`<span class="method-icon-svg">${lt(r)}</span>`:I`<span class="method-icon-emoji">${r}</span>`,t=I`
238
238
  <style>
239
239
  :host {
240
240
  display: block;
@@ -446,13 +446,13 @@ Minimum version required to store current data is: `+y+`.
446
446
 
447
447
  <div class="login-sidebar">
448
448
  <div class="login-methods">
449
- ${this.loginMethods.map(n=>L`
449
+ ${this.loginMethods.map(r=>I`
450
450
  <button
451
- class="login-method ${this.selectedMethod===n.id?"active":""}"
452
- data-method="${n.id}"
451
+ class="login-method ${this.selectedMethod===r.id?"active":""}"
452
+ data-method="${r.id}"
453
453
  >
454
- ${e(n.icon)}
455
- <span class="method-name">${n.name}</span>
454
+ ${e(r.icon)}
455
+ <span class="method-name">${r.name}</span>
456
456
  </button>
457
457
  `)}
458
458
  </div>
@@ -461,4 +461,4 @@ Minimum version required to store current data is: `+y+`.
461
461
  ${this.renderLoginForm()}
462
462
  </div>
463
463
  </div>
464
- `;rt(r,this.shadowRoot)}}customElements.define("kv-login",mr)}));
464
+ `;ct(t,this.shadowRoot)}}customElements.define("kv-login",qr)}));
package/index.html CHANGED
@@ -74,7 +74,7 @@
74
74
  <div class="demo-container">
75
75
  <div class="login-section">
76
76
  <h2>登录组件</h2>
77
- <kv-login id="loginComponent">
77
+ <kv-login>
78
78
  <div id="weixinLogin"></div>
79
79
  </kv-login>
80
80
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/kv-login",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "src/main.ts",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "build": "vite build --config vite-lib.config.ts",
9
9
  "build:test": "vite build",
10
10
  "prepub": "rm -rf ./dist && pnpm run build:test",
11
- "pub": "ev deploy ./dist -k kv-login-test -v 0.0.4 -u -y yes"
11
+ "pub": "ev deploy ./dist -k kv-login-test -v 0.0.5 -u -y yes"
12
12
  },
13
13
  "keywords": [],
14
14
  "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "type": "module",
21
21
  "dependencies": {
22
+ "@kevisual/context": "^0.0.4",
22
23
  "@kevisual/query-login": "^0.0.6",
23
24
  "lit-html": "^3.3.1",
24
25
  "qrcode": "^1.5.4"
package/readme.md CHANGED
@@ -5,3 +5,8 @@
5
5
  黑白
6
6
 
7
7
 
8
+ ```html
9
+ <kv-login>
10
+ <div id="weixinLogin"></div>
11
+ </kv-login>
12
+ ```
@@ -1,23 +1,25 @@
1
1
  import { query } from './query.ts';
2
2
  import { createMessage } from '../pages/kv-message.ts';
3
3
  import { WX_MP_APP_ID } from '../pages/kv-login.ts';
4
+ import { emit } from './mitt.ts';
4
5
  export const message = createMessage();
5
6
  type LoginOpts = {
6
7
  loginMethod: 'password' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket',
7
8
  data: any,
8
9
  el: HTMLElement
9
10
  }
11
+ /**
12
+ * 登录成功后重定向到首页
13
+ */
10
14
  export const redirectHome = () => {
11
- console.log('重定向到首页')
12
15
  const href = window.location.href;
13
16
  const url = new URL(href);
14
17
  const redirect = url.searchParams.get('redirect');
15
18
  if (redirect) {
16
19
  const href = decodeURIComponent(redirect);
17
20
  window.open(href, '_self');
18
- } else {
19
- window.open('/root/home', '_self');
20
21
  }
22
+ emit({ type: 'login-success', data: {} });
21
23
  }
22
24
  export const loginHandle = async (opts: LoginOpts) => {
23
25
  const { loginMethod, data, el } = opts