mirror of
https://github.com/jumpserver/lina.git
synced 2025-07-04 02:36:35 +00:00
Fixed: Image Upload
This commit is contained in:
parent
aaad6b8380
commit
446cb0b85e
@ -10,6 +10,9 @@
|
|||||||
<div>
|
<div>
|
||||||
<img v-if="preview" :class="showBG ? 'show-bg' : ''" :src="preview" v-bind="$attrs" alt="">
|
<img v-if="preview" :class="showBG ? 'show-bg' : ''" :src="preview" v-bind="$attrs" alt="">
|
||||||
</div>
|
</div>
|
||||||
|
<el-button v-if="fileName" size="mini" type="danger" @click.native.stop="resetUpload">
|
||||||
|
{{ this.$t('Cancel') }}
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -55,21 +58,29 @@ export default {
|
|||||||
},
|
},
|
||||||
Onchange(e) {
|
Onchange(e) {
|
||||||
const upLoadFile = e.target.files[0]
|
const upLoadFile = e.target.files[0]
|
||||||
|
|
||||||
if (upLoadFile === undefined) {
|
if (upLoadFile === undefined) {
|
||||||
this.$emit('input', this.initial)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fileName = upLoadFile?.name || ''
|
this.fileName = upLoadFile?.name || ''
|
||||||
this.$emit('fileChange', upLoadFile)
|
this.$emit('fileChange', upLoadFile)
|
||||||
this.$emit('input', this.getObjectURL(upLoadFile))
|
this.$emit('input', this.getObjectURL(upLoadFile))
|
||||||
},
|
},
|
||||||
|
resetUpload() {
|
||||||
|
this.fileName = ''
|
||||||
|
this.preview = ''
|
||||||
|
this.$refs.upLoadFile.value = ''
|
||||||
|
this.$emit('input', '')
|
||||||
|
this.$emit('fileChange', null)
|
||||||
|
},
|
||||||
getObjectURL(file) {
|
getObjectURL(file) {
|
||||||
let url = null
|
let url = null
|
||||||
if (window.createObjectURL !== undefined) { // basic
|
if (window.createObjectURL !== undefined) {
|
||||||
url = window.createObjectURL(file)
|
url = window.createObjectURL(file)
|
||||||
} else if (window.URL !== undefined) { // mozilla(firefox)
|
} else if (window.URL !== undefined) {
|
||||||
url = window.URL.createObjectURL(file)
|
url = window.URL.createObjectURL(file)
|
||||||
} else if (window.webkitURL !== undefined) { // webkit or chrome
|
} else if (window.webkitURL !== undefined) {
|
||||||
url = window.webkitURL.createObjectURL(file)
|
url = window.webkitURL.createObjectURL(file)
|
||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
|
Loading…
Reference in New Issue
Block a user