|
4 | 4 | <el-form-item label="用户头像"> |
5 | 5 | <el-upload |
6 | 6 | ref="headerUpload" |
7 | | - action="/api/vue-blog/addUserHeader" |
8 | 7 | accept="image/png, image/jpeg" |
9 | 8 | list-type="picture-card" |
| 9 | + :action="action" |
10 | 10 | :file-list="fileList" |
11 | | - :data="{ id: $route.params.id }" |
| 11 | + :data="{ token, key: `id-${$route.params.id}` }" |
12 | 12 | :before-upload="beforeAvatarUpload" |
13 | 13 | :on-success="avatarUploadSuccess"> |
14 | 14 | <i class="el-icon-plus"></i> |
@@ -48,6 +48,8 @@ export default { |
48 | 48 | data () { |
49 | 49 | return { |
50 | 50 | headimg: '', |
| 51 | + token: '', |
| 52 | + action: process.env.VUE_APP_qiniu_domain, |
51 | 53 | userInfo: { |
52 | 54 | headimg: '', |
53 | 55 | name: '', |
@@ -93,8 +95,13 @@ export default { |
93 | 95 | }, |
94 | 96 | created () { |
95 | 97 | this.apiSelectUserMethod() |
| 98 | + this.getToken() |
96 | 99 | }, |
97 | 100 | methods: { |
| 101 | + async getToken () { |
| 102 | + const result = await this.axios.get(`/addUserHeader/getToken?id=${this.$route.params.id}`, { showLoading: true }) |
| 103 | + result.isok && (this.token = result.upToken) |
| 104 | + }, |
98 | 105 | async apiSelectUserMethod () { |
99 | 106 | let result = await apiSelectUser({ |
100 | 107 | authorId: this.$route.params.id |
@@ -123,10 +130,15 @@ export default { |
123 | 130 | return (isJPG || isPNG) && isLt2M |
124 | 131 | }, |
125 | 132 | avatarUploadSuccess (result) { |
126 | | - if (result.isok) { |
127 | | - this.fileList = [{ url: `${process.env.VUE_APP_host}/${result.data.src}` }] |
128 | | - this.$nextTick(() => { |
129 | | - this.$store.dispatch('tokenGetUserInfo') |
| 133 | + if (result.key) { |
| 134 | + this.fileList = [{ url: `${process.env.VUE_APP_img_domain}/${result.key}` }] |
| 135 | + this.axios.post('/addUserHeader/add', { |
| 136 | + id: this.$route.params.id, |
| 137 | + headerPath: `${process.env.VUE_APP_img_domain}/${result.key}` |
| 138 | + }, { showLoading: true }).then(() => { |
| 139 | + this.$nextTick(() => { |
| 140 | + this.$store.dispatch('tokenGetUserInfo') |
| 141 | + }) |
130 | 142 | }) |
131 | 143 | } |
132 | 144 | }, |
|
0 commit comments