acdr-ui/dist/build/mp-weixin/sheep/store/user.js

2 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";var e=(e,t,r)=>new Promise(((n,o)=>{var i=e=>{try{a(r.next(e))}catch(t){o(t)}},s=e=>{try{a(r.throw(e))}catch(t){o(t)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(i,s);a((r=r.apply(e,t)).next())}));const t=require("../../common/vendor.js"),r=require("../platform/share.js"),n=require("./cart.js"),o=require("./app.js"),i=require("../hooks/useModal.js"),s=require("../api/member/user.js"),a=require("../api/pay/wallet.js"),u=require("../api/trade/order.js"),l=require("../api/promotion/coupon.js"),d={avatar:"",nickname:"",gender:0,mobile:"",point:0},h={balance:0},c={unusedCouponCount:0,orderCount:{allCount:0,unpaidCount:0,undeliveredCount:0,deliveredCount:0,uncommentedCount:0,afterSaleCount:0}},p=t.defineStore({id:"user",state:()=>({userInfo:t.clone(d),userWallet:t.clone(h),isLogin:!!t.index.getStorageSync("token"),numData:t.cloneDeep(c),lastUpdateTime:0}),actions:{getInfo(){return e(this,null,(function*(){const{code:e,data:t}=yield s.UserApi.getUserInfo();if(0===e)return this.userInfo=t,Promise.resolve(t)}))},getWallet(){return e(this,null,(function*(){const{code:e,data:t}=yield a.PayWalletApi.getPayWallet();0===e&&(this.userWallet=t)}))},getNumData(){u.OrderApi.getOrderCount().then((e=>{0===e.code&&(this.numData.orderCount=e.data)})),l.CouponApi.getUnusedCouponCount().then((e=>{0===e.code&&(this.numData.unusedCouponCount=e.data)}))},setToken(e="",r=""){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",r),this.loginAfter()),this.isLogin},updateUserData(){return e(this,null,(function*(){if(!this.isLogin)return void this.resetUserData();const e=(new Date).getTime();return this.lastUpdateTime+5e3>e?void 0:(this.lastUpdateTime=e,yield this.getInfo(),this.getWallet(),this.getNumData(),this.userInfo)}))},resetUserData(){this.setToken(),this.userInfo=t.clone(d),this.userWallet=t.clone(h),this.numData=t.cloneDeep(c),n.cart().emptyList()},loginAfter(){return e(this,null,(function*(){yield this.updateUserData(),n.cart().getList(),r.$share.getShareInfo(),o.app().platform.bind_mobile&&!this.userInfo.mobile&&i.showAuthModal("changeMobile"),r.$share.bindBrokerageUser()}))},logout(){return e(this,null,(function*(){return this.resetUserData(),!this.isLogin}))}},persist:{enabled:!0,strategies:[{key:"user-store"}]}}),g=Object.freeze(Object.defineProperty({__proto__:null,default:p},Symbol.toStringTag,{value:"Module"}));exports.__vite_glob_0_4=g,exports.user=p;