fix: 商品详情替换为下划线
This commit is contained in:
parent
954a9d49f0
commit
76fce7bb8b
@ -96,8 +96,8 @@ export const handleGetNewSkuList = (data: any) => {
|
||||
item.vvSkuPropertyValueList.forEach((child: any, index: number) => {
|
||||
child.categoryPropertyName = child.productPropertyName
|
||||
child.categoryPropertyValue = child.productPropertyValue
|
||||
categoryPropertyNames += (index === 0 ? '' : '-') + child.categoryPropertyName
|
||||
name += (index === 0 ? '' : '-') + child.categoryPropertyValue
|
||||
categoryPropertyNames += (index === 0 ? '' : '_') + child.categoryPropertyName
|
||||
name += (index === 0 ? '' : '_') + child.categoryPropertyValue
|
||||
})
|
||||
return {
|
||||
...item,
|
||||
@ -118,17 +118,17 @@ export const sortByPrefix = <T extends { name?: string }>(arr: T[]): T[] => {
|
||||
return arr
|
||||
}
|
||||
|
||||
// 计算前缀:如果 name 包含 "-",取最后一个 "-" 之前的部分作为前缀
|
||||
// 计算前缀:如果 name 包含 "_",取最后一个 "_" 之前的部分作为前缀
|
||||
const getPrefix = (name: string): string => {
|
||||
if (!name) return ''
|
||||
|
||||
// 找到最后一个 "-" 的位置,取之前的部分作为前缀
|
||||
const lastDashIndex = name.lastIndexOf('-')
|
||||
// 找到最后一个 "_" 的位置,取之前的部分作为前缀
|
||||
const lastDashIndex = name.lastIndexOf('_')
|
||||
if (lastDashIndex > 0) {
|
||||
return name.substring(0, lastDashIndex + 1) // 包含 "-" 分隔符
|
||||
return name.substring(0, lastDashIndex + 1) // 包含 "_" 分隔符
|
||||
}
|
||||
|
||||
// 如果没有 "-",返回整个字符串
|
||||
// 如果没有 "_",返回整个字符串
|
||||
return name
|
||||
}
|
||||
|
||||
|
||||
@ -146,7 +146,7 @@
|
||||
<dd class="flex mb-2">
|
||||
<div v-for="child in item.vvPropertyValueList" :key="item.id + '-' + child.id">
|
||||
<el-input
|
||||
v-if="curPropertyValueId === item.id + '-' + child.id"
|
||||
v-if="curPropertyValueId === item.id + '_' + child.id"
|
||||
ref="editPropertyValueInputRef"
|
||||
class="w-20"
|
||||
size="small"
|
||||
|
||||
@ -39,12 +39,12 @@ const handleEditSkuListPropertyName = (
|
||||
) => {
|
||||
skuList.forEach((item: any) => {
|
||||
const index = (item.categoryPropertyNames || '')
|
||||
.split('-')
|
||||
.split('_')
|
||||
.findIndex((item: string) => item === oldCategoryPropertyName)
|
||||
if (index !== -1) {
|
||||
const arr = (item.categoryPropertyNames || '').split('-')
|
||||
const arr = (item.categoryPropertyNames || '').split('_')
|
||||
arr.splice(index, 1, newCategoryPropertyName)
|
||||
item.categoryPropertyNames = arr.join('-')
|
||||
item.categoryPropertyNames = arr.join('_')
|
||||
item.vvSkuPropertyValueList.forEach((item: any) => {
|
||||
if (item.categoryPropertyName === oldCategoryPropertyName) {
|
||||
item.categoryPropertyName = newCategoryPropertyName
|
||||
@ -63,7 +63,7 @@ export const inputEditPropertyValue = ref('')
|
||||
export const editPropertyValueInputRef = ref()
|
||||
|
||||
export const onClickPropertyValue = (item: any, child: any) => {
|
||||
curPropertyValueId.value = item.id + '-' + child.id
|
||||
curPropertyValueId.value = item.id + '_' + child.id
|
||||
inputEditPropertyValue.value = child.categoryPropertyValue
|
||||
nextTick(() => {
|
||||
editPropertyValueInputRef.value[0].input!.focus()
|
||||
@ -81,6 +81,10 @@ export const onEditPropertyValue = (child: any, skuList: any, vvPropertyValueLis
|
||||
ElMessage.error('属性值已存在,请重新输入')
|
||||
return
|
||||
}
|
||||
if (inputEditPropertyValue.value.includes('_')) {
|
||||
ElMessage.error('属性值不能包含下划线')
|
||||
return
|
||||
}
|
||||
child.categoryPropertyValue = inputEditPropertyValue.value
|
||||
handleEditSkuListPropertyValue(
|
||||
child.categoryPropertyName,
|
||||
@ -102,13 +106,13 @@ const handleEditSkuListPropertyValue = (
|
||||
const newPropertyValue = inputEditPropertyValue
|
||||
skuList.forEach((item: any) => {
|
||||
const index = (item.categoryPropertyNames || '')
|
||||
.split('-')
|
||||
.split('_')
|
||||
.findIndex((item: string) => item === categoryPropertyName)
|
||||
if (index !== -1) {
|
||||
const names = (item.name || '').split('-')
|
||||
const names = (item.name || '').split('_')
|
||||
if (names[index] === oldCategoryPropertyValue) {
|
||||
names[index] = newPropertyValue
|
||||
item.name = names.join('-')
|
||||
item.name = names.join('_')
|
||||
}
|
||||
}
|
||||
item.vvSkuPropertyValueList.forEach((item: any) => {
|
||||
|
||||
@ -40,9 +40,9 @@ export const generateSkuList = (adminCategoryData: CategoryDataMock): TSkuList[]
|
||||
// 使用递归生成所有可能的组合
|
||||
const combine = (index: number, current: Option[]) => {
|
||||
if (index === optionGroups.length) {
|
||||
const serialNo = current.map((opt) => opt.id.toString()).join('-')
|
||||
const name = current.map((opt) => opt.categoryPropertyValue).join('-')
|
||||
const categoryPropertyNames = current.map((opt) => opt.categoryPropertyName).join('-')
|
||||
const serialNo = current.map((opt) => opt.id.toString()).join('_')
|
||||
const name = current.map((opt) => opt.categoryPropertyValue).join('_')
|
||||
const categoryPropertyNames = current.map((opt) => opt.categoryPropertyName).join('_')
|
||||
result.push({
|
||||
serialNo,
|
||||
name,
|
||||
@ -115,6 +115,11 @@ export const usePropertyValue = () => {
|
||||
inputValue.value = ''
|
||||
return
|
||||
}
|
||||
if (inputValue.value.includes('_')) {
|
||||
ElMessage.error('属性值不能包含下划线')
|
||||
inputValue.value = ''
|
||||
return
|
||||
}
|
||||
if (inputValue.value) {
|
||||
const id = Math.random()
|
||||
const newData = {
|
||||
@ -126,8 +131,8 @@ export const usePropertyValue = () => {
|
||||
adminCategoryData[lineIndex].vvPropertyValueList.push({ ...newData })
|
||||
if (skuList?.length && skuList[0].vvSkuPropertyValueList.length < adminCategoryData.length) {
|
||||
skuList.forEach((item: TSkuList) => {
|
||||
item.name += '-' + inputValue.value
|
||||
item.categoryPropertyNames += '-' + adminCategoryData[lineIndex].categoryPropertyName
|
||||
item.name += '_' + inputValue.value
|
||||
item.categoryPropertyNames += '_' + adminCategoryData[lineIndex].categoryPropertyName
|
||||
item.vvSkuPropertyValueList.push({ ...newData })
|
||||
})
|
||||
} else {
|
||||
@ -155,9 +160,9 @@ export const usePropertyValue = () => {
|
||||
// 使用递归生成所有可能的组合
|
||||
const combine = (index: number, current: Option[]) => {
|
||||
if (index === optionGroups.length) {
|
||||
const serialNo = current.map((opt) => opt.id.toString()).join('-')
|
||||
const name = current.map((opt) => opt.categoryPropertyValue).join('-')
|
||||
const categoryPropertyNames = current.map((opt) => opt.categoryPropertyName).join('-')
|
||||
const serialNo = current.map((opt) => opt.id.toString()).join('_')
|
||||
const name = current.map((opt) => opt.categoryPropertyValue).join('_')
|
||||
const categoryPropertyNames = current.map((opt) => opt.categoryPropertyName).join('_')
|
||||
result.push({
|
||||
serialNo,
|
||||
name,
|
||||
@ -315,11 +320,11 @@ export const generateSkuList = (categories: CategoryDataMock): TSkuList[] => {
|
||||
combos = next
|
||||
}
|
||||
|
||||
// 3) 生成目标对象:name 由 value 用 '-' 拼接;originArray 记录来源对象
|
||||
// 3) 生成目标对象:name 由 value 用 '_' 拼接;originArray 记录来源对象
|
||||
return combos.map((combo) => {
|
||||
const serialNo = combo.map((opt) => opt.id.toString()).join('-')
|
||||
const name = combo.map((opt) => String(opt.categoryPropertyValue)).join('-')
|
||||
const categoryPropertyNames = combo.map((opt) => String(opt.categoryPropertyName)).join('-')
|
||||
const serialNo = combo.map((opt) => opt.id.toString()).join('_')
|
||||
const name = combo.map((opt) => String(opt.categoryPropertyValue)).join('_')
|
||||
const categoryPropertyNames = combo.map((opt) => String(opt.categoryPropertyName)).join('_')
|
||||
const originArray = combo
|
||||
return {
|
||||
serialNo,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user