商品规格字符长度限制

master
15386982806 2024-01-05 15:54:10 +08:00
parent 77e7d095a7
commit 42c64920b1
1 changed files with 20 additions and 0 deletions

View File

@ -1131,6 +1131,10 @@ export default {
this.$Message.error("已存在相同规格项!");
return;
}
if (this.zz(0, val) > 20) {
this.$Message.error("规格项最多十个字符长度!");
return;
}
this.skuTableData = this.skuTableData.map((e) => {
e[val] = e[this.currentSkuItem];
delete e[this.currentSkuItem];
@ -1139,6 +1143,18 @@ export default {
this.currentSkuItem = val;
this.renderTableData(this.skuTableData);
},
// 1020
zz(len, value) {
for(let i=0; i<value.length; i++) {
//
if (/[\u4e00-\u9fa5]/.test(value[i])) {
len+=2;
} else {
len++;
}
}
return len;
},
//
skuValueChange(val, index, item) {
if (this.skuTableData.find((i) => i[val.name] === val.value)) {
@ -1149,6 +1165,10 @@ export default {
this.$Message.error("规格值不能为空!");
return;
}
if (this.zz(0, val.value) > 20) {
this.$Message.error("规格值最多十个字符长度!");
return;
}
let curVal = this.currentSkuVal;
this.skuTableData = this.skuTableData.map((e) => {
if (e[val.name] === curVal) {