Browse Source

对接修改用户信息接口

master
邓平艺 4 years ago
parent
commit
edd2aaad89
  1. 17
      common/js/utils.js
  2. 13
      components/lf-nav/lf-nav.vue
  3. 15
      pages/user/my/center.vue
  4. 47
      pages/user/my/editname.vue
  5. 63
      pages/user/my/setting.vue

17
common/js/utils.js

@ -349,6 +349,20 @@ function pageLogin(url,callback){
} }
// 接口获取更新后的用户信息
function getUpdateUserInfo(token){
return new Promise((resolve, reject) => {
sandBox.get({
api: 'api/user',
header: {
Authorization: token
}
}).then(res => {
cookieStorage.set('user_info', res.data);
resolve(res.data);
}).catch(err => reject(err));
})
}
module.exports = { module.exports = {
@ -364,6 +378,7 @@ module.exports = {
GetUrl:GetUrl, GetUrl:GetUrl,
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
autoLogin:autoLogin
autoLogin:autoLogin,
// #endif // #endif
getUpdateUserInfo: getUpdateUserInfo
} }

13
components/lf-nav/lf-nav.vue

@ -64,6 +64,13 @@
type: Boolean, // showIcontrue type: Boolean, // showIcontrue
default: false default: false
}, },
backDiy: {
type: Boolean, // backInquiry
default: false
},
backCallback: {
type: Function //
},
boderBottom: { boderBottom: {
type: Boolean, // 线 type: Boolean, // 线
default: false default: false
@ -98,7 +105,11 @@
} }
}) })
}else{ }else{
this.$back();
if(this.backDiy){
this.$emit('backCallback');
}else{
this.$back();
}
} }
}, },
$back(){ $back(){

15
pages/user/my/center.vue

@ -100,7 +100,7 @@
<script> <script>
import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue' import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue'
import { getUrl } from '@/common/js/utils.js';
import { getUrl, getUpdateUserInfo } from '@/common/js/utils.js';
export default { export default {
components: { components: {
lfTabbar lfTabbar
@ -210,17 +210,6 @@
this.centerInfo = res.data.data; this.centerInfo = res.data.data;
}) })
}, },
//
getUpdateUserInfo(){
this.$http.get({
api: 'api/user',
header: {
Authorization: this.token
}
}).then(res => {
this.$cookieStorage.set('user_info', res.data);
})
},
// //
clickAvatar(){ clickAvatar(){
if(this.token && this.userInfo.avatar){ if(this.token && this.userInfo.avatar){
@ -278,7 +267,7 @@
res = res.data; res = res.data;
if (res.status) { if (res.status) {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
this.getUpdateUserInfo();
getUpdateUserInfo(this.token);
// #endif // #endif
uni.hideLoading(); uni.hideLoading();
} else { } else {

47
pages/user/my/editname.vue

@ -1,15 +1,15 @@
<template> <template>
<view> <view>
<lf-nav :spreadOut="true" :showIcon="true" title="修改昵称"></lf-nav>
<lf-nav :spreadOut="true" :showIcon="true" title="修改昵称" :backDiy="true" @backCallback="backCallback"></lf-nav>
<view class="lf-color-black lf-font-28 lf-p-30"> <view class="lf-color-black lf-font-28 lf-p-30">
可使用中英文数字和下划线字符限制1-10字符 可使用中英文数字和下划线字符限制1-10字符
</view> </view>
<view class="lf-p-l-32 lf-p-r-32"> <view class="lf-p-l-32 lf-p-r-32">
<view class="set-tag lf-border-bottom"> <view class="set-tag lf-border-bottom">
<view class="lf-font-28 lf-color-black"> <view class="lf-font-28 lf-color-black">
<input type="text" placeholder="输入新的昵称" />
<input v-model="name" type="text" placeholder="起一个好听的昵称吧" />
</view> </view>
<view class="lf-flex">
<view class="lf-flex" v-if="name.length" @click="clear">
<text class="lf-iconfont icon-cuo lf-font-24 lf-m-l-10 lf-color-777"></text> <text class="lf-iconfont icon-cuo lf-font-24 lf-m-l-10 lf-color-777"></text>
</view> </view>
</view> </view>
@ -18,6 +18,47 @@
</template> </template>
<script> <script>
export default {
data(){
return {
name: ''
}
},
methods: {
clear(){
this.name = '';
},
backCallback(){
if(!this.name){
return this.$toBack();
};
uni.showLoading({
title: '正在保存中'
})
let token = this.$cookieStorage.get('user_token');
this.$http.post({
api: 'api/users/update/info',
data: {
nick_name: this.name
},
header: {
Authorization: token,
Accept: 'application/json'
}
}).then(res => {
uni.hideLoading();
this.$msg('保存成功', {icon: 'success'}).then(() => {
this.$toBack();
});
}).catch(err => {
uni.hideLoading();
this.$msg('保存失败', {icon: 'error'}).then(() => {
this.$toBack();
});
})
}
}
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

63
pages/user/my/setting.vue

@ -7,12 +7,12 @@
昵称 昵称
</view> </view>
<view class="lf-flex"> <view class="lf-flex">
<view class="lf-font-28 lf-color-555">{{ userInfo.mobile_replace }}</view><text class="lf-iconfont icon-xiangyou lf-font-24 lf-m-l-10 lf-color-777"></text>
<view class="lf-font-28 lf-color-555">{{ userInfo.nick_name || userInfo.mobile }}</view><text class="lf-iconfont icon-xiangyou lf-font-24 lf-m-l-10 lf-color-777"></text>
</view> </view>
</view> </view>
</view> </view>
<view class="lf-p-l-32 lf-p-r-32 lf-bg-white"> <view class="lf-p-l-32 lf-p-r-32 lf-bg-white">
<view class="set-tag lf-border-bottom" @click="$msg('敬请期待')">
<view class="set-tag lf-border-bottom" @click="changeImage">
<view class="lf-font-28 lf-color-black"> <view class="lf-font-28 lf-color-black">
头像 头像
</view> </view>
@ -93,17 +93,70 @@
</template> </template>
<script> <script>
import { config, getUpdateUserInfo } from '@/common/js/utils.js';
export default { export default {
data(){ data(){
return { return {
userInfo: {}
userInfo: {},
token: '',
shou_count: 0
} }
}, },
onLoad(){ onLoad(){
var userInfo = this.$cookieStorage.get('user_info');
this.userInfo = userInfo || {};
// var userInfo = this.$cookieStorage.get('user_info');
// this.userInfo = userInfo || {};
var token = this.$cookieStorage.get('user_token');
this.token = token;
this.getMeInfo();
},
onShow(){
this.shou_count++;
if(this.shou_count > 1){
this.getMeInfo();
}
}, },
methods: { methods: {
//
getMeInfo(){
this.$http.get({
api: 'api/me',
header: {
Authorization: this.token
}
}).then(res => {
this.userInfo = res.data.data;
})
},
//
changeImage: function() {
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'], //
sourceType: ['album'], //
success: res => {
var tempFilePaths = res.tempFilePaths;
this.newImage = tempFilePaths[0];
uni.uploadFile({
header: {
Authorization: this.token
},
url: config.GLOBAL.baseUrl + 'api/users/upload/avatar',
filePath: tempFilePaths[0],
fileType: 'image',
name: 'avatar_file',
success: res => {
var result = JSON.parse(res.data);
// this.setData({
// 'userInfo.avatar': result.data.url
// });
this.userInfo.avatar = result.data.url;
getUpdateUserInfo(this.token);
}
})
}
});
},
signOut(){ signOut(){
this.$msg('敬请期待') this.$msg('敬请期待')
} }

Loading…
Cancel
Save