const SaUploader = { template: `
`, emit: ['update:modelValue', 'success'], props: { modelValue: { type: [Array, String], default: '' }, size: { type: [String, Number], default: '' }, multiple: { type: Boolean, default: false }, type: { type: String, default: '' }, }, setup(props, { emit }) { const { ref, computed, watch, nextTick, getCurrentInstance } = Vue const { proxy } = getCurrentInstance(); const urlList = ref(props.modelValue ? isArray(props.modelValue) ? props.modelValue : props.modelValue.split(',') : []) watch(() => props.modelValue, () => { urlList.value = props.modelValue ? isArray(props.modelValue) ? props.modelValue : props.modelValue.split(',') : [] }) const itemStyle = computed(() => ({ width: `${props.size}px`, height: `${props.size}px` })) const previewVisible = ref(false) // 图片加载完毕 function onImageLoaded() { nextTick(() => { if (props.type === 'size') { emit('success', { image_width: proxy.$refs.imageRef_0._.refs.container.firstChild.naturalWidth, image_height: proxy.$refs.imageRef_0._.refs.container.firstChild.naturalHeight }) } }) } function onSelectFile() { Fast.api.open(`general/attachment/select?multiple=${props.multiple}`, "选择", { callback: function (data) { data.url.split(',').forEach(item => { urlList.value.push(item) }); emit('update:modelValue', props.multiple ? urlList.value : urlList.value.join(',')) } }); } function onDeleteFile(index) { urlList.value.splice(index, 1) emit('update:modelValue', props.multiple ? urlList.value : urlList.value.join(',')) } return { Fast, props, emit, urlList, itemStyle, previewVisible, onSelectFile, onDeleteFile, onImageLoaded } } }