login.vue
5.54 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<template>
<view class="login-page">
<!-- 自定义头部 -->
<view class="header">
<image class="header-bg" src="./header_bg.png" />
<view class="header-content">
<image class="header-logo" src="/static/logo201.png" mode="widthFix" />
<text class="header-title">欢迎登录楚江销售系统</text>
</view>
</view>
<!-- 表单区 -->
<view class="form">
<view class="input-item">
<input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" placeholder-style="color:#aaa;" maxlength="30" />
</view>
<view class="input-item">
<input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" placeholder-style="color:#aaa;" maxlength="20" />
</view>
<view class="input-row" v-if="captchaEnabled">
<input v-model="loginForm.captcha" type="text" class="input" placeholder="请输入验证码" placeholder-style="color:#aaa;" maxlength="4" />
<image :src="codeUrl" @click="getCode" class="captcha-img" />
</view>
<view class="agree-row">
<uni-data-checkbox v-model="agreeVal" :localdata="agreeOptions" :multiple="true" />
<text @click="handleUserAgrement" class="link">《用户协议》</text>
<text @click="handlePrivacy" class="link">《隐私协议》</text>
</view>
<button @click="handleLogin" :disabled="Array.isArray(agreeVal) ? agreeVal.length===0 : !agreeVal" class="login-btn">立即登录</button>
<view class="reg text-center" v-if="register">
<text class="text-grey1">没有账号?</text>
<text @click="handleUserRegister" class="text-blue">立即注册</text>
</view>
</view>
</view>
</template>
<script>
import { getCodeImg } from '@/api/login'
import config from '@/config'
export default {
data() {
return {
//获取配置文件对象
globalConfig: getApp().globalData.config,
codeUrl: "",
captchaEnabled: false,
agreeVal: [],
agreeOptions: [{ text: '已预览并同意', value: '1' }],
// 用户注册开关
register: false,
//默认登录账号和密码
loginForm: {
username: getApp().globalData.config.loginInfo.userName,
password: getApp().globalData.config.loginInfo.password,
captcha: "",
sn: ''
}
}
},
created() {
this.getCode()
},
methods: {
// 用户注册
handleUserRegister() {
this.$tab.redirectTo('/pages/register')
},
// 隐私协议
handlePrivacy() {
let site = this.globalConfig.appInfo.agreements[0]
this.$tab.navigateTo('/pages/common/webview/index?title=' + site.title + '&url=' + site.url)
},
// 用户协议
handleUserAgrement() {
let site = this.globalConfig.appInfo.agreements[1]
this.$tab.navigateTo('/pages/common/webview/index?title=' + site.title + '&url=' + site.url)
},
// 获取图形验证码
getCode() {
getCodeImg().then(res => {
this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled
if (this.captchaEnabled) {
this.codeUrl = res.data.image
this.loginForm.sn = res.data.sn
}
})
},
// 登录方法
async handleLogin() {
if (this.loginForm.username === "") {
this.$modal.msgError("请输入您的账号")
} else if (this.loginForm.password === "") {
this.$modal.msgError("请输入您的密码")
} else if (this.loginForm.captcha === "" && this.captchaEnabled) {
this.$modal.msgError("请输入验证码")
} else {
this.$modal.loading("登录中,请耐心等待...")
this.pwdLogin()
}
},
// 密码登录
async pwdLogin() {
this.$store.dispatch('Login', this.loginForm).then(() => {
this.$modal.closeLoading()
this.loginSuccess()
}).catch(() => {
if (this.captchaEnabled) {
this.getCode()
}
})
},
// 登录成功后,处理函数
loginSuccess(result) {
this.$tab.reLaunch('/pages/index/index')
}
}
}
</script>
<style scoped lang="scss">
page { background-color: #fff; }
.login-page { width: 100%; height: 100%; }
.header {
position: relative;
height: 500rpx;
overflow: hidden;
&-bg {
width: 100%;
height: 100%;
}
&-content {
position: absolute;
left: 0;
right: 0;
top: 192rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
&-logo {
width: 298rpx; height: 120rpx;
margin-bottom: 60rpx;
}
&-title {
height: 60rpx;
font-weight: 600;
font-size: 44rpx;
color: rgba(0,0,0,0.9);
line-height: 60rpx;
}
}
.form {
margin: 34rpx auto 0;
width: 626rpx;
}
.input-item {
margin-bottom: 40rpx;
background-color: #fff;
border: 1px solid #F1F1F1;
height: 96rpx;
border-radius: 8rpx;
display: flex;
align-items: center;
}
.input { width: 100%; font-size: 32rpx; padding: 0 24rpx; }
.input-row {
margin: 30rpx auto;
display: flex;
align-items: center;
background-color: #fff;
border: 1px solid #e5e7eb;
height: 88rpx;
border-radius: 18rpx;
}
.captcha-img { width: 200rpx; height: 88rpx; border-left: 1px solid #e5e7eb; }
.agree-row {
display: flex;
align-items: center;
color: rgba(0,0,0,0.9);
margin-top: 8rpx;
font-size: 28rpx;
.link {
color: #3D48A3;
}
}
.login-btn {
width: 100%;
height: 88rpx;
line-height: 88rpx;
border-radius: 8rpx;
margin-top: 64rpx;
background-color: #3D48A3;
color: #fff;
font-size: 32rpx;
text-align: center;
}
.login-btn[disabled] {
background-color: rgba(61,72,163,0.5);
color: #fff;
}
.reg { margin-top: 20rpx; text-align: center; }
</style>