From cafd74193fbad8b32e579a6c81187e247a51f6fe Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 16 May 2023 10:12:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E5=8A=A8copyValueToTarget?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=88=B0utils/index=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 43e541f9449e3474379b8bd7903666f783454963) --- src/utils/index.ts | 18 ++++++++++++++++++ src/utils/object.ts | 18 ------------------ .../product/spu/components/BasicInfoForm.vue | 9 +++++---- .../product/spu/components/DescriptionForm.vue | 2 +- .../spu/components/OtherSettingsForm.vue | 3 ++- .../mall/product/spu/components/SkuList.vue | 4 ++-- 6 files changed, 28 insertions(+), 26 deletions(-) delete mode 100644 src/utils/object.ts diff --git a/src/utils/index.ts b/src/utils/index.ts index e016c1e2..d74bbe99 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -155,3 +155,21 @@ export const fileSizeFormatter = (row, column, cellValue) => { const sizeStr = size.toFixed(2) //保留的小数位数 return sizeStr + ' ' + unitArr[index] } + +/** + * 将值复制到目标对象,且以目标对象属性为准,例:target: {a:1} source:{a:2,b:3} 结果为:{a:2} + * @param target 目标对象 + * @param source 源对象 + */ +export const copyValueToTarget = (target, source) => { + const newObj = Object.assign({}, target, source) + // 删除多余属性 + Object.keys(newObj).forEach((key) => { + // 如果不是target中的属性则删除 + if (Object.keys(target).indexOf(key) === -1) { + delete newObj[key] + } + }) + // 更新目标对象值 + Object.assign(target, newObj) +} diff --git a/src/utils/object.ts b/src/utils/object.ts deleted file mode 100644 index 6612da74..00000000 --- a/src/utils/object.ts +++ /dev/null @@ -1,18 +0,0 @@ -// TODO @puhui999:这个方法,可以考虑放到 index.js -/** - * 将值复制到目标对象,且以目标对象属性为准,例:target: {a:1} source:{a:2,b:3} 结果为:{a:2} - * @param target 目标对象 - * @param source 源对象 - */ -export const copyValueToTarget = (target, source) => { - const newObj = Object.assign({}, target, source) - // 删除多余属性 - Object.keys(newObj).forEach((key) => { - // 如果不是target中的属性则删除 - if (Object.keys(target).indexOf(key) === -1) { - delete newObj[key] - } - }) - // 更新目标对象值 - Object.assign(target, newObj) -} diff --git a/src/views/mall/product/spu/components/BasicInfoForm.vue b/src/views/mall/product/spu/components/BasicInfoForm.vue index 249a3830..222623a5 100644 --- a/src/views/mall/product/spu/components/BasicInfoForm.vue +++ b/src/views/mall/product/spu/components/BasicInfoForm.vue @@ -14,9 +14,9 @@ :data="categoryList" :props="defaultProps" check-strictly + class="w-1/1" node-key="id" placeholder="请选择商品分类" - class="w-1/1" /> @@ -27,7 +27,7 @@ - + - + @@ -112,10 +112,11 @@ import { defaultProps, handleTree } from '@/utils/tree' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import type { SpuType } from '@/api/mall/product/management/type/spuType' import { UploadImg, UploadImgs } from '@/components/UploadFile' -import { copyValueToTarget } from '@/utils/object' +import { copyValueToTarget } from '@/utils' import { ProductAttributes, ProductAttributesAddForm, SkuList } from './index' import * as ProductCategoryApi from '@/api/mall/product/category' import { propTypes } from '@/utils/propTypes' + const message = useMessage() // 消息弹窗 const props = defineProps({ diff --git a/src/views/mall/product/spu/components/DescriptionForm.vue b/src/views/mall/product/spu/components/DescriptionForm.vue index 0a7f522b..2a32e1af 100644 --- a/src/views/mall/product/spu/components/DescriptionForm.vue +++ b/src/views/mall/product/spu/components/DescriptionForm.vue @@ -10,7 +10,7 @@ import type { SpuType } from '@/api/mall/product/management/type/spuType' import { Editor } from '@/components/Editor' import { PropType } from 'vue' -import { copyValueToTarget } from '@/utils/object' +import { copyValueToTarget } from '@/utils' import { propTypes } from '@/utils/propTypes' const message = useMessage() // 消息弹窗 diff --git a/src/views/mall/product/spu/components/OtherSettingsForm.vue b/src/views/mall/product/spu/components/OtherSettingsForm.vue index c0fc5122..fb4facd7 100644 --- a/src/views/mall/product/spu/components/OtherSettingsForm.vue +++ b/src/views/mall/product/spu/components/OtherSettingsForm.vue @@ -53,8 +53,9 @@