Ai
376 Star 3.6K Fork 2.7K

唛盟开源/低代码开发平台-唛盟lcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Index.vue 5.22 KB
一键复制 编辑 原始数据 按行查看 历史
Admin 提交于 2024-05-10 13:52 +08:00 . 优化
<template>
<section>
<span v-if="!myVal||myVal.length==0" @click="$refs['imageDialog'].open()">
<el-image :lazy="lazy" :key="idx" :style="styleObj" :fit="fit" :z-index="zIndex" :initial-index="initialIndex" @load="onLoad" @error="onError" @click="$refs['imageDialog'].open()">
<template #planceholder>
<slot name="placeholder" >
{{ placeholder }}
</slot>
</template>
<template #error>
<slot name="error" >
</slot>
</template>
</el-image>
</span>
<span v-else-if="!this.multiple" @click="$refs['imageDialog'].open()">
<el-image :src="myVal" :previewSrcList="previewSrcList" :lazy="lazy" :key="idx" :style="styleObj" :fit="fit" :z-index="zIndex" :initial-index="initialIndex" @load="onLoad" @error="onError" @click="$refs['imageDialog'].open()">
<template #planceholder>
<slot name="placeholder" >
{{ placeholder }}
</slot>
</template>
<template #error>
<slot name="error" >
</slot>
</template>
</el-image>
</span>
<span v-else @click="$refs['imageDialog'].open()">
<el-image v-for="img,idx in myVal" :previewSrcList="previewSrcList" :lazy="lazy" :key="idx" :src="img" :style="styleObj" :fit="fit" :z-index="zIndex" :initial-index="initialIndex" @load="onLoad" @error="onError">
<template #planceholder>
<slot name="placeholder" >
{{ placeholder }}
</slot>
</template>
<template #error>
<slot name="error" >
</slot>
</template>
</el-image>
</span>
<mdp-dialog ref="imageDialog">
<mdp-select-image @select="onChange"/>
</mdp-dialog>
</section>
</template>
<script>
/**
* 图片展示并可选择组件
*/
export default {
name:'MdpImage',
components: {
},
computed: {
myVal:{
set(val){
this.$emit('update:modelValue',val)
},
get(){
var val=this.modelValue
if(!val){
return val
}else{
if(this.multiple){
if(this.split){
return val.split(this.split)
}
}
}
return val
}
}
},
props:{
/**
* 存储自定义表单数据的字段
*/
styleObj:{
type:Object,
default: function(){
return {
width: '100px', height: '100px'
}
}
},
fit:{
type:String,
default:'none',
},
lazy:{
type:Boolean,
default:false
},
previewSrcList:{
type:Array,
default:null,
},
zIndex:{
type:Number,
default:2000
},
initialIndex:{
type:Number,
default:null
},
modelValue:{
type:[String,Array],
default:null,
},
multiple:{
type: Boolean,
default:false
},
split:{
type:String,
default:null,
},
placeholder:{
type:String,
default:'图片上传'
}
},
watch: {
modelValue(val){
this.initCurrData()
}
},
data() {
return {
load:{list:false},
}
},
methods: {
onLoad(e){
this.$emit('load',e)
},
onError(e){
this.$emit('error',e)
},
onChange(imgs){
this.$refs['imageDialog'].close();
if(!imgs){
this.myVal=null
}
if(this.multiple==true ){
var val=imgs.map(k=>k.url);
if(this.split){
var valJoin=val.join(this.split)
if(valJoin!=this.modelValue){
this.myVal=valJoin
this.$emit('change',valJoin)
this.$emit("change2",imgs)
}
}else{
this.myVal=val
this.$emit('change',val)
this.$emit("change2",imgs)
}
}else{
var val=imgs[0].url;
this.myVal=val
this.$emit('change',val)
this.$emit("change2",imgs[0])
}
},
initCurrData(){
}
},
mounted() {
this.initCurrData();
}
}
</script>
<style scoped>
</style>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/maimengcloud/mdp-lcode-ui-web.git
git@gitee.com:maimengcloud/mdp-lcode-ui-web.git
maimengcloud
mdp-lcode-ui-web
低代码开发平台-唛盟lcode
master

搜索帮助