"use strict"; const common_vendor = require("../vendor.js"); const gen_Apis = require("../../gen/Apis.js"); const common_libraries_apiLoading = require("../libraries/apiLoading.js"); const wxAppId = "wxa191e69e5e77acca"; const useWeAppAuthStore = common_vendor.defineStore("we_app_auth", () => { const loading = common_vendor.ref(true); const hasError = common_vendor.ref(false); const data = common_vendor.ref({ user: { id: 0, username: "" }, work_info: { session_key: "", openid: "" }, environment: "" }); function login(app) { common_vendor.index.login({ provider: "weixin", //使用微信登录 success: function(loginRes) { console.log(loginRes); getWXToken(app, loginRes.code); } }); } const getWXToken = (app, code) => { gen_Apis.Apis.Login.Auth.Login({ code, app_id: wxAppId }).then((res) => { var _a, _b, _c; console.log("登录", res == null ? void 0 : res.data); data.value.user = (_a = res.data) == null ? void 0 : _a.user; loading.value = false; common_vendor.index.setStorageSync("ACCESS_TOKEN_CUSTOMER", (_c = (_b = res == null ? void 0 : res.data) == null ? void 0 : _b.token) == null ? void 0 : _c.token); app == null ? void 0 : app.appContext.config.globalProperties.$isResolve(); }).catch(() => { loading.value = false; hasError.value = true; }); }; function me() { common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.Me, {}).then((res) => { data.value.user = res.data.user; console.log("me", res.data); loading.value = false; hasError.value = false; }); } const handleUserLogin = async (from_data) => { common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.BindPhoneNumber, { app_id: wxAppId, ...from_data }).then((res) => { common_vendor.index.navigateBack({ delta: 1 }); me(); }); }; return { loading, hasError, data, login, me, handleUserLogin }; }); exports.useWeAppAuthStore = useWeAppAuthStore;