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
+52 -14
View File
@@ -79,17 +79,25 @@
</t-cell>
</t-cell-group>
<card-container v-entrance-transition>
<media-selector
class="media-selector"
:model-value="photoList"
:photo-items="photoItemList"
:show-viewer-actions="canUpdateCustomer"
:show-add="false"
:show-remove="false"
:submit="submitPhotoItems"
show-type-label
<attachment-selector
:readonly="true"
class="attachment-selector"
:items="photoItemList"
title="照片列表"
/>
>
<template #item-label="{ item }">
<span v-text="getAttachmentTypeText(item.attachType)" />
</template>
<template #viewer-actions="{ item, index, close }">
<attachment-viewer-actions
v-if="canUpdateCustomer"
:attach-type="item.attachType"
:busy="isPhotoSaving"
@change-type="changePhotoType(index, $event, close)"
@remove="removePhoto(index, close)"
/>
</template>
</attachment-selector>
</card-container>
<customer-tag-card
v-if="canReadTag"
@@ -191,7 +199,8 @@ import TagAPI from "@/api/TagAPI";
import BodyAreaSelector from "@/components/BodyAreaSelector.vue";
import CustomerRemoveDialog from "@/pages/customer/component/CustomerRemoveDialog.vue";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentViewerActions from "@/components/attachmentSelector/AttachmentViewerActions.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import TagSelector from "@/components/TagSelector.vue";
import CustomerTagCard from "@/pages/customer/component/CustomerTagCard.vue";
import type { PointAccount } from "@/types/Point";
@@ -199,7 +208,7 @@ import type { PhotoItem } from "@/types/Photo";
import type { GaoSalesOrderType } from "@/types/SalesOrder";
import type { Tag } from "@/types/Tag";
import { bodyAreaLabelMap } from "@/utils/bodyArea";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getAttachmentReadURL, getAttachmentTypeText } from "@/utils/attachment";
import { normalizeBodyAreaValue } from "@/utils/customer";
import { corePermissionCodes, permissionCodes } from "@/utils/permission";
import { LunarCalendar } from "@/utils/LunarCalendar";
@@ -275,7 +284,7 @@ const photoItemList = computed(() => (customer.value?.attachmentList || [])
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const photoList = computed(() => photoItemList.value.map(item => item.url));
const isPhotoSaving = ref(false);
async function submitPhotoItems(photoItems: PhotoItem[]): Promise<void> {
const currentCustomer = customer.value;
@@ -297,6 +306,35 @@ async function submitPhotoItems(photoItems: PhotoItem[]): Promise<void> {
};
}
async function applyPhotoItems(photoItems: PhotoItem[], close: () => void): Promise<void> {
if (isPhotoSaving.value) {
return;
}
isPhotoSaving.value = true;
try {
await submitPhotoItems(photoItems);
close();
} catch {
Message.error("媒体修改失败");
} finally {
isPhotoSaving.value = false;
}
}
async function changePhotoType(index: number, attachType: string, close: () => void): Promise<void> {
if (!photoItemList.value[index] || photoItemList.value[index].attachType === attachType) {
return;
}
await applyPhotoItems(photoItemList.value.map((item, itemIndex) => itemIndex === index ? { ...item, attachType } : item), close);
}
async function removePhoto(index: number, close: () => void): Promise<void> {
if (!photoItemList.value[index]) {
return;
}
await applyPhotoItems(photoItemList.value.filter((_, itemIndex) => itemIndex !== index), close);
}
function buildPhotoAttachmentList(photoItems: PhotoItem[]): Attachment[] {
return photoItems.flatMap(item => {
if (item.attachment) {
@@ -621,7 +659,7 @@ onUnmounted(() => clearPageNavBarRight());
}
}
:deep(.media-selector) {
:deep(.attachment-selector) {
padding: 1rem;
}
+48 -109
View File
@@ -116,21 +116,28 @@
</t-form-item>
<t-form-item label-width="0">
<div class="photo">
<media-selector
v-model="photoList"
v-model:photo-items="photoItemList"
:edit-mode="true"
:show-add="!isCustomerBound"
:show-remove="!isCustomerBound"
:show-viewer-actions="!isCustomerBound"
:add-actions="photoAddActions"
:loading="isPhotoUploading"
show-type-label
@add="openPhotoPicker('OTHER')"
@action="handlePhotoAction"
@capture-photo="capturePhoto"
@capture-video="captureVideo"
/>
<attachment-selector
:readonly="!!isCustomerBound"
v-model:items="photoItemList"
:busy="isPhotoUploading"
@select-start="handlePhotoPickerStart"
@select="handlePhotoSelected($event.files)"
>
<template #capture-actions="{ capturePhoto }">
<t-button
class="add-action"
variant="text"
theme="primary"
:disabled="isPhotoUploading"
@click="handlePointCardCapture(capturePhoto)"
>
<template #icon>
<t-icon name="camera" />
</template>
拍积分卡
</t-button>
</template>
</attachment-selector>
<div class="tips orange" v-if="!hasCustomerDeletePermission">当前账户权限编辑客户需要上传照片和积分卡</div>
</div>
</t-form-item>
@@ -219,29 +226,6 @@
/>
</t-form-item>
</t-form>
<input
ref="photoInputRef"
class="file-input"
type="file"
accept="*/*"
@change="handlePhotoSelected"
>
<input
ref="photoCameraInputRef"
class="file-input"
type="file"
accept="image/*"
capture="environment"
@change="handlePhotoSelected"
>
<input
ref="videoInputRef"
class="file-input"
type="file"
accept="video/*"
capture="environment"
@change="handlePhotoSelected"
>
<customer-selector
v-if="!isCustomerBound"
v-model="introducerCustomerId"
@@ -276,8 +260,8 @@ import BodyAreaSelector from "@/components/BodyAreaSelector.vue";
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 AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { AttachmentSelectorSelection } from "@/components/attachmentSelector/types";
import TagSelector from "@/components/TagSelector.vue";
import CustomerTagCard from "@/pages/customer/component/CustomerTagCard.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
@@ -287,8 +271,7 @@ import { bodyAreaLabelMap } from "@/utils/bodyArea";
import { getAttachmentReadURL } from "@/utils/attachment";
import { normalizeBodyAreaValue } from "@/utils/customer";
import { corePermissionCodes, gaoRoleCodes, permissionCodes } from "@/utils/permission";
import { compressUploadImage } from "@/utils/imageCompression";
import { saveCapturedFilesFromInput } from "@/utils/twaBridge";
import { compressUploadImageList } from "@/utils/imageCompression";
const pageNavBarRight = reactive({
icon: "",
@@ -544,46 +527,21 @@ function confirmBodyAreaPicker(): void {
bodyAreaPickerVisible.value = false;
}
function openPhotoPicker(target: CustomerAttachmentType): void {
if (isCustomerBound.value) {
return;
function handlePhotoPickerStart(source: AttachmentSelectorSelection["source"]): void {
if (isPointCardCapture.value && source === "photo") {
photoPickerTarget.value = "POINT_CARD";
} else if (source === "photo") {
photoPickerTarget.value = "PHOTO";
} else {
photoPickerTarget.value = "OTHER";
}
photoPickerTarget.value = target;
photoInputRef.value?.click();
isPointCardCapture.value = false;
}
function capturePhoto(): void {
if (isCustomerBound.value) {
return;
}
photoPickerTarget.value = "PHOTO";
photoCameraInputRef.value?.click();
}
function capturePointCard(): void {
if (isCustomerBound.value) {
return;
}
photoPickerTarget.value = "POINT_CARD";
photoCameraInputRef.value?.click();
}
function captureVideo(): void {
if (isCustomerBound.value) {
return;
}
photoPickerTarget.value = "OTHER";
videoInputRef.value?.click();
}
function handlePhotoAction(action: MediaSelectorAddAction): void {
if (action.emit === "add-point-card") {
capturePointCard();
return;
}
if (action.emit === "add-other") {
openPhotoPicker("OTHER");
}
function handlePointCardCapture(capturePhoto: () => void): void {
isPointCardCapture.value = true;
capturePhoto();
isPointCardCapture.value = false;
}
watch(isCustomerBound, (value) => {
@@ -675,29 +633,10 @@ watch(() => formData.birthdate, (value) => {
// ---------- 照片 ----------
const photoInputRef = ref<HTMLInputElement>();
const photoCameraInputRef = ref<HTMLInputElement>();
const videoInputRef = ref<HTMLInputElement>();
const photoAddActions = [
{
icon: "cardmembership",
text: "拍积分卡",
emit: "add-point-card",
theme: "primary"
}
] as const;
const isPointCardCapture = ref(false);
const photoPickerTarget = ref<CustomerAttachmentType>("PHOTO");
const isPhotoUploading = ref(false);
const photoItemList = ref<EditableCustomerPhoto[]>([]);
const photoList = computed<string[]>({
get() {
return photoItemList.value.map(item => item.url);
},
set(value) {
const urlSet = new Set(value);
photoItemList.value = photoItemList.value.filter(item => urlSet.has(item.url));
}
});
function normalizeAttachmentType(attachType?: string): CustomerAttachmentType {
if (attachType === "POINT_CARD" || attachType === "OTHER") {
@@ -724,28 +663,26 @@ function validateCustomerPhotoList(): boolean {
return true;
}
async function handlePhotoSelected(event: Event): Promise<void> {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
if (!file) {
async function handlePhotoSelected(files: File[]): Promise<void> {
if (!files.length) {
return;
}
saveCapturedFilesFromInput(input, [file]);
isPhotoUploading.value = true;
try {
const compressedFile = await compressUploadImage(file);
const [tempFile] = await AttachmentAPI.upload(compressedFile);
if (tempFile?.id) {
const tempFileList = await AttachmentAPI.upload(await compressUploadImageList(files));
for (const [index, tempFile] of tempFileList.entries()) {
if (!tempFile.id) {
continue;
}
photoItemList.value.push({
attachType: photoPickerTarget.value,
mimeType: file.type,
mimeType: files[index]?.type,
tempFileId: tempFile.id,
url: AttachmentAPI.getTempReadURL(tempFile.id)
});
}
} finally {
isPhotoUploading.value = false;
input.value = "";
}
}
@@ -919,6 +856,8 @@ function buildAttachmentList(): Attachment[] {
.photo {
width: 100%;
.tips {
font-size: .875rem;
text-align: center;
+46 -11
View File
@@ -110,15 +110,21 @@
核销登记记录
</t-button>
<div v-if="record" class="photo-wrapper" v-entrance-transition>
<media-selector
:model-value="recordPhotoList"
:photo-items="recordPhotoItemList"
:show-viewer-actions="canUpdateRecord"
:show-add="false"
:show-remove="false"
:submit="submitPhotoItems"
<attachment-selector
:readonly="true"
:items="recordPhotoItemList"
title="登记照片"
/>
>
<template #viewer-actions="{ item, index, close }">
<attachment-viewer-actions
v-if="canUpdateRecord"
:attach-type="item.attachType"
:busy="isPhotoSaving"
@change-type="changePhotoType(index, $event, close)"
@remove="removePhoto(index, close)"
/>
</template>
</attachment-selector>
</div>
<t-button
v-if="record && canDeleteRecord"
@@ -149,7 +155,8 @@ import EventRecordAPI from "@/api/EventRecordAPI";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import EventOptionSelector from "@/components/EventOptionSelector.vue";
import EventRecordVerifyDialog from "@/components/EventRecordVerifyDialog.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentViewerActions from "@/components/attachmentSelector/AttachmentViewerActions.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { PhotoItem } from "@/types/Photo";
import type { PointLedgerChangeType } from "@/types/Point";
import { getAttachmentReadURL } from "@/utils/attachment";
@@ -207,6 +214,7 @@ const record = ref<EventRecord>();
const isLoading = ref(false);
const isVerifying = ref(false);
const isDeleting = ref(false);
const isPhotoSaving = ref(false);
const verifyDialogVisible = ref(false);
const isRetiredRecord = computed(() => isRetiredEvent(record.value?.event));
@@ -222,8 +230,6 @@ const recordPhotoItemList = computed(() => (record.value?.attachmentList || [])
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 64)
})));
const recordPhotoList = computed(() => recordPhotoItemList.value.map(item => item.url));
async function submitPhotoItems(photoItems: PhotoItem[]): Promise<void> {
const currentRecord = record.value;
if (!currentRecord?.id || isRetiredRecord.value) {
@@ -242,6 +248,35 @@ async function submitPhotoItems(photoItems: PhotoItem[]): Promise<void> {
};
}
async function applyPhotoItems(photoItems: PhotoItem[], close: () => void): Promise<void> {
if (isPhotoSaving.value) {
return;
}
isPhotoSaving.value = true;
try {
await submitPhotoItems(photoItems);
close();
} catch (error) {
Message.error(getErrorMessage(error, "登记照片修改失败"));
} finally {
isPhotoSaving.value = false;
}
}
async function changePhotoType(index: number, attachType: string, close: () => void): Promise<void> {
if (!recordPhotoItemList.value[index] || recordPhotoItemList.value[index].attachType === attachType) {
return;
}
await applyPhotoItems(recordPhotoItemList.value.map((item, itemIndex) => itemIndex === index ? { ...item, attachType } : item), close);
}
async function removePhoto(index: number, close: () => void): Promise<void> {
if (!recordPhotoItemList.value[index]) {
return;
}
await applyPhotoItems(recordPhotoItemList.value.filter((_, itemIndex) => itemIndex !== index), close);
}
function buildPhotoAttachmentList(photoItems: PhotoItem[]): Attachment[] {
return photoItems.flatMap(item => {
if (item.attachment) {
+5 -40
View File
@@ -155,16 +155,12 @@
</t-form-item>
<div class="photo-part">
<media-selector
<attachment-selector
title="登记事件照片"
:required="selectedRequiredPhotoEventList.length > 0"
v-model="photoList"
v-model:photo-items="photoItemList"
:edit-mode="true"
:loading="isPhotoUploading"
@add="selectPhotoFile"
@capture-photo="capturePhoto"
@capture-video="captureVideo"
v-model:items="photoItemList"
:busy="isPhotoUploading"
@select="handleRecordPhotoSelected($event.files)"
/>
</div>
</t-form>
@@ -213,30 +209,6 @@
/>
</div>
</t-popup>
<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>
<t-popup v-model="registeredAtPickerVisible" placement="bottom">
<t-date-time-picker
@@ -264,7 +236,7 @@ import CustomerList from "@/components/CustomerList.vue";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import CustomerSelector from "@/components/CustomerSelector.vue";
import EventOptionSelector from "@/components/EventOptionSelector.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import EventSelector from "@/components/EventSelector.vue";
import { useEventRecordPhoto } from "@/pages/event/component/useEventRecordPhoto";
import type { Customer } from "@/types/Customer";
@@ -581,15 +553,8 @@ function validateNumberValueList(): boolean {
// ---------- 照片 ----------
const {
recordPhotoInputRef,
recordPhotoCameraInputRef,
videoInputRef,
photoItemList,
isPhotoUploading,
photoList,
capturePhoto,
selectPhotoFile,
captureVideo,
handleRecordPhotoSelected,
setExistingPhotoList,
buildTempFileIdList,
@@ -1,45 +1,17 @@
import { computed, ref } from "vue";
import { ref } from "vue";
import { AttachmentAPI, type Attachment } from "timi-web-api";
import type { PhotoItem } from "@/types/Photo";
import { getAttachmentReadURL } from "@/utils/attachment";
import { compressUploadImageList } from "@/utils/imageCompression";
import { saveCapturedFilesFromInput } from "@/utils/twaBridge";
export function useEventRecordPhoto() {
const recordPhotoInputRef = ref<HTMLInputElement>();
const recordPhotoCameraInputRef = ref<HTMLInputElement>();
const videoInputRef = ref<HTMLInputElement>();
const photoItemList = ref<PhotoItem[]>([]);
const isPhotoUploading = ref(false);
const photoList = computed<string[]>({
get() {
return photoItemList.value.map(item => item.url);
},
set(value) {
const urlSet = new Set(value);
photoItemList.value = photoItemList.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);
isPhotoUploading.value = true;
try {
const compressedFileList = await compressUploadImageList(fileList);
@@ -56,7 +28,6 @@ export function useEventRecordPhoto() {
}
} finally {
isPhotoUploading.value = false;
input.value = "";
}
}
@@ -93,15 +64,8 @@ export function useEventRecordPhoto() {
}
return {
recordPhotoInputRef,
recordPhotoCameraInputRef,
videoInputRef,
photoItemList,
isPhotoUploading,
photoList,
capturePhoto,
selectPhotoFile,
captureVideo,
handleRecordPhotoSelected,
setExistingPhotoList,
buildTempFileIdList,
@@ -70,12 +70,8 @@
<t-cell-group title="跟进内容" theme="card" v-entrance-transition>
<div class="content bg-white" v-text="detail.content || '未填写跟进内容'" />
<div class="media-wrap bg-white">
<media-selector
:model-value="attachmentUrlList"
:photo-items="attachmentItemList"
:show-add="false"
:show-remove="false"
:show-viewer-actions="false"
<attachment-selector :readonly="true"
:items="attachmentItemList"
empty-text="暂无附件"
title="附件"
/>
@@ -133,7 +129,7 @@ import { Message } from "@/utils/message";
import { getErrorMessage } from "@/utils/error";
import FollowUpReminderAPI from "@/api/FollowUpReminderAPI";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { PhotoItem } from "@/types/Photo";
import { getAttachmentReadURL } from "@/utils/attachment";
import { corePermissionCodes, permissionCodes } from "@/utils/permission";
@@ -202,7 +198,6 @@ const attachmentItemList = computed<PhotoItem[]>(() => (detail.value?.attachment
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const attachmentUrlList = computed(() => attachmentItemList.value.map(item => item.url));
function hasChannel(channel: FollowUpReminderNotifyChannel): boolean {
const item = detail.value;
@@ -80,14 +80,10 @@
/>
</t-form-item>
<t-form-item label-width="0">
<media-selector
:model-value="photoUrlList"
v-model:photo-items="photoItems"
<attachment-selector
v-model:items="photoItems"
:upload="uploadReminderPhotoList"
:edit-mode="true"
:loading="isSaving || isUploading"
add-text="选择照片"
:show-type-label="false"
:busy="isSaving || isUploading"
title="附件照片"
/>
</t-form-item>
@@ -163,7 +159,7 @@ import FollowUpReminderAPI from "@/api/FollowUpReminderAPI";
import CustomerAPI from "@/api/CustomerAPI";
import CustomerSelector from "@/components/CustomerSelector.vue";
import ManagedUserSelector from "@/pages/followUpReminder/component/ManagedUserSelector.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import type { ManagedUser } from "@/types/ManagedUser";
import type {
@@ -252,7 +248,6 @@ const formModel = reactive({
const selectedCustomer = ref<Customer>();
const selectedResponsible = ref<ManagedUser>();
const photoItems = ref<PhotoItem[]>([]);
const photoUrlList = computed(() => photoItems.value.map(item => item.previewUrl || item.url));
const customerSelectorVisible = ref(false);
const responsibleSelectorVisible = ref(false);
const customerPickerStoreId = computed(() => formModel.storeId || currentStoreStore.currentStoreId);
@@ -159,12 +159,10 @@
<t-textarea v-model="remark" borderless autosize maxlength="500" />
</t-form-item>
<t-form-item label-width="0">
<media-selector
<attachment-selector
v-if="order"
:model-value="photoUrlList"
v-model:photo-items="photoItems"
v-model:items="photoItems"
:upload="uploadPhotoList"
:edit-mode="true"
required
title="履约凭证照片"
/>
@@ -192,7 +190,7 @@ import SalesOrderAPI from "@/api/SalesOrderAPI";
import FulfillmentAPI from "@/api/FulfillmentAPI";
import ProductAPI from "@/api/ProductAPI";
import { Time } from "timi-web";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import ProductStockPreview from "@/components/ProductStockPreview.vue";
import { useUserStore } from "timi-web-api";
@@ -277,7 +275,6 @@ const isStockChecking = ref(false);
const stockPreviewList = ref<ProductStockPreviewItem[]>([]);
let stockCheckToken = 0;
let stockPreviewTimer: number | undefined;
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const isPackage = computed(() => order.value?.orderType === "PACKAGE");
const expectedItemType = computed(() => isPackage.value ? "PACKAGE_ENTITLEMENT" : "DIRECT_PRODUCT");
const sourceItems = computed<GaoSalesOrderItem[]>(() => (order.value?.itemList || []).filter(item => item.itemType === expectedItemType.value
@@ -22,12 +22,8 @@
<t-cell v-if="fulfillment.reason" title="原因" :note="fulfillment.reason" />
<t-cell v-if="fulfillment.remark" title="备注" :note="fulfillment.remark" />
<div class="photo-wrap bg-white">
<media-selector
:model-value="fulfillmentPhotoURLList"
:photo-items="fulfillmentPhotoItems"
:show-add="false"
:show-remove="false"
:show-viewer-actions="false"
<attachment-selector :readonly="true"
:items="fulfillmentPhotoItems"
title="履约照片"
/>
</div>
@@ -134,7 +130,7 @@ import { useUserStore } from "timi-web-api";
import FulfillmentAPI from "@/api/FulfillmentAPI";
import ProductAPI from "@/api/ProductAPI";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import ProductStockPreview from "@/components/ProductStockPreview.vue";
import OrderFulfillmentRevoke from "@/pages/fulfillment/components/OrderFulfillmentRevoke.vue";
@@ -176,7 +172,6 @@ const fulfillmentPhotoItems = computed<PhotoItem[]>(() => (fulfillment.value?.at
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const fulfillmentPhotoURLList = computed(() => fulfillmentPhotoItems.value.map(item => item.url));
const isWaitingStock = computed(() => fulfillment.value?.status === "WAITING_STOCK");
const isPending = computed(() => fulfillment.value?.status === "PENDING");
const isVerified = computed(() => fulfillment.value?.status === "VERIFIED");
@@ -86,11 +86,9 @@
</template>
</t-cell>
<div class="photo-wrap bg-white">
<media-selector
:model-value="photoUrlList"
v-model:photo-items="photoItems"
<attachment-selector
v-model:items="photoItems"
:upload="uploadPhotoList"
:edit-mode="true"
required
title="履约凭证照片"
/>
@@ -134,7 +132,7 @@ import FulfillmentAPI from "@/api/FulfillmentAPI";
import ProductAPI from "@/api/ProductAPI";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import CustomerSelector from "@/components/CustomerSelector.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
import ProductStockPreview from "@/components/ProductStockPreview.vue";
import OrderFulfillmentQuickQuantity from "@/pages/fulfillment/components/OrderFulfillmentQuickQuantity.vue";
@@ -199,7 +197,6 @@ const canDirectVerify = computed(() => userStore.hasRoles(gaoRoleCodes.storeMana
&& userStore.hasPermissions(permissionCodes.orderFulfillment.create)
&& userStore.hasPermissions(permissionCodes.orderFulfillment.verify)
&& userStore.hasPermissions(permissionCodes.productStock.read));
const photoUrlList = computed(() => photoItems.value.map(item => item.previewUrl || item.url));
// ---------- SKU 选择 ----------
@@ -31,11 +31,9 @@
<t-switch v-model="returnedToStore" />
</t-form-item>
<t-form-item label-width="0">
<media-selector
:model-value="photoUrlList"
v-model:photo-items="photoItems"
<attachment-selector
v-model:items="photoItems"
:upload="uploadPhotoList"
:edit-mode="true"
required
title="冲正凭证照片"
/>
@@ -62,7 +60,7 @@
import { BottomPopup } from "timi-tdesign-mobile";
import type { Attachment } from "timi-web-api";
import FulfillmentAPI from "@/api/FulfillmentAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { OrderFulfillment } from "@/types/Fulfillment";
import type { PhotoItem } from "@/types/Photo";
import { getErrorMessage } from "@/utils/error";
@@ -90,7 +88,6 @@ const photoItems = ref<PhotoItem[]>([]);
const reasonPickerVisible = ref(false);
const reasonPickerDraft = ref<string[]>([]);
const requestNo = ref("");
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const reasonOptions = [
"客户申请撤销履约",
"履约数量填写有误",
+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 = "";
}
}
+7 -16
View File
@@ -253,20 +253,16 @@
</div>
</t-form-item>
<t-form-item v-if="(paymentVerified && parsedPaymentAmount) || (receiveFullPayment && parsedSaleAmount)" label-width="0">
<media-selector
:model-value="paymentPhotoUrlList"
v-model:photo-items="paymentPhotoItems"
<attachment-selector
v-model:items="paymentPhotoItems"
:upload="uploadPhotoList"
:edit-mode="true"
title="收款凭证照片(必要)"
/>
</t-form-item>
<t-form-item v-if="fulfillAll" label-width="0">
<media-selector
:model-value="fulfillmentPhotoUrlList"
v-model:photo-items="fulfillmentPhotoItems"
<attachment-selector
v-model:items="fulfillmentPhotoItems"
:upload="uploadPhotoList"
:edit-mode="true"
title="履约凭证照片(必要)"
/>
</t-form-item>
@@ -279,11 +275,9 @@
/>
</t-form-item>
<t-form-item label-width="0">
<media-selector
:model-value="photoUrlList"
v-model:photo-items="photoItems"
<attachment-selector
v-model:items="photoItems"
:upload="uploadPhotoList"
:edit-mode="true"
title="订单照片"
/>
</t-form-item>
@@ -383,7 +377,7 @@ import CodeScanner from "@/components/CodeScanner.vue";
import CustomerList from "@/components/CustomerList.vue";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import CustomerSelector from "@/components/CustomerSelector.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSelectFormItem from "@/components/productSelector/ProductSelectFormItem.vue";
import ProductStockPreview from "@/components/ProductStockPreview.vue";
import { usePackagePurchase } from "@/pages/package/usePackagePurchase";
@@ -599,9 +593,6 @@ const photoItems = ref<PhotoItem[]>([]);
const paymentPhotoItems = ref<PhotoItem[]>([]);
const fulfillmentPhotoItems = ref<PhotoItem[]>([]);
const paymentAmountText = ref("0");
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const paymentPhotoUrlList = computed(() => paymentPhotoItems.value.map(item => item.url));
const fulfillmentPhotoUrlList = computed(() => fulfillmentPhotoItems.value.map(item => item.url));
const receiveFullPayment = ref(false);
const fulfillAll = ref(false);
const isStockChecking = ref(false);
+3 -6
View File
@@ -117,11 +117,9 @@
</t-form-item>
</template>
<div class="photo-wrap">
<media-selector
v-model="photoUrls"
v-model:photo-items="photos"
<attachment-selector
v-model:items="photos"
:upload="uploadPhotoList"
edit-mode
required
title="兑换凭证照片"
/>
@@ -179,7 +177,7 @@ import PointAPI from "@/api/PointAPI";
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 AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { Customer } from "@/types/Customer";
import type { PhotoItem } from "@/types/Photo";
import type { PointAccount, PointRedeemSku } from "@/types/Point";
@@ -245,7 +243,6 @@ const requestNo = ref("");
const saving = ref(false);
const canReadPointAccount = computed(() => userStore.hasPermissions(permissionCodes.point.accountRead));
const canAdjust = computed(() => userStore.hasPermissions(permissionCodes.pointRedemption.pointAdjust));
const photoUrls = computed(() => photos.value.map(item => item.url));
const customerName = computed(() => customer.value?.name);
const skuName = computed(() => selectedSku.value ? `${selectedSku.value.product?.name || selectedSku.value.sku?.name || "未命名产品"} · ${selectedSku.value.unit?.name || ""}` : "");
const quantityStep = computed(() => getProductQuantityStep(selectedSku.value?.sku));
+15 -14
View File
@@ -22,11 +22,8 @@
<t-cell title="兑换时间" :note="timeText(item.redeemedAt)" />
<t-cell v-if="item.remark" title="备注" :note="item.remark" />
<div class="photo-wrap bg-white">
<media-selector
:model-value="attachmentUrls"
:show-add="false"
:show-remove="false"
:show-viewer-actions="false"
<attachment-selector :readonly="true"
:items="redemptionPhotoItems"
title="兑换凭证照片"
/>
</div>
@@ -69,11 +66,9 @@
<t-textarea v-model.trim="returnRemark" maxlength="500" autosize />
</t-form-item>
<t-form-item label-width="0">
<media-selector
v-model="returnPhotoUrls"
v-model:photo-items="returnPhotos"
<attachment-selector
v-model:items="returnPhotos"
:upload="uploadPhotoList"
edit-mode
required
title="冲正凭证照片"
/>
@@ -85,13 +80,14 @@
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import { AttachmentAPI, useUserStore } from "timi-web-api";
import { useUserStore } from "timi-web-api";
import CustomerAPI from "@/api/CustomerAPI";
import PointAPI from "@/api/PointAPI";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { Customer } from "@/types/Customer";
import type { PhotoItem } from "@/types/Photo";
import { getAttachmentReadURL } from "@/utils/attachment";
import type { PointRedemption, PointRedemptionReturn, PointRedemptionStatus } from "@/types/Point";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
@@ -114,10 +110,15 @@ const returnRemark = ref("");
const returnPhotos = ref<PhotoItem[]>([]);
const returnRequestNo = ref("");
const returning = ref(false);
const attachmentUrls = computed(() => (item.value?.attachmentList || [])
const redemptionPhotoItems = computed<PhotoItem[]>(() => (item.value?.attachmentList || [])
.filter(attachment => !!attachment.id)
.map(attachment => AttachmentAPI.getReadURL(attachment.id!)));
const returnPhotoUrls = computed(() => returnPhotos.value.map(photo => photo.url));
.map(attachment => ({
attachment,
attachType: attachment.attachType || "PHOTO",
mimeType: attachment.mimeType,
previewUrl: getAttachmentReadURL(attachment.id || ""),
url: getAttachmentReadURL(attachment.id || "", 90)
})));
const canReturn = computed(() => userStore.hasPermissions(permissionCodes.pointRedemption.return)
&& (item.value?.status === "COMPLETED" || item.value?.status === "PARTIALLY_RETURNED")
&& 0 < comparePackageQuantity(remaining(), "0"));
+7 -17
View File
@@ -61,14 +61,10 @@
<t-cell title="状态" :note="getProductStatusText(product.status)" />
<t-cell title="备注" :note="Text.display(product.remark)"></t-cell>
<t-cell>
<media-selector
:model-value="attachmentUrlList"
:photo-items="attachmentItemList"
<attachment-selector :readonly="true"
:items="attachmentItemList"
title="附件列表"
:show-add="false"
:show-remove="false"
:show-viewer-actions="false"
/>
/>
</t-cell>
</t-cell-group>
<t-cell-group theme="card" v-entrance-transition>
@@ -153,15 +149,11 @@
<t-cell v-if="selectedSku.remark" title="备注" :note="Text.display(selectedSku.remark)" />
</t-cell-group>
<div class="media-wrap">
<media-selector
<attachment-selector :readonly="true"
v-if="skuPhotoItemList.length"
:model-value="skuPhotoUrlList"
:photo-items="skuPhotoItemList"
:items="skuPhotoItemList"
title="SKU 图片"
:show-add="false"
:show-remove="false"
:show-viewer-actions="false"
/>
/>
</div>
<div class="unit">
<div class="header">
@@ -205,7 +197,7 @@ async function handlePageNavBarAction(action: NavBarAction): Promise<void> {
await action.action();
}
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
defineOptions({ name: "ProductDetail" });
@@ -225,7 +217,6 @@ const attachmentItemList = computed<PhotoItem[]>(() => (product.value?.attachmen
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const attachmentUrlList = computed(() => attachmentItemList.value.map(item => item.url));
const skuPhotoItemList = computed<PhotoItem[]>(() => (selectedSku.value?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
@@ -234,7 +225,6 @@ const skuPhotoItemList = computed<PhotoItem[]>(() => (selectedSku.value?.attachm
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const skuPhotoUrlList = computed(() => skuPhotoItemList.value.map(item => item.url));
const actionList = computed<NavBarAction[]>(() => {
const list: NavBarAction[] = [];
if (userStore.hasPermissions(permissionCodes.product.update)) {
+22 -62
View File
@@ -68,18 +68,11 @@
<t-textarea v-model="form.remark" borderless maxlength="255" autosize placeholder="可填写产品说明" />
</t-form-item>
<t-form-item label-width="0">
<media-selector
v-model="attachmentUrlList"
v-model:photo-items="attachmentItemList"
<attachment-selector
v-model:items="attachmentItemList"
title="产品公共图片及附件"
:edit-mode="true"
:loading="isAttachmentUploading"
:show-viewer-actions="false"
:add-actions="attachmentAddActions"
@add="openAttachmentPicker('OTHER')"
@action="handleAttachmentAction"
@capture-photo="capturePhoto"
@capture-video="captureVideo"
:busy="isAttachmentUploading"
@select="handleAttachmentSelected($event.files, $event.source)"
/>
</t-form-item>
<t-form-item label="纯色封面" label-width="8rem" content-align="right">
@@ -245,9 +238,6 @@
>
<t-color-picker v-if="coverColorPickerVisible" v-model="coverColorDraft" format="HEX" type="multiple" :swatch-colors="colorSwatchList" @palette-bar-change="updateCoverColorDraftFromPalette" />
</bottom-popup>
<input ref="attachmentInputRef" class="file-input" type="file" accept="*/*" @change="handleAttachmentSelected" />
<input ref="photoInputRef" class="file-input" type="file" accept="image/*" capture="environment" @change="handleAttachmentSelected" />
<input ref="videoInputRef" class="file-input" type="file" accept="video/*" capture="environment" @change="handleAttachmentSelected" />
</div>
</template>
@@ -256,21 +246,20 @@ import { BottomPopup } from "timi-tdesign-mobile";
import { DialogPlugin, type ColorObject } from "tdesign-mobile-vue";
import { type Attachment, AttachmentAPI, useUserStore } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.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 type { AttachmentSelectorSelection } from "@/components/attachmentSelector/types";
import type { Product, ProductAttachmentType, ProductCategory, ProductSku, ProductSkuUnit, ProductSpec, ProductType } from "@/types/Product";
import type { ProductAttachmentItem, ProductForm, ProductSkuForm as SkuForm, ProductSkuUnitForm as UnitForm, ProductSpecForm as SpecForm, ProductSpecValueForm as SpecValueForm } from "@/types/ProductEditor";
import { compressUploadImage } from "@/utils/imageCompression";
import { compressUploadImageList } from "@/utils/imageCompression";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getErrorMessage } from "@/utils/error";
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
import { formatProductAmount, getProductStatusText, getProductTypeText, normalizeProductQuantity, parseProductAmount } from "@/utils/product";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { saveCapturedFilesFromInput } from "@/utils/twaBridge";
const pageNavBarRight = reactive({
icon: "",
@@ -345,10 +334,6 @@ const categoryList = ref<ProductCategory[]>([]);
const typePickerVisible = ref(false);
const categoryPickerVisible = ref(false);
const statusPickerVisible = ref(false);
const attachmentInputRef = ref<HTMLInputElement>();
const photoInputRef = ref<HTMLInputElement>();
const videoInputRef = ref<HTMLInputElement>();
const attachmentPickerTarget = ref<ProductAttachmentType>("PHOTO");
const isAttachmentUploading = ref(false);
const coverColorPickerVisible = ref(false);
const coverColorDraft = ref(DEFAULT_COVER_COLOR);
@@ -364,17 +349,7 @@ const categoryOptions = computed(() => [{ label: "不设置分类", value: "" },
const statusOptions = [{ label: "启用", value: "ACTIVE" }, { label: "停用", value: "INACTIVE" }];
const colorSwatchList = ["#2F88FF", "#0EA5E9", "#10B981", "#22C55E", "#F59E0B", "#F97316", "#EF4444", "#EC4899", "#8B5CF6", "#64748B"];
const selectedCategoryName = computed(() => categoryList.value.find(item => item.id === form.categoryId)?.name || "不设置分类");
const attachmentAddActions = [
{ icon: "file-attachment", text: "其他文件", emit: "add-other", theme: "default" }
] as const;
const attachmentItemList = ref<ProductAttachmentItem[]>([]);
const attachmentUrlList = computed<string[]>({
get: () => attachmentItemList.value.map(item => item.url),
set: value => {
const urlSet = new Set(value);
attachmentItemList.value = attachmentItemList.value.filter(item => urlSet.has(item.url));
}
});
const solidColorCoverColor = computed(() => attachmentItemList.value.find(item => item.isSolidColorCover)?.solidColor || "");
const skuCombinationCount = computed(() => {
if (!form.specList.length) {
@@ -655,27 +630,6 @@ function confirmStatus(value: Array<string | number>): void {
statusPickerVisible.value = false;
}
function openAttachmentPicker(target: ProductAttachmentType): void {
attachmentPickerTarget.value = target;
attachmentInputRef.value?.click();
}
function capturePhoto(): void {
attachmentPickerTarget.value = "PHOTO";
photoInputRef.value?.click();
}
function captureVideo(): void {
attachmentPickerTarget.value = "OTHER";
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;
@@ -742,24 +696,30 @@ async function confirmCoverColorPicker(): Promise<void> {
}
}
async function handleAttachmentSelected(event: Event): Promise<void> {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
if (!file) {
async function handleAttachmentSelected(files: File[], source: AttachmentSelectorSelection["source"]): Promise<void> {
if (!files.length) {
return;
}
saveCapturedFilesFromInput(input, [file]);
const attachType: ProductAttachmentType = source === "photo" ? "PHOTO" : "OTHER";
isAttachmentUploading.value = true;
try {
const tempFile = (await AttachmentAPI.upload(await compressUploadImage(file)))[0];
if (tempFile?.id) {
attachmentItemList.value.push({ attachType: attachmentPickerTarget.value, mimeType: file.type, tempFileId: tempFile.id, url: AttachmentAPI.getTempReadURL(tempFile.id) });
const compressedFiles = await compressUploadImageList(files);
const tempFileList = await AttachmentAPI.upload(compressedFiles);
for (const [index, tempFile] of tempFileList.entries()) {
if (!tempFile.id) {
continue;
}
attachmentItemList.value.push({
attachType,
mimeType: files[index]?.type,
tempFileId: tempFile.id,
url: AttachmentAPI.getTempReadURL(tempFile.id)
});
}
} catch (error) {
Message.error(getErrorMessage(error, "产品附件上传失败"));
} finally {
isAttachmentUploading.value = false;
input.value = "";
}
}
@@ -68,15 +68,12 @@
</div>
</t-form-item>
<t-form-item label-width="0">
<media-selector
:model-value="globalAttachmentUrlList"
v-model:photo-items="productStockBatchStore.attachmentItems"
<attachment-selector
v-model:items="productStockBatchStore.attachmentItems"
:upload="uploadPhotos"
:edit-mode="true"
:loading="isSaving"
:show-remove="!isSaving"
:busy="isSaving"
title="共有入库记录(无专有记录时使用)"
@update:photo-items="invalidateRequestNo"
@update:items="invalidateRequestNo"
/>
</t-form-item>
</t-form>
@@ -160,16 +157,13 @@
</div>
</div>
</div>
<media-selector
<attachment-selector
v-if="isAttachmentVisible(item.sku.id || '')"
:model-value="getAttachmentUrlList(item.attachmentItems)"
v-model:photo-items="item.attachmentItems"
v-model:items="item.attachmentItems"
:upload="uploadPhotos"
:edit-mode="true"
title=""
:loading="isSaving"
:show-remove="!isSaving"
@update:photo-items="invalidateRequestNo"
:busy="isSaving"
@update:items="invalidateRequestNo"
/>
</div>
</t-form-item>
@@ -185,7 +179,7 @@
import { onBeforeRouteLeave } from "vue-router";
import { useUserStore } from "timi-web-api";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductAPI from "@/api/ProductAPI";
import type { ProductSkuUnit, ProductStockManualInBatchItem, ProductStockManualInBatchRequest } from "@/types/Product";
import type { PhotoItem } from "@/types/Photo";
@@ -250,7 +244,6 @@ const unitPickerVisible = ref(false);
const unitPickerSkuId = ref("");
const unitPickerDraft = ref<PickerValue[]>([]);
const quickRemarkText = "正常入库";
const globalAttachmentUrlList = computed(() => productStockBatchStore.attachmentItems.map(item => item.url));
const unitPickerOptions = computed(() => {
const item = productStockBatchStore.selectedItemList.find(candidate => candidate.sku.id === unitPickerSkuId.value);
return getSelectableUnits(item).map(unit => ({ label: unit.name || "未命名单位", value: unit.id || "" }));
@@ -276,10 +269,6 @@ function isDefaultSku(item: ProductStockBatchSelection): boolean {
return !item.sku.specValueIdList?.length;
}
function getAttachmentUrlList(itemList: PhotoItem[]): string[] {
return itemList.map(item => item.url);
}
function getAttachmentList(itemList: PhotoItem[]): NonNullable<ProductStockManualInBatchItem["attachmentList"]> {
return itemList.flatMap(item => item.tempFileId ? [{
tempFileId: item.tempFileId,
+5 -13
View File
@@ -90,12 +90,8 @@
<span></span>
</template>
<template #description>
<media-selector
:model-value="photoURLList"
:photo-items="photoItemList"
:show-add="false"
:show-remove="false"
:show-viewer-actions="false"
<attachment-selector :readonly="true"
:items="photoItemList"
title="操作照片"
/>
</template>
@@ -126,11 +122,9 @@
<t-textarea v-model="revokeRemark" borderless autosize maxlength="500" placeholder="请输入冲正备注" />
</t-form-item>
</t-form>
<media-selector
:model-value="revokePhotoUrlList"
v-model:photo-items="revokePhotoItems"
<attachment-selector
v-model:items="revokePhotoItems"
:upload="uploadPhotoList"
:edit-mode="true"
required
title="冲正凭证照片"
/>
@@ -144,7 +138,7 @@ import { BottomPopup } from "timi-tdesign-mobile";
import { TimeLabel } from "timi-web";
import { useUserStore, type Attachment } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import type { StockBizType, StockRecord } from "@/types/Product";
import { getAttachmentReadURL } from "@/utils/attachment";
@@ -170,7 +164,6 @@ const revokeVisible = ref(false);
const revokeRemark = ref("");
const revokeRequestNo = ref("");
const revokePhotoItems = ref<PhotoItem[]>([]);
const revokePhotoUrlList = computed(() => revokePhotoItems.value.map(item => item.url));
const canManualRevoke = computed(() => {
const operationType = record.value?.operationType;
return (operationType === "MANUAL_IN" || operationType === "MANUAL_OUT")
@@ -188,7 +181,6 @@ const photoItemList = computed<PhotoItem[]>(() => (record.value?.attachmentList
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 128)
})));
const photoURLList = computed(() => photoItemList.value.map(item => item.url));
function getOperationTheme(value?: number | string): "success" | "danger" | "default" {
const amount = Number(value || 0);
@@ -77,11 +77,9 @@
<t-input v-model.trim="sku.remark" borderless maxlength="255" placeholder="选填" />
</t-form-item>
<div class="photo-wrap">
<media-selector
:model-value="photoUrlList"
v-model:photo-items="sku.photoItemList"
<attachment-selector
v-model:items="sku.photoItemList"
title="SKU 图片(选填)"
:edit-mode="true"
:viewer-z-index="skuEditorZIndex + 1"
:upload="uploadPhotoList"
/>
@@ -110,7 +108,7 @@
import { BottomPopup } from "timi-tdesign-mobile";
import type { ProductType } from "@/types/Product";
import type { ProductSkuForm, ProductSpecForm } from "@/types/ProductEditor";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuUnitList from "@/pages/product/component/ProductSkuUnitList.vue";
import { uploadPhotoList } from "@/utils/photo";
@@ -130,7 +128,6 @@ const emit = defineEmits<{
const editorVisible = ref(false);
const skuEditorZIndex = 12000;
const photoUrlList = computed(() => sku.value.photoItemList.map(item => item.url));
const skuTitle = computed(() => sku.value.name?.trim() || sku.value.specSummary?.trim() || (props.specList.length ? `SKU 明细 ${props.skuIndex + 1}` : "默认 SKU"));
function openEditor(): void {
@@ -60,11 +60,9 @@
</div>
</t-form-item>
<t-form-item label-width="0">
<media-selector
:model-value="photoUrlList"
v-model:photo-items="photoItems"
<attachment-selector
v-model:items="photoItems"
:upload="uploadPhotoList"
:edit-mode="true"
title="操作照片"
required
/>
@@ -99,7 +97,7 @@ import { watch } from "vue";
import { BottomPopup } from "timi-tdesign-mobile";
import { Time } from "timi-web";
import ProductAPI from "@/api/ProductAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type {
Product,
ProductSku,
@@ -137,7 +135,6 @@ const occurredAtText = ref("");
const occurredAtDraftText = ref("");
const occurredAtPickerVisible = ref(false);
const photoItems = ref<PhotoItem[]>([]);
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const selectedUnitId = ref("");
const unitPickerVisible = ref(false);
const unitDraft = ref<PickerValue[]>([]);
+4 -9
View File
@@ -49,14 +49,10 @@
@click="toSalesOrder"
/>
<div class="photo-wrap bg-white">
<media-selector
:model-value="photoURLList"
:photo-items="photoItems"
<attachment-selector :readonly="true"
:items="photoItems"
title="业务照片"
:show-add="false"
:show-remove="false"
:show-viewer-actions="false"
/>
/>
</div>
</t-cell-group>
<t-cell-group theme="card" v-entrance-transition>
@@ -131,7 +127,7 @@ import { DialogPlugin } from "tdesign-mobile-vue";
import { TimeLabel, Text } from "timi-web";
import { useUserStore } from "timi-web-api";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { PhotoItem } from "@/types/Photo";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getErrorMessage } from "@/utils/error";
@@ -243,7 +239,6 @@ const photoItems = computed<PhotoItem[]>(() => (record.value?.attachmentList ||
attachType: item.attachType || "PHOTO",
url: getAttachmentReadURL(item.id || "")
})));
const photoURLList = computed(() => photoItems.value.map(item => item.url));
// ---------- 收款操作 ----------
+3 -6
View File
@@ -109,12 +109,10 @@
/>
</t-form-item>
<div class="photo-wrap">
<media-selector
<attachment-selector
v-if="record"
:model-value="photoUrlList"
v-model:photo-items="photoItems"
v-model:items="photoItems"
:upload="uploadPhotoList"
:edit-mode="true"
required
title="冲正凭证照片"
/>
@@ -150,7 +148,7 @@
import { Time } from "timi-web";
import { useUserStore, type Attachment } from "timi-web-api";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import type { PhotoItem } from "@/types/Photo";
import { createPackageRequestNo, formatPackageAmount } from "@/utils/package";
import { getFundOperationText, getFundStatusText } from "@/utils/salesOrder";
@@ -210,7 +208,6 @@ const photoItems = ref<PhotoItem[]>([]);
const isLoading = ref(false);
const isSaving = ref(false);
const requestNo = ref("");
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const canReadSalesOrder = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.read));
const reasonOptions = [
"客户申请撤销本次资金操作",
+6 -13
View File
@@ -182,20 +182,16 @@
</div>
</t-form-item>
<t-form-item v-if="(paymentVerified && paymentAmount) || (receiveFullPayment && totalAmount)" label-width="0">
<media-selector
:model-value="paymentPhotoUrlList"
v-model:photo-items="paymentPhotoItems"
<attachment-selector
v-model:items="paymentPhotoItems"
:upload="uploadPhotoList"
:edit-mode="true"
title="收款凭证照片(必要)"
/>
</t-form-item>
<t-form-item v-if="fulfillAll" label-width="0">
<media-selector
:model-value="fulfillmentPhotoUrlList"
v-model:photo-items="fulfillmentPhotoItems"
<attachment-selector
v-model:items="fulfillmentPhotoItems"
:upload="uploadPhotoList"
:edit-mode="true"
title="履约凭证照片(必要)"
/>
</t-form-item>
@@ -203,7 +199,7 @@
<t-textarea v-model="remark" class="textarea" borderless autosize maxlength="500" placeholder="记录本单需要注意的内容" />
</t-form-item>
<div class="photo-part">
<media-selector :model-value="photoUrlList" v-model:photo-items="photoItems" :upload="uploadPhotoList" :edit-mode="true" title="订单照片(选填)" />
<attachment-selector v-model:items="photoItems" :upload="uploadPhotoList" title="订单照片(选填)" />
</div>
</t-form>
<div class="submit-wrap glass-white bg-white">
@@ -243,7 +239,7 @@ import SalesOrderAPI from "@/api/SalesOrderAPI";
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 AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSelectFormItem from "@/components/productSelector/ProductSelectFormItem.vue";
import ProductStockPreview from "@/components/ProductStockPreview.vue";
import type { Customer } from "@/types/Customer";
@@ -281,9 +277,6 @@ const photoItems = ref<PhotoItem[]>([]);
const paymentPhotoItems = ref<PhotoItem[]>([]);
const fulfillmentPhotoItems = ref<PhotoItem[]>([]);
const paymentAmountText = ref("0");
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const paymentPhotoUrlList = computed(() => paymentPhotoItems.value.map(item => item.url));
const fulfillmentPhotoUrlList = computed(() => fulfillmentPhotoItems.value.map(item => item.url));
const receiveFullPayment = ref(false);
const fulfillAll = ref(false);
const isStockChecking = ref(false);
+3 -9
View File
@@ -42,13 +42,8 @@
</t-form-item>
<t-form-item label-width="0">
<div class="photo-wrap" v-entrance-transition>
<media-selector
:model-value="photoURLList"
v-model:photo-items="photoItems"
:edit-mode="isEditing"
:show-add="isEditing"
:show-remove="isEditing"
:show-viewer-actions="isEditing"
<attachment-selector :readonly="!isEditing"
v-model:items="photoItems"
:upload="isEditing ? uploadPhotoList : undefined"
title="订单照片"
/>
@@ -237,7 +232,7 @@ import { type Attachment, useUserStore } from "timi-web-api";
import FulfillmentAPI from "@/api/FulfillmentAPI";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import type { PhotoItem } from "@/types/Photo";
import { convertPackageQuantity, formatPackageAmount, getPackageQuantityText } from "@/utils/package";
@@ -278,7 +273,6 @@ const canRefund = computed(() => !!order.value && order.value.status === "CANCEL
const canConfirmNoRefund = computed(() => !!order.value && order.value.status === "CANCELLED" && order.value.refundStatus === "PENDING" && userStore.hasPermissions(permissionCodes.fund.refund));
const canCancel = computed(() => !!order.value && order.value.status === "ACTIVE" && !hasPendingFulfillment.value && userStore.hasPermissions(permissionCodes.salesOrder.cancel));
const canFulfillByPayment = computed(() => order.value?.paymentStatus === "PAID" || userStore.hasRoles(gaoRoleCodes.storeManager));
const photoURLList = computed(() => photoItems.value.map(item => item.url));
function toPhotoItems(attachmentList?: readonly Partial<Attachment>[]): PhotoItem[] {
return (attachmentList || [])
+3 -6
View File
@@ -117,13 +117,11 @@
/>
</t-form-item>
<t-form-item label-width="0">
<media-selector
<attachment-selector
v-if="order"
:model-value="photoUrlList"
v-model:photo-items="photoItems"
v-model:items="photoItems"
class="photo-field"
:upload="uploadPhotoList"
:edit-mode="true"
required
title="收款凭证照片"
/>
@@ -139,7 +137,7 @@
<script setup lang="ts">
import { useUserStore, type Attachment } from "timi-web-api";
import { Time } from "timi-web";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import type { PhotoItem } from "@/types/Photo";
import { createPackageRequestNo, formatPackageAmount, formatPackageAmountInput, parsePackageAmount } from "@/utils/package";
@@ -195,7 +193,6 @@ const draftTime = ref("");
const pickerVisible = ref(false);
const remark = ref("");
const photoItems = ref<PhotoItem[]>([]);
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const requestNo = ref("");
const directVerify = ref(false);
const canDirectVerify = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager)
+3 -6
View File
@@ -120,13 +120,11 @@
/>
</t-form-item>
<t-form-item label-width="0">
<media-selector
<attachment-selector
v-if="order"
:model-value="photoUrlList"
v-model:photo-items="photoItems"
v-model:items="photoItems"
class="photo-field"
:upload="uploadPhotoList"
:edit-mode="true"
required
title="退款凭证照片"
/>
@@ -161,7 +159,7 @@
<script setup lang="ts">
import { Time } from "timi-web";
import { useUserStore, type Attachment } from "timi-web-api";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import SalesOrderAPI from "@/api/SalesOrderAPI";
import type { PhotoItem } from "@/types/Photo";
import { createPackageRequestNo, formatPackageAmount, formatPackageAmountInput, parsePackageAmount } from "@/utils/package";
@@ -221,7 +219,6 @@ const refundReasonPickerDraft = ref<string[]>([]);
const refundReasonPickerVisible = ref(false);
const remark = ref("");
const photoItems = ref<PhotoItem[]>([]);
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
const requestNo = ref("");
const refundableAmount = computed(() => (order.value?.paidAmount || 0) - (order.value?.refundedAmount || 0));
const refundReasonOptions = [
+3 -9
View File
@@ -57,13 +57,8 @@
/>
</header>
<div v-if="additionalPhotoItemList.length" class="additional-photos-wrapper">
<media-selector
:model-value="additionalPhotoList"
:photo-items="additionalPhotoItemList"
:show-add="false"
:show-remove="false"
:show-type-label="false"
:show-viewer-actions="false"
<attachment-selector :readonly="true"
:items="additionalPhotoItemList"
title="附加照片"
v-entrance-transition
/>
@@ -116,7 +111,7 @@ import { DialogPlugin } from "tdesign-mobile-vue";
import { TimeLabel } from "timi-web";
import { UserAPI, type Attachment, useUserStore } from "timi-web-api";
import StoreDiaryAPI from "@/api/StoreDiaryAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import type { PhotoItem } from "@/types/Photo";
import { getAttachmentReadURL } from "@/utils/attachment";
@@ -184,7 +179,6 @@ const additionalPhotoItemList = computed<PhotoItem[]>(() => (article.value?.atta
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const additionalPhotoList = computed(() => additionalPhotoItemList.value.map(item => item.url));
function resolveAttachmentUrl(attachmentId: string): string {
return getAttachmentReadURL(attachmentId);
+6 -63
View File
@@ -64,42 +64,12 @@
/>
</t-form-item>
<section class="photo-wrapper" v-entrance-transition>
<media-selector
v-model="photoList"
v-model:photo-items="photoItemList"
<attachment-selector
v-model:items="photoItemList"
title="附加照片"
:edit-mode="true"
:loading="isPhotoUploading"
:show-type-label="false"
:show-viewer-actions="false"
@add="openPhotoPicker"
@capture-photo="capturePhoto"
@capture-video="captureVideo"
:busy="isPhotoUploading"
@select="handlePhotoSelected($event.files)"
/>
<input
ref="photoInputRef"
class="file-input"
type="file"
accept="*/*"
multiple
@change="handlePhotoSelected"
>
<input
ref="photoCameraInputRef"
class="file-input"
type="file"
accept="image/*"
capture="environment"
@change="handlePhotoSelected"
>
<input
ref="videoInputRef"
class="file-input"
type="file"
accept="video/*"
capture="environment"
@change="handlePhotoSelected"
>
</section>
<section class="editor-wrapper" v-entrance-transition>
<article-editor
@@ -126,7 +96,7 @@ import {
} from "timi-tdesign-mobile";
import { AttachmentAPI, type Attachment, useUserStore } from "timi-web-api";
import StoreDiaryAPI from "@/api/StoreDiaryAPI";
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import type { PhotoItem } from "@/types/Photo";
import { getErrorMessage } from "@/utils/error";
@@ -134,7 +104,6 @@ import { compressUploadImage, compressUploadImageList } from "@/utils/imageCompr
import { getAttachmentReadURL } from "@/utils/attachment";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { saveCapturedFilesFromInput } from "@/utils/twaBridge";
const pageNavBarRight = reactive({
icon: "",
@@ -236,38 +205,13 @@ function getCreateTitle(): string {
// ---------- 附加照片 ----------
const photoInputRef = ref<HTMLInputElement>();
const photoCameraInputRef = ref<HTMLInputElement>();
const videoInputRef = ref<HTMLInputElement>();
const photoItemList = ref<PhotoItem[]>([]);
const isPhotoUploading = ref(false);
const photoList = computed<string[]>({
get: () => photoItemList.value.map(item => item.url),
set: value => {
const urlSet = new Set(value);
photoItemList.value = photoItemList.value.filter(item => urlSet.has(item.url));
}
});
function openPhotoPicker(): void {
photoInputRef.value?.click();
}
function capturePhoto(): void {
photoCameraInputRef.value?.click();
}
function captureVideo(): void {
videoInputRef.value?.click();
}
async function handlePhotoSelected(event: Event): Promise<void> {
const input = event.target as HTMLInputElement;
const fileList = Array.from(input.files || []);
async function handlePhotoSelected(fileList: File[]): Promise<void> {
if (!fileList.length) {
return;
}
saveCapturedFilesFromInput(input, fileList);
isPhotoUploading.value = true;
try {
@@ -287,7 +231,6 @@ async function handlePhotoSelected(event: Event): Promise<void> {
Message.error(getErrorMessage(error, "附加照片上传失败"));
} finally {
isPhotoUploading.value = false;
input.value = "";
}
}