@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.
@@ -1,76 +1,53 @@
1
1
  <template>
2
- <div class="page-dict-type 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>
9
- </TButton>
10
- </div>
11
- <div class="right">
12
- <TInput v-model="$Data.searchKeyword" placeholder="搜索类型名称" clearable @enter="$Method.handleSearch" @clear="$Method.handleSearch">
13
- <template #suffix-icon>
14
- <ILucideSearch />
15
- </template>
16
- </TInput>
17
- <TButton shape="circle" @click="$Method.handleRefresh">
18
- <template #icon>
19
- <ILucideRotateCw />
20
- </template>
21
- </TButton>
22
- </div>
23
- </div>
24
- <div class="main-content">
25
- <div class="main-table">
26
- <TTable
27
- :data="$Data.tableData"
28
- :columns="$Data.columns"
29
- :loading="$Data.loading"
30
- :active-row-keys="$Data.activeRowKeys"
31
- row-key="id"
32
- height="calc(100vh - var(--search-height) - var(--pagination-height) - var(--layout-gap) * 4)"
33
- active-row-type="single"
34
- @active-change="$Method.onActiveChange"
35
- >
36
- <template #operation="{ row }">
37
- <TDropdown trigger="click" placement="bottom-right" @click="(data) => $Method.onAction(data.value, row)">
38
- <TButton theme="primary" size="small">
39
- 操作
40
- <template #suffix> <ILucideChevronDown /></template>
41
- </TButton>
42
- <TDropdownMenu slot="dropdown">
43
- <TDropdownItem value="upd">
44
- <ILucidePencil />
45
- 编辑
46
- </TDropdownItem>
47
- <TDropdownItem value="del" :divider="true">
48
- <ILucideTrash2 style="width: 14px; height: 14px; margin-right: 6px" />
49
- 删除
50
- </TDropdownItem>
51
- </TDropdownMenu>
52
- </TDropdown>
53
- </template>
54
- </TTable>
55
- </div>
2
+ <PagedTableDetailPage class="page-dict-type page-table" :columns="$Data.columns" :endpoints="$Data.endpoints">
3
+ <template #toolLeft>
4
+ <TButton theme="primary" @click="$Method.onAdd">
5
+ <template #icon>
6
+ <ILucidePlus />
7
+ </template>
8
+ </TButton>
9
+ </template>
56
10
 
57
- <div class="main-detail">
58
- <DetailPanel :data="$Data.currentRow" :fields="$Data.columns" />
59
- </div>
60
- </div>
11
+ <template #toolRight="scope">
12
+ <TInput v-model="$Data.searchKeyword" placeholder="搜索类型名称" clearable @enter="$Method.handleSearch(scope.reload)" @clear="$Method.handleSearch(scope.reload)">
13
+ <template #suffix-icon>
14
+ <ILucideSearch />
15
+ </template>
16
+ </TInput>
17
+ <TButton shape="circle" @click="$Method.handleRefresh(scope.reload)">
18
+ <template #icon>
19
+ <ILucideRotateCw />
20
+ </template>
21
+ </TButton>
22
+ </template>
61
23
 
62
- <div class="main-page">
63
- <TPagination :current-page="$Data.pagerConfig.currentPage" :page-size="$Data.pagerConfig.limit" :total="$Data.pagerConfig.total" @current-change="$Method.onPageChange" @page-size-change="$Method.handleSizeChange" />
64
- </div>
24
+ <template #operation="{ row, deleteRow }">
25
+ <TDropdown trigger="click" placement="bottom-right" @click="$Method.onDropdownAction($event, row, deleteRow)">
26
+ <TButton theme="primary" size="small">
27
+ 操作
28
+ <template #suffix> <ILucideChevronDown /></template>
29
+ </TButton>
30
+ <TDropdownMenu slot="dropdown">
31
+ <TDropdownItem value="upd">
32
+ <ILucidePencil />
33
+ 编辑
34
+ </TDropdownItem>
35
+ <TDropdownItem value="del" :divider="true">
36
+ <ILucideTrash2 style="width: 14px; height: 14px; margin-right: 6px" />
37
+ 删除
38
+ </TDropdownItem>
39
+ </TDropdownMenu>
40
+ </TDropdown>
41
+ </template>
65
42
 
66
- <EditDialog v-if="$Data.editVisible" v-model="$Data.editVisible" :action-type="$Data.actionType" :row-data="$Data.rowData" @success="$Method.apiDictTypeList" />
67
- </div>
43
+ <template #dialogs="scope">
44
+ <EditDialog v-if="$Data.editVisible" v-model="$Data.editVisible" :action-type="$Data.actionType" :row-data="$Data.rowData" @success="$Method.onDialogSuccess(scope.reload)" />
45
+ </template>
46
+ </PagedTableDetailPage>
68
47
  </template>
69
48
 
