pay-customer/dist/dev/mp-weixin/common/store/useWeAppAuthStore.js

91 lines
3.1 KiB
JavaScript
Raw Normal View History

2025-07-15 16:18:34 +08:00
"use strict";
const common_vendor = require("../vendor.js");
const gen_Apis = require("../../gen/Apis.js");
const common_libraries_apiLoading = require("../libraries/apiLoading.js");
2025-08-29 09:51:02 +08:00
const wxAppId = "wx31500e871924b903";
2025-07-15 16:18:34 +08:00
const useWeAppAuthStore = common_vendor.defineStore("we_app_auth", () => {
const loading = common_vendor.ref(true);
const hasError = common_vendor.ref(false);
2025-12-15 18:19:04 +08:00
const is_house_exist = common_vendor.ref(0);
2025-07-15 16:18:34 +08:00
const data = common_vendor.ref({
2025-08-29 09:51:02 +08:00
user: { id: 0, name: "" },
2025-07-15 16:18:34 +08:00
work_info: { session_key: "", openid: "" },
2025-08-29 09:51:02 +08:00
selected_house: {},
environment: "",
house_occupant: false,
2025-12-15 18:19:04 +08:00
house_register: false,
2026-01-14 16:52:59 +08:00
is_house_exist: 0,
config: {}
2025-07-15 16:18:34 +08:00
});
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) => {
2026-01-14 16:52:59 +08:00
var _a, _b, _c, _d, _e;
2025-07-15 16:18:34 +08:00
console.log("登录", res == null ? void 0 : res.data);
data.value.user = (_a = res.data) == null ? void 0 : _a.user;
2025-08-29 09:51:02 +08:00
data.value.selected_house = (_b = res.data) == null ? void 0 : _b.selected_house;
2026-01-14 16:52:59 +08:00
data.value.config = (_c = res.data) == null ? void 0 : _c.config;
2025-07-15 16:18:34 +08:00
loading.value = false;
2026-01-14 16:52:59 +08:00
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);
2025-08-29 09:51:02 +08:00
if (data.value.user) {
getIsHouseExist();
}
2025-07-15 16:18:34 +08:00
app == null ? void 0 : app.appContext.config.globalProperties.$isResolve();
}).catch(() => {
loading.value = false;
hasError.value = true;
});
};
2025-08-29 09:51:02 +08:00
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;
2025-12-15 18:19:04 +08:00
data.value.is_house_exist = is_house_exist.value + 1;
2025-08-29 09:51:02 +08:00
});
};
function me(fun) {
2025-07-15 16:18:34 +08:00
common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.Me, {}).then((res) => {
2025-08-29 09:51:02 +08:00
var _a;
2025-07-15 16:18:34 +08:00
data.value.user = res.data.user;
2025-08-29 09:51:02 +08:00
data.value.selected_house = (_a = res.data) == null ? void 0 : _a.selected_house;
2025-07-15 16:18:34 +08:00
console.log("me", res.data);
loading.value = false;
hasError.value = false;
2025-08-29 09:51:02 +08:00
if (data.value.user) {
getIsHouseExist();
}
return fun == null ? void 0 : fun();
2025-07-15 16:18:34 +08:00
});
}
const handleUserLogin = async (from_data) => {
common_libraries_apiLoading.getApiLoading(gen_Apis.Apis.Login.Auth.BindPhoneNumber, {
app_id: wxAppId,
...from_data
}).then((res) => {
2025-08-29 09:51:02 +08:00
me(() => {
common_vendor.index.navigateBack({ delta: 1 });
});
2025-07-15 16:18:34 +08:00
});
};
return {
loading,
hasError,
data,
login,
me,
2025-12-15 18:19:04 +08:00
handleUserLogin,
getIsHouseExist
2025-07-15 16:18:34 +08:00
};
});
exports.useWeAppAuthStore = useWeAppAuthStore;