新增
This commit is contained in:
@@ -109,13 +109,14 @@
|
||||
|
||||
<script setup lang="ts" name="userSetting">
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { nextTick, onMounted, ref, reactive } from 'vue'
|
||||
import { nextTick, onMounted, onUnmounted, ref, reactive } from 'vue'
|
||||
import { Loading, CircleCheck, Connection } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
import { setUserInfo, getWorkWechatConfig, bindWorkWechat, unbindWorkWechat } from '@/api/user'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import feedback from '@/utils/feedback'
|
||||
import { attachWecomOAuthMessageCapture } from '@/utils/wecomOauthPostMessage'
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const userStore = useUserStore()
|
||||
@@ -135,12 +136,17 @@ const rules = reactive<object>({
|
||||
name: [{ required: true, message: '请输入名称', trigger: ['blur'] }]
|
||||
})
|
||||
|
||||
/** 与 bind-work-wechat 页一致:避免企微 postMessage 跳转后重复 onMounted 两次请求同一 code */
|
||||
const WX_BIND_OAUTH_LOCK = 'like_admin_wx_bind_oauth'
|
||||
|
||||
// 企业微信相关
|
||||
const wxWorkEnabled = ref(false)
|
||||
const wxWorkConfig = ref<{ corp_id: string; agent_id: string }>({ corp_id: '', agent_id: '' })
|
||||
const bindDialogVisible = ref(false)
|
||||
const bindLoading = ref(false)
|
||||
|
||||
let detachSettingWecomCapture: (() => void) | null = null
|
||||
|
||||
// 获取个人设置
|
||||
const getUser = async () => {
|
||||
const userInfo = userStore.userInfo
|
||||
@@ -200,6 +206,14 @@ const showBindDialog = async () => {
|
||||
bindLoading.value = false
|
||||
await nextTick()
|
||||
|
||||
detachSettingWecomCapture?.()
|
||||
detachSettingWecomCapture = attachWecomOAuthMessageCapture({
|
||||
pathIncludes: 'user/setting',
|
||||
lockKey: WX_BIND_OAUTH_LOCK,
|
||||
wxBindState: 'bind_wxwork',
|
||||
onCode: (code) => handleBindCallback(code)
|
||||
})
|
||||
|
||||
const redirectUri = encodeURIComponent(getBindRedirectUri())
|
||||
new (window as any).WwLogin({
|
||||
id: 'bind_wxwork_qrcode',
|
||||
@@ -215,6 +229,8 @@ const showBindDialog = async () => {
|
||||
|
||||
const onBindDialogClose = () => {
|
||||
bindLoading.value = false
|
||||
detachSettingWecomCapture?.()
|
||||
detachSettingWecomCapture = null
|
||||
}
|
||||
|
||||
// 解绑
|
||||
@@ -235,6 +251,7 @@ const handleBindCallback = async (code: string) => {
|
||||
try {
|
||||
const res = await bindWorkWechat({ code })
|
||||
formData.work_wechat_userid = res?.work_wechat_userid || ''
|
||||
bindDialogVisible.value = false
|
||||
ElMessage.success('企业微信绑定成功')
|
||||
userStore.getUserInfo()
|
||||
} catch (e: any) {
|
||||
@@ -265,11 +282,22 @@ onMounted(async () => {
|
||||
const isBind = urlParams.get('bind_wxwork')
|
||||
|
||||
if (bindCode && (state === 'bind_wxwork' || isBind === '1')) {
|
||||
handleBindCallback(bindCode)
|
||||
if (sessionStorage.getItem(WX_BIND_OAUTH_LOCK) === bindCode) {
|
||||
return
|
||||
}
|
||||
sessionStorage.setItem(WX_BIND_OAUTH_LOCK, bindCode)
|
||||
handleBindCallback(bindCode).finally(() => {
|
||||
sessionStorage.removeItem(WX_BIND_OAUTH_LOCK)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
getUser()
|
||||
|
||||
onUnmounted(() => {
|
||||
detachSettingWecomCapture?.()
|
||||
detachSettingWecomCapture = null
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user