"use strict"; const common_vendor = require("../vendor.js"); const gen_Apis = require("../../gen/Apis.js"); const common_libraries_apiLoading = require("../libraries/apiLoading.js"); 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: "" } }); function login(app) { var _a, _b, _c; const res = common_vendor.index.getSystemInfoSync(); if ((res == null ? void 0 : res.environment) === "wxwork") { (_b = (_a = common_vendor.index) == null ? void 0 : _a.qy) == null ? void 0 : _b.login({ success: function(loginRes) { console.log(loginRes); getWorkToken(app, loginRes.code); } }); } else { (_c = common_vendor.index) == null ? void 0 : _c.login({ provider: "weixin", //使用微信登录 success: function(loginRes) { console.log(loginRes); getWXToken(app, loginRes.code); } }); } } const getWorkToken = (app, code) => { gen_Apis.Apis.Login.Auth.WorkLogin({ code, app_id: "ww8e14f3d20774c997" }).then((res) => { var _a, _b, _c, _d; 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(); if (!((_d = res.data) == null ? void 0 : _d.user)) { common_vendor.index.redirectTo({ url: "/pages/login" }); return false; } }).catch(() => { loading.value = false; hasError.value = true; }); }; const getWXToken = (app, code) => { gen_Apis.Apis.Login.Auth.Login({ code, app_id: "wx09b52ea34b5e8855" }).then((res) => { var _a, _b, _c, _d; 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(); if (!((_d = res.data) == null ? void 0 : _d.user)) { common_vendor.index.redirectTo({ url: "/pages/login" }); return false; } }).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: "wx09b52ea34b5e8855", ...from_data }).then((res) => { me(); }); }; return { loading, hasError, data, login, me, handleUserLogin }; }); exports.useWeAppAuthStore = useWeAppAuthStore;