Showing
1 changed file
with
58 additions
and
19 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-08-31 16:16:49 | 2 | * @Date: 2022-08-31 16:16:49 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-03-29 18:04:07 | 4 | + * @LastEditTime: 2024-06-06 16:50:41 |
| 5 | * @FilePath: /data-table/src/components/ImageUploaderField/index.vue | 5 | * @FilePath: /data-table/src/components/ImageUploaderField/index.vue |
| 6 | * @Description: 图片上传控件 | 6 | * @Description: 图片上传控件 |
| 7 | --> | 7 | --> |
| ... | @@ -16,24 +16,36 @@ | ... | @@ -16,24 +16,36 @@ |
| 16 | v-html="item.component_props.note" | 16 | v-html="item.component_props.note" |
| 17 | style="font-size: 0.9rem; margin-left: 1rem; color: gray; padding-bottom: 0.5rem; padding-top: 0.25rem; white-space: pre-wrap;" | 17 | style="font-size: 0.9rem; margin-left: 1rem; color: gray; padding-bottom: 0.5rem; padding-top: 0.25rem; white-space: pre-wrap;" |
| 18 | /> | 18 | /> |
| 19 | - <div style="padding: 1rem"> | 19 | + <div v-if="!item.component_props.readonly"> |
| 20 | - <van-uploader | 20 | + <div style="padding: 1rem"> |
| 21 | - :name="item.name" | 21 | + <van-uploader |
| 22 | - upload-icon="add" | 22 | + :name="item.name" |
| 23 | - :before-read="beforeRead" | 23 | + upload-icon="add" |
| 24 | - :after-read="afterRead" | 24 | + :before-read="beforeRead" |
| 25 | - :before-delete="beforeDelete" | 25 | + :after-read="afterRead" |
| 26 | - v-model="fileList" | 26 | + :before-delete="beforeDelete" |
| 27 | - :multiple="item.component_props.max_size > 1" | 27 | + v-model="fileList" |
| 28 | - /> | 28 | + :multiple="item.component_props.max_size > 1" |
| 29 | + /> | ||
| 30 | + </div> | ||
| 31 | + <div class="type-text">上传类型: {{ type_text }}</div> | ||
| 32 | + <div | ||
| 33 | + v-if="show_empty" | ||
| 34 | + class="van-field__error-message" | ||
| 35 | + style="padding: 0 1rem 1rem 1rem" | ||
| 36 | + > | ||
| 37 | + 图片上传不能为空 | ||
| 38 | + </div> | ||
| 29 | </div> | 39 | </div> |
| 30 | - <div class="type-text">上传类型: {{ type_text }}</div> | 40 | + <div v-else style="padding: 1rem"> |
| 31 | - <div | 41 | + <van-image |
| 32 | - v-if="show_empty" | 42 | + v-for="(item, index) in default_list" :key="index" |
| 33 | - class="van-field__error-message" | 43 | + @click="onImgClick(index)" |
| 34 | - style="padding: 0 1rem 1rem 1rem" | 44 | + width="100" |
| 35 | - > | 45 | + height="100" |
| 36 | - 图片上传不能为空 | 46 | + :src="item" |
| 47 | + style="margin-right: 0.5rem; margin-block-end: 0.25rem;" | ||
| 48 | + /> | ||
| 37 | </div> | 49 | </div> |
| 38 | <van-divider /> | 50 | <van-divider /> |
| 39 | </div> | 51 | </div> |
| ... | @@ -52,7 +64,7 @@ | ... | @@ -52,7 +64,7 @@ |
| 52 | * @param image_type[Array] 图片上传类型 | 64 | * @param image_type[Array] 图片上传类型 |
| 53 | * @param multiple[Boolean] 图片多选 | 65 | * @param multiple[Boolean] 图片多选 |
| 54 | */ | 66 | */ |
| 55 | -import { showSuccessToast, showFailToast, showToast } from "vant"; | 67 | +import { showSuccessToast, showFailToast, showToast, showImagePreview } from "vant"; |
| 56 | import _ from "lodash"; | 68 | import _ from "lodash"; |
| 57 | import { v4 as uuidv4 } from "uuid"; | 69 | import { v4 as uuidv4 } from "uuid"; |
| 58 | import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from "@/api/common"; | 70 | import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from "@/api/common"; |
| ... | @@ -65,10 +77,29 @@ const $route = useRoute(); | ... | @@ -65,10 +77,29 @@ const $route = useRoute(); |
| 65 | const props = defineProps({ | 77 | const props = defineProps({ |
| 66 | item: Object, | 78 | item: Object, |
| 67 | }); | 79 | }); |
| 80 | + | ||
| 68 | // 隐藏显示 | 81 | // 隐藏显示 |
| 69 | const HideShow = computed(() => { | 82 | const HideShow = computed(() => { |
| 70 | return !props.item.component_props.disabled | 83 | return !props.item.component_props.disabled |
| 84 | +}); | ||
| 85 | +// 默认图片列表 | ||
| 86 | +const default_tmp = [{ | ||
| 87 | + name : "92C3D730-CB73-40DD-AB1F-E86A159D2F11.png", | ||
| 88 | + url : "https://cdn.ipadbiz.cn/uploadForm/kibnjo/91b15c62bc3d002fb1c2dd2023648376.png" | ||
| 89 | +}, { | ||
| 90 | + name : "92C3D730-CB73-40DD-AB1F-E86A159D2F11.png", | ||
| 91 | + url : "https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg" | ||
| 92 | +}]; | ||
| 93 | +const default_list = ref([]); | ||
| 94 | + | ||
| 95 | +onMounted(() => { | ||
| 96 | + // TODO: 没有默认的default字段 | ||
| 97 | + if (default_tmp.length) { | ||
| 98 | + default_list.value = default_tmp.map(item => item.url) | ||
| 99 | + console.log("🚀 ~ file: index.vue:97 ~ onMounted ~ default_list.value :", default_list.value ); | ||
| 100 | + } | ||
| 71 | }) | 101 | }) |
| 102 | + | ||
| 72 | const emit = defineEmits(["active"]); | 103 | const emit = defineEmits(["active"]); |
| 73 | const show_empty = ref(false); | 104 | const show_empty = ref(false); |
| 74 | 105 | ||
| ... | @@ -328,6 +359,14 @@ const validImageUploader = () => { | ... | @@ -328,6 +359,14 @@ const validImageUploader = () => { |
| 328 | return !show_empty.value; | 359 | return !show_empty.value; |
| 329 | }; | 360 | }; |
| 330 | 361 | ||
| 362 | +// 预览只读图片 | ||
| 363 | +const onImgClick = (i) => { | ||
| 364 | + showImagePreview({ | ||
| 365 | + images: default_list.value, | ||
| 366 | + startPosition: i, | ||
| 367 | + }); | ||
| 368 | +} | ||
| 369 | + | ||
| 331 | defineExpose({ validImageUploader }); | 370 | defineExpose({ validImageUploader }); |
| 332 | </script> | 371 | </script> |
| 333 | 372 | ... | ... |
-
Please register or login to post a comment