|
|
@@ -1,31 +1,47 @@
|
|
|
<template>
|
|
|
-
|
|
|
-
|
|
|
- <div style="height: 100vh; overflow: hidden; display: flex; flex-direction: column;">
|
|
|
-
|
|
|
+ <div
|
|
|
+ style="
|
|
|
+ height: 100vh;
|
|
|
+ overflow: hidden;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ "
|
|
|
+ >
|
|
|
<!-- 用户名称 -->
|
|
|
- <div style="height: 100%;
|
|
|
- background-image: url('static/images/bg-login.png');
|
|
|
- background-repeat: no-repeat;
|
|
|
- background-position-y: 0px;
|
|
|
- background-size: 100%">
|
|
|
-
|
|
|
- <div style="padding: 100px 16px 30px 32px; display: flex;
|
|
|
- justify-content:space-between;
|
|
|
- align-items:center;">
|
|
|
+ <div
|
|
|
+ style="
|
|
|
+ height: 100%;
|
|
|
+ background-image: url('static/images/bg-login.png');
|
|
|
+ background-repeat: no-repeat;
|
|
|
+ background-position-y: 0px;
|
|
|
+ background-size: 100%;
|
|
|
+ "
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ style="
|
|
|
+ padding: 100px 16px 30px 32px;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+ "
|
|
|
+ >
|
|
|
<div>
|
|
|
- <div style="color: #5C677C; height: 30px;">
|
|
|
+ <div style="color: #5c677c; height: 30px">
|
|
|
<van-tag type="primary" size="large">欢迎登录</van-tag>
|
|
|
</div>
|
|
|
- <div style="font-size: 1.1rem; font-weight: bold;">
|
|
|
+ <div style="font-size: 1.1rem; font-weight: bold">
|
|
|
<span>驼人物联网平台</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
-
|
|
|
- <div style="margin-top: 60px;">
|
|
|
- <van-form ref="formRef" show-error :show-error-message="false" @submit="onSubmit">
|
|
|
+ <div style="margin-top: 60px">
|
|
|
+ <van-form
|
|
|
+ ref="formRef"
|
|
|
+ show-error
|
|
|
+ :show-error-message="false"
|
|
|
+ @submit="onSubmit"
|
|
|
+ >
|
|
|
<van-cell-group inset>
|
|
|
<van-field
|
|
|
v-model="username"
|
|
|
@@ -47,13 +63,15 @@
|
|
|
:rules="[{ required: true, message: '请输入密码' }]"
|
|
|
>
|
|
|
</van-field>
|
|
|
- <van-field style="align-items: center;"
|
|
|
+ <van-field
|
|
|
+ style="align-items: center"
|
|
|
v-model="captchaCode"
|
|
|
name="captchaCode"
|
|
|
label="验证码"
|
|
|
label-width="70"
|
|
|
placeholder="请输入验证码"
|
|
|
- :rules="[{ required: true, message: '请填写账号' }]">
|
|
|
+ :rules="[{ required: true, message: '请填写账号' }]"
|
|
|
+ >
|
|
|
<template #button>
|
|
|
<van-image
|
|
|
width="100"
|
|
|
@@ -64,16 +82,29 @@
|
|
|
/>
|
|
|
</template>
|
|
|
</van-field>
|
|
|
- <div style="padding: 16px;">
|
|
|
- <van-checkbox v-model="isRememberMe" shape="square">记住密码</van-checkbox>
|
|
|
+ <div style="padding: 16px">
|
|
|
+ <van-checkbox v-model="isRememberMe" shape="square"
|
|
|
+ >记住密码</van-checkbox
|
|
|
+ >
|
|
|
</div>
|
|
|
</van-cell-group>
|
|
|
- <div style="margin: 16px;">
|
|
|
+ <div style="margin: 16px">
|
|
|
<van-button
|
|
|
- round block type="primary" size="large"
|
|
|
- native-type="submit">登录</van-button>
|
|
|
+ round
|
|
|
+ block
|
|
|
+ type="primary"
|
|
|
+ size="large"
|
|
|
+ native-type="submit"
|
|
|
+ >登录</van-button
|
|
|
+ >
|
|
|
</div>
|
|
|
- <div style="padding: 0px 16px; display: flex; justify-content: space-between;">
|
|
|
+ <div
|
|
|
+ style="
|
|
|
+ padding: 0px 16px;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ "
|
|
|
+ >
|
|
|
<div>
|
|
|
<a @click="onFindpassword">忘记密码?</a>
|
|
|
</div>
|
|
|
@@ -83,141 +114,132 @@
|
|
|
</div>
|
|
|
</van-form>
|
|
|
</div>
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
</div>
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
</div>
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
- import { onMounted, ref } from 'vue'
|
|
|
- import { useStoreOfUserInfo } from '@/store/userInfo'
|
|
|
- import { useRouter } from 'vue-router'
|
|
|
- import { post, post_promise } from '@/network/axios';
|
|
|
- import { showToast, type FormInstance } from 'vant';
|
|
|
- // 路由
|
|
|
- const router = useRouter();
|
|
|
- const userInfo = useStoreOfUserInfo();
|
|
|
- // 表单实例
|
|
|
- const formRef = ref<FormInstance>();
|
|
|
- // 用户名和验证码
|
|
|
- const username = ref('')
|
|
|
- const password = ref('')
|
|
|
- const captchaCode = ref('')
|
|
|
- const captchaKey = ref('')
|
|
|
- const isRememberMe = ref(true);
|
|
|
-
|
|
|
-
|
|
|
- // 验证吗
|
|
|
- const captchaSrc = ref<string>('');
|
|
|
- const refreshVerifycode = () => {
|
|
|
- post({url: '/open/getCaptcha'}, (result: any) => {
|
|
|
- console.log(result.data.captchaImg)
|
|
|
- captchaSrc.value = result.data.captchaImg
|
|
|
- captchaKey.value = result.data.captchaKey
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // 点击了验证码
|
|
|
- const onClickVerifyCode = (event: any) => {
|
|
|
- console.log(event)
|
|
|
- refreshVerifycode();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 点击了注册
|
|
|
- const onRegister = () => {
|
|
|
- // 跳转到注册
|
|
|
- router.replace('/register');
|
|
|
- }
|
|
|
-
|
|
|
- // 点击了忘记密码
|
|
|
- const onFindpassword = () => {
|
|
|
- // 跳转到注册
|
|
|
- router.replace('/findpassword');
|
|
|
+import { onMounted, ref } from "vue";
|
|
|
+import { useStoreOfUserInfo } from "@/store/userInfo";
|
|
|
+import { useRouter } from "vue-router";
|
|
|
+import { post, post_promise } from "@/network/axios";
|
|
|
+import { showToast, type FormInstance } from "vant";
|
|
|
+// 路由
|
|
|
+const router = useRouter();
|
|
|
+const userInfo = useStoreOfUserInfo();
|
|
|
+// 表单实例
|
|
|
+const formRef = ref<FormInstance>();
|
|
|
+// 用户名和验证码
|
|
|
+const username = ref("");
|
|
|
+const password = ref("");
|
|
|
+const captchaCode = ref("");
|
|
|
+const captchaKey = ref("");
|
|
|
+const isRememberMe = ref(true);
|
|
|
+
|
|
|
+// 验证吗
|
|
|
+const captchaSrc = ref<string>("");
|
|
|
+const refreshVerifycode = () => {
|
|
|
+ post({ url: "/open/getCaptcha" }, (result: any) => {
|
|
|
+ console.log(result.data.captchaImg);
|
|
|
+ captchaSrc.value = result.data.captchaImg;
|
|
|
+ captchaKey.value = result.data.captchaKey;
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+// 点击了验证码
|
|
|
+const onClickVerifyCode = (event: any) => {
|
|
|
+ console.log(event);
|
|
|
+ refreshVerifycode();
|
|
|
+};
|
|
|
+
|
|
|
+// 点击了注册
|
|
|
+const onRegister = () => {
|
|
|
+ // 跳转到注册
|
|
|
+ router.replace("/register");
|
|
|
+};
|
|
|
+
|
|
|
+// 点击了忘记密码
|
|
|
+const onFindpassword = () => {
|
|
|
+ // 跳转到注册
|
|
|
+ router.replace("/findpassword");
|
|
|
+};
|
|
|
+
|
|
|
+// 生命周期
|
|
|
+onMounted(() => {
|
|
|
+ console.log("onMounted");
|
|
|
+ refreshVerifycode();
|
|
|
+ isRememberMe.value = userInfo.isRememberMe as boolean;
|
|
|
+ if (isRememberMe.value) {
|
|
|
+ username.value = userInfo.username;
|
|
|
+ password.value = userInfo.password as string;
|
|
|
}
|
|
|
-
|
|
|
- // 生命周期
|
|
|
- onMounted(() => {
|
|
|
- console.log('onMounted');
|
|
|
- refreshVerifycode();
|
|
|
- isRememberMe.value = userInfo.isRememberMe as boolean;
|
|
|
- if(isRememberMe.value){
|
|
|
- username.value = userInfo.username
|
|
|
- password.value = userInfo.password as string;
|
|
|
- }
|
|
|
- })
|
|
|
- // 登录提交
|
|
|
- const onSubmit = () => {
|
|
|
- formRef.value?.validate().then(() => {
|
|
|
+});
|
|
|
+// 登录提交
|
|
|
+const onSubmit = () => {
|
|
|
+ formRef.value
|
|
|
+ ?.validate()
|
|
|
+ .then(() => {
|
|
|
// 记住密码
|
|
|
userInfo.$patch({
|
|
|
- isRememberMe: isRememberMe.value as any
|
|
|
- })
|
|
|
+ isRememberMe: isRememberMe.value as any,
|
|
|
+ });
|
|
|
// 记住账号密码
|
|
|
- if(isRememberMe.value){
|
|
|
+ if (isRememberMe.value) {
|
|
|
userInfo.$patch({
|
|
|
username: username.value as any,
|
|
|
- password: password.value as any
|
|
|
- })
|
|
|
+ password: password.value as any,
|
|
|
+ });
|
|
|
}
|
|
|
// 登录
|
|
|
- post_promise({url: '/user/login', data: {
|
|
|
- username: username.value,
|
|
|
- password: password.value,
|
|
|
- captchaCode: captchaCode.value,
|
|
|
- captchaKey: captchaKey.value,
|
|
|
- }})
|
|
|
- .then((result) => {
|
|
|
- console.log(result)
|
|
|
- const { username, token, roleIds, mobile } = result.data;
|
|
|
- userInfo.$patch({
|
|
|
- mobile: mobile,
|
|
|
- username: username,
|
|
|
- token: token,
|
|
|
- roles: roleIds,
|
|
|
- isLogin: true as any,
|
|
|
- isRememberMe: isRememberMe.value as any,
|
|
|
- })
|
|
|
- // 是否记住密码
|
|
|
- if(isRememberMe.value){
|
|
|
- userInfo.$patch({
|
|
|
- password: password.value as any
|
|
|
- })
|
|
|
- }else{
|
|
|
+ post_promise({
|
|
|
+ url: "/user/login",
|
|
|
+ data: {
|
|
|
+ username: username.value,
|
|
|
+ password: password.value,
|
|
|
+ captchaCode: captchaCode.value,
|
|
|
+ captchaKey: captchaKey.value,
|
|
|
+ },
|
|
|
+ }).then(
|
|
|
+ (result) => {
|
|
|
+ console.log(result);
|
|
|
+ const { username, token, roleIds, mobile, id } = result.data;
|
|
|
userInfo.$patch({
|
|
|
- password: '' as any
|
|
|
- })
|
|
|
+ id: id,
|
|
|
+ mobile: mobile,
|
|
|
+ username: username,
|
|
|
+ token: token,
|
|
|
+ roles: roleIds,
|
|
|
+ isLogin: true as any,
|
|
|
+ isRememberMe: isRememberMe.value as any,
|
|
|
+ });
|
|
|
+ // 是否记住密码
|
|
|
+ if (isRememberMe.value) {
|
|
|
+ userInfo.$patch({
|
|
|
+ password: password.value as any,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ userInfo.$patch({
|
|
|
+ password: "" as any,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ console.log(userInfo);
|
|
|
+ // 跳转到首页
|
|
|
+ router.replace("/");
|
|
|
+ },
|
|
|
+ (result) => {
|
|
|
+ showToast(result);
|
|
|
}
|
|
|
- console.log(userInfo)
|
|
|
- // 跳转到首页
|
|
|
- router.replace('/');
|
|
|
- },(result) => {
|
|
|
- showToast(result);
|
|
|
- })
|
|
|
- }).catch((ex) => {
|
|
|
- showToast(ex);
|
|
|
+ );
|
|
|
})
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ .catch((ex) => {
|
|
|
+ showToast(ex);
|
|
|
+ });
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
- .van-tabbar--fixed{
|
|
|
- left: auto;
|
|
|
- max-width: 475px;
|
|
|
- }
|
|
|
-
|
|
|
-</style>
|
|
|
+.van-tabbar--fixed {
|
|
|
+ left: auto;
|
|
|
+ max-width: 475px;
|
|
|
+}
|
|
|
+</style>
|