|
@@ -6,7 +6,7 @@
|
|
</div>
|
|
</div>
|
|
<div class="login-tabs">
|
|
<div class="login-tabs">
|
|
<div class="tab" :class="{ active: activeTab === 'phone' }" @click="activeTab = 'phone'">手机号登录</div>
|
|
<div class="tab" :class="{ active: activeTab === 'phone' }" @click="activeTab = 'phone'">手机号登录</div>
|
|
- <!-- <div class="tab" :class="{ active: activeTab === 'wechat' }" @click="activeTab = 'wechat'">微信登录</div> -->
|
|
|
|
|
|
+ <div class="tab" :class="{ active: activeTab === 'wechat' }" @click="activeTab = 'wechat'">微信登录</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="login-content">
|
|
<div class="login-content">
|
|
@@ -44,7 +44,7 @@
|
|
<!-- 使用vue-qrcode组件 -->
|
|
<!-- 使用vue-qrcode组件 -->
|
|
<qrcode-vue :value="qrcodeValue" :width="200" />
|
|
<qrcode-vue :value="qrcodeValue" :width="200" />
|
|
<!-- 过期遮罩层 -->
|
|
<!-- 过期遮罩层 -->
|
|
- <div v-if="isQrcodeExpired" class="expired-mask">
|
|
|
|
|
|
+ <div class="expired-mask">
|
|
<el-icon :size="40">
|
|
<el-icon :size="40">
|
|
<Refresh />
|
|
<Refresh />
|
|
</el-icon>
|
|
</el-icon>
|
|
@@ -52,7 +52,7 @@
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<p class="qrcode-tip">请使用微信扫一扫登录</p>
|
|
<p class="qrcode-tip">请使用微信扫一扫登录</p>
|
|
- <p class="qrcode-refresh">二维码已失效?<a href="javascript:;" @click="refreshQrcode">点击刷新</a></p>
|
|
|
|
|
|
+ <!-- <p class="qrcode-refresh">二维码已失效?<a href="javascript:;" @click="refreshQrcode">点击刷新</a></p> -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="agreement">
|
|
<div class="agreement">
|
|
@@ -141,14 +141,15 @@ const loading = ref(false)
|
|
const captchaLoading = ref(false)
|
|
const captchaLoading = ref(false)
|
|
|
|
|
|
// 二维码值
|
|
// 二维码值
|
|
-const qrcodeValue = ref('https://example.com/login?token=' + Date.now())
|
|
|
|
|
|
+const qrcodeValue = ref('')
|
|
let countdown = 60
|
|
let countdown = 60
|
|
let timer1 = null
|
|
let timer1 = null
|
|
let timer2 = null
|
|
let timer2 = null
|
|
// 刷新二维码
|
|
// 刷新二维码
|
|
const refreshQrcode = async () => {
|
|
const refreshQrcode = async () => {
|
|
|
|
+ clearTimeout(timer)
|
|
// const result = await getQRcode()
|
|
// const result = await getQRcode()
|
|
- qrcodeValue.value = 'https://example.com/login?token=' + Date.now()
|
|
|
|
|
|
+ getQrCode()
|
|
}
|
|
}
|
|
|
|
|
|
// 获取验证码
|
|
// 获取验证码
|
|
@@ -175,7 +176,6 @@ const handlePhoneLogin = async () => {
|
|
phone: phone.value,
|
|
phone: phone.value,
|
|
captcha: captcha.value,
|
|
captcha: captcha.value,
|
|
authType: "PHONE",
|
|
authType: "PHONE",
|
|
- clientId: "ef51c9a3e9046c4f2ea45142c8a8344a"
|
|
|
|
})
|
|
})
|
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -187,20 +187,16 @@ const handlePhoneLogin = async () => {
|
|
}
|
|
}
|
|
|
|
|
|
// 微信扫码登录处理
|
|
// 微信扫码登录处理
|
|
-const handleWechatLogin = async (token) => {
|
|
|
|
|
|
+const handleWechatLogin = async (code) => {
|
|
try {
|
|
try {
|
|
loading.value = true
|
|
loading.value = true
|
|
// 调用user仓库的登录方法,使用微信登录类型
|
|
// 调用user仓库的登录方法,使用微信登录类型
|
|
- const loginResult = await userStore.login({
|
|
|
|
- type: 'wechat',
|
|
|
|
- // 这里可以传递微信登录相关的参数
|
|
|
|
- wechatToken: token || qrcodeValue.value.split('token=')[1]
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- if (loginResult) {
|
|
|
|
- ElMessage.success('微信登录成功')
|
|
|
|
- // 登录成功后可以执行其他操作
|
|
|
|
- }
|
|
|
|
|
|
+ userStore.login({
|
|
|
|
+ authType: "SOCIAL",
|
|
|
|
+ source: "wechat_mp",
|
|
|
|
+ state: state.value,
|
|
|
|
+ code,
|
|
|
|
+ })
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error('微信登录失败:', error)
|
|
console.error('微信登录失败:', error)
|
|
ElMessage.error('微信登录失败,请稍后重试')
|
|
ElMessage.error('微信登录失败,请稍后重试')
|
|
@@ -208,14 +204,19 @@ const handleWechatLogin = async (token) => {
|
|
loading.value = false
|
|
loading.value = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-const checkQRcodeResult = async () => {
|
|
|
|
- const res = await getQRcodeResult(qrcodeValue.value)
|
|
|
|
- if (res.code === 200) {
|
|
|
|
- await handleWechatLogin(res.data)
|
|
|
|
|
|
+const checkQRcodeResult = async (state) => {
|
|
|
|
+ const res = await getQRcodeResult(state)
|
|
|
|
+ console.log(res.data.code);
|
|
|
|
+
|
|
|
|
+ if (!!res.data.code) {
|
|
|
|
+ await handleWechatLogin(res.data.code)
|
|
} else {
|
|
} else {
|
|
- setTimeout(() => {
|
|
|
|
- checkQRcodeResult()
|
|
|
|
- }, 5000);
|
|
|
|
|
|
+ await new Promise((res) => setTimeout(() => {
|
|
|
|
+ res()
|
|
|
|
+ }, 1000))
|
|
|
|
+ console.log(state,121212);
|
|
|
|
+
|
|
|
|
+ checkQRcodeResult(state)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 验证手机号
|
|
// 验证手机号
|
|
@@ -230,22 +231,61 @@ const validatePhone = () => {
|
|
}
|
|
}
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
-watch(activeTab, (newTab) => {
|
|
|
|
- if (newTab === 'wechat') {
|
|
|
|
- getWeChatLoginCode({source:'wechat_mp'}).then(res => {
|
|
|
|
- qrcodeValue.value = res.authorizeUrl
|
|
|
|
|
|
+let timer = null
|
|
|
|
+const state = ref('')
|
|
|
|
+function getQrCode() {
|
|
|
|
+ isQrcodeExpired.value = false
|
|
|
|
+ timer = setTimeout(() => {
|
|
|
|
+ isQrcodeExpired.value = true
|
|
|
|
+ console.log(isQrcodeExpired.value);
|
|
|
|
+
|
|
|
|
+ }, 1000 * 4);
|
|
|
|
+ getWeChatLoginCode({ source: 'wechat_mp' }).then(res => {
|
|
|
|
+ console.log(res.data.authorizeUrl);
|
|
|
|
+ // 解析URL参数
|
|
|
|
+ const urlParams = getUrlParams(res.data.authorizeUrl);
|
|
|
|
+ qrcodeValue.value = res.data.authorizeUrl
|
|
|
|
+
|
|
|
|
+ state.value = urlParams.state
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ checkQRcodeResult(res.data.state)
|
|
|
|
+ }, 1000);
|
|
|
|
+ console.log('URL参数对象:', urlParams);
|
|
})
|
|
})
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 添加解析URL参数的函数
|
|
|
|
+function getUrlParams(url) {
|
|
|
|
+ try {
|
|
|
|
+ // 创建URL对象
|
|
|
|
+ const urlObj = new URL(url);
|
|
|
|
+ // 获取searchParams对象
|
|
|
|
+ const params = urlObj.searchParams;
|
|
|
|
+ // 将参数转换为对象
|
|
|
|
+ const paramsObj = {};
|
|
|
|
+ for (const [key, value] of params.entries()) {
|
|
|
|
+ paramsObj[key] = value;
|
|
|
|
+ }
|
|
|
|
+ return paramsObj;
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('解析URL参数失败:', error);
|
|
|
|
+ return {};
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+watch(activeTab, (newTab) => {
|
|
|
|
+ if (newTab === 'wechat' && !qrcodeValue.value) {
|
|
|
|
+ getQrCode()
|
|
// qrcodeValue.value = 'https://example.com/login?token=' + Date.now()
|
|
// qrcodeValue.value = 'https://example.com/login?token=' + Date.now()
|
|
- // setTimeout(() => {
|
|
|
|
- // checkQRcodeResult()
|
|
|
|
- // }, 1000);
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
// 组件挂载时的处理
|
|
// 组件挂载时的处理
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
})
|
|
})
|
|
-
|
|
|
|
|
|
+onUnmounted(() => {
|
|
|
|
+ clearTimeout(timer)
|
|
|
|
+})
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
@@ -424,11 +464,59 @@ onMounted(() => {
|
|
background-color: #fff;
|
|
background-color: #fff;
|
|
border-radius: 12px;
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
|
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
|
|
|
|
+ position: relative; /* 添加相对定位 */
|
|
|
|
+ cursor: pointer; /* 添加指针样式 */
|
|
|
|
+
|
|
img {
|
|
img {
|
|
width:100%
|
|
width:100%
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /* 过期遮罩层样式 */
|
|
|
|
+ .expired-mask {
|
|
|
|
+ position: absolute;
|
|
|
|
+ top: 0;
|
|
|
|
+ left: 0;
|
|
|
|
+ width: 100%;
|
|
|
|
+ height: 100%;
|
|
|
|
+ background-color: rgba(0, 0, 0, 0.6);
|
|
|
|
+ border-radius: 12px;
|
|
|
|
+ display: flex;
|
|
|
|
+ flex-direction: column;
|
|
|
|
+ justify-content: center;
|
|
|
|
+ align-items: center;
|
|
|
|
+ color: #fff;
|
|
|
|
+ opacity: 0;
|
|
|
|
+ transition: opacity 0.3s ease;
|
|
|
|
+ pointer-events: none;
|
|
|
|
+
|
|
|
|
+ .el-icon {
|
|
|
|
+ margin-bottom: 10px;
|
|
|
|
+ // animation: rotate 2s infinite linear;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ p {
|
|
|
|
+ font-size: 16px;
|
|
|
|
+ font-weight: 500;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* 当二维码过期时显示遮罩层 */
|
|
|
|
+ &.expired .expired-mask {
|
|
|
|
+ opacity: 1;
|
|
|
|
+ pointer-events: auto;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /* 添加旋转动画 */
|
|
|
|
+ // @keyframes rotate {
|
|
|
|
+ // from {
|
|
|
|
+ // transform: rotate(0deg);
|
|
|
|
+ // }
|
|
|
|
+ // to {
|
|
|
|
+ // transform: rotate(360deg);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+
|
|
.qrcode-tip {
|
|
.qrcode-tip {
|
|
font-size: 16px;
|
|
font-size: 16px;
|
|
color: #333;
|
|
color: #333;
|