fix: 商品详情替换为下划线

This commit is contained in:
zc 2025-11-06 23:20:55 +08:00
parent 954a9d49f0
commit 76fce7bb8b
4 changed files with 36 additions and 27 deletions

View File

@ -96,8 +96,8 @@ export const handleGetNewSkuList = (data: any) => {
item.vvSkuPropertyValueList.forEach((child: any, index: number) => { item.vvSkuPropertyValueList.forEach((child: any, index: number) => {
child.categoryPropertyName = child.productPropertyName child.categoryPropertyName = child.productPropertyName
child.categoryPropertyValue = child.productPropertyValue child.categoryPropertyValue = child.productPropertyValue
categoryPropertyNames += (index === 0 ? '' : '-') + child.categoryPropertyName categoryPropertyNames += (index === 0 ? '' : '_') + child.categoryPropertyName
name += (index === 0 ? '' : '-') + child.categoryPropertyValue name += (index === 0 ? '' : '_') + child.categoryPropertyValue
}) })
return { return {
...item, ...item,
@ -118,17 +118,17 @@ export const sortByPrefix = <T extends { name?: string }>(arr: T[]): T[] => {
return arr return arr
} }
// 计算前缀:如果 name 包含 "-",取最后一个 "-" 之前的部分作为前缀 // 计算前缀:如果 name 包含 "_",取最后一个 "_" 之前的部分作为前缀
const getPrefix = (name: string): string => { const getPrefix = (name: string): string => {
if (!name) return '' if (!name) return ''
// 找到最后一个 "-" 的位置,取之前的部分作为前缀 // 找到最后一个 "_" 的位置,取之前的部分作为前缀
const lastDashIndex = name.lastIndexOf('-') const lastDashIndex = name.lastIndexOf('_')
if (lastDashIndex > 0) { if (lastDashIndex > 0) {
return name.substring(0, lastDashIndex + 1) // 包含 "-" 分隔符 return name.substring(0, lastDashIndex + 1) // 包含 "_" 分隔符
} }
// 如果没有 "-",返回整个字符串 // 如果没有 "_",返回整个字符串
return name return name
} }

View File

@ -146,7 +146,7 @@
<dd class="flex mb-2"> <dd class="flex mb-2">
<div v-for="child in item.vvPropertyValueList" :key="item.id + '-' + child.id"> <div v-for="child in item.vvPropertyValueList" :key="item.id + '-' + child.id">
<el-input <el-input
v-if="curPropertyValueId === item.id + '-' + child.id" v-if="curPropertyValueId === item.id + '_' + child.id"
ref="editPropertyValueInputRef" ref="editPropertyValueInputRef"
class="w-20" class="w-20"
size="small" size="small"

View File

@ -39,12 +39,12 @@ const handleEditSkuListPropertyName = (
) => { ) => {
skuList.forEach((item: any) => { skuList.forEach((item: any) => {
const index = (item.categoryPropertyNames || '') const index = (item.categoryPropertyNames || '')
.split('-') .split('_')
.findIndex((item: string) => item === oldCategoryPropertyName) .findIndex((item: string) => item === oldCategoryPropertyName)
if (index !== -1) { if (index !== -1) {
const arr = (item.categoryPropertyNames || '').split('-') const arr = (item.categoryPropertyNames || '').split('_')
arr.splice(index, 1, newCategoryPropertyName) arr.splice(index, 1, newCategoryPropertyName)
item.categoryPropertyNames = arr.join('-') item.categoryPropertyNames = arr.join('_')
item.vvSkuPropertyValueList.forEach((item: any) => { item.vvSkuPropertyValueList.forEach((item: any) => {
if (item.categoryPropertyName === oldCategoryPropertyName) { if (item.categoryPropertyName === oldCategoryPropertyName) {
item.categoryPropertyName = newCategoryPropertyName item.categoryPropertyName = newCategoryPropertyName
@ -63,7 +63,7 @@ export const inputEditPropertyValue = ref('')
export const editPropertyValueInputRef = ref() export const editPropertyValueInputRef = ref()
export const onClickPropertyValue = (item: any, child: any) => { export const onClickPropertyValue = (item: any, child: any) => {
curPropertyValueId.value = item.id + '-' + child.id curPropertyValueId.value = item.id + '_' + child.id
inputEditPropertyValue.value = child.categoryPropertyValue inputEditPropertyValue.value = child.categoryPropertyValue
nextTick(() => { nextTick(() => {
editPropertyValueInputRef.value[0].input!.focus() editPropertyValueInputRef.value[0].input!.focus()
@ -81,6 +81,10 @@ export const onEditPropertyValue = (child: any, skuList: any, vvPropertyValueLis
ElMessage.error('属性值已存在,请重新输入') ElMessage.error('属性值已存在,请重新输入')
return return
} }
if (inputEditPropertyValue.value.includes('_')) {
ElMessage.error('属性值不能包含下划线')
return
}
child.categoryPropertyValue = inputEditPropertyValue.value child.categoryPropertyValue = inputEditPropertyValue.value
handleEditSkuListPropertyValue( handleEditSkuListPropertyValue(
child.categoryPropertyName, child.categoryPropertyName,
@ -102,13 +106,13 @@ const handleEditSkuListPropertyValue = (
const newPropertyValue = inputEditPropertyValue const newPropertyValue = inputEditPropertyValue
skuList.forEach((item: any) => { skuList.forEach((item: any) => {
const index = (item.categoryPropertyNames || '') const index = (item.categoryPropertyNames || '')
.split('-') .split('_')
.findIndex((item: string) => item === categoryPropertyName) .findIndex((item: string) => item === categoryPropertyName)
if (index !== -1) { if (index !== -1) {
const names = (item.name || '').split('-') const names = (item.name || '').split('_')
if (names[index] === oldCategoryPropertyValue) { if (names[index] === oldCategoryPropertyValue) {
names[index] = newPropertyValue names[index] = newPropertyValue
item.name = names.join('-') item.name = names.join('_')
} }
} }
item.vvSkuPropertyValueList.forEach((item: any) => { item.vvSkuPropertyValueList.forEach((item: any) => {

View File

@ -40,9 +40,9 @@ export const generateSkuList = (adminCategoryData: CategoryDataMock): TSkuList[]
// 使用递归生成所有可能的组合 // 使用递归生成所有可能的组合
const combine = (index: number, current: Option[]) => { const combine = (index: number, current: Option[]) => {
if (index === optionGroups.length) { if (index === optionGroups.length) {
const serialNo = current.map((opt) => opt.id.toString()).join('-') const serialNo = current.map((opt) => opt.id.toString()).join('_')
const name = current.map((opt) => opt.categoryPropertyValue).join('-') const name = current.map((opt) => opt.categoryPropertyValue).join('_')
const categoryPropertyNames = current.map((opt) => opt.categoryPropertyName).join('-') const categoryPropertyNames = current.map((opt) => opt.categoryPropertyName).join('_')
result.push({ result.push({
serialNo, serialNo,
name, name,
@ -115,6 +115,11 @@ export const usePropertyValue = () => {
inputValue.value = '' inputValue.value = ''
return return
} }
if (inputValue.value.includes('_')) {
ElMessage.error('属性值不能包含下划线')
inputValue.value = ''
return
}
if (inputValue.value) { if (inputValue.value) {
const id = Math.random() const id = Math.random()
const newData = { const newData = {
@ -126,8 +131,8 @@ export const usePropertyValue = () => {
adminCategoryData[lineIndex].vvPropertyValueList.push({ ...newData }) adminCategoryData[lineIndex].vvPropertyValueList.push({ ...newData })
if (skuList?.length && skuList[0].vvSkuPropertyValueList.length < adminCategoryData.length) { if (skuList?.length && skuList[0].vvSkuPropertyValueList.length < adminCategoryData.length) {
skuList.forEach((item: TSkuList) => { skuList.forEach((item: TSkuList) => {
item.name += '-' + inputValue.value item.name += '_' + inputValue.value
item.categoryPropertyNames += '-' + adminCategoryData[lineIndex].categoryPropertyName item.categoryPropertyNames += '_' + adminCategoryData[lineIndex].categoryPropertyName
item.vvSkuPropertyValueList.push({ ...newData }) item.vvSkuPropertyValueList.push({ ...newData })
}) })
} else { } else {
@ -155,9 +160,9 @@ export const usePropertyValue = () => {
// 使用递归生成所有可能的组合 // 使用递归生成所有可能的组合
const combine = (index: number, current: Option[]) => { const combine = (index: number, current: Option[]) => {
if (index === optionGroups.length) { if (index === optionGroups.length) {
const serialNo = current.map((opt) => opt.id.toString()).join('-') const serialNo = current.map((opt) => opt.id.toString()).join('_')
const name = current.map((opt) => opt.categoryPropertyValue).join('-') const name = current.map((opt) => opt.categoryPropertyValue).join('_')
const categoryPropertyNames = current.map((opt) => opt.categoryPropertyName).join('-') const categoryPropertyNames = current.map((opt) => opt.categoryPropertyName).join('_')
result.push({ result.push({
serialNo, serialNo,
name, name,
@ -315,11 +320,11 @@ export const generateSkuList = (categories: CategoryDataMock): TSkuList[] => {
combos = next combos = next
} }
// 3) 生成目标对象name 由 value 用 '-' 拼接originArray 记录来源对象 // 3) 生成目标对象name 由 value 用 '_' 拼接originArray 记录来源对象
return combos.map((combo) => { return combos.map((combo) => {
const serialNo = combo.map((opt) => opt.id.toString()).join('-') const serialNo = combo.map((opt) => opt.id.toString()).join('_')
const name = combo.map((opt) => String(opt.categoryPropertyValue)).join('-') const name = combo.map((opt) => String(opt.categoryPropertyValue)).join('_')
const categoryPropertyNames = combo.map((opt) => String(opt.categoryPropertyName)).join('-') const categoryPropertyNames = combo.map((opt) => String(opt.categoryPropertyName)).join('_')
const originArray = combo const originArray = combo
return { return {
serialNo, serialNo,