You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
2.4 KiB

"use strict";const t=require("../../common/vendor.js"),u=require("../platform/share.js"),s=require("./cart.js"),l=require("./app.js"),d=require("../hooks/useModal.js"),h=require("../api/member/user.js"),c=require("../api/pay/wallet.js"),p=require("../api/trade/order.js"),a={avatar:"",nickname:"",gender:0,mobile:"",point:0},r={balance:0},n={unusedCouponCount:0,orderCount:{allCount:0,unpaidCount:0,undeliveredCount:0,deliveredCount:0,uncommentedCount:0,afterSaleCount:0}},i=t.defineStore({id:"user",state:()=>({userInfo:t.lodashExports.clone(a),userWallet:t.lodashExports.clone(r),isLogin:!!t.index.getStorageSync("token"),numData:t.lodashExports.cloneDeep(n),lastUpdateTime:0}),actions:{async getInfo(){const{code:e,data:o}=await h.UserApi.getUserInfo();if(e===0)return this.userInfo=o,Promise.resolve(o)},async getWallet(){const{code:e,data:o}=await c.PayWalletApi.getPayWallet();e===0&&(this.userWallet=o)},getNumData(){p.OrderApi.getOrderCount().then(e=>{e.code===0&&(this.numData.orderCount=e.data)}),CouponApi.getUnusedCouponCount().then(e=>{e.code===0&&(this.numData.unusedCouponCount=e.data)})},async addShareLog(e){const{error:o}=await userApi.addShareLog(e);o===0&&t.index.removeStorageSync("shareLog")},setToken(e="",o=""){return e===""?(this.isLogin=!1,t.index.removeStorageSync("token"),t.index.removeStorageSync("refresh-token")):(this.isLogin=!0,t.index.setStorageSync("token",e),t.index.setStorageSync("refresh-token",o),this.loginAfter()),this.isLogin},async updateUserData(){if(!this.isLogin){this.resetUserData();return}const e=new Date().getTime();if(!(this.lastUpdateTime+5e3>e))return this.lastUpdateTime=e,await this.getInfo(),this.getWallet(),this.getNumData(),this.userInfo},resetUserData(){this.setToken(),this.userInfo=t.lodashExports.clone(a),this.userWallet=t.lodashExports.clone(r),this.numData=t.lodashExports.cloneDeep(n),s.cart().emptyList()},async loginAfter(){await this.updateUserData(),s.cart().getList(),u.$share.getShareInfo(),l.app().platform.bind_mobile&&!this.userInfo.mobile&&d.showAuthModal("changeMobile");const e=t.index.getStorageSync("shareLog");t.lodashExports.isEmpty(e)||this.addShareLog({...e})},async logout(){return this.resetUserData(),!this.isLogin}},persist:{enabled:!0,strategies:[{key:"user-store"}]}}),g=Object.freeze(Object.defineProperty({__proto__:null,default:i},Symbol.toStringTag,{value:"Module"}));exports.__vite_glob_0_4=g;exports.user=i;