@befly-addon/admin 1.8.2 → 1.8.4

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.
@@ -56,7 +56,10 @@ const $Prop = defineProps({
56
56
  }
57
57
  });
58
58
 
59
- const $Emit = defineEmits(["update:modelValue", "success"]);
59
+ const $Emit = defineEmits<{
60
+ (e: "update:modelValue", value: boolean): void;
61
+ (e: "success"): void;
62
+ }>();
60
63
 
61
64
  const $Data = $ref({
62
65
  visible: false,
@@ -60,7 +60,10 @@ const $Prop = defineProps({
60
60
  }
61
61
  });
62
62
 
63
- const $Emit = defineEmits(["update:modelValue", "success"]);
63
+ const $Emit = defineEmits<{
64
+ (e: "update:modelValue", value: boolean): void;
65
+ (e: "success"): void;
66
+ }>();
64
67
 
65
68
  // 表单引用
66
69
  const $From = $shallowRef({
@@ -57,7 +57,10 @@ const $Prop = defineProps({
57
57
  }
58
58
  });
59
59
 
60
- const $Emit = defineEmits(["update:modelValue", "success"]);
60
+ const $Emit = defineEmits<{
61
+ (e: "update:modelValue", value: boolean): void;
62
+ (e: "success"): void;
63
+ }>();
61
64
 
62
65
  const $Data = $ref({
63
66
  visible: false,
@@ -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
+ <PagedTableDetailPage 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="$Method.onAdd">
5
+ <template #icon>
6
+ <ILucidePlus />
7
+ </template>
8
+ </TButton>
9
+ </template>
10
+
11
+ <template #toolRight="scope">
12
+ <TButton shape="circle" @click="$Method.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
+ {{ $Method.getPathCount(row.menus) }}
27
+ </template>
28
+
29
+ <template #apiCount="{ row }">
30
+ {{ $Method.getPathCount(row.apis) }}
31
+ </template>
32
+
33
+ <template #operation="{ row, deleteRow }">
34
+ <TDropdown trigger="click" placement="bottom-right" @click="$Method.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="$Method.onDialogSuccess(scope.reload)" />
63
+
64
+ <!-- 菜单权限对话框组件 -->
65
+ <MenuDialog v-if="$Data.menuVisible" v-model="$Data.menuVisible" :row-data="$Data.rowData" @success="$Method.onDialogSuccess(scope.reload)" />
66
+
67
+ <!-- 接口权限对话框组件 -->
68
+ <ApiDialog v-if="$Data.apiVisible" v-model="$Data.apiVisible" :row-data="$Data.rowData" @success="$Method.onDialogSuccess(scope.reload)" />
69
+ </template>
70
+ </PagedTableDetailPage>
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 PagedTableDetailPage from "@/components/PagedTableDetailPage.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,
@@ -136,138 +124,55 @@ const $Data = $ref({
136
124
 
137
125
  // 方法
138
126
  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;
127
+ onAdd() {
128
+ $Method.onAction("add", {});
142
129
  },
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
130
 
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
- }
131
+ onReload(reload) {
132
+ reload({ keepSelection: true });
176
133
  },
177
134
 
178
- // 删除角色
179
- async apiRoleDel(row) {
180
- let dialog = null;
181
- let destroyed = false;
182
-
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
- }
201
-
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
- });
135
+ onDialogSuccess(reload) {
136
+ reload({ keepSelection: true });
221
137
  },
222
138
 
223
- // 刷新
224
- handleRefresh() {
225
- $Method.apiRoleList();
139
+ getPathCount(value) {
140
+ if (!Array.isArray(value)) return 0;
141
+ return value.filter((p) => typeof p === "string" && p.trim().length > 0).length;
226
142
  },
143
+ onAction(command, rowData) {
144
+ $Data.actionType = command;
227
145
 
228
- // 分页改变
229
- onPageChange({ currentPage }) {
230
- $Data.pagerConfig.currentPage = currentPage;
231
- $Method.apiRoleList();
232
- },
146
+ if (command === "add") {
147
+ $Data.rowData = {};
148
+ } else {
149
+ $Data.rowData = Object.assign({}, rowData);
150
+ }
233
151
 
234
- // 每页条数改变
235
- handleSizeChange({ pageSize }) {
236
- $Data.pagerConfig.limit = pageSize;
237
- $Data.pagerConfig.currentPage = 1;
238
- $Method.apiRoleList();
239
- },
152
+ if (command === "add" || command === "upd") {
153
+ $Data.editVisible = true;
154
+ return;
155
+ }
240
156
 
241
- // 高亮行变化
242
- onActiveChange(value, context) {
243
- // 禁止取消高亮:如果新值为空,保持当前选中
244
- if (value.length === 0 && $Data.activeRowKeys.length > 0) {
157
+ if (command === "menu") {
158
+ $Data.menuVisible = true;
245
159
  return;
246
160
  }
247
- $Data.activeRowKeys = value;
248
- // 更新当前高亮的行数据
249
- if (context.activeRowList && context.activeRowList.length > 0) {
250
- $Data.currentRow = context.activeRowList[0].row;
161
+
162
+ if (command === "api") {
163
+ $Data.apiVisible = true;
251
164
  }
252
165
  },
253
166
 
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);
167
+ onDropdownAction(data, rowData, deleteRow) {
168
+ const cmd = data && data.value ? String(data.value) : "";
169
+ if (cmd === "del") {
170
+ deleteRow(rowData);
171
+ return;
266
172
  }
173
+ $Method.onAction(cmd, rowData);
267
174
  }
268
175
  };
269
-
270
- $Method.initData();
271
176
  </script>
272
177
 
273
178
  <style scoped lang="scss">
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.4",
4
+ "gitHead": "9823cc29996ba9950dd08bfd72856e3b65815039",
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"