From fe75cffbf3bae6777aa2794fd89fa5dc37f5df8d Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 10:11:23 +0800 Subject: [PATCH] 项目初始化 --- src/pages/login.vue | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 208 insertions(+), 0 deletions(-) diff --git a/src/pages/login.vue b/src/pages/login.vue new file mode 100644 index 0000000..620bdaa --- /dev/null +++ b/src/pages/login.vue @@ -0,0 +1,208 @@ +<template> + <view class="normal-login-container"> + <view class="logo-content align-center justify-center flex"> + <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix"> + </image> + <text class="title">鑻ヤ緷绉诲姩绔櫥褰�</text> + </view> + <view class="login-form-content"> + <view class="input-item flex align-center"> + <view class="iconfont icon-user icon"></view> + <input v-model="loginForm.username" class="input" type="text" placeholder="璇疯緭鍏ヨ处鍙�" maxlength="30" /> + </view> + <view class="input-item flex align-center"> + <view class="iconfont icon-password icon"></view> + <input v-model="loginForm.password" type="password" class="input" placeholder="璇疯緭鍏ュ瘑鐮�" maxlength="20" /> + </view> + <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled"> + <view class="iconfont icon-code icon"></view> + <input v-model="loginForm.code" type="number" class="input" placeholder="璇疯緭鍏ラ獙璇佺爜" maxlength="4" /> + <view class="login-code"> + <image :src="codeUrl" @click="getCode" class="login-code-img"></image> + </view> + </view> + <view class="action-btn"> + <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">鐧诲綍</button> + </view> + </view> + + <view class="xieyi text-center"> + <text class="text-grey1">鐧诲綍鍗充唬琛ㄥ悓鎰�</text> + <text @click="handleUserAgrement" class="text-blue">銆婄敤鎴峰崗璁��</text> + <text @click="handlePrivacy" class="text-blue">銆婇殣绉佸崗璁��</text> + </view> + </view> +</template> + +<script setup> +import modal from '@/plugins/modal' +import { getCodeImg } from '@/api/login' +import { ref } from "vue"; +import config from '@/config.js' +import useUserStore from '@/store/modules/user' +import { getWxCode } from '@/utils/geek'; +import { wxLogin } from '@/api/oauth'; +import { setToken } from '@/utils/auth'; +const userStore = useUserStore() +const codeUrl = ref(""); +const captchaEnabled = ref(true); // 鏄惁寮�鍚獙璇佺爜 +const useWxLogin = ref(false); // 鏄惁浣跨敤寰俊鐧诲綍 +const globalConfig = ref(config); +const loginForm = ref({ + username: "admin", + password: "admin123", + code: "", + uuid: '' +}); + +if (useWxLogin.value) { + getWxCode().then(res => { + console.log(res); + wxLogin('miniapp',res).then(res => { + if(res.token != null){ + setToken(res.token); + loginSuccess() + } + }); + }) +} + + +// 鑾峰彇鍥惧舰楠岃瘉鐮� +function getCode() { + getCodeImg().then(res => { + captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled + if (captchaEnabled.value) { + codeUrl.value = 'data:image/gif;base64,' + res.img + loginForm.value.uuid = res.uuid + } + }) +}; + +async function handleLogin() { + if (loginForm.value.username === "") { + modal.msgError("璇疯緭鍏ユ偍鐨勮处鍙�") + } else if (loginForm.value.password === "") { + modal.msgError("璇疯緭鍏ユ偍鐨勫瘑鐮�") + } else if (loginForm.value.code === "" && captchaEnabled.value) { + modal.msgError("璇疯緭鍏ラ獙璇佺爜") + } else { + modal.loading("鐧诲綍涓紝璇疯�愬績绛夊緟...") + pwdLogin() + } +}; +// 瀵嗙爜鐧诲綍 +async function pwdLogin() { + userStore.login(loginForm.value).then(() => { + modal.closeLoading() + loginSuccess() + }).catch(() => { + if (captchaEnabled.value) { + modal.closeLoading() + getCode() + } + }) +}; + +function loginSuccess(result) { + // 璁剧疆鐢ㄦ埛淇℃伅 + userStore.getInfo().then(res => { + uni.switchTab({ + url: '/pages/index' + }); + }) +} + +// 闅愮鍗忚 +function handlePrivacy() { + let site = globalConfig.value.appInfo.agreements[0]; + uni.navigateTo({ + url: `/pages/common/webview/index?title=${site.title}&url=${site.url}` + }); +}; +// 鐢ㄦ埛鍗忚 +function handleUserAgrement() { + let site = globalConfig.value.appInfo.agreements[1] + uni.navigateTo({ + url: `/pages/common/webview/index?title=${site.title}&url=${site.url}` + }); +}; + +getCode(); +</script> + +<style lang="scss"> +page { + background-color: #ffffff; +} + +.normal-login-container { + width: 100%; + + .logo-content { + width: 100%; + font-size: 21px; + text-align: center; + padding-top: 15%; + + image { + border-radius: 4px; + } + + .title { + margin-left: 10px; + } + } + + .login-form-content { + text-align: center; + margin: 20px auto; + margin-top: 15%; + width: 80%; + + .input-item { + margin: 20px auto; + background-color: #f5f6f7; + height: 45px; + border-radius: 20px; + + .icon { + font-size: 38rpx; + margin-left: 10px; + color: #999; + } + + .input { + width: 100%; + font-size: 14px; + line-height: 20px; + text-align: left; + padding-left: 15px; + } + + } + + .login-btn { + margin-top: 40px; + height: 45px; + } + + .xieyi { + color: #333; + margin-top: 20px; + } + + .login-code { + height: 38px; + float: right; + + .login-code-img { + height: 38px; + position: absolute; + margin-left: 10px; + width: 200rpx; + } + } + } +} +</style> -- Gitblit v1.9.3