mrr.sj.front/components/dynamic-form/FormItemImage.vue

54 lines
1.5 KiB
Vue

<template>
<ali-oss-uploader v-model="currentValue" :max-count="maxCount" :max-size="maxSize" accept="image/*" :userId="computedUserId"
:type="computedOssType" width="100%" :sortable="true" @input="onInput" @change="onChange" />
</template>
<script>
import AliOssUploader from '../ali-oss-uploader/ali-oss-uploader.vue'
export default {
name: 'FormItemImage',
components: { AliOssUploader },
props: {
value: { type: Array, default: function () { return []; } },
maxCount: { type: Number, default: 9 },
maxSize: { type: Number, default: 5 },
userId: { type: [Number, String], default: null },
ossType: { type: [Number, String], default: null }
},
data: function () {
return {
currentValue: []
};
},
computed: {
computedUserId: function () {
if (this.userId) return this.userId;
return this.$store && this.$store.state && this.$store.state.sjInfo
? this.$store.state.sjInfo.id : null;
},
computedOssType: function () {
if (this.ossType) return this.ossType;
var artisanType = getApp().globalData ? getApp().globalData.artisanType : 0;
return (artisanType || 0) + 1;
}
},
watch: {
value: {
handler: function (val) {
this.currentValue = Array.isArray(val) ? val.slice() : [];
},
immediate: true
}
},
methods: {
onInput: function (list) {
this.$emit('input', list);
},
onChange: function (list) {
this.$emit('change', list);
}
}
};
</script>