get rid of slots
This commit is contained in:
parent
6de4dcc7c9
commit
457132fb37
2 changed files with 9 additions and 43 deletions
|
@ -78,42 +78,18 @@ const UserSettings = {
|
||||||
uploadFile (slot, e) {
|
uploadFile (slot, e) {
|
||||||
const file = e.target.files[0]
|
const file = e.target.files[0]
|
||||||
if (!file) { return }
|
if (!file) { return }
|
||||||
var error = () => {}
|
|
||||||
switch (slot) {
|
|
||||||
case 0:
|
|
||||||
error = (error) => { this.avatarUploadError = error }
|
|
||||||
break
|
|
||||||
case 1:
|
|
||||||
error = (error) => { this.bannerUploadError = error }
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
error = (error) => { this.backgroundUploadError = error }
|
|
||||||
break
|
|
||||||
}
|
|
||||||
var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit]
|
var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit]
|
||||||
if (file.size > limit[slot]) {
|
if (file.size > limit[slot]) {
|
||||||
const filesize = fileSizeFormatService.fileSizeFormat(file.size)
|
const filesize = fileSizeFormatService.fileSizeFormat(file.size)
|
||||||
const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot])
|
const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot])
|
||||||
error(this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}))
|
this[slot + 'UploadError'] = this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.onload = ({target}) => {
|
reader.onload = ({target}) => {
|
||||||
const img = target.result
|
const img = target.result
|
||||||
var preview = () => {}
|
this[slot + 'Preview'] = img
|
||||||
switch (slot) {
|
|
||||||
case 0:
|
|
||||||
preview = (preview) => { this.avatarPreview = preview }
|
|
||||||
break
|
|
||||||
case 1:
|
|
||||||
preview = (preview) => { this.bannerPreview = preview }
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
preview = (preview) => { this.backgroundPreview = preview }
|
|
||||||
break
|
|
||||||
}
|
|
||||||
preview(img)
|
|
||||||
}
|
}
|
||||||
reader.readAsDataURL(file)
|
reader.readAsDataURL(file)
|
||||||
},
|
},
|
||||||
|
@ -149,17 +125,7 @@ const UserSettings = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
clearUploadError (slot) {
|
clearUploadError (slot) {
|
||||||
switch (slot) {
|
this[slot + 'UploadError'] = null
|
||||||
case 0:
|
|
||||||
this.avatarUploadError = null
|
|
||||||
break
|
|
||||||
case 1:
|
|
||||||
this.bannerUploadError = null
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
this.backgroundUploadError = null
|
|
||||||
break
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
submitBanner () {
|
submitBanner () {
|
||||||
if (!this.bannerPreview) { return }
|
if (!this.bannerPreview) { return }
|
||||||
|
|
|
@ -39,13 +39,13 @@
|
||||||
<img class="new-avatar" v-bind:src="avatarPreview" v-if="avatarPreview">
|
<img class="new-avatar" v-bind:src="avatarPreview" v-if="avatarPreview">
|
||||||
</img>
|
</img>
|
||||||
<div>
|
<div>
|
||||||
<input type="file" @change="uploadFile(0, $event)" ></input>
|
<input type="file" @change="uploadFile('avatar', $event)" ></input>
|
||||||
</div>
|
</div>
|
||||||
<i class="icon-spin4 animate-spin" v-if="avatarUploading"></i>
|
<i class="icon-spin4 animate-spin" v-if="avatarUploading"></i>
|
||||||
<button class="btn btn-default" v-else-if="avatarPreview" @click="submitAvatar">{{$t('general.submit')}}</button>
|
<button class="btn btn-default" v-else-if="avatarPreview" @click="submitAvatar">{{$t('general.submit')}}</button>
|
||||||
<div class='alert error' v-if="avatarUploadError">
|
<div class='alert error' v-if="avatarUploadError">
|
||||||
Error: {{ avatarUploadError }}
|
Error: {{ avatarUploadError }}
|
||||||
<i class="icon-cancel" @click="clearUploadError(0)"></i>
|
<i class="icon-cancel" @click="clearUploadError('avatar')"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
|
@ -56,13 +56,13 @@
|
||||||
<img class="banner" v-bind:src="bannerPreview" v-if="bannerPreview">
|
<img class="banner" v-bind:src="bannerPreview" v-if="bannerPreview">
|
||||||
</img>
|
</img>
|
||||||
<div>
|
<div>
|
||||||
<input type="file" @change="uploadFile(1, $event)" ></input>
|
<input type="file" @change="uploadFile('banner', $event)" ></input>
|
||||||
</div>
|
</div>
|
||||||
<i class=" icon-spin4 animate-spin uploading" v-if="bannerUploading"></i>
|
<i class=" icon-spin4 animate-spin uploading" v-if="bannerUploading"></i>
|
||||||
<button class="btn btn-default" v-else-if="bannerPreview" @click="submitBanner">{{$t('general.submit')}}</button>
|
<button class="btn btn-default" v-else-if="bannerPreview" @click="submitBanner">{{$t('general.submit')}}</button>
|
||||||
<div class='alert error' v-if="bannerUploadError">
|
<div class='alert error' v-if="bannerUploadError">
|
||||||
Error: {{ bannerUploadError }}
|
Error: {{ bannerUploadError }}
|
||||||
<i class="icon-cancel" @click="clearUploadError(1)"></i>
|
<i class="icon-cancel" @click="clearUploadError('banner')"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
|
@ -71,13 +71,13 @@
|
||||||
<img class="bg" v-bind:src="backgroundPreview" v-if="backgroundPreview">
|
<img class="bg" v-bind:src="backgroundPreview" v-if="backgroundPreview">
|
||||||
</img>
|
</img>
|
||||||
<div>
|
<div>
|
||||||
<input type="file" @change="uploadFile(2, $event)" ></input>
|
<input type="file" @change="uploadFile('background', $event)" ></input>
|
||||||
</div>
|
</div>
|
||||||
<i class=" icon-spin4 animate-spin uploading" v-if="backgroundUploading"></i>
|
<i class=" icon-spin4 animate-spin uploading" v-if="backgroundUploading"></i>
|
||||||
<button class="btn btn-default" v-else-if="backgroundPreview" @click="submitBg">{{$t('general.submit')}}</button>
|
<button class="btn btn-default" v-else-if="backgroundPreview" @click="submitBg">{{$t('general.submit')}}</button>
|
||||||
<div class='alert error' v-if="backgroundUploadError">
|
<div class='alert error' v-if="backgroundUploadError">
|
||||||
Error: {{ backgroundUploadError }}
|
Error: {{ backgroundUploadError }}
|
||||||
<i class="icon-cancel" @click="clearUploadError(2)"></i>
|
<i class="icon-cancel" @click="clearUploadError('background')"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue