From e69fddd2f7b3bc0edbd63241c10de592c296cc4a Mon Sep 17 00:00:00 2001
From: wolfcode <37436228+wolf-leo@users.noreply.github.com>
Date: Fri, 13 Sep 2024 10:51:11 +0800
Subject: [PATCH] =?UTF-8?q?feat(table):=20=E6=96=B0=E5=A2=9E=20visible=20?=
=?UTF-8?q?=E5=8F=82=E6=95=B0=E5=80=BC=E6=8E=A7=E5=88=B6=E5=B1=9E=E6=80=A7?=
=?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=8E=E5=90=A6=20pass=20`data`=20param=20?=
=?UTF-8?q?to=20`buildOperatHtml`=20for=20visibility=20logic?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Pass the `data` parameter to the `buildOperatHtml` function to support dynamic visibility checks for table operations. This allows operation visibility to be conditionally determined
based on the provided data.
---
public/static/plugs/easy-admin/easy-admin.js | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/public/static/plugs/easy-admin/easy-admin.js b/public/static/plugs/easy-admin/easy-admin.js
index 9c561f0..7c8a7ea 100644
--- a/public/static/plugs/easy-admin/easy-admin.js
+++ b/public/static/plugs/easy-admin/easy-admin.js
@@ -501,7 +501,7 @@ define(["jquery", "tableSelect"], function ($, tableSelect) {
return html;
},
- buildOperatHtml: function (operat) {
+ buildOperatHtml: function (operat, data) {
var html = '';
operat.class = operat.class || '';
operat.icon = operat.icon || '';
@@ -512,6 +512,7 @@ define(["jquery", "tableSelect"], function ($, tableSelect) {
operat.field = operat.field || 'id';
operat.title = operat.title || operat.text;
operat.text = operat.text || operat.title;
+ operat.visible = typeof operat.visible !== 'undefined' ? operat.visible : true;
var formatOperat = operat;
formatOperat.icon = formatOperat.icon !== '' ? ' ' : '';
@@ -525,6 +526,17 @@ define(["jquery", "tableSelect"], function ($, tableSelect) {
}
html = '' + formatOperat.icon + formatOperat.text + '';
+ if ('function' === typeof formatOperat.visible) {
+ let visible = formatOperat.visible(data);
+ if (typeof visible === 'boolean') {
+ if (!visible) html = ''
+ }
+ } else {
+ if (typeof formatOperat.visible === 'boolean') {
+ if (!formatOperat.visible) html = ''
+ }
+ }
+
return html;
},
toolSpliceUrl(url, field, data) {
@@ -611,7 +623,7 @@ define(["jquery", "tableSelect"], function ($, tableSelect) {
};
operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data);
if (admin.checkAuth(operat.auth, elem)) {
- html += admin.table.buildOperatHtml(operat);
+ html += admin.table.buildOperatHtml(operat, data);
}
break;
case 'delete':
@@ -628,7 +640,7 @@ define(["jquery", "tableSelect"], function ($, tableSelect) {
};
operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data);
if (admin.checkAuth(operat.auth, elem)) {
- html += admin.table.buildOperatHtml(operat);
+ html += admin.table.buildOperatHtml(operat, data);
}
break;
}
@@ -655,7 +667,7 @@ define(["jquery", "tableSelect"], function ($, tableSelect) {
operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data);
if (admin.checkAuth(operat.auth, elem)) {
- html += admin.table.buildOperatHtml(operat);
+ html += admin.table.buildOperatHtml(operat, data);
}
});
}