login.vue
8.01 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<template>
<view class="page-login">
<view class="page-login__logo">
<image src="/static/logo.png" mode="aspectFit"></image>
</view>
<view class="page-login__title">
<view class="welcome">欢迎使用</view>
<view class="title">则一飞牛货主</view>
</view>
<!-- #ifdef MP-WEIXIN -->
<view class="page-login__content">
<u-cell title="手机号">
<template #value>
<input maxlength="11" v-model="form.mobile" placeholder="请输入手机号" type="number" />
</template>
</u-cell>
</view>
<view class="page-login__button">
<u-button shape="circle" type="primary" hover-class="active" :disabled="!isValidated" :loading="sendding" @click="sendCode">登录</u-button>
</view>
<!-- #endif -->
<!-- #ifdef MP-DINGTALK -->
<view class="page-login__dingtalk">
<u-button type="primary" plain shape="circle" :loading="submitting" loading-text="登录中..." @click="handleDingTalkLogin">
<u-icon :name="checked.includes('checked') ? 'lock-opened-fill' : 'lock-fill'" size="inherit" />
<text>钉钉授权登录</text>
</u-button>
</view>
<!-- #endif -->
<!-- <view class="page-login__check">-->
<!-- <u-checkbox-group v-model="checked" placement="column">-->
<!-- <u-checkbox name="checked" />-->
<!-- </u-checkbox-group>-->
<!-- <text>勾选即代表您同意</text>-->
<!-- <text class="link" @click="openPolicy">《用户协议》</text>-->
<!-- <text>以及</text>-->
<!-- <text class="link" @click="openPrivacy">《隐私政策》</text>-->
<!-- </view>-->
<!-- #ifdef MP-WEIXIN -->
<view class="page-login__wechat">
<u-button type="primary" plain shape="circle" open-type="getPhoneNumber" :loading="submitting" loading-text="登录中..." @getphonenumber="onGetPhoneNumber">
<!-- <u-icon name="weixin-fill" size="inherit" /> -->
<text>手机号快捷登录</text>
</u-button>
</view>
<!-- #endif -->
</view>
</template>
<script>
import { mapState } from 'vuex';
// #ifdef MP-DINGTALK
import { openAuthMiniApp, disposeAuthData } from 'dingtalk-design-libs/biz/openAuthMiniApp';
// #endif
export default {
data() {
return {
form: {
mobile: '',
verificationCode: '',
},
code: '',
sendding: false,
submitting: false,
checked: [],
};
},
computed: {
...mapState({
origin: state => state.origin,
}),
isValidated() {
//校验手机号和位数
let patt = /^[1][3-9][\d]{9}/;
return patt.test(this.form.mobile);
},
isChecked() {
return true; // this.checked.includes('checked');
},
},
onLoad() {
this.generateWeChatAuthCode();
},
onShow() {
uni.hideHomeButton();
},
methods: {
// 获取微信登录code
generateWeChatAuthCode() {
uni.login({
provider: 'weixin',
success: response => {
const { code } = response;
if (code) {
this.code = code;
} else {
return uni.showToast({ icon: 'none', title: '授权失败' });
}
},
});
},
// 用户协议
openPolicy() {
uni.$u.route({
url: '/pages/common/webview',
params: { url: 'https://zeyi-tms-product.oss-cn-hangzhou.aliyuncs.com/webview/consignor/consignor-policy.html' },
});
},
// 隐私政策
openPrivacy() {
uni.$u.route({
url: '/pages/common/webview',
params: { url: 'https://zeyi-tms-product.oss-cn-hangzhou.aliyuncs.com/webview/consignor/consignor-privacy.html' },
});
},
// 发送验证码并打开验证码页面
sendCode() {
// if (!this.isChecked) {
// return uni.showToast({ icon: 'none', title: '请您阅读并勾选《用户协议》和《隐私政策》' });
// }
if (!this.sendding) {
this.sendding = true;
uni.$u.api.login
.send({ mobile: this.form.mobile, origin: this.origin })
.then(() => {
uni.$u.route({ url: '/pages/login/code', params: { mobile: this.form.mobile } });
})
.finally(() => {
this.sendding = false;
});
}
},
// 获取当前登录用户手机号成功后自动登录
onGetPhoneNumber(e) {
if (!this.isChecked) {
return uni.showToast({ icon: 'none', title: '请您阅读并勾选《用户协议》和《隐私政策》' });
}
if (!e.detail.code) {
return;
}
console.info(e.detail);
if (!this.submitting) {
this.submitting = true;
uni.$u.api.login
.wxbind({ code: this.code, mobileCode: e.detail.code, encryptedData: e.detail.encryptedData, iv: e.detail.iv, origin: this.origin })
.then(response => {
const result = response.result || {};
this.$store.commit('SET_AUTHED', result.hasBind);
this.$store.commit('SET_USER_INFO', result);
uni.showToast({ title: '登录成功', icon: 'none' });
uni.$emit('refresh-permission');
setTimeout(() => {
uni.switchTab({ url: '/pages/order/index' });
}, 1500);
})
.catch(() => {
this.generateWeChatAuthCode();
})
.finally(() => {
this.submitting = false;
});
}
},
// 处理钉钉授权登录
handleDingTalkLogin() {
// if (!this.isChecked) {
// return uni.showToast({ icon: 'none', title: '请您阅读并勾选《用户协议》和《隐私政策》' });
// }
// #ifdef MP-DINGTALK
openAuthMiniApp({
path: 'pages/home/home', //不要改,这里是小程序dingwlanwvdmrtjjwdmd下的一个页面地址
panelHeight: 'percent50',
extraData: {
clientId: 'suiteyaqgg5vsf9ktnhec', // 应用ID(唯一标识)
rpcScope: 'Contact.User.Read',
fieldScope: 'Contact.User.mobile',
type: 0,
ext: JSON.stringify({}),
from: '',
},
});
// #endif
},
},
};
</script>
<style lang="scss">
.page-login {
padding: $padding-md;
font-size: $font-md;
min-height: 100vh;
background-color: #fff;
box-sizing: border-box;
&__logo {
text-align: center;
height: 240upx;
image {
height: 100%;
width: 100%;
}
}
&__title {
margin-top: $padding-md;
font-size: $font-lg * 1.2;
padding: $padding-md;
line-height: 2;
text-align: center;
color: $color-primary;
.welcome {
font-size: 40rpx;
}
.title {
font-size: 70rpx;
}
}
&__content {
color: $color-minor;
margin-top: $padding-md;
.u-cell__body__content {
flex: initial !important;
}
.u-cell__title {
min-width: $padding-md * 5 !important;
}
.u-cell input {
flex: auto;
}
}
&__button {
margin-top: $padding-md;
button {
border: 0;
color: #fff;
background-color: $color-primary;
padding: $padding-md;
line-height: 1.5;
text-align: center;
font-size: $font-md * 1.2;
border-radius: $radius-lg * 2;
&::after {
border: 0;
}
&.active {
background-color: darken($color-primary, 3%);
}
}
}
&__check {
display: flex;
align-items: center;
margin-top: $padding-md;
font-size: $font-sm;
.link {
color: $color-primary;
}
}
&__wechat {
color: $color-primary;
margin-top: $padding-md * 3;
.u-icon {
margin-right: $padding-base;
font-size: $font-lg * 1.5;
}
.u-button {
border: none !important;
font-size: $font-lg !important;
}
}
&__dingtalk {
margin-top: $padding-md * 3;
margin-bottom: $padding-md * 3;
.u-icon {
margin-right: $padding-sm;
font-size: $font-lg * 1.5;
color: $color-primary;
}
.u-button {
border: 1px solid $color-primary !important;
font-size: $font-lg !important;
background-color: $color-white;
}
}
}
</style>