From cbdb8d21bfb4e41e111d09b5c559054fce6c8268 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com>
Date: Thu, 3 Oct 2024 06:41:56 +0800
Subject: [PATCH] =?UTF-8?q?refactor(BaTable):=E5=8D=95=E5=85=83=E6=A0=BC?=
=?UTF-8?q?=E6=B8=B2=E6=9F=93=E5=99=A8=E6=8B=86=E5=88=86=E4=B8=BA=E7=8B=AC?=
=?UTF-8?q?=E7=AB=8B=E7=BB=84=E4=BB=B6=E5=B9=B6=E6=94=B9=E7=94=A8=E6=98=93?=
=?UTF-8?q?=E4=BA=8E=E6=89=A9=E5=B1=95=E7=9A=84=E6=96=B9=E5=BC=8F=E5=8A=A0?=
=?UTF-8?q?=E8=BD=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/package.json | 2 +-
.../components/table/fieldRender/buttons.vue | 144 +++++++++
.../components/table/fieldRender/color.vue | 28 ++
.../table/fieldRender/customRender.vue | 28 ++
.../table/fieldRender/customTemplate.vue | 21 ++
.../components/table/fieldRender/datetime.vue | 22 ++
.../components/table/fieldRender/default.vue | 5 +
web/src/components/table/fieldRender/icon.vue | 19 ++
.../components/table/fieldRender/image.vue | 35 ++
.../components/table/fieldRender/images.vue | 42 +++
.../components/table/fieldRender/index.vue | 299 ------------------
.../components/table/fieldRender/switch.vue | 44 +++
web/src/components/table/fieldRender/tag.vue | 28 ++
web/src/components/table/fieldRender/tags.vue | 54 ++++
web/src/components/table/fieldRender/url.vue | 39 +++
web/src/components/table/index.ts | 40 ++-
web/src/components/table/index.vue | 36 ++-
web/src/utils/baTable.ts | 19 +-
web/src/utils/build.ts | 40 ++-
web/types/table.d.ts | 19 +-
web/types/tableRenderer.d.ts | 15 +
21 files changed, 622 insertions(+), 357 deletions(-)
create mode 100644 web/src/components/table/fieldRender/buttons.vue
create mode 100644 web/src/components/table/fieldRender/color.vue
create mode 100644 web/src/components/table/fieldRender/customRender.vue
create mode 100644 web/src/components/table/fieldRender/customTemplate.vue
create mode 100644 web/src/components/table/fieldRender/datetime.vue
create mode 100644 web/src/components/table/fieldRender/default.vue
create mode 100644 web/src/components/table/fieldRender/icon.vue
create mode 100644 web/src/components/table/fieldRender/image.vue
create mode 100644 web/src/components/table/fieldRender/images.vue
delete mode 100644 web/src/components/table/fieldRender/index.vue
create mode 100644 web/src/components/table/fieldRender/switch.vue
create mode 100644 web/src/components/table/fieldRender/tag.vue
create mode 100644 web/src/components/table/fieldRender/tags.vue
create mode 100644 web/src/components/table/fieldRender/url.vue
create mode 100644 web/types/tableRenderer.d.ts
diff --git a/web/package.json b/web/package.json
index 37868851..c51d863a 100644
--- a/web/package.json
+++ b/web/package.json
@@ -4,7 +4,7 @@
"license": "Apache-2.0",
"type": "module",
"scripts": {
- "dev": "vite --force",
+ "dev": "esno ./src/utils/build.ts && vite --force",
"build": "vite build && esno ./src/utils/build.ts",
"lint": "eslint .",
"lint-fix": "eslint --fix .",
diff --git a/web/src/components/table/fieldRender/buttons.vue b/web/src/components/table/fieldRender/buttons.vue
new file mode 100644
index 00000000..e58e306a
--- /dev/null
+++ b/web/src/components/table/fieldRender/buttons.vue
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
+ {{ getTranslation(btn.text) }}
+
+
+
+
+
+
+ {{ getTranslation(btn.text) }}
+
+
+
+
+
+
+
+
+
+
+ {{ getTranslation(btn.text) }}
+
+
+
+
+
+
+
+
+
+
+ {{ getTranslation(btn.text) }}
+
+
+
+
+
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/color.vue b/web/src/components/table/fieldRender/color.vue
new file mode 100644
index 00000000..6ba1f747
--- /dev/null
+++ b/web/src/components/table/fieldRender/color.vue
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/customRender.vue b/web/src/components/table/fieldRender/customRender.vue
new file mode 100644
index 00000000..d9bac394
--- /dev/null
+++ b/web/src/components/table/fieldRender/customRender.vue
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/customTemplate.vue b/web/src/components/table/fieldRender/customTemplate.vue
new file mode 100644
index 00000000..5d95401a
--- /dev/null
+++ b/web/src/components/table/fieldRender/customTemplate.vue
@@ -0,0 +1,21 @@
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/datetime.vue b/web/src/components/table/fieldRender/datetime.vue
new file mode 100644
index 00000000..09dc1a3a
--- /dev/null
+++ b/web/src/components/table/fieldRender/datetime.vue
@@ -0,0 +1,22 @@
+
+
+ {{ !cellValue ? '-' : timeFormat(cellValue, field.timeFormat ?? 'yyyy-mm-dd hh:MM:ss') }}
+
+
+
+
diff --git a/web/src/components/table/fieldRender/default.vue b/web/src/components/table/fieldRender/default.vue
new file mode 100644
index 00000000..27bfa306
--- /dev/null
+++ b/web/src/components/table/fieldRender/default.vue
@@ -0,0 +1,5 @@
+
+
+ Field renderer not found
+
+
diff --git a/web/src/components/table/fieldRender/icon.vue b/web/src/components/table/fieldRender/icon.vue
new file mode 100644
index 00000000..7f75608f
--- /dev/null
+++ b/web/src/components/table/fieldRender/icon.vue
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/image.vue b/web/src/components/table/fieldRender/image.vue
new file mode 100644
index 00000000..dd156857
--- /dev/null
+++ b/web/src/components/table/fieldRender/image.vue
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/images.vue b/web/src/components/table/fieldRender/images.vue
new file mode 100644
index 00000000..9e970ba0
--- /dev/null
+++ b/web/src/components/table/fieldRender/images.vue
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/index.vue b/web/src/components/table/fieldRender/index.vue
deleted file mode 100644
index c701ab43..00000000
--- a/web/src/components/table/fieldRender/index.vue
+++ /dev/null
@@ -1,299 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ field.replaceValue ? field.replaceValue[fieldValue] ?? fieldValue : fieldValue }}
-
-
-
-
-
-
-
-
- {{ field.replaceValue ? field.replaceValue[tag] ?? tag : tag }}
-
-
-
-
- {{ field.replaceValue ? field.replaceValue[fieldValue] ?? fieldValue : fieldValue }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ !fieldValue ? '-' : timeFormat(fieldValue, field.timeFormat ?? undefined) }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ btn.text }}
-
-
-
-
-
-
- {{ btn.text }}
-
-
-
-
-
-
-
-
-
-
- {{ btn.text }}
-
-
-
-
-
-
-
-
-
-
- {{ btn.text }}
-
-
-
-
-
-
-
-
-
-
diff --git a/web/src/components/table/fieldRender/switch.vue b/web/src/components/table/fieldRender/switch.vue
new file mode 100644
index 00000000..158a6116
--- /dev/null
+++ b/web/src/components/table/fieldRender/switch.vue
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/tag.vue b/web/src/components/table/fieldRender/tag.vue
new file mode 100644
index 00000000..bc3c49db
--- /dev/null
+++ b/web/src/components/table/fieldRender/tag.vue
@@ -0,0 +1,28 @@
+
+
+
+ {{ !isEmpty(field.replaceValue) ? field.replaceValue[cellValue] ?? cellValue : cellValue }}
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/tags.vue b/web/src/components/table/fieldRender/tags.vue
new file mode 100644
index 00000000..f314ff0c
--- /dev/null
+++ b/web/src/components/table/fieldRender/tags.vue
@@ -0,0 +1,54 @@
+
+
+
+
+
+ {{ !isEmpty(field.replaceValue) ? field.replaceValue[tag] ?? tag : tag }}
+
+
+
+
+
+ {{ !isEmpty(field.replaceValue) ? field.replaceValue[cellValue] ?? cellValue : cellValue }}
+
+
+
+
+
+
+
+
diff --git a/web/src/components/table/fieldRender/url.vue b/web/src/components/table/fieldRender/url.vue
new file mode 100644
index 00000000..eb2e8366
--- /dev/null
+++ b/web/src/components/table/fieldRender/url.vue
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/web/src/components/table/index.ts b/web/src/components/table/index.ts
index 6e81fae8..8f6c82a1 100644
--- a/web/src/components/table/index.ts
+++ b/web/src/components/table/index.ts
@@ -1,14 +1,40 @@
+import { TableColumnCtx } from 'element-plus'
import { i18n } from '/@/lang/index'
-/*
- * 默认Url点击事件处理
+/**
+ * 获取单元格值
*/
-export const openUrl = (url: string, field: TableColumn) => {
- if (field.target == '_blank') {
- window.open(url)
- } else {
- window.location.href = url
+export const getCellValue = (row: TableRow, field: TableColumn, column: TableColumnCtx, index: number) => {
+ if (!field.prop) return ''
+
+ const prop = field.prop
+ let cellValue: any = row[prop]
+
+ // 字段 prop 带 . 比如 user.nickname
+ if (prop.indexOf('.') > -1) {
+ const fieldNameArr = prop.split('.')
+ cellValue = row[fieldNameArr[0]]
+ for (let index = 1; index < fieldNameArr.length; index++) {
+ cellValue = cellValue ? cellValue[fieldNameArr[index]] ?? '' : ''
+ }
+ return cellValue
}
+
+ // 若无值,尝试取默认值
+ if (cellValue === undefined || cellValue === null) {
+ cellValue = field.default
+ }
+
+ // 渲染前格式化
+ if (field.renderFormatter && typeof field.renderFormatter == 'function') {
+ cellValue = field.renderFormatter(row, field, cellValue, column, index)
+ console.warn('baTable.table.column.renderFormatter 即将废弃,请直接使用兼容 el-table 的 baTable.table.column.formatter 代替')
+ }
+ if (field.formatter && typeof field.formatter == 'function') {
+ cellValue = field.formatter(row, column, cellValue, index)
+ }
+
+ return cellValue
}
/*
diff --git a/web/src/components/table/index.vue b/web/src/components/table/index.vue
index 12c30753..0286300d 100644
--- a/web/src/components/table/index.vue
+++ b/web/src/components/table/index.vue
@@ -30,22 +30,15 @@
v-bind="item"
:column-key="(item['columnKey'] ? item['columnKey'] : `table-column-${item.prop}`) || shortUuid()"
>
-
+
-
@@ -71,8 +64,8 @@