wkw 3 tuần trước cách đây
mục cha
commit
14f2c41f0c

+ 6 - 4
app.js

@@ -1,10 +1,12 @@
-import {login} from './api/user';
-import { FETCH_AND_FORMAT_USER_INFO } from './utils/util.js'
 App({
   async onLaunch() {
+    const userInfo = wx.getStorageSync('userInfo') || null;
+    const programConfig = wx.getStorageSync('programConfig') || null;
+    this.globalData.userInfo = userInfo;
+    this.globalData.programConfig = programConfig;
   },
   globalData: {
     userInfo: null,
-    programConfig:null
+    programConfig: null
   }
-})
+});

+ 0 - 1
pages/index/index - 副本.js

@@ -152,7 +152,6 @@ Page({
   
     // 昵称放在头像右侧
     const nickName = app.globalData.userInfo.nickname || '123456';
-    console.log(app.globalData.userInfo.nickName)
     ctx.setFontSize(16);
     ctx.setFillStyle('#000');
     ctx.fillText(nickName, 100, canvasHeight - bottomHeight + 40);

+ 1 - 0
pages/index/index.js

@@ -20,6 +20,7 @@ Page({
   },
   async onLoad(){
     const res = await miniProgramConfig();
+    wx.setStorageSync('programConfig', res.data);
     app.globalData.programConfig = res.data;
     this.setData({
       banners:res.data.carousels,

+ 1 - 0
pages/mine/mine.js

@@ -67,6 +67,7 @@ Page({
   async onSave(pathUrl) {
     const res = await userModify({ avatar: pathUrl });
     if(res.code == 200){
+      wx.setStorageSync('userInfo', res.data)
       app.globalData.userInfo = res.data;
     } else {
       wx.showToast({

+ 1 - 1
pages/register/register.js

@@ -201,8 +201,8 @@ Page({
       this.setData({
         couponInfo:res.data[0]
       })
+      await FETCH_AND_FORMAT_USER_INFO();
       this.setData({ showRegistrationSuccess: true });
-      app.globalData.userInfo = await FETCH_AND_FORMAT_USER_INFO();
     } else {
       wx.showToast({ title: res.message || '报名失败', icon: 'none', duration: 2000 });
     }

+ 3 - 0
pages/setting/setting.js

@@ -53,6 +53,8 @@ Page({
       wx.removeStorageSync('token');
       wx.removeStorageSync('expires_in');
       wx.removeStorageSync('posterCache');
+      wx.removeStorageSync('userInfo');
+      wx.removeStorageSync('programConfig');
       app.globalData.userInfo = null;
       app.globalData.programConfig = null;
       wx.navigateBack({ delta: 1 });
@@ -70,6 +72,7 @@ Page({
         icon: 'none',
         duration: 2000
       });
+      wx.setStorageSync('userInfo', res.data)
       app.globalData.userInfo = res.data;
       wx.navigateBack({ delta: 1 });
     }else{

+ 1 - 1
pages/store/store.wxml

@@ -11,7 +11,7 @@
     bindrefresherrefresh="onPullDownRefresh"
   >
     <view wx:for="{{list}}" wx:key="index" class="list-card {{index === list.length - 1 ? 'no-margin' : ''}}" bindtap="goDetail" data-id="{{item.id}}">
-      <image class="card-img" src="{{ item.avatar}}"  mode="aspectFill"/>
+      <image class="card-img" src="{{ item.avatar}}"  mode="aspectFit"/>
       <view class="card-ri">
         <view class="card-ri-title m-ellipsis">{{item.name}}</view>
         <view class="card-ri-time">营业时间 {{item.business_hours}}</view>

+ 1 - 1
pages/storeDetail/storeDetail.wxml

@@ -2,7 +2,7 @@
   <header text="店铺详情"></header>
   <view class="content">
     <view class="shop-card">
-      <image class="card-img" src="{{dataInfo.avatar}}" mode="aspectFill"/>
+      <image class="card-img" src="{{dataInfo.avatar}}" mode="aspectFit"/>
       <view class="card-ri">
         <view class="card-ri-title">{{dataInfo.name}}</view>
         <view class="card-ri-time">营业时间 {{dataInfo.business_hours}}</view>

+ 3 - 5
utils/util.js

@@ -18,14 +18,12 @@ export const MAKE_PHONE_CALL = (phoneNumber) => {
 export async function FETCH_AND_FORMAT_USER_INFO() {
   const userRes = await getUserInfo()
   const data = userRes.data || {};
-  getApp().globalData.userInfo = {
-    ...data,
-    nickname: data.nickname || data.phone || data.username.substring(0,6)
-  }
-  return {
+  let dataInfo = {
     ...data,
     nickname: data.nickname || data.phone || data.username.substring(0,6)
   }
+  wx.setStorageSync('userInfo', dataInfo)
+  getApp().globalData.userInfo = dataInfo
 }
 // 埋点上报
 export async function REPORT_BEHAVIOR(eventName = '', extra = {}) {