This commit is contained in:
2025-01-07 11:03:02 +08:00
13 changed files with 1188 additions and 1047 deletions

View File

@@ -11,3 +11,12 @@ export async function init() {
} }
}) })
} }
/**
*
*/
export const commonType = (num) => {
return http.request({
url: `/common/type/${num}`,
})
}

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

@@ -0,0 +1,43 @@
import http from '@/http/http.js'
/**
* 登录
*/
export const login = (data) => {
return http.request({
url: '/Login/registerCode',
method: 'POST',
params: 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
})
}
/**
* 修改密码
*/
export const forgetPwd = (data) => {
return http.request({
url: '/Login/forgetPwd',
method: 'POST',
params: data
})
}

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

@@ -141,28 +141,36 @@ function req(uri, data, method = "GET", showLoading = true, extParams = {}) {
// 默认 显示loading(控制 xxs 内 不提示loading ) // 默认 显示loading(控制 xxs 内 不提示loading )
function request(args) { function request(args) {
const { let {
url, url,
data, data,
params, params,
method = "GET", method = "GET",
showLoading = true, showLoading = true,
extParams = {}, extParams = {}
} = args; } = args
let headerObject = {}; if (params) {
return commonsProcess(showLoading, () => { let result = ''
return uni.request( Object.keys(params).forEach((key) => {
Object.assign( if (!Object.is(params[key], undefined) && !Object.is(params[key], null) && !Object.is(JSON.stringify(params[key]), '{}')) {
{ result += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]) + "&"
url: slash(baseUrl, url), }
data: params || data, })
method: method, url = url+'?'+result
header: getHeader(), params = null
}, }
extParams let headerObject = {}
) return commonsProcess(showLoading, () => {
); return uni.request(
}); Object.assign({
url: slash(baseUrl, url),
data: params || data,
method: method,
header: getHeader()
}, extParams)
)
})
} }
// 处理/ // 处理/
function slash(baseUrl, url) { function slash(baseUrl, url) {

View File

@@ -79,6 +79,16 @@
"style": { "style": {
"navigationBarTitleText": "个人资料" "navigationBarTitleText": "个人资料"
} }
}, {
"path": "pages/me/privacy",
"style": {
"navigationBarTitleText": "隐私协议"
}
}, {
"path": "pages/me/agreement",
"style": {
"navigationBarTitleText": "服务协议"
}
}, },
{ {
"path": "pages/index/search/index", "path": "pages/index/search/index",

View File

@@ -19,137 +19,134 @@
</template> </template>
<script> <script>
import listCell from '@/components/com-input'; import { reactive } from 'vue';
export default { import { onLoad} from '@dcloudio/uni-app'
components: { import {setSendMsg,forgetPwd} from '@/api/login/login.js';
listCell let data = reactive({
}, mobile: '',
data() { code: '',
return { loginIng: false,
mobile: '', sendIng: false,
code: '', sendTime: '获取验证码',
loginIng: false, count: 60,
sendIng: false, type: '',
sendTime: '获取验证码', })
count: 60,
type: '',
}
},
onLoad(option) {
if (option.type) {
this.type = option.type
}
},
methods: {
inputChange(e) {
const key = e.currentTarget.dataset.key;
this[key] = e.detail.value;
},
countDown() { onLoad((option) => {
const { if (option.type) {
count data.type = option.type
} = this; }
if (count === 1) { })
this.count = 60;
this.sendIng = false; function inputChange(e) {
this.sendTime = '获取验证码' const key = e.currentTarget.dataset.key;
data[key] = e.detail.value;
}
function countDown() {
const {
count
} = data;
if (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);
}
}
function sendMsg() {
const {
mobile
} = data;
if (!mobile) {
data.$queue.showToast("请输入手机号");
} else if (mobile.length !== 11) {
data.$queue.showToast("请输入正确的手机号");
} else {
data.$queue.showLoading("正在发送验证码...");
http.request({
url: 'app/Login/sendMsg/' + mobile + '/gzg',
}).then(res => {
if (res.code === 0) {
data.sendIng = true;
uni.showToast({ title: '验证码发送成功请注意查收', icon: 'none', })
data.countDown();
} else { } else {
this.count = count - 1; uni.showModal({
this.sendIng = true; showCancel: false,
this.sendTime = count - 1 + '秒后重新获取'; title: '短信发送失败',
setTimeout(this.countDown.bind(this), 1000); content: res.msg ? res.msg : '请一分钟后再获取验证码'
}
},
sendMsg() {
const {
mobile
} = this;
if (!mobile) {
this.$queue.showToast("请输入手机号");
} else if (mobile.length !== 11) {
this.$queue.showToast("请输入正确的手机号");
} else {
this.$queue.showLoading("正在发送验证码...");
http.request({
url: 'app/Login/sendMsg/' + mobile + '/gzg',
}).then(res => {
if (res.code === 0) {
this.sendIng = true;
this.$queue.showToast('验证码发送成功请注意查收');
this.countDown();
} else {
uni.showModal({
showCancel: false,
title: '短信发送失败',
content: res.msg ? res.msg : '请一分钟后再获取验证码'
});
}
uni.hideLoading();
})
}
},
toLogin() {
const {
mobile,
code
} = this;
let userId = this.$queue.getData("userId");
if (!mobile) {
this.$queue.showToast("请输入手机号");
} else if (mobile.length !== 11) {
this.$queue.showToast("请输入正确的手机号");
} else if (!code) {
this.$queue.showToast("请输入验证码");
} else {
this.$queue.showLoading("正在绑定中...");
let openId = this.$queue.getData('openId') ? this.$queue.getData('openId') : '';
let openidnickname = this.$queue.getData('openidnickname') ? this.$queue.getData('openidnickname') :
'';
let openidheadimgurl = this.$queue.getData('openidheadimgurl') ? this.$queue.getData(
'openidheadimgurl') : '';
let invitation = this.$queue.getData('inviterCode') ? this.$queue.getData('inviterCode') : '';
let userId = this.$queue.getData('userId') ? this.$queue.getData('userId') : '';
http.request({
url: `app/Login/registerCode`,
method: 'post',
data: {
phone: mobile,
wxId: openId,
userId: userId,
inviterCode: invitation,
avatar: openidheadimgurl,
userName: openidnickname,
msg: code
}
}).then(res => {
if (res.code === 0) {
this.$queue.setData("token", res.token);
this.$queue.setData('userId', res.user.userId);
this.$queue.setData('userName', res.user.userName);
this.$queue.setData('phone', res.user.phone);
this.$queue.setData('avatar', res.user.avatar ? res.user.avatar :
'../../static/logo.png');
this.$queue.showToast('绑定成功');
setTimeout(function() {
uni.navigateBack()
}, 1000)
} else {
uni.showModal({
showCancel: false,
title: '绑定失败',
content: res.msg,
});
}
uni.hideLoading();
}); });
} }
},
},
uni.hideLoading();
})
}
}
function toLogin() {
const {
mobile,
code
} = data;
let userId = this.$queue.getData("userId");
if (!mobile) {
uni.showToast({ title: '请输入手机号', icon: 'none', })
} else if (mobile.length !== 11) {
uni.showToast({ title: '请输入正确的手机号', icon: 'none', })
} else if (!code) {
uni.showToast({ title: '请输入验证码', icon: 'none', })
} else {
uni.showLoading({ title: '正在绑定中...' })
let openId = this.$queue.getData('openId') ? this.$queue.getData('openId') : '';
let openidnickname = this.$queue.getData('openidnickname') ? this.$queue.getData('openidnickname') :
'';
let openidheadimgurl = this.$queue.getData('openidheadimgurl') ? this.$queue.getData(
'openidheadimgurl') : '';
let invitation = this.$queue.getData('inviterCode') ? this.$queue.getData('inviterCode') : '';
let userId = this.$queue.getData('userId') ? this.$queue.getData('userId') : '';
http.request({
url: `app/Login/registerCode`,
method: 'post',
data: {
phone: mobile,
wxId: openId,
userId: userId,
inviterCode: invitation,
avatar: openidheadimgurl,
userName: openidnickname,
msg: code
}
}).then(res => {
if (res.code === 0) {
this.$queue.setData("token", res.token);
this.$queue.setData('userId', res.user.userId);
this.$queue.setData('userName', res.user.userName);
this.$queue.setData('phone', res.user.phone);
this.$queue.setData('avatar', res.user.avatar ? res.user.avatar :
'../../static/logo.png');
this.$queue.showToast('绑定成功');
uni.showToast({ title: '绑定成功', icon: 'none', })
setTimeout(function() {
uni.navigateBack()
}, 1000)
} else {
uni.showModal({
showCancel: false,
title: '绑定失败',
content: res.msg,
});
}
uni.hideLoading();
});
}
} }
</script> </script>

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,132 @@
</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 {setSendMsg,forgetPwd} from '@/api/login/login.js';
return { let data = reactive({
code: '', code: '',
mobile: '', mobile: '',
password: '', password: '',
sending: false, sending: false,
sendTime: '获取验证码', sendTime: '获取验证码',
count: 60, count: 60,
}; })
},
onLoad() {
},
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 + '/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,
});
}
});
}
/**
* 发送验证码
*/
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,'forget')
uni.hideLoading();
uni.hideToast();
if( res ){
data.sending = true;
uni.showToast({
title: '验证码发送成功请注意查收',
icon: 'none',
})
data.countDown();
} else {
uni.showModal({
showCancel: false,
title: '短信发送失败',
content: '请一分钟后再获取验证码'
});
} }
} }
}; }
/**
* 验证码倒计时
*/
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;
}
/**
* 注册
*/
async 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: '正在修改密码中...'
})
let res = await forgetPwd({
pwd: data.password,
phone: data.mobile,
msg: data.code,
})
uni.hideLoading();
uni.showToast({
title: '密码找回成功',
icon: 'none'
});
setTimeout(function() {
uni.navigateTo({
url: '/pages/login/login'
});
}, 1000)
}
}
</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,13 +31,13 @@
</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>
<!-- 协议地址 --> <!-- 协议地址 -->
<navigator url="/me/setting/mimi" open-type="navigate">隐私政策</navigator> <navigator url="/pages/me/privacy" open-type="navigate">隐私政策</navigator>
<navigator url="/me/setting/xieyi" open-type="navigate">用户服务协议</navigator> <navigator url="/pages/me/agreement" open-type="navigate">用户服务协议</navigator>
</view> </view>
<u-toast ref="uToast" /> <u-toast ref="uToast" />
@@ -45,135 +45,115 @@
</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({
url: '/pages/login/register'
});
}
/**
* 忘记密码
*/
function forget () {
uni.navigateTo({
url: '/pages/login/forgetPwd'
});
}
/**
* 获取手机号/密码
*/
function inputChange (e) {
const key = e.currentTarget.dataset.key;
data[key] = e.detail.value;
}
/**
* 同意协议
*/
function radioChange (e) {
data.checked = e
}
/**
* 登录
*/
async function toLogin () {
if (!data.checked) {
uni.showToast({
title: '请阅读并同意《隐私政策》和《用户服务协议》',
icon: 'none',
})
return;
}
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
})
console.log(res)
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.hideLoading();
methods: { uni.showToast({
title: '登录成功',
/** icon: 'none'
* 注册 })
*/ uni.reLaunch({
register() { url:'/pages/index/index'
uni.navigateTo({ })
url: '/pages/login/register'
});
},
/**
* 忘记密码
*/
forget() {
uni.navigateTo({
url: '/pages/login/forgetPwd'
});
},
/**
* 获取手机号/密码
* @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() {
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'
})
}
})
}
},
} }
}; }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -207,10 +187,7 @@
font-weight: 400; font-weight: 400;
font-size: 24rpx; font-size: 24rpx;
color: #333333; color: #333333;
position: absolute; margin-top: 50rpx;
left: 0;
right: 0;
bottom: 78rpx;
} }

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,250 +31,249 @@
</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>
<!-- 协议地址 --> <!-- 协议地址 -->
<navigator url="/me/setting/mimi" open-type="navigate" style="color: #37A6FF;">隐私政策</navigator> <navigator url="/pages/me/privacy" open-type="navigate" style="color: #37A6FF;">隐私政策</navigator>
<navigator url="/me/setting/xieyi" open-type="navigate" style="color: #37A6FF;">用户协议</navigator> <navigator url="/pages/me/agreement" open-type="navigate" style="color: #37A6FF;">用户协议</navigator>
</view> </view>
</view> </view>
</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 {setSendMsg,registerCode} from '@/api/login/login.js';
return { import {commonType} from '@/api/init.js';
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: {
/** let data = reactive({
* 发送验证码 code: '',
*/ mobile: '',
sendMsg() { password: '',
if (!this.mobile) { sending: false,
uni.showToast({ sendTime: '获取验证码',
title: '请输入手机号', count: 60,
icon: 'none', relation: "",
duration: 1000 invitation: '',
}) registerCode: '',
} else if (this.mobile.length !== 11) { qdCodeion: '', //渠道码
uni.showToast({ checked: false,
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(); onLoad(async ( options ) => {
}) if (uni.getStorageSync('qdCodeion')) { data.qdCodeion = uni.getStorageSync('qdCodeion') }
if (options.qdCode) { data.qdCodeion = options.qdCode }
if (options.invitation ) { data.invitation = options.invitation }
} let res = await commonType(3)
}, data.registerCode = res.value
})
/** /**
* 验证码倒计时 * 发送验证码
*/ */
countDown() { async function sendMsg () {
const { count } = this; if (!data.mobile) {
if (count === 1) { uni.showToast({
this.count = 60; title: '请输入手机号',
this.sending = false; icon: 'none',
this.sendTime = '获取验证码'; duration: 1000
} else { })
this.count = count - 1; } else if (data.mobile.length !== 11) {
this.sending = true; uni.showToast({
this.sendTime = count - 1 + '秒后重新获取'; title: '请输入正确的手机号',
setTimeout(this.countDown.bind(this), 1000); icon: 'none',
} duration: 1000
}, })
} else {
/** uni.showLoading({
* 获取注册值 title: '正在发送验证码...'
* @param {Object} e })
*/ let res = await setSendMsg(data.mobile,'login')
inputChange(e) { uni.hideLoading();
const key = e.currentTarget.dataset.key; uni.hideToast();
this[key] = e.detail.value; if( res ){
}, data.sending = true;
uni.showToast({
/** title: '验证码发送成功请注意查收',
* 是否同意协议 icon: 'none',
* @param {Object} e duration: 1000
*/ })
radioChange(e) { data.countDown();
this.checked = e } else {
}, uni.showModal({
showCancel: false,
/** title: '短信发送失败',
* 登录 content: '请一分钟后再获取验证码'
*/
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();
})
} }
} }
}; }
/**
* 验证码倒计时
*/
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
} = data;
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 + '秒后重新获取'; uni.showToast({
setTimeout(this.countDown.bind(this), 1000); title: '验证码发送成功请注意查收',
icon: 'none',
duration: 1000
})
this.countDown();
} else {
uni.showModal({
showCancel: false,
title: '短信发送失败',
content: res.msg ? res.msg : '请一分钟后再获取验证码'
});
} }
},
inputChange(e) {
const key = e.currentTarget.dataset.key;
this[key] = e.detail.value;
},
navBack() {
uni.navigateBack();
},
navTo(url) { uni.hideLoading();
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({
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
});
}
});
},
} }
}; }
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>

