Merge pull request 'dengjie commit : 上传头像和收藏产品' (#68) from dengjie into dev
Reviewed-on: http://git.hchyun.com/feashow/pupil/pulls/68
This commit is contained in:
@@ -53,10 +53,10 @@
|
||||
url: '../../packageMy/changeAvatar/changeAvatar'
|
||||
})
|
||||
},
|
||||
//获取普通会员和VIP会员
|
||||
//获取头像昵称和普通会员和VIP会员
|
||||
getUser() {
|
||||
this.$apiServe.getUser().then(res => {
|
||||
// console.log('个人信息==', res.data.data);
|
||||
console.log('个人信息==', res.data.data);
|
||||
var data = res.data.data
|
||||
this.avatar = data.avatar
|
||||
this.nickname = data.nickname
|
||||
|
||||
@@ -29,9 +29,10 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<u-button v-if="type==1" type="success" text="移除" color="#0EBB5B" @click="deleteProduct(item)">
|
||||
|
||||
<u-button v-if="type==1" type="success" text="取消收藏" color="#0EBB5B" @click="cancelCollect(item)">
|
||||
</u-button>
|
||||
<u-button v-if="type==2" type="success" text="取消收藏" color="#0EBB5B" @click="cancelCollect(item)">
|
||||
<u-button v-if="type==2" type="success" text="移除" color="#0EBB5B" @click="deleteProduct(item)">
|
||||
</u-button>
|
||||
</u-grid-item>
|
||||
</u-grid>
|
||||
@@ -40,10 +41,11 @@
|
||||
</u-modal> -->
|
||||
<view style="font-size: 24rpx;color: #A3A3A3;text-align: center;padding: 26rpx 0;"
|
||||
v-if="type==1&&productList.length==0">
|
||||
暂无更多浏览记录</view>
|
||||
暂无更多收藏记录</view>
|
||||
<view style="font-size: 24rpx;color: #A3A3A3;text-align: center;padding: 26rpx 0;"
|
||||
v-if="type==2&&productList.length==0">
|
||||
暂无更多收藏记录</view>
|
||||
暂无更多浏览记录</view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<view>
|
||||
<productsBtn :type="1" ref="browseHistory"></productsBtn>
|
||||
<productsBtn :type="2" ref="browseHistory"></productsBtn>
|
||||
<!-- <view style="margin:0 20rpx;">
|
||||
<u-overlay :show="!isLoad">
|
||||
<login @success="reOnLoad()" @fail="failToLoad()"></login>
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
apiService
|
||||
} from '../../service/request'
|
||||
import login from 'pages/my/login/login'
|
||||
export default {
|
||||
components: {
|
||||
@@ -30,7 +33,7 @@
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
avatar: 'https://cdn.uviewui.com/uview/album/2.jpg',
|
||||
avatar: '',
|
||||
model: {
|
||||
userInfo: {
|
||||
name: ''
|
||||
@@ -40,6 +43,7 @@
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getUser()
|
||||
if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {
|
||||
this.isLoad = false
|
||||
// uni.navigateTo({
|
||||
@@ -50,45 +54,66 @@
|
||||
this.isLoad = true
|
||||
},
|
||||
methods: {
|
||||
//修改头像
|
||||
//获取头像昵称
|
||||
getUser() {
|
||||
this.$apiServe.getUser().then(res => {
|
||||
console.log('头像昵称', res.data);
|
||||
var data = res.data.data
|
||||
this.avatar = data.avatar
|
||||
this.model.userInfo.name = data.nickname
|
||||
}).finally(_ => {})
|
||||
},
|
||||
updatePromise(filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const token = uni.getStorageSync('loginToken')
|
||||
const a = uni.uploadFile({
|
||||
url: apiService.uploadImgUrl + '/upload/image/',
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
'Authorization': token
|
||||
},
|
||||
success: (res) => {
|
||||
console.log('上传头像', JSON.parse(res.data));
|
||||
// setTimeout(() => {
|
||||
resolve(JSON.parse(res.data).data.uri)
|
||||
// }, 1000)
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
//点击头像修改
|
||||
changeAvatar() {
|
||||
uni.chooseImage({ // 从本地相册选择图片或使用相机拍照。
|
||||
count: 1, //默认选择1张图片
|
||||
sizeType: ['original', 'compressed'], //original 原图,compressed 压缩图,默认二者都有
|
||||
success: (res) => {
|
||||
console.log(res.tempFilePaths[0]); //成功则返回图片的本地文件路径列表 tempFilePaths
|
||||
this.avatar = res.tempFilePaths[0] //更新本地浏览头像图片
|
||||
|
||||
// this.update(res.tempFilePaths[0]) //上传图片
|
||||
// console.log(res.tempFilePaths[0]); //成功则返回图片的本地文件路径列表 tempFilePaths
|
||||
// this.avatar = res.tempFilePaths[0] //更新本地浏览头像图片
|
||||
if (res.tempFilePaths[0]) {
|
||||
this.updatePromise(res.tempFilePaths[0]) //上传图片
|
||||
}
|
||||
});
|
||||
},
|
||||
update(filePath) {
|
||||
const _this = this
|
||||
const token = uni.getStorageSync('loginToken')
|
||||
const res = uni.uploadFile({
|
||||
url: _this.action, //仅为示例,非真实的接口地址
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
header: {
|
||||
'Authorization': token
|
||||
},
|
||||
success: (res) => {
|
||||
// console.log(JSON.parse(res.data).data) 处理格式
|
||||
this.weChatRegister({
|
||||
headimg: REQUEST_BASE_URL + '/' + JSON.parse(res.data).data
|
||||
}) //将真实图片地址请求给后端做修改
|
||||
|
||||
const result = this.updatePromise(res.tempFilePaths[0])
|
||||
result.then(value => {
|
||||
this.avatar = value
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
//提交头像和昵称
|
||||
handleSubmit() {
|
||||
console.log('昵称', this.model.userInfo.name);
|
||||
console.log('头像', this.avatar);
|
||||
this.$apiServe.updateUser({
|
||||
nickname: this.model.userInfo.name,
|
||||
avatar: this.avatar
|
||||
}).then(res => {
|
||||
console.log('修改头像昵称==', res);
|
||||
this.$toast.success(res.data.msg)
|
||||
uni.reLaunch({
|
||||
url: '/pages/my/my'
|
||||
})
|
||||
}).finally(_ => {})
|
||||
},
|
||||
reOnLoad() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<view>
|
||||
<productsBtn :type="2"></productsBtn>
|
||||
<productsBtn :type="1"></productsBtn>
|
||||
<!-- <view style="margin:0 20rpx;">
|
||||
<u-overlay :show="!isLoad">
|
||||
<login @success="reOnLoad()" @fail="failToLoad()"></login>
|
||||
|
||||
Reference in New Issue
Block a user