@befly-addon/admin 1.8.2 → 1.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,95 +1,77 @@
1
1
  <template>
2
- <div class="page-role page-table">
3
- <div class="main-tool">
4
- <div class="left">
5
- <TButton theme="primary" @click="$Method.onAction('add', {})">
6
- <template #icon>
7
- <ILucidePlus />
8
- </template>
2
+ <PagedTableDetail class="page-role page-table" :columns="$Data.columns" :endpoints="$Data.endpoints" :table-slot-names="['state', 'menuCount', 'apiCount']">
3
+ <template #toolLeft>
4
+ <TButton theme="primary" @click="onAdd">
5
+ <template #icon>
6
+ <ILucidePlus />
7
+ </template>
8
+ </TButton>
9
+ </template>
10
+
11
+ <template #toolRight="scope">
12
+ <TButton shape="circle" @click="onReload(scope.reload)">
13
+ <template #icon>
14
+ <ILucideRotateCw />
15
+ </template>
16
+ </TButton>
17
+ </template>
18
+
19
+ <template #state="{ row }">
20
+ <TTag v-if="row.state === 1" shape="round" theme="success" variant="light-outline">正常</TTag>
21
+ <TTag v-else-if="row.state === 2" shape="round" theme="warning" variant="light-outline">禁用</TTag>
22
+ <TTag v-else shape="round" theme="danger" variant="light-outline">已删除</TTag>
23
+ </template>
24
+
25
+ <template #menuCount="{ row }">
26
+ {{ getPathCount(row.menus) }}
27
+ </template>
28
+
29
+ <template #apiCount="{ row }">
30
+ {{ getPathCount(row.apis) }}
31
+ </template>
32
+
33
+ <template #operation="{ row, deleteRow }">
34
+ <TDropdown trigger="click" placement="bottom-right" @click="onDropdownAction($event, row, deleteRow)">
35
+ <TButton theme="primary" size="small">
36
+ 操作
37
+ <template #suffix> <ILucideChevronDown /></template>
9
38
  </TButton>
