You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.7 KiB

3 months ago
<template>
<el-row v-show="getShow" class="login-form" style="margin-right: -10px; margin-left: -10px">
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
2 months ago
<img class="topImg" src="@/assets/imgs/screen/login-top.png" alt="logo" />
3 months ago
</el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px; margin-bottom:20px; text-align: center">
<img width="320px" height="320px" :src="imageUrl" alt="Converted Image" v-if="imageUrl" />
3 months ago
</el-col>
2 months ago
<el-col v-if="!refreshQR" :span="24" style="padding-right: 10px; padding-left: 10px; text-align: center">
<img class="bottomImg" src="@/assets/imgs/screen/login-bottom.png" alt="logo" />
</el-col>
<el-col v-if="refreshQR" :span="24" style="padding-right: 10px; padding-left: 10px; text-align: center">
<img class="bottomImg" src="@/assets/imgs/screen/qrsx.png" alt="logo" @click="handleRefresh" />
3 months ago
</el-col>
</el-row>
</template>
<script lang="ts" setup>
import logoImg from '@/assets/imgs/logo.png'
2 months ago
import * as LoginApi from '@/api/login'
import * as authUtil from '@/utils/auth'
3 months ago
import LoginFormTitle from './LoginFormTitle.vue'
import { LoginStateEnum, useLoginState } from './useLogin'
2 months ago
import router from '@/router'
3 months ago
defineOptions({ name: 'QrCodeForm' })
2 months ago
const imageUrl = ref('');
const uuuid =ref('')
2 months ago
const refreshQR = ref(false)
2 months ago
3 months ago
const { t } = useI18n()
const { handleBackLogin, getLoginState } = useLoginState()
const getShow = computed(() => true)
2 months ago
// 存储定时器 ID,用于后续清除定时器
let intervalId = ref();
2 months ago
const handleRefresh = () => {
window.location.reload()
}
2 months ago
const getimg =async ()=>{
const array = new Uint32Array(4);
crypto.getRandomValues(array);
let result = '';
array.forEach((value) => {
result += value.toString(16).padStart(8, '0');
});
uuuid.value = result;
var mockBinaryData = await LoginApi.getCodeWebPic({
scene:uuuid.value,
path: 'sub/common/waiting',
checkPath: false
});
// 对 Base64 编码的字符串进行解码
const binaryString = atob(mockBinaryData);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
// 将二进制数据转换为Blob对象
const blob = new Blob([bytes], { type: 'image/png' });
// 创建临时的URL
imageUrl.value = URL.createObjectURL(blob);
//开始刷新扫码信息
refaulst();
}
2 months ago
// 记录定时器开始的时间
const startTime = Date.now();
// 10 分钟的毫秒数
2 months ago
const tenMinutes = 10 *60 * 10000 ;
2 months ago
//定时刷新 判断是否扫码允许
const refaulst = ()=>{
2 months ago
refreshQR.value = false;
2 months ago
// 先清除之前的定时器,避免重复调用
if (intervalId) {
clearInterval(intervalId.value);
}
// 设置定时器,每 5 秒(可根据实际需求调整)调用一次接口
intervalId.value = setInterval(async () => {
try {
2 months ago
// 检查是否已经过去了 10 分钟
if (Date.now() - startTime >= tenMinutes) {
clearInterval(intervalId.value);
console.log('定时器已停止,已过去 10 分钟。');
2 months ago
refreshQR.value = true;
2 months ago
return;
}
2 months ago
const res = await LoginApi.qrLoginCode({code:uuuid.value})
if(res){
2 months ago
clearInterval(intervalId.value);
2 months ago
authUtil.setToken(res)
router.push({ path: '/' })
}
} catch (error) {
console.error('获取扫码状态失败:', error);
}
}, 5000);
}
onMounted(() => {
// getCookie()
getimg()
})
3 months ago
</script>
2 months ago
<style lang="scss" scoped>
.expired-text{
color: #ff0000;
margin-top: 40px;
margin-right: 10px;
}
.bottomImg{
width:320px;
}
.topImg{
height: 200px;
}
</style>