UNPKG

bjchy-auth-sdk

Version:

朝阳区认证SDK - 简洁易用的扫码登录和请求工具包

3 lines (2 loc) 49.8 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),t=require("axios"),n={blz:{key:"blz",name:"八里庄街道"},yyc:{key:"yyc",name:"亚运村街道"},hjl:{key:"hjl",name:"呼家楼街道"},jt:{key:"jt",name:"将台地区"},tjh:{key:"tjh",name:"团结湖街道"},ty:{key:"ty",name:"通运街道"}};function o(e=window.location.href){const t=new URLSearchParams(window.location.search).get("street");if(t&&n[t])return t;const o=window.location.pathname.split("/").filter((e=>e));for(const c of o)if(n[c])return c;const r=window.location.hostname.toLowerCase();for(const c in n)if(r.includes(c))return c;const i=Object.keys(n).join("|"),a=new RegExp(`(${i})`,"gi"),s=e.match(a);if(s&&s[0]&&n[s[0].toLowerCase()]){return s[0].toLowerCase()}const l=localStorage.getItem("bjchy_current_street");return l&&n[l]?l:null}function r(e){return n[e]||null}function i(e){n[e]&&(localStorage.setItem("bjchy_current_street",e),"undefined"!=typeof window&&(window.__BJCHY_CURRENT_STREET__=e))}const a={baseURL:"https://pdb.bjchy.gov.cn/mdb3/api",timeout:1e4,tokenKey:"bjchy_token",userKey:"bjchy_user_info",enableAutoDetectStreet:!0,enableTokenAutoRefresh:!0,loginUrl:"/",tokenErrorCodes:["TOKEN_EXPIRED","INVALID_TOKEN","TOKEN_MALFORMED","TOKEN_NOT_ACTIVE","MISSING_TOKEN","MISSING_AUTH_HEADER","INVALID_AUTH_FORMAT","TOKEN_EXTRACTION_ERROR"]};let s={...a};const l=new Set;function c(e={}){console.log("📝 配置SDK:",e);const t={...s,...e};if(e.baseURL&&"string"!=typeof e.baseURL)throw new Error("baseURL 必须是字符串类型");if(e.roule&&"string"!=typeof e.roule)throw new Error("roule 必须是字符串类型");if(e.timeout&&("number"!=typeof e.timeout||e.timeout<=0))throw new Error("timeout 必须是正数");const n={...s};return s=t,l.forEach((e=>{try{e(t,n)}catch(o){console.error("配置监听器执行失败:",o)}})),console.log("✅ SDK配置已更新:",s),s}function u(){return{...s}}function d(e){if("function"!=typeof e)throw new Error("监听器必须是函数");l.add(e)}function g(){const e=u(),n=t.create({baseURL:e.baseURL,timeout:e.timeout,headers:{"Content-Type":"application/json"}});return n.interceptors.request.use((t=>{t.url&&(t.url.startsWith("http://")||t.url.startsWith("https://"))&&(t.baseURL="");const n=localStorage.getItem(e.tokenKey);if(n&&(t.headers.Authorization=`Bearer ${n}`),e.enableAutoDetectStreet){const e=o();e&&(t.headers["X-Street-Key"]=e)}return t}),(e=>Promise.reject(e))),n.interceptors.response.use((t=>{const n=t.data;if(n&&!1===n.success&&n.code&&e.tokenErrorCodes.includes(n.code)){localStorage.removeItem(e.tokenKey),localStorage.removeItem(e.userKey),window.dispatchEvent(new CustomEvent("bjchy-token-expired",{detail:{response:n,streetKey:o()}}));const t=e.loginUrl||"/";return"undefined"!=typeof window&&window.location&&(console.log(`🔄 Token失效(${n.code}),自动跳转到:`,t),console.log("错误信息:",n.error||n.message)),Promise.reject(new Error(n.error||n.message||"Token失效"))}if(e.enableTokenAutoRefresh){const n=t.headers["x-new-token"];n&&localStorage.setItem(e.tokenKey,n)}return t.data}),(t=>{var n;if(401===(null==(n=t.response)?void 0:n.status)){localStorage.removeItem(e.tokenKey),localStorage.removeItem(e.userKey),window.dispatchEvent(new CustomEvent("bjchy-token-expired",{detail:{error:t,streetKey:o()}}));const n=e.loginUrl||"/";"undefined"!=typeof window&&window.location&&(console.log("🔄 Token过期(401),自动跳转到:",n),window.location.href=n)}return Promise.reject(t)})),n.get=(e,t={})=>n({method:"GET",url:e,params:t}),n.post=(e,t={})=>n({method:"POST",url:e,data:t}),n.put=(e,t={})=>n({method:"PUT",url:e,data:t}),n.delete=(e,t={})=>n({method:"DELETE",url:e,params:t}),n}let f=g();d(((e,t)=>{(e.baseURL!==t.baseURL||e.timeout!==t.timeout||e.tokenKey!==t.tokenKey||e.enableAutoDetectStreet!==t.enableAutoDetectStreet||e.enableTokenAutoRefresh!==t.enableTokenAutoRefresh||e.loginUrl!==t.loginUrl||JSON.stringify(e.tokenErrorCodes)!==JSON.stringify(t.tokenErrorCodes))&&(console.log("🔄 全局配置变更,重新创建默认请求实例"),f=g(),Object.setPrototypeOf(p,f),Object.assign(p,f))}));const p=new Proxy(f,{get:(e,t)=>f[t],apply:(e,t,n)=>f.apply(t,n)});var h={},m={},y={};let w;const b=[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];y.getSymbolSize=function(e){if(!e)throw new Error('"version" cannot be null or undefined');if(e<1||e>40)throw new Error('"version" should be in range from 1 to 40');return 4*e+17},y.getSymbolTotalCodewords=function(e){return b[e]},y.getBCHDigit=function(e){let t=0;for(;0!==e;)t++,e>>>=1;return t},y.setToSJISFunction=function(e){if("function"!=typeof e)throw new Error('"toSJISFunc" is not a valid function.');w=e},y.isKanjiModeEnabled=function(){return void 0!==w},y.toSJIS=function(e){return w(e)};var x,v={};function E(){this.buffer=[],this.length=0}(x=v).L={bit:1},x.M={bit:0},x.Q={bit:3},x.H={bit:2},x.isValid=function(e){return e&&void 0!==e.bit&&e.bit>=0&&e.bit<4},x.from=function(e,t){if(x.isValid(e))return e;try{return function(e){if("string"!=typeof e)throw new Error("Param is not a string");switch(e.toLowerCase()){case"l":case"low":return x.L;case"m":case"medium":return x.M;case"q":case"quartile":return x.Q;case"h":case"high":return x.H;default:throw new Error("Unknown EC Level: "+e)}}(e)}catch(n){return t}},E.prototype={get:function(e){const t=Math.floor(e/8);return 1==(this.buffer[t]>>>7-e%8&1)},put:function(e,t){for(let n=0;n<t;n++)this.putBit(1==(e>>>t-n-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++}};var S=E;function k(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)}k.prototype.set=function(e,t,n,o){const r=e*this.size+t;this.data[r]=n,o&&(this.reservedBit[r]=!0)},k.prototype.get=function(e,t){return this.data[e*this.size+t]},k.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},k.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var C=k,I={};!function(e){const t=y.getSymbolSize;e.getRowColCoords=function(e){if(1===e)return[];const n=Math.floor(e/7)+2,o=t(e),r=145===o?26:2*Math.ceil((o-13)/(2*n-2)),i=[o-7];for(let t=1;t<n-1;t++)i[t]=i[t-1]-r;return i.push(6),i.reverse()},e.getPositions=function(t){const n=[],o=e.getRowColCoords(t),r=o.length;for(let e=0;e<r;e++)for(let t=0;t<r;t++)0===e&&0===t||0===e&&t===r-1||e===r-1&&0===t||n.push([o[e],o[t]]);return n}}(I);var N={};const B=y.getSymbolSize;N.getPositions=function(e){const t=B(e);return[[0,0],[t-7,0],[0,t-7]]};var R={};!function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t=3,n=3,o=40,r=10;function i(t,n,o){switch(t){case e.Patterns.PATTERN000:return(n+o)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return o%3==0;case e.Patterns.PATTERN011:return(n+o)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(o/3))%2==0;case e.Patterns.PATTERN101:return n*o%2+n*o%3==0;case e.Patterns.PATTERN110:return(n*o%2+n*o%3)%2==0;case e.Patterns.PATTERN111:return(n*o%3+(n+o)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}}e.isValid=function(e){return null!=e&&""!==e&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){const n=e.size;let o=0,r=0,i=0,a=null,s=null;for(let l=0;l<n;l++){r=i=0,a=s=null;for(let c=0;c<n;c++){let n=e.get(l,c);n===a?r++:(r>=5&&(o+=t+(r-5)),a=n,r=1),n=e.get(c,l),n===s?i++:(i>=5&&(o+=t+(i-5)),s=n,i=1)}r>=5&&(o+=t+(r-5)),i>=5&&(o+=t+(i-5))}return o},e.getPenaltyN2=function(e){const t=e.size;let o=0;for(let n=0;n<t-1;n++)for(let r=0;r<t-1;r++){const t=e.get(n,r)+e.get(n,r+1)+e.get(n+1,r)+e.get(n+1,r+1);4!==t&&0!==t||o++}return o*n},e.getPenaltyN3=function(e){const t=e.size;let n=0,r=0,i=0;for(let o=0;o<t;o++){r=i=0;for(let a=0;a<t;a++)r=r<<1&2047|e.get(o,a),a>=10&&(1488===r||93===r)&&n++,i=i<<1&2047|e.get(a,o),a>=10&&(1488===i||93===i)&&n++}return n*o},e.getPenaltyN4=function(e){let t=0;const n=e.data.length;for(let o=0;o<n;o++)t+=e.data[o];return Math.abs(Math.ceil(100*t/n/5)-10)*r},e.applyMask=function(e,t){const n=t.size;for(let o=0;o<n;o++)for(let r=0;r<n;r++)t.isReserved(r,o)||t.xor(r,o,i(e,r,o))},e.getBestMask=function(t,n){const o=Object.keys(e.Patterns).length;let r=0,i=1/0;for(let a=0;a<o;a++){n(a),e.applyMask(a,t);const o=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(a,t),o<i&&(i=o,r=a)}return r}}(R);var A={};const T=v,L=[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],M=[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];A.getBlocksCount=function(e,t){switch(t){case T.L:return L[4*(e-1)+0];case T.M:return L[4*(e-1)+1];case T.Q:return L[4*(e-1)+2];case T.H:return L[4*(e-1)+3];default:return}},A.getTotalCodewordsCount=function(e,t){switch(t){case T.L:return M[4*(e-1)+0];case T.M:return M[4*(e-1)+1];case T.Q:return M[4*(e-1)+2];case T.H:return M[4*(e-1)+3];default:return}};var P={},K={};const U=new Uint8Array(512),z=new Uint8Array(256);!function(){let e=1;for(let t=0;t<255;t++)U[t]=e,z[e]=t,e<<=1,256&e&&(e^=285);for(let t=255;t<512;t++)U[t]=U[t-255]}(),K.log=function(e){if(e<1)throw new Error("log("+e+")");return z[e]},K.exp=function(e){return U[e]},K.mul=function(e,t){return 0===e||0===t?0:U[z[e]+z[t]]},function(e){const t=K;e.mul=function(e,n){const o=new Uint8Array(e.length+n.length-1);for(let r=0;r<e.length;r++)for(let i=0;i<n.length;i++)o[r+i]^=t.mul(e[r],n[i]);return o},e.mod=function(e,n){let o=new Uint8Array(e);for(;o.length-n.length>=0;){const e=o[0];for(let i=0;i<n.length;i++)o[i]^=t.mul(n[i],e);let r=0;for(;r<o.length&&0===o[r];)r++;o=o.slice(r)}return o},e.generateECPolynomial=function(n){let o=new Uint8Array([1]);for(let r=0;r<n;r++)o=e.mul(o,new Uint8Array([1,t.exp(r)]));return o}}(P);const D=P;function _(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}_.prototype.initialize=function(e){this.degree=e,this.genPoly=D.generateECPolynomial(this.degree)},_.prototype.encode=function(e){if(!this.genPoly)throw new Error("Encoder not initialized");const t=new Uint8Array(e.length+this.degree);t.set(e);const n=D.mod(t,this.genPoly),o=this.degree-n.length;if(o>0){const e=new Uint8Array(this.degree);return e.set(n,o),e}return n};var V=_,j={},F={},O={isValid:function(e){return!isNaN(e)&&e>=1&&e<=40}},H={};const J="[0-9]+";let Y="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Y=Y.replace(/u/g,"\\u");const q="(?:(?![A-Z0-9 $%*+\\-./:]|"+Y+")(?:.|[\r\n]))+";H.KANJI=new RegExp(Y,"g"),H.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),H.BYTE=new RegExp(q,"g"),H.NUMERIC=new RegExp(J,"g"),H.ALPHANUMERIC=new RegExp("[A-Z $%*+\\-./:]+","g");const Q=new RegExp("^"+Y+"$"),$=new RegExp("^"+J+"$"),W=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");H.testKanji=function(e){return Q.test(e)},H.testNumeric=function(e){return $.test(e)},H.testAlphanumeric=function(e){return W.test(e)},function(e){const t=O,n=H;e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(e,n){if(!e.ccBits)throw new Error("Invalid mode: "+e);if(!t.isValid(n))throw new Error("Invalid version: "+n);return n>=1&&n<10?e.ccBits[0]:n<27?e.ccBits[1]:e.ccBits[2]},e.getBestModeForData=function(t){return n.testNumeric(t)?e.NUMERIC:n.testAlphanumeric(t)?e.ALPHANUMERIC:n.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(e){if(e&&e.id)return e.id;throw new Error("Invalid mode")},e.isValid=function(e){return e&&e.bit&&e.ccBits},e.from=function(t,n){if(e.isValid(t))return t;try{return function(t){if("string"!=typeof t)throw new Error("Param is not a string");switch(t.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+t)}}(t)}catch(o){return n}}}(F),function(e){const t=y,n=A,o=v,r=F,i=O,a=t.getBCHDigit(7973);function s(e,t){return r.getCharCountIndicator(e,t)+4}function l(e,t){let n=0;return e.forEach((function(e){const o=s(e.mode,t);n+=o+e.getBitsLength()})),n}e.from=function(e,t){return i.isValid(e)?parseInt(e,10):t},e.getCapacity=function(e,o,a){if(!i.isValid(e))throw new Error("Invalid QR Code version");void 0===a&&(a=r.BYTE);const l=8*(t.getSymbolTotalCodewords(e)-n.getTotalCodewordsCount(e,o));if(a===r.MIXED)return l;const c=l-s(a,e);switch(a){case r.NUMERIC:return Math.floor(c/10*3);case r.ALPHANUMERIC:return Math.floor(c/11*2);case r.KANJI:return Math.floor(c/13);case r.BYTE:default:return Math.floor(c/8)}},e.getBestVersionForData=function(t,n){let i;const a=o.from(n,o.M);if(Array.isArray(t)){if(t.length>1)return function(t,n){for(let o=1;o<=40;o++)if(l(t,o)<=e.getCapacity(o,n,r.MIXED))return o}(t,a);if(0===t.length)return 1;i=t[0]}else i=t;return function(t,n,o){for(let r=1;r<=40;r++)if(n<=e.getCapacity(r,o,t))return r}(i.mode,i.getLength(),a)},e.getEncodedBits=function(e){if(!i.isValid(e)||e<7)throw new Error("Invalid QR Code version");let n=e<<12;for(;t.getBCHDigit(n)-a>=0;)n^=7973<<t.getBCHDigit(n)-a;return e<<12|n}}(j);var X={};const G=y,Z=G.getBCHDigit(1335);X.getEncodedBits=function(e,t){const n=e.bit<<3|t;let o=n<<10;for(;G.getBCHDigit(o)-Z>=0;)o^=1335<<G.getBCHDigit(o)-Z;return 21522^(n<<10|o)};var ee={};const te=F;function ne(e){this.mode=te.NUMERIC,this.data=e.toString()}ne.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},ne.prototype.getLength=function(){return this.data.length},ne.prototype.getBitsLength=function(){return ne.getBitsLength(this.data.length)},ne.prototype.write=function(e){let t,n,o;for(t=0;t+3<=this.data.length;t+=3)n=this.data.substr(t,3),o=parseInt(n,10),e.put(o,10);const r=this.data.length-t;r>0&&(n=this.data.substr(t),o=parseInt(n,10),e.put(o,3*r+1))};var oe=ne;const re=F,ie=["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 ae(e){this.mode=re.ALPHANUMERIC,this.data=e}ae.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},ae.prototype.getLength=function(){return this.data.length},ae.prototype.getBitsLength=function(){return ae.getBitsLength(this.data.length)},ae.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=45*ie.indexOf(this.data[t]);n+=ie.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(ie.indexOf(this.data[t]),6)};var se=ae;const le=F;function ce(e){this.mode=le.BYTE,this.data="string"==typeof e?(new TextEncoder).encode(e):new Uint8Array(e)}ce.getBitsLength=function(e){return 8*e},ce.prototype.getLength=function(){return this.data.length},ce.prototype.getBitsLength=function(){return ce.getBitsLength(this.data.length)},ce.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)};var ue=ce;const de=F,ge=y;function fe(e){this.mode=de.KANJI,this.data=e}fe.getBitsLength=function(e){return 13*e},fe.prototype.getLength=function(){return this.data.length},fe.prototype.getBitsLength=function(){return fe.getBitsLength(this.data.length)},fe.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=ge.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else{if(!(n>=57408&&n<=60351))throw new Error("Invalid SJIS character: "+this.data[t]+"\nMake sure your charset is UTF-8");n-=49472}n=192*(n>>>8&255)+(255&n),e.put(n,13)}};var pe,he=fe,me={exports:{}},ye=me.exports=pe={single_source_shortest_paths:function(e,t,n){var o={},r={};r[t]=0;var i,a,s,l,c,u,d,g=pe.PriorityQueue.make();for(g.push(t,0);!g.empty();)for(s in a=(i=g.pop()).value,l=i.cost,c=e[a]||{})c.hasOwnProperty(s)&&(u=l+c[s],d=r[s],(void 0===r[s]||d>u)&&(r[s]=u,g.push(s,u),o[s]=a));if(void 0!==n&&void 0===r[n]){var f=["Could not find a path from ",t," to ",n,"."].join("");throw new Error(f)}return o},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],o=t;o;)n.push(o),e[o],o=e[o];return n.reverse(),n},find_path:function(e,t,n){var o=pe.single_source_shortest_paths(e,t,n);return pe.extract_shortest_path_from_predecessor_list(o,n)},PriorityQueue:{make:function(e){var t,n=pe.PriorityQueue,o={};for(t in e=e||{},n)n.hasOwnProperty(t)&&(o[t]=n[t]);return o.queue=[],o.sorter=e.sorter||n.default_sorter,o},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};!function(e){const t=F,n=oe,o=se,r=ue,i=he,a=H,s=y,l=ye;function c(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){const o=[];let r;for(;null!==(r=e.exec(n));)o.push({data:r[0],index:r.index,mode:t,length:r[0].length});return o}function d(e){const n=u(a.NUMERIC,t.NUMERIC,e),o=u(a.ALPHANUMERIC,t.ALPHANUMERIC,e);let r,i;s.isKanjiModeEnabled()?(r=u(a.BYTE,t.BYTE,e),i=u(a.KANJI,t.KANJI,e)):(r=u(a.BYTE_KANJI,t.BYTE,e),i=[]);return n.concat(o,r,i).sort((function(e,t){return e.index-t.index})).map((function(e){return{data:e.data,mode:e.mode,length:e.length}}))}function g(e,a){switch(a){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return o.getBitsLength(e);case t.KANJI:return i.getBitsLength(e);case t.BYTE:return r.getBitsLength(e)}}function f(e,a){let l;const c=t.getBestModeForData(e);if(l=t.from(a,c),l!==t.BYTE&&l.bit<c.bit)throw new Error('"'+e+'" cannot be encoded with mode '+t.toString(l)+".\n Suggested mode is: "+t.toString(c));switch(l!==t.KANJI||s.isKanjiModeEnabled()||(l=t.BYTE),l){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new o(e);case t.KANJI:return new i(e);case t.BYTE:return new r(e)}}e.fromArray=function(e){return e.reduce((function(e,t){return"string"==typeof t?e.push(f(t,null)):t.data&&e.push(f(t.data,t.mode)),e}),[])},e.fromString=function(n,o){const r=function(e){const n=[];for(let o=0;o<e.length;o++){const r=e[o];switch(r.mode){case t.NUMERIC:n.push([r,{data:r.data,mode:t.ALPHANUMERIC,length:r.length},{data:r.data,mode:t.BYTE,length:r.length}]);break;case t.ALPHANUMERIC:n.push([r,{data:r.data,mode:t.BYTE,length:r.length}]);break;case t.KANJI:n.push([r,{data:r.data,mode:t.BYTE,length:c(r.data)}]);break;case t.BYTE:n.push([{data:r.data,mode:t.BYTE,length:c(r.data)}])}}return n}(d(n,s.isKanjiModeEnabled())),i=function(e,n){const o={},r={start:{}};let i=["start"];for(let a=0;a<e.length;a++){const s=e[a],l=[];for(let e=0;e<s.length;e++){const c=s[e],u=""+a+e;l.push(u),o[u]={node:c,lastCount:0},r[u]={};for(let e=0;e<i.length;e++){const a=i[e];o[a]&&o[a].node.mode===c.mode?(r[a][u]=g(o[a].lastCount+c.length,c.mode)-g(o[a].lastCount,c.mode),o[a].lastCount+=c.length):(o[a]&&(o[a].lastCount=c.length),r[a][u]=g(c.length,c.mode)+4+t.getCharCountIndicator(c.mode,n))}}i=l}for(let t=0;t<i.length;t++)r[i[t]].end=0;return{map:r,table:o}}(r,o),a=l.find_path(i.map,"start","end"),u=[];for(let e=1;e<a.length-1;e++)u.push(i.table[a[e]].node);return e.fromArray(function(e){return e.reduce((function(e,t){const n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)}),[])}(u))},e.rawSplit=function(t){return e.fromArray(d(t,s.isKanjiModeEnabled()))}}(ee);const we=y,be=v,xe=S,ve=C,Ee=I,Se=N,ke=R,Ce=A,Ie=V,Ne=j,Be=X,Re=F,Ae=ee;function Te(e,t,n){const o=e.size,r=Be.getEncodedBits(t,n);let i,a;for(i=0;i<15;i++)a=1==(r>>i&1),i<6?e.set(i,8,a,!0):i<8?e.set(i+1,8,a,!0):e.set(o-15+i,8,a,!0),i<8?e.set(8,o-i-1,a,!0):i<9?e.set(8,15-i-1+1,a,!0):e.set(8,15-i-1,a,!0);e.set(o-8,8,1,!0)}function Le(e,t,n){const o=new xe;n.forEach((function(t){o.put(t.mode.bit,4),o.put(t.getLength(),Re.getCharCountIndicator(t.mode,e)),t.write(o)}));const r=8*(we.getSymbolTotalCodewords(e)-Ce.getTotalCodewordsCount(e,t));for(o.getLengthInBits()+4<=r&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(0);const i=(r-o.getLengthInBits())/8;for(let a=0;a<i;a++)o.put(a%2?17:236,8);return function(e,t,n){const o=we.getSymbolTotalCodewords(t),r=Ce.getTotalCodewordsCount(t,n),i=o-r,a=Ce.getBlocksCount(t,n),s=o%a,l=a-s,c=Math.floor(o/a),u=Math.floor(i/a),d=u+1,g=c-u,f=new Ie(g);let p=0;const h=new Array(a),m=new Array(a);let y=0;const w=new Uint8Array(e.buffer);for(let S=0;S<a;S++){const e=S<l?u:d;h[S]=w.slice(p,p+e),m[S]=f.encode(h[S]),p+=e,y=Math.max(y,e)}const b=new Uint8Array(o);let x,v,E=0;for(x=0;x<y;x++)for(v=0;v<a;v++)x<h[v].length&&(b[E++]=h[v][x]);for(x=0;x<g;x++)for(v=0;v<a;v++)b[E++]=m[v][x];return b}(o,e,t)}function Me(e,t,n,o){let r;if(Array.isArray(e))r=Ae.fromArray(e);else{if("string"!=typeof e)throw new Error("Invalid data");{let o=t;if(!o){const t=Ae.rawSplit(e);o=Ne.getBestVersionForData(t,n)}r=Ae.fromString(e,o||40)}}const i=Ne.getBestVersionForData(r,n);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(t){if(t<i)throw new Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+i+".\n")}else t=i;const a=Le(t,n,r),s=we.getSymbolSize(t),l=new ve(s);return function(e,t){const n=e.size,o=Se.getPositions(t);for(let r=0;r<o.length;r++){const t=o[r][0],i=o[r][1];for(let o=-1;o<=7;o++)if(!(t+o<=-1||n<=t+o))for(let r=-1;r<=7;r++)i+r<=-1||n<=i+r||(o>=0&&o<=6&&(0===r||6===r)||r>=0&&r<=6&&(0===o||6===o)||o>=2&&o<=4&&r>=2&&r<=4?e.set(t+o,i+r,!0,!0):e.set(t+o,i+r,!1,!0))}}(l,t),function(e){const t=e.size;for(let n=8;n<t-8;n++){const t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}(l),function(e,t){const n=Ee.getPositions(t);for(let o=0;o<n.length;o++){const t=n[o][0],r=n[o][1];for(let n=-2;n<=2;n++)for(let o=-2;o<=2;o++)-2===n||2===n||-2===o||2===o||0===n&&0===o?e.set(t+n,r+o,!0,!0):e.set(t+n,r+o,!1,!0)}}(l,t),Te(l,n,0),t>=7&&function(e,t){const n=e.size,o=Ne.getEncodedBits(t);let r,i,a;for(let s=0;s<18;s++)r=Math.floor(s/3),i=s%3+n-8-3,a=1==(o>>s&1),e.set(r,i,a,!0),e.set(i,r,a,!0)}(l,t),function(e,t){const n=e.size;let o=-1,r=n-1,i=7,a=0;for(let s=n-1;s>0;s-=2)for(6===s&&s--;;){for(let n=0;n<2;n++)if(!e.isReserved(r,s-n)){let o=!1;a<t.length&&(o=1==(t[a]>>>i&1)),e.set(r,s-n,o),i--,-1===i&&(a++,i=7)}if(r+=o,r<0||n<=r){r-=o,o=-o;break}}}(l,a),isNaN(o)&&(o=ke.getBestMask(l,Te.bind(null,l,n))),ke.applyMask(o,l),Te(l,n,o),{modules:l,version:t,errorCorrectionLevel:n,maskPattern:o,segments:r}}m.create=function(e,t){if(void 0===e||""===e)throw new Error("No input text");let n,o,r=be.M;return void 0!==t&&(r=be.from(t.errorCorrectionLevel,be.M),n=Ne.from(t.version),o=ke.from(t.maskPattern),t.toSJISFunc&&we.setToSJISFunction(t.toSJISFunc)),Me(e,n,r,o)};var Pe={},Ke={};!function(e){function t(e){if("number"==typeof e&&(e=e.toString()),"string"!=typeof e)throw new Error("Color should be defined as hex string");let t=e.slice().replace("#","").split("");if(t.length<3||5===t.length||t.length>8)throw new Error("Invalid hex color: "+e);3!==t.length&&4!==t.length||(t=Array.prototype.concat.apply([],t.map((function(e){return[e,e]})))),6===t.length&&t.push("F","F");const n=parseInt(t.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:255&n,hex:"#"+t.slice(0,6).join("")}}e.getOptions=function(e){e||(e={}),e.color||(e.color={});const n=void 0===e.margin||null===e.margin||e.margin<0?4:e.margin,o=e.width&&e.width>=21?e.width:void 0,r=e.scale||4;return{width:o,scale:o?4:r,margin:n,color:{dark:t(e.color.dark||"#000000ff"),light:t(e.color.light||"#ffffffff")},type:e.type,rendererOpts:e.rendererOpts||{}}},e.getScale=function(e,t){return t.width&&t.width>=e+2*t.margin?t.width/(e+2*t.margin):t.scale},e.getImageWidth=function(t,n){const o=e.getScale(t,n);return Math.floor((t+2*n.margin)*o)},e.qrToImageData=function(t,n,o){const r=n.modules.size,i=n.modules.data,a=e.getScale(r,o),s=Math.floor((r+2*o.margin)*a),l=o.margin*a,c=[o.color.light,o.color.dark];for(let e=0;e<s;e++)for(let n=0;n<s;n++){let u=4*(e*s+n),d=o.color.light;if(e>=l&&n>=l&&e<s-l&&n<s-l){d=c[i[Math.floor((e-l)/a)*r+Math.floor((n-l)/a)]?1:0]}t[u++]=d.r,t[u++]=d.g,t[u++]=d.b,t[u]=d.a}}}(Ke),function(e){const t=Ke;e.render=function(e,n,o){let r=o,i=n;void 0!==r||n&&n.getContext||(r=n,n=void 0),n||(i=function(){try{return document.createElement("canvas")}catch(e){throw new Error("You need to specify a canvas element")}}()),r=t.getOptions(r);const a=t.getImageWidth(e.modules.size,r),s=i.getContext("2d"),l=s.createImageData(a,a);return t.qrToImageData(l.data,e,r),function(e,t,n){e.clearRect(0,0,t.width,t.height),t.style||(t.style={}),t.height=n,t.width=n,t.style.height=n+"px",t.style.width=n+"px"}(s,i,a),s.putImageData(l,0,0),i},e.renderToDataURL=function(t,n,o){let r=o;void 0!==r||n&&n.getContext||(r=n,n=void 0),r||(r={});const i=e.render(t,n,r),a=r.type||"image/png",s=r.rendererOpts||{};return i.toDataURL(a,s.quality)}}(Pe);var Ue={};const ze=Ke;function De(e,t){const n=e.a/255,o=t+'="'+e.hex+'"';return n<1?o+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':o}function _e(e,t,n){let o=e+t;return void 0!==n&&(o+=" "+n),o}Ue.render=function(e,t,n){const o=ze.getOptions(t),r=e.modules.size,i=e.modules.data,a=r+2*o.margin,s=o.color.light.a?"<path "+De(o.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",l="<path "+De(o.color.dark,"stroke")+' d="'+function(e,t,n){let o="",r=0,i=!1,a=0;for(let s=0;s<e.length;s++){const l=Math.floor(s%t),c=Math.floor(s/t);l||i||(i=!0),e[s]?(a++,s>0&&l>0&&e[s-1]||(o+=i?_e("M",l+n,.5+c+n):_e("m",r,0),r=0,i=!1),l+1<t&&e[s+1]||(o+=_e("h",a),a=0)):r++}return o}(i,r,o.margin)+'"/>',c='viewBox="0 0 '+a+" "+a+'"',u='<svg xmlns="http://www.w3.org/2000/svg" '+(o.width?'width="'+o.width+'" height="'+o.width+'" ':"")+c+' shape-rendering="crispEdges">'+s+l+"</svg>\n";return"function"==typeof n&&n(null,u),u};const Ve=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then},je=m,Fe=Pe,Oe=Ue;function He(e,t,n,o,r){const i=[].slice.call(arguments,1),a=i.length,s="function"==typeof i[a-1];if(!s&&!Ve())throw new Error("Callback required as last argument");if(!s){if(a<1)throw new Error("Too few arguments provided");return 1===a?(n=t,t=o=void 0):2!==a||t.getContext||(o=n,n=t,t=void 0),new Promise((function(r,i){try{const i=je.create(n,o);r(e(i,t,o))}catch(a){i(a)}}))}if(a<2)throw new Error("Too few arguments provided");2===a?(r=n,n=t,t=o=void 0):3===a&&(t.getContext&&void 0===r?(r=o,o=void 0):(r=o,o=n,n=t,t=void 0));try{const i=je.create(n,o);r(null,e(i,t,o))}catch(l){r(l)}}h.create=je.create,h.toCanvas=He.bind(null,Fe.render),h.toDataURL=He.bind(null,Fe.renderToDataURL),h.toString=He.bind(null,(function(e,t,n){return Oe.render(e,n)}));const Je=async(e,t={})=>{try{const n={...{width:200,height:200,margin:2,color:{dark:"#000000",light:"#FFFFFF"}},...t};return await h.toDataURL(e,n)}catch(n){throw console.error("生成二维码失败:",n),n}},Ye=Je,qe=(e,t)=>{const n=e.__vccOpts||e;for(const[o,r]of t)n[o]=r;return n},Qe={class:"bjchy-qrcode-login",style:{width:"100%","max-width":"400px",margin:"0 auto",padding:"24px",background:"#ffffff","border-radius":"12px","box-shadow":"0 4px 20px rgba(0, 0, 0, 0.08)",border:"1px solid #e5e7eb","font-family":"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif"}},$e={key:0,style:{"text-align":"center","margin-bottom":"32px"}},We={key:0,style:{margin:"0 0 8px 0","font-size":"24px","font-weight":"600",color:"#1f2937","line-height":"1.3"}},Xe={key:1,style:{margin:"0","font-size":"14px",color:"#6b7280","line-height":"1.4"}},Ge={style:{display:"flex","flex-direction":"column","align-items":"center",gap:"20px"}},Ze={key:0,style:{display:"flex","justify-content":"center","align-items":"center",padding:"40px 20px",background:"#fef2f2","border-radius":"12px",border:"2px solid #fecaca",width:"240px","min-height":"240px","box-sizing":"border-box"}},et={style:{"text-align":"center"}},tt={style:{margin:"0","font-size":"14px",color:"#7f1d1d","line-height":"1.4"}},nt={key:1,style:{display:"flex","justify-content":"center","align-items":"center",padding:"20px",background:"#f9fafb","border-radius":"12px",border:"2px dashed #d1d5db"}},ot=["src"],rt={key:2,style:{display:"flex","justify-content":"center","align-items":"center",padding:"40px 20px",background:"#fef2f2","border-radius":"12px",border:"2px solid #fecaca",width:"240px",height:"240px","box-sizing":"border-box"}},it={key:3,style:{display:"flex","justify-content":"center","align-items":"center","flex-direction":"column",padding:"40px 20px",background:"#f3f4f6","border-radius":"12px",border:"2px dashed #d1d5db",width:"240px",height:"240px","box-sizing":"border-box"}},at={key:4,style:{display:"flex","align-items":"center","justify-content":"center",gap:"12px",padding:"16px 20px",background:"#f8fafc","border-radius":"8px",border:"1px solid #e2e8f0","min-height":"20px"}},st={style:{"font-size":"14px","font-weight":"500",color:"#475569","text-align":"center","line-height":"1.4"}},lt=qe({__name:"QrCodeLogin",props:{streetKey:{type:String,default:""},title:{type:String,default:""},subtitle:{type:String,default:""}},emits:["login-success","login-error","status-change"],setup(t,{emit:a}){const s=Object.keys(n),l=async(e,t)=>{x.value=!0,h.value="confirmed",N(),R();const n=u();localStorage.setItem(n.tokenKey,e),localStorage.setItem(n.userKey,JSON.stringify(t)),d("login-success",{token:e,userInfo:t,status:"confirmed"})},c=t,d=a,g=e.ref(""),f=e.ref(""),h=e.ref("waiting"),m=e.ref(null),y=e.ref(6e4),w=e.ref(null),b=e.ref(""),x=e.ref(!1),v=e.computed((()=>{if(c.streetKey)return s.includes(c.streetKey)?c.streetKey:(b.value="无效的标识",null);const e=o();return e&&s.includes(e)?e:(b.value="无法获取配置信息。",null)})),E=e.computed((()=>{if(!v.value)return"";const e=r(v.value);return e?e.name:""})),S=e.computed((()=>({waiting:E.value?`请使用微信扫描${E.value}二维码`:"请使用微信扫描二维码",scanned:"扫描成功,请在手机上确认登录",confirmed:"登录成功,正在跳转...",expired:"二维码已过期,请重新生成"}[h.value]||"请使用微信扫描二维码"))),k=()=>{const e={waiting:"background: #94a3b8;",scanned:"background: #f59e0b;",confirmed:"background: #10b981;",expired:"background: #ef4444;"};return"width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; transition: all 0.3s ease; "+(e[h.value]||e.waiting)},C=async()=>{try{if(x.value)return;if(!v.value)return void d("login-error",{type:"invalid-street-key",error:b.value});N(),R(),i(v.value),f.value=T();const e=u().roule||"",t=`https://pdb.bjchy.gov.cn/publicfiles/webcode/${v.value}/t=scanwebcode&t=scanwebcode&id=${f.value}&p=login&roule=${e}`;g.value=await Ye(t,{width:200,height:200}),h.value="waiting",I(),B(),d("status-change",{status:"generated",sessionId:f.value,streetKey:v.value})}catch(e){console.error("生成二维码失败:",e),N(),R(),d("login-error",{type:"qrcode-generation-failed",error:e})}},I=()=>{x.value||(N(),m.value=setInterval((async()=>{try{if(x.value||!f.value||!v.value)return void N();const e=await p.post("https://pdb.bjchy.gov.cn/mdb3/api/auth/statuscheck",{sessionId:f.value,streetKey:v.value});e.success&&e.data?"confirmed"===e.data.status?await l(e.data.token,e.data.userInfo):"scanned"===e.data.status&&(h.value="scanned",d("status-change",{status:"scanned"})):e.message&&e.message.includes("过期")&&(h.value="expired",N(),R(),d("status-change",{status:"expired"}))}catch(e){console.error("检查登录状态失败:",e)}}),2e3))},N=()=>{m.value&&(clearInterval(m.value),m.value=null)},B=()=>{R(),y.value=6e4,w.value=setInterval((()=>{y.value-=100,y.value<=0&&(h.value="expired",N(),R(),d("status-change",{status:"timeout"}))}),100)},R=()=>{w.value&&(clearInterval(w.value),w.value=null)},A=()=>{v.value&&(N(),R(),setTimeout((()=>{C()}),100))},T=(e=16)=>{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let o=0;o<e;o++)n+=t.charAt(Math.floor(62*Math.random()));return n};e.watch((()=>c.streetKey),(()=>{b.value="",v.value&&(N(),R(),setTimeout((()=>{C()}),100))}),{immediate:!1});const L=()=>{document.hidden&&!x.value?(N(),R()):!document.hidden&&!x.value&&v.value&&f.value&&(I(),B())};return e.onMounted((async()=>{if(v.value){await(async()=>{const e=new URLSearchParams(window.location.search).get("sid");if(e)try{f.value=e,console.log("检测到URL中的sessionId,尝试直接登录...");const t=await p.post("https://pdb.bjchy.gov.cn/mdb3/api/auth/statuscheck",{sessionId:e,streetKey:v.value}),{status:n,token:o,userInfo:r}=t.data;return"confirmed"===n&&o?(console.log("URL sessionId登录成功"),await l(o,r),!0):(console.log("URL sessionId登录失败,状态为:",n),!1)}catch(t){return console.error("URL sessionId登录失败:",t),!1}return!1})()||C()}document.addEventListener("visibilitychange",L)})),e.onUnmounted((()=>{x.value=!0,N(),R(),document.removeEventListener("visibilitychange",L)})),(t,n)=>(e.openBlock(),e.createElementBlock("div",Qe,[c.title||c.subtitle?(e.openBlock(),e.createElementBlock("div",$e,[c.title?(e.openBlock(),e.createElementBlock("h2",We,e.toDisplayString(c.title),1)):e.createCommentVNode("",!0),c.subtitle?(e.openBlock(),e.createElementBlock("p",Xe,e.toDisplayString(c.subtitle),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.createElementVNode("div",Ge,[b.value?(e.openBlock(),e.createElementBlock("div",Ze,[e.createElementVNode("div",et,[n[0]||(n[0]=e.createElementVNode("div",{style:{width:"48px",height:"48px",background:"#fca5a5","border-radius":"50%",display:"flex","align-items":"center","justify-content":"center",margin:"0 auto 16px"}},[e.createElementVNode("span",{style:{color:"#991b1b","font-size":"24px","font-weight":"bold"}},"!")],-1)),n[1]||(n[1]=e.createElementVNode("p",{style:{margin:"0 0 8px 0","font-size":"16px",color:"#991b1b","font-weight":"600"}},"配置错误",-1)),e.createElementVNode("p",tt,e.toDisplayString(b.value),1)])])):g.value&&"expired"!==h.value?(e.openBlock(),e.createElementBlock("div",nt,[e.createElementVNode("img",{src:g.value,alt:"登录二维码",style:{width:"200px",height:"200px","border-radius":"8px",display:"block"}},null,8,ot)])):"expired"===h.value?(e.openBlock(),e.createElementBlock("div",rt,[e.createElementVNode("div",{style:{"text-align":"center"}},[n[2]||(n[2]=e.createElementVNode("p",{style:{margin:"0 0 16px 0","font-size":"16px",color:"#991b1b","font-weight":"500"}},"二维码已过期",-1)),e.createElementVNode("button",{onClick:A,style:{background:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",color:"white",border:"none",padding:"12px 24px","border-radius":"8px","font-size":"14px","font-weight":"500",cursor:"pointer","box-shadow":"0 2px 8px rgba(59, 130, 246, 0.3)"}}," 刷新二维码 ")])])):b.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",it,n[3]||(n[3]=[e.createElementVNode("div",{style:{width:"24px",height:"24px",border:"3px solid #e5e7eb","border-top":"3px solid #3b82f6","border-radius":"50%",animation:"spin 1s linear infinite","margin-bottom":"16px"}},null,-1),e.createElementVNode("p",{style:{margin:"0","font-size":"14px",color:"#6b7280","text-align":"center"}},"正在生成二维码...",-1)]))),b.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",at,[e.createElementVNode("span",st,e.toDisplayString(S.value),1),e.createElementVNode("div",{style:e.normalizeStyle(k())},null,4)]))])]))}},[["__scopeId","data-v-9b2ff3bb"]]),ct=["aria-label","disabled"],ut=["placeholder","disabled"],dt=["disabled"],gt=["onClick"],ft={style:{fontWeight:"500",color:"#1f2937"}},pt={style:{fontSize:"12px",color:"#6b7280",marginTop:"2px"}},ht={key:0,style:{color:"#9ca3af",marginLeft:"8px"}},mt=["disabled"];const yt=qe({name:"MapLocationPicker",props:{lat:{type:Number,default:null},lng:{type:Number,default:null}},emits:["location-selected"],setup(t,{emit:n}){const o=e.ref(!1),r=e.ref(null),i=e.ref(null),a=e.ref(""),s=e.ref([]),l=e.ref(""),c=e.ref(!1),u=e.ref(!1);let d=null,g=null,f=null;const p=e.reactive({lat:null!==t.lat?t.lat:39.921489,lng:null!==t.lng?t.lng:116.486409}),h=e.computed((()=>null!==t.lat&&null!==t.lng));e.watch((()=>[t.lat,t.lng]),(([e,t],[n,o])=>{e===n&&t===o||null!==e&&null!==t&&(console.log("📍 Props坐标变化,更新地图中心:",{lat:e,lng:t}),d?x(e,t,!0):(p.lat=e,p.lng=t))}),{immediate:!1,deep:!1});const m=()=>{o.value=!1,s.value=[],a.value="",l.value="",d&&(d.destroy(),d=null),g=null,f=null},y=async()=>{try{await new Promise(((e,t)=>{if(window.AMap)return void e();const n=document.createElement("script");n.src="https://webapi.amap.com/maps?v=2.0&key=db7f33a6e7e61fa5ba565b5b922c28f4",n.onload=()=>e(),n.onerror=()=>t(new Error("高德地图API加载失败")),document.head.appendChild(n)})),d=new window.AMap.Map(r.value,{zoom:15,center:[p.lng,p.lat],mapStyle:"amap://styles/normal",showLabel:!0}),await new Promise(((e,t)=>{window.AMap.plugin(["AMap.Geocoder","AMap.PlaceSearch"],(function(){try{g=new window.AMap.Geocoder({radius:1e3,extensions:"all"}),f=new window.AMap.PlaceSearch({pageSize:10,pageIndex:1,city:"全国",map:d,autoFitView:!1}),e()}catch(n){t(n)}}))})),d.on("moveend",w),await b()}catch(e){throw console.error("地图初始化失败:",e),e}},w=async()=>{const e=d.getCenter();p.lat=e.lat,p.lng=e.lng,await b()},b=async()=>{if(g)try{c.value=!0;const e=await new Promise(((e,t)=>{g.getAddress([p.lng,p.lat],((n,o)=>{"complete"===n&&o.regeocode?e(o.regeocode.formattedAddress):t(new Error("地址解析失败"))}))}));l.value=e}catch(e){console.error("获取地址失败:",e),l.value="地址解析失败"}finally{c.value=!1}},x=(e,t,n=!0)=>{if(d)try{n?d.panTo([t,e],500):d.setCenter([t,e]),p.lat=e,p.lng=t,b()}catch(o){console.error("更新地图中心点失败:",o)}},v={position:"relative",width:window.innerWidth<=768?"95vw":"80vw",height:window.innerWidth<=768?"90vh":"80vh",maxWidth:"1000px",maxHeight:"800px",backgroundColor:"white",borderRadius:"12px",overflow:"hidden",boxShadow:"0 20px 60px rgba(0, 0, 0, 0.3)",animation:"slideIn 0.3s ease"},E={position:"absolute",top:"16px",left:"16px",right:window.innerWidth<=768?"64px":"72px",zIndex:"1000",display:"flex",gap:"8px"},S={position:"absolute",top:"60px",left:"16px",right:window.innerWidth<=768?"64px":"72px",maxHeight:"200px",overflowY:"auto",backgroundColor:"white",borderRadius:"8px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",zIndex:"1001",border:"1px solid #e5e7eb"};return e.onUnmounted((()=>{d&&d.destroy(),g=null,f=null})),{showMapDialog:o,mapContainer:r,searchInput:i,searchKeyword:a,searchResults:s,currentAddress:l,isLoading:c,isInitializing:u,hasCoordinates:h,openMapDialog:async()=>{try{u.value=!0,o.value=!0,await e.nextTick(),await y()}catch(t){console.error("打开地图失败:",t);let e="地图加载失败,请检查网络连接";t.message.includes("Geocoder")?e="地理编码服务加载失败,请刷新页面重试":t.message.includes("高德地图API加载失败")&&(e="高德地图API加载失败,请检查网络连接"),alert(e),o.value=!1}finally{u.value=!1}},closeMapDialog:m,searchLocation:async()=>{if(a.value.trim()&&f)try{c.value=!0,s.value=[],await new Promise(((e,t)=>{f.search(a.value,((t,n)=>{"complete"===t&&n.poiList&&n.poiList.pois?(s.value=n.poiList.pois.map((e=>({name:e.name,address:e.address,location:[e.location.lng,e.location.lat],district:e.adname||e.cityname||""}))),e()):(s.value=[],console.warn("搜索结果为空或搜索失败:",t,n),e())}))}))}catch(e){console.error("搜索失败:",e),s.value=[],alert("搜索失败,请重试")}finally{c.value=!1}},selectSearchResult:e=>{const[t,n]=e.location;l.value=e.address,d?x(n,t,!0):(p.lat=n,p.lng=t),s.value=[],a.value=""},confirmSelection:()=>{const e={lat:p.lat,lng:p.lng};l.value&&"地址解析失败"!==l.value&&(e.address=l.value),n("location-selected",e),m()},updateMapCenter:x,buttonStyle:{background:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",color:"white",border:"none",borderRadius:"8px",padding:"12px 24px",fontSize:"14px",fontWeight:"500",cursor:"pointer",boxShadow:"0 2px 8px rgba(59, 130, 246, 0.3)",transition:"all 0.3s ease",outline:"none"},overlayStyle:{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"9999",animation:"fadeIn 0.3s ease"},mapContainerStyle:v,searchContainerStyle:E,searchInputStyle:{flex:"1",padding:"12px 16px",border:"1px solid #d1d5db",borderRadius:"8px",fontSize:"14px",outline:"none",backgroundColor:"white",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.1)"},searchButtonStyle:{padding:"12px 16px",background:"#3b82f6",color:"white",border:"none",borderRadius:"8px",cursor:"pointer",fontSize:"14px",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.1)",transition:"background 0.2s ease"},searchResultsStyle:S,searchResultItemStyle:{padding:"12px 16px",cursor:"pointer",borderBottom:"1px solid #f3f4f6",transition:"background 0.2s ease"},mapDisplayStyle:{width:"100%",height:"100%",position:"relative"},centerMarkerStyle:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -100%)",fontSize:"24px",zIndex:"999",pointerEvents:"none",filter:"drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3))"},addressDisplayStyle:{position:"absolute",bottom:"80px",left:"16px",right:"16px",backgroundColor:"rgba(255, 255, 255, 0.95)",padding:"12px 16px",borderRadius:"8px",fontSize:"14px",color:"#374151",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.1)",textAlign:"center",zIndex:"1000"},confirmButtonStyle:{position:"absolute",bottom:"16px",left:"50%",transform:"translateX(-50%)",background:"linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)",color:"white",border:"none",borderRadius:"8px",padding:"12px 32px",fontSize:"14px",fontWeight:"500",cursor:"pointer",boxShadow:"0 4px 12px rgba(59, 130, 246, 0.4)",transition:"all 0.3s ease",zIndex:"1000",outline:"none"},closeButtonStyle:{position:"absolute",top:"16px",right:"16px",width:"40px",height:"40px",backgroundColor:"rgba(255, 255, 255, 0.9)",border:"none",borderRadius:"50%",cursor:"pointer",fontSize:"16px",color:"#6b7280",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.1)",transition:"all 0.2s ease",zIndex:"1000",outline:"none"}}}},[["render",function(t,n,o,r,i,a){return e.openBlock(),e.createElementBlock("div",null,[e.createElementVNode("button",{onClick:n[0]||(n[0]=(...e)=>r.openMapDialog&&r.openMapDialog(...e)),style:e.normalizeStyle(r.buttonStyle),"aria-label":r.hasCoordinates?"选择位置":"开始定位",disabled:r.isInitializing,class:"location-picker-btn"},e.toDisplayString(r.isInitializing?"⏳ 地图加载中...":"📍 "+(r.hasCoordinates?"选择位置":"开始定位")),13,ct),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[r.showMapDialog?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(r.overlayStyle),onClick:n[7]||(n[7]=(...e)=>r.closeMapDialog&&r.closeMapDialog(...e)),class:"map-overlay"},[e.createElementVNode("div",{style:e.normalizeStyle(r.mapContainerStyle),onClick:n[6]||(n[6]=e.withModifiers((()=>{}),["stop"])),class:"map-container"},[e.createElementVNode("div",{style:e.normalizeStyle(r.searchContainerStyle)},[e.withDirectives(e.createElementVNode("input",{ref:"searchInput","onUpdate:modelValue":n[1]||(n[1]=e=>r.searchKeyword=e),onKeyup:n[2]||(n[2]=e.withKeys(((...e)=>r.searchLocation&&r.searchLocation(...e)),["enter"])),style:e.normalizeStyle(r.searchInputStyle),placeholder:r.isLoading?"搜索中...":"搜索地点...",disabled:r.isLoading,"aria-label":"搜索地点"},null,44,ut),[[e.vModelText,r.searchKeyword]]),e.createElementVNode("button",{onClick:n[3]||(n[3]=(...e)=>r.searchLocation&&r.searchLocation(...e)),style:e.normalizeStyle(r.searchButtonStyle),disabled:!r.searchKeyword.trim()||r.isLoading,"aria-label":"搜索"},e.toDisplayString(r.isLoading?"⏳":"🔍"),13,dt)],4),r.searchResults.length>0?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(r.searchResultsStyle),class:"search-results"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.searchResults,((t,n)=>(e.openBlock(),e.createElementBlock("div",{key:n,onClick:e=>r.selectSearchResult(t),style:e.normalizeStyle(r.searchResultItemStyle),class:"search-result-item"},[e.createElementVNode("div",ft,e.toDisplayString(t.name),1),e.createElementVNode("div",pt,[e.createTextVNode(e.toDisplayString(t.address)+" ",1),t.district?(e.openBlock(),e.createElementBlock("span",ht," · "+e.toDisplayString(t.district),1)):e.createCommentVNode("",!0)])],12,gt)))),128))],4)):e.createCommentVNode("",!0),e.createElementVNode("div",{ref:"mapContainer",style:e.normalizeStyle(r.mapDisplayStyle),class:"map-display"},null,4),e.createElementVNode("div",{style:e.normalizeStyle(r.centerMarkerStyle),class:"center-marker"}," 📍 ",4),r.currentAddress?(e.openBlock(),e.createElementBlock("div",{key:1,style:e.normalizeStyle(r.addressDisplayStyle),class:"address-display"},e.toDisplayString(r.currentAddress),5)):e.createCommentVNode("",!0),e.createElementVNode("button",{onClick:n[4]||(n[4]=(...e)=>r.confirmSelection&&r.confirmSelection(...e)),style:e.normalizeStyle(r.confirmButtonStyle),disabled:r.isLoading,class:"confirm-btn","aria-label":"确认选择当前位置"},e.toDisplayString(r.isLoading?"定位中...":"确认选择"),13,mt),e.createElementVNode("button",{onClick:n[5]||(n[5]=(...e)=>r.closeMapDialog&&r.closeMapDialog(...e)),style:e.normalizeStyle(r.closeButtonStyle),class:"close-btn","aria-label":"关闭地图"}," ✕ ",4)],4)],4)):e.createCommentVNode("",!0)]))])}],["__scopeId","data-v-85492a9d"]]),wt=()=>{const e=u(),t=localStorage.getItem(e.tokenKey),n=localStorage.getItem(e.userKey);if(!t)return{isLoggedIn:!1,token:null,userInfo:null};try{return{isLoggedIn:!0,token:t,userInfo:n?JSON.parse(n):null}}catch(o){return console.error("解析用户信息失败:",o),localStorage.removeItem(e.userKey),{isLoggedIn:!!t,token:t,userInfo:null}}};const bt={install:function(e,t={}){(t.baseURL||t.timeout||t.roule||t.tokenKey||t.userKey||t.loginUrl||t.tokenErrorCodes)&&(console.log("🔧 通过Vue插件配置SDK:",t),c(t)),e.component("QrCodeLogin",lt),e.component("MapLocationPicker",yt);const n=t.streetKey||o();n&&i(n),e.config.globalProperties.$bjchyAuth={request:p,streetKey:n,detectStreetKey:o,setCurrentStreet:i},e.provide("bjchyAuth",{request:p,streetKey:n,detectStreetKey:o,setCurrentStreet:i})}};exports.MapLocationPicker=yt,exports.QrCodeLogin=lt,exports.addConfigListener=d,exports.checkLoginStatus=wt,exports.configureSDK=c,exports.default=bt,exports.detectStreetKey=o,exports.generateQRCode=Je,exports.generateQRCodeImage=Ye,exports.getConfigValue=function(e){return s[e]},exports.getCurrentStreetKey=function(){if("undefined"!=typeof window&&window.__BJCHY_CURRENT_STREET__)return window.__BJCHY_CURRENT_STREET__;const e=localStorage.getItem("bjchy_current_street");return e&&n[e]?e:o()},exports.getCurrentToken=()=>{const e=u();return localStorage.getItem(e.tokenKey)},exports.getCurrentUser=()=>{const{userInfo:e}=wt();return e},exports.getSDKConfig=u,exports.getStreetConfig=r,exports.logout=async(e={})=>{const{clearLocal:t=!0,sendRequest:n=!0}=e;try{const e={success:!0,localCleared:!1,serverNotified:!1},r=u();if(n)try{if(localStorage.getItem(r.tokenKey)){const t=await p.get("/auth/logout");e.serverNotified=!0,console.log("服务器退出成功:",t)}}catch(o){console.warn("服务器退出请求失败:",o)}return t&&(localStorage.removeItem(r.tokenKey),localStorage.removeItem(r.userKey),e.localCleared=!0,console.log("本地认证信息已清除")),e}catch(o){return console.error("退出登录失败:",o),{success:!1,error:o.message||"退出登录失败",localCleared:!1,serverNotified:!1}}},exports.printConfig=function(){console.group("🔧 当前SDK配置"),Object.entries(s).forEach((([e,t])=>{console.log(`${e}:`,t)})),console.groupEnd()},exports.removeConfigListener=function(e){l.delete(e)},exports.request=p,exports.resetSDKConfig=function(){console.log("🔄 重置SDK配置为默认值"),c(a)},exports.setCurrentStreet=i,exports.validateConfig=function(){const e=[];return s.baseURL?"string"!=typeof s.baseURL?e.push("baseURL 必须是字符串"):s.baseURL.startsWith("http")||e.push("baseURL 必须以 http:// 或 https:// 开头"):e.push("baseURL 不能为空"),s.timeout<=0&&e.push("timeout 必须大于 0"),s.tokenKey&&"string"==typeof s.tokenKey||e.push("tokenKey 不能为空且必须是字符串"),s.userKey&&"string"==typeof s.userKey||e.push("userKey 不能为空且必须是字符串"),{valid:0===e.length,errors:e}}; //# sourceMappingURL=index.cjs.js.map