提交 f3793a09 编写于 作者: DCloud_JSON's avatar DCloud_JSON

改为点击头像直接修改头像

上级 8e68abdd
......@@ -15,7 +15,8 @@ module.exports = {
"router":{
"needLogin":[ //配置需要路由拦截的页面地址,在打开这些页面之前会自动检查(不联网)uni_id_token的值是否存在/过期等
"/uni_modules/uni-id-users/pages/uni-id-users/edit",
"/uni_modules/uni-news-favorite/pages/uni-news-favorite/list"
"/uni_modules/uni-news-favorite/pages/uni-news-favorite/list",
"/pages/ucenter/edit/uploadCutImageToUnicloud"
],
"login":["univerify","smsCode","username","weixin","apple"] //默认就是短信验证码登陆
},
......
......@@ -111,7 +111,10 @@
}
// #endif
},
methods: {
methods: {
...mapMutations({
setUserInfo: 'user/login'
}),
toSettings() {
uni.navigateTo({
url: "/pages/ucenter/settings/settings"
......@@ -131,9 +134,52 @@
},
toEdit() {
console.log('点击编辑信息');
uni.navigateTo({
url: '/uni_modules/uni-id-users/pages/uni-id-users/edit'
})
// uni.navigateTo({
// url: '/uni_modules/uni-id-users/pages/uni-id-users/edit'
// })
const token = uni.getStorageSync('uni_id_token')
if(token){
uni.chooseImage({
count:1,
success:(res)=> {
// 头像剪裁尺寸
let options = {
width:600,
height:600
}
// 剪裁并上传头像
uni.navigateTo({
url:'/pages/ucenter/edit/uploadCutImageToUnicloud?path=' + res.tempFilePaths[0] + `&options=${JSON.stringify(options)}`,
animationType:"fade-in",
events:{
uploadAvatarAfter:({url})=>{
console.log(url);
// 使用 clientDB 提交数据
db.collection('uni-id-users').where('_id==$env.uid').update({avatar:url}).then((res) => {
console.log(res);
uni.showToast({
icon: 'none',
title: '修改成功'
})
this.setUserInfo({avatar:url});
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
}
}
});
}
})
}else{
uni.navigateTo({
url:'/uni_modules/uni-login-page/pages/index/index'
})
}
},
tapGrid(index) {
uni.showToast({
......
......@@ -50,7 +50,7 @@
return {
formData: {
"avatar": "",
"gender": 0,
"gender": '',
"mobile": "",
"nickname": ""
},
......@@ -100,12 +100,6 @@
width:600,
height:600
}
uni.navigateTo({
url: '/pages/ucenter/edit/uploadCutImageToUnicloud',
success: res => {},
fail: () => {},
complete: () => {}
});
// 剪裁并上传头像
uni.navigateTo({
url:'/pages/ucenter/edit/uploadCutImageToUnicloud?path=' + res.tempFilePaths[0] + `&options=${JSON.stringify(options)}`,
......
......@@ -32,18 +32,6 @@ exports.main = async (event, context) => {
return recentRecord.data.filter(item => item.state === 0).length === recordSize;
}
//注册成功后为用户执行相关操作,如创建该用户的积分表等
function registerSuccess(uid) {
await db.collection('uni-id-scores').add({
user_id: uid,
score: 1,
type: 1,
balance: 1,
comment: "",
create_date: Date.now()
})
}
//设置某些模块不需要token(也就是登陆成功后)才能操作,如果需要token就获取当前操作账户的uid
let noCheckAction = [
'register', 'checkToken', 'login', 'logout', 'sendSmsCode',
......@@ -66,7 +54,17 @@ exports.main = async (event, context) => {
params.uid = payload.uid
}
//注册成功后为用户执行相关操作,如创建该用户的积分表等
async function registerSuccess(uid) {
await db.collection('uni-id-scores').add({
user_id: uid,
score: 1,
type: 1,
balance: 1,
comment: "",
create_date: Date.now()
})
}
//记录成功登陆的日志
const loginLog = async (res = {}, type = 'login') => {
const now = Date.now()
......@@ -86,8 +84,10 @@ exports.main = async (event, context) => {
} : {
state: 0
})
return uniIdLogCollection.add(logData)
if(res.type == 'register'){
await registerSuccess(res.uid)
}
return await uniIdLogCollection.add(logData)
}
......@@ -118,7 +118,7 @@ exports.main = async (event, context) => {
password
});
if (res.code === 0) {
registerSuccess(res.uid)
await registerSuccess(res.uid)
}
break;
case 'login':
......@@ -136,10 +136,6 @@ exports.main = async (event, context) => {
queryField: ['username', 'email', 'mobile']
});
await loginLog(res);
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
needCaptcha = await getNeedCaptcha();
}
......@@ -150,25 +146,17 @@ exports.main = async (event, context) => {
await uniID.updateUser({
uid: res.uid,
username: "微信用户"
});
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
});
res.userInfo.username = "微信用户"
loginLog(res)
await loginLog(res)
break;
case 'login_by_univerify':
res = await uniID.loginByUniverify(params)
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
res = await uniID.loginByUniverify(params)
await loginLog(res)
break;
case 'login_by_apple':
res = await uniID.loginByApple(params)
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
loginLog(res)
res = await uniID.loginByApple(params)
await loginLog(res)
break;
case 'checkToken':
res = await uniID.checkToken(event.uniIdToken);
......@@ -202,10 +190,8 @@ exports.main = async (event, context) => {
code,
type: params.type,
templateId
})
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
})
await loginLog(res)
break;
case 'loginBySms':
if (!params.code) {
......@@ -220,11 +206,8 @@ exports.main = async (event, context) => {
msg: '手机号码填写错误'
}
}
res = await uniID.loginBySms(params)
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
loginLog(res)
res = await uniID.loginBySms(params)
await loginLog(res)
break;
case 'inviteLogin':
if (!params.code) {
......@@ -236,10 +219,7 @@ exports.main = async (event, context) => {
res = await uniID.loginBySms({
...params,
type: 'register'
})
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
})
break;
case 'resetPwdBySmsCode':
if (!params.code) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册