67
pages/me/agreement.vue Normal file
View File

@@ -0,0 +1,67 @@
<template>
<view style="line-height: 26px;padding: 32upx;" class="home1 ">
<view style="font-size: 28upx;" v-html="data.content"></view>
<view class="btn-box u-flex u-row-center" v-if="!isLogin">
<view class="btn cancel" @click="cancel">拒绝</view>
<view class="btn" @click="back">同意</view>
</view>
</view>
</template>
<script setup>
import { reactive } from 'vue';
import { onLoad } from '@dcloudio/uni-app'
import config from '@/commons/config.js';
import {selectUserById} from '@/api/user/user.js';
import {commonType} from '@/api/init.js';
let data = reactive({
content: '',
isLogin:false
})
onLoad(() => {
getGuize()
data.isLogin=uni.getStorageSync('token')?true:false
})
async function getGuize() {
let res = await commonType(154)
data.content = res.value
}
function cancel(){
// #ifdef H5
uni.navigateBack()
// #endif
// #ifdef APP
plus.runtime.quit();
// #endif
}
function back(){
uni.navigateBack()
}
</script>
<style scoped>
.btn {
width: 100%;
height: 42px;
line-height: 42px;
border-radius: 30px;
background: #ff7581;
color: #ffffff;
text-align: center;
}
.btn-box{
gap: 20px;
padding: 30rpx 130rpx;
}
.cancel{
background-color: #eee;
color: #999;
}
page{
/* background: #1c1b20; */
}
</style>