10
- </div>
11
- <div class="right">
12
- <TButton shape="circle" @click="$Method.handleRefresh">
13
- <template #icon>
14
- <ILucideRotateCw />
15
- </template>
16
- </TButton>
17
- </div>
18
- </div>
19
- <div class="main-content">
20
- <div class="main-table">
21
- <TTable
22
- :data="$Data.tableData"
23
- :columns="$Data.columns"
24
- :loading="$Data.loading"
25
- :active-row-keys="$Data.activeRowKeys"
26
- row-key="id"
27
- height="calc(100vh - var(--search-height) - var(--pagination-height) - var(--layout-gap) * 4)"
28
- active-row-type="single"
29
- @active-change="$Method.onActiveChange"
30
- >
31
- <template #state="{ row }">
32
- <TTag v-if="row.state === 1" shape="round" theme="success" variant="light-outline">正常</TTag>
33
- <TTag v-else-if="row.state === 2" shape="round" theme="warning" variant="light-outline">禁用</TTag>
34
- <TTag v-else shape="round" theme="danger" variant="light-outline">已删除</TTag>
35
- </template>
36
- <template #menuCount="{ row }">
37
- {{ $Method.getPathCount(row.menus) }}
38
- </template>
39
- <template #apiCount="{ row }">
40
- {{ $Method.getPathCount(row.apis) }}
41
- </template>
42
- <template #operation="{ row }">
43
- <TDropdown trigger="click" placement="bottom-right" @click="(data) => $Method.onAction(data.value, row)">
44
- <TButton theme="primary" size="small">
45
- 操作
46
- <template #suffix> <ILucideChevronDown /></template>
47
- </TButton>
48
- <TDropdownMenu slot="dropdown">
49
- <TDropdownItem value="upd">
50
- <ILucidePencil />
51
- 编辑
52
- </TDropdownItem>
53
- <TDropdownItem value="menu">
54
- <ILucideSettings />
55
- 菜单权限
56
- </TDropdownItem>
57
- <TDropdownItem value="api">
58
- <ILucideCode />
59
- 接口权限
60
- </TDropdownItem>
61
- <TDropdownItem value="del" :divider="true">
62
- <ILucideTrash2 style="width: 14px; height: 14px; margin-right: 6px" />
63
- 删除
64
- </TDropdownItem>
65
- </TDropdownMenu>
66
- </TDropdown>
67
- </template>
68
- </TTable>
69
- </div>
70
-
71
- <div class="main-detail">
72
- <DetailPanel :data="$Data.currentRow" :fields="$Data.columns" />
73
- </div>
74
- </div>
75
-
76
- <div class="main-page">
77
- <TPagination :current-page="$Data.pagerConfig.currentPage" :page-size="$Data.pagerConfig.limit" :total="$Data.pagerConfig.total" @current-change="$Method.onPageChange" @page-size-change="$Method.handleSizeChange" />
78
- </div>
79
-
80
- <!-- 编辑对话框组件 -->
81
- <EditDialog v-if="$Data.editVisible" v-model="$Data.editVisible" :action-type="$Data.actionType" :row-data="$Data.rowData" @success="$Method.apiRoleList" />
82
-
83
- <!-- 菜单权限对话框组件 -->
84
- <MenuDialog v-if="$Data.menuVisible" v-model="$Data.menuVisible" :row-data="$Data.rowData" @success="$Method.apiRoleList" />
85
-
86
- <!-- 接口权限对话框组件 -->
87
- <ApiDialog v-if="$Data.apiVisible" v-model="$Data.apiVisible" :row-data="$Data.rowData" @success="$Method.apiRoleList" />
88
- </div>
39
+ <TDropdownMenu slot="dropdown">
40
+ <TDropdownItem value="upd">
41
+ <ILucidePencil />
42
+ 编辑
43
+ </TDropdownItem>
44
+ <TDropdownItem value="menu">
45
+ <ILucideSettings />
46
+ 菜单权限
47
+ </TDropdownItem>
48
+ <TDropdownItem value="api">
49
+ <ILucideCode />
50
+ 接口权限
51
+ </TDropdownItem>
52
+ <TDropdownItem value="del" :divider="true">
53
+ <ILucideTrash2 style="width: 14px; height: 14px; margin-right: 6px" />
54
+ 删除
55
+ </TDropdownItem>
56
+ </TDropdownMenu>
57
+ </TDropdown>
58
+ </template>
59
+
60
+ <template #dialogs="scope">
61
+ <!-- 编辑对话框组件 -->
62
+ <EditDialog v-if="$Data.editVisible" v-model="$Data.editVisible" :action-type="$Data.actionType" :row-data="$Data.rowData" @success="onDialogSuccess(scope.reload)" />
63
+
64
+ <!-- 菜单权限对话框组件 -->
65
+ <MenuDialog v-if="$Data.menuVisible" v-model="$Data.menuVisible" :row-data="$Data.rowData" @success="onDialogSuccess(scope.reload)" />
66
+
67
+ <!-- 接口权限对话框组件 -->
68
+ <ApiDialog v-if="$Data.apiVisible" v-model="$Data.apiVisible" :row-data="$Data.rowData" @success="onDialogSuccess(scope.reload)" />
69
+ </template>
70
+ </PagedTableDetail>
89
71
  </template>
90
72
 
91
73
  <script setup lang="ts">
92
- import { Button as TButton, Table as TTable, Tag as TTag, Dropdown as TDropdown, DropdownMenu as TDropdownMenu, DropdownItem as TDropdownItem, Pagination as TPagination, MessagePlugin, DialogPlugin } from "tdesign-vue-next";
74
+ import { Button as TButton, Dropdown as TDropdown, DropdownItem as TDropdownItem, DropdownMenu as TDropdownMenu, Tag as TTag } from "tdesign-vue-next";
93
75
  import ILucidePlus from "~icons/lucide/plus";
94
76
  import ILucideRotateCw from "~icons/lucide/rotate-cw";
95
77
  import ILucidePencil from "~icons/lucide/pencil";
@@ -100,16 +82,11 @@ import ILucideChevronDown from "~icons/lucide/chevron-down";
100
82
  import EditDialog from "./components/edit.vue";
101
83
  import MenuDialog from "./components/menu.vue";
102
84
  import ApiDialog from "./components/api.vue";
103
- import DetailPanel from "@/components/DetailPanel.vue";
104
- import { $Http } from "@/plugins/http";
85
+ import PagedTableDetail from "@/components/pagedTableDetail.vue";
105
86
  import { withDefaultColumns } from "befly-shared/utils/withDefaultColumns";
106
87
 
