forked from natuka/web.puabadge.com
显示多个空格
This commit is contained in:
1 parent
a3a2aa76c9
commit
d56c9c2f6b
1 file changed
+12
-14
+12
-14
@@ -774,15 +774,19 @@ const validateInput = (input: string) => {
|
|||||||
|
|
||||||
const handleInput = (value: string) => {
|
const handleInput = (value: string) => {
|
||||||
let byteLength = calculateByteLength(value);
|
let byteLength = calculateByteLength(value);
|
||||||
// 如果超过最大字节数,禁止继续输入
|
|
||||||
console.log('byteLength', byteLength, limitCount.value)
|
console.log('byteLength', byteLength, limitCount.value)
|
||||||
if (byteLength > limitCount.value) {
|
if (byteLength > limitCount.value) {
|
||||||
// 超出字节数,直接截断到允许的最大字节数
|
|
||||||
let validValue = '';
|
let validValue = '';
|
||||||
let currentBytes = 0;
|
let currentBytes = 0;
|
||||||
for (let i = 0; i < value.length; i++) {
|
for (let i = 0; i < value.length; i++) {
|
||||||
const char = value.charAt(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) {
|
if (currentBytes + charBytes <= limitCount.value) {
|
||||||
validValue += char;
|
validValue += char;
|
||||||
currentBytes += charBytes;
|
currentBytes += charBytes;
|
||||||
@@ -793,7 +797,6 @@ const handleInput = (value: string) => {
|
|||||||
shapeText.value = validValue;
|
shapeText.value = validValue;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 未超过最大字节数,正常更新
|
|
||||||
shapeText.value = value;
|
shapeText.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -801,21 +804,15 @@ const calculateByteLength = (str: string) => {
|
|||||||
let len = 0;
|
let len = 0;
|
||||||
for (let i = 0; i < str.length; i++) {
|
for (let i = 0; i < str.length; i++) {
|
||||||
const code = str.charCodeAt(i);
|
const code = str.charCodeAt(i);
|
||||||
// 中文字符和特殊符号占2字节,英文占1字节
|
if (code === 32) {
|
||||||
|
len += 1;
|
||||||
|
} else {
|
||||||
len += code > 255 ? 2 : 1;
|
len += code > 255 ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const typeChange = (id: number) => {
|
|
||||||
// console.log('typeChange', id)
|
|
||||||
// typeId.value = id;
|
|
||||||
// shapeList.value = [];
|
|
||||||
// shapeImage.value = '';
|
|
||||||
// getStyle.value = '';
|
|
||||||
// getShapeList()
|
|
||||||
// }
|
|
||||||
|
|
||||||
const shapeChange = (item: any) => {
|
const shapeChange = (item: any) => {
|
||||||
console.log('shapeChange', item)
|
console.log('shapeChange', item)
|
||||||
sizeList.value.map((item: any) => {
|
sizeList.value.map((item: any) => {
|
||||||
@@ -1448,6 +1445,7 @@ onUnmounted(() => {
|
|||||||
font-family: chinese;
|
font-family: chinese;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-shadow: 1px 0px 1px #000000a1;
|
text-shadow: 1px 0px 1px #000000a1;
|
||||||
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
.shape-item-image-round {
|
.shape-item-image-round {
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
|
|||||||
Reference in new issue
Block a user