70
49
  <script setup lang="ts">
71
- import { onMounted } from "vue";
72
-
73
- import { Button as TButton, Table as TTable, Input as TInput, Dropdown as TDropdown, DropdownMenu as TDropdownMenu, DropdownItem as TDropdownItem, Pagination as TPagination, MessagePlugin, DialogPlugin } from "tdesign-vue-next";
50
+ import { Button as TButton, Dropdown as TDropdown, DropdownItem as TDropdownItem, DropdownMenu as TDropdownMenu, Input as TInput } from "tdesign-vue-next";
74
51
  import ILucidePlus from "~icons/lucide/plus";
75
52
  import ILucideRotateCw from "~icons/lucide/rotate-cw";
76
53
  import ILucideSearch from "~icons/lucide/search";
@@ -78,15 +55,10 @@ import ILucidePencil from "~icons/lucide/pencil";
78
55
  import ILucideTrash2 from "~icons/lucide/trash-2";
79
56
  import ILucideChevronDown from "~icons/lucide/chevron-down";
80
57
  import EditDialog from "./components/edit.vue";
81
- import DetailPanel from "@/components/DetailPanel.vue";
82
- import { $Http } from "@/plugins/http";
58
+ import PagedTableDetailPage from "@/components/PagedTableDetailPage.vue";
83
59
  import { withDefaultColumns } from "befly-shared/utils/withDefaultColumns";
84
60
 
