代码优化
This commit is contained in:
@@ -9,21 +9,21 @@
|
||||
|
||||
<view class="cu-form-group">
|
||||
<view class="title">手机号</view>
|
||||
<input class="input" type="number" :value="mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile"
|
||||
<input class="input" type="number" :value="data.mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile"
|
||||
@input="inputChange" />
|
||||
</view>
|
||||
<view class="cu-form-group">
|
||||
<text class="title">验证码</text>
|
||||
<view class="input flex">
|
||||
<input type="number" :value="code" placeholder="请输入验证码" maxlength="6" data-key="code"
|
||||
<input type="number" :value="data.code" placeholder="请输入验证码" maxlength="6" data-key="code"
|
||||
@input="inputChange" @confirm="toRegister" />
|
||||
<button class="send-msg" @click="sendMsg" :disabled="sending">{{ sendTime }}</button>
|
||||
<button class="send-msg" @click="sendMsg" :disabled="data.sending">{{ data.sendTime }}</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="cu-form-group">
|
||||
<text class="title">设置密码</text>
|
||||
<input class="input" type="password" :value="password" placeholder="请设置新密码" placeholder-class="input-empty"
|
||||
<input class="input" type="password" :value="data.password" placeholder="请设置新密码" placeholder-class="input-empty"
|
||||
maxlength="20" minlength="6" data-key="password" @input="inputChange" @confirm="toRegister" />
|
||||
</view>
|
||||
<button class="confirm-btn" @click="toRegister">注册</button>
|
||||
@@ -31,7 +31,7 @@
|
||||
</view>
|
||||
<view class="footerView">
|
||||
<u-checkbox-group>
|
||||
<u-checkbox v-model="checked" label-size='24upx' shape="circle" @change="radioChange"></u-checkbox>
|
||||
<u-checkbox v-model="data.checked" label-size='24upx' shape="circle" @change="radioChange"></u-checkbox>
|
||||
</u-checkbox-group>
|
||||
<view>注册即同意</view>
|
||||
<!-- 协议地址 -->
|
||||
@@ -43,238 +43,240 @@
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup>
|
||||
import { reactive } from 'vue';
|
||||
import { onLoad} from '@dcloudio/uni-app'
|
||||
import http from '@/http/http.js';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
code: '',
|
||||
mobile: '',
|
||||
password: '',
|
||||
sending: false,
|
||||
sendTime: '获取验证码',
|
||||
count: 60,
|
||||
relation: "",
|
||||
invitation: '',
|
||||
registerCode: '',
|
||||
qdCodeion: '', //渠道码
|
||||
checked: false,
|
||||
};
|
||||
},
|
||||
onLoad( options ) {
|
||||
if (uni.getStorageSync('qdCodeion')) { this.qdCodeion = uni.getStorageSync('qdCodeion') }
|
||||
if (options.qdCode) { this.qdCodeion = options.qdCode }
|
||||
if (options.invitation ) { this.invitation = options.invitation }
|
||||
|
||||
http.request({
|
||||
url:'app/common/type/3',
|
||||
}).then(res => {
|
||||
if (res.code == 0) {
|
||||
this.registerCode = res.data.value
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*/
|
||||
sendMsg() {
|
||||
if (!this.mobile) {
|
||||
uni.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else if (this.mobile.length !== 11) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else {
|
||||
uni.showLoading({
|
||||
title: '正在发送验证码...'
|
||||
})
|
||||
http.request({
|
||||
url:'app/Login/sendMsg/' + this.mobile + '/login',
|
||||
}).then(res => {
|
||||
if ( res.code == 0 ) {
|
||||
this.sending = true;
|
||||
uni.showToast({
|
||||
title: '验证码发送成功请注意查收',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
this.countDown();
|
||||
} else {
|
||||
uni.showModal({
|
||||
showCancel: false,
|
||||
title: '短信发送失败',
|
||||
content: res.msg ? res.msg : '请一分钟后再获取验证码'
|
||||
});
|
||||
}
|
||||
|
||||
uni.hideLoading();
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 验证码倒计时
|
||||
*/
|
||||
countDown() {
|
||||
const { count } = this;
|
||||
if (count === 1) {
|
||||
this.count = 60;
|
||||
this.sending = false;
|
||||
this.sendTime = '获取验证码';
|
||||
} else {
|
||||
this.count = count - 1;
|
||||
this.sending = true;
|
||||
this.sendTime = count - 1 + '秒后重新获取';
|
||||
setTimeout(this.countDown.bind(this), 1000);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取注册值
|
||||
* @param {Object} e
|
||||
*/
|
||||
inputChange(e) {
|
||||
const key = e.currentTarget.dataset.key;
|
||||
this[key] = e.detail.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* 是否同意协议
|
||||
* @param {Object} e
|
||||
*/
|
||||
radioChange(e) {
|
||||
this.checked = e
|
||||
},
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
toLogin() {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
import {setSendMsg} from '@/api/login/login.js';
|
||||
let data = reactive({
|
||||
code: '',
|
||||
mobile: '',
|
||||
password: '',
|
||||
sending: false,
|
||||
sendTime: '获取验证码',
|
||||
count: 60,
|
||||
relation: "",
|
||||
invitation: '',
|
||||
registerCode: '',
|
||||
qdCodeion: '', //渠道码
|
||||
checked: false,
|
||||
})
|
||||
|
||||
onLoad(( options ) => {
|
||||
if (uni.getStorageSync('qdCodeion')) { data.qdCodeion = uni.getStorageSync('qdCodeion') }
|
||||
if (options.qdCode) { data.qdCodeion = options.qdCode }
|
||||
if (options.invitation ) { data.invitation = options.invitation }
|
||||
|
||||
http.request({
|
||||
url:'app/common/type/3',
|
||||
}).then(res => {
|
||||
if (res.code == 0) {
|
||||
data.registerCode = res.data.value
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*/
|
||||
async function sendMsg () {
|
||||
if (!data.mobile) {
|
||||
uni.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else if (data.mobile.length !== 11) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的手机号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
} else {
|
||||
uni.showLoading({
|
||||
title: '正在发送验证码...'
|
||||
})
|
||||
let res = await setSendMsg(data.mobile,'login')
|
||||
console.log(res)
|
||||
if ( res.code == 0 ) {
|
||||
data.sending = true;
|
||||
uni.showToast({
|
||||
title: '验证码发送成功请注意查收',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
data.countDown();
|
||||
} else {
|
||||
uni.showModal({
|
||||
showCancel: false,
|
||||
title: '短信发送失败',
|
||||
content: res.msg ? res.msg : '请一分钟后再获取验证码'
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
toRegister() {
|
||||
const {
|
||||
mobile,
|
||||
password,
|
||||
code,
|
||||
checked,
|
||||
invitation,
|
||||
registerCode,
|
||||
qdCodeion
|
||||
} = this;
|
||||
if (!mobile) {
|
||||
uni.showToast({
|
||||
title: '请输入账号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!code) {
|
||||
uni.showToast({
|
||||
title: '请输入验证码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!password) {
|
||||
uni.showToast({
|
||||
title: '请设置密码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (password.length < 6) {
|
||||
uni.showToast({
|
||||
title: '密码位数必须大于六位',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (invitation.length == 0 && registerCode == '是') {
|
||||
uni.showToast({
|
||||
title: '请输入邀请码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!checked) {
|
||||
uni.showToast({
|
||||
title: '请先同意《隐私政策》和《用户协议》',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
this.logining = true;
|
||||
uni.showLoading({
|
||||
title: '注册中...'
|
||||
})
|
||||
let platform = ''
|
||||
// #ifdef APP
|
||||
platform = 'app'
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
platform = 'h5'
|
||||
// #endif
|
||||
http.request({
|
||||
url: 'app/Login/registerCode?password=' + password + '&phone=' + mobile + '&msg=' + code +
|
||||
'&inviterCode=' + invitation + '&platform=' + platform + '&qdCode=' + qdCodeion,
|
||||
method: 'post'
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
if (res.code === 0) {
|
||||
uni.setStorageSync('token', res.token)
|
||||
uni.setStorageSync('userId', res.user.userId)
|
||||
uni.setStorageSync('phone', res.user.phone)
|
||||
uni.setStorageSync('invitationCode', res.user.invitationCode)
|
||||
//设置渠道码
|
||||
if (res.user.qdCod) {
|
||||
uni.setStorageSync('qdCod', res.user.qdCod)
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '注册成功',
|
||||
icon: 'none'
|
||||
})
|
||||
setTimeout(function() {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
});
|
||||
}, 1000)
|
||||
} else {
|
||||
uni.showModal({
|
||||
showCancel: false,
|
||||
title: '注册失败',
|
||||
content: res.msg
|
||||
});
|
||||
}
|
||||
uni.hideLoading();
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
uni.hideLoading();
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证码倒计时
|
||||
*/
|
||||
function countDown() {
|
||||
if (data.count === 1) {
|
||||
data.count = 60;
|
||||
data.sending = false;
|
||||
data.sendTime = '获取验证码';
|
||||
} else {
|
||||
data.count = count - 1;
|
||||
data.sending = true;
|
||||
data.sendTime = count - 1 + '秒后重新获取';
|
||||
setTimeout(data.countDown.bind(data), 1000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取注册值
|
||||
* @param {Object} e
|
||||
*/
|
||||
function inputChange(e) {
|
||||
const key = e.currentTarget.dataset.key;
|
||||
data[key] = e.detail.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否同意协议
|
||||
* @param {Object} e
|
||||
*/
|
||||
function radioChange(e) {
|
||||
data.checked = e
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
function toLogin() {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
async function toRegister() {
|
||||
const {
|
||||
mobile,
|
||||
password,
|
||||
code,
|
||||
checked,
|
||||
invitation,
|
||||
registerCode,
|
||||
qdCodeion
|
||||
} = this;
|
||||
if (!mobile) {
|
||||
uni.showToast({
|
||||
title: '请输入账号',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!code) {
|
||||
uni.showToast({
|
||||
title: '请输入验证码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!password) {
|
||||
uni.showToast({
|
||||
title: '请设置密码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (password.length < 6) {
|
||||
uni.showToast({
|
||||
title: '密码位数必须大于六位',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (invitation.length == 0 && registerCode == '是') {
|
||||
uni.showToast({
|
||||
title: '请输入邀请码',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!checked) {
|
||||
uni.showToast({
|
||||
title: '请先同意《隐私政策》和《用户协议》',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
data.logining = true;
|
||||
uni.showLoading({
|
||||
title: '注册中...'
|
||||
})
|
||||
let platform = ''
|
||||
// #ifdef APP
|
||||
platform = 'app'
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
platform = 'h5'
|
||||
// #endif
|
||||
|
||||
|
||||
let res = await registerCode({
|
||||
password: password,
|
||||
phone: mobile,
|
||||
msg: code,
|
||||
inviterCode: invitation,
|
||||
platform: platform,
|
||||
qdCode: qdCodeion,
|
||||
})
|
||||
|
||||
if (res.code === 0) {
|
||||
uni.setStorageSync('token', res.token)
|
||||
uni.setStorageSync('userId', res.user.userId)
|
||||
uni.setStorageSync('phone', res.user.phone)
|
||||
uni.setStorageSync('invitationCode', res.user.invitationCode)
|
||||
//设置渠道码
|
||||
if (res.user.qdCod) {
|
||||
uni.setStorageSync('qdCod', res.user.qdCod)
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '注册成功',
|
||||
icon: 'none'
|
||||
})
|
||||
setTimeout(function() {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
});
|
||||
}, 1000)
|
||||
} else {
|
||||
uni.showModal({
|
||||
showCancel: false,
|
||||
title: '注册失败',
|
||||
content: res.msg
|
||||
});
|
||||
}
|
||||
uni.hideLoading();
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" >
|
||||
|
||||
Reference in New Issue
Block a user