修改:图片输入组件
This commit is contained in:
parent
c47928748c
commit
adc097b2f2
@ -42,4 +42,12 @@ export default {
|
|||||||
data
|
data
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
// 上传url形式图片
|
||||||
|
uploadLinkImage: function(params) {
|
||||||
|
return request({
|
||||||
|
url: '/upload-markdown-link-image',
|
||||||
|
method: 'post',
|
||||||
|
data: params
|
||||||
|
})
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,32 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<el-upload
|
<el-upload
|
||||||
action="https://jsonplaceholder.typicode.com/posts/"
|
action="/api/upload-markdown-image"
|
||||||
:show-file-list="false"
|
:headers="headers"
|
||||||
:limit="1">
|
:data="extraData"
|
||||||
<el-button size="small" type="text">点击上传</el-button>
|
name="files"
|
||||||
|
accept="image/*"
|
||||||
|
:show-file-list="true"
|
||||||
|
:file-list="fileList"
|
||||||
|
list-type="picture"
|
||||||
|
:limit="1"
|
||||||
|
:on-success="handleSuccess"
|
||||||
|
>
|
||||||
|
<el-button size="small" type="text">点击上传</el-button>或者输入图片的url
|
||||||
|
<div slot="tip">{{ uploadTip }}</div>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
<el-tooltip class="item" effect="dark" placement="bottom">
|
<el-tooltip v-if="fileList.length === 0" class="item" effect="dark" placement="bottom">
|
||||||
<el-input :autosize="{ minRows: 2, maxRows: 4}" type="textarea" width="100%" v-model="currentValue" @change="change"></el-input>
|
<el-input :autosize="{ minRows: 1, maxRows: 4}" type="textarea" width="100%" v-model="currentValue" @change="change" @input="input" @focus="isLocked = true"></el-input>
|
||||||
<div slot="content">
|
<div slot="content">
|
||||||
<el-image style="width: 150px;" :src="currentValue" fit="contain"></el-image>
|
<el-image style="width: 150px;" :src="currentValue" fit="contain" @load="loadSuccess"></el-image>
|
||||||
</div>
|
</div>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import fileConfig from "@/utils/file-config";
|
||||||
|
import markdownApi from "@/api/markdown-api.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'UploadImageInput',
|
name: 'UploadImageInput',
|
||||||
props: {
|
props: {
|
||||||
@ -25,18 +37,89 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
currentValue: this.value
|
headers: {
|
||||||
|
'jmal-token': this.$store.state.user.token,
|
||||||
|
'username': this.$store.state.user.name,
|
||||||
|
'userId': this.$store.state.user.userId
|
||||||
|
},
|
||||||
|
extraData: {
|
||||||
|
'username': this.$store.state.user.name,
|
||||||
|
'userId': this.$store.state.user.userId
|
||||||
|
},
|
||||||
|
currentValue: this.value,
|
||||||
|
fileList: [],
|
||||||
|
isLocked: false, // true表示输入框正在输入状态
|
||||||
|
timer: null,
|
||||||
|
uploadTip: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
value(val) {
|
value(val) {
|
||||||
this.currentValue = val
|
this.currentValue = val
|
||||||
|
// const reg = /[^\\\/]*[\\\/]+/g
|
||||||
|
// this.fileList.push({name: val.replace(reg, ''), url: val})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
change() {
|
change(value) {
|
||||||
this.$emit('input', this.currentValue)
|
this.isLocked = false
|
||||||
|
console.log('change')
|
||||||
|
this.$emit('input', value)
|
||||||
|
},
|
||||||
|
input(value) {
|
||||||
|
console.log('input')
|
||||||
|
},
|
||||||
|
handleSuccess(response, file, fileList) {
|
||||||
|
if(response.code === 0){
|
||||||
|
if(response.data && response.data.length > 0){
|
||||||
|
this.currentValue = window.location.origin + fileConfig.mardownPreviewUrl(response.data[0].filepath) + "?o=thumbnail"
|
||||||
|
this.change(this.currentValue)
|
||||||
|
fileList[0].name = response.data[0].filename;
|
||||||
|
fileList[0].url = this.currentValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loadSuccess() {
|
||||||
|
if(this.timer == null){
|
||||||
|
if(this.isLocked){
|
||||||
|
const that = this
|
||||||
|
this.timer = setTimeout(function (){
|
||||||
|
if(!that.currentValue.startsWith(window.location.origin)){
|
||||||
|
that.uploadTip = "图片加载成功,准备上传"
|
||||||
|
markdownApi.uploadLinkImage({
|
||||||
|
username: that.$store.state.user.name,
|
||||||
|
userId: that.$store.state.user.userId,
|
||||||
|
url: that.currentValue
|
||||||
|
}).then((res) => {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearTimeout(this.timer)
|
||||||
|
this.timer = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
/deep/ .el-upload-list--picture {
|
||||||
|
.el-upload-list__item-thumbnail {
|
||||||
|
width: unset;
|
||||||
|
height: 90px;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
.el-upload-list__item {
|
||||||
|
margin-top: 0;
|
||||||
|
padding: 0px 0px 0px 80px;
|
||||||
|
}
|
||||||
|
.el-upload-list__item.is-success .el-upload-list__item-name {
|
||||||
|
line-height: 90px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/deep/ .el-upload-list__item-name {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@ -13,9 +13,7 @@
|
|||||||
<el-collapse-item title="网站首页背景" name="1">
|
<el-collapse-item title="网站首页背景" name="1">
|
||||||
<div class="config-itme-label">站点背景大图:
|
<div class="config-itme-label">站点背景大图:
|
||||||
</div>
|
</div>
|
||||||
<upload-image-input
|
<upload-image-input v-model="form.backgroundSite"/>
|
||||||
v-model="form.backgroundSite"
|
|
||||||
/>
|
|
||||||
<span class="instruction">在这里填入图片的URL地址, 以在网站首页显示一个背景大图。</span>
|
<span class="instruction">在这里填入图片的URL地址, 以在网站首页显示一个背景大图。</span>
|
||||||
<div class="config-itme-label">首页大图内文字:</div>
|
<div class="config-itme-label">首页大图内文字:</div>
|
||||||
<el-input autosize type="textarea" v-model="form.backgroundTextSite"></el-input>
|
<el-input autosize type="textarea" v-model="form.backgroundTextSite"></el-input>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user