85
61
  const $Data = $ref({
86
- tableData: [],
87
- loading: false,
88
- activeRowKeys: [],
89
- currentRow: null,
90
62
  searchKeyword: "",
91
63
  columns: withDefaultColumns([
92
64
  { colKey: "code", title: "类型代码" },
@@ -95,12 +67,31 @@ const $Data = $ref({
95
67
  { colKey: "sort", title: "排序" },
96
68
  { colKey: "operation", title: "操作" }
97
69
  ]),
98
- pagerConfig: {
99
- currentPage: 1,
100
- limit: 30,
101
- total: 0,
102
- align: "right",
103
- layout: "total, prev, pager, next, jumper"
70
+ endpoints: {
71
+ list: {
72
+ path: "/addon/admin/dictType/list",
73
+ dropValues: [0, ""],
74
+ dropKeyValue: {
75
+ keyword: [""]
76
+ },
77
+ buildData: () => {
78
+ return {
79
+ keyword: $Data.searchKeyword
80
+ };
81
+ }
82
+ },
83
+ delete: {
84
+ path: "/addon/admin/dictType/del",
85
+ idKey: "id",
86
+ confirm: (row) => {
87
+ return {
88
+ header: "确认删除",
89
+ body: `确认删除类型“${row.name}”吗?`,
90
+ confirmBtn: "删除",
91
+ status: "warning"
92
+ };
93
+ }
94
+ }
104
95
  },
105
96
  editVisible: false,
106
97
  actionType: "add",
@@ -108,130 +99,47 @@ const $Data = $ref({
108
99
  });
109
100
 
110
101
  const $Method = {
111
- async initData() {
112
- await $Method.apiDictTypeList();
102
+ onAdd() {
103
+ $Method.onAction("add", {});
113
104
  },
114
- async apiDictTypeList() {
115
- $Data.loading = true;
116
- try {
117
- const res = await $Http.post(
118
- "/addon/admin/dictType/list",
119
- {
120
- page: $Data.pagerConfig.currentPage,
121
- limit: $Data.pagerConfig.limit,
122
- keyword: $Data.searchKeyword
123
- },
124
- {
125
- dropValues: [0, ""],
126
- dropKeyValue: {
127
- page: [],
128
- limit: [],
129
- keyword: [""]
130
- }
131
- }
132
- );
133
- $Data.tableData = res.data.lists || [];
134
- $Data.pagerConfig.total = res.data.total || 0;
135
105
 
136
- if ($Data.tableData.length > 0) {
137
- $Data.currentRow = $Data.tableData[0];
138
- $Data.activeRowKeys = [$Data.tableData[0].id];
139
- } else {
140
- $Data.currentRow = null;
141
- $Data.activeRowKeys = [];
142
- }
143
- } catch (error) {
144
- MessagePlugin.error("加载数据失败");
145
- } finally {
146
- $Data.loading = false;
147
- }
106
+ onDialogSuccess(reload) {
107
+ reload({ keepSelection: true });
148
108
  },
149
- async apiDictTypeDel(row) {
150
- let dialog = null;
151
- let destroyed = false;
152
-
153
- const destroy = () => {
154
- if (destroyed) return;
155
- destroyed = true;
156
- if (dialog && typeof dialog.destroy === "function") {
157
- dialog.destroy();
158
- }
159
- };
160
-
161
- dialog = DialogPlugin.confirm({
162
- header: "确认删除",
163
- body: `确认删除类型“${row.name}”吗?`,
164
- status: "warning",
165
- confirmBtn: "删除",
166
- cancelBtn: "取消",
167
- onConfirm: async () => {
168
- if (dialog && typeof dialog.setConfirmLoading === "function") {
169
- dialog.setConfirmLoading(true);
170
- }
171
109
 
172
- try {
173
- await $Http.post("/addon/admin/dictType/del", {
174
- id: row.id
175
- });
176
- MessagePlugin.success("删除成功");
177
- destroy();
178
- await $Method.apiDictTypeList();
179
- } catch (error) {
180
- MessagePlugin.error("删除失败");
181
- } finally {
182
- if (dialog && typeof dialog.setConfirmLoading === "function") {
183
- dialog.setConfirmLoading(false);
184
- }
185
- }
186
- },
187
- onClose: () => {
188
- destroy();
189
- }
190
- });
110
+ handleSearch(reload) {
111
+ reload({ keepSelection: false, resetPage: true });
191
112
  },
192
- handleSearch() {
193
- $Data.pagerConfig.currentPage = 1;
194
- $Method.apiDictTypeList();
195
- },
196
- handleRefresh() {
113
+
114
+ handleRefresh(reload) {
197
115
  $Data.searchKeyword = "";
198
- $Data.pagerConfig.currentPage = 1;
199
- $Method.apiDictTypeList();
200
- },
201
- onPageChange({ currentPage }) {
202
- $Data.pagerConfig.currentPage = currentPage;
203
- $Method.apiDictTypeList();
204
- },
205
- handleSizeChange({ pageSize }) {
206
- $Data.pagerConfig.limit = pageSize;
207
- $Data.pagerConfig.currentPage = 1;
208
- $Method.apiDictTypeList();
209
- },
210
- onActiveChange(value, context) {
211
- if (value.length === 0 && $Data.activeRowKeys.length > 0) {
212
- return;
213
- }
214
- $Data.activeRowKeys = value;
215
- $Data.currentRow = context.currentRowData;
116
+ reload({ keepSelection: false, resetPage: true });
216
117
  },
118
+
217
119
  onAction(type, row) {
218
120
  if (type === "add") {
219
121
  $Data.actionType = "add";
220
122
  $Data.rowData = {};
221
123
  $Data.editVisible = true;
222
- } else if (type === "upd") {
124
+ return;
125
+ }
126
+
127
+ if (type === "upd") {
223
128
  $Data.actionType = "upd";
224
- $Data.rowData = { ...row };
129
+ $Data.rowData = Object.assign({}, row);
225
130
  $Data.editVisible = true;
226
- } else if (type === "del") {
227
- $Method.apiDictTypeDel(row);
228
131
  }
132
+ },
133
+
134
+ onDropdownAction(data, row, deleteRow) {
135
+ const cmd = data && data.value ? String(data.value) : "";
136
+ if (cmd === "del") {
137
+ deleteRow(row);
138
+ return;
139
+ }
140
+ $Method.onAction(cmd, row);
229
141
  }
230
142
  };
231
-
232
- onMounted(() => {
233
- $Method.initData();
234
- });
235
143
  </script>
236
144
 
237
145
  <style scoped lang="scss">
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <TDialog v-model:visible="$Data.visible" :title="$Prop.actionType === 'upd' ? '编辑配置' : '添加配置'" width="600px" :append-to-body="true" :show-footer="true" :esc-closable="false" top="10vh" @close="$Method.onClose">
3
- <TForm :model="$Data.formData" label-width="120px" label-position="left" :rules="$Data2.formRules" :ref="(el) => ($Form.form = el)">
3
+ <TForm :model="$Data.formData" label-width="120px" label-position="left" :rules="$Data2.formRules" :ref="(el) => ($From.form = el)">
4
4
  <TFormItem label="配置名称" prop="name">
5
5
  <TInput v-model="$Data.formData.name" placeholder="请输入配置名称" :disabled="$Data.isSystem" />
6
6
  </TFormItem>
@@ -63,10 +63,13 @@ const $Prop = defineProps({
63
63
  }
64
64
  });
65
65
 
66
- const $Emit = defineEmits(["update:modelValue", "success"]);
66
+ const $Emit = defineEmits<{
67
+ (e: "update:modelValue", value: boolean): void;
68
+ (e: "success"): void;
69
+ }>();
67
70
 
68
71
  // 表单引用
69
- const $Form = $shallowRef({
72
+ const $From = $shallowRef({
70
73
  form: null
71
74
  });
72
75
 
@@ -141,7 +144,7 @@ const $Method = {
141
144
  },
142
145
 
143
146
  async onSubmit() {
144
- const valid = await $Form.form?.validate();
147
+ const valid = await $From.form?.validate();
145
148
  if (valid !== true) return;
146
149
 
147
150
  $Data.submitting = true;