Browse Source

头像上传

master
mk 2 years ago
parent
commit
aec19da74e
  1. 2
      pages/heartNew/heartNew.wxml
  2. 104
      pages/mine/mine.js
  3. 3
      pages/mine/mine.json
  4. 6
      pages/mine/mine.wxml
  5. 8
      utils/api.js

2
pages/heartNew/heartNew.wxml

@ -198,7 +198,7 @@
</view>
<activity bind:toActDetail="toActDetailDown" id="state-2" state="2"></activity>
</view>
<move-btn wx:if="{{applyBtn.imgUrl}}" area-top="120" area-height="90%" button-width="208" button-height="122" button-top="850" button-left="520" img-url="{{applyBtn.imgUrl}}" bindmovebtnCallBack="myApply"></move-btn>
<move-btn area-top="120" area-height="90%" button-width="208" button-height="122" button-top="850" button-left="520" img-url="{{'../../images/heart/apply-new.png'}}" bindmovebtnCallBack="myApply"></move-btn>
<move-btn wx:if="{{scanBtn.imgUrl && btnTop!=0}}" area-top="120" area-height="90%" button-width="200" button-height="200" button-top="{{btnTop}}" button-left="{{btnLeft}}" img-url="{{scanBtn.imgUrl}}" bindmovebtnCallBack="scanCode"></move-btn>
<!-- <move-btn wx:if="{{shouye.id}}"
area-top="120"

104
pages/mine/mine.js

@ -1,4 +1,7 @@
const api = require("../../utils/api")
import { $wuxActionSheet } from "../../dist/index"
const config = require("../../utils/config")
import {
getTimestamp
} from "../../utils/common"
@ -29,7 +32,8 @@ Page({
changeName:false,
visible: false,
signMsg: '',
signCode: 0
signCode: 0,
uploadImageList:[]
},
onLoad () {
if(app.globalData.infoCompleted == 0 || app.globalData.infoCompleted == 4){//当状态为0 或者 4 的时候 显示完善个人信息其余状态为更改个人信息
@ -335,7 +339,105 @@ Page({
duration: 1000
})
},
chooseImage () {
const _this = this
$wuxActionSheet().showSheet({
buttons: [
{ text: "拍照" },
{ text: "从相册中获取" },
],
className: "dialog-class",
buttonClicked (index) {
if (index === 0) {
wx.chooseImage({
count: 1,
sizeType: [ "compressed"],
sourceType: ["camera"],
success (res) {
const uploadImageList = [..._this.data.uploadImageList]
uploadImageList.push({
uploaded: false,
ossUrl: "",
imgUrl: res.tempFilePaths[0],
imageId: ++_this.data.imageId
})
_this.setData({
uploadImageList
})
wx.uploadFile({
url: `${config.BASEURL()}group/topic/upload`,
filePath: res.tempFilePaths[0],
name: "file",
header: {
"Content-type": "multipart/form-data"
},
success (fileRes){
console.log(fileRes);
uploadImageList[index].uploaded = true
// uploadImageList[index].ossUrl = JSON.parse(fileRes.data).data
_this.imageSave(JSON.parse(fileRes.data).data)
}
})
}
})
} else if (index === 1) {
wx.chooseImage({
count: 1,
sizeType: ["compressed"],
sourceType: ["album"],
success (res) {
console.log(res);
const uploadImageList = []
const endIndex = _this.data.uploadImageList.length
res.tempFilePaths.forEach(item => {
uploadImageList.push({
uploaded: false,
ossUrl: "",
imgUrl: item,
imageId: ++_this.data.imageId
})
})
_this.setData({
uploadImageList: [...uploadImageList]
})
uploadImageList.forEach((item, index) => {
return (function (index) {
wx.uploadFile({
url: `${config.BASEURL()}group/topic/upload`,
filePath: res.tempFilePaths[index],
name: "file",
header: {
"Content-type": "multipart/form-data"
},
success (fileRes){
uploadImageList[index].uploaded = true
uploadImageList[index].ossUrl = JSON.parse(fileRes.data).data
_this.imageSave(JSON.parse(fileRes.data).data)
}
})
})(index)
})
}
})
}
return true
},
cancelText: "取消",
cancel () {},
// destructiveButtonClicked () {},
})
},
imageSave(url){
api.updateAvata(url).then(res=>{
console.log(res);
this.getUserInfo()
}).catch(err=>{
console.log(err);
})
}
// 签到 2020.07.24
// toSignUp () {
// if (this.data.userInfo.isSignUp == 1) {

3
pages/mine/mine.json

@ -9,6 +9,7 @@
"preload-topic-item": "./components/preloadTopicItem/preloadTopicItem",
"load-more": "../../components/loadMore/loadMore",
"completeInfo-dialog": "../../components/completeInfoDialog/completeInfoDialog",
"wux-popup": "../../dist/popup/index"
"wux-popup": "../../dist/popup/index",
"wux-actionsheet": "../../dist/actionsheet/index"
}
}

6
pages/mine/mine.wxml

@ -7,12 +7,12 @@
<view class="top">
<view class="left">
<view class="avatar">
<image class="avatar-content" src="{{userInfo.faceImg}}" />
<image class="avatar-content" bindtap="chooseImage" src="{{userInfo.faceImg}}" />
</view>
<view class="right">
<view class="nickname">
<view>{{userInfo.nickname}}</view>
<image src="../../images/mine/ic_dangbiaoqian.png" class="dangbiao" wx:if="{{userInfo.partyFlag == '1'}}"/>
<image src="../../images/mine/ic_dangbiaoqian.png" class="dangbiao" wx:if="{{userInfo.partyFlag == '1'}}"/>
</view>
<!-- <view class="party-flag" wx:if="{{userInfo.partyFlag == '1'}}">
<view>党员</view>
@ -138,7 +138,7 @@
<completeInfo-dialog completeInfoDialogVisible="{{completeInfoDialogVisible}}">
</completeInfo-dialog>
<wux-actionsheet id="wux-actionsheet" />
<!-- 签到后提醒 -->
<wux-popup visible="{{visible}}" title="{{signCode === 0 ? '签到成功' : '签到失败'}}" content="{{signMsg}}" bind:close="onClose">
<view slot="footer" class="popup__button" bindtap="onClose">确定</view>

8
utils/api.js

@ -90,8 +90,8 @@ module.exports = {
submitVote,
getVoterDetail,
getVoterConfig,
//
getVolunteerPioneerList
getVolunteerPioneerList,
updateAvata
}
function getToken (wxCode) {
@ -722,3 +722,7 @@ function getVoterConfig() {
function getVolunteerPioneerList({ pageIndex, pageSize }) {
return fly.get('heart/volunteer/getVolunteerPioneerList', { pageIndex, pageSize })
}
// 头像上传
function updateAvata(updateAvataUrl) {
return fly.post(`app-user/user/updateAvatar?avatar=${updateAvataUrl}`)
}
Loading…
Cancel
Save