7145d1c6 by 华明祺

手机登录

1 parent 023f830b
......@@ -28,9 +28,8 @@ function pcLogin(data) {
method: 'post',
params: data
}).then((res) => {
uni.setStorageSync('userName', data.username)
uni.setStorageSync('token', 'Bearer ' + res.data.token)
})
}).then(getInfo)
}
function h5Login(userName) {
......@@ -42,7 +41,7 @@ function h5Login(userName) {
}
}).then((res) => {
uni.setStorageSync('token', 'Bearer ' + res.data.token)
})
}).then(getInfo)
}
function h5LoginAuto() {
......@@ -205,6 +204,60 @@ function getCodeImg() {
})
}
// 代退图形认证的获取手机验证码
function getSmsCode(data) {
return request({
url: '/captchaSmsWithCaptchaImage',
method: 'post',
params: data
})
}
function loginByPhone(phonenumber, code) {
const data = {
phonenumber,
code
}
return request({
url: '/userLoginByPhone',
method: 'post',
params: data
}).then((res) => {
uni.setStorageSync('token', 'Bearer ' + res.data.token)
}).then(getInfo)
}
// 获取用户详细信息
function getInfo() {
return request({
url: '/getInfo',
method: 'get'
}).then(res => {
const user = res.data.user
uni.setStorageSync('userName', user.userName)
switch (user.dept.deptType) {
case '1':// 中跆协
uni.setStorageSync('userType', '1')
break
case '2':// 省
case '3':
uni.setStorageSync('userType', '2')
break
case '6':// 道馆
uni.setStorageSync('userType', '4')
break
default:// 市、区
uni.setStorageSync('userType', '3')
break
}
delete user.dept
uni.setStorageSync('user', JSON.stringify(user))
})
}
export {
getNowOpenId,
wxLogin,
......@@ -215,6 +268,8 @@ export {
checkUserAuth,
initData,
getCodeImg,
getSmsCode,
h5Login,
h5LoginAuto
h5LoginAuto,
loginByPhone
}
......
......@@ -38,36 +38,36 @@
</template>
<script setup>
import * as api from '@/common/api.js';
import * as loginServer from '@/common/login.js';
import {
import * as api from '@/common/api.js';
import * as loginServer from '@/common/login.js';
import {
getWxUser,
getWxUserPhone
} from '@/common/login.js';
import {
} from '@/common/login.js';
import {
onLoad,
onShow,
onReady,
onShareAppMessage,
onShareTimeline,
onPullDownRefresh
} from '@dcloudio/uni-app';
import {
} from '@dcloudio/uni-app';
import {
ref,
getCurrentInstance
} from 'vue';
} from 'vue';
const {
const {
proxy
} = getCurrentInstance()
const app = getApp();
} = getCurrentInstance()
const app = getApp();
let proId;
let goPath;
const svId = ref(null);
const list = ref([{
let proId;
let goPath;
const svId = ref(null);
const list = ref([{
url: '/static/c1.png',
text: '会员调动',
badge: '0',
......@@ -107,9 +107,9 @@
url: '/static/c8.png',
text: '段位证书发送'
}
]);
]);
onShow(() => {
onShow(() => {
if (app.globalData.isLogin) {
init();
} else {
......@@ -118,41 +118,43 @@
init();
};
}
})
onLoad(option => {
})
onLoad(option => {
if (option.scene) {
proId = decodeURIComponent(option.scene);
} else {
proId = option.proId;
}
});
});
function gologin(){
function gologin(){
let path = '/pages/index/login';
uni.navigateTo({
url: path
});
}
}
function goCenter() {
function goCenter() {
let path = '/pages/usercenter/usercenter';
if (checkUserPhone(path)) {
uni.navigateTo({
url: path
});
}
}
function init() {
}
}
function init() {
uni.showToast({
title:uni.getStorageSync('userType')
})
}
function goMsgList(){
function goMsgList(){
}
}
function goItem(item) {
function goItem(item) {
if (item.path) {
let path = item.path
// if (checkUserPhone(path)) {
......@@ -167,7 +169,7 @@
});
}
}
}
</script>
<style scope lang="scss">
.welcome{padding: 55rpx;
......
......@@ -31,17 +31,20 @@
<form v-if="isActive==1">
<view class="round-input-item">
<image class="icon" src="@/static/login/tag01@2x.png"></image>
<input placeholder="请输入手机号" />
<uni-easyinput placeholder="请输入手机号" v-model="form2.telNo" />
</view>
<view class="round-input-item">
<image class="icon" src="@/static/login/tag02@2x.png"></image>
<input placeholder="图形验证码" />
<image />
<uni-easyinput placeholder="图形验证码" v-model="form2.captcha" />
<image :src="codeUrl" @click="getCode" />
</view>
<view class="round-input-item">
<image class="icon" src="@/static/login/tag04@2x.png"></image>
<input placeholder="短信验证码" />
<text>获取验证码</text>
<uni-easyinput placeholder="短信验证码" v-model="form2.code" />
<text v-if="!countDown.start" @click="getCaptchaSms">获取验证码</text>
<uni-countdown v-if="countDown.start" color="#014A9F" :show-day="false" :show-hour="false"
:show-min="false" @timeup="timeup" :start="countDown.start"
:second="countDown.second"></uni-countdown>
</view>
</form>
......@@ -68,9 +71,9 @@
</view>
<image class="ren2" src="@/static/login/ren2.png" />
<view class="fixedagree">
<image @click="changeAgree(agree)" v-if="agree" src="@/static/login/xz_dwn@2x.png"></image>
<!-- <image @click="changeAgree(agree)" v-if="agree" src="@/static/login/xz_dwn@2x.png"></image>
<image v-else src="@/static/login/xz2@2x.png"></image>
<view>登录即代表您同意<text>《用户协议》</text><text>《隐私策略》</text></view>
<view>登录即代表您同意<text>《用户协议》</text><text>《隐私策略》</text></view> -->
</view>
</view>
</template>
......@@ -83,7 +86,9 @@ import {
import {
getCodeImg,
pcLogin
getSmsCode,
pcLogin,
loginByPhone
} from '@/common/login.js'
const isActive = ref(0)
......@@ -96,6 +101,16 @@ const form = ref({
code: null,
uuid: null
})
const form2 = ref({
telNo: null,
captcha: null,
code: null,
uuid: null
})
const countDown = ref({
start: false,
second: 60
})
const app = getApp()
......@@ -113,6 +128,29 @@ function changeAgree(item) {
}
function login() {
if (isActive.value == 0) {
if (!form.value.username) {
uni.showToast({
title: '账号不能为空',
icon: 'none'
})
return
}
if (!form.value.password) {
uni.showToast({
title: '密码不能为空',
icon: 'none'
})
return
}
if (!form.value.code) {
uni.showToast({
title: '验证码不能为空',
icon: 'none'
})
return
}
pcLogin(form.value)
.then(() => {
app.globalData.isLogin = true
......@@ -121,6 +159,30 @@ function login() {
})
})
.catch(getCode)
} else if (isActive.value == 1) {
if (!form2.value.telNo) {
uni.showToast({
title: '手机号不能为空',
icon: 'none'
})
return
}
if (!form2.value.code) {
uni.showToast({
title: '短信验证码不能为空',
icon: 'none'
})
return
}
loginByPhone(form2.value.telNo,form2.value.code)
.then(() => {
app.globalData.isLogin = true
uni.redirectTo({
url: '/pages/index/index'
})
})
}
}
function goRegister() {
......@@ -134,8 +196,46 @@ function getCode() {
getCodeImg().then((res) => {
codeUrl.value = 'data:image/gif;base64,' + res.data.img
form.value.uuid = res.data.uuid
form2.value.uuid = res.data.uuid
})
}
// 发送短信验证码
function getCaptchaSms() {
if (!form2.value.telNo) {
uni.showToast({
title: '手机号不能为空',
icon: 'none'
})
return
}
if (!form2.value.captcha) {
uni.showToast({
title: '图形验证码不能为空',
icon: 'none'
})
return
}
getSmsCode({
uuid: form2.value.uuid,
telNo: form2.value.telNo,
code: form2.value.captcha
}).then(res => {
uni.showToast({
title: '短信验证码下发成功',
icon: 'none'
})
countDown.value.start = true
}).catch(getCode)
}
function timeup() {
countDown.value.start = false
countDown.value.second = 60
getCode()
}
</script>
<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!