107
88
  // 响应式数据
108
89
  const $Data = $ref({
109
- tableData: [],
110
- loading: false,
111
- activeRowKeys: [],
112
- currentRow: null,
113
90
  columns: withDefaultColumns([
114
91
  { colKey: "name", title: "角色名称" },
115
92
  { colKey: "code", title: "角色代码", width: 150 },
@@ -120,12 +97,23 @@ const $Data = $ref({
120
97
  { colKey: "description", title: "描述" },
121
98
  { colKey: "operation", title: "操作" }
122
99
  ]),
123
- pagerConfig: {
124
- currentPage: 1,
125
- limit: 30,
126
- total: 0,
127
- align: "right",
128
- layout: "total, prev, pager, next, jumper"
100
+ endpoints: {
101
+ list: {
102
+ path: "/addon/admin/role/list",
103
+ dropValues: [""]
104
+ },
105
+ delete: {
106
+ path: "/addon/admin/role/del",
107
+ idKey: "id",
108
+ confirm: (row) => {
109
+ return {
110
+ header: "确认删除",
111
+ body: `确认删除角色“${row.name}”吗?`,
112
+ confirmBtn: "删除",
113
+ status: "warning"
114
+ };
115
+ }
116
+ }
129
117
  },
130
118
  editVisible: false,
131
119
  menuVisible: false,
@@ -134,140 +122,57 @@ const $Data = $ref({
134
122
  rowData: {}
135
123
  });
136
124
 
137
- // 方法
138
- const $Method = {
139
- getPathCount(value) {
140
- if (!Array.isArray(value)) return 0;
141
- return value.filter((p) => typeof p === "string" && p.trim().length > 0).length;
142
- },
143
- async initData() {
144
- await $Method.apiRoleList();
145
- },
146
- // 加载角色列表
147
- async apiRoleList() {
148
- $Data.loading = true;
149
- try {
150
- const res = await $Http.post(
151
- "/addon/admin/role/list",
152
- {
153
- page: $Data.pagerConfig.currentPage,
154
- limit: $Data.pagerConfig.limit
155
- },
156
- {
157
- dropValues: [""]
158
- }
159
- );
160
- $Data.tableData = res.data.lists || [];
161
- $Data.pagerConfig.total = res.data.total || 0;
162
-
163
- // 自动选中并高亮第一行
164
- if ($Data.tableData.length > 0) {
165
- $Data.currentRow = $Data.tableData[0];
166
- $Data.activeRowKeys = [$Data.tableData[0].id];
167
- } else {
168
- $Data.currentRow = null;
169
- $Data.activeRowKeys = [];
170
- }
171
- } catch (error) {
172
- MessagePlugin.error("加载数据失败");
173
- } finally {
174
- $Data.loading = false;
175
- }
176
- },
177
-
178
- // 删除角色
179
- async apiRoleDel(row) {
180
- let dialog = null;
181
- let destroyed = false;
125
+ function onAdd(): void {
126
+ onAction("add", {});
127
+ }
182
128
 
183
- const destroy = () => {
184
- if (destroyed) return;
185
- destroyed = true;
186
- if (dialog && typeof dialog.destroy === "function") {
187
- dialog.destroy();
188
- }
189
- };
190
-
191
- dialog = DialogPlugin.confirm({
192
- header: "确认删除",
193
- body: `确认删除角色“${row.name}”吗?`,
194
- status: "warning",
195
- confirmBtn: "删除",
196
- cancelBtn: "取消",
197
- onConfirm: async () => {
198
- if (dialog && typeof dialog.setConfirmLoading === "function") {
199
- dialog.setConfirmLoading(true);
200
- }
129
+ function onReload(reload: (options: { keepSelection?: boolean }) => void): void {
130
+ reload({ keepSelection: true });
131
+ }
201
132
 
202
- try {
203
- await $Http.post("/addon/admin/role/del", {
204
- id: row.id
205
- });
206
- MessagePlugin.success("删除成功");
207
- destroy();
208
- await $Method.apiRoleList();
209
- } catch (error) {
210
- MessagePlugin.error("删除失败");
211
- } finally {
212
- if (dialog && typeof dialog.setConfirmLoading === "function") {
213
- dialog.setConfirmLoading(false);
214
- }
215
- }
216
- },
217
- onClose: () => {
218
- destroy();
219
- }
220
- });
221
- },
133
+ function onDialogSuccess(reload: (options: { keepSelection?: boolean }) => void): void {
134
+ reload({ keepSelection: true });
135
+ }
222
136
 
223
- // 刷新
224
- handleRefresh() {
225
- $Method.apiRoleList();
226
- },
137
+ function getPathCount(value: unknown): number {
138
+ if (!Array.isArray(value)) return 0;
139
+ return value.filter((p) => typeof p === "string" && p.trim().length > 0).length;
140
+ }
227
141
 
228
- // 分页改变
229
- onPageChange({ currentPage }) {
230
- $Data.pagerConfig.currentPage = currentPage;
231
- $Method.apiRoleList();
232
- },
142
+ function onAction(command: string, rowData: Record<string, unknown>): void {
143
+ $Data.actionType = command;
233
144
 
234
- // 每页条数改变
235
- handleSizeChange({ pageSize }) {
236
- $Data.pagerConfig.limit = pageSize;
237
- $Data.pagerConfig.currentPage = 1;
238
- $Method.apiRoleList();
239
- },
145
+ if (command === "add") {
146
+ $Data.rowData = {};
147
+ } else {
148
+ $Data.rowData = Object.assign({}, rowData);
149
+ }
240
150
 
241
- // 高亮行变化
242
- onActiveChange(value, context) {
243
- // 禁止取消高亮:如果新值为空,保持当前选中
244
- if (value.length === 0 && $Data.activeRowKeys.length > 0) {
245
- return;
246
- }
247
- $Data.activeRowKeys = value;
248
- // 更新当前高亮的行数据
249
- if (context.activeRowList && context.activeRowList.length > 0) {
250
- $Data.currentRow = context.activeRowList[0].row;
251
- }
252
- },
151
+ if (command === "add" || command === "upd") {
152
+ $Data.editVisible = true;
153
+ return;
154
+ }
253
155
 
254
- // 操作菜单点击
255
- onAction(command, rowData) {
256
- $Data.actionType = command;
257
- $Data.rowData = rowData;
258
- if (command === "add" || command === "upd") {
259
- $Data.editVisible = true;
260
- } else if (command === "menu") {
261
- $Data.menuVisible = true;
262
- } else if (command === "api") {
263
- $Data.apiVisible = true;
264
- } else if (command === "del") {
265
- $Method.apiRoleDel(rowData);
266
- }
156
+ if (command === "menu") {
157
+ $Data.menuVisible = true;
158
+ return;
267
159
  }
268
- };
269
160
 
270
- $Method.initData();
161
+ if (command === "api") {
162
+ $Data.apiVisible = true;
163
+ }
164
+ }
165
+
166
+ function onDropdownAction(data: unknown, rowData: Record<string, unknown>, deleteRow: (row: Record<string, unknown>) => void): void {
167
+ const record = data as Record<string, unknown>;
168
+ const rawValue = record && record["value"] ? record["value"] : "";
169
+ const cmd = rawValue ? String(rawValue) : "";
170
+ if (cmd === "del") {
171
+ deleteRow(rowData);
172
+ return;
173
+ }
174
+ onAction(cmd, rowData);
175
+ }
271
176
  </script>
272
177
 
273
178
  <style scoped lang="scss">
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "allowJs": true,
6
+ "types": ["vite/client", "unplugin-icons/types/vue"],
7
+ "baseUrl": ".",
8
+ "paths": {
9
+ "@/*": ["../../admin/src/*"]
10
+ }
11
+ },
12
+ "include": ["**/*.vue", "**/*.ts", "**/*.d.ts"],
13
+ "exclude": ["node_modules", "dist", "logs", "temp"]
14
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@befly-addon/admin",
3
- "version": "1.8.2",
4
- "gitHead": "0e9cfa6f2979b12725e06e34936737738a219747",
3
+ "version": "1.8.5",
4
+ "gitHead": "607fe5ea9c06653ec6da8a9e4175d1f9c7b98c13",
5
5
  "private": false,
6
6
  "description": "Befly - 管理后台功能组件",
7
7
  "keywords": [
@@ -54,7 +54,7 @@
54
54
  "ua-parser-js": "^2.0.8"
55
55
  },
56
56
  "devDependencies": {
57
- "befly": "3.16.2"
57
+ "befly": "^3.16.4"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "befly": "^3.14.0"