Skip to content

Commit 43e541f

Browse files
author
puhui999
committed
fix: 移动copyValueToTarget方法到utils/index中
1 parent e92361e commit 43e541f

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

src/utils/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,21 @@ export const fileSizeFormatter = (row, column, cellValue) => {
155155
const sizeStr = size.toFixed(2) //保留的小数位数
156156
return sizeStr + ' ' + unitArr[index]
157157
}
158+
159+
/**
160+
* 将值复制到目标对象,且以目标对象属性为准,例:target: {a:1} source:{a:2,b:3} 结果为:{a:2}
161+
* @param target 目标对象
162+
* @param source 源对象
163+
*/
164+
export const copyValueToTarget = (target, source) => {
165+
const newObj = Object.assign({}, target, source)
166+
// 删除多余属性
167+
Object.keys(newObj).forEach((key) => {
168+
// 如果不是target中的属性则删除
169+
if (Object.keys(target).indexOf(key) === -1) {
170+
delete newObj[key]
171+
}
172+
})
173+
// 更新目标对象值
174+
Object.assign(target, newObj)
175+
}

src/utils/object.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/views/mall/product/spu/components/BasicInfoForm.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
:data="categoryList"
1515
:props="defaultProps"
1616
check-strictly
17+
class="w-1/1"
1718
node-key="id"
1819
placeholder="请选择商品分类"
19-
class="w-1/1"
2020
/>
2121
</el-form-item>
2222
</el-col>
@@ -27,7 +27,7 @@
2727
</el-col>
2828
<el-col :span="12">
2929
<el-form-item label="单位" prop="unit">
30-
<el-select v-model="formData.unit" placeholder="请选择单位" class="w-1/1">
30+
<el-select v-model="formData.unit" class="w-1/1" placeholder="请选择单位">
3131
<el-option
3232
v-for="dict in getIntDictOptions(DICT_TYPE.PRODUCT_UNIT)"
3333
:key="dict.value"
@@ -59,7 +59,7 @@
5959
</el-col>
6060
<el-col :span="12">
6161
<el-form-item label="运费模板" prop="deliveryTemplateId">
62-
<el-select v-model="formData.deliveryTemplateId" placeholder="请选择" class="w-1/1">
62+
<el-select v-model="formData.deliveryTemplateId" class="w-1/1" placeholder="请选择">
6363
<el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.id" />
6464
</el-select>
6565
</el-form-item>
@@ -112,10 +112,11 @@ import { defaultProps, handleTree } from '@/utils/tree'
112112
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
113113
import type { SpuType } from '@/api/mall/product/management/type/spuType'
114114
import { UploadImg, UploadImgs } from '@/components/UploadFile'
115-
import { copyValueToTarget } from '@/utils/object'
115+
import { copyValueToTarget } from '@/utils'
116116
import { ProductAttributes, ProductAttributesAddForm, SkuList } from './index'
117117
import * as ProductCategoryApi from '@/api/mall/product/category'
118118
import { propTypes } from '@/utils/propTypes'
119+
119120
const message = useMessage() // 消息弹窗
120121
121122
const props = defineProps({

src/views/mall/product/spu/components/DescriptionForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type { SpuType } from '@/api/mall/product/management/type/spuType'
1111
import { Editor } from '@/components/Editor'
1212
import { PropType } from 'vue'
13-
import { copyValueToTarget } from '@/utils/object'
13+
import { copyValueToTarget } from '@/utils'
1414
import { propTypes } from '@/utils/propTypes'
1515
1616
const message = useMessage() // 消息弹窗

src/views/mall/product/spu/components/OtherSettingsForm.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
<script lang="ts" name="OtherSettingsForm" setup>
5454
import type { SpuType } from '@/api/mall/product/management/type/spuType'
5555
import { PropType } from 'vue'
56-
import { copyValueToTarget } from '@/utils/object'
56+
import { copyValueToTarget } from '@/utils'
5757
import { propTypes } from '@/utils/propTypes'
58+
5859
const message = useMessage() // 消息弹窗
5960
6061
const props = defineProps({

src/views/mall/product/spu/components/SkuList.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</template>
2626
</el-table-column>
2727
</template>
28-
<!-- TODO @puhui999: controls-position="right" 可以去掉哈,不然太长了,手动输入更方便 -->
28+
<!-- TODO @puhui999: controls-position=" " 可以去掉哈,不然太长了,手动输入更方便 -->
2929
<el-table-column align="center" label="商品条码" min-width="168">
3030
<template #default="{ row }">
3131
<el-input v-model="row.barCode" class="w-100%" />
@@ -110,7 +110,7 @@ import { PropType } from 'vue'
110110
import { SpuType } from '@/api/mall/product/management/type/spuType'
111111
import { propTypes } from '@/utils/propTypes'
112112
import { SkuType } from '@/api/mall/product/management/type/skuType'
113-
import { copyValueToTarget } from '@/utils/object'
113+
import { copyValueToTarget } from '@/utils'
114114
115115
const props = defineProps({
116116
propFormData: {

0 commit comments

Comments
 (0)