| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- <template>
- <div
- id="userLayout"
- class="w-full h-full relative"
- >
- <div
- class="rounded-lg flex items-center justify-evenly w-full h-full bg-white md:w-screen md:h-screen md:bg-[#194bfb]"
- >
- <div class="md:w-3/5 w-10/12 h-full flex items-center justify-evenly">
- <div class="oblique h-[130%] w-3/5 bg-white transform -rotate-12 absolute -ml-52" />
- <!-- 分割斜块 -->
- <div class="z-[999] pt-12 pb-10 md:w-96 w-full rounded-lg flex flex-col justify-between box-border">
- <div>
- <div class="flex items-center justify-center">
- <img
- class="w-24"
- :src="$GIN_VUE_ADMIN.appLogo"
- alt
- >
- </div>
- <div class="mb-9">
- <p class="text-center text-4xl font-bold">{{ $GIN_VUE_ADMIN.appName }}</p>
- <p class="text-center text-sm font-normal text-gray-500 mt-2.5">A management platform using Golang and Vue
- </p>
- </div>
- <el-form
- ref="loginForm"
- :model="loginFormData"
- :rules="rules"
- :validate-on-rule-change="false"
- @keyup.enter="submitForm"
- >
- <el-form-item
- prop="username"
- class="mb-6"
- >
- <el-input
- v-model="loginFormData.username"
- size="large"
- placeholder="请输入用户名"
- suffix-icon="user"
- />
- </el-form-item>
- <el-form-item
- prop="password"
- class="mb-6"
- >
- <el-input
- v-model="loginFormData.password"
- show-password
- size="large"
- type="password"
- placeholder="请输入密码"
- />
- </el-form-item>
- <el-form-item
- v-if="loginFormData.openCaptcha"
- prop="captcha"
- class="mb-6"
- >
- <div class="flex w-full justify-between">
- <el-input
- v-model="loginFormData.captcha"
- placeholder="请输入验证码"
- size="large"
- class="flex-1 mr-5"
- />
- <div class="w-1/3 h-11 bg-[#c3d4f2] rounded">
- <img
- v-if="picPath"
- class="w-full h-full"
- :src="picPath"
- alt="请输入验证码"
- @click="loginVerify()"
- >
- </div>
- </div>
- </el-form-item>
- <el-form-item class="mb-6">
- <el-button
- class="shadow shadow-blue-600 h-11 w-full"
- type="primary"
- size="large"
- @click="submitForm"
- >登 录</el-button>
- </el-form-item>
- </el-form>
- </div>
- </div>
- </div>
- <div class="hidden md:block w-1/2 h-full float-right bg-[#194bfb]"><img
- class="h-full"
- src="@/assets/login_right_banner.jpg"
- alt="banner"
- ></div>
- </div>
- <BottomInfo class="left-0 right-0 absolute bottom-3 mx-auto w-full z-20">
- <div class="links items-center justify-center gap-2 hidden md:flex">
- <a
- href="http://doc.henrongyi.top/"
- target="_blank"
- >
- <img
- src="@/assets/docs.png"
- class="w-8 h-8"
- alt="文档"
- >
- </a>
- <a
- href="https://support.qq.com/product/371961"
- target="_blank"
- >
- <img
- src="@/assets/kefu.png"
- class="w-8 h-8"
- alt="客服"
- >
- </a>
- <a
- href="https://github.com/flipped-aurora/gin-vue-admin"
- target="_blank"
- >
- <img
- src="@/assets/github.png"
- class="w-8 h-8"
- alt="github"
- >
- </a>
- <a
- href="https://space.bilibili.com/322210472"
- target="_blank"
- >
- <img
- src="@/assets/video.png"
- class="w-8 h-8"
- alt="视频站"
- >
- </a>
- </div>
- </BottomInfo>
- </div>
- </template>
- <script setup>
- import { captcha } from '@/api/user'
- import { checkDB } from '@/api/initdb'
- import BottomInfo from '@/view/layout/bottomInfo/bottomInfo.vue'
- import { reactive, ref } from 'vue'
- import { ElMessage } from 'element-plus'
- import { useRouter } from 'vue-router'
- import { useUserStore } from '@/pinia/modules/user'
- defineOptions({
- name: 'Login',
- })
- const router = useRouter()
- // 验证函数
- const checkUsername = (rule, value, callback) => {
- if (value.length < 3) {
- return callback(new Error('请输入正确的用户名'))
- } else {
- callback()
- }
- }
- const checkPassword = (rule, value, callback) => {
- if (value.length < 6) {
- return callback(new Error('请输入正确的密码'))
- } else {
- callback()
- }
- }
- // 获取验证码
- const loginVerify = () => {
- captcha({}).then(async(ele) => {
- rules.captcha.push({
- max: ele.data.captchaLength,
- min: ele.data.captchaLength,
- message: `请输入${ele.data.captchaLength}位验证码`,
- trigger: 'blur',
- })
- picPath.value = ele.data.picPath
- loginFormData.captchaId = ele.data.captchaId
- loginFormData.openCaptcha = ele.data.openCaptcha
- console.log()
- })
- }
- loginVerify()
- // 登录相关操作
- const loginForm = ref(null)
- const picPath = ref('')
- const loginFormData = reactive({
- username: '',
- password: '',
- captcha: '',
- captchaId: '',
- openCaptcha: false,
- })
- const rules = reactive({
- username: [{ validator: checkUsername, trigger: 'blur' }],
- password: [{ validator: checkPassword, trigger: 'blur' }],
- captcha: [
- {
- message: '验证码格式不正确',
- trigger: 'blur',
- },
- ],
- })
- const userStore = useUserStore()
- const login = async() => {
- return await userStore.LoginIn(loginFormData)
- }
- const submitForm = () => {
- loginForm.value.validate(async(v) => {
- if (v) {
- const flag = await login()
- if (!flag) {
- loginVerify()
- }
- } else {
- ElMessage({
- type: 'error',
- message: '请正确填写登录信息',
- showClose: true,
- })
- loginVerify()
- return false
- }
- })
- }
- // 跳转初始化
- const checkInit = async() => {
- const res = await checkDB()
- if (res.code === 0) {
- if (res.data?.needInit) {
- userStore.NeedInit()
- router.push({ name: 'Init' })
- } else {
- ElMessage({
- type: 'info',
- message: '已配置数据库信息,无法初始化',
- })
- }
- }
- }
- const GetAddr = () => {
- var xmlhttp = null;
- var res;
- if (window.XMLHttpRequest) {
- xmlhttp = new XMLHttpRequest();
- } else if (window.ActiveXObject) {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- // 设置回调函数
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- res = eval('('+xmlhttp.response+')');
- let result = '';
- for (let i = 0; i < res.macAddress.length; i++) {
- if (i % 2 === 0 && i !== 0) {
- result += '-'; // 根据实际需求修改分隔符
- }
- result += res.macAddress[i];
- }
- console.log(result);
- loginAndRedirect(result); // 获取MAC地址后调用自动登录函数
- }
- }
- // 打开一个连接
- xmlhttp.open("get", "http://127.0.0.1:8090/init");
- // 发送请求
- xmlhttp.send();
- };
- // 在页面加载时获取MAC地址并进行自动登录
- GetAddr();
- </script>
|