mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-01-30 14:09:58 +08:00
Allow set avatar from skinlib
This commit is contained in:
parent
70c9226bf8
commit
0dfdf593ca
33
resources/assets/src/components/mixins/setAsAvatar.js
Normal file
33
resources/assets/src/components/mixins/setAsAvatar.js
Normal file
@ -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)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
@ -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"
|
||||
/>
|
||||
<a
|
||||
v-if="liked"
|
||||
v-t="'skinlib.removeFromCloset'"
|
||||
style="margin-left: 12px"
|
||||
class="btn btn-primary pull-right"
|
||||
class="btn btn-primary pull-right pulled-right-btn"
|
||||
@click="removeFromCloset"
|
||||
/>
|
||||
<a
|
||||
v-else
|
||||
v-t="'skinlib.addToCloset'"
|
||||
style="margin-left: 12px"
|
||||
class="btn btn-primary pull-right"
|
||||
class="btn btn-primary pull-right pulled-right-btn"
|
||||
@click="addToCloset"
|
||||
/>
|
||||
<button
|
||||
v-if="type !== 'cape'"
|
||||
v-t="'user.setAsAvatar'"
|
||||
class="btn btn-default pull-right pulled-right-btn"
|
||||
@click="setAsAvatar"
|
||||
/>
|
||||
<a
|
||||
v-if="canBeDownloaded"
|
||||
v-t="'skinlib.show.download'"
|
||||
@ -138,12 +141,14 @@
|
||||
<script>
|
||||
import toastr from 'toastr'
|
||||
import { swal } from '../../js/notify'
|
||||
import setAsAvatar from '../mixins/setAsAvatar'
|
||||
|
||||
export default {
|
||||
name: 'Show',
|
||||
components: {
|
||||
Previewer: () => import('../common/Previewer'),
|
||||
},
|
||||
mixins: [setAsAvatar],
|
||||
props: {
|
||||
baseUrl: {
|
||||
type: String,
|
||||
@ -346,4 +351,8 @@ export default {
|
||||
.table > tbody > tr > td {
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
.pulled-right-btn {
|
||||
margin-left: 12px;
|
||||
}
|
||||
</style>
|
||||
|
@ -35,9 +35,11 @@
|
||||
<script>
|
||||
import toastr from 'toastr'
|
||||
import { swal } from '../../js/notify'
|
||||
import setAsAvatar from '../mixins/setAsAvatar'
|
||||
|
||||
export default {
|
||||
name: 'ClosetItem',
|
||||
mixins: [setAsAvatar],
|
||||
props: {
|
||||
tid: {
|
||||
type: Number,
|
||||
@ -111,33 +113,6 @@ export default {
|
||||
toastr.warning(msg)
|
||||
}
|
||||
},
|
||||
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)
|
||||
|
||||
// Refresh avatars
|
||||
$('[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)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -130,6 +130,27 @@ test('link to downloading texture', async () => {
|
||||
expect(wrapper.contains('a[title="123"]')).toBeFalse()
|
||||
expect(wrapper.contains('span[title="123"]')).toBeTrue()
|
||||
})
|
||||
test('set as avatar', () => {
|
||||
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: true })
|
||||
Vue.prototype.$http.get.mockResolvedValueOnce({ type: 'steve' })
|
||||
.mockResolvedValueOnce({ type: 'cape' })
|
||||
const wrapper = mount(Show, {
|
||||
mocks: {
|
||||
$route: ['/skinlib/show/1', '1'],
|
||||
},
|
||||
stubs: { previewer },
|
||||
})
|
||||
wrapper.find('button.btn-default').trigger('click')
|
||||
expect(swal).toBeCalled()
|
||||
|
||||
const noSetAsAvatar = mount(Show, {
|
||||
mocks: {
|
||||
$route: ['/skinlib/show/1', '1'],
|
||||
},
|
||||
stubs: { previewer },
|
||||
})
|
||||
expect(noSetAsAvatar.find('button.btn-default').isEmpty()).toBeTrue()
|
||||
})
|
||||
test('add to closet', async () => {
|
||||
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: false })
|
||||
Vue.prototype.$http.get.mockResolvedValue({ name: 'wow', likes: 2 })
|
||||
|
Loading…
Reference in New Issue
Block a user