7145d1c6 by 华明祺

手机登录

1 parent 023f830b
...@@ -28,9 +28,8 @@ function pcLogin(data) { ...@@ -28,9 +28,8 @@ function pcLogin(data) {
28 method: 'post', 28 method: 'post',
29 params: data 29 params: data
30 }).then((res) => { 30 }).then((res) => {
31 uni.setStorageSync('userName', data.username)
32 uni.setStorageSync('token', 'Bearer ' + res.data.token) 31 uni.setStorageSync('token', 'Bearer ' + res.data.token)
33 }) 32 }).then(getInfo)
34 } 33 }
35 34
36 function h5Login(userName) { 35 function h5Login(userName) {
...@@ -42,7 +41,7 @@ function h5Login(userName) { ...@@ -42,7 +41,7 @@ function h5Login(userName) {
42 } 41 }
43 }).then((res) => { 42 }).then((res) => {
44 uni.setStorageSync('token', 'Bearer ' + res.data.token) 43 uni.setStorageSync('token', 'Bearer ' + res.data.token)
45 }) 44 }).then(getInfo)
46 } 45 }
47 46
48 function h5LoginAuto() { 47 function h5LoginAuto() {
...@@ -205,6 +204,60 @@ function getCodeImg() { ...@@ -205,6 +204,60 @@ function getCodeImg() {
205 }) 204 })
206 } 205 }
207 206
207 // 代退图形认证的获取手机验证码
208 function getSmsCode(data) {
209 return request({
210 url: '/captchaSmsWithCaptchaImage',
211 method: 'post',
212 params: data
213 })
214 }
215
216 function loginByPhone(phonenumber, code) {
217 const data = {
218 phonenumber,
219 code
220 }
221 return request({
222 url: '/userLoginByPhone',
223 method: 'post',
224 params: data
225 }).then((res) => {
226 uni.setStorageSync('token', 'Bearer ' + res.data.token)
227 }).then(getInfo)
228 }
229
230 // 获取用户详细信息
231 function getInfo() {
232 return request({
233 url: '/getInfo',
234 method: 'get'
235 }).then(res => {
236 const user = res.data.user
237 uni.setStorageSync('userName', user.userName)
238
239 switch (user.dept.deptType) {
240 case '1':// 中跆协
241 uni.setStorageSync('userType', '1')
242 break
243 case '2':// 省
244 case '3':
245 uni.setStorageSync('userType', '2')
246 break
247 case '6':// 道馆
248 uni.setStorageSync('userType', '4')
249 break
250 default:// 市、区
251 uni.setStorageSync('userType', '3')
252 break
253 }
254
255 delete user.dept
256 uni.setStorageSync('user', JSON.stringify(user))
257 })
258 }
259
260
208 export { 261 export {
209 getNowOpenId, 262 getNowOpenId,
210 wxLogin, 263 wxLogin,
...@@ -215,6 +268,8 @@ export { ...@@ -215,6 +268,8 @@ export {
215 checkUserAuth, 268 checkUserAuth,
216 initData, 269 initData,
217 getCodeImg, 270 getCodeImg,
271 getSmsCode,
218 h5Login, 272 h5Login,
219 h5LoginAuto 273 h5LoginAuto,
274 loginByPhone
220 } 275 }
......
...@@ -38,36 +38,36 @@ ...@@ -38,36 +38,36 @@
38 </template> 38 </template>
39 39
40 <script setup> 40 <script setup>
41 import * as api from '@/common/api.js'; 41 import * as api from '@/common/api.js';
42 import * as loginServer from '@/common/login.js'; 42 import * as loginServer from '@/common/login.js';
43 import { 43 import {
44 getWxUser, 44 getWxUser,
45 getWxUserPhone 45 getWxUserPhone
46 } from '@/common/login.js'; 46 } from '@/common/login.js';
47 import { 47 import {
48 onLoad, 48 onLoad,
49 onShow, 49 onShow,
50 onReady, 50 onReady,
51 onShareAppMessage, 51 onShareAppMessage,
52 onShareTimeline, 52 onShareTimeline,
53 onPullDownRefresh 53 onPullDownRefresh
54 } from '@dcloudio/uni-app'; 54 } from '@dcloudio/uni-app';
55 import { 55 import {
56 ref, 56 ref,
57 getCurrentInstance 57 getCurrentInstance
58 } from 'vue'; 58 } from 'vue';
59 59
60 60
61 const { 61 const {
62 proxy 62 proxy
63 } = getCurrentInstance() 63 } = getCurrentInstance()
64 const app = getApp(); 64 const app = getApp();
65 65
66 66
67 let proId; 67 let proId;
68 let goPath; 68 let goPath;
69 const svId = ref(null); 69 const svId = ref(null);
70 const list = ref([{ 70 const list = ref([{
71 url: '/static/c1.png', 71 url: '/static/c1.png',
72 text: '会员调动', 72 text: '会员调动',
73 badge: '0', 73 badge: '0',
...@@ -107,9 +107,9 @@ ...@@ -107,9 +107,9 @@
107 url: '/static/c8.png', 107 url: '/static/c8.png',
108 text: '段位证书发送' 108 text: '段位证书发送'
109 } 109 }
110 ]); 110 ]);
111 111
112 onShow(() => { 112 onShow(() => {
113 if (app.globalData.isLogin) { 113 if (app.globalData.isLogin) {
114 init(); 114 init();
115 } else { 115 } else {
...@@ -118,41 +118,43 @@ ...@@ -118,41 +118,43 @@
118 init(); 118 init();
119 }; 119 };
120 } 120 }
121 }) 121 })
122 onLoad(option => { 122 onLoad(option => {
123 if (option.scene) { 123 if (option.scene) {
124 proId = decodeURIComponent(option.scene); 124 proId = decodeURIComponent(option.scene);
125 } else { 125 } else {
126 proId = option.proId; 126 proId = option.proId;
127 } 127 }
128 128
129 }); 129 });
130 130
131 function gologin(){ 131 function gologin(){
132 let path = '/pages/index/login'; 132 let path = '/pages/index/login';
133 uni.navigateTo({ 133 uni.navigateTo({
134 url: path 134 url: path
135 }); 135 });
136 } 136 }
137 137
138 function goCenter() { 138 function goCenter() {
139 let path = '/pages/usercenter/usercenter'; 139 let path = '/pages/usercenter/usercenter';
140 if (checkUserPhone(path)) { 140 if (checkUserPhone(path)) {
141 uni.navigateTo({ 141 uni.navigateTo({
142 url: path 142 url: path
143 }); 143 });
144 } 144 }
145 } 145 }
146
147 function init() {
148 146
149 } 147 function init() {
148 uni.showToast({
149 title:uni.getStorageSync('userType')
150 })
151 }
150 152
151 function goMsgList(){ 153 function goMsgList(){
152 154
153 } 155 }
154 156
155 function goItem(item) { 157 function goItem(item) {
156 if (item.path) { 158 if (item.path) {
157 let path = item.path 159 let path = item.path
158 // if (checkUserPhone(path)) { 160 // if (checkUserPhone(path)) {
...@@ -167,7 +169,7 @@ ...@@ -167,7 +169,7 @@
167 }); 169 });
168 } 170 }
169 171
170 } 172 }
171 </script> 173 </script>
172 <style scope lang="scss"> 174 <style scope lang="scss">
173 .welcome{padding: 55rpx; 175 .welcome{padding: 55rpx;
......
...@@ -31,17 +31,20 @@ ...@@ -31,17 +31,20 @@
31 <form v-if="isActive==1"> 31 <form v-if="isActive==1">
32 <view class="round-input-item"> 32 <view class="round-input-item">
33 <image class="icon" src="@/static/login/tag01@2x.png"></image> 33 <image class="icon" src="@/static/login/tag01@2x.png"></image>
34 <input placeholder="请输入手机号" /> 34 <uni-easyinput placeholder="请输入手机号" v-model="form2.telNo" />
35 </view> 35 </view>
36 <view class="round-input-item"> 36 <view class="round-input-item">
37 <image class="icon" src="@/static/login/tag02@2x.png"></image> 37 <image class="icon" src="@/static/login/tag02@2x.png"></image>
38 <input placeholder="图形验证码" /> 38 <uni-easyinput placeholder="图形验证码" v-model="form2.captcha" />
39 <image /> 39 <image :src="codeUrl" @click="getCode" />
40 </view> 40 </view>
41 <view class="round-input-item"> 41 <view class="round-input-item">
42 <image class="icon" src="@/static/login/tag04@2x.png"></image> 42 <image class="icon" src="@/static/login/tag04@2x.png"></image>
43 <input placeholder="短信验证码" /> 43 <uni-easyinput placeholder="短信验证码" v-model="form2.code" />
44 <text>获取验证码</text> 44 <text v-if="!countDown.start" @click="getCaptchaSms">获取验证码</text>
45 <uni-countdown v-if="countDown.start" color="#014A9F" :show-day="false" :show-hour="false"
46 :show-min="false" @timeup="timeup" :start="countDown.start"
47 :second="countDown.second"></uni-countdown>
45 </view> 48 </view>
46 49
47 </form> 50 </form>
...@@ -68,9 +71,9 @@ ...@@ -68,9 +71,9 @@
68 </view> 71 </view>
69 <image class="ren2" src="@/static/login/ren2.png" /> 72 <image class="ren2" src="@/static/login/ren2.png" />
70 <view class="fixedagree"> 73 <view class="fixedagree">
71 <image @click="changeAgree(agree)" v-if="agree" src="@/static/login/xz_dwn@2x.png"></image> 74 <!-- <image @click="changeAgree(agree)" v-if="agree" src="@/static/login/xz_dwn@2x.png"></image>
72 <image v-else src="@/static/login/xz2@2x.png"></image> 75 <image v-else src="@/static/login/xz2@2x.png"></image>
73 <view>登录即代表您同意<text>《用户协议》</text><text>《隐私策略》</text></view> 76 <view>登录即代表您同意<text>《用户协议》</text><text>《隐私策略》</text></view> -->
74 </view> 77 </view>
75 </view> 78 </view>
76 </template> 79 </template>
...@@ -83,7 +86,9 @@ import { ...@@ -83,7 +86,9 @@ import {
83 86
84 import { 87 import {
85 getCodeImg, 88 getCodeImg,
86 pcLogin 89 getSmsCode,
90 pcLogin,
91 loginByPhone
87 } from '@/common/login.js' 92 } from '@/common/login.js'
88 93
89 const isActive = ref(0) 94 const isActive = ref(0)
...@@ -96,6 +101,16 @@ const form = ref({ ...@@ -96,6 +101,16 @@ const form = ref({
96 code: null, 101 code: null,
97 uuid: null 102 uuid: null
98 }) 103 })
104 const form2 = ref({
105 telNo: null,
106 captcha: null,
107 code: null,
108 uuid: null
109 })
110 const countDown = ref({
111 start: false,
112 second: 60
113 })
99 114
100 const app = getApp() 115 const app = getApp()
101 116
...@@ -113,6 +128,29 @@ function changeAgree(item) { ...@@ -113,6 +128,29 @@ function changeAgree(item) {
113 } 128 }
114 129
115 function login() { 130 function login() {
131 if (isActive.value == 0) {
132 if (!form.value.username) {
133 uni.showToast({
134 title: '账号不能为空',
135 icon: 'none'
136 })
137 return
138 }
139 if (!form.value.password) {
140 uni.showToast({
141 title: '密码不能为空',
142 icon: 'none'
143 })
144 return
145 }
146 if (!form.value.code) {
147 uni.showToast({
148 title: '验证码不能为空',
149 icon: 'none'
150 })
151 return
152 }
153
116 pcLogin(form.value) 154 pcLogin(form.value)
117 .then(() => { 155 .then(() => {
118 app.globalData.isLogin = true 156 app.globalData.isLogin = true
...@@ -121,6 +159,30 @@ function login() { ...@@ -121,6 +159,30 @@ function login() {
121 }) 159 })
122 }) 160 })
123 .catch(getCode) 161 .catch(getCode)
162 } else if (isActive.value == 1) {
163 if (!form2.value.telNo) {
164 uni.showToast({
165 title: '手机号不能为空',
166 icon: 'none'
167 })
168 return
169 }
170 if (!form2.value.code) {
171 uni.showToast({
172 title: '短信验证码不能为空',
173 icon: 'none'
174 })
175 return
176 }
177
178 loginByPhone(form2.value.telNo,form2.value.code)
179 .then(() => {
180 app.globalData.isLogin = true
181 uni.redirectTo({
182 url: '/pages/index/index'
183 })
184 })
185 }
124 } 186 }
125 187
126 function goRegister() { 188 function goRegister() {
...@@ -134,8 +196,46 @@ function getCode() { ...@@ -134,8 +196,46 @@ function getCode() {
134 getCodeImg().then((res) => { 196 getCodeImg().then((res) => {
135 codeUrl.value = 'data:image/gif;base64,' + res.data.img 197 codeUrl.value = 'data:image/gif;base64,' + res.data.img
136 form.value.uuid = res.data.uuid 198 form.value.uuid = res.data.uuid
199 form2.value.uuid = res.data.uuid
200 })
201 }
202
203 // 发送短信验证码
204 function getCaptchaSms() {
205 if (!form2.value.telNo) {
206 uni.showToast({
207 title: '手机号不能为空',
208 icon: 'none'
137 }) 209 })
210 return
211 }
212 if (!form2.value.captcha) {
213 uni.showToast({
214 title: '图形验证码不能为空',
215 icon: 'none'
216 })
217 return
218 }
219
220 getSmsCode({
221 uuid: form2.value.uuid,
222 telNo: form2.value.telNo,
223 code: form2.value.captcha
224 }).then(res => {
225 uni.showToast({
226 title: '短信验证码下发成功',
227 icon: 'none'
228 })
229 countDown.value.start = true
230 }).catch(getCode)
138 } 231 }
232
233 function timeup() {
234 countDown.value.start = false
235 countDown.value.second = 60
236 getCode()
237 }
238
139 </script> 239 </script>
140 240
141 <style scoped lang="scss"> 241 <style scoped lang="scss">
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!