代码优化

This commit is contained in:
GaoHao
2025-01-07 09:54:54 +08:00
parent 4ccddee396
commit 5b19340974
10 changed files with 882 additions and 885 deletions

View File

@@ -15,7 +15,7 @@
onShow: function() { onShow: function() {
// ios是否在审核 // ios是否在审核
http.request({ http.request({
url: 'app/common/type/919', url: 'common/type/919',
}).then(res => { }).then(res => {
if (res.code == 0) { if (res.code == 0) {
uni.setStorageSync('isExamine', res.data.value) uni.setStorageSync('isExamine', res.data.value)

32
api/login/login.js Normal file
View File

@@ -0,0 +1,32 @@
import http from '@/http/http.js'
/**
* 登录
*/
export const login = (data) => {
return http.request({
url: '/Login/registerCode',
method: 'POST',
data: data
})
}
/**
* 发送验证码
*/
export const setSendMsg = (mobile,type) => {
return http.request({
url: '/Login/sendMsg/' + mobile + '/'+type
})
}
/**
* 注册
*/
export const registerCode = (params) => {
return http.request({
url: '/Login/registerCode',
params: params
})
}

11
api/user/user.js Normal file
View File

@@ -0,0 +1,11 @@
import http from '@/http/http.js'
/**
* 获取用户信息
*/
export const selectUserById = (data) => {
return http.request({
url: '/user/selectUserById',
data: data
})
}

View File

@@ -4,7 +4,7 @@ const env='test' //test , production,local
export const encryptKey='1234567890123456' // http数据加解密的key export const encryptKey='1234567890123456' // http数据加解密的key
export const apiUrl='/czg/' export const apiUrl='/czg/app'
export const h5Config = { export const h5Config = {
production: 'https://dj-h5.hnsiyao.cn', production: 'https://dj-h5.hnsiyao.cn',
test: 'https://web-api.hnsiyao.cn', test: 'https://web-api.hnsiyao.cn',

View File

@@ -13,8 +13,8 @@ const loadingShowTime = 200
function getHeader() { function getHeader() {
const headerObject = {} const headerObject = {}
headerObject["token"] = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNjkyNSIsImlhdCI6MTczNTg4OTk5NCwiZXhwIjoxNzM2NDk0Nzk0fQ.j-KFEE1FHckmFCO8UA884RBWvpMv8MfEGj7GPGf3kVo6sHeORl043Yle_w7HdTZKPpQqSr2LQLCq_rUxG4qqwA' // headerObject["token"] = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNjkyNSIsImlhdCI6MTczNTg4OTk5NCwiZXhwIjoxNzM2NDk0Nzk0fQ.j-KFEE1FHckmFCO8UA884RBWvpMv8MfEGj7GPGf3kVo6sHeORl043Yle_w7HdTZKPpQqSr2LQLCq_rUxG4qqwA'
// headerObject["token"] = uni.getStorageSync('token') headerObject["token"] = uni.getStorageSync('token')
return headerObject return headerObject
} }

View File

@@ -8,21 +8,21 @@
<view style="font-size: 58rpx;font-weight: bold;color: #333;margin-bottom: 48rpx;">重置密码</view> <view style="font-size: 58rpx;font-weight: bold;color: #333;margin-bottom: 48rpx;">重置密码</view>
<view class="cu-form-group"> <view class="cu-form-group">
<view class="title">手机号</view> <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" /> @input="inputChange" />
</view> </view>
<view class="cu-form-group"> <view class="cu-form-group">
<text class="title">验证码</text> <text class="title">验证码</text>
<view class="input flex"> <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="reset" /> @input="inputChange" @confirm="reset" />
<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> </view>
<view class="cu-form-group"> <view class="cu-form-group">
<text class="title">设置密码</text> <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="reset" /> maxlength="20" minlength="6" data-key="password" @input="inputChange" @confirm="reset" />
</view> </view>
<button class="confirm-btn" @click="reset">立即重置</button> <button class="confirm-btn" @click="reset">立即重置</button>
@@ -32,169 +32,148 @@
</view> </view>
</template> </template>
<script> <script setup>
import { reactive } from 'vue';
import { onLoad} from '@dcloudio/uni-app'
import http from '@/http/http.js'; import http from '@/http/http.js';
export default { let data = reactive({
data() { code: '',
return { mobile: '',
code: '', password: '',
mobile: '', sending: false,
password: '', sendTime: '获取验证码',
sending: false, count: 60,
sendTime: '获取验证码', })
count: 60,
}; /**
}, * 发送验证码
onLoad() { */
function sendMsg() {
}, if (!data.mobile) {
methods: { uni.showToast({
title: '请输入手机号',
/** icon: 'none',
* 发送验证码 duration: 1000
*/ })
sendMsg() { } else if (data.mobile.length !== 11) {
if (!this.mobile) { uni.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1000
})
} else {
uni.showLoading({
title: '正在发送验证码...'
})
http.request({
url:'app/Login/sendMsg/' + data.mobile + '/forget',
}).then(res => {
if ( res.code == 0 ) {
data.sending = true;
uni.showToast({ uni.showToast({
title: '请输入手机号', title: '验证码发送成功请注意查收',
icon: 'none',
duration: 1000
})
} else if (this.mobile.length !== 11) {
uni.showToast({
title: '请输入正确的手机号',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
data.countDown();
} else { } else {
uni.showLoading({ uni.showModal({
title: '正在发送验证码...' showCancel: false,
}) title: '短信发送失败',
http.request({ content: res.msg ? res.msg : '请一分钟后再获取验证码'
url:'app/Login/sendMsg/' + this.mobile + '/forget', });
}).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;
},
/**
* 注册
*/
reset() {
const {
mobile,
password,
code
} = this;
if (!mobile) {
// this.$queue.showToast("请输入手机号");
uni.showToast({
title: '请输入手机号',
icon: 'none',
duration: 1000
})
} else if (!code) {
// this.$queue.showToast("密码位数必须大于六位");
uni.showToast({
title: '请输入验证码',
icon: 'none',
duration: 1000
})
} else if (!password) {
// this.$queue.showToast("请设置密码");
uni.showToast({
title: '请输入密码',
icon: 'none',
duration: 1000
})
} else {
this.loginIng = true;
// this.$queue.showLoading("正在修改密码中...");
uni.showLoading({
title: '正在修改密码中...'
})
http.request({
url: 'app/Login/forgetPwd?pwd=' + password + '&phone=' + mobile + '&msg=' + code,
method: 'post'
}).then(
res => {
// this.$Request.postJson("/appLogin/forgetPwd",{
// pwd: password,
// phone: mobile,
// msg: code
// }).then(res => {
uni.hideLoading();
if (res.code === 0) {
uni.showToast({
title: '密码找回成功',
icon: 'none'
});
setTimeout(function() {
uni.navigateTo({
url: '/pages/login/login'
});
}, 1000)
} else {
uni.showModal({
showCancel: false,
title: '密码找回失败',
content: res.msg,
});
}
});
} }
} 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;
}
/**
* 注册
*/
function reset() {
if (!data.mobile) {
uni.showToast({
title: '请输入手机号',
icon: 'none',
duration: 1000
})
} else if (!data.code) {
uni.showToast({
title: '请输入验证码',
icon: 'none',
duration: 1000
})
} else if (!data.password) {
uni.showToast({
title: '请输入密码',
icon: 'none',
duration: 1000
})
} else {
data.loginIng = true;
uni.showLoading({
title: '正在修改密码中...'
})
http.request({
url: 'app/Login/forgetPwd?pwd=' + data.password + '&phone=' + data.mobile + '&msg=' + data.code,
method: 'post'
}).then(
res => {
uni.hideLoading();
if (res.code === 0) {
uni.showToast({
title: '密码找回成功',
icon: 'none'
});
setTimeout(function() {
uni.navigateTo({
url: '/pages/login/login'
});
}, 1000)
} else {
uni.showModal({
showCancel: false,
title: '密码找回失败',
content: res.msg,
});
}
});
}
}
</script> </script>
<style lang="scss" > <style lang="scss" >

View File

@@ -9,14 +9,14 @@
<view class="cu-form-group"> <view class="cu-form-group">
<view class="title">手机号</view> <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" /> @input="inputChange" />
</view> </view>
<view class="cu-form-group"> <view class="cu-form-group">
<text class="title">密码</text> <text class="title">密码</text>
<view class="input flex"> <view class="input flex" style="padding-left: 0;">
<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="toLogin" /> maxlength="20" minlength="6" data-key="password" @input="inputChange" @confirm="toLogin" />
<text class="send-msg" @click="forget" style="flex-shrink: 0;">忘记密码</text> <text class="send-msg" @click="forget" style="flex-shrink: 0;">忘记密码</text>
</view> </view>
@@ -31,7 +31,7 @@
</view> </view>
<view class="footerView"> <view class="footerView">
<u-checkbox-group> <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> </u-checkbox-group>
<view>同意</view> <view>同意</view>
<!-- 协议地址 --> <!-- 协议地址 -->
@@ -45,135 +45,121 @@
</view> </view>
</template> </template>
<script> <script setup>
import http from '@/http/http.js'; import { reactive } from 'vue';
export default { import { onLoad} from '@dcloudio/uni-app'
data() { import { login } from '@/api/login/login.js';
return { let data = reactive({
mobile: '', mobile: '',
password: '', password: '',
checked: false checked: false
}; })
},
onLoad() { onLoad(() => {
if (uni.getStorageSync('isSafeView')) {
uni.showModal({ })
title: '提示',
content: '您正在使用无痕浏览,可能导致登录状态失效,建议切换浏览模式', /**
}) * 注册
uni.setStorageSync("isSafeView", null) */
} function register () {
}, uni.navigateTo({
methods: { url: '/pages/login/register'
});
/** }
* 注册
*/ /**
register() { * 忘记密码
uni.navigateTo({ */
url: '/pages/login/register' function forget () {
}); uni.navigateTo({
}, url: '/pages/login/forgetPwd'
});
/** }
* 忘记密码
*/ /**
forget() { * 获取手机号/密码
uni.navigateTo({ */
url: '/pages/login/forgetPwd' function inputChange (e) {
}); const key = e.currentTarget.dataset.key;
}, data[key] = e.detail.value;
}
/**
* 获取手机号/密码 /**
* @param {Object} e * 同意协议
*/ */
inputChange(e) { function radioChange (e) {
const key = e.currentTarget.dataset.key; data.checked = e
this[key] = e.detail.value; }
},
/**
/** * 登录
* 同意协议 */
* @param {Object} e async function toLogin () {
*/ if (!data.checked) {
radioChange(e) { uni.showToast({
this.checked = e title: '请阅读并同意《隐私政策》和《用户服务协议》',
}, icon: 'none',
})
/** return;
* 登录
*/
toLogin() {
if (!this.checked) {
uni.showToast({
title: '请阅读并同意《隐私政策》和《用户服务协议》',
icon: 'none',
})
return;
}
const { mobile, password } = this;
console.log(this.mobile)
if (!mobile) {
uni.showToast({
title: '请输入手机号',
icon: 'none',
})
} else if (mobile.length != 11) {
uni.showToast({
title: '请输入正确的手机号',
icon: 'none',
})
} else if (!password) {
uni.showToast({
title: '请输入密码',
icon: 'none',
})
} else {
uni.showLoading({
title: '正在登录中...',
})
http.request({
url: 'app/Login/registerCode?password=' + password + '&phone=' + mobile,
method: 'post'
}).then(res => {
console.log(res)
if (res.code === 0) {
uni.setStorageSync('token', res.token)
uni.setStorageSync('userId', res.user.userId)
uni.setStorageSync('userName', res.user.userName)
uni.setStorageSync('avatar', res.user.avatar ? res.user.avatar : '../../static/default/avatar.png')
uni.setStorageSync('phone', res.user.phone)
uni.setStorageSync('invitationCode', res.user.invitationCode)
uni.setStorageSync('sex', res.user.sex)
uni.setStorageSync('userId', res.user.userId)
//设置渠道码
if (res.user.qdCode) {
uni.setStorageSync('qdCode', res.user.qdCode)
}
uni.showToast({
title: '登录成功',
icon: 'none'
})
uni.reLaunch({
url:'/pages/index/index'
})
} else{
uni.hideLoading();
uni.showToast({
title: res.msg,
icon: 'none'
})
}
})
}
},
} }
};
const { mobile, password } = data;
if (!mobile) {
uni.showToast({
title: '请输入手机号',
icon: 'none',
})
} else if (mobile.length != 11) {
uni.showToast({
title: '请输入正确的手机号',
icon: 'none',
})
} else if (!password) {
uni.showToast({
title: '请输入密码',
icon: 'none',
})
} else {
uni.showLoading({
title: '正在登录中...',
})
let res = await login({
password: password,
phone: mobile
})
if (res.code === 0) {
uni.setStorageSync('token', res.token)
uni.setStorageSync('userId', res.user.userId)
uni.setStorageSync('userName', res.user.userName)
uni.setStorageSync('avatar', res.user.avatar ? res.user.avatar : '../../static/default/avatar.png')
uni.setStorageSync('phone', res.user.phone)
uni.setStorageSync('invitationCode', res.user.invitationCode)
uni.setStorageSync('sex', res.user.sex)
uni.setStorageSync('userId', res.user.userId)
//设置渠道码
if (res.user.qdCode) {
uni.setStorageSync('qdCode', res.user.qdCode)
}
uni.showToast({
title: '登录成功',
icon: 'none'
})
uni.reLaunch({
url:'/pages/index/index'
})
} else{
uni.hideLoading();
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -9,21 +9,21 @@
<view class="cu-form-group"> <view class="cu-form-group">
<view class="title">手机号</view> <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" /> @input="inputChange" />
</view> </view>
<view class="cu-form-group"> <view class="cu-form-group">
<text class="title">验证码</text> <text class="title">验证码</text>
<view class="input flex"> <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" /> @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> </view>
<view class="cu-form-group"> <view class="cu-form-group">
<text class="title">设置密码</text> <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" /> maxlength="20" minlength="6" data-key="password" @input="inputChange" @confirm="toRegister" />
</view> </view>
<button class="confirm-btn" @click="toRegister">注册</button> <button class="confirm-btn" @click="toRegister">注册</button>
@@ -31,7 +31,7 @@
</view> </view>
<view class="footerView"> <view class="footerView">
<u-checkbox-group> <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> </u-checkbox-group>
<view>注册即同意</view> <view>注册即同意</view>
<!-- 协议地址 --> <!-- 协议地址 -->
@@ -43,238 +43,240 @@
</view> </view>
</template> </template>
<script> <script setup>
import { reactive } from 'vue';
import { onLoad} from '@dcloudio/uni-app'
import http from '@/http/http.js'; import http from '@/http/http.js';
export default { import {setSendMsg} from '@/api/login/login.js';
data() { let data = reactive({
return { code: '',
code: '', mobile: '',
mobile: '', password: '',
password: '', sending: false,
sending: false, sendTime: '获取验证码',
sendTime: '获取验证码', count: 60,
count: 60, relation: "",
relation: "", invitation: '',
invitation: '', registerCode: '',
registerCode: '', qdCodeion: '', //渠道码
qdCodeion: '', //渠道码 checked: false,
checked: false, })
};
}, onLoad(( options ) => {
onLoad( options ) { if (uni.getStorageSync('qdCodeion')) { data.qdCodeion = uni.getStorageSync('qdCodeion') }
if (uni.getStorageSync('qdCodeion')) { this.qdCodeion = uni.getStorageSync('qdCodeion') } if (options.qdCode) { data.qdCodeion = options.qdCode }
if (options.qdCode) { this.qdCodeion = options.qdCode } if (options.invitation ) { data.invitation = options.invitation }
if (options.invitation ) { this.invitation = options.invitation }
http.request({
http.request({ url:'app/common/type/3',
url:'app/common/type/3', }).then(res => {
}).then(res => { if (res.code == 0) {
if (res.code == 0) { data.registerCode = res.data.value
this.registerCode = res.data.value }
} });
}); })
},
methods: { /**
* 发送验证码
/** */
* 发送验证码 async function sendMsg () {
*/ if (!data.mobile) {
sendMsg() { uni.showToast({
if (!this.mobile) { title: '请输入手机号',
uni.showToast({ icon: 'none',
title: '请输入手机号', duration: 1000
icon: 'none', })
duration: 1000 } else if (data.mobile.length !== 11) {
}) uni.showToast({
} else if (this.mobile.length !== 11) { title: '请输入正确的手机号',
uni.showToast({ icon: 'none',
title: '请输入正确的手机号', duration: 1000
icon: 'none', })
duration: 1000 } else {
}) uni.showLoading({
} else { title: '正在发送验证码...'
uni.showLoading({ })
title: '正在发送验证码...' let res = await setSendMsg(data.mobile,'login')
}) console.log(res)
http.request({ if ( res.code == 0 ) {
url:'app/Login/sendMsg/' + this.mobile + '/login', data.sending = true;
}).then(res => { uni.showToast({
if ( res.code == 0 ) { title: '验证码发送成功请注意查收',
this.sending = true; icon: 'none',
uni.showToast({ duration: 1000
title: '验证码发送成功请注意查收', })
icon: 'none', data.countDown();
duration: 1000 } else {
}) uni.showModal({
this.countDown(); showCancel: false,
} else { title: '短信发送失败',
uni.showModal({ content: res.msg ? res.msg : '请一分钟后再获取验证码'
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'
}); });
},
/**
* 注册
*/
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> </script>
<style lang="scss" > <style lang="scss" >

View File

@@ -52,244 +52,234 @@
</view> </view>
</template> </template>
<script> <script setup>
import { reactive } from 'vue';
import { onLoad} from '@dcloudio/uni-app'
import http from '@/http/http.js'; import http from '@/http/http.js';
export default { let data = reactive({
data() { code: '',
return { mobile: '',
code: '', password: '',
mobile: '', sending: false,
password: '', sendTime: '获取验证码',
sending: false, count: 60,
sendTime: '获取验证码', relation: "",
count: 60, invitation: '',
relation: "", registerCode: '',
invitation: '', qdCodeion: '', //渠道码
registerCode: '', checked: false,
qdCodeion: '', })
checked: false,
}; onLoad(( options ) => {
}, let relation = e.invitation
onLoad(e) { if (relation) {
let relation = e.invitation this.relation = relation;
if (relation) { this.invitation = relation;
this.relation = relation; }
this.invitation = relation; if (e.qdCode) {
this.qdCodeion = e.qdCode
}
http.request({
url:'app/common/type/3',
}).then(res => {
if (res.code == 0) {
this.registerCode = res.data.value
} }
if (e.qdCode) { });
this.qdCodeion = e.qdCode })
/**
* 是否同意协议
* @param {Object} e
*/
function radioChange(e) {
this.checked = e
}
function showMa() {
//查询官方邀请码
this.$Request.getT('/common/type/88').then(res => {
if (res.code == 0) {
this.invitation = res.data.value;
} }
});
}
function sendMsg() {
const {
mobile
} = this;
if (!mobile) {
uni.showToast({
title: '请输入手机号',
icon: 'none',
duration: 1000
})
} else if (mobile.length !== 11) {
uni.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1000
})
} else {
uni.showLoading({
title: '正在发送验证码...'
})
http.request({ http.request({
url:'app/common/type/3', url:'app/Login/sendMsg/' + mobile + '/login',
}).then(res => { }).then(res => {
if (res.code == 0) { if (res.code === 0) {
this.registerCode = res.data.value
}
});
},
methods: {
/**
* 是否同意协议
* @param {Object} e
*/
radioChange(e) {
this.checked = e
},
showMa() {
//查询官方邀请码
this.$Request.getT('/common/type/88').then(res => {
if (res.code == 0) {
this.invitation = res.data.value;
}
});
},
sendMsg() {
const {
mobile
} = this;
if (!mobile) {
uni.showToast({
title: '请输入手机号',
icon: 'none',
duration: 1000
})
} else if (mobile.length !== 11) {
uni.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1000
})
} else {
uni.showLoading({
title: '正在发送验证码...'
})
http.request({
url:'app/Login/sendMsg/' + 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.sending = true;
this.sendTime = count - 1 + '秒后重新获取';
setTimeout(this.countDown.bind(this), 1000);
}
},
inputChange(e) {
const key = e.currentTarget.dataset.key;
this[key] = e.detail.value;
},
navBack() {
uni.navigateBack();
},
navTo(url) {
uni.navigateTo({
url
});
},
toLogin() {
console.log("123");
uni.reLaunch({
url: '/pages/login/login'
});
},
toRegister() {
const {
mobile,
password,
code,
checked,
invitation,
registerCode,
qdCodeion
} = this;
if (!mobile) {
uni.showToast({ uni.showToast({
title: '请输入账号', title: '验证码发送成功请注意查收',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
return this.countDown();
} else {
uni.showModal({
showCancel: false,
title: '短信发送失败',
content: res.msg ? res.msg : '请一分钟后再获取验证码'
});
} }
if (!code) {
uni.showToast({ uni.hideLoading();
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 => {
if (res.code === 0) {
// this.$queue.remove('invitation');
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.qdCode) {
uni.setStorageSync('qdCode', res.user.qdCode)
}
uni.showToast({
title: '注册成功',
icon: 'none'
})
setTimeout(function() {
uni.navigateTo({
url: '/pages/login/appEq'
})
}, 1000)
} else {
uni.hideLoading();
uni.showModal({
showCancel: false,
title: '注册失败',
content: res.msg
});
}
});
},
} }
}; }
function 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);
}
}
function inputChange(e) {
const key = e.currentTarget.dataset.key;
this[key] = e.detail.value;
}
function toLogin() {
console.log("123");
uni.reLaunch({
url: '/pages/login/login'
});
}
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
}
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 => {
if (res.code === 0) {
// this.$queue.remove('invitation');
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.qdCode) {
uni.setStorageSync('qdCode', res.user.qdCode)
}
uni.showToast({
title: '注册成功',
icon: 'none'
})
setTimeout(function() {
uni.navigateTo({
url: '/pages/login/appEq'
})
}, 1000)
} else {
uni.hideLoading();
uni.showModal({
showCancel: false,
title: '注册失败',
content: res.msg
});
}
});
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -3,18 +3,18 @@
<up-cell-group> <up-cell-group>
<up-cell title="头像"> <up-cell title="头像">
<template #value> <template #value>
<image :src="userInfo.avatar?userInfo.avatar:'../../static/default/avatar.png'" mode="" @click="uploadImg" <image :src="data.userInfo.avatar?data.userInfo.avatar:'../../static/default/avatar.png'" mode="" @click="uploadImg"
style="width: 111rpx;height: 111rpx;border-radius: 50%;"></image> style="width: 111rpx;height: 111rpx;border-radius: 50%;"></image>
</template> </template>
</up-cell> </up-cell>
<up-cell title="用户名"> <up-cell title="用户名">
<template #value> <template #value>
<input v-model="userInfo.userName" align="right" placeholder="请输入用户名" /> <input v-model="data.userInfo.userName" align="right" placeholder="请输入用户名" />
</template> </template>
</up-cell> </up-cell>
<up-cell title="手机"> <up-cell title="手机">
<template #value> <template #value>
<input :disabled="userInfo.phone?true:false" v-model="userInfo.phone" align="right" placeholder="请输入联系电话" /> <input :disabled="data.userInfo.phone?true:false" v-model="data.userInfo.phone" align="right" placeholder="请输入联系电话" />
</template> </template>
</up-cell> </up-cell>
</up-cell-group> </up-cell-group>
@@ -22,144 +22,141 @@
</view> </view>
</template> </template>
<script> <script setup>
import { reactive } from 'vue';
import { onShow} from '@dcloudio/uni-app'
import config from '@/commons/config.js'; import config from '@/commons/config.js';
import http from '@/http/http.js'; import {selectUserById} from '@/api/user/user.js';
export default {
data() { let data = reactive({
return{ userInfo: {
userInfo: { avatar: '',
avatar: '', userName: '',
userName: '', phone: '',
phone: '', }
} })
}
}, onShow(() => {
onLoad( options ) { // console.log(1)
this.getUserInfo() getUserInfo()
}, })
methods: { /**
/** * 获取个人信息
* 获取个人信息 */
*/ async function getUserInfo () {
getUserInfo() { let res = await selectUserById()
http.request({ if ( res.code == 0 ) {
url:'app/user/selectUserById', data.userInfo = res.data
}).then(res => { }
this.userInfo = res.data }
})
}, /**
* 上传头像
/** */
* 上次头像 function uploadImg () {
*/ var url = null;
uploadImg() { uni.showActionSheet({
let that = this; // itemList按钮的文字接受的是数组
var url = null; itemList: ["查看头像", "从相册选择图片"],
uni.showActionSheet({ success(e) {
// itemList按钮的文字接受的是数组 var index = e.tapIndex
itemList: ["查看头像", "从相册选择图片"], console.log(index)
success(e) { if (index === 0) {
var index = e.tapIndex // 用户点击了预览当前图片
console.log(index) // 可以自己实现当前头像链接的读取
if (index === 0) { let url = data.userInfo.avatar;
// 用户点击了预览当前图片 let arr = []
// 可以自己实现当前头像链接的读取 arr.push(url)
let url = that.headImg; uni.previewImage({
let arr = [] // 预览功能图片也必须是数组的
arr.push(url) urls: arr
uni.previewImage({ })
// 预览功能图片也必须是数组的 } else if (index === 1) {
urls: arr uni.chooseImage({
}) count: 1, //默认9
} else if (index === 1) { sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
uni.chooseImage({ sourceType: ['album'], //从相册选择
count: 1, //默认9 success: function(res) {
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 uni.showLoading({
sourceType: ['album'], //从相册选择 title: '上传中...'
success: function(res) { });
uni.showLoading({ uni.uploadFile({
title: '上传中...' url: config.baseApiUrl + 'alioss/upload',
}); filePath: res.tempFilePaths[0],
uni.uploadFile({ name: 'file',
url: config.baseApiUrl + 'alioss/upload', success: uploadFileRes => {
filePath: res.tempFilePaths[0], url = JSON.parse(uploadFileRes.data);
name: 'file', console.log(url)
success: uploadFileRes => { data.userInfo.avatar = url.data
url = JSON.parse(uploadFileRes.data); uni.hideLoading();
console.log(url)
this.userInfo.avatar = url.data
uni.hideLoading();
}
});
} }
}); });
} }
} });
})
},
/**
* 保存
*/
save() {
if (!this.userInfo.userName) {
uni.showToast({
title: "用户名不能为空",
icon: "none"
})
return
} }
if (!this.userInfo.phone) { }
uni.showToast({ })
title: "手机号不能空", }
icon: "none"
}) /**
return * 保存
} */
if (this.checkPhone(this.userInfo.phone) == false) { function save () {
uni.showToast({ if (!data.userInfo.userName) {
title: "手机号格式不正确", uni.showToast({
icon: "none" title: "用户名不能为空",
}) icon: "none"
return })
} return
uni.showModal({
title: '温馨提示',
content: '确定保存信息',
confirmColor: '#ff7581',
success: e => {
if (e.confirm) {
http.request({
url:'app/user/updateUsers',
method: 'post',
data: {
userName: this.userInfo.userName,
avatar: this.userInfo.avatar,
phone: this.userInfo.phone,
}
}).then(res => {
uni.showToast({
title: '保存成功',
icon: "none"
})
setTimeout(function() {
uni.navigateBack()
}, 1000)
})
}
}
});
},
//根据正则验证手机号是否正确包括校验长度
checkPhone(phone) {
return /^1[3456789]\d{9}$/.test(phone);
},
} }
if (!data.userInfo.phone) {
uni.showToast({
title: "手机号不能空",
icon: "none"
})
return
}
if (checkPhone(data.userInfo.phone) == false) {
uni.showToast({
title: "手机号格式不正确",
icon: "none"
})
return
}
uni.showModal({
title: '温馨提示',
content: '确定保存信息',
confirmColor: '#ff7581',
success: e => {
if (e.confirm) {
http.request({
url:'app/user/updateUsers',
method: 'post',
data: {
userName: data.userInfo.userName,
avatar: data.userInfo.avatar,
phone: data.userInfo.phone,
}
}).then(res => {
uni.showToast({
title: '保存成功',
icon: "none"
})
setTimeout(function() {
uni.navigateBack()
}, 1000)
})
}
}
});
}
function checkPhone(phone) {
return /^1[3456789]\d{9}$/.test(phone);
} }
</script> </script>