pay-customer/dist/build/mp-weixin/common/store/useWeAppAuthStore.js
2025-12-15 18:19:04 +08:00

2 lines
1.7 KiB
JavaScript

"use strict";const e=require("../vendor.js"),o=require("../../gen/Apis.js"),s=require("../libraries/apiLoading.js"),u="wx31500e871924b903",n=e.defineStore("we_app_auth",(()=>{const n=e.ref(!0),i=e.ref(!1),a=e.ref(0),t=e.ref({user:{id:0,name:""},work_info:{session_key:"",openid:""},selected_house:{},environment:"",house_occupant:!1,house_register:!1,is_house_exist:0});const l=(s,a)=>{o.Apis.Login.Auth.Login({code:a,app_id:u}).then((o=>{var u,i,a,l;console.log("登录",null==o?void 0:o.data),t.value.user=null==(u=o.data)?void 0:u.user,t.value.selected_house=null==(i=o.data)?void 0:i.selected_house,n.value=!1,e.index.setStorageSync("NCHL_PROD_ACCESS_TOKEN_CUSTOMER",null==(l=null==(a=null==o?void 0:o.data)?void 0:a.token)?void 0:l.token),t.value.user&&r(),null==s||s.appContext.config.globalProperties.$isResolve()})).catch((()=>{n.value=!1,i.value=!0}))},r=()=>{o.Apis.Archive.HouseOccupants.GetCustomerHouseIsExist().then((e=>{var o,s;t.value.house_occupant=(null==(o=e.data)?void 0:o.house_occupant)||!1,t.value.house_register=(null==(s=e.data)?void 0:s.house_register)||!1,t.value.is_house_exist=a.value+1}))};function d(e){s.getApiLoading(o.Apis.Login.Auth.Me,{}).then((o=>{var s;return t.value.user=o.data.user,t.value.selected_house=null==(s=o.data)?void 0:s.selected_house,console.log("me",o.data),n.value=!1,i.value=!1,t.value.user&&r(),null==e?void 0:e()}))}return{loading:n,hasError:i,data:t,login:function(o){e.index.login({provider:"weixin",success:function(e){console.log(e),l(o,e.code)}})},me:d,handleUserLogin:async n=>{s.getApiLoading(o.Apis.Login.Auth.BindPhoneNumber,{app_id:u,...n}).then((o=>{d((()=>{e.index.navigateBack({delta:1})}))}))},getIsHouseExist:r}}));exports.useWeAppAuthStore=n;