|
|
@@ -2,11 +2,28 @@ import store from '@/store'
|
|
|
import UTIL from '@/utils/util'
|
|
|
import { getStaffApi, getUserApi } from '@/api/common'
|
|
|
import { postWxCode,getDictionaries } from '@/api/mini'
|
|
|
+import { currentInfo } from '@/api/user'
|
|
|
import { TOKEN_STORAGE_KEY } from '@/constant/storageKeys'
|
|
|
|
|
|
-//获取商城端用户信息
|
|
|
+/**
|
|
|
+ * 拉取商城登录用户信息。
|
|
|
+ * update=true 时强制请求 /user/current-info,并同步 shopUser 与 loginInfo。
|
|
|
+ * 「我的」页展示的是 loginInfo.name,不写 loginInfo 的话改昵称返回后不会刷新。
|
|
|
+ */
|
|
|
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
|
|
|
}
|
|
|
|
|
|
/**
|