|
@@ -213,10 +213,26 @@ const baseURL = process.env.VUE_APP_BASE_API || ''
|
|
|
parseSpecs(specs) {
|
|
parseSpecs(specs) {
|
|
|
if (!specs) return '-'
|
|
if (!specs) return '-'
|
|
|
try {
|
|
try {
|
|
|
|
|
+ if (typeof specs === 'object' && Array.isArray(specs)) {
|
|
|
|
|
+ return specs.map((item) => {
|
|
|
|
|
+ if (item && typeof item === 'object') {
|
|
|
|
|
+ return (item.name || '') + ':' + (item.value !== undefined && item.value !== null ? item.value : '')
|
|
|
|
|
+ }
|
|
|
|
|
+ return String(item)
|
|
|
|
|
+ }).filter(s => s && s !== ':').join('; ')
|
|
|
|
|
+ }
|
|
|
if (typeof specs === 'object') {
|
|
if (typeof specs === 'object') {
|
|
|
return Object.entries(specs).map(([k, v]) => k + ':' + v).join('; ')
|
|
return Object.entries(specs).map(([k, v]) => k + ':' + v).join('; ')
|
|
|
}
|
|
}
|
|
|
const obj = JSON.parse(specs)
|
|
const obj = JSON.parse(specs)
|
|
|
|
|
+ if (Array.isArray(obj)) {
|
|
|
|
|
+ return obj.map((item) => {
|
|
|
|
|
+ if (item && typeof item === 'object') {
|
|
|
|
|
+ return (item.name || '') + ':' + (item.value !== undefined && item.value !== null ? item.value : '')
|
|
|
|
|
+ }
|
|
|
|
|
+ return String(item)
|
|
|
|
|
+ }).filter(s => s && s !== ':').join('; ')
|
|
|
|
|
+ }
|
|
|
if (typeof obj === 'object' && obj !== null) {
|
|
if (typeof obj === 'object' && obj !== null) {
|
|
|
return Object.entries(obj).map(([k, v]) => k + ':' + v).join('; ')
|
|
return Object.entries(obj).map(([k, v]) => k + ':' + v).join('; ')
|
|
|
}
|
|
}
|
|
@@ -227,7 +243,7 @@ const baseURL = process.env.VUE_APP_BASE_API || ''
|
|
|
},
|
|
},
|
|
|
formatSpecsForInput(specs) {
|
|
formatSpecsForInput(specs) {
|
|
|
if (!specs) return ''
|
|
if (!specs) return ''
|
|
|
- if (typeof specs === 'object') {
|
|
|
|
|
|
|
+ if (typeof specs === 'object' && !Array.isArray(specs)) {
|
|
|
return Object.entries(specs).map(([k, v]) => k + ':' + v).join('; ')
|
|
return Object.entries(specs).map(([k, v]) => k + ':' + v).join('; ')
|
|
|
}
|
|
}
|
|
|
const text = String(specs).trim()
|
|
const text = String(specs).trim()
|
|
@@ -235,7 +251,12 @@ const baseURL = process.env.VUE_APP_BASE_API || ''
|
|
|
try {
|
|
try {
|
|
|
const parsed = JSON.parse(text)
|
|
const parsed = JSON.parse(text)
|
|
|
if (Array.isArray(parsed)) {
|
|
if (Array.isArray(parsed)) {
|
|
|
- return parsed.map((item, index) => '规格' + (index + 1) + ':' + item).join('; ')
|
|
|
|
|
|
|
+ return parsed.map((item) => {
|
|
|
|
|
+ if (item && typeof item === 'object') {
|
|
|
|
|
+ return (item.name || '') + ':' + (item.value !== undefined && item.value !== null ? item.value : '')
|
|
|
|
|
+ }
|
|
|
|
|
+ return String(item)
|
|
|
|
|
+ }).filter(s => s && s !== ':').join('; ')
|
|
|
}
|
|
}
|
|
|
if (parsed && typeof parsed === 'object') {
|
|
if (parsed && typeof parsed === 'object') {
|
|
|
return Object.entries(parsed).map(([k, v]) => k + ':' + v).join('; ')
|
|
return Object.entries(parsed).map(([k, v]) => k + ':' + v).join('; ')
|
|
@@ -245,10 +266,11 @@ const baseURL = process.env.VUE_APP_BASE_API || ''
|
|
|
return text
|
|
return text
|
|
|
},
|
|
},
|
|
|
normalizeSpecsToJson(specs) {
|
|
normalizeSpecsToJson(specs) {
|
|
|
- if (!specs || !specs.trim()) return '{}'
|
|
|
|
|
|
|
+ if (!specs || !specs.trim()) return '[]'
|
|
|
const trimmed = specs.trim()
|
|
const trimmed = specs.trim()
|
|
|
|
|
+ // 已是 JSON(对象或数组格式),原样返回
|
|
|
if (trimmed.startsWith('{') || trimmed.startsWith('[')) return trimmed
|
|
if (trimmed.startsWith('{') || trimmed.startsWith('[')) return trimmed
|
|
|
- const map = {}
|
|
|
|
|
|
|
+ const arr = []
|
|
|
trimmed.split(/[;;]/).forEach(pair => {
|
|
trimmed.split(/[;;]/).forEach(pair => {
|
|
|
pair = pair.trim()
|
|
pair = pair.trim()
|
|
|
if (!pair) return
|
|
if (!pair) return
|
|
@@ -256,10 +278,13 @@ const baseURL = process.env.VUE_APP_BASE_API || ''
|
|
|
const idx2 = pair.indexOf(':')
|
|
const idx2 = pair.indexOf(':')
|
|
|
const ci = idx === -1 ? idx2 : (idx2 === -1 ? idx : Math.min(idx, idx2))
|
|
const ci = idx === -1 ? idx2 : (idx2 === -1 ? idx : Math.min(idx, idx2))
|
|
|
if (ci > 0) {
|
|
if (ci > 0) {
|
|
|
- map[pair.substring(0, ci).trim()] = pair.substring(ci + 1).trim()
|
|
|
|
|
|
|
+ arr.push({
|
|
|
|
|
+ name: pair.substring(0, ci).trim(),
|
|
|
|
|
+ value: pair.substring(ci + 1).trim()
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- return Object.keys(map).length ? JSON.stringify(map) : '{}'
|
|
|
|
|
|
|
+ return arr.length ? JSON.stringify(arr) : '[]'
|
|
|
},
|
|
},
|
|
|
formatPrice(val) {
|
|
formatPrice(val) {
|
|
|
if (!val) return '¥0.00'
|
|
if (!val) return '¥0.00'
|