70
pages/me/privacy.vue Normal file
View File

@@ -0,0 +1,70 @@
<template>
<view style="font-size: 14px;line-height: 26px;padding: 32upx;" class="home1 ">
<view style="font-size: 28upx;" v-html="data.content"></view>
<view class="btn-box u-flex u-row-center" v-if="!isLogin">
<view class="btn cancel" @click="cancel">拒绝</view>
<view class="btn" @click="back">同意</view>
</view>
</view>
</template>
<script setup>
import { reactive } from 'vue';
import { onLoad } from '@dcloudio/uni-app'
import config from '@/commons/config.js';
import {selectUserById} from '@/api/user/user.js';
import {commonType} from '@/api/init.js';
let data = reactive({
content: '',
isLogin:false
})
onLoad(() => {
getGuize()
data.isLogin=uni.getStorageSync('token')?true:false
})
async function getGuize() {
let res = await commonType(155)
data.content = res.value
}
function cancel(){
// #ifdef H5
uni.navigateBack()
// #endif
// #ifdef APP
plus.runtime.quit();
// #endif
}
function back(){
uni.navigateBack()
}
</script>
<style scoped>
.btn {
width: 100%;
height: 42px;
line-height: 42px;
border-radius: 30px;
background: #ff7581;
color: #ffffff;
text-align: center;
}
.btn-box{
gap: 20px;
padding: 30rpx 130rpx;
}
.cancel{
background-color: #eee;
color: #999;
}
page{
/* background: #1c1b20; */
}
</style>

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() {
return{
userInfo: {
avatar: '',
userName: '',
phone: '',
}
}
},
onLoad( options ) {
this.getUserInfo()
},
methods: { let data = reactive({
/** userInfo: {
* 获取个人信息 avatar: '',
*/ userName: '',
getUserInfo() { phone: '',
http.request({ }
url:'app/user/selectUserById', })
}).then(res => {
this.userInfo = res.data
})
},
/** onShow(() => {
* 上次头像 // console.log(1)
*/ getUserInfo()
uploadImg() { })
let that = this;
var url = null; /**
uni.showActionSheet({ * 获取个人信息
// itemList按钮的文字接受的是数组 */
itemList: ["查看头像", "从相册选择图片"], async function getUserInfo () {
success(e) { let res = await selectUserById()
var index = e.tapIndex if ( res.code == 0 ) {
console.log(index) data.userInfo = res.data
if (index === 0) { }
// 用户点击了预览当前图片 }
// 可以自己实现当前头像链接的读取
let url = that.headImg; /**
let arr = [] * 上传头像
arr.push(url) */
uni.previewImage({ function uploadImg () {
// 预览功能图片也必须是数组的 var url = null;
urls: arr uni.showActionSheet({
}) // itemList按钮的文字接受的是数组
} else if (index === 1) { itemList: ["查看头像", "从相册选择图片"],
uni.chooseImage({ success(e) {
count: 1, //默认9 var index = e.tapIndex
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 console.log(index)
sourceType: ['album'], //从相册选择 if (index === 0) {
success: function(res) { // 用户点击了预览当前图片
uni.showLoading({ // 可以自己实现当前头像链接的读取
title: '上传中...' let url = data.userInfo.avatar;
}); let arr = []
uni.uploadFile({ arr.push(url)
url: config.baseApiUrl + 'alioss/upload', uni.previewImage({
filePath: res.tempFilePaths[0], // 预览功能图片也必须是数组的
name: 'file', urls: arr
success: uploadFileRes => { })
url = JSON.parse(uploadFileRes.data); } else if (index === 1) {
console.log(url) uni.chooseImage({
this.userInfo.avatar = url.data count: 1, //默认9
uni.hideLoading(); sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: function(res) {
uni.showLoading({
title: '上传中...'
});
uni.uploadFile({
url: config.baseApiUrl + 'alioss/upload',
filePath: res.tempFilePaths[0],
name: 'file',
success: uploadFileRes => {
url = JSON.parse(uploadFileRes.data);
console.log(url)
data.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) {
uni.showToast({
title: "手机号格式不正确",
icon: "none"
})
return
} }
}
})
}
uni.showModal({ /**
title: '温馨提示', * 保存
content: '确定保存信息', */
confirmColor: '#ff7581', function save () {
success: e => { if (!data.userInfo.userName) {
if (e.confirm) { uni.showToast({
http.request({ title: "用户名不能为空",
url:'app/user/updateUsers', icon: "none"
method: 'post', })
data: { return
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>