|
|
@@ -1,2 +1,239 @@
|
|
1
|
|
-<script lang="ts" setup></script>
|
|
2
|
|
-<template></template>
|
|
|
1
|
+<template>
|
|
|
2
|
+ <div v-if="showPage == true">
|
|
|
3
|
+ <div class="page_title">手机号登录</div>
|
|
|
4
|
+ <div class="flex flex-col justify-center items-center py-25">
|
|
|
5
|
+ <image src="https://test.bjtdba.com/applet/static/home/404986b1e3aeaf4b3829efa2c2ac6bf.png" mode="widthFix"
|
|
|
6
|
+ class="w-35 h-35"></image>
|
|
|
7
|
+ </div>
|
|
|
8
|
+
|
|
|
9
|
+ <nut-input v-model="state.phone" placeholder="请输入手机号" type="number">
|
|
|
10
|
+ <template #right>
|
|
|
11
|
+ <nut-button type='primary' size="small" @click="handleGetCode" :loading="state.isAuthVerify">
|
|
|
12
|
+ {{ state.buttonText }}
|
|
|
13
|
+ </nut-button>
|
|
|
14
|
+ </template>
|
|
|
15
|
+ </nut-input>
|
|
|
16
|
+ <nut-input v-model="state.code" placeholder="请输入验证码" clearable type="number">
|
|
|
17
|
+ </nut-input>
|
|
|
18
|
+
|
|
|
19
|
+ <div class="flex w-full">
|
|
|
20
|
+ <div class="p-3 w-full">
|
|
|
21
|
+ <nut-button type="primary" @click="handleLogin" block :disabled="!isFormVerify">登录</nut-button>
|
|
|
22
|
+ <!-- <div class="text-xs text-gray flex flex-col justify-center items-center p-3">-->
|
|
|
23
|
+ <!-- <div>-->
|
|
|
24
|
+ <!-- 我已阅读并同意<span class="text-red text-xs" @click="handleViewXieyi(2)">《注册协议》</span>和<span-->
|
|
|
25
|
+ <!-- class="text-red text-xs" @click="handleViewXieyi(1)">《隐私协议》</span>-->
|
|
|
26
|
+ <!-- </div>-->
|
|
|
27
|
+ <!-- </div>-->
|
|
|
28
|
+
|
|
|
29
|
+ </div>
|
|
|
30
|
+
|
|
|
31
|
+ </div>
|
|
|
32
|
+
|
|
|
33
|
+ </div>
|
|
|
34
|
+</template>
|
|
|
35
|
+<script setup lang="ts">
|
|
|
36
|
+import CXBBasePage from "~/components/CXBBasePage/CXBBasePage.vue";
|
|
|
37
|
+import CXBBanner from "~/components/CXBBanner/CXBBanner.vue";
|
|
|
38
|
+import { authSmsLogin, authVerify } from "~/apis/auth.api";
|
|
|
39
|
+import Cache from "~/utils/cache";
|
|
|
40
|
+import { getUserUnionId } from "~/apis/user";
|
|
|
41
|
+const userStore = useUserStore()
|
|
|
42
|
+const pageStore = usePageStoreWidthOut()
|
|
|
43
|
+const state = reactive({
|
|
|
44
|
+ phone: '',
|
|
|
45
|
+ code: '',
|
|
|
46
|
+ spread: '',
|
|
|
47
|
+ isAuthVerify: false,
|
|
|
48
|
+ buttonText: '获取验证码',
|
|
|
49
|
+})
|
|
|
50
|
+const showPage = ref(false)
|
|
|
51
|
+onLoad((options: any) => {
|
|
|
52
|
+ uni.showLoading({
|
|
|
53
|
+ title: '加载中',
|
|
|
54
|
+ });
|
|
|
55
|
+ console.log(userStore.uid);
|
|
|
56
|
+ pageStore.setPageConfig({
|
|
|
57
|
+ currentPage: {
|
|
|
58
|
+ type: 'tab',
|
|
|
59
|
+ url: '/pages/home/index'
|
|
|
60
|
+ }
|
|
|
61
|
+ })
|
|
|
62
|
+ if (userStore.uid) {
|
|
|
63
|
+ uni.hideLoading()
|
|
|
64
|
+ return uni.switchTab({
|
|
|
65
|
+ url: '/pages/home/index'
|
|
|
66
|
+ })
|
|
|
67
|
+ }
|
|
|
68
|
+ showPage.value = true
|
|
|
69
|
+ console.log(options);
|
|
|
70
|
+ uni.setNavigationBarTitle({
|
|
|
71
|
+ title: '手机登录'
|
|
|
72
|
+ })
|
|
|
73
|
+ if (options.scene) {
|
|
|
74
|
+ let queryString = decodeURIComponent(options.scene)
|
|
|
75
|
+ console.log(queryString);
|
|
|
76
|
+
|
|
|
77
|
+ // 将字符串按 '&' 分割成数组
|
|
|
78
|
+ state.spread = queryString.split('=')[1];
|
|
|
79
|
+ console.log(state.spread);
|
|
|
80
|
+ }
|
|
|
81
|
+ uni.hideLoading()
|
|
|
82
|
+})
|
|
|
83
|
+function sendCode() {
|
|
|
84
|
+ if (state.isAuthVerify) return
|
|
|
85
|
+ // if (this.disabled) return;
|
|
|
86
|
+ // this.disabled = true;
|
|
|
87
|
+ state.isAuthVerify = true
|
|
|
88
|
+ let n = 60;
|
|
|
89
|
+ state.buttonText = "剩余 " + n + "s";
|
|
|
90
|
+ const run = setInterval(() => {
|
|
|
91
|
+ n = n - 1;
|
|
|
92
|
+ if (n < 0) {
|
|
|
93
|
+ clearInterval(run);
|
|
|
94
|
+ n = 0
|
|
|
95
|
+ }
|
|
|
96
|
+ state.buttonText = "剩余 " + n + "s";
|
|
|
97
|
+ if (state.buttonText === "剩余 " + 0 + "s") {
|
|
|
98
|
+ state.isAuthVerify = false;
|
|
|
99
|
+ state.buttonText = "重新获取";
|
|
|
100
|
+ }
|
|
|
101
|
+ }, 1000);
|
|
|
102
|
+}
|
|
|
103
|
+
|
|
|
104
|
+const isFormVerify = computed(() => {
|
|
|
105
|
+ if (state.phone !== '' && state.code !== '') {
|
|
|
106
|
+ return true
|
|
|
107
|
+ }
|
|
|
108
|
+})
|
|
|
109
|
+function handleGetCode() {
|
|
|
110
|
+ if (!state.phone) {
|
|
|
111
|
+ return uni.showToast({
|
|
|
112
|
+ title: '请填写手机号码',
|
|
|
113
|
+ icon: 'none'
|
|
|
114
|
+ })
|
|
|
115
|
+ }
|
|
|
116
|
+ if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(state.phone)) {
|
|
|
117
|
+ return uni.showToast({
|
|
|
118
|
+ title: '请输入正确的手机号码',
|
|
|
119
|
+ icon: 'none'
|
|
|
120
|
+ })
|
|
|
121
|
+ }
|
|
|
122
|
+
|
|
|
123
|
+ state.isAuthVerify = true
|
|
|
124
|
+ authVerify(state.phone).then(res => {
|
|
|
125
|
+ state.isAuthVerify = false
|
|
|
126
|
+ sendCode()
|
|
|
127
|
+ }).catch(res => {
|
|
|
128
|
+ })
|
|
|
129
|
+}
|
|
|
130
|
+function handleViewXieyi(type: number) {
|
|
|
131
|
+ uni.navigateTo({
|
|
|
132
|
+ url: `/pages/user/login/user-agreement?type=${type}`
|
|
|
133
|
+ })
|
|
|
134
|
+}
|
|
|
135
|
+
|
|
|
136
|
+function handleLogin() {
|
|
|
137
|
+ uni.showLoading({
|
|
|
138
|
+ title: '登录中'
|
|
|
139
|
+ });
|
|
|
140
|
+ const shareId = Cache.get('SHARE_ID')
|
|
|
141
|
+ // uni.login({
|
|
|
142
|
+ // provider: 'weixin',
|
|
|
143
|
+ // univerifyStyle: {
|
|
|
144
|
+ // fullScreen: true
|
|
|
145
|
+ // },
|
|
|
146
|
+ // success: result => {
|
|
|
147
|
+ // // console.log(result)
|
|
|
148
|
+ // getUserUnionId({
|
|
|
149
|
+ // code: result.code,
|
|
|
150
|
+ // source: 'cxb'
|
|
|
151
|
+ // }).then(unionRes => {
|
|
|
152
|
+ // console.log(111111, unionRes)
|
|
|
153
|
+ // // const shareId = Cache.get('SHARE_ID')
|
|
|
154
|
+ // //存储openid
|
|
|
155
|
+ // userStore.setOpenid(unionRes.openid)
|
|
|
156
|
+ // })
|
|
|
157
|
+ // }
|
|
|
158
|
+ // })
|
|
|
159
|
+ let params = {
|
|
|
160
|
+ phone: state.phone,
|
|
|
161
|
+ sms_code: state.code,
|
|
|
162
|
+ // share_id:
|
|
|
163
|
+ }
|
|
|
164
|
+ if (shareId && shareId !== '') {
|
|
|
165
|
+ params.share_id = shareId
|
|
|
166
|
+ }
|
|
|
167
|
+ if (state.spread && state.spread !== '' && state.spread != '0') {
|
|
|
168
|
+ params.spread = state.spread
|
|
|
169
|
+ }
|
|
|
170
|
+ authSmsLogin({
|
|
|
171
|
+ ...params
|
|
|
172
|
+ }).then(authRes => {
|
|
|
173
|
+ console.log(111111, authRes)
|
|
|
174
|
+ userStore.login(authRes.token, authRes.exp)
|
|
|
175
|
+ userStore.setUID(authRes.user.uid)
|
|
|
176
|
+ userStore.setUserInfo(authRes.user)
|
|
|
177
|
+ uni.hideLoading();
|
|
|
178
|
+ uni.showToast({
|
|
|
179
|
+ title: '登录成功',
|
|
|
180
|
+ icon: 'none'
|
|
|
181
|
+ })
|
|
|
182
|
+ Cache.clear('SHARE_ID')
|
|
|
183
|
+ state.isAuthVerify = false
|
|
|
184
|
+ let redirectPageObj: { page: string, type: 'page' | 'tab' }
|
|
|
185
|
+ if (Cache.get('SHARE_REDIRECT_PAGE')) {
|
|
|
186
|
+ redirectPageObj = JSON.parse(Cache.get('SHARE_REDIRECT_PAGE'))
|
|
|
187
|
+ }
|
|
|
188
|
+ setTimeout(() => {
|
|
|
189
|
+ if (redirectPageObj) {
|
|
|
190
|
+ if (redirectPageObj.type === 'page') {
|
|
|
191
|
+ return uni.redirectTo({
|
|
|
192
|
+ url: redirectPageObj.page
|
|
|
193
|
+ })
|
|
|
194
|
+ }
|
|
|
195
|
+ if (redirectPageObj.type === 'tab') {
|
|
|
196
|
+ return uni.switchTab({
|
|
|
197
|
+ url: redirectPageObj.page
|
|
|
198
|
+ })
|
|
|
199
|
+ }
|
|
|
200
|
+ } else {
|
|
|
201
|
+ uni.switchTab({
|
|
|
202
|
+ url: '/pages/home/index'
|
|
|
203
|
+ })
|
|
|
204
|
+ }
|
|
|
205
|
+ }, 200)
|
|
|
206
|
+
|
|
|
207
|
+
|
|
|
208
|
+ }).catch((errorMsg) => {
|
|
|
209
|
+ console.log(errorMsg)
|
|
|
210
|
+ uni.showToast({
|
|
|
211
|
+ title: errorMsg,
|
|
|
212
|
+ icon: 'none'
|
|
|
213
|
+ })
|
|
|
214
|
+ })
|
|
|
215
|
+}
|
|
|
216
|
+</script>
|
|
|
217
|
+
|
|
|
218
|
+<route lang="yaml">
|
|
|
219
|
+style:
|
|
|
220
|
+ navigationBarTitleText: 手机号登录
|
|
|
221
|
+ navigationStyle: custom
|
|
|
222
|
+ enablePullDownRefresh: false
|
|
|
223
|
+</route>
|
|
|
224
|
+
|
|
|
225
|
+<style>
|
|
|
226
|
+page {
|
|
|
227
|
+ background: #f8f8f8;
|
|
|
228
|
+}
|
|
|
229
|
+
|
|
|
230
|
+.page_title {
|
|
|
231
|
+ width: 180rpx;
|
|
|
232
|
+ height: 48rpx;
|
|
|
233
|
+ position: absolute;
|
|
|
234
|
+ margin-top: 110rpx;
|
|
|
235
|
+ left: 50%;
|
|
|
236
|
+ text-align: center;
|
|
|
237
|
+ margin-left: -90rpx;
|
|
|
238
|
+}
|
|
|
239
|
+</style>
|