Browse Source

img width

master
chutingting 1 year ago
parent
commit
e5d77ba566
2 changed files with 23 additions and 3 deletions
  1. +7
    -3
      src/components/ueditor/index.vue
  2. +16
    -0
      src/components/uploadFile/index.vue

+ 7
- 3
src/components/ueditor/index.vue View File

@@ -11,7 +11,7 @@
<el-dialog v-if="uploadDiolagVisible" :visible.sync="uploadDiolagVisible" append-to-body title="图片上传">
<el-form>
<el-form-item label="上传图片">
<uploadFile :url.sync="imgUrl" type="image" width="auto" height="auto"/>
<uploadFile :url.sync="imgUrl" :imgWidth.sync="imgWidth" type="image" width="auto" height="auto" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="saveImg()">保存</el-button>
@@ -137,7 +137,8 @@ export default {
UEDITOR_HOME_URL: 'https://admin.meta-autotv.com/ueditor/' // UEditor资源文件的存放路径
},
imgUrl: '',
uploadDiolagVisible: false
uploadDiolagVisible: false,
imgWidth: 0
}
},
watch: {
@@ -162,7 +163,10 @@ export default {
if (this.isDisabled) this.editor.options.readonly = true
},
saveImg() {
let imageHtml = '<p><img width="100%" src=\"' + this.imgUrl + '\"/></p>'
let imageHtml = '<p><img src=\"' + this.imgUrl + '\"/></p>'
if (this.imgWidth > 800) {
imageHtml = '<p><img width="100%" src=\"' + this.imgUrl + '\"/></p>'
}
this.editor.execCommand('inserthtml', imageHtml)
this.uploadDiolagVisible = false
},


+ 16
- 0
src/components/uploadFile/index.vue View File

@@ -65,6 +65,22 @@ export default {
this.$message.error(txt)
return false
}
this.asyncImgChecked(file)
},
asyncImgChecked(file) {
var reader = new FileReader()
let that = this
reader.onload = function(event) {
var txt = event.target.result
var img = document.createElement('img')
img.src = txt
img.onload = function() {
that.$emit('update:imgWidth', img.width)
// console.log(img.width);
// console.log(img.height);
}
}
reader.readAsDataURL(file)
},
getVideo(videoId) {
uploadProgress(videoId).then(d => {


Loading…
Cancel
Save