Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 7719df5

Browse files
committed
修复 配置文件数值类型转型问题
1 parent 34d1529 commit 7719df5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/app/service/common.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ export function getDescriptionByTitle(description, title = "") {
126126
return _exec(arr, description);
127127
}
128128

129+
// 适用于配置文件解析成 JSON 格式后再解析成网页可循环的二维表格式
130+
// 其具体原理是实现一个简单双向绑定,来对应每一个具体的配置项目
129131
export function jsonToMap(json, topTitle = "", map = {}) {
130132
for (const key in json) {
131133
let title = null;
@@ -160,6 +162,8 @@ export function jsonToMap(json, topTitle = "", map = {}) {
160162
return json[key];
161163
},
162164
set(v) {
165+
const preValue = json[key];
166+
if (typeof preValue === "number" && !isNaN(Number(v))) return (json[key] = Number(v));
163167
json[key] = v;
164168
}
165169
});
@@ -171,12 +175,11 @@ export function jsonToMap(json, topTitle = "", map = {}) {
171175
export function toUnicode(str) {
172176
var value = "";
173177
for (var i = 0; i < str.length; i++) {
174-
if ((/([\u4E00-\u9FA5]|[\uFE30-\uFFA0])/g).test(str[i])) {
178+
if (/([\u4E00-\u9FA5]|[\uFE30-\uFFA0])/g.test(str[i])) {
175179
value += "\\u" + leftZero4(parseInt(str.charCodeAt(i)).toString(16));
176180
} else {
177181
value += str[i];
178182
}
179-
180183
}
181184
return value;
182185
}
@@ -187,4 +190,4 @@ function leftZero4(str) {
187190
}
188191
}
189192
return str;
190-
}
193+
}

0 commit comments

Comments
 (0)