代码优化

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,35 +32,30 @@
</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() {
return {
code: '', code: '',
mobile: '', mobile: '',
password: '', password: '',
sending: false, sending: false,
sendTime: '获取验证码', sendTime: '获取验证码',
count: 60, count: 60,
}; })
},
onLoad() {
},
methods: {
/** /**
* 发送验证码 * 发送验证码
*/ */
sendMsg() { function sendMsg() {
if (!this.mobile) { if (!data.mobile) {
uni.showToast({ uni.showToast({
title: '请输入手机号', title: '请输入手机号',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
} else if (this.mobile.length !== 11) { } else if (data.mobile.length !== 11) {
uni.showToast({ uni.showToast({
title: '请输入正确的手机号', title: '请输入正确的手机号',
icon: 'none', icon: 'none',
@@ -71,16 +66,16 @@
title: '正在发送验证码...' title: '正在发送验证码...'
}) })
http.request({ http.request({
url:'app/Login/sendMsg/' + this.mobile + '/forget', url:'app/Login/sendMsg/' + data.mobile + '/forget',
}).then(res => { }).then(res => {
if ( res.code == 0 ) { if ( res.code == 0 ) {
this.sending = true; data.sending = true;
uni.showToast({ uni.showToast({
title: '验证码发送成功请注意查收', title: '验证码发送成功请注意查收',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
this.countDown(); data.countDown();
} else { } else {
uni.showModal({ uni.showModal({
showCancel: false, showCancel: false,
@@ -93,81 +88,68 @@
}) })
} }
}, }
/** /**
* 验证码倒计时 * 验证码倒计时
*/ */
countDown() { function countDown() {
const { count } = this; if (data.count === 1) {
if (count === 1) { data.count = 60;
this.count = 60; data.sending = false;
this.sending = false; data.sendTime = '获取验证码';
this.sendTime = '获取验证码';
} else { } else {
this.count = count - 1; data.count = count - 1;
this.sending = true; data.sending = true;
this.sendTime = count - 1 + '秒后重新获取'; data.sendTime = count - 1 + '秒后重新获取';
setTimeout(this.countDown.bind(this), 1000); setTimeout(data.countDown.bind(data), 1000);
}
} }
},
/** /**
* 获取手机号/验证码/密码 * 获取手机号/验证码/密码
* @param {Object} e * @param {Object} e
*/ */
inputChange(e) { function inputChange(e) {
const key = e.currentTarget.dataset.key; const key = e.currentTarget.dataset.key;
this[key] = e.detail.value; data[key] = e.detail.value;
}, }
/** /**
* 注册 * 注册
*/ */
reset() { function reset() {
const {
mobile, if (!data.mobile) {
password,
code
} = this;
if (!mobile) {
// this.$queue.showToast("请输入手机号");
uni.showToast({ uni.showToast({
title: '请输入手机号', title: '请输入手机号',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
} else if (!code) { } else if (!data.code) {
// this.$queue.showToast("密码位数必须大于六位");
uni.showToast({ uni.showToast({
title: '请输入验证码', title: '请输入验证码',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
} else if (!password) { } else if (!data.password) {
// this.$queue.showToast("请设置密码");
uni.showToast({ uni.showToast({
title: '请输入密码', title: '请输入密码',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
} else { } else {
this.loginIng = true; data.loginIng = true;
// this.$queue.showLoading("正在修改密码中...");
uni.showLoading({ uni.showLoading({
title: '正在修改密码中...' title: '正在修改密码中...'
}) })
http.request({ http.request({
url: 'app/Login/forgetPwd?pwd=' + password + '&phone=' + mobile + '&msg=' + code, url: 'app/Login/forgetPwd?pwd=' + data.password + '&phone=' + data.mobile + '&msg=' + data.code,
method: 'post' method: 'post'
}).then( }).then(
res => { res => {
// this.$Request.postJson("/appLogin/forgetPwd",{
// pwd: password,
// phone: mobile,
// msg: code
// }).then(res => {
uni.hideLoading(); uni.hideLoading();
if (res.code === 0) { if (res.code === 0) {
uni.showToast({ uni.showToast({
@@ -192,9 +174,6 @@
} }
} }
}
};
</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,67 +45,58 @@
</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() {
if (uni.getStorageSync('isSafeView')) {
uni.showModal({
title: '提示',
content: '您正在使用无痕浏览,可能导致登录状态失效,建议切换浏览模式',
}) })
uni.setStorageSync("isSafeView", null)
} onLoad(() => {
},
methods: { })
/** /**
* 注册 * 注册
*/ */
register() { function register () {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/register' url: '/pages/login/register'
}); });
}, }
/** /**
* 忘记密码 * 忘记密码
*/ */
forget() { function forget () {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/forgetPwd' url: '/pages/login/forgetPwd'
}); });
}, }
/** /**
* 获取手机号/密码 * 获取手机号/密码
* @param {Object} e
*/ */
inputChange(e) { function inputChange (e) {
const key = e.currentTarget.dataset.key; const key = e.currentTarget.dataset.key;
this[key] = e.detail.value; data[key] = e.detail.value;
}, }
/** /**
* 同意协议 * 同意协议
* @param {Object} e
*/ */
radioChange(e) { function radioChange (e) {
this.checked = e data.checked = e
}, }
/** /**
* 登录 * 登录
*/ */
toLogin() { async function toLogin () {
if (!this.checked) { if (!data.checked) {
uni.showToast({ uni.showToast({
title: '请阅读并同意《隐私政策》和《用户服务协议》', title: '请阅读并同意《隐私政策》和《用户服务协议》',
icon: 'none', icon: 'none',
@@ -113,8 +104,7 @@
return; return;
} }
const { mobile, password } = this; const { mobile, password } = data;
console.log(this.mobile)
if (!mobile) { if (!mobile) {
uni.showToast({ uni.showToast({
title: '请输入手机号', title: '请输入手机号',
@@ -134,11 +124,11 @@
uni.showLoading({ uni.showLoading({
title: '正在登录中...', title: '正在登录中...',
}) })
http.request({ let res = await login({
url: 'app/Login/registerCode?password=' + password + '&phone=' + mobile, password: password,
method: 'post' phone: mobile
}).then(res => { })
console.log(res)
if (res.code === 0) { if (res.code === 0) {
uni.setStorageSync('token', res.token) uni.setStorageSync('token', res.token)
uni.setStorageSync('userId', res.user.userId) uni.setStorageSync('userId', res.user.userId)
@@ -166,14 +156,10 @@
icon: 'none' 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,11 +43,12 @@
</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: '',
@@ -59,34 +60,33 @@
registerCode: '', registerCode: '',
qdCodeion: '', //渠道码 qdCodeion: '', //渠道码
checked: false, checked: false,
}; })
},
onLoad( options ) { onLoad(( options ) => {
if (uni.getStorageSync('qdCodeion')) { this.qdCodeion = uni.getStorageSync('qdCodeion') } if (uni.getStorageSync('qdCodeion')) { data.qdCodeion = uni.getStorageSync('qdCodeion') }
if (options.qdCode) { this.qdCodeion = options.qdCode } if (options.qdCode) { data.qdCodeion = options.qdCode }
if (options.invitation ) { this.invitation = options.invitation } if (options.invitation ) { data.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) {
this.registerCode = res.data.value data.registerCode = res.data.value
} }
}); });
}, })
methods: {
/** /**
* 发送验证码 * 发送验证码
*/ */
sendMsg() { async function sendMsg () {
if (!this.mobile) { if (!data.mobile) {
uni.showToast({ uni.showToast({
title: '请输入手机号', title: '请输入手机号',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
} else if (this.mobile.length !== 11) { } else if (data.mobile.length !== 11) {
uni.showToast({ uni.showToast({
title: '请输入正确的手机号', title: '请输入正确的手机号',
icon: 'none', icon: 'none',
@@ -96,17 +96,16 @@
uni.showLoading({ uni.showLoading({
title: '正在发送验证码...' title: '正在发送验证码...'
}) })
http.request({ let res = await setSendMsg(data.mobile,'login')
url:'app/Login/sendMsg/' + this.mobile + '/login', console.log(res)
}).then(res => {
if ( res.code == 0 ) { if ( res.code == 0 ) {
this.sending = true; data.sending = true;
uni.showToast({ uni.showToast({
title: '验证码发送成功请注意查收', title: '验证码发送成功请注意查收',
icon: 'none', icon: 'none',
duration: 1000 duration: 1000
}) })
this.countDown(); data.countDown();
} else { } else {
uni.showModal({ uni.showModal({
showCancel: false, showCancel: false,
@@ -116,58 +115,59 @@
} }
uni.hideLoading(); uni.hideLoading();
})
} }
}, }
/** /**
* 验证码倒计时 * 验证码倒计时
*/ */
countDown() { function countDown() {
const { count } = this; if (data.count === 1) {
if (count === 1) { data.count = 60;
this.count = 60; data.sending = false;
this.sending = false; data.sendTime = '获取验证码';
this.sendTime = '获取验证码';
} else { } else {
this.count = count - 1; data.count = count - 1;
this.sending = true; data.sending = true;
this.sendTime = count - 1 + '秒后重新获取'; data.sendTime = count - 1 + '秒后重新获取';
setTimeout(this.countDown.bind(this), 1000); setTimeout(data.countDown.bind(data), 1000);
}
} }
},
/** /**
* 获取注册值 * 获取注册值
* @param {Object} e * @param {Object} e
*/ */
inputChange(e) { function inputChange(e) {
const key = e.currentTarget.dataset.key; const key = e.currentTarget.dataset.key;
this[key] = e.detail.value; data[key] = e.detail.value;
}, }
/** /**
* 是否同意协议 * 是否同意协议
* @param {Object} e * @param {Object} e
*/ */
radioChange(e) { function radioChange(e) {
this.checked = e data.checked = e
}, }
/** /**
* 登录 * 登录
*/ */
toLogin() { function toLogin() {
uni.reLaunch({ uni.reLaunch({
url: '/pages/login/login' url: '/pages/login/login'
}); });
}, }
/** /**
* 注册 * 注册
*/ */
toRegister() { async function toRegister() {
const { const {
mobile, mobile,
password, password,
@@ -225,7 +225,7 @@
}) })
return return
} }
this.logining = true; data.logining = true;
uni.showLoading({ uni.showLoading({
title: '注册中...' title: '注册中...'
}) })
@@ -236,12 +236,17 @@
// #ifdef H5 // #ifdef H5
platform = 'h5' platform = 'h5'
// #endif // #endif
http.request({
url: 'app/Login/registerCode?password=' + password + '&phone=' + mobile + '&msg=' + code +
'&inviterCode=' + invitation + '&platform=' + platform + '&qdCode=' + qdCodeion, let res = await registerCode({
method: 'post' password: password,
}).then(res => { phone: mobile,
console.log(res) msg: code,
inviterCode: invitation,
platform: platform,
qdCode: qdCodeion,
})
if (res.code === 0) { if (res.code === 0) {
uni.setStorageSync('token', res.token) uni.setStorageSync('token', res.token)
uni.setStorageSync('userId', res.user.userId) uni.setStorageSync('userId', res.user.userId)
@@ -269,12 +274,9 @@
}); });
} }
uni.hideLoading(); uni.hideLoading();
})
} }
}
};
</script> </script>
<style lang="scss" > <style lang="scss" >

View File

@@ -52,11 +52,11 @@
</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() {
return {
code: '', code: '',
mobile: '', mobile: '',
password: '', password: '',
@@ -66,11 +66,11 @@
relation: "", relation: "",
invitation: '', invitation: '',
registerCode: '', registerCode: '',
qdCodeion: '', qdCodeion: '', //渠道码
checked: false, checked: false,
}; })
},
onLoad(e) { onLoad(( options ) => {
let relation = e.invitation let relation = e.invitation
if (relation) { if (relation) {
this.relation = relation; this.relation = relation;
@@ -86,27 +86,26 @@
this.registerCode = res.data.value this.registerCode = res.data.value
} }
}); });
})
},
methods: {
/** /**
* 是否同意协议 * 是否同意协议
* @param {Object} e * @param {Object} e
*/ */
radioChange(e) { function radioChange(e) {
this.checked = e this.checked = e
}, }
showMa() { function showMa() {
//查询官方邀请码 //查询官方邀请码
this.$Request.getT('/common/type/88').then(res => { this.$Request.getT('/common/type/88').then(res => {
if (res.code == 0) { if (res.code == 0) {
this.invitation = res.data.value; this.invitation = res.data.value;
} }
}); });
}, }
sendMsg() {
function sendMsg() {
const { const {
mobile mobile
} = this; } = this;
@@ -149,8 +148,8 @@
}) })
} }
}, }
countDown() { function countDown() {
const { const {
count count
} = this; } = this;
@@ -164,27 +163,21 @@
this.sendTime = count - 1 + '秒后重新获取'; this.sendTime = count - 1 + '秒后重新获取';
setTimeout(this.countDown.bind(this), 1000); setTimeout(this.countDown.bind(this), 1000);
} }
}, }
inputChange(e) {
function inputChange(e) {
const key = e.currentTarget.dataset.key; const key = e.currentTarget.dataset.key;
this[key] = e.detail.value; this[key] = e.detail.value;
}, }
navBack() {
uni.navigateBack();
},
navTo(url) { function toLogin() {
uni.navigateTo({
url
});
},
toLogin() {
console.log("123"); console.log("123");
uni.reLaunch({ uni.reLaunch({
url: '/pages/login/login' url: '/pages/login/login'
}); });
}, }
toRegister() {
function toRegister() {
const { const {
mobile, mobile,
password, password,
@@ -286,10 +279,7 @@
}); });
} }
}); });
},
} }
};
</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,40 +22,39 @@
</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: '',
} }
} })
},
onLoad( options ) { onShow(() => {
this.getUserInfo() // console.log(1)
}, getUserInfo()
})
methods: {
/** /**
* 获取个人信息 * 获取个人信息
*/ */
getUserInfo() { async function getUserInfo () {
http.request({ let res = await selectUserById()
url:'app/user/selectUserById', if ( res.code == 0 ) {
}).then(res => { data.userInfo = res.data
this.userInfo = res.data }
}) }
},
/** /**
* 上头像 * 上头像
*/ */
uploadImg() { function uploadImg () {
let that = this;
var url = null; var url = null;
uni.showActionSheet({ uni.showActionSheet({
// itemList按钮的文字接受的是数组 // itemList按钮的文字接受的是数组
@@ -66,7 +65,7 @@
if (index === 0) { if (index === 0) {
// 用户点击了预览当前图片 // 用户点击了预览当前图片
// 可以自己实现当前头像链接的读取 // 可以自己实现当前头像链接的读取
let url = that.headImg; let url = data.userInfo.avatar;
let arr = [] let arr = []
arr.push(url) arr.push(url)
uni.previewImage({ uni.previewImage({
@@ -89,7 +88,7 @@
success: uploadFileRes => { success: uploadFileRes => {
url = JSON.parse(uploadFileRes.data); url = JSON.parse(uploadFileRes.data);
console.log(url) console.log(url)
this.userInfo.avatar = url.data data.userInfo.avatar = url.data
uni.hideLoading(); uni.hideLoading();
} }
@@ -99,27 +98,27 @@
} }
} }
}) })
}, }
/** /**
* 保存 * 保存
*/ */
save() { function save () {
if (!this.userInfo.userName) { if (!data.userInfo.userName) {
uni.showToast({ uni.showToast({
title: "用户名不能为空", title: "用户名不能为空",
icon: "none" icon: "none"
}) })
return return
} }
if (!this.userInfo.phone) { if (!data.userInfo.phone) {
uni.showToast({ uni.showToast({
title: "手机号不能空", title: "手机号不能空",
icon: "none" icon: "none"
}) })
return return
} }
if (this.checkPhone(this.userInfo.phone) == false) { if (checkPhone(data.userInfo.phone) == false) {
uni.showToast({ uni.showToast({
title: "手机号格式不正确", title: "手机号格式不正确",
icon: "none" icon: "none"
@@ -137,9 +136,9 @@
url:'app/user/updateUsers', url:'app/user/updateUsers',
method: 'post', method: 'post',
data: { data: {
userName: this.userInfo.userName, userName: data.userInfo.userName,
avatar: this.userInfo.avatar, avatar: data.userInfo.avatar,
phone: this.userInfo.phone, phone: data.userInfo.phone,
} }
}).then(res => { }).then(res => {
uni.showToast({ uni.showToast({
@@ -154,12 +153,10 @@
} }
} }
}); });
},
//根据正则验证手机号是否正确包括校验长度
checkPhone(phone) {
return /^1[3456789]\d{9}$/.test(phone);
},
} }
function checkPhone(phone) {
return /^1[3456789]\d{9}$/.test(phone);
} }
</script> </script>