Skip to content

Commit 88a22d9

Browse files
author
puhui999
committed
解决钉钉绑定失败的问题
1 parent 6ee2492 commit 88a22d9

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/views/Profile/Index.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,26 @@
1515
</div>
1616
</template>
1717
<div>
18-
<el-tabs v-model="activeName" tab-position="top" style="height: 400px" class="profile-tabs">
18+
<el-tabs v-model="activeName" class="profile-tabs" style="height: 400px" tab-position="top">
1919
<el-tab-pane :label="t('profile.info.basicInfo')" name="basicInfo">
2020
<BasicInfo />
2121
</el-tab-pane>
2222
<el-tab-pane :label="t('profile.info.resetPwd')" name="resetPwd">
2323
<ResetPwd />
2424
</el-tab-pane>
2525
<el-tab-pane :label="t('profile.info.userSocial')" name="userSocial">
26-
<UserSocial />
26+
<UserSocial v-model:activeName="activeName" />
2727
</el-tab-pane>
2828
</el-tabs>
2929
</div>
3030
</el-card>
3131
</div>
3232
</template>
33-
<script setup lang="ts" name="Profile">
34-
import { BasicInfo, ProfileUser, ResetPwd, UserSocial } from './components/'
35-
const { t } = useI18n()
33+
<script lang="ts" setup>
34+
import { BasicInfo, ProfileUser, ResetPwd, UserSocial } from './components'
3635
36+
const { t } = useI18n()
37+
defineOptions({ name: 'Profile' })
3738
const activeName = ref('basicInfo')
3839
</script>
3940
<style scoped>

src/views/Profile/components/UserSocial.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
2727
import { socialAuthRedirect, socialBind, socialUnbind } from '@/api/system/user/socialUser'
2828
2929
defineOptions({ name: 'UserSocial' })
30-
30+
defineProps<{
31+
activeName: string
32+
}>()
3133
const message = useMessage()
3234
const socialUsers = ref<any[]>([])
3335
const userInfo = ref<ProfileVO>()
3436
3537
const initSocial = async () => {
38+
socialUsers.value = [] // 重置避免无限增长
3639
const res = await getUserProfile()
3740
userInfo.value = res
3841
for (const i in SystemUserSocialTypeEnum) {
@@ -49,21 +52,33 @@ const initSocial = async () => {
4952
}
5053
}
5154
const route = useRoute()
55+
const emit = defineEmits<{
56+
(e: 'update:activeName', v: string): void
57+
}>()
5258
const bindSocial = () => {
5359
// 社交绑定
54-
const type = route.query.type
60+
const type = getUrlValue('type')
5561
const code = route.query.code
5662
const state = route.query.state
5763
if (!code) {
5864
return
5965
}
6066
socialBind(type, code, state).then(() => {
6167
message.success('绑定成功')
68+
emit('update:activeName', 'userSocial')
6269
initSocial()
6370
})
6471
}
72+
73+
// 双层 encode 需要在回调后进行 decode
74+
function getUrlValue(key: string): string {
75+
const url = new URL(decodeURIComponent(location.href))
76+
return url.searchParams.get(key) ?? ''
77+
}
78+
6579
const bind = (row) => {
66-
const redirectUri = location.origin + '/user/profile?type=' + row.type
80+
// 双层 encode 解决钉钉回调 type 参数丢失的问题
81+
const redirectUri = location.origin + '/user/profile?' + encodeURIComponent(`type=${row.type}`)
6782
// 进行跳转
6883
socialAuthRedirect(row.type, encodeURIComponent(redirectUri)).then((res) => {
6984
window.location.href = res
@@ -83,9 +98,8 @@ onMounted(async () => {
8398
8499
watch(
85100
() => route,
86-
(newRoute) => {
101+
() => {
87102
bindSocial()
88-
console.log(newRoute)
89103
},
90104
{
91105
immediate: true

0 commit comments

Comments
 (0)