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

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

上级 8e68abdd
...@@ -15,7 +15,8 @@ module.exports = { ...@@ -15,7 +15,8 @@ module.exports = {
"router":{ "router":{
"needLogin":[ //配置需要路由拦截的页面地址,在打开这些页面之前会自动检查(不联网)uni_id_token的值是否存在/过期等 "needLogin":[ //配置需要路由拦截的页面地址,在打开这些页面之前会自动检查(不联网)uni_id_token的值是否存在/过期等
"/uni_modules/uni-id-users/pages/uni-id-users/edit", "/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"] //默认就是短信验证码登陆 "login":["univerify","smsCode","username","weixin","apple"] //默认就是短信验证码登陆
}, },
......
...@@ -112,6 +112,9 @@ ...@@ -112,6 +112,9 @@
// #endif // #endif
}, },
methods: { methods: {
...mapMutations({
setUserInfo: 'user/login'
}),
toSettings() { toSettings() {
uni.navigateTo({ uni.navigateTo({
url: "/pages/ucenter/settings/settings" url: "/pages/ucenter/settings/settings"
...@@ -131,9 +134,52 @@ ...@@ -131,9 +134,52 @@
}, },
toEdit() { toEdit() {
console.log('点击编辑信息'); console.log('点击编辑信息');
// 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({ uni.navigateTo({
url: '/uni_modules/uni-id-users/pages/uni-id-users/edit' url:'/uni_modules/uni-login-page/pages/index/index'
}) })
}
}, },
tapGrid(index) { tapGrid(index) {
uni.showToast({ uni.showToast({
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
return { return {
formData: { formData: {
"avatar": "", "avatar": "",
"gender": 0, "gender": '',
"mobile": "", "mobile": "",
"nickname": "" "nickname": ""
}, },
...@@ -100,12 +100,6 @@ ...@@ -100,12 +100,6 @@
width:600, width:600,
height:600 height:600
} }
uni.navigateTo({
url: '/pages/ucenter/edit/uploadCutImageToUnicloud',
success: res => {},
fail: () => {},
complete: () => {}
});
// 剪裁并上传头像 // 剪裁并上传头像
uni.navigateTo({ uni.navigateTo({
url:'/pages/ucenter/edit/uploadCutImageToUnicloud?path=' + res.tempFilePaths[0] + `&options=${JSON.stringify(options)}`, url:'/pages/ucenter/edit/uploadCutImageToUnicloud?path=' + res.tempFilePaths[0] + `&options=${JSON.stringify(options)}`,
......
...@@ -32,18 +32,6 @@ exports.main = async (event, context) => { ...@@ -32,18 +32,6 @@ exports.main = async (event, context) => {
return recentRecord.data.filter(item => item.state === 0).length === recordSize; 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 //设置某些模块不需要token(也就是登陆成功后)才能操作,如果需要token就获取当前操作账户的uid
let noCheckAction = [ let noCheckAction = [
'register', 'checkToken', 'login', 'logout', 'sendSmsCode', 'register', 'checkToken', 'login', 'logout', 'sendSmsCode',
...@@ -66,7 +54,17 @@ exports.main = async (event, context) => { ...@@ -66,7 +54,17 @@ exports.main = async (event, context) => {
params.uid = payload.uid 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 loginLog = async (res = {}, type = 'login') => {
const now = Date.now() const now = Date.now()
...@@ -86,8 +84,10 @@ exports.main = async (event, context) => { ...@@ -86,8 +84,10 @@ exports.main = async (event, context) => {
} : { } : {
state: 0 state: 0
}) })
if(res.type == 'register'){
return uniIdLogCollection.add(logData) await registerSuccess(res.uid)
}
return await uniIdLogCollection.add(logData)
} }
...@@ -118,7 +118,7 @@ exports.main = async (event, context) => { ...@@ -118,7 +118,7 @@ exports.main = async (event, context) => {
password password
}); });
if (res.code === 0) { if (res.code === 0) {
registerSuccess(res.uid) await registerSuccess(res.uid)
} }
break; break;
case 'login': case 'login':
...@@ -136,10 +136,6 @@ exports.main = async (event, context) => { ...@@ -136,10 +136,6 @@ exports.main = async (event, context) => {
queryField: ['username', 'email', 'mobile'] queryField: ['username', 'email', 'mobile']
}); });
await loginLog(res); await loginLog(res);
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
needCaptcha = await getNeedCaptcha(); needCaptcha = await getNeedCaptcha();
} }
...@@ -151,24 +147,16 @@ exports.main = async (event, context) => { ...@@ -151,24 +147,16 @@ exports.main = async (event, context) => {
uid: res.uid, uid: res.uid,
username: "微信用户" username: "微信用户"
}); });
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
res.userInfo.username = "微信用户" res.userInfo.username = "微信用户"
loginLog(res) await loginLog(res)
break; break;
case 'login_by_univerify': case 'login_by_univerify':
res = await uniID.loginByUniverify(params) res = await uniID.loginByUniverify(params)
if (res.code == 0 && res.type == 'register') { await loginLog(res)
registerSuccess(res.uid)
}
break; break;
case 'login_by_apple': case 'login_by_apple':
res = await uniID.loginByApple(params) res = await uniID.loginByApple(params)
if (res.code == 0 && res.type == 'register') { await loginLog(res)
registerSuccess(res.uid)
}
loginLog(res)
break; break;
case 'checkToken': case 'checkToken':
res = await uniID.checkToken(event.uniIdToken); res = await uniID.checkToken(event.uniIdToken);
...@@ -203,9 +191,7 @@ exports.main = async (event, context) => { ...@@ -203,9 +191,7 @@ exports.main = async (event, context) => {
type: params.type, type: params.type,
templateId templateId
}) })
if (res.code == 0 && res.type == 'register') { await loginLog(res)
registerSuccess(res.uid)
}
break; break;
case 'loginBySms': case 'loginBySms':
if (!params.code) { if (!params.code) {
...@@ -221,10 +207,7 @@ exports.main = async (event, context) => { ...@@ -221,10 +207,7 @@ exports.main = async (event, context) => {
} }
} }
res = await uniID.loginBySms(params) res = await uniID.loginBySms(params)
if (res.code == 0 && res.type == 'register') { await loginLog(res)
registerSuccess(res.uid)
}
loginLog(res)
break; break;
case 'inviteLogin': case 'inviteLogin':
if (!params.code) { if (!params.code) {
...@@ -237,9 +220,6 @@ exports.main = async (event, context) => { ...@@ -237,9 +220,6 @@ exports.main = async (event, context) => {
...params, ...params,
type: 'register' type: 'register'
}) })
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
break; break;
case 'resetPwdBySmsCode': case 'resetPwdBySmsCode':
if (!params.code) { if (!params.code) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册