"use strict"; const common_vendor = require("../common/vendor.js"); const utils_uuid = require("../utils/uuid.js"); const apiservice_apiService = require("../apiservice/apiService.js"); const useUserStore = common_vendor.defineStore("user", { state: () => ({ id: "", uuid: "", createdAt: "", username: "", avatarUrl: "", sex: "", // 'male' / 'female' / 'unknown' phone: "" }), actions: { async initUser() { var _a, _b; const info = common_vendor.index.getStorageSync("user_info"); if (info && info.uuid) { Object.assign(this, info); } else { const randomUUID = utils_uuid.generateUUIDv4(); const createdAt = (/* @__PURE__ */ new Date()).toISOString(); const emptyUser = { id: "", uuid: randomUUID, createdAt, username: "", avatarUrl: "", sex: "", phone: "" }; try { const res = await apiservice_apiService.apiService.touristAdd(emptyUser); if (res.code === 1e3) { common_vendor.index.__f__("log", "at stores/user.js:38", "游客添加成功:", (_a = res.data) == null ? void 0 : _a.id); emptyUser.id = (_b = res.data) == null ? void 0 : _b.id; } else { common_vendor.index.__f__("warn", "at stores/user.js:41", "游客添加失败:", res.message); } } catch (err) { common_vendor.index.__f__("error", "at stores/user.js:44", "游客上报错误:", err); } Object.assign(this, emptyUser); common_vendor.index.__f__("log", "at stores/user.js:47", emptyUser); common_vendor.index.setStorageSync("user_info", emptyUser); } }, saveUserInfo({ username, avatarUrl, sex, phone }) { const updated = { username: username ?? this.username, avatarUrl: avatarUrl ?? this.avatarUrl, sex: sex ?? this.sex, phone: phone ?? this.phone }; Object.assign(this, updated); common_vendor.index.setStorageSync("user_info", { ...this.$state }); } } }); exports.useUserStore = useUserStore; //# sourceMappingURL=../../.sourcemap/mp-weixin/stores/user.js.map