From 0dfdf593ca4cc6e6e84179b08119c43073c8f9df Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 17 Mar 2019 00:12:56 +0800 Subject: [PATCH] Allow set avatar from skinlib --- .../src/components/mixins/setAsAvatar.js | 33 +++++++++++++++++++ .../assets/src/components/skinlib/Show.vue | 21 ++++++++---- .../assets/src/components/user/ClosetItem.vue | 29 ++-------------- .../tests/components/skinlib/Show.test.js | 21 ++++++++++++ 4 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 resources/assets/src/components/mixins/setAsAvatar.js diff --git a/resources/assets/src/components/mixins/setAsAvatar.js b/resources/assets/src/components/mixins/setAsAvatar.js new file mode 100644 index 00000000..1b13ae05 --- /dev/null +++ b/resources/assets/src/components/mixins/setAsAvatar.js @@ -0,0 +1,33 @@ +import toastr from 'toastr' +import { swal } from '../../js/notify' + +export default { + methods: { + async setAsAvatar() { + const { dismiss } = await swal({ + title: this.$t('user.setAvatar'), + text: this.$t('user.setAvatarNotice'), + type: 'question', + showCancelButton: true, + }) + if (dismiss) { + return + } + + const { errno, msg } = await this.$http.post( + '/user/profile/avatar', + { tid: this.tid } + ) + if (errno === 0) { + toastr.success(msg) + + $('[alt="User Image"]').each(function it() { + // eslint-disable-next-line no-invalid-this + $(this).prop('src', `${$(this).attr('src')}?${new Date().getTime()}`) + }) + } else { + toastr.warning(msg) + } + }, + }, +} diff --git a/resources/assets/src/components/skinlib/Show.vue b/resources/assets/src/components/skinlib/Show.vue index c73a2d0c..f6ce5a42 100644 --- a/resources/assets/src/components/skinlib/Show.vue +++ b/resources/assets/src/components/skinlib/Show.vue @@ -19,23 +19,26 @@ v-if="liked" v-t="'skinlib.apply'" :href="`${baseUrl}/user/closet?tid=${tid}`" - class="btn btn-success pull-right" - style="margin-left: 12px" + class="btn btn-success pull-right pulled-right-btn" /> +