From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目

---
 src/views/Profile/components/UserSocial.vue |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/src/views/Profile/components/UserSocial.vue b/src/views/Profile/components/UserSocial.vue
new file mode 100644
index 0000000..8d25354
--- /dev/null
+++ b/src/views/Profile/components/UserSocial.vue
@@ -0,0 +1,107 @@
+<template>
+  <el-table :data="socialUsers" :show-header="false">
+    <el-table-column fixed="left" title="搴忓彿" type="seq" width="60" />
+    <el-table-column align="left" label="绀句氦骞冲彴" width="120">
+      <template #default="{ row }">
+        <img :src="row.img" alt="" class="h-5 align-middle" />
+        <p class="mr-5">{{ row.title }}</p>
+      </template>
+    </el-table-column>
+    <el-table-column align="center" label="鎿嶄綔">
+      <template #default="{ row }">
+        <template v-if="row.openid">
+          宸茬粦瀹�
+          <XTextButton class="mr-5" title="(瑙g粦)" type="primary" @click="unbind(row)" />
+        </template>
+        <template v-else>
+          鏈粦瀹�
+          <XTextButton class="mr-5" title="(缁戝畾)" type="primary" @click="bind(row)" />
+        </template>
+      </template>
+    </el-table-column>
+  </el-table>
+</template>
+<script lang="ts" setup>
+import { SystemUserSocialTypeEnum } from '@/utils/constants'
+import { getBindSocialUserList } from '@/api/system/social/user'
+import { socialAuthRedirect, socialBind, socialUnbind } from '@/api/system/user/socialUser'
+
+defineOptions({ name: 'UserSocial' })
+defineProps<{
+  activeName: string
+}>()
+const message = useMessage()
+const socialUsers = ref<any[]>([])
+
+const initSocial = async () => {
+  socialUsers.value = [] // 閲嶇疆閬垮厤鏃犻檺澧為暱
+  // 鑾峰彇宸茬粦瀹氱殑绀句氦鐢ㄦ埛鍒楄〃
+  const bindSocialUserList = await getBindSocialUserList()
+  // 妫�鏌ヨ绀句氦骞冲彴鏄惁宸茬粦瀹�
+  for (const i in SystemUserSocialTypeEnum) {
+    const socialUser = { ...SystemUserSocialTypeEnum[i] }
+    socialUsers.value.push(socialUser)
+    if (bindSocialUserList && bindSocialUserList.length > 0) {
+      for (const bindUser of bindSocialUserList) {
+        if (socialUser.type === bindUser.type) {
+          socialUser.openid = bindUser.openid
+          break
+        }
+      }
+    }
+  }
+}
+const route = useRoute()
+const emit = defineEmits<{
+  (e: 'update:activeName', v: string): void
+}>()
+const bindSocial = () => {
+  // 绀句氦缁戝畾
+  const type = getUrlValue('type')
+  const code = route.query.code
+  const state = route.query.state
+  if (!code) {
+    return
+  }
+  socialBind(type, code, state).then(() => {
+    message.success('缁戝畾鎴愬姛')
+    emit('update:activeName', 'userSocial')
+  })
+}
+
+// 鍙屽眰 encode 闇�瑕佸湪鍥炶皟鍚庤繘琛� decode
+function getUrlValue(key: string): string {
+  const url = new URL(decodeURIComponent(location.href))
+  return url.searchParams.get(key) ?? ''
+}
+
+const bind = (row) => {
+  // 鍙屽眰 encode 瑙e喅閽夐拤鍥炶皟 type 鍙傛暟涓㈠け鐨勯棶棰�
+  const redirectUri = location.origin + '/user/profile?' + encodeURIComponent(`type=${row.type}`)
+  // 杩涜璺宠浆
+  socialAuthRedirect(row.type, encodeURIComponent(redirectUri)).then((res) => {
+    window.location.href = res
+  })
+}
+const unbind = async (row) => {
+  const res = await socialUnbind(row.type, row.openid)
+  if (res) {
+    row.openid = undefined
+  }
+  message.success('瑙g粦鎴愬姛')
+}
+
+onMounted(async () => {
+  await initSocial()
+})
+
+watch(
+  () => route,
+  () => {
+    bindSocial()
+  },
+  {
+    immediate: true
+  }
+)
+</script>

--
Gitblit v1.8.0