diff --git a/src/components/mediaSelector/MediaSelector.vue b/src/components/mediaSelector/MediaSelector.vue index dbaeb8d..ed3d005 100644 --- a/src/components/mediaSelector/MediaSelector.vue +++ b/src/components/mediaSelector/MediaSelector.vue @@ -25,9 +25,10 @@ :add-text="props.addText ?? '选择文件'" :busy="isBusy" :upload-enabled="!!props.upload" - @add="emit('add')" - @capture-photo="emit('capture-photo')" - @capture-video="emit('capture-video')" + @add="handleAdd" + @action="handleAddAction" + @capture-photo="handleCapturePhoto" + @capture-video="handleCaptureVideo" @file-change="handleFileChange" /> @@ -90,13 +91,32 @@ const props = withDefaults(defineProps(), { }); type Emits = { - (event: string): void; - (event: "update:modelValue", value: string[]): void; - (event: "update:photoItems", value: PhotoItem[]): void; + add: []; + action: [value: MediaSelectorAddAction]; + "capture-photo": []; + "capture-video": []; + "update:modelValue": [value: string[]]; + "update:photoItems": [value: PhotoItem[]]; }; const emit = defineEmits(); +function handleAddAction(action: MediaSelectorAddAction): void { + emit("action", action); +} + +function handleAdd(): void { + emit("add"); +} + +function handleCapturePhoto(): void { + emit("capture-photo"); +} + +function handleCaptureVideo(): void { + emit("capture-video"); +} + const photoViewerVisible = ref(false); const photoViewerImages = ref([]); const photoViewerItems = ref([]); diff --git a/src/components/mediaSelector/MediaSelectorAdd.vue b/src/components/mediaSelector/MediaSelectorAdd.vue index 7d1e0c7..db84b87 100644 --- a/src/components/mediaSelector/MediaSelectorAdd.vue +++ b/src/components/mediaSelector/MediaSelectorAdd.vue @@ -91,14 +91,12 @@ interface Props { const props = defineProps(); const emit = defineEmits<{ - (event: "add"): void; - (event: "capture-photo"): void; - (event: "capture-video"): void; - (event: "file-change", value: Event): void; + add: []; + action: [value: MediaSelectorAddAction]; + "capture-photo": []; + "capture-video": []; + "file-change": [value: Event]; }>(); -const emitExternal = (event: string): void => { - (emit as unknown as (eventName: string) => void)(event); -}; const capturePopoverVisible = ref(false); const fileInput = ref(); @@ -127,15 +125,23 @@ function handleFileAction(): void { function handleCaptureAction(action: MediaSelectorAddAction): void { capturePopoverVisible.value = false; - if (action.emit === "capture-photo" && props.uploadEnabled) { - photoFileInput.value?.click(); + if (action.emit === "capture-photo") { + if (props.uploadEnabled) { + photoFileInput.value?.click(); + return; + } + emit("capture-photo"); return; } - if (action.emit === "capture-video" && props.uploadEnabled) { - videoFileInput.value?.click(); + if (action.emit === "capture-video") { + if (props.uploadEnabled) { + videoFileInput.value?.click(); + return; + } + emit("capture-video"); return; } - emitExternal(action.emit); + emit("action", action); } function handleFileChange(event: Event): void { diff --git a/src/pages/customer/CustomerEdit.vue b/src/pages/customer/CustomerEdit.vue index 78cff9d..fb4ca32 100644 --- a/src/pages/customer/CustomerEdit.vue +++ b/src/pages/customer/CustomerEdit.vue @@ -81,10 +81,9 @@ :add-actions="photoAddActions" :loading="isPhotoUploading" @add="openPhotoPicker('OTHER')" + @action="handlePhotoAction" @capture-photo="capturePhoto" @capture-video="captureVideo" - @add-point-card="capturePointCard" - @add-other="openPhotoPicker('OTHER')" />
当前账户权限编辑客户需要上传照片和积分卡
@@ -232,6 +231,7 @@ import CodeScanner from "@/components/CodeScanner.vue"; import CustomerProfileCard from "@/components/CustomerProfileCard.vue"; import CustomerSelector from "@/components/CustomerSelector.vue"; import MediaSelector from "@/components/mediaSelector/MediaSelector.vue"; +import type { MediaSelectorAddAction } from "@/components/mediaSelector/types"; import TagSelector from "@/components/TagSelector.vue"; import CustomerTagCard from "@/pages/customer/component/CustomerTagCard.vue"; import { useCurrentStoreStore } from "@/store/currentStoreStore"; @@ -484,6 +484,16 @@ function captureVideo(): void { videoInputRef.value?.click(); } +function handlePhotoAction(action: MediaSelectorAddAction): void { + if (action.emit === "add-point-card") { + capturePointCard(); + return; + } + if (action.emit === "add-other") { + openPhotoPicker("OTHER"); + } +} + watch(isCustomerBound, (value) => { navBarStore.setRightDisabled(value); if (!value) { diff --git a/src/pages/product/ProductEdit.vue b/src/pages/product/ProductEdit.vue index 5cdbcf3..b105ca0 100644 --- a/src/pages/product/ProductEdit.vue +++ b/src/pages/product/ProductEdit.vue @@ -32,9 +32,9 @@ :show-viewer-actions="false" :add-actions="attachmentAddActions" @add="openAttachmentPicker('OTHER')" + @action="handleAttachmentAction" @capture-photo="capturePhoto" @capture-video="captureVideo" - @add-other="openAttachmentPicker('OTHER')" /> @@ -214,6 +214,7 @@ import MediaSelector from "@/components/mediaSelector/MediaSelector.vue"; import ProductSkuEditor from "@/pages/product/component/ProductSkuEditor.vue"; import ProductSkuUnitEditor from "@/pages/product/component/ProductSkuUnitEditor.vue"; import ProductSkuUnitBatchEditor from "@/pages/product/component/ProductSkuUnitBatchEditor.vue"; +import type { MediaSelectorAddAction } from "@/components/mediaSelector/types"; import { useNavBarStore } from "@/store/navBarStore"; import type { PhotoItem } from "@/types/Photo"; import type { Product, ProductAttachmentType, ProductCategory, ProductSku, ProductSkuUnit, ProductSpec, ProductType } from "@/types/Product"; @@ -567,6 +568,12 @@ function captureVideo(): void { videoInputRef.value?.click(); } +function handleAttachmentAction(action: MediaSelectorAddAction): void { + if (action.emit === "add-other") { + openAttachmentPicker("OTHER"); + } +} + function openCoverColorPicker(): void { coverColorDraft.value = solidColorCoverColor.value || DEFAULT_COVER_COLOR; coverColorPickerVisible.value = true; diff --git a/twa/app/src/main/res/xml/shortcuts.xml b/twa/app/src/main/res/xml/shortcuts.xml index 7f3e9c1..5effdb1 100644 --- a/twa/app/src/main/res/xml/shortcuts.xml +++ b/twa/app/src/main/res/xml/shortcuts.xml @@ -1,16 +1 @@ -