"use strict";const e=require("../vendor.js"),n=require("../../gen/Apis.js"),o=require("../libraries/apiLoading.js"),i="wx04d2d27ca198367b",l=e.defineStore("we_app_auth",(()=>{const l=e.ref(!1),a=e.ref(!1),t=e.ref({user:{id:0,name:"",phone:""},work_info:{session_key:"",openid:""},environment:""});const d=(o,i)=>{n.Apis.Login.Auth.WorkLogin({code:i,app_id:"ww96c806131a95c739"}).then((n=>{var i,a,d,u;console.log("企业微信登录",null==n?void 0:n.data),t.value.user=null==(i=n.data)?void 0:i.user,t.value.work_info=null==(a=n.data)?void 0:a.work_info,l.value=!1,e.index.setStorageSync("NCHL_PROD_ACCESS_TOKEN_CUSTOMER",null==(u=null==(d=null==n?void 0:n.data)?void 0:d.token)?void 0:u.token),null==o||o.appContext.config.globalProperties.$isResolve()})).catch((()=>{l.value=!1,a.value=!0}))},u=(o,d)=>{n.Apis.Login.Auth.Login({code:d,app_id:i}).then((n=>{var i,a,d;console.log("登录",null==n?void 0:n.data),t.value.user=null==(i=n.data)?void 0:i.user,l.value=!1,e.index.setStorageSync("NCHL_PROD_ACCESS_TOKEN_CUSTOMER",null==(d=null==(a=null==n?void 0:n.data)?void 0:a.token)?void 0:d.token),null==o||o.appContext.config.globalProperties.$isResolve()})).catch((()=>{l.value=!1,a.value=!0}))};function s(e){o.getApiLoading(n.Apis.Login.Auth.Me,{}).then((n=>(t.value.user=n.data.user,console.log("me",n.data),l.value=!1,a.value=!1,e())))}return{loading:l,hasError:a,data:t,login:function(n){const o=e.index.getSystemInfoSync();t.value.environment=null==o?void 0:o.environment,console.log(null==o?void 0:o.environment,"res?.environment"),"wxwork"===(null==o?void 0:o.environment)?e.index.qy.login({success:function(e){console.log(e),d(n,e.code)}}):e.index.login({provider:"weixin",success:function(e){console.log(e),u(n,e.code)}})},me:s,handleUserLogin:async l=>{o.getApiLoading(n.Apis.Login.Auth.BindPhoneNumber,{app_id:i,...l}).then((n=>{s((()=>{e.index.navigateBack({delta:1})}))}))},handleUserLoginWxwork:async l=>{var a,d;o.getApiLoading(n.Apis.Login.Auth.BindWork,{app_id:i,session_key:null==(d=null==(a=null==t?void 0:t.value)?void 0:a.work_info)?void 0:d.session_key,iv:null==l?void 0:l.iv,encrypted_data:null==l?void 0:l.encryptedData}).then((n=>{s((()=>{e.index.navigateBack({delta:1})}))}))}}}));exports.useWeAppAuthStore=l;
