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
+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[]>([]);