fix: WecomBind.vue — 修复 auth.user 不存在的问题
auth store 暴露的是独立字段 (name/userId/role) 而非 user 对象, 导致 auth.user?.name 始终为 undefined。 修复: - auth.name 替代 auth.user?.name - 调用 /users/me 获取 wecom_userid (store 不存储该字段) - window.location.href 替代 router.push (企微浏览器兼容) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,20 +11,25 @@ const auth = useAuthStore()
|
||||
const binding = ref(false)
|
||||
const bound = ref(false)
|
||||
const errorMsg = ref('')
|
||||
const wecomUserId = ref('')
|
||||
|
||||
const bindToken = (route.query.token as string) || ''
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
if (!bindToken) {
|
||||
errorMsg.value = '无效的绑定链接'
|
||||
setTimeout(() => router.replace('/'), 2000)
|
||||
return
|
||||
}
|
||||
if (!auth.isLoggedIn) {
|
||||
// Not logged in yet — redirect to login (use window.location for WeChat Work browser compat)
|
||||
window.location.href = `/login?redirect=${encodeURIComponent(route.fullPath)}`
|
||||
return
|
||||
}
|
||||
// Fetch current user's wecom_userid
|
||||
try {
|
||||
const res = await api.get('/users/me')
|
||||
wecomUserId.value = res.data.wecom_userid || ''
|
||||
} catch (_) {}
|
||||
})
|
||||
|
||||
async function doBind() {
|
||||
@@ -34,7 +39,7 @@ async function doBind() {
|
||||
const res = await api.post('/wecom/bind-confirm', { token: bindToken })
|
||||
if (res.data.code === 200) {
|
||||
bound.value = true
|
||||
auth.user!.wecom_userid = res.data.wecom_userid
|
||||
wecomUserId.value = res.data.wecom_userid
|
||||
ElMessage.success('绑定成功!')
|
||||
setTimeout(() => router.replace('/'), 1500)
|
||||
} else {
|
||||
@@ -61,23 +66,23 @@ async function doBind() {
|
||||
<div class="bind-info">
|
||||
<div class="info-row">
|
||||
<span class="info-label">当前账号</span>
|
||||
<span class="info-value">{{ auth.user?.name || '--' }}</span>
|
||||
<span class="info-value">{{ auth.name || '--' }}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="info-label">绑定状态</span>
|
||||
<span :class="['info-tag', auth.user?.wecom_userid ? 'bound' : 'unbound']">
|
||||
{{ auth.user?.wecom_userid ? '已绑定' : '未绑定' }}
|
||||
<span :class="['info-tag', wecomUserId ? 'bound' : 'unbound']">
|
||||
{{ wecomUserId ? '已绑定' : '未绑定' }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="auth.user?.wecom_userid" class="info-row">
|
||||
<div v-if="wecomUserId" class="info-row">
|
||||
<span class="info-label">企微ID</span>
|
||||
<span class="info-value">{{ auth.user.wecom_userid }}</span>
|
||||
<span class="info-value">{{ wecomUserId }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bind-actions">
|
||||
<el-button
|
||||
v-if="!bound && !auth.user?.wecom_userid"
|
||||
v-if="!bound && !wecomUserId"
|
||||
type="primary"
|
||||
size="large"
|
||||
:loading="binding"
|
||||
|
||||
Reference in New Issue
Block a user