From ac42cc9f121fba588682e157bd1f95fff126395c Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 14 七月 2023 16:42:32 +0800 Subject: [PATCH] 2023-07-14 --- src/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 32 ++++++++++++++++++++++++-------- 1 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx index e4c2fc2..f8bfcf3 100644 --- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx @@ -842,21 +842,35 @@ ) } 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 = '' + } + } 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 = '' + } } } @@ -871,7 +885,9 @@ content = content.toFixed(col.decimal) } - 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