Explorar o código

零售端-修改昵称后,同步更新缓存。公告改为显示摘要

ouyang hai 1 día
pai
achega
cf1ffa4e70

+ 2 - 1
mallApp/src/components/home/noticeBar.vue

@@ -24,7 +24,8 @@
           @change="onNoticeChange"
           @change="onNoticeChange"
         >
         >
           <swiper-item v-for="item in noticeList" :key="item.id">
           <swiper-item v-for="item in noticeList" :key="item.id">
-            <text class="notice-summary">{{ item.title || item.summary }}</text>
+            <!-- 公告条展示摘要;无摘要时回退标题,避免空条 -->
+            <text class="notice-summary">{{ item.summary || item.title }}</text>
           </swiper-item>
           </swiper-item>
         </swiper>
         </swiper>
       </view>
       </view>

+ 2 - 1
mallApp/src/pages/home/shop-category.vue

@@ -47,7 +47,8 @@
             @change="onNoticeChange"
             @change="onNoticeChange"
           >
           >
             <swiper-item v-for="item in noticeList" :key="item.id">
             <swiper-item v-for="item in noticeList" :key="item.id">
-              <text class="notice-summary">{{ item.title || item.summary }}</text>
+              <!-- 分类页公告条展示摘要;无摘要时回退标题,避免空条 -->
+              <text class="notice-summary">{{ item.summary || item.title }}</text>
             </swiper-item>
             </swiper-item>
           </swiper>
           </swiper>
         </view>
         </view>

+ 1 - 0
mallApp/src/pages/home/user.vue

@@ -177,6 +177,7 @@ export default {
     uni.removeStorageSync(SHOP_NAV_ACTIVE_KEY);
     uni.removeStorageSync(SHOP_NAV_ACTIVE_KEY);
     uni.showTabBar({ animation: false });
     uni.showTabBar({ animation: false });
     if (this.isLoggedIn) {
     if (this.isLoggedIn) {
+      // 强制刷新:改昵称等资料后返回本页,需用接口结果覆盖 loginInfo
       getShopUser(true).then(() => {});
       getShopUser(true).then(() => {});
     }
     }
   },
   },

+ 17 - 14
mallApp/src/pages/user/edit.vue

@@ -1,3 +1,7 @@
+<!--
+  商城「我的」资料编辑:改昵称、看/改生日、退出登录。
+  改昵称成功后必须写入 vuex loginInfo,否则返回「我的」仍显示旧名字。
+-->
 <template>
 <template>
 	<div class="app-content">
 	<div class="app-content">
 		<form @submit="formSubmit">
 		<form @submit="formSubmit">
@@ -93,8 +97,11 @@ export default {
 		goToBirthday() {
 		goToBirthday() {
 			this.pageTo({ url: '/pages/user/birthday'})
 			this.pageTo({ url: '/pages/user/birthday'})
 		},
 		},
+		/**
+		 * 提交昵称:校验后调 /user/update,并把新名字写入 loginInfo(含本地缓存)。
+		 * 「我的」页读的是 loginInfo.name,只改接口不写 vuex 会看起来没更新。
+		 */
 		formSubmit(e) {
 		formSubmit(e) {
-			// 表单规则
 			let rules = [
 			let rules = [
 				{
 				{
 					name: 'name',
 					name: 'name',
@@ -102,25 +109,21 @@ export default {
 					msg: ['请输入昵称']
 					msg: ['请输入昵称']
 				}
 				}
 			]
 			]
-			// 进行表单检查
-			let formData = e.detail.value
+			let formData = (e && e.detail && e.detail.value) ? e.detail.value : this.form
 			let checkRes = form.validation(formData, rules)
 			let checkRes = form.validation(formData, rules)
-			// 验证通过!
-			if (!checkRes) {
-				setTimeout(() => {
-					this.confirmFn()
-				})
-			} else {
+			if (checkRes) {
 				this.$msg(checkRes)
 				this.$msg(checkRes)
+				return
 			}
 			}
-		},
-		formSubmit(){
-			updateInfo(this.form).then(res=>{
-				if(res.code == 1){
+			const name = String(formData.name != null ? formData.name : this.form.name).trim()
+			updateInfo({ name }).then(res => {
+				if (res.code == 1) {
+					const loginInfo = Object.assign({}, this.$store.getters.getLoginInfo || {}, { name })
+					this.$store.commit('setLoginInfo', loginInfo)
 					this.$msg('已修改')
 					this.$msg('已修改')
 					setTimeout(() => {
 					setTimeout(() => {
 						uni.navigateBack({})
 						uni.navigateBack({})
-					}, 1000);
+					}, 1000)
 				}
 				}
 			})
 			})
 		}
 		}

+ 19 - 2
mallApp/src/utils/auth.js

@@ -2,11 +2,28 @@ import store from '@/store'
 import UTIL from '@/utils/util'
 import UTIL from '@/utils/util'
 import { getStaffApi, getUserApi } from '@/api/common'
 import { getStaffApi, getUserApi } from '@/api/common'
 import { postWxCode,getDictionaries } from '@/api/mini'
 import { postWxCode,getDictionaries } from '@/api/mini'
+import { currentInfo } from '@/api/user'
 import { TOKEN_STORAGE_KEY } from '@/constant/storageKeys'
 import { TOKEN_STORAGE_KEY } from '@/constant/storageKeys'
 
 
-//获取商城端用户信息
+/**
+ * 拉取商城登录用户信息。
+ * update=true 时强制请求 /user/current-info,并同步 shopUser 与 loginInfo。
+ * 「我的」页展示的是 loginInfo.name,不写 loginInfo 的话改昵称返回后不会刷新。
+ */
 export async function getShopUser(update) {
 export async function getShopUser(update) {
-	
+	let userInfo = store.getters.getShopUser
+	if (!UTIL.isEmpty(userInfo) && !update) {
+		return userInfo
+	}
+	await currentInfo().then((res) => {
+		if (res && res.code == 1 && res.data && res.data.info) {
+			userInfo = res.data.info
+			store.dispatch('setShopUser', userInfo)
+			const loginInfo = store.getters.getLoginInfo || {}
+			store.commit('setLoginInfo', Object.assign({}, loginInfo, userInfo))
+		}
+	}).catch(() => {})
+	return userInfo
 }
 }
 
 
 /**
 /**