From d1448cb0ef10f358bb7bddb4e1ec268515e0b787 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 11:46:57 +0800 Subject: [PATCH] 项目初始化 --- pages/login/index.vue | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 115 insertions(+), 0 deletions(-) diff --git a/pages/login/index.vue b/pages/login/index.vue new file mode 100644 index 0000000..4317149 --- /dev/null +++ b/pages/login/index.vue @@ -0,0 +1,115 @@ +<!-- 钃濊壊绠�娲佺櫥褰曢〉闈� --> +<template> + <view class="t-login"> + <!-- 椤甸潰瑁呴グ鍥剧墖 --> + <image class="img-a" src="/static/img/b-1.png"></image> + <image class="img-b" src="/static/img/b-2.png"></image> + <!-- 鏍囬 --> + <view class="t-b">{{ title }}</view> + <view class="t-b2">{{ subTitle }}</view> + <form class="cl"> + <!-- 鐧诲綍璐﹀彿 --> + <view class="login-form-item"> + <u-input v-model="username" placeholder="璇疯緭鍏ョ櫥褰曠敤鎴峰悕" maxlength="30"> + <u-icon slot="prefix" name="account" size="35px"></u-icon> + </u-input> + </view> + <!-- 鐧诲綍瀵嗙爜 --> + <view class="login-form-item"> + <u-input v-model="password" type="password" placeholder="璇疯緭鍏ョ櫥褰曞瘑鐮�" maxlength="16"> + <u-icon slot="prefix" name="lock" size="35px"></u-icon> + </u-input> + </view> + <!-- 鍥惧舰楠岃瘉鐮� --> + <view class="login-form-item t-captcha"> + <u-input v-model="captchaCode" type="number" placeholder="璇疯緭鍏ラ獙璇佺爜" maxlength="4"> + <u-icon slot="prefix" name="fingerprint" size="35px"></u-icon> + </u-input> + <image :src="captcha" @click="getCaptcha" class="t-captcha-img"></image> + </view> + <button @tap="login()">鐧� 褰�</button> + </form> + </view> +</template> +<script> +import * as CaptchaApi from '@/api/captcha' +import { isEmpty } from '@/utils/verify.js' + +export default { + data() { + return { + title: '鑻ヤ緷鏉冮檺绠$悊绯荤粺', + subTitle: '娆㈣繋鍥炴潵锛屽紑濮嬪伐浣滃惂锛�', + // 鍥惧舰楠岃瘉鐮佷俊鎭� + captcha: null, + // 鐧诲綍璐﹀彿 + username: 'admin', + // 瀵嗙爜 + password: 'admin123', + // 鍥惧舰楠岃瘉鐮� + captchaCode: '', + uuid: '' + }; + }, + created() { + // 鑾峰彇鍥惧舰楠岃瘉鐮� + this.getCaptcha() + }, + methods: { + // 鑾峰彇鍥惧舰楠岃瘉鐮� + getCaptcha() { + const app = this + CaptchaApi.image().then(result => { + app.captcha = 'data:image/gif;base64,' + result.img + app.uuid = result.uuid + }) + }, + // 楠岃瘉琛ㄥ崟鍐呭 + validItem() { + const app = this + if (isEmpty(app.username)) { + uni.$u.toast('璇疯緭鍏ョ櫥褰曠敤鎴峰悕') + return false + } + if (isEmpty(app.password)) { + uni.$u.toast('璇疯緭鍏ョ櫥褰曞瘑鐮�') + return false + } + if (isEmpty(app.captchaCode)) { + uni.$u.toast('璇疯緭鍏ラ獙璇佺爜') + return false + } + return true + }, + // 纭鐧诲綍 + login() { + const app = this + let valid = app.validItem(); + if (valid) { + app.isLoading = true + app.$store.dispatch('Login', { + username: app.username, + password: app.password, + code: app.captchaCode, + uuid: app.uuid + }).then(result => { + uni.switchTab({ + url: '/pages/index/index', + fail(err) { + console.log(err) + } + }) + }) + .catch(err => { + app.captchaCode = '' + app.getCaptcha() + }) + .finally(() => app.isLoading = false) + } + }, + } +}; +</script> +<style lang="scss" scoped> +@import 'index.scss'; +</style> -- Gitblit v1.9.3