Browse Source

快捷登陆

master
赵鹏 2 months ago
parent
commit
8d174badfe
  1. 13
      src/api/login/index.ts
  2. 3
      src/views/Login/Login.vue
  3. 12
      src/views/Login/components/LoginForm.vue
  4. 77
      src/views/Login/components/QrCodeForm.vue

13
src/api/login/index.ts

@ -7,6 +7,8 @@ export interface SmsCodeVO {
scene: number scene: number
} }
export interface SmsLoginVO { export interface SmsLoginVO {
mobile: string mobile: string
code: string code: string
@ -72,10 +74,19 @@ export const socialAuthRedirect = (type: number, redirectUri: string) => {
} }
// 获取验证图片以及 token // 获取验证图片以及 token
export const getCode = (data: any) => { export const getCode = (data: any) => {
debugger
return request.postOriginal({ url: 'system/captcha/get', data }) return request.postOriginal({ url: 'system/captcha/get', data })
} }
// 获取登陆图片
export const getCodeWebPic = (data: any) => {
return request.post({ url: 'system/auth/web_code_login', data })
}
// 根据扫码生产的uuuid 进行登陆
export const qrLoginCode = (data: any) => {
return request.post({ url: 'system/auth/social-qr-login-openid', data })
}
// 滑动或者点选验证 // 滑动或者点选验证
export const reqCheck = (data: any) => { export const reqCheck = (data: any) => {
return request.postOriginal({ url: 'system/captcha/check', data }) return request.postOriginal({ url: 'system/captcha/check', data })

3
src/views/Login/Login.vue

@ -51,8 +51,7 @@
> >
<!-- 账号登录 --> <!-- 账号登录 -->
<LoginForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" /> <LoginForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
<!-- 手机登录 -->
<MobileForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
<!-- 二维码登录 --> <!-- 二维码登录 -->
<QrCodeForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" /> <QrCodeForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
<!-- 注册 --> <!-- 注册 -->

12
src/views/Login/components/LoginForm.vue

@ -92,13 +92,13 @@
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item> <el-form-item>
<el-row :gutter="5" justify="space-between" style="width: 100%"> <el-row :gutter="5" justify="space-between" style="width: 100%">
<el-col :span="8"> <!-- <el-col :span="8">
<XButton <XButton
:title="t('login.btnMobile')" :title="t('login.btnMobile')"
class="w-[100%]" class="w-[100%]"
@click="setLoginState(LoginStateEnum.MOBILE)" @click="setLoginState(LoginStateEnum.MOBILE)"
/> />
</el-col> </el-col> -->
<el-col :span="8"> <el-col :span="8">
<XButton <XButton
:title="t('login.btnQRCode')" :title="t('login.btnQRCode')"
@ -116,7 +116,7 @@
</el-row> </el-row>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-divider content-position="center">{{ t('login.otherLogin') }}</el-divider> <!-- <el-divider content-position="center">{{ t('login.otherLogin') }}</el-divider>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item> <el-form-item>
<div class="w-[100%] flex justify-between"> <div class="w-[100%] flex justify-between">
@ -131,8 +131,8 @@
/> />
</div> </div>
</el-form-item> </el-form-item>
</el-col> </el-col> -->
<el-divider content-position="center">萌新必读</el-divider> <!-- <el-divider content-position="center">萌新必读</el-divider>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item> <el-form-item>
<div class="w-[100%] flex justify-between"> <div class="w-[100%] flex justify-between">
@ -146,7 +146,7 @@
</el-link> </el-link>
</div> </div>
</el-form-item> </el-form-item>
</el-col> </el-col> -->
</el-row> </el-row>
</el-form> </el-form>
</template> </template>

77
src/views/Login/components/QrCodeForm.vue

@ -5,7 +5,10 @@
</el-col> </el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-card class="mb-10px text-center" shadow="hover"> <el-card class="mb-10px text-center" shadow="hover">
<Qrcode :logo="logoImg" /> <!-- <Qrcode :logo="logoImg" /> -->
<!-- 显示图片 -->
<img :src="imageUrl" alt="Converted Image" v-if="imageUrl" />
<XButton title="显示登陆二维码" class="w-[100%]" @click="getimg()" />
</el-card> </el-card>
</el-col> </el-col>
<el-divider class="enter-x">{{ t('login.qrcode') }}</el-divider> <el-divider class="enter-x">{{ t('login.qrcode') }}</el-divider>
@ -18,13 +21,81 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import logoImg from '@/assets/imgs/logo.png' import logoImg from '@/assets/imgs/logo.png'
import * as LoginApi from '@/api/login'
import * as authUtil from '@/utils/auth'
import LoginFormTitle from './LoginFormTitle.vue' import LoginFormTitle from './LoginFormTitle.vue'
import { LoginStateEnum, useLoginState } from './useLogin' import { LoginStateEnum, useLoginState } from './useLogin'
import router from '@/router'
defineOptions({ name: 'QrCodeForm' }) defineOptions({ name: 'QrCodeForm' })
const imageUrl = ref('');
const uuuid =ref('')
const { t } = useI18n() const { t } = useI18n()
const { handleBackLogin, getLoginState } = useLoginState() const { handleBackLogin, getLoginState } = useLoginState()
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.QR_CODE) const getShow = computed(() => unref(getLoginState) === LoginStateEnum.QR_CODE)
// ID
let intervalId = ref();
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();
}
//
const refaulst = ()=>{
//
if (intervalId) {
clearInterval(intervalId.value);
}
// 5
intervalId.value = setInterval(async () => {
try {
const res = await LoginApi.qrLoginCode({code:uuuid.value})
if(res){
debugger
authUtil.setToken(res)
router.push({ path: '/' })
clearInterval(intervalId.value);
}
} catch (error) {
console.error('获取扫码状态失败:', error);
}
}, 5000);
}
onMounted(() => {
// getCookie()
getimg()
})
</script> </script>

Loading…
Cancel
Save