更新
This commit is contained in:
@@ -125,20 +125,26 @@
|
||||
popupStstus: 0,
|
||||
messageText: "",
|
||||
msgType: "success",
|
||||
detailData: null
|
||||
detailData: null,
|
||||
// 上次刷新用户信息的时间戳
|
||||
lastRefreshTime: 0
|
||||
|
||||
}
|
||||
},
|
||||
onShow(options) {
|
||||
if (uni.getStorageSync('token')) {
|
||||
this.getUserInfo()
|
||||
// this.getUserInfo()
|
||||
if (uni.getStorageSync('BarHeight')) {
|
||||
this.statusBarHeight = uni.getStorageSync('BarHeight')
|
||||
}
|
||||
if (uni.getStorageSync('Theme_Data')) {
|
||||
this.ThemeData = JSON.parse(uni.getStorageSync('Theme_Data'))
|
||||
}
|
||||
if (options.guild_id) {
|
||||
|
||||
// 每次页面显示时都刷新用户信息(处理从APP实名认证返回的情况)
|
||||
this.refreshUserInfo()
|
||||
|
||||
if (options && options.guild_id) {
|
||||
//如果有传入公会id 把工会ID放到搜索框去
|
||||
this.searchValue = options.guild_id
|
||||
this.getUnionList(options.guild_id)
|
||||
@@ -149,18 +155,33 @@
|
||||
|
||||
},
|
||||
methods: {
|
||||
// 获取用户信息 拿实名信息
|
||||
async getUserInfo() {
|
||||
http.get('/api/User/get_user_info', {
|
||||
token: uni.getStorageSync('token') || ''
|
||||
}).then(response => {
|
||||
const {
|
||||
data,
|
||||
code
|
||||
} = response
|
||||
this.isAuth = code ? data.auth : 0
|
||||
})
|
||||
// 刷新用户信息(获取最新的实名状态)
|
||||
async refreshUserInfo(force = false) {
|
||||
// 防抖:如果距离上次刷新不到 3 秒,且不是强制刷新,则跳过
|
||||
const now = Date.now()
|
||||
if (!force && now - this.lastRefreshTime < 3000) {
|
||||
console.log('跳过频繁刷新')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await http.get('/api/User/get_user_info', {
|
||||
token: uni.getStorageSync('token') || ''
|
||||
})
|
||||
|
||||
if (response.code) {
|
||||
this.isAuth = response.data.auth || false
|
||||
// 可以将实名状态缓存起来,避免频繁请求
|
||||
uni.setStorageSync('user_auth_status', this.isAuth)
|
||||
this.lastRefreshTime = now
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
// 如果请求失败,尝试从缓存读取
|
||||
this.isAuth = uni.getStorageSync('user_auth_status') || false
|
||||
}
|
||||
},
|
||||
|
||||
async getUnionList(name) {
|
||||
this.loading = true
|
||||
http.get('/api/Guild/guild_list', {
|
||||
@@ -188,16 +209,55 @@
|
||||
}
|
||||
},
|
||||
// 申請加入工會
|
||||
applyUnion(data) {
|
||||
if (this.isAuth) {
|
||||
this.detailData = data
|
||||
this.popupStstus = 1
|
||||
this.messageContent = "是否选择加入当前公会"
|
||||
this.$refs.popup.open('center')
|
||||
} else {
|
||||
this.popupStstus = 3
|
||||
this.messageContent = "当前尚未实名认证,是否跳转到实名认证页面?"
|
||||
this.$refs.popup.open('center')
|
||||
async applyUnion(rowData) {
|
||||
// 显示加载状态
|
||||
uni.showLoading({
|
||||
title: '检查实名状态...',
|
||||
mask: true
|
||||
})
|
||||
|
||||
try {
|
||||
// 强制获取最新的用户信息和实名状态
|
||||
const response = await http.get('/api/User/get_user_info', {
|
||||
token: uni.getStorageSync('token') || ''
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (response.code) {
|
||||
const isRealNameAuth = response.data.auth || false
|
||||
|
||||
// 更新实名状态和刷新时间
|
||||
this.isAuth = isRealNameAuth
|
||||
this.lastRefreshTime = Date.now()
|
||||
uni.setStorageSync('user_auth_status', isRealNameAuth)
|
||||
|
||||
if (isRealNameAuth) {
|
||||
// 已实名,弹出加入公会确认框
|
||||
this.detailData = rowData
|
||||
this.popupStstus = 1
|
||||
this.messageContent = "是否选择加入当前公会"
|
||||
this.$refs.popup.open('center')
|
||||
} else {
|
||||
// 未实名,弹出实名认证提示框
|
||||
this.detailData = rowData // 保存公会数据,实名后可能需要
|
||||
this.popupStstus = 3
|
||||
this.messageContent = "当前尚未实名认证,是否跳转到实名认证页面?"
|
||||
this.$refs.popup.open('center')
|
||||
}
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: response.msg || '获取用户信息失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
console.error('获取用户信息失败:', error)
|
||||
this.messageText = '请求失败,请重试!'
|
||||
this.msgType = 'error'
|
||||
this.$refs.message.open()
|
||||
}
|
||||
},
|
||||
closePopup() {
|
||||
@@ -227,6 +287,13 @@
|
||||
window.Android.enterAuthent();
|
||||
}
|
||||
this.closePopup()
|
||||
|
||||
// 提示用户完成实名后返回
|
||||
uni.showToast({
|
||||
title: '请完成实名认证后返回',
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
})
|
||||
},
|
||||
// 申请加入公会
|
||||
async joinUnionize() {
|
||||
|
||||
Reference in New Issue
Block a user