upload-evo.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <script setup lang="ts">
  2. // defineProps<>()
  3. const modelValue = defineModel({ type: String, default: '' })
  4. const props = defineProps<{ multiple?: boolean; limit?: number; disabled?: boolean }>()
  5. const fileList = ref([])
  6. const action = ref(`${import.meta.env.VITE_SERVER_BASEURL}/app-api/infra/file/upload`)
  7. const fileUrls = computed(() => fileList.value.map(({ response }) => JSON.parse(response).data))
  8. const handleChange = ({ fileList: files }) => {
  9. fileList.value = files
  10. console.log(fileList.value)
  11. console.log(fileUrls.value)
  12. if (!props.multiple) {
  13. modelValue.value = fileUrls.value[0] || ''
  14. }
  15. }
  16. watch(
  17. () => fileList,
  18. () => {
  19. // console.log(modelValue.value)
  20. },
  21. )
  22. onMounted(() => {
  23. // console.log(modelValue.value)
  24. if (typeof modelValue.value === 'string' && (modelValue.value ?? '') !== '') {
  25. fileList.value = [{ url: modelValue.value }]
  26. }
  27. // console.log(fileList.value)
  28. })
  29. </script>
  30. <template>
  31. <wd-upload
  32. :disabled="disabled"
  33. :file-list="fileList"
  34. image-mode="aspectFill"
  35. :action="action"
  36. :multiple="multiple ?? false"
  37. :limit="limit ?? 1"
  38. @change="handleChange"
  39. ></wd-upload>
  40. </template>