upper attachment-selector to lib

This commit is contained in:
Timi
2026-10-21 16:24:00 +08:00
parent e40c912dd9
commit c870bcdd39
43 changed files with 678 additions and 1663 deletions
+6 -63
View File
@@ -82,16 +82,12 @@
</t-form-item>
</t-form>
<div v-if="showRecordPhotoInput" class="input-form photo-form content-margin">
<media-selector
<attachment-selector
title="登记事件照片"
:required="selectedRequiredPhotoEventList.length > 0"
v-model="recordPhotoList"
v-model:photo-items="recordPhotoItemList"
:edit-mode="true"
:loading="recordPhotoUploading"
@add="selectPhotoFile"
@capture-photo="capturePhoto"
@capture-video="captureVideo"
v-model:items="recordPhotoItemList"
:busy="recordPhotoUploading"
@select="handleRecordPhotoSelected($event.files)"
/>
</div>
<t-cell-group
@@ -120,30 +116,6 @@
</template>
</t-cell>
</t-cell-group>
<input
ref="recordPhotoInputRef"
class="file-input"
type="file"
accept="*/*"
multiple
@change="handleRecordPhotoSelected"
>
<input
ref="recordPhotoCameraInputRef"
class="file-input"
type="file"
accept="image/*"
capture="environment"
@change="handleRecordPhotoSelected"
>
<input
ref="videoInputRef"
class="file-input"
type="file"
accept="video/*"
capture="environment"
@change="handleRecordPhotoSelected"
>
</div>
<bottom-popup
v-model="eventPopupVisible"
@@ -178,7 +150,7 @@ import EventRecordAPI from "@/api/EventRecordAPI";
import CodeScanner from "@/components/CodeScanner.vue";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import EventOptionSelector from "@/components/EventOptionSelector.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import { useSettingStore } from "@/store/settingStore";
import type { Customer } from "@/types/Customer";
import type { EventItem, EventOptionSelectionMap } from "@/types/EventItem";
@@ -190,7 +162,6 @@ import { resolveSelectedOptionGroupList, validateEventOptionSelection } from "@/
import { permissionCodes } from "@/utils/permission";
import { getEventRecordPhotoURL, hasPhotoAttachment } from "@/utils/eventRecord";
import { compressUploadImageList } from "@/utils/imageCompression";
import { saveCapturedFilesFromInput } from "@/utils/twaBridge";
import { Storage, Time } from "timi-web";
import { type Attachment, AttachmentAPI } from "timi-web-api";
import EventSelector from "@/components/EventSelector.vue";
@@ -423,41 +394,14 @@ function validateNumberValueList(): boolean {
// ---------- 照片 ----------
const recordPhotoInputRef = ref<HTMLInputElement>();
const recordPhotoCameraInputRef = ref<HTMLInputElement>();
const videoInputRef = ref<HTMLInputElement>();
const recordPhotoItemList = ref<PhotoItem[]>([]);
const recordPhotoUploading = ref(false);
const showRecordPhotoInput = computed(() => selectedRequiredPhotoEventList.value.length > 0 || recordPhotoItemList.value.length > 0);
const recordPhotoList = computed<string[]>({
get() {
return recordPhotoItemList.value.map(item => item.url);
},
set(value) {
const urlSet = new Set(value);
recordPhotoItemList.value = recordPhotoItemList.value.filter(item => urlSet.has(item.url));
}
});
function capturePhoto(): void {
recordPhotoCameraInputRef.value?.click();
}
function selectPhotoFile(): void {
recordPhotoInputRef.value?.click();
}
function captureVideo(): void {
videoInputRef.value?.click();
}
async function handleRecordPhotoSelected(event: Event): Promise<void> {
const input = event.target as HTMLInputElement;
const fileList = Array.from(input.files || []);
async function handleRecordPhotoSelected(fileList: File[]): Promise<void> {
if (!fileList.length) {
return;
}
saveCapturedFilesFromInput(input, fileList);
recordPhotoUploading.value = true;
try {
const compressedFileList = await compressUploadImageList(fileList);
@@ -475,7 +419,6 @@ async function handleRecordPhotoSelected(event: Event): Promise<void> {
}
} finally {
recordPhotoUploading.value = false;
input.value = "";
}
}