myinfo.vue
3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<template>
<view class="page">
<view class="bg">
<image src="/static/bg.jpg"></image>
</view>
<view class="back" @click="home"><image src="../../static/left.png"></image></view>
<pyh-nv ref="nv" :config="nvConfig"></pyh-nv>
<view class="listBox" :style="{'padding-top':(pageTop+'px')}">
<view class="content" style="padding: 20rpx;">
<view class="" style="background-color: rgba(255,255,255,0.6);border-radius: 20rpx;padding: 20rpx;">
<view class="" style="display: flex;justify-content: space-between;align-items: center;">
<view class="">
用户头像:
</view>
<view class="">
<u-upload name="1" :fileList="fileList" @delete="deletePic" @afterRead="afterRead" :previewFullImage="true" :maxCount="1"></u-upload>
</view>
</view>
<view class="" style="display: flex;justify-content: space-between;align-items: center;">
<view class="">
用户名:
</view>
<view class="">
<template>
<u--input
v-model="nickName"
placeholder="请输入名称"
border="bottom"
clearable
style="width: 70vw;"
></u--input>
</template>
</view>
</view>
<view class="" style="position: relative;position: fixed;bottom: 0;;width: 90vw;margin-bottom: 20rpx;">
<u-button @click="tj" type="primary" style="border: 1px solid red;width: 100vw;" text="提交修改"></u-button>
</view>
</view>
</view>
</view>
<u-toast ref="uToast"></u-toast>
</view>
</template>
<script>
import BASE_URL from "@/common/config.js"
export default {
data() {
return {
BASE_URL,
nvConfig:{
title:"个人信息修改",
bgColor:"#ffffff",
color:"#000000",
fixedAssist:{
hide:true,
},
back:{
hide:true
},
},
fileList: [],
nickName:"",
};
},
onPageScroll(e) {this.$refs.nv.pageScroll(e)},
computed:{
pageTop(){return parseInt(88*uni.getSystemInfoSync().windowWidth/750) + uni.getSystemInfoSync().statusBarHeight}
},
onLoad() {
uni.hideTabBar();
this.hquserinfo();
},
methods: {
// 获取用户信息
hquserinfo(){
var info = {
userId:uni.getStorageSync("USERS_KEY").userId,
}
this.API.hquserinfo(info).then(res=>{
console.log("获取用户信息",res);
this.fileList.push({
name:"1",
fileId:res.newFileName,
url: res.data.avatar
})
this.nickName = res.data.nickName;
})
},
home(){
uni.navigateBack({
delta: 1
});
},
tj(){
var info = {
userId:uni.getStorageSync("USERS_KEY").userId,
nickName:this.nickName,
avatar:this.fileList[0].url
}
this.API.xguserinfo(info).then(res=>{
console.log("修改用户信息",res);
this.$refs.uToast.show({
type: 'success',
title: '成功主题(带图标)',
message: "用户信息修改成功",
iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
})
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 2000);
})
},
// 删除图片
deletePic(event) {
},
// 上传图片
async afterRead(event) {
console.log(event);
var res = await this.uploadImg(event.file.url)
console.log("上传图片",res)
res = JSON.parse(res.data)
this.fileList = []
this.fileList.push({
name:res.fileName,
fileId:res.newFileName,
url: this.BASE_URL + res.fileName
})
},
uploadImg(url) {
return new Promise((r, e) => {
uni.uploadFile({
url: this.BASE_URL + "/common/upload",
filePath: url,
name: "file",
success: (d) => r(d)
})
})
},
deletePic(event) {
this.fileList.splice(event.index, 1)
},
}
}
</script>
<style scoped lang="scss">
@import 'myinfo.scss';
</style>