Browse Source

显示多个空格

lzm_web
Linzm 5 months ago
parent
commit
d56c9c2f6b
  1. 26
      src/views/badge/preview.vue

26
src/views/badge/preview.vue

@ -774,15 +774,19 @@ const validateInput = (input: string) => { @@ -774,15 +774,19 @@ const validateInput = (input: string) => {
const handleInput = (value: string) => {
let byteLength = calculateByteLength(value);
//
console.log('byteLength', byteLength, limitCount.value)
if (byteLength > limitCount.value) {
//
let validValue = '';
let currentBytes = 0;
for (let i = 0; i < value.length; i++) {
const char = value.charAt(i);
const charBytes = char.charCodeAt(0) > 255 ? 2 : 1;
const code = char.charCodeAt(0);
let charBytes = 0;
if (code === 32) {
charBytes = 1;
} else {
charBytes = code > 255 ? 2 : 1;
}
if (currentBytes + charBytes <= limitCount.value) {
validValue += char;
currentBytes += charBytes;
@ -793,7 +797,6 @@ const handleInput = (value: string) => { @@ -793,7 +797,6 @@ const handleInput = (value: string) => {
shapeText.value = validValue;
return;
}
//
shapeText.value = value;
}
@ -801,21 +804,15 @@ const calculateByteLength = (str: string) => { @@ -801,21 +804,15 @@ const calculateByteLength = (str: string) => {
let len = 0;
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i);
// 21
if (code === 32) {
len += 1;
} else {
len += code > 255 ? 2 : 1;
}
}
return len;
}
// const typeChange = (id: number) => {
// console.log('typeChange', id)
// typeId.value = id;
// shapeList.value = [];
// shapeImage.value = '';
// getStyle.value = '';
// getShapeList()
// }
const shapeChange = (item: any) => {
console.log('shapeChange', item)
sizeList.value.map((item: any) => {
@ -1448,6 +1445,7 @@ onUnmounted(() => { @@ -1448,6 +1445,7 @@ onUnmounted(() => {
font-family: chinese;
overflow: hidden;
text-shadow: 1px 0px 1px #000000a1;
white-space: pre-wrap;
}
.shape-item-image-round {
border-radius: 50%;

Loading…
Cancel
Save