pay-customer/dist/dev/mp-weixin/common/store/useWeAppAuthStore.js
2026-01-14 16:52:59 +08:00

91 lines
3.1 KiB
JavaScript

"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 = "wx31500e871924b903";
const useWeAppAuthStore = common_vendor.defineStore("we_app_auth", () => {
const loading = common_vendor.ref(true);
const hasError = common_vendor.ref(false);
const is_house_exist = common_vendor.ref(0);
const data = common_vendor.ref({
user: { id: 0, name: "" },
work_info: { session_key: "", openid: "" },
selected_house: {},
environment: "",
house_occupant: false,
house_register: false,
is_house_exist: 0,
config: {}
});
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, _d, _e;
console.log("登录", res == null ? void 0 : res.data);
data.value.user = (_a = res.data) == null ? void 0 : _a.user;
data.value.selected_house = (_b = res.data) == null ? void 0 : _b.selected_house;
data.value.config = (_c = res.data) == null ? void 0 : _c.config;
loading.value = false;
common_vendor.index.setStorageSync("ACCESS_TOKEN_CUSTOMER", (_e = (_d = res == null ? void 0 : res.data) == null ? void 0 : _d.token) == null ? void 0 : _e.token);
if (data.value.user) {
getIsHouseExist();
}
app == null ? void 0 : app.appContext.config.globalProperties.$isResolve();
}).catch(() => {
loading.value = false;
hasError.value = true;
});
};
const getIsHouseExist = () => {
gen_Apis.Apis.Archive.HouseOccupants.GetCustomerHouseIsExist().then((res) => {
var _a, _b;
data.value.house_occupant = ((_a = res.data) == null ? void 0 : _a.house_occupant) || false;
data.value.house_register = ((_b = res.data) == null ? void 0 : _b.house_register) || false;
data.value.is_house_exist = is_house_exist.value + 1;
});
};
function me(fun) {
common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.Me, {}).then((res) => {
var _a;
data.value.user = res.data.user;
data.value.selected_house = (_a = res.data) == null ? void 0 : _a.selected_house;
console.log("me", res.data);
loading.value = false;
hasError.value = false;
if (data.value.user) {
getIsHouseExist();
}
return fun == null ? void 0 : fun();
});
}
const handleUserLogin = async (from_data) => {
common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.BindPhoneNumber, {
app_id: wxAppId,
...from_data
}).then((res) => {
me(() => {
common_vendor.index.navigateBack({ delta: 1 });
});
});
};
return {
loading,
hasError,
data,
login,
me,
handleUserLogin,
getIsHouseExist
};
});
exports.useWeAppAuthStore = useWeAppAuthStore;