changeziliao.vue
3.3 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
<template>
<div class="containerbox">
<div class="changeitem flextwo">
<div class="changeitemleft">头像</div>
<div class="changeitemright flexone">
<img :src="avatar" alt class="headimg" />
<input
type="file"
class="shangtu"
accept="image/*"
@change="afterRead"
/>
<!-- <input type="file" class="shangtu" @click="afterRead" /> -->
<!-- <van-uploader v-model="fileList" multiple="false" :after-read="afterRead" :max-count="1" /> -->
<img src="../../../assets/grayrow.png" alt class="yourow" />
</div>
</div>
<van-loading type="spinner" color="#1989fa" v-if="cardzheng" />
<div class="changeitem flextwo">
<div class="changeitemleft">姓名</div>
<div class="changeitemleft">
<input type="text" v-model="username" placeholder="请输入姓名" />
</div>
</div>
<div class="kaishilu" @click="save">保存</div>
</div>
</template>
<script>
import Vue from "vue";
import { Toast, Uploader, Loading } from "vant";
import "vant/lib/index.css";
Vue.use(Loading);
Vue.use(Toast);
Vue.use(Uploader);
export default {
data() {
return {
username: "",
avatar: "",
fileList: [],
chuanimage: "",
cardzheng: false
};
},
created() {
document.title = "唐元集公众号";
this.username = this.$route.query.username;
this.avatar = this.$route.query.avatar;
console.log(this.avatar);
let obj = {
url: this.avatar
};
this.fileList.push(obj);
},
methods: {
// 上传图片
afterRead(e) {
console.log(e);
let file = e.target.files[0];
let that = this;
that.cardzheng = true;
var formdata = new FormData();
formdata.append("file", file);
var url = "/api/common/upload";
let param = {
id: 1
};
that.$uploadFile
.post(url, formdata)
.then(function(res) {
that.cardzheng = false;
console.log(res);
that.cardzheng = false;
let url = "http://tangyuanji.t.brotop.cn" + res.data.url;
that.avatar = url;
that.chuanimage = res.data.url;
})
.catch(err => {
console.log(err);
});
},
save() {
let that = this;
// if (that.chuanimage == '' && that.cardzheng == false) {
// Toast("请上传图片")
// return false
// }
if (that.chuanimage == "" && that.cardzheng == true) {
Toast("图片正在上传中");
return false;
}
var url =
"/api/user/profile?avatar=" +
that.chuanimage +
"&nickname=" +
that.username;
let param = {
avatar: that.chuanimage,
nickname: that.username
};
console.log(param);
that.$axios
.get(url)
.then(function(res) {
console.log(res);
Toast("保存成功");
that.$router.go(-1);
})
.catch(function(err) {
console.log(err);
});
}
}
};
</script>
<style scoped>
@import "../../../style/usercenter.css";
.changeitemleft input {
text-align: right;
}
.van-loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 99;
}
</style>