feat:【mall 商城】商品发布 - 库存价格【antd】100%: 迁移完成

pull/235/head
puhui999 2025-10-21 16:39:54 +08:00
parent 93149876e5
commit 6bbf878171
3 changed files with 36 additions and 25 deletions

View File

@ -29,7 +29,7 @@ interface Props {
isDetail?: boolean;
}
const inputValue = ref(''); //
const inputValue = ref<string[]>([]); // tags 使
const attributeIndex = ref<null | number>(null); // index
//
const inputVisible = computed(() => (index: number) => {
@ -95,26 +95,29 @@ const showInput = async (index: number) => {
// success
const handleInputConfirm = async (index: number, propertyId: number) => {
if (inputValue.value) {
// tags inputValue
const currentValue = inputValue.value?.[inputValue.value.length - 1]?.trim();
if (currentValue) {
// 1.
if (
attributeList.value?.[index]?.values?.find(
(item) => item.name === inputValue.value,
(item) => item.name === currentValue,
)
) {
message.warning('已存在相同属性值,请重试');
attributeIndex.value = null;
inputValue.value = '';
inputValue.value = [];
return;
}
// 2.1 使
const existValue = attributeOptions.value.find(
(item) => item.name === inputValue.value,
(item) => item.name === currentValue,
);
if (existValue) {
attributeIndex.value = null;
inputValue.value = '';
inputValue.value = [];
attributeList.value?.[index]?.values?.push({
id: existValue.id!,
name: existValue.name,
@ -127,11 +130,11 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
try {
const id = await createPropertyValue({
propertyId,
name: inputValue.value,
name: currentValue,
});
attributeList.value?.[index]?.values?.push({
id,
name: inputValue.value,
name: currentValue,
});
message.success($t('common.createSuccess'));
emit('success', attributeList.value);
@ -140,7 +143,7 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
}
}
attributeIndex.value = null;
inputValue.value = '';
inputValue.value = [];
};
/** 获取商品属性下拉选项 */
@ -179,11 +182,11 @@ const getAttributeOptions = async (propertyId: number) => {
:ref="setInputRef"
v-model:value="inputValue"
allow-clear
class="!w-30"
mode="tags"
:max-tag-count="1"
:filter-option="true"
size="small"
style="width: 100px"
@blur="handleInputConfirm(index, item.id)"
@change="handleInputConfirm(index, item.id)"
@keyup.enter="handleInputConfirm(index, item.id)"

View File

@ -7,7 +7,7 @@ import type { MallSpuApi } from '#/api/mall/product/spu';
import { ref, watch } from 'vue';
import { formatToFraction, isEmpty } from '@vben/utils';
import { copyValueToTarget, formatToFraction, isEmpty } from '@vben/utils';
import { Button, Image, Input, InputNumber, message } from 'ant-design-vue';
@ -59,20 +59,11 @@ const skuList = ref<MallSpuApi.Sku[]>([
},
]); //
/** 商品图预览 */
const imagePreview = (imgUrl: string) => {
// TODO @puhui999:
// createImageViewer({
// zIndex: 9_999_999,
// urlList: [imgUrl],
// });
};
/** 批量添加 */
const batchAdd = () => {
validateProperty();
formData.value!.skus!.forEach((item: MallSpuApi.Sku) => {
// copyValueToTarget(item, skuList.value[0]);
copyValueToTarget(item, skuList.value[0]);
});
};
@ -478,8 +469,7 @@ defineExpose({ generateTableData, validateSku, getSkuTableRef });
v-if="row.picUrl"
:src="row.picUrl"
class="h-[50px] w-[50px] cursor-pointer"
:preview="false"
@click="imagePreview(row.picUrl)"
:preview="true"
/>
</template>
</VxeColumn>
@ -563,8 +553,7 @@ defineExpose({ generateTableData, validateSku, getSkuTableRef });
<Image
:src="row.picUrl"
class="h-[60px] w-[60px] cursor-pointer"
:preview="false"
@click="imagePreview(row.picUrl)"
:preview="true"
/>
</template>
</VxeColumn>

View File

@ -68,3 +68,22 @@ export const getUrlValue = (
const url = new URL(decodeURIComponent(urlStr));
return url.searchParams.get(key) ?? '';
};
/**
* target: {a:1} source:{a:2,b:3} {a:2}
* @param target
* @param source
*/
export const copyValueToTarget = (target: any, source: any) => {
const newObj = Object.assign({}, target, source);
// 删除多余属性
Object.keys(newObj).forEach((key) => {
// 如果不是target中的属性则删除
if (!Object.keys(target).includes(key)) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete newObj[key];
}
});
// 更新目标对象值
Object.assign(target, newObj);
};