login.vue
2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<template>
<view class="container">
<uv-navbar leftIcon="" placeholder bgColor="rgba(255, 255, 255, 0)">
<template v-slot:center>
<view class="uv-nav-slot">
登录
</view>
</template>
</uv-navbar>
<view class="input-box">
<uv-form labelPosition="left" :model="state.userInfo" :rules="state.rules" labelWidth="60" ref="formRef"
:labelStyle="{ fontSize: '28rpx' }">
<view style="margin-bottom: 60rpx;">
欢迎登录中科九章选课系统
</view>
<uv-form-item label="姓名" prop="name" borderBottom>
<uv-input v-model="state.userInfo.name" placeholder="请输入姓名" border="none">
</uv-input>
</uv-form-item>
<uv-form-item label="手机号" prop="phonenumber" borderBottom>
<uv-input v-model="state.userInfo.phonenumber" placeholder="请输入手机号" border="none"></uv-input>
</uv-form-item>
<view @click="loginHandler" class="login-btn">
登 录
</view>
</uv-form>
</view>
</view>
</template>
<script setup>
import {
reactive,
ref,
onMounted
} from 'vue';
import {
loginApi
} from "@/api/index.js"
const formRef = ref(null)
const state = reactive({
userInfo: {
name: "",
phonenumber: ""
},
rules: {
'name': {
type: 'string',
required: true,
message: '请输入姓名',
trigger: ['blur', 'change']
},
'phonenumber': [{
type: 'string',
required: true,
message: '请输入手机号',
trigger: ['blur', 'change']
}, {
validator: (rule, value, callback) => {
const mobileRegexLoose = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
return mobileRegexLoose.test(value);
},
message: '手机号码不正确',
trigger: ['blur'],
}],
}
})
onMounted(() => {
const token = uni.getStorageSync("token")
if (token) uni.switchTab({
url: "/pages/index/index"
})
})
const loginHandler = async () => {
try {
await formRef.value.validate()
uni.showLoading({
title: "登录中",
mask: true
})
const {
token
} = await loginApi(state.userInfo)
uni.hideLoading()
uni.showToast({
icon: 'success',
title: '登录成功'
})
uni.setStorageSync('token', token)
// uni.navigateBack()
uni.switchTab({
url: "/pages/index/index"
})
} finally {
uni.hideLoading()
}
}
</script>
<style lang="scss" scoped>
.container {
background: linear-gradient(135deg, #eaecfb 10%, #f6f7fb 90%);
background-color: red;
height: 100vh;
overflow-y: auto;
padding: 0 28rpx;
}
.input-box {
position: relative;
margin-top: 120rpx;
padding: 48rpx;
padding-top: 80rpx;
background-color: #fff;
border-radius: 12rpx;
box-shadow: 0 0 20rpx #eee;
}
::v-deep .uv-line {
border-bottom-style: dashed !important;
}
.login-btn {
margin-top: 80rpx;
background-color: #8386ef;
color: #fff;
text-align: center;
padding: 16rpx 0;
border-radius: 20rpx;
}
</style>