解决钉钉绑定失败的问题

This commit is contained in:
puhui999 2023-10-26 16:19:22 +08:00
parent 6ee2492ff1
commit 88a22d90e5
2 changed files with 25 additions and 10 deletions

View File

@ -15,7 +15,7 @@
</div> </div>
</template> </template>
<div> <div>
<el-tabs v-model="activeName" tab-position="top" style="height: 400px" class="profile-tabs"> <el-tabs v-model="activeName" class="profile-tabs" style="height: 400px" tab-position="top">
<el-tab-pane :label="t('profile.info.basicInfo')" name="basicInfo"> <el-tab-pane :label="t('profile.info.basicInfo')" name="basicInfo">
<BasicInfo /> <BasicInfo />
</el-tab-pane> </el-tab-pane>
@ -23,17 +23,18 @@
<ResetPwd /> <ResetPwd />
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="t('profile.info.userSocial')" name="userSocial"> <el-tab-pane :label="t('profile.info.userSocial')" name="userSocial">
<UserSocial /> <UserSocial v-model:activeName="activeName" />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
</el-card> </el-card>
</div> </div>
</template> </template>
<script setup lang="ts" name="Profile"> <script lang="ts" setup>
import { BasicInfo, ProfileUser, ResetPwd, UserSocial } from './components/' import { BasicInfo, ProfileUser, ResetPwd, UserSocial } from './components'
const { t } = useI18n()
const { t } = useI18n()
defineOptions({ name: 'Profile' })
const activeName = ref('basicInfo') const activeName = ref('basicInfo')
</script> </script>
<style scoped> <style scoped>

View File

@ -27,12 +27,15 @@ import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
import { socialAuthRedirect, socialBind, socialUnbind } from '@/api/system/user/socialUser' import { socialAuthRedirect, socialBind, socialUnbind } from '@/api/system/user/socialUser'
defineOptions({ name: 'UserSocial' }) defineOptions({ name: 'UserSocial' })
defineProps<{
activeName: string
}>()
const message = useMessage() const message = useMessage()
const socialUsers = ref<any[]>([]) const socialUsers = ref<any[]>([])
const userInfo = ref<ProfileVO>() const userInfo = ref<ProfileVO>()
const initSocial = async () => { const initSocial = async () => {
socialUsers.value = [] //
const res = await getUserProfile() const res = await getUserProfile()
userInfo.value = res userInfo.value = res
for (const i in SystemUserSocialTypeEnum) { for (const i in SystemUserSocialTypeEnum) {
@ -49,9 +52,12 @@ const initSocial = async () => {
} }
} }
const route = useRoute() const route = useRoute()
const emit = defineEmits<{
(e: 'update:activeName', v: string): void
}>()
const bindSocial = () => { const bindSocial = () => {
// //
const type = route.query.type const type = getUrlValue('type')
const code = route.query.code const code = route.query.code
const state = route.query.state const state = route.query.state
if (!code) { if (!code) {
@ -59,11 +65,20 @@ const bindSocial = () => {
} }
socialBind(type, code, state).then(() => { socialBind(type, code, state).then(() => {
message.success('绑定成功') message.success('绑定成功')
emit('update:activeName', 'userSocial')
initSocial() initSocial()
}) })
} }
// encode decode
function getUrlValue(key: string): string {
const url = new URL(decodeURIComponent(location.href))
return url.searchParams.get(key) ?? ''
}
const bind = (row) => { const bind = (row) => {
const redirectUri = location.origin + '/user/profile?type=' + row.type // encode type
const redirectUri = location.origin + '/user/profile?' + encodeURIComponent(`type=${row.type}`)
// //
socialAuthRedirect(row.type, encodeURIComponent(redirectUri)).then((res) => { socialAuthRedirect(row.type, encodeURIComponent(redirectUri)).then((res) => {
window.location.href = res window.location.href = res
@ -83,9 +98,8 @@ onMounted(async () => {
watch( watch(
() => route, () => route,
(newRoute) => { () => {
bindSocial() bindSocial()
console.log(newRoute)
}, },
{ {
immediate: true immediate: true