Compare commits

...

2 Commits

Author SHA1 Message Date
CPPAlien
beb630d5a2 fix: calc bug 2021-06-22 16:59:52 +08:00
CPPAlien
eeb4f8a0fa fix: 四则运算 2021-06-22 16:45:39 +08:00
2 changed files with 52 additions and 46 deletions

View File

@ -1,4 +1,8 @@
module.exports = function (s) { /* eslint-disable */
// 四则运算
!(function () {
var calculate = function (s) {
s = s.trim(); s = s.trim();
const stack = new Array(); const stack = new Array();
let preSign = '+'; let preSign = '+';
@ -18,7 +22,7 @@ module.exports = function (s) {
numStr = `${calculate(s.slice(i + 1, j))}`; numStr = `${calculate(s.slice(i + 1, j))}`;
i = j; i = j;
} }
if (isNaN(Number(s[i]) && s[i] !== '.') || i === n - 1) { if ((isNaN(Number(s[i])) && s[i] !== '.') || i === n - 1) {
let num = parseFloat(numStr); let num = parseFloat(numStr);
switch (preSign) { switch (preSign) {
case '+': case '+':
@ -46,3 +50,5 @@ module.exports = function (s) {
} }
return ans; return ans;
}; };
module.exports = calculate;
})();

View File

@ -851,7 +851,7 @@ function setStringPrototype(screenK, scale) {
const formula = /^calc\((.+)\)$/.exec(this); const formula = /^calc\((.+)\)$/.exec(this);
if (formula && formula[1]) { if (formula && formula[1]) {
// 进行 calc 计算 // 进行 calc 计算
const afterOne = formula[1].replace(/([^\s]+)\.(left|right|bottom|top|width|height)/g, word => { const afterOne = formula[1].replace(/([^\s\(\+\-\*\/]+)\.(left|right|bottom|top|width|height)/g, word => {
const [id, attr] = word.split('.'); const [id, attr] = word.split('.');
return penCache.viewRect[id][attr]; return penCache.viewRect[id][attr];
}); });