From b1df470c0c1ef83fdc5929c8ec369dcda022c38f Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 14 七月 2023 16:12:33 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/tabviews/custom/components/share/normalTable/index.jsx | 39 +++++++++++++++++++++++++++------------ 1 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/tabviews/custom/components/share/normalTable/index.jsx b/src/tabviews/custom/components/share/normalTable/index.jsx index 83b7612..b16b14a 100644 --- a/src/tabviews/custom/components/share/normalTable/index.jsx +++ b/src/tabviews/custom/components/share/normalTable/index.jsx @@ -330,32 +330,47 @@ ) } else if (col.type === 'formula') { let content = col.formula - Object.keys(record).forEach(key => { - let reg = new RegExp('@' + key + '@', 'ig') - content = content.replace(reg, record[key]) - }) - if (col.eval !== 'false') { + if (col.eval === 'func') { try { // eslint-disable-next-line - content = eval(content) + let func = new Function('data', col.formula) + content = func([record]) } catch (e) { if (window.debugger) { - console.info(content) console.warn(e) } content = '' } - - if (col.round && typeof(content) === 'number') { - content = Math.round(content * col.round) / col.round - content = content.toFixed(col.decimal) + } else { + Object.keys(record).forEach(key => { + let reg = new RegExp('@' + key + '@', 'ig') + content = content.replace(reg, record[key]) + }) + if (col.eval !== 'false') { + try { + // eslint-disable-next-line + content = eval(content) + } catch (e) { + if (window.debugger) { + console.info(content) + console.warn(e) + } + content = '' + } + + if (col.round && typeof(content) === 'number') { + content = Math.round(content * col.round) / col.round + content = content.toFixed(col.decimal) + } } } content = content === undefined ? '' : content - if (content !== '') { + if (col.eval === 'func') { + content = <span dangerouslySetInnerHTML={{__html: content}}></span> + } else if (content !== '') { content = `${col.prefix || ''}${content}${col.postfix || ''}` content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, ' ') content = <span dangerouslySetInnerHTML={{__html: content}}></span> -- Gitblit v1.8.0