@kevisual/kv-login 0.0.1

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.
@@ -0,0 +1,429 @@
1
+ (function(K){typeof define=="function"&&define.amd?define(K):K()})((function(){"use strict";const K=globalThis,ae=K.trustedTypes,We=ae?ae.createPolicy("lit-html",{createHTML:t=>t}):void 0,Oe="$lit$",N=`lit$${Math.random().toFixed(9).slice(2)}$`,Je="?"+N,Yt=`<${Je}>`,H=document,Z=()=>H.createComment(""),ee=t=>t===null||typeof t!="object"&&typeof t!="function",de=Array.isArray,Xt=t=>de(t)||typeof t?.[Symbol.iterator]=="function",fe=`[
2
+ \f\r]`,te=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Ke=/-->/g,Ge=/>/g,z=RegExp(`>|${fe}(?:([^\\s"'>=/]+)(${fe}*=${fe}*(?:[^
3
+ \f\r"'\`<>=]|("|')|))|$)`,"g"),Qe=/'/g,Ye=/"/g,Xe=/^(?:script|style|textarea|title)$/i,Zt=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),$=Zt(1),ne=Symbol.for("lit-noChange"),M=Symbol.for("lit-nothing"),Ze=new WeakMap,V=H.createTreeWalker(H,129);function et(t,e){if(!de(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return We!==void 0?We.createHTML(e):e}const en=(t,e)=>{const n=t.length-1,r=[];let o,s=e===2?"<svg>":e===3?"<math>":"",i=te;for(let c=0;c<n;c++){const a=t[c];let u,l,h=-1,f=0;for(;f<a.length&&(i.lastIndex=f,l=i.exec(a),l!==null);)f=i.lastIndex,i===te?l[1]==="!--"?i=Ke:l[1]!==void 0?i=Ge:l[2]!==void 0?(Xe.test(l[2])&&(o=RegExp("</"+l[2],"g")),i=z):l[3]!==void 0&&(i=z):i===z?l[0]===">"?(i=o??te,h=-1):l[1]===void 0?h=-2:(h=i.lastIndex-l[2].length,u=l[1],i=l[3]===void 0?z:l[3]==='"'?Ye:Qe):i===Ye||i===Qe?i=z:i===Ke||i===Ge?i=te:(i=z,o=void 0);const d=i===z&&t[c+1].startsWith("/>")?" ":"";s+=i===te?a+Yt:h>=0?(r.push(u),a.slice(0,h)+Oe+a.slice(h)+N+d):a+N+(h===-2?c:d)}return[et(t,s+(t[n]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),r]};class re{constructor({strings:e,_$litType$:n},r){let o;this.parts=[];let s=0,i=0;const c=e.length-1,a=this.parts,[u,l]=en(e,n);if(this.el=re.createElement(u,r),V.currentNode=this.el.content,n===2||n===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(o=V.nextNode())!==null&&a.length<c;){if(o.nodeType===1){if(o.hasAttributes())for(const h of o.getAttributeNames())if(h.endsWith(Oe)){const f=l[i++],d=o.getAttribute(h).split(N),w=/([.?@])?(.*)/.exec(f);a.push({type:1,index:s,name:w[2],strings:d,ctor:w[1]==="."?nn:w[1]==="?"?rn:w[1]==="@"?on:ce}),o.removeAttribute(h)}else h.startsWith(N)&&(a.push({type:6,index:s}),o.removeAttribute(h));if(Xe.test(o.tagName)){const h=o.textContent.split(N),f=h.length-1;if(f>0){o.textContent=ae?ae.emptyScript:"";for(let d=0;d<f;d++)o.append(h[d],Z()),V.nextNode(),a.push({type:2,index:++s});o.append(h[f],Z())}}}else if(o.nodeType===8)if(o.data===Je)a.push({type:2,index:s});else{let h=-1;for(;(h=o.data.indexOf(N,h+1))!==-1;)a.push({type:7,index:s}),h+=N.length-1}s++}}static createElement(e,n){const r=H.createElement("template");return r.innerHTML=e,r}}function G(t,e,n=t,r){if(e===ne)return e;let o=r!==void 0?n._$Co?.[r]:n._$Cl;const s=ee(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,n,r)),r!==void 0?(n._$Co??=[])[r]=o:n._$Cl=o),o!==void 0&&(e=G(t,o._$AS(t,e.values),o,r)),e}class tn{constructor(e,n){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=n}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:n},parts:r}=this._$AD,o=(e?.creationScope??H).importNode(n,!0);V.currentNode=o;let s=V.nextNode(),i=0,c=0,a=r[0];for(;a!==void 0;){if(i===a.index){let u;a.type===2?u=new oe(s,s.nextSibling,this,e):a.type===1?u=new a.ctor(s,a.name,a.strings,this,e):a.type===6&&(u=new sn(s,this,e)),this._$AV.push(u),a=r[++c]}i!==a?.index&&(s=V.nextNode(),i++)}return V.currentNode=H,o}p(e){let n=0;for(const r of this._$AV)r!==void 0&&(r.strings!==void 0?(r._$AI(e,r,n),n+=r.strings.length-2):r._$AI(e[n])),n++}}class oe{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,n,r,o){this.type=2,this._$AH=M,this._$AN=void 0,this._$AA=e,this._$AB=n,this._$AM=r,this.options=o,this._$Cv=o?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode;const n=this._$AM;return n!==void 0&&e?.nodeType===11&&(e=n.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,n=this){e=G(this,e,n),ee(e)?e===M||e==null||e===""?(this._$AH!==M&&this._$AR(),this._$AH=M):e!==this._$AH&&e!==ne&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Xt(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&&ee(this._$AH)?this._$AA.nextSibling.data=e:this.T(H.createTextNode(e)),this._$AH=e}$(e){const{values:n,_$litType$:r}=e,o=typeof r=="number"?this._$AC(e):(r.el===void 0&&(r.el=re.createElement(et(r.h,r.h[0]),this.options)),r);if(this._$AH?._$AD===o)this._$AH.p(n);else{const s=new tn(o,this),i=s.u(this.options);s.p(n),this.T(i),this._$AH=s}}_$AC(e){let n=Ze.get(e.strings);return n===void 0&&Ze.set(e.strings,n=new re(e)),n}k(e){de(this._$AH)||(this._$AH=[],this._$AR());const n=this._$AH;let r,o=0;for(const s of e)o===n.length?n.push(r=new oe(this.O(Z()),this.O(Z()),this,this.options)):r=n[o],r._$AI(s),o++;o<n.length&&(this._$AR(r&&r._$AB.nextSibling,o),n.length=o)}_$AR(e=this._$AA.nextSibling,n){for(this._$AP?.(!1,!0,n);e!==this._$AB;){const r=e.nextSibling;e.remove(),e=r}}setConnected(e){this._$AM===void 0&&(this._$Cv=e,this._$AP?.(e))}}class ce{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,n,r,o,s){this.type=1,this._$AH=M,this._$AN=void 0,this.element=e,this.name=n,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=M}_$AI(e,n=this,r,o){const s=this.strings;let i=!1;if(s===void 0)e=G(this,e,n,0),i=!ee(e)||e!==this._$AH&&e!==ne,i&&(this._$AH=e);else{const c=e;let a,u;for(e=s[0],a=0;a<s.length-1;a++)u=G(this,c[r+a],n,a),u===ne&&(u=this._$AH[a]),i||=!ee(u)||u!==this._$AH[a],u===M?e=M:e!==M&&(e+=(u??"")+s[a+1]),this._$AH[a]=u}i&&!o&&this.j(e)}j(e){e===M?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class nn extends ce{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===M?void 0:e}}class rn extends ce{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==M)}}class on extends ce{constructor(e,n,r,o,s){super(e,n,r,o,s),this.type=5}_$AI(e,n=this){if((e=G(this,e,n,0)??M)===ne)return;const r=this._$AH,o=e===M&&r!==M||e.capture!==r.capture||e.once!==r.once||e.passive!==r.passive,s=e!==M&&(r===M||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 sn{constructor(e,n,r){this.element=e,this.type=6,this._$AN=void 0,this._$AM=n,this.options=r}get _$AU(){return this._$AM._$AU}_$AI(e){G(this,e)}}const an=K.litHtmlPolyfillSupport;an?.(re,oe),(K.litHtmlVersions??=[]).push("3.3.1");const tt=(t,e,n)=>{const r=e;let o=r._$litPart$;return o===void 0&&(r._$litPart$=o=new oe(e.insertBefore(Z(),null),null,void 0,{})),o._$AI(t),o},cn=t=>t?["text/","xml","html","javascript","css","csv","plain","x-www-form-urlencoded"].some(n=>t.includes(n)):!1,nt=async(t={},e)=>{const n=new AbortController,r=n.signal,o=t.isBlob||!1,s=t.isText||!1,i=t.isPostFile||!1,c=t.timeout||6e4*3,a=setTimeout(()=>{n.abort()},c);let u=e?.method||t?.method||"POST",l={...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=u==="GET";d&&(f.search=new URLSearchParams(t.body).toString());let w;return d?w=void 0:i?w=t.body:(l={"Content-Type":"application/json",...l},w=JSON.stringify(t.body)),fetch(f,{method:u.toUpperCase(),signal:r,body:w,...e,headers:l}).then(async m=>{const S=m.headers.get("Content-Type");return o?await m.blob():S&&S.includes("application/json")&&!s?await m.json():cn(S)?{code:200,status:m.status,data:await m.text()}:m}).catch(m=>(m.name==="AbortError"&&console.log("Request timed out and was aborted"),console.error(m),{code:500})).finally(()=>{clearTimeout(a)})},rt=t=>(t.success=t.code===200,t.showError=e=>{!t.success&&!t.noMsg&&e?.()},t),ge=({code:t,message:e})=>({code:t||500,success:!1,message:e||"api request error",showError:r=>{},noMsg:!0});class ot{adapter;url;beforeRequest;afterResponse;headers;timeout;stop;qws;constructor(e){this.adapter=e?.adapter||nt,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,n){return this.post(e,n)}async post(e,n){const r=n?.url||this.url,{headers:o,adapter:s,beforeRequest:i,afterResponse:c,timeout:a,...u}=n||{},l={...this.headers,...o},h=s||this.adapter,f=i||this.beforeRequest,d=c||this.afterResponse,w=a||this.timeout,m={url:r,headers:l,body:e,timeout:w,...u};try{if(f&&await f(m)===!1)return ge({code:500,message:"request is cancel",req:m})}catch(S){return console.error("request beforeFn error",S,m),ge({code:500,message:"api request beforeFn error"})}if(this.stop&&!n?.noStop){const S=this;await new Promise(C=>{let B=0;const k=setInterval(()=>{S.stop||(clearInterval(k),C(!0)),B++,B>30&&console.error("request stop: timeout",m.url,B)},1e3)})}return h(m).then(async S=>{try{return rt(S),d?await d(S,{req:m,res:S,fetch:s}):S}catch(C){return console.error("request afterFn error",C,m),ge({code:500,message:"api request afterFn error"})}})}before(e){this.beforeRequest=e}after(e){this.afterResponse=e}async fetchText(e,n){let r={...n};typeof e=="string"&&!r.url&&(r.url=e),typeof e=="object"&&(r={...e,...r});const o=await nt({method:"GET",...r,headers:{...this.headers,...r?.headers||{}}});return rt(o)}}class un{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,n){return this.query.post(e,n)}get(e,n){return this.query.get(e,n)}}const st=t=>(t.success=t.code===200,t.showError=e=>{!t.success&&!t.noMsg&&e?.()},t);function L(t){return new Promise((e,n)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>n(t.error)})}function it(t,e){const n=indexedDB.open(t);n.onupgradeneeded=()=>n.result.createObjectStore(e);const r=L(n);return(o,s)=>r.then(i=>s(i.transaction(e,o).objectStore(e)))}let me;function x(){return me||(me=it("keyval-store","keyval")),me}function at(t,e=x()){return e("readonly",n=>L(n.get(t)))}function ct(t,e,n=x()){return n("readwrite",r=>(r.put(e,t),L(r.transaction)))}function ln(t,e=x()){return e("readwrite",n=>(t.forEach(r=>n.put(r[1],r[0])),L(n.transaction)))}function hn(t,e=x()){return e("readonly",n=>Promise.all(t.map(r=>L(n.get(r)))))}function dn(t,e,n=x()){return n("readwrite",r=>new Promise((o,s)=>{r.get(t).onsuccess=function(){try{r.put(e(this.result),t),o(L(r.transaction))}catch(i){s(i)}}}))}function ut(t,e=x()){return e("readwrite",n=>(n.delete(t),L(n.transaction)))}function fn(t,e=x()){return e("readwrite",n=>(t.forEach(r=>n.delete(r)),L(n.transaction)))}function lt(t=x()){return t("readwrite",e=>(e.clear(),L(e.transaction)))}function pe(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},L(t.transaction)}function gn(t=x()){return t("readonly",e=>{if(e.getAllKeys)return L(e.getAllKeys());const n=[];return pe(e,r=>n.push(r.key)).then(()=>n)})}function mn(t=x()){return t("readonly",e=>{if(e.getAll)return L(e.getAll());const n=[];return pe(e,r=>n.push(r.value)).then(()=>n)})}function pn(t=x()){return t("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 n=[];return t("readonly",r=>pe(r,o=>n.push([o.key,o.value])).then(()=>n))})}var wn=Object.freeze({__proto__:null,clear:lt,createStore:it,del:ut,delMany:fn,entries:pn,get:at,getMany:hn,keys:gn,promisifyRequest:L,set:ct,setMany:ln,update:dn,values:mn});class yn{storage;data=null;constructor(){this.storage=wn}async get(e){const n=await at(e);return this.data=n,n}async set(e,n){this.data=n,await ct(e,n)}async del(e){this.data=null,await ut(e)}async clear(){await lt()}}class bn extends yn{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,n){const o=Date.now()+(n?.expireTime||1e3*60*60*24*10),s={data:e,updatedAt:n?.updatedAt||Date.now(),expireTime:o};await super.set(this.name,s),this.updatedAt=s.updatedAt}async del(){await super.del(this.name)}}var An=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(n=>n.id===t.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(n=>n?.id&&n.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(n=>n.id===t.id)&&(this.cacheData.loginUsers=this.cacheData?.loginUsers?.filter(n=>n?.id&&n.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)}},Cn=class extends un{cacheStore;isBrowser;load;storage;onLoad;constructor(t){super({query:t?.query||new ot}),this.cacheStore=new An({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(n){return console.log("error",n),{code:400}}}async login(t){const e=await this.post({key:"login",...t});if(e.code===200){const{accessToken:n,refreshToken:r}=e?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:r})}return e}async loginByCode(t){const e=await this.post({path:"sms",key:"login",data:t});if(e.code===200){const{accessToken:n,refreshToken:r}=e?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:r})}return e}async setLoginToken(t){const{accessToken:e,refreshToken:n}=t;this.storage.setItem("token",e||""),await this.beforeSetLoginUser({accessToken:e,refreshToken:n})}async loginByWechat(t){const e=await this.post({path:"wx",key:"open-login",code:t.code});if(e.code===200){const{accessToken:n,refreshToken:r}=e?.data||{};this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:r})}return e}async checkWechat({onSuccess:t,onError:e}){const n=new URL(window.location.href),r=n.searchParams.get("code"),o=n.searchParams.get("state");if(r&&o){const s=await this.loginByWechat({code:r});s.code===200?t?.(s.data):e?.(s)}}async beforeSetLoginUser({accessToken:t,refreshToken:e,check401:n}){if(t&&e){const r=await this.getMe(t,n);if(r.code===200){const o=r.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 n={refreshToken:e};return e?this.post({key:"refreshToken",data:n},{afterResponse:async(r,o)=>(st(r),r)}):(await this.cacheStore.clearCurrentUser(),{code:401,message:"请先登录",data:{}})}async afterCheck401ToRefreshToken(t,e,n){const r=this;if(t?.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}),n&&e&&e.req&&e.req.url&&e.fetch){await new Promise(f=>setTimeout(f,1500));const a=e.req?.url,u=e.req?.body,l=e.req?.headers,h=await e.fetch(a,{method:"POST",body:u,headers:{...l,Authorization:`Bearer ${i}`}});return st(h),h}}else r.storage.removeItem("token"),await r.cacheStore.clearCurrentUser();return s}}return t}async run401Action(t,e,n){const r=this,o=n?.refetch??!1;if(t?.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(t,e,o);return r.query.stop=!1,n?.afterCheck?.(s),s.code===401&&n?.afterAlso401?.(s),s}else return t}async getMe(t,e=!0){const n=t||this.storage.getItem("token"),r=this;return r.post({key:"me"},{beforeRequest:async o=>(o.headers&&(o.headers.Authorization=`Bearer ${n}`),o),afterResponse:async(o,s)=>o?.code===401&&e&&!t?await r.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 n=(await this.cacheStore.getCurrentUserList()).find(o=>o.user.username===t);if(n)return this.storage.setItem("token",n.accessToken||""),await this.beforeSetLoginUser({accessToken:n.accessToken,refreshToken:n.refreshToken}),{code:200,data:{accessToken:n.accessToken,refreshToken:n.refreshToken},success:!0,message:"切换用户成功"};const r=await this.postSwitchUser(t);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(n=>n?.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(n,r)=>n?.code===401?await e.afterCheck401ToRefreshToken(n,r,!0):n})}async checkLoginStatus(t){const e=await this.post({path:"user",key:"checkLoginStatus",loginToken:t});if(e.code===200){const n=e.data?.accessToken;return this.storage.setItem("token",n||""),await this.beforeSetLoginUser({accessToken:n,refreshToken:e.data?.refreshToken}),e}return!1}loginWithWeb(t,{MD5:e,jsonwebtoken:n}){const r=Math.random().toString(36).substring(2,15),o=Date.now(),s="xiao"+r,i=e(`${s}${o}`).toString(),c=n.sign({randomId:r,timestamp:o,sign:i},s,{expiresIn:600});return{url:`${t}/api/router?path=user&key=webLogin&p&loginToken=${c}&sign=${i}&randomId=${r}`,token:c,tokenSecret:s}}},Tn=class extends Cn{constructor(t){super({...t,cache:new bn("login")})}};const vn=new ot,j=new Tn({query:vn});class kn 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:n,closable:r}=this.options,s=$`
4
+ <style>
5
+ :host {
6
+ display: block;
7
+ margin-bottom: 12px;
8
+ animation: slideIn 0.3s ease-out;
9
+ }
10
+
11
+ .message-container {
12
+ display: flex;
13
+ align-items: center;
14
+ gap: 8px;
15
+ padding: 12px 16px;
16
+ border-radius: 6px;
17
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
18
+ background: white;
19
+ position: relative;
20
+ min-width: 300px;
21
+ max-width: 500px;
22
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
23
+ font-size: 14px;
24
+ line-height: 1.4;
25
+ }
26
+
27
+ .message-container.success {
28
+ border-left: 4px solid #52c41a;
29
+ }
30
+
31
+ .message-container.error {
32
+ border-left: 4px solid #ff4d4f;
33
+ }
34
+
35
+ .message-container.loading {
36
+ border-left: 4px solid #1890ff;
37
+ }
38
+
39
+ .message-icon {
40
+ display: flex;
41
+ align-items: center;
42
+ justify-content: center;
43
+ width: 16px;
44
+ height: 16px;
45
+ flex-shrink: 0;
46
+ }
47
+
48
+ .success .message-icon {
49
+ color: #52c41a;
50
+ font-weight: bold;
51
+ }
52
+
53
+ .error .message-icon {
54
+ color: #ff4d4f;
55
+ font-weight: bold;
56
+ }
57
+
58
+ .loading .message-icon {
59
+ color: #1890ff;
60
+ }
61
+
62
+ .loading-spinner {
63
+ width: 14px;
64
+ height: 14px;
65
+ border: 2px solid #f3f3f3;
66
+ border-top: 2px solid #1890ff;
67
+ border-radius: 50%;
68
+ animation: spin 1s linear infinite;
69
+ }
70
+
71
+ .message-content {
72
+ flex: 1;
73
+ color: #333;
74
+ }
75
+
76
+ .message-close {
77
+ display: flex;
78
+ align-items: center;
79
+ justify-content: center;
80
+ width: 16px;
81
+ height: 16px;
82
+ cursor: pointer;
83
+ color: #999;
84
+ background: none;
85
+ border: none;
86
+ font-size: 12px;
87
+ border-radius: 50%;
88
+ transition: all 0.2s;
89
+ }
90
+
91
+ .message-close:hover {
92
+ color: #666;
93
+ background: #f0f0f0;
94
+ }
95
+
96
+ @keyframes slideIn {
97
+ from {
98
+ transform: translateX(100%);
99
+ opacity: 0;
100
+ }
101
+ to {
102
+ transform: translateX(0);
103
+ opacity: 1;
104
+ }
105
+ }
106
+
107
+ @keyframes slideOut {
108
+ from {
109
+ transform: translateX(0);
110
+ opacity: 1;
111
+ }
112
+ to {
113
+ transform: translateX(100%);
114
+ opacity: 0;
115
+ }
116
+ }
117
+
118
+ @keyframes spin {
119
+ 0% { transform: rotate(0deg); }
120
+ 100% { transform: rotate(360deg); }
121
+ }
122
+
123
+ .removing {
124
+ animation: slideOut 0.3s ease-out forwards;
125
+ }
126
+ </style>
127
+
128
+ <div class="message-container ${e}">
129
+ <div class="message-icon">
130
+ ${(()=>{switch(e){case"success":return"✓";case"error":return"✕";case"loading":return $`<div class="loading-spinner"></div>`;default:return""}})()}
131
+ </div>
132
+ <div class="message-content">${n}</div>
133
+ ${r?$`
134
+ <button class="message-close" @click=${()=>this.remove()}>&times;</button>
135
+ `:""}
136
+ </div>
137
+ `;tt(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",kn);class Q{static instance;container=null;defaultPosition="center";static getInstance(){return Q.instance||(Q.instance=new Q),Q.instance}setDefaultPosition(e){this.defaultPosition=e}getContainer(e){const n=e||this.defaultPosition;return this.container||(this.container=document.getElementById("messages"),this.container||(this.container=document.createElement("div"),this.container.id="messages",n==="center"?this.container.style.cssText=`
138
+ position: fixed;
139
+ top: 20px;
140
+ left: 50%;
141
+ transform: translateX(-50%);
142
+ z-index: 9999;
143
+ display: flex;
144
+ gap: 8px;
145
+ flex-direction: column;
146
+ align-items: center;
147
+ pointer-events: none;
148
+ `:this.container.style.cssText=`
149
+ position: fixed;
150
+ top: 20px;
151
+ right: 20px;
152
+ z-index: 9999;
153
+ display: flex;
154
+ gap: 8px;
155
+ flex-direction: column;
156
+ align-items: flex-end;
157
+ pointer-events: none;
158
+ `,document.body.appendChild(this.container))),this.container}show(e){const n=this.getContainer(e.position),r=document.createElement("kv-message");return r.setOptions(e),r.style.cssText="pointer-events: auto;",n.appendChild(r),r}success(e,n){return this.show({type:"success",message:e,duration:n?.duration||2e3,position:n?.position,closable:n?.closable})}error(e,n){return this.show({type:"error",message:e,duration:n?.duration||3e3,position:n?.position,closable:n?.closable})}loading(e,n){return this.show({type:"loading",message:e,duration:0,position:n?.position,closable:n?.closable})}remove(e){e.remove()}clear(){this.getContainer().querySelectorAll("kv-message").forEach(r=>{r.remove()})}}const ht=()=>Q.getInstance();window.createMessage=ht;const W=ht(),ue=()=>{console.log("重定向到首页");const t=window.location.href,n=new URL(t).searchParams.get("redirect");if(n){const r=decodeURIComponent(n);window.open(r,"_self")}else window.open("/root/home","_self")},En=async t=>{const{loginMethod:e,data:n}=t;switch(e){case"password":await _n(n);break;case"phone":await Rn(n);break;case"wechat-mp":await Sn(n);break;case"wechat":await Bn(n);break;default:console.warn("未知的登录方式:",e)}},_n=async t=>{console.log("使用用户名密码登录:",t);let e=!0;if(await j.checkLocalToken()&&(await j.checkLocalUser())?.username===t?.username&&(await j.getMe()).code===200&&(e=!1,console.log("已登录,跳过登录步骤"),W.success("已登录")),!e){ue();return}const r=await j.login({username:t.username,password:t.password});r.code===200?(console.log("登录成功"),W.success("登录成功"),ue()):W.error(`登录失败: ${r.message}`)},Rn=async t=>{console.log("使用手机号登录:",t)},Bn=async t=>{console.log("使用微信登录:",t)},Sn=async t=>{console.log("使用微信公众号登录:",t)},Mn=()=>{const t=new URL(window.location.href);t.searchParams.delete("code"),t.searchParams.delete("state"),window.history.replaceState({},document.title,t.toString())},In=async()=>{const t=new URL(window.location.href),e=t.searchParams.get("code");if(t.searchParams.get("state")?.includes?.("-")||!e)return;const r=await j.loginByWechat({code:e});r.code===200?(W.success("登录成功"),ue()):(W.error(r.message||"登录失败"),Mn())},Ln=async()=>{const t=new URL(window.location.href),e=t.searchParams.get("state"),[n,r]=e?e.split("-"):[null,null];if(console.log("检查微信公众号登录流程:",n,r,e),n==="1")Pn();else if(n==="2"){const o=t.searchParams.get("code"),s=await j.post({path:"wx",key:"mplogin",state:r,code:o});s.code===200?W.success("登录成功"):W.error(s.message||"登录失败"),dt()}},xn=()=>{const t=navigator.userAgent.toLowerCase();return/micromessenger/i.test(t)},dt=(t=2e3)=>{if(!xn()){setTimeout(()=>{window.close()},t);return}window.WeixinJSBridge?setTimeout(()=>{window.WeixinJSBridge.call("closeWindow")},t):setTimeout(()=>{window.close()},t)},Pn=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=Ot,n=new URL(window.location.href),r=n.searchParams.get("state");let[o,s]=r?r.split("-"):[null,null];const i=new URL(n.pathname,n.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."),dt();return}const u=t.replace("APPID",e).replace("REDIRECT_URI",c).replace("SCOPE",a).replace("STATE",s);setTimeout(()=>{window.location.href=u},100)};setTimeout(()=>{Ln()},100);const ft=async t=>{let e=t?.redirect_uri;const{appid:n}=t||{};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),!n){console.error("appid is not cant be empty");return}const o=new WxLogin({self_redirect:!1,id:"weixinLogin",appid:n,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 $n(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")){ft(t);return}const n=document.body.appendChild(e);n.onload=function(){ft(t)}}function qn(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Y={},we,gt;function Dn(){return gt||(gt=1,we=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),we}var ye={},U={},mt;function O(){if(mt)return U;mt=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 U.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},U.getSymbolTotalCodewords=function(r){return e[r]},U.getBCHDigit=function(n){let r=0;for(;n!==0;)r++,n>>>=1;return r},U.setToSJISFunction=function(r){if(typeof r!="function")throw new Error('"toSJISFunc" is not a valid function.');t=r},U.isKanjiModeEnabled=function(){return typeof t<"u"},U.toSJIS=function(r){return t(r)},U}var be={},pt;function Ae(){return pt||(pt=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function e(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.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: "+n)}}t.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},t.from=function(r,o){if(t.isValid(r))return r;try{return e(r)}catch{return o}}})(be)),be}var Ce,wt;function Nn(){if(wt)return Ce;wt=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(e){const n=Math.floor(e/8);return(this.buffer[n]>>>7-e%8&1)===1},put:function(e,n){for(let r=0;r<n;r++)this.putBit((e>>>n-r-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),e&&(this.buffer[n]|=128>>>this.length%8),this.length++}},Ce=t,Ce}var Te,yt;function Un(){if(yt)return Te;yt=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,n,r,o){const s=e*this.size+n;this.data[s]=r,o&&(this.reservedBit[s]=!0)},t.prototype.get=function(e,n){return this.data[e*this.size+n]},t.prototype.xor=function(e,n,r){this.data[e*this.size+n]^=r},t.prototype.isReserved=function(e,n){return this.reservedBit[e*this.size+n]},Te=t,Te}var ve={},bt;function Fn(){return bt||(bt=1,(function(t){const e=O().getSymbolSize;t.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()},t.getPositions=function(r){const o=[],s=t.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}})(ve)),ve}var ke={},At;function Hn(){if(At)return ke;At=1;const t=O().getSymbolSize,e=7;return ke.getPositions=function(r){const o=t(r);return[[0,0],[o-e,0],[0,o-e]]},ke}var Ee={},Ct;function zn(){return Ct||(Ct=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,u=null,l=null;for(let h=0;h<s;h++){c=a=0,u=l=null;for(let f=0;f<s;f++){let d=o.get(h,f);d===u?c++:(c>=5&&(i+=e.N1+(c-5)),u=d,c=1),d=o.get(f,h),d===l?a++:(a>=5&&(i+=e.N1+(a-5)),l=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 u=o.get(c,a)+o.get(c,a+1)+o.get(c+1,a)+o.get(c+1,a+1);(u===4||u===0)&&i++}return i*e.N2},t.getPenaltyN3=function(o){const s=o.size;let i=0,c=0,a=0;for(let u=0;u<s;u++){c=a=0;for(let l=0;l<s;l++)c=c<<1&2047|o.get(u,l),l>=10&&(c===1488||c===93)&&i++,a=a<<1&2047|o.get(l,u),l>=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 n(r,o,s){switch(r){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:"+r)}}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,n(o,a,c))},t.getBestMask=function(o,s){const i=Object.keys(t.Patterns).length;let c=0,a=1/0;for(let u=0;u<i;u++){s(u),t.applyMask(u,o);const l=t.getPenaltyN1(o)+t.getPenaltyN2(o)+t.getPenaltyN3(o)+t.getPenaltyN4(o);t.applyMask(u,o),l<a&&(a=l,c=u)}return c}})(Ee)),Ee}var le={},Tt;function vt(){if(Tt)return le;Tt=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],n=[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 le.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}},le.getTotalCodewordsCount=function(o,s){switch(s){case t.L:return n[(o-1)*4+0];case t.M:return n[(o-1)*4+1];case t.Q:return n[(o-1)*4+2];case t.H:return n[(o-1)*4+3];default:return}},le}var _e={},se={},kt;function Vn(){if(kt)return se;kt=1;const t=new Uint8Array(512),e=new Uint8Array(256);return(function(){let r=1;for(let o=0;o<255;o++)t[o]=r,e[r]=o,r<<=1,r&256&&(r^=285);for(let o=255;o<512;o++)t[o]=t[o-255]})(),se.log=function(r){if(r<1)throw new Error("log("+r+")");return e[r]},se.exp=function(r){return t[r]},se.mul=function(r,o){return r===0||o===0?0:t[e[r]+e[o]]},se}var Et;function jn(){return Et||(Et=1,(function(t){const e=Vn();t.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},t.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},t.generateECPolynomial=function(r){let o=new Uint8Array([1]);for(let s=0;s<r;s++)o=t.mul(o,new Uint8Array([1,e.exp(s)]));return o}})(_e)),_e}var Re,_t;function Wn(){if(_t)return Re;_t=1;const t=jn();function e(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return e.prototype.initialize=function(r){this.degree=r,this.genPoly=t.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=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={},Se={},Me={},Rt;function Bt(){return Rt||(Rt=1,Me.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}),Me}var P={},St;function Mt(){if(St)return P;St=1;const t="[0-9]+",e="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const r="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
159
+ ]))+`;P.KANJI=new RegExp(n,"g"),P.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),P.BYTE=new RegExp(r,"g"),P.NUMERIC=new RegExp(t,"g"),P.ALPHANUMERIC=new RegExp(e,"g");const o=new RegExp("^"+n+"$"),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=Bt(),n=Mt();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 n.testNumeric(s)?t.NUMERIC:n.testAlphanumeric(s)?t.ALPHANUMERIC:n.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 r(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 r(s)}catch{return i}}})(Se)),Se}var Lt;function On(){return Lt||(Lt=1,(function(t){const e=O(),n=vt(),r=Ae(),o=J(),s=Bt(),i=7973,c=e.getBCHDigit(i);function a(f,d,w){for(let m=1;m<=40;m++)if(d<=t.getCapacity(m,w,f))return m}function u(f,d){return o.getCharCountIndicator(f,d)+4}function l(f,d){let w=0;return f.forEach(function(m){const S=u(m.mode,d);w+=S+m.getBitsLength()}),w}function h(f,d){for(let w=1;w<=40;w++)if(l(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,m){if(!s.isValid(d))throw new Error("Invalid QR Code version");typeof m>"u"&&(m=o.BYTE);const S=e.getSymbolTotalCodewords(d),C=n.getTotalCodewordsCount(d,w),B=(S-C)*8;if(m===o.MIXED)return B;const k=B-u(m,d);switch(m){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 m;const S=r.from(w,r.M);if(Array.isArray(d)){if(d.length>1)return h(d,S);if(d.length===0)return 1;m=d[0]}else m=d;return a(m.mode,m.getLength(),S)},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 Ie={},xt;function Jn(){if(xt)return Ie;xt=1;const t=O(),e=1335,n=21522,r=t.getBCHDigit(e);return Ie.getEncodedBits=function(s,i){const c=s.bit<<3|i;let a=c<<10;for(;t.getBCHDigit(a)-r>=0;)a^=e<<t.getBCHDigit(a)-r;return(c<<10|a)^n},Ie}var Le={},xe,Pt;function Kn(){if(Pt)return xe;Pt=1;const t=J();function e(n){this.mode=t.NUMERIC,this.data=n.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))},xe=e,xe}var Pe,$t;function Gn(){if($t)return Pe;$t=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 n(r){this.mode=t.ALPHANUMERIC,this.data=r}return n.getBitsLength=function(o){return 11*Math.floor(o/2)+6*(o%2)},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.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=n,Pe}var $e,qt;function Qn(){if(qt)return $e;qt=1;const t=J();function e(n){this.mode=t.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}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(n){for(let r=0,o=this.data.length;r<o;r++)n.put(this.data[r],8)},$e=e,$e}var qe,Dt;function Yn(){if(Dt)return qe;Dt=1;const t=J(),e=O();function n(r){this.mode=t.KANJI,this.data=r}return n.getBitsLength=function(o){return o*13},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.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)}},qe=n,qe}var De={exports:{}},Nt;function Xn(){return Nt||(Nt=1,(function(t){var e={single_source_shortest_paths:function(n,r,o){var s={},i={};i[r]=0;var c=e.PriorityQueue.make();c.push(r,0);for(var a,u,l,h,f,d,w,m,S;!c.empty();){a=c.pop(),u=a.value,h=a.cost,f=n[u]||{};for(l in f)f.hasOwnProperty(l)&&(d=f[l],w=h+d,m=i[l],S=typeof i[l]>"u",(S||m>w)&&(i[l]=w,c.push(l,w),s[l]=u))}if(typeof o<"u"&&typeof i[o]>"u"){var C=["Could not find a path from ",r," to ",o,"."].join("");throw new Error(C)}return s},extract_shortest_path_from_predecessor_list:function(n,r){for(var o=[],s=r;s;)o.push(s),n[s],s=n[s];return o.reverse(),o},find_path:function(n,r,o){var s=e.single_source_shortest_paths(n,r,o);return e.extract_shortest_path_from_predecessor_list(s,o)},PriorityQueue:{make:function(n){var r=e.PriorityQueue,o={},s;n=n||{};for(s in r)r.hasOwnProperty(s)&&(o[s]=r[s]);return o.queue=[],o.sorter=n.sorter||r.default_sorter,o},default_sorter:function(n,r){return n.cost-r.cost},push:function(n,r){var o={value:n,cost:r};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})(De)),De.exports}var Ut;function Zn(){return Ut||(Ut=1,(function(t){const e=J(),n=Kn(),r=Gn(),o=Qn(),s=Yn(),i=Mt(),c=O(),a=Xn();function u(C){return unescape(encodeURIComponent(C)).length}function l(C,B,k){const E=[];let I;for(;(I=C.exec(k))!==null;)E.push({data:I[0],index:I.index,mode:B,length:I[0].length});return E}function h(C){const B=l(i.NUMERIC,e.NUMERIC,C),k=l(i.ALPHANUMERIC,e.ALPHANUMERIC,C);let E,I;return c.isKanjiModeEnabled()?(E=l(i.BYTE,e.BYTE,C),I=l(i.KANJI,e.KANJI,C)):(E=l(i.BYTE_KANJI,e.BYTE,C),I=[]),B.concat(k,E,I).sort(function(T,A){return T.index-A.index}).map(function(T){return{data:T.data,mode:T.mode,length:T.length}})}function f(C,B){switch(B){case e.NUMERIC:return n.getBitsLength(C);case e.ALPHANUMERIC:return r.getBitsLength(C);case e.KANJI:return s.getBitsLength(C);case e.BYTE:return o.getBitsLength(C)}}function d(C){return C.reduce(function(B,k){const E=B.length-1>=0?B[B.length-1]:null;return E&&E.mode===k.mode?(B[B.length-1].data+=k.data,B):(B.push(k),B)},[])}function w(C){const B=[];for(let k=0;k<C.length;k++){const E=C[k];switch(E.mode){case e.NUMERIC:B.push([E,{data:E.data,mode:e.ALPHANUMERIC,length:E.length},{data:E.data,mode:e.BYTE,length:E.length}]);break;case e.ALPHANUMERIC:B.push([E,{data:E.data,mode:e.BYTE,length:E.length}]);break;case e.KANJI:B.push([E,{data:E.data,mode:e.BYTE,length:u(E.data)}]);break;case e.BYTE:B.push([{data:E.data,mode:e.BYTE,length:u(E.data)}])}}return B}function m(C,B){const k={},E={start:{}};let I=["start"];for(let p=0;p<C.length;p++){const T=C[p],A=[];for(let g=0;g<T.length;g++){const _=T[g],y=""+p+g;A.push(y),k[y]={node:_,lastCount:0},E[y]={};for(let v=0;v<I.length;v++){const b=I[v];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,B))}}I=A}for(let p=0;p<I.length;p++)E[I[p]].end=0;return{map:E,table:k}}function S(C,B){let k;const E=e.getBestModeForData(C);if(k=e.from(B,E),k!==e.BYTE&&k.bit<E.bit)throw new Error('"'+C+'" 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 n(C);case e.ALPHANUMERIC:return new r(C);case e.KANJI:return new s(C);case e.BYTE:return new o(C)}}t.fromArray=function(B){return B.reduce(function(k,E){return typeof E=="string"?k.push(S(E,null)):E.data&&k.push(S(E.data,E.mode)),k},[])},t.fromString=function(B,k){const E=h(B,c.isKanjiModeEnabled()),I=w(E),p=m(I,k),T=a.find_path(p.map,"start","end"),A=[];for(let g=1;g<T.length-1;g++)A.push(p.table[T[g]].node);return t.fromArray(d(A))},t.rawSplit=function(B){return t.fromArray(h(B,c.isKanjiModeEnabled()))}})(Le)),Le}var Ft;function er(){if(Ft)return ye;Ft=1;const t=O(),e=Ae(),n=Nn(),r=Un(),o=Fn(),s=Hn(),i=zn(),c=vt(),a=Wn(),u=On(),l=Jn(),h=J(),f=Zn();function d(p,T){const A=p.size,g=s.getPositions(T);for(let _=0;_<g.length;_++){const y=g[_][0],v=g[_][1];for(let b=-1;b<=7;b++)if(!(y+b<=-1||A<=y+b))for(let R=-1;R<=7;R++)v+R<=-1||A<=v+R||(b>=0&&b<=6&&(R===0||R===6)||R>=0&&R<=6&&(b===0||b===6)||b>=2&&b<=4&&R>=2&&R<=4?p.set(y+b,v+R,!0,!0):p.set(y+b,v+R,!1,!0))}}function w(p){const T=p.size;for(let A=8;A<T-8;A++){const g=A%2===0;p.set(A,6,g,!0),p.set(6,A,g,!0)}}function m(p,T){const A=o.getPositions(T);for(let g=0;g<A.length;g++){const _=A[g][0],y=A[g][1];for(let v=-2;v<=2;v++)for(let b=-2;b<=2;b++)v===-2||v===2||b===-2||b===2||v===0&&b===0?p.set(_+v,y+b,!0,!0):p.set(_+v,y+b,!1,!0)}}function S(p,T){const A=p.size,g=u.getEncodedBits(T);let _,y,v;for(let b=0;b<18;b++)_=Math.floor(b/3),y=b%3+A-8-3,v=(g>>b&1)===1,p.set(_,y,v,!0),p.set(y,_,v,!0)}function C(p,T,A){const g=p.size,_=l.getEncodedBits(T,A);let y,v;for(y=0;y<15;y++)v=(_>>y&1)===1,y<6?p.set(y,8,v,!0):y<8?p.set(y+1,8,v,!0):p.set(g-15+y,8,v,!0),y<8?p.set(8,g-y-1,v,!0):y<9?p.set(8,15-y-1+1,v,!0):p.set(8,15-y-1,v,!0);p.set(g-8,8,1,!0)}function B(p,T){const A=p.size;let g=-1,_=A-1,y=7,v=0;for(let b=A-1;b>0;b-=2)for(b===6&&b--;;){for(let R=0;R<2;R++)if(!p.isReserved(_,b-R)){let F=!1;v<T.length&&(F=(T[v]>>>y&1)===1),p.set(_,b-R,F),y--,y===-1&&(v++,y=7)}if(_+=g,_<0||A<=_){_-=g,g=-g;break}}}function k(p,T,A){const g=new n;A.forEach(function(R){g.put(R.mode.bit,4),g.put(R.getLength(),h.getCharCountIndicator(R.mode,p)),R.write(g)});const _=t.getSymbolTotalCodewords(p),y=c.getTotalCodewordsCount(p,T),v=(_-y)*8;for(g.getLengthInBits()+4<=v&&g.put(0,4);g.getLengthInBits()%8!==0;)g.putBit(0);const b=(v-g.getLengthInBits())/8;for(let R=0;R<b;R++)g.put(R%2?17:236,8);return E(g,p,T)}function E(p,T,A){const g=t.getSymbolTotalCodewords(T),_=c.getTotalCodewordsCount(T,A),y=g-_,v=c.getBlocksCount(T,A),b=g%v,R=v-b,F=Math.floor(g/v),ie=Math.floor(y/v),ur=ie+1,Kt=F-ie,lr=new a(Kt);let He=0;const he=new Array(v),Gt=new Array(v);let ze=0;const hr=new Uint8Array(p.buffer);for(let X=0;X<v;X++){const je=X<R?ie:ur;he[X]=hr.slice(He,He+je),Gt[X]=lr.encode(he[X]),He+=je,ze=Math.max(ze,je)}const Ve=new Uint8Array(g);let Qt=0,q,D;for(q=0;q<ze;q++)for(D=0;D<v;D++)q<he[D].length&&(Ve[Qt++]=he[D][q]);for(q=0;q<Kt;q++)for(D=0;D<v;D++)Ve[Qt++]=Gt[D][q];return Ve}function I(p,T,A,g){let _;if(Array.isArray(p))_=f.fromArray(p);else if(typeof p=="string"){let F=T;if(!F){const ie=f.rawSplit(p);F=u.getBestVersionForData(ie,A)}_=f.fromString(p,F||40)}else throw new Error("Invalid data");const y=u.getBestVersionForData(_,A);if(!y)throw new Error("The amount of data is too big to be stored in a QR Code");if(!T)T=y;else if(T<y)throw new Error(`
162
+ The chosen QR Code version cannot contain this amount of data.
163
+ Minimum version required to store current data is: `+y+`.
164
+ `);const v=k(T,A,_),b=t.getSymbolSize(T),R=new r(b);return d(R,T),w(R),m(R,T),C(R,A,0),T>=7&&S(R,T),B(R,v),isNaN(g)&&(g=i.getBestMask(R,C.bind(null,R,A))),i.applyMask(g,R),C(R,A,g),{modules:R,version:T,errorCorrectionLevel:A,maskPattern:g,segments:_}}return ye.create=function(T,A){if(typeof T>"u"||T==="")throw new Error("No input text");let g=e.M,_,y;return typeof A<"u"&&(g=e.from(A.errorCorrectionLevel,e.M),_=u.from(A.version),y=i.from(A.maskPattern),A.toSJISFunc&&t.setToSJISFunction(A.toSJISFunc)),I(T,_,g,y)},ye}var Ne={},Ue={},Ht;function zt(){return Ht||(Ht=1,(function(t){function e(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let r=n.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+n);(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("")}}t.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||{}}},t.getScale=function(r,o){return o.width&&o.width>=r+o.margin*2?o.width/(r+o.margin*2):o.scale},t.getImageWidth=function(r,o){const s=t.getScale(r,o);return Math.floor((r+o.margin*2)*s)},t.qrToImageData=function(r,o,s){const i=o.modules.size,c=o.modules.data,a=t.getScale(i,s),u=Math.floor((i+s.margin*2)*a),l=s.margin*a,h=[s.color.light,s.color.dark];for(let f=0;f<u;f++)for(let d=0;d<u;d++){let w=(f*u+d)*4,m=s.color.light;if(f>=l&&d>=l&&f<u-l&&d<u-l){const S=Math.floor((f-l)/a),C=Math.floor((d-l)/a);m=h[c[S*i+C]?1:0]}r[w++]=m.r,r[w++]=m.g,r[w++]=m.b,r[w]=m.a}}})(Ue)),Ue}var Vt;function tr(){return Vt||(Vt=1,(function(t){const e=zt();function n(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")}}t.render=function(s,i,c){let a=c,u=i;typeof a>"u"&&(!i||!i.getContext)&&(a=i,i=void 0),i||(u=r()),a=e.getOptions(a);const l=e.getImageWidth(s.modules.size,a),h=u.getContext("2d"),f=h.createImageData(l,l);return e.qrToImageData(f.data,s,a),n(h,u,l),h.putImageData(f,0,0),u},t.renderToDataURL=function(s,i,c){let a=c;typeof a>"u"&&(!i||!i.getContext)&&(a=i,i=void 0),a||(a={});const u=t.render(s,i,a),l=a.type||"image/png",h=a.rendererOpts||{};return u.toDataURL(l,h.quality)}})(Ne)),Ne}var Fe={},jt;function nr(){if(jt)return Fe;jt=1;const t=zt();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 n(o,s,i){let c=o+s;return typeof i<"u"&&(c+=" "+i),c}function r(o,s,i){let c="",a=0,u=!1,l=0;for(let h=0;h<o.length;h++){const f=Math.floor(h%s),d=Math.floor(h/s);!f&&!u&&(u=!0),o[h]?(l++,h>0&&f>0&&o[h-1]||(c+=u?n("M",f+i,.5+d+i):n("m",a,0),a=0,u=!1),f+1<s&&o[h+1]||(c+=n("h",l),l=0)):a++}return c}return Fe.render=function(s,i,c){const a=t.getOptions(i),u=s.modules.size,l=s.modules.data,h=u+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(l,u,a.margin)+'"/>',w='viewBox="0 0 '+h+" "+h+'"',S='<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,S),S},Fe}var Wt;function rr(){if(Wt)return Y;Wt=1;const t=Dn(),e=er(),n=tr(),r=nr();function o(s,i,c,a,u){const l=[].slice.call(arguments,1),h=l.length,f=typeof l[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?(u=c,c=i,i=a=void 0):h===3&&(i.getContext&&typeof u>"u"?(u=a,a=void 0):(u=a,a=c,c=i,i=void 0))}else{if(h<1)throw new Error("Too few arguments provided");return h===1?(c=i,i=a=void 0):h===2&&!i.getContext&&(a=c,c=i,i=void 0),new Promise(function(d,w){try{const m=e.create(c,a);d(s(m,i,a))}catch(m){w(m)}})}try{const d=e.create(c,a);u(null,s(d,i,a))}catch(d){u(d)}}return Y.create=e.create,Y.toCanvas=o.bind(null,n.render),Y.toDataURL=o.bind(null,n.renderToDataURL),Y.toString=o.bind(null,function(s,i,c){return r.render(s,c)}),Y}var or=rr();const sr=qn(or),ir=t=>{var e={errorCorrectionLevel:"H",type:"image/jpeg",margin:1,width:300};let n=null;const r=async a=>{const u=new URL(window.location.href),l=new URL(u.pathname,u.origin);l.searchParams.set("state","1-"+a),console.log("生成登录二维码链接:",l.toString());var h=t||document.getElementById("qrcode");await sr.toDataURL(h,l.toString(),e)},o=async a=>{const u=await fetch(`/api/router?path=wx&key=checkLogin&state=${a}`).then(l=>l.json());if(u.code===200){console.log(u);const l=u.data;l&&(localStorage.setItem("token",l.accessToken),await j.setLoginToken(l)),c(),setTimeout(()=>{ue()},1e3)}else n=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(n),r(a),o(a),console.log("更新二维码")},9e4),c=()=>{clearTimeout(n),clearInterval(i),console.log("停止检测登录状态")};return{createQrcode:r,clear:c}},Ot="wxff97d569b1db16b6",ar=[{id:"password",name:"密码登录",icon:"🔒"},{id:"wechat",name:"微信登录",icon:"💬",appid:"wx9378885c8390e09b"},{id:"wechat-mp",name:"微信公众号登录",icon:"💬",appid:Ot},{id:"phone",name:"手机号登录",icon:"📱"}],Jt=()=>{const t=window.location.hostname;let e=[];switch(t){case"kevisual.xiongxiao.me":e=["password","wechat-mp"];break;case"kevisual.cn":e=["password","wechat"];break;default:e=["password","phone","wechat","wechat-mp"];break}return ar.filter(n=>e.includes(n.id))};console.log("可用登录方式:",Jt().map(t=>t.name).join(", "));class cr extends HTMLElement{selectedMethod="password";loginMethods=Jt();setLoginMethods(e){this.loginMethods=e,this.render()}constructor(){super()}connectedCallback(){this.attachShadow({mode:"open"}),this.render(),this.bindEvents(),In()}#e=null;selectLoginMethod(e){this.selectedMethod=e,this.render(),this.#e&&(this.#e(),this.#e=null)}getMethodData(e){return this.loginMethods.find(n=>n.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 n=e.target;n&&n.id==="loginForm"&&(e.preventDefault(),this.handleLogin())}))}handleLogin(){const e=this.getFormData();En({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"),n=this.shadowRoot.querySelector("#password");return{username:e?.value||"",password:n?.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 $`
166
+ <form id="loginForm" class="login-form">
167
+ <div class="form-group">
168
+ <input
169
+ type="text"
170
+ id="username"
171
+ name="username"
172
+ placeholder="请输入用户名"
173
+ autocomplete="username"
174
+ required
175
+ />
176
+ </div>
177
+ <div class="form-group">
178
+ <input
179
+ type="password"
180
+ id="password"
181
+ name="password"
182
+ placeholder="请输入密码"
183
+ autocomplete="current-password"
184
+ required
185
+ />
186
+ </div>
187
+ <button type="submit" class="login-button">登录</button>
188
+ </form>
189
+ `}renderPhoneForm(){return $`
190
+ <form id="loginForm" class="login-form">
191
+ <div class="form-group">
192
+ <input
193
+ type="tel"
194
+ id="phone"
195
+ name="phone"
196
+ placeholder="请输入手机号"
197
+ pattern="[0-9]{11}"
198
+ autocomplete="tel"
199
+ required
200
+ />
201
+ </div>
202
+ <div class="form-group code-group">
203
+ <input
204
+ type="text"
205
+ id="code"
206
+ name="code"
207
+ placeholder="请输入验证码"
208
+ autocomplete="one-time-code"
209
+ required
210
+ />
211
+ <button type="button" class="code-button" @click=${this.sendVerificationCode}>获取验证码</button>
212
+ </div>
213
+ <button type="submit" class="login-button">登录</button>
214
+ </form>
215
+ `}renderWechatForm(){return $`
216
+ <div class="wechat-login">
217
+ <slot></slot>
218
+ </div>
219
+ `}renderWechatMpForm(){const e=this;return setTimeout(()=>{const n=e.shadowRoot.querySelector("#qrcode"),{clear:r}=ir(n);e.#e=r},0),$`
220
+ <div class="wechat-login">
221
+ <div class="qr-container">
222
+ <div class="qr-placeholder">
223
+ <canvas id='qrcode' width='300' height='300'></canvas>
224
+ <p class="qr-desc">请使用微信扫描二维码登录</p>
225
+ </div>
226
+ </div>
227
+ </div>
228
+ `}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 $n({appid:e?.appid||""}),this.renderWechatForm();case"wechat-mp":return this.renderWechatMpForm();default:return this.renderPasswordForm()}}render(){if(!this.shadowRoot)return;const e=$`
229
+ <style>
230
+ :host {
231
+ display: block;
232
+ width: 100%;
233
+ min-width: 400px;
234
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
235
+ }
236
+
237
+ .login-sidebar {
238
+ background: white;
239
+ border-radius: 12px;
240
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
241
+ overflow: hidden;
242
+ }
243
+
244
+ .login-methods {
245
+ display: flex;
246
+ background: #f8f9fa;
247
+ border-bottom: 1px solid #e9ecef;
248
+ }
249
+
250
+ .login-method {
251
+ flex: 1;
252
+ padding: 16px 8px;
253
+ border: none;
254
+ background: none;
255
+ cursor: pointer;
256
+ display: flex;
257
+ flex-direction: column;
258
+ align-items: center;
259
+ gap: 4px;
260
+ transition: all 0.3s ease;
261
+ position: relative;
262
+ }
263
+
264
+ .login-method:hover {
265
+ background: #e9ecef;
266
+ }
267
+
268
+ .login-method.active {
269
+ background: white;
270
+ color: #007bff;
271
+ }
272
+
273
+ .login-method.active::after {
274
+ content: '';
275
+ position: absolute;
276
+ bottom: 0;
277
+ left: 0;
278
+ right: 0;
279
+ height: 2px;
280
+ background: #007bff;
281
+ }
282
+
283
+ .method-icon {
284
+ font-size: 20px;
285
+ }
286
+
287
+ .method-name {
288
+ font-size: 12px;
289
+ font-weight: 500;
290
+ }
291
+
292
+ .login-content {
293
+ padding: 32px 24px;
294
+ }
295
+ .impowerBox .qrcode {
296
+ width: 200px !important;
297
+ }
298
+ .login-form {
299
+ display: flex;
300
+ flex-direction: column;
301
+ gap: 16px;
302
+ }
303
+
304
+ .form-group {
305
+ position: relative;
306
+ }
307
+
308
+ .form-group input {
309
+ width: 100%;
310
+ padding: 12px 16px;
311
+ border: 2px solid #e9ecef;
312
+ border-radius: 8px;
313
+ font-size: 14px;
314
+ transition: border-color 0.3s ease;
315
+ box-sizing: border-box;
316
+ }
317
+
318
+ .form-group input:focus {
319
+ outline: none;
320
+ border-color: #007bff;
321
+ }
322
+
323
+ .code-group {
324
+ display: flex;
325
+ gap: 12px;
326
+ }
327
+
328
+ .code-group input {
329
+ flex: 1;
330
+ }
331
+
332
+ .code-button {
333
+ padding: 0 16px;
334
+ background: #6c757d;
335
+ color: white;
336
+ border: none;
337
+ border-radius: 8px;
338
+ font-size: 14px;
339
+ cursor: pointer;
340
+ white-space: nowrap;
341
+ transition: background-color 0.3s ease;
342
+ }
343
+
344
+ .code-button:hover {
345
+ background: #5a6268;
346
+ }
347
+
348
+ .login-button {
349
+ padding: 12px;
350
+ background: #007bff;
351
+ color: white;
352
+ border: none;
353
+ border-radius: 8px;
354
+ font-size: 16px;
355
+ font-weight: 500;
356
+ cursor: pointer;
357
+ transition: background-color 0.3s ease;
358
+ }
359
+
360
+ .login-button:hover {
361
+ background: #0056b3;
362
+ }
363
+
364
+ .wechat-login {
365
+ display: flex;
366
+ flex-direction: column;
367
+ align-items: center;
368
+ gap: 20px;
369
+ }
370
+
371
+ .qr-container {
372
+ width: 400px;
373
+ height: 400px;
374
+ border: 2px dashed #e9ecef;
375
+ border-radius: 8px;
376
+ display: flex;
377
+ align-items: center;
378
+ justify-content: center;
379
+ }
380
+
381
+ .qr-placeholder {
382
+ text-align: center;
383
+ color: #6c757d;
384
+ }
385
+
386
+ .qr-icon {
387
+ font-size: 48px;
388
+ margin-bottom: 8px;
389
+ }
390
+
391
+ .qr-desc {
392
+ font-size: 12px;
393
+ margin-top: 4px;
394
+ }
395
+
396
+ .refresh-button {
397
+ padding: 8px 16px;
398
+ background: #6c757d;
399
+ color: white;
400
+ border: none;
401
+ border-radius: 6px;
402
+ font-size: 14px;
403
+ cursor: pointer;
404
+ transition: background-color 0.3s ease;
405
+ }
406
+
407
+ .refresh-button:hover {
408
+ background: #5a6268;
409
+ }
410
+ </style>
411
+
412
+ <div class="login-sidebar">
413
+ <div class="login-methods">
414
+ ${this.loginMethods.map(n=>$`
415
+ <button
416
+ class="login-method ${this.selectedMethod===n.id?"active":""}"
417
+ data-method="${n.id}"
418
+ >
419
+ <span class="method-icon">${n.icon}</span>
420
+ <span class="method-name">${n.name}</span>
421
+ </button>
422
+ `)}
423
+ </div>
424
+
425
+ <div class="login-content">
426
+ ${this.renderLoginForm()}
427
+ </div>
428
+ </div>
429
+ `;tt(e,this.shadowRoot)}}customElements.define("kv-login",cr)}));
package/index.html ADDED
@@ -0,0 +1,84 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>KvMessage Demo</title>
8
+ <script type="module" src="./src/main.ts"></script>
9
+ <style>
10
+ body {
11
+ margin: 0;
12
+ padding: 20px;
13
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
14
+ }
15
+
16
+ .demo-container {
17
+ display: flex;
18
+ flex-direction: column;
19
+ align-items: center;
20
+ gap: 20px;
21
+ padding: 40px 20px;
22
+ }
23
+
24
+ .button-group {
25
+ display: flex;
26
+ gap: 12px;
27
+ flex-wrap: wrap;
28
+ justify-content: center;
29
+ }
30
+
31
+ .demo-button {
32
+ padding: 10px 20px;
33
+ border: none;
34
+ border-radius: 6px;
35
+ cursor: pointer;
36
+ font-size: 14px;
37
+ transition: all 0.2s;
38
+ }
39
+
40
+ .demo-button.success {
41
+ background: #52c41a;
42
+ color: white;
43
+ }
44
+
45
+ .demo-button.success:hover {
46
+ background: #389e0d;
47
+ }
48
+
49
+ .demo-button.error {
50
+ background: #ff4d4f;
51
+ color: white;
52
+ }
53
+
54
+ .demo-button.error:hover {
55
+ background: #cf1322;
56
+ }
57
+
58
+ .demo-button.loading {
59
+ background: #1890ff;
60
+ color: white;
61
+ }
62
+
63
+ .demo-button.loading:hover {
64
+ background: #096dd9;
65
+ }
66
+
67
+ .login-section {
68
+ text-align: center;
69
+ }
70
+ </style>
71
+ </head>
72
+
73
+ <body>
74
+ <div class="demo-container">
75
+ <div class="login-section">
76
+ <h2>登录组件</h2>
77
+ <kv-login id="loginComponent">
78
+ <div id="weixinLogin"></div>
79
+ </kv-login>
80
+ </div>
81
+ </div>
82
+ </body>
83
+
84
+ </html>
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@kevisual/kv-login",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "src/main.ts",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build --config vite-lib.config.ts",
9
+ "build:test": "vite build",
10
+ "prepub": "rm -rf ./dist && pnpm run build:test",
11
+ "pub": "ev deploy ./dist -k kv-login-test -v 0.0.1 -u -y yes"
12
+ },
13
+ "keywords": [],
14
+ "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
15
+ "license": "MIT",
16
+ "packageManager": "pnpm@10.19.0",
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "type": "module",
21
+ "dependencies": {
22
+ "@kevisual/query-login": "^0.0.6",
23
+ "lit-html": "^3.3.1",
24
+ "qrcode": "^1.5.4"
25
+ },
26
+ "exports": {
27
+ ".": "./dist/kv-login.es.js",
28
+ "./kv-login.es.js": "./dist/kv-login.es.js",
29
+ "./kv-login.umd.js": "./dist/kv-login.umd.js"
30
+ }
31
+ }
package/src/main.ts ADDED
@@ -0,0 +1,2 @@
1
+ import './pages/kv-login'
2
+ import './pages/kv-message'