@befly-addon/admin 1.0.54 → 1.0.56

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.
Files changed (82) hide show
  1. package/apis/admin/cacheRefresh.ts +17 -14
  2. package/apis/admin/ins.ts +11 -15
  3. package/apis/admin/upd.ts +1 -13
  4. package/apis/api/all.ts +1 -1
  5. package/apis/api/list.ts +30 -0
  6. package/apis/auth/login.ts +51 -7
  7. package/apis/dashboard/serviceStatus.ts +2 -2
  8. package/apis/dashboard/systemResources.ts +1 -1
  9. package/apis/dict/all.ts +1 -1
  10. package/apis/dict/del.ts +1 -1
  11. package/apis/dict/detail.ts +2 -2
  12. package/apis/dict/ins.ts +1 -1
  13. package/apis/dict/upd.ts +1 -1
  14. package/apis/email/config.ts +16 -0
  15. package/apis/email/logList.ts +13 -0
  16. package/apis/email/send.ts +42 -0
  17. package/apis/email/verify.ts +12 -0
  18. package/apis/loginLog/list.ts +13 -0
  19. package/apis/menu/all.ts +2 -2
  20. package/apis/menu/list.ts +1 -1
  21. package/apis/operateLog/list.ts +13 -0
  22. package/apis/role/del.ts +2 -2
  23. package/apis/role/save.ts +2 -2
  24. package/apis/sysConfig/all.ts +12 -0
  25. package/apis/sysConfig/del.ts +30 -0
  26. package/apis/sysConfig/get.ts +31 -0
  27. package/apis/sysConfig/ins.ts +38 -0
  28. package/apis/sysConfig/list.ts +14 -0
  29. package/apis/sysConfig/upd.ts +50 -0
  30. package/package.json +14 -3
  31. package/plugins/email.ts +206 -0
  32. package/styles/variables.scss +121 -60
  33. package/tables/admin.json +0 -15
  34. package/tables/emailLog.json +69 -0
  35. package/tables/loginLog.json +96 -0
  36. package/tables/operateLog.json +82 -0
  37. package/tables/role.json +1 -1
  38. package/tables/sysConfig.json +53 -0
  39. package/views/403_1/meta.json +4 -0
  40. package/views/{dict → config/dict}/components/edit.vue +7 -5
  41. package/views/config/dict/index.vue +205 -0
  42. package/views/config/dict/meta.json +4 -0
  43. package/views/config/meta.json +4 -0
  44. package/views/config/system/components/edit.vue +179 -0
  45. package/views/config/system/index.vue +256 -0
  46. package/views/config/system/meta.json +4 -0
  47. package/views/index/index.vue +46 -9
  48. package/views/index/meta.json +4 -0
  49. package/views/log/email/index.vue +285 -0
  50. package/views/log/email/meta.json +4 -0
  51. package/views/log/login/index.vue +180 -0
  52. package/views/log/login/meta.json +4 -0
  53. package/views/log/meta.json +4 -0
  54. package/views/log/operate/index.vue +242 -0
  55. package/views/log/operate/meta.json +4 -0
  56. package/views/login_1/meta.json +4 -0
  57. package/views/{admin → people/admin}/components/edit.vue +23 -35
  58. package/views/{admin → people/admin}/index.vue +37 -96
  59. package/views/people/admin/meta.json +4 -0
  60. package/views/people/meta.json +4 -0
  61. package/views/permission/api/index.vue +143 -0
  62. package/views/permission/api/meta.json +4 -0
  63. package/views/permission/menu/index.vue +146 -0
  64. package/views/permission/menu/meta.json +4 -0
  65. package/views/permission/meta.json +4 -0
  66. package/views/{role → permission/role}/components/api.vue +22 -51
  67. package/views/{role → permission/role}/components/edit.vue +14 -15
  68. package/views/{role → permission/role}/components/menu.vue +11 -38
  69. package/views/permission/role/index.vue +227 -0
  70. package/views/permission/role/meta.json +4 -0
  71. package/apis/menu/del.ts +0 -31
  72. package/apis/menu/ins.ts +0 -19
  73. package/apis/menu/upd.ts +0 -27
  74. package/views/dict/index.vue +0 -162
  75. package/views/menu/components/edit.vue +0 -145
  76. package/views/menu/index.vue +0 -173
  77. package/views/role/index.vue +0 -184
  78. /package/views/{403 → 403_1}/index.vue +0 -0
  79. /package/views/{login → login_1}/components/emailLoginForm.vue +0 -0
  80. /package/views/{login → login_1}/components/registerForm.vue +0 -0
  81. /package/views/{login → login_1}/components/welcomePanel.vue +0 -0
  82. /package/views/{login/index_1.vue → login_1/index.vue} +0 -0
@@ -0,0 +1,96 @@
1
+ {
2
+ "adminId": {
3
+ "name": "管理员ID",
4
+ "type": "number",
5
+ "min": 0,
6
+ "max": 999999999999999,
7
+ "index": true
8
+ },
9
+ "username": {
10
+ "name": "用户名",
11
+ "type": "string",
12
+ "min": 1,
13
+ "max": 50
14
+ },
15
+ "nickname": {
16
+ "name": "昵称",
17
+ "type": "string",
18
+ "max": 50
19
+ },
20
+ "ip": {
21
+ "name": "登录IP",
22
+ "type": "string",
23
+ "max": 50,
24
+ "index": true
25
+ },
26
+ "userAgent": {
27
+ "name": "用户代理",
28
+ "type": "string",
29
+ "max": 500
30
+ },
31
+ "browserName": {
32
+ "name": "浏览器名称",
33
+ "type": "string",
34
+ "max": 50
35
+ },
36
+ "browserVersion": {
37
+ "name": "浏览器版本",
38
+ "type": "string",
39
+ "max": 50
40
+ },
41
+ "osName": {
42
+ "name": "操作系统",
43
+ "type": "string",
44
+ "max": 50
45
+ },
46
+ "osVersion": {
47
+ "name": "系统版本",
48
+ "type": "string",
49
+ "max": 50
50
+ },
51
+ "deviceType": {
52
+ "name": "设备类型",
53
+ "type": "string",
54
+ "max": 20
55
+ },
56
+ "deviceVendor": {
57
+ "name": "设备厂商",
58
+ "type": "string",
59
+ "max": 50
60
+ },
61
+ "deviceModel": {
62
+ "name": "设备型号",
63
+ "type": "string",
64
+ "max": 50
65
+ },
66
+ "engineName": {
67
+ "name": "引擎名称",
68
+ "type": "string",
69
+ "max": 50
70
+ },
71
+ "cpuArchitecture": {
72
+ "name": "CPU架构",
73
+ "type": "string",
74
+ "max": 20
75
+ },
76
+ "loginTime": {
77
+ "name": "登录时间",
78
+ "type": "number",
79
+ "min": 0,
80
+ "max": 9999999999999,
81
+ "index": true
82
+ },
83
+ "loginResult": {
84
+ "name": "登录结果",
85
+ "type": "number",
86
+ "min": 0,
87
+ "max": 1,
88
+ "default": 1,
89
+ "index": true
90
+ },
91
+ "failReason": {
92
+ "name": "失败原因",
93
+ "type": "string",
94
+ "max": 200
95
+ }
96
+ }
@@ -0,0 +1,82 @@
1
+ {
2
+ "adminId": {
3
+ "name": "管理员ID",
4
+ "type": "number",
5
+ "min": 0,
6
+ "max": 999999999999999,
7
+ "index": true
8
+ },
9
+ "username": {
10
+ "name": "用户名",
11
+ "type": "string",
12
+ "min": 1,
13
+ "max": 50
14
+ },
15
+ "nickname": {
16
+ "name": "昵称",
17
+ "type": "string",
18
+ "max": 50
19
+ },
20
+ "ip": {
21
+ "name": "操作IP",
22
+ "type": "string",
23
+ "max": 50,
24
+ "index": true
25
+ },
26
+ "module": {
27
+ "name": "操作模块",
28
+ "type": "string",
29
+ "max": 50,
30
+ "index": true
31
+ },
32
+ "action": {
33
+ "name": "操作类型",
34
+ "type": "string",
35
+ "max": 50,
36
+ "index": true
37
+ },
38
+ "method": {
39
+ "name": "请求方法",
40
+ "type": "string",
41
+ "max": 10
42
+ },
43
+ "path": {
44
+ "name": "请求路径",
45
+ "type": "string",
46
+ "max": 200
47
+ },
48
+ "params": {
49
+ "name": "请求参数",
50
+ "type": "text"
51
+ },
52
+ "result": {
53
+ "name": "操作结果",
54
+ "type": "number",
55
+ "min": 0,
56
+ "max": 1,
57
+ "default": 1,
58
+ "comment": "1成功 0失败"
59
+ },
60
+ "response": {
61
+ "name": "响应内容",
62
+ "type": "text"
63
+ },
64
+ "duration": {
65
+ "name": "耗时毫秒",
66
+ "type": "number",
67
+ "min": 0,
68
+ "max": 999999999
69
+ },
70
+ "operateTime": {
71
+ "name": "操作时间",
72
+ "type": "number",
73
+ "min": 0,
74
+ "max": 9999999999999,
75
+ "index": true
76
+ },
77
+ "remark": {
78
+ "name": "备注",
79
+ "type": "string",
80
+ "max": 500
81
+ }
82
+ }
package/tables/role.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "min": 2,
13
13
  "max": 50,
14
14
  "index": true,
15
- "regexp": "@alphanumeric_"
15
+ "regexp": "@alphanumericDash_"
16
16
  },
17
17
  "description": {
18
18
  "name": "角色描述",
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": {
3
+ "name": "配置名称",
4
+ "type": "string",
5
+ "min": 2,
6
+ "max": 50
7
+ },
8
+ "code": {
9
+ "name": "配置代码",
10
+ "type": "string",
11
+ "min": 2,
12
+ "max": 100,
13
+ "unique": true,
14
+ "regexp": "@alphanumeric_"
15
+ },
16
+ "value": {
17
+ "name": "配置值",
18
+ "type": "text"
19
+ },
20
+ "valueType": {
21
+ "name": "值类型",
22
+ "type": "string",
23
+ "max": 20,
24
+ "default": "string",
25
+ "comment": "string number boolean json"
26
+ },
27
+ "group": {
28
+ "name": "配置分组",
29
+ "type": "string",
30
+ "max": 50,
31
+ "index": true
32
+ },
33
+ "sort": {
34
+ "name": "排序",
35
+ "type": "number",
36
+ "min": 0,
37
+ "max": 9999,
38
+ "default": 0
39
+ },
40
+ "isSystem": {
41
+ "name": "是否系统配置",
42
+ "type": "number",
43
+ "min": 0,
44
+ "max": 1,
45
+ "default": 0,
46
+ "comment": "1是 0否"
47
+ },
48
+ "description": {
49
+ "name": "描述说明",
50
+ "type": "string",
51
+ "max": 500
52
+ }
53
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "403",
3
+ "order": 101
4
+ }
@@ -28,7 +28,7 @@
28
28
  </TForm>
29
29
  <template #footer>
30
30
  <TButton @click="$Method.onClose">取消</TButton>
31
- <TButton theme="primary" @click="$Method.onSubmit">确定</TButton>
31
+ <TButton theme="primary" :loading="$Data.submitting" @click="$Method.onSubmit">确定</TButton>
32
32
  </template>
33
33
  </TDialog>
34
34
  </template>
@@ -62,6 +62,7 @@ const $From = $shallowRef({
62
62
 
63
63
  const $Data = $ref({
64
64
  visible: false,
65
+ submitting: false,
65
66
  formData: {
66
67
  id: 0,
67
68
  name: '',
@@ -127,16 +128,17 @@ const $Method = {
127
128
  const valid = await $From.form.validate();
128
129
  if (!valid) return;
129
130
 
131
+ $Data.submitting = true;
130
132
  const res = await $Http($Prop.actionType === 'add' ? '/addon/admin/dictIns' : '/addon/admin/dictUpd', $Data.formData);
131
133
 
132
- MessagePlugin.info({
133
- message: $Prop.actionType === 'add' ? '添加成功' : '编辑成功',
134
- status: 'success'
135
- });
134
+ MessagePlugin.success($Prop.actionType === 'add' ? '添加成功' : '编辑成功');
136
135
  $Method.onClose();
137
136
  $Emit('success');
138
137
  } catch (error) {
139
138
  console.error('提交失败:', error);
139
+ MessagePlugin.error('提交失败');
140
+ } finally {
141
+ $Data.submitting = false;
140
142
  }
141
143
  }
142
144
  };
@@ -0,0 +1,205 @@
1
+ <template>
2
+ <div class="page-dict 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
+ <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 :data="$Data.dictList" :columns="$Data.columns" :loading="$Data.loading" :active-row-keys="$Data.activeRowKeys" row-key="id" height="calc(100vh - 94px)" active-row-type="single" @active-change="$Method.onActiveChange">
22
+ <template #state="{ row }">
23
+ <TTag v-if="row.state === 1" shape="round" theme="success" variant="light-outline">正常</TTag>
24
+ <TTag v-else-if="row.state === 2" shape="round" theme="warning" variant="light-outline">禁用</TTag>
25
+ <TTag v-else shape="round" theme="danger" variant="light-outline">已删除</TTag>
26
+ </template>
27
+ <template #operation="{ row }">
28
+ <TDropdown trigger="click" placement="bottom-right" @click="(data) => $Method.onAction(data.value, row)">
29
+ <TButton theme="primary" size="small">
30
+ 操作
31
+ <template #suffix> <t-icon name="chevron-down" size="16" /></template>
32
+ </TButton>
33
+ <TDropdownMenu slot="dropdown">
34
+ <TDropdownItem value="upd">
35
+ <ILucidePencil />
36
+ 编辑
37
+ </TDropdownItem>
38
+ <TDropdownItem value="del" :divider="true">
39
+ <ILucideTrash2 style="width: 14px; height: 14px; margin-right: 6px" />
40
+ 删除
41
+ </TDropdownItem>
42
+ </TDropdownMenu>
43
+ </TDropdown>
44
+ </template>
45
+ </TTable>
46
+ </div>
47
+
48
+ <div class="main-detail">
49
+ <DetailPanel :data="$Data.currentRow" :fields="$Data.columns" />
50
+ </div>
51
+ </div>
52
+
53
+ <div class="main-page">
54
+ <TPagination :current-page="$Data.pagerConfig.currentPage" :page-size="$Data.pagerConfig.limit" :total="$Data.pagerConfig.total" @current-change="$Method.onPageChange" @page-size-change="$Method.handleSizeChange" />
55
+ </div>
56
+
57
+ <!-- 编辑对话框组件 -->
58
+ <EditDialog v-if="$Data.editVisible" v-model="$Data.editVisible" :action-type="$Data.actionType" :row-data="$Data.rowData" @success="$Method.apiDictList" />
59
+ </div>
60
+ </template>
61
+
62
+ <script setup>
63
+ 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';
64
+ import ILucidePlus from '~icons/lucide/plus';
65
+ import ILucideRotateCw from '~icons/lucide/rotate-cw';
66
+ import ILucidePencil from '~icons/lucide/pencil';
67
+ import ILucideTrash2 from '~icons/lucide/trash-2';
68
+ import EditDialog from './components/edit.vue';
69
+ import DetailPanel from '@/components/DetailPanel.vue';
70
+ import { $Http } from '@/plugins/http';
71
+ import { withDefaultColumns } from '@/utils';
72
+
73
+ // 响应式数据
74
+ const $Data = $ref({
75
+ dictList: [],
76
+ loading: false,
77
+ activeRowKeys: [],
78
+ currentRow: null,
79
+ columns: withDefaultColumns([
80
+ { colKey: 'index', title: '序号' },
81
+ { colKey: 'name', title: '字典名称' },
82
+ { colKey: 'code', title: '字典代码' },
83
+ { colKey: 'value', title: '字典值' },
84
+ { colKey: 'pid', title: '父级ID' },
85
+ { colKey: 'sort', title: '排序' },
86
+ { colKey: 'description', title: '描述' },
87
+ { colKey: 'state', title: '状态' },
88
+ { colKey: 'operation', title: '操作' }
89
+ ]),
90
+ pagerConfig: {
91
+ currentPage: 1,
92
+ limit: 30,
93
+ total: 0,
94
+ align: 'right',
95
+ layout: 'total, prev, pager, next, jumper'
96
+ },
97
+ editVisible: false,
98
+ actionType: 'add',
99
+ rowData: {}
100
+ });
101
+
102
+ // 方法
103
+ const $Method = {
104
+ async initData() {
105
+ await $Method.apiDictList();
106
+ },
107
+
108
+ // 加载字典列表
109
+ async apiDictList() {
110
+ $Data.loading = true;
111
+ try {
112
+ const res = await $Http('/addon/admin/dict/list', {
113
+ page: $Data.pagerConfig.currentPage,
114
+ limit: $Data.pagerConfig.limit
115
+ });
116
+ $Data.dictList = res.data.lists || [];
117
+ $Data.pagerConfig.total = res.data.total || 0;
118
+
119
+ // 自动选中并高亮第一行
120
+ if ($Data.dictList.length > 0) {
121
+ $Data.currentRow = $Data.dictList[0];
122
+ $Data.activeRowKeys = [$Data.dictList[0].id];
123
+ } else {
124
+ $Data.currentRow = null;
125
+ $Data.activeRowKeys = [];
126
+ }
127
+ } catch (error) {
128
+ console.error('加载字典列表失败:', error);
129
+ MessagePlugin.error('加载数据失败');
130
+ } finally {
131
+ $Data.loading = false;
132
+ }
133
+ },
134
+
135
+ // 删除字典
136
+ async apiDictDel(row) {
137
+ DialogPlugin.confirm({
138
+ header: '确认删除',
139
+ body: `确定要删除字典“${row.name}” 吗?`,
140
+ status: 'warning'
141
+ }).then(async () => {
142
+ try {
143
+ const res = await $Http('/addon/admin/dict/del', { id: row.id });
144
+ if (res.code === 0) {
145
+ MessagePlugin.success('删除成功');
146
+ $Method.apiDictList();
147
+ } else {
148
+ MessagePlugin.error(res.msg || '删除失败');
149
+ }
150
+ } catch (error) {
151
+ console.error('删除失败:', error);
152
+ MessagePlugin.error('删除失败');
153
+ }
154
+ });
155
+ },
156
+
157
+ // 刷新
158
+ handleRefresh() {
159
+ $Method.apiDictList();
160
+ },
161
+
162
+ // 分页改变
163
+ onPageChange({ currentPage }) {
164
+ $Data.pagerConfig.currentPage = currentPage;
165
+ $Method.apiDictList();
166
+ },
167
+
168
+ // 每页条数改变
169
+ handleSizeChange({ pageSize }) {
170
+ $Data.pagerConfig.limit = pageSize;
171
+ $Data.pagerConfig.currentPage = 1;
172
+ $Method.apiDictList();
173
+ },
174
+
175
+ // 高亮行变化
176
+ onActiveChange(value, context) {
177
+ // 禁止取消高亮:如果新值为空,保持当前选中
178
+ if (value.length === 0 && $Data.activeRowKeys.length > 0) {
179
+ return;
180
+ }
181
+ $Data.activeRowKeys = value;
182
+ // 更新当前高亮的行数据
183
+ if (context.activeRowList && context.activeRowList.length > 0) {
184
+ $Data.currentRow = context.activeRowList[0].row;
185
+ }
186
+ },
187
+
188
+ // 操作菜单点击
189
+ onAction(command, rowData) {
190
+ $Data.actionType = command;
191
+ $Data.rowData = rowData;
192
+ if (command === 'add' || command === 'upd') {
193
+ $Data.editVisible = true;
194
+ } else if (command === 'del') {
195
+ $Method.apiDictDel(rowData);
196
+ }
197
+ }
198
+ };
199
+
200
+ $Method.initData();
201
+ </script>
202
+
203
+ <style scoped lang="scss">
204
+ // 样式继承自全局 page-table
205
+ </style>
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "字典配置",
3
+ "order": 1
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "配置管理",
3
+ "order": 30
4
+ }
@@ -0,0 +1,179 @@
1
+ <template>
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)">
4
+ <TFormItem label="配置名称" prop="name">
5
+ <TInput v-model="$Data.formData.name" placeholder="请输入配置名称" :disabled="$Data.isSystem" />
6
+ </TFormItem>
7
+ <TFormItem label="配置代码" prop="code">
8
+ <TInput v-model="$Data.formData.code" placeholder="请输入配置代码,如:site_name" :disabled="$Prop.actionType === 'upd'" />
9
+ </TFormItem>
10
+ <TFormItem label="配置值" prop="value">
11
+ <TTextarea v-if="$Data.formData.valueType === 'json' || $Data.formData.valueType === 'text'" v-model="$Data.formData.value" placeholder="请输入配置值" :autosize="{ minRows: 3, maxRows: 8 }" />
12
+ <TInput v-else v-model="$Data.formData.value" placeholder="请输入配置值" />
13
+ </TFormItem>
14
+ <TFormItem label="值类型" prop="valueType">
15
+ <TSelect v-model="$Data.formData.valueType" :disabled="$Data.isSystem">
16
+ <TOption label="字符串" value="string" />
17
+ <TOption label="数字" value="number" />
18
+ <TOption label="布尔" value="boolean" />
19
+ <TOption label="JSON" value="json" />
20
+ </TSelect>
21
+ </TFormItem>
22
+ <TFormItem label="配置分组" prop="group">
23
+ <TSelect v-model="$Data.formData.group" placeholder="请选择分组" clearable :disabled="$Data.isSystem">
24
+ <TOption v-for="item in $Data2.groupOptions" :key="item" :label="item" :value="item" />
25
+ </TSelect>
26
+ </TFormItem>
27
+ <TFormItem label="排序" prop="sort">
28
+ <TInputNumber v-model="$Data.formData.sort" :min="0" :max="9999" :disabled="$Data.isSystem" />
29
+ </TFormItem>
30
+ <TFormItem label="描述说明" prop="description">
31
+ <TTextarea v-model="$Data.formData.description" placeholder="请输入描述说明" :autosize="{ minRows: 2, maxRows: 4 }" :disabled="$Data.isSystem" />
32
+ </TFormItem>
33
+ <TFormItem v-if="$Prop.actionType === 'upd' && !$Data.isSystem" label="状态" prop="state">
34
+ <TRadioGroup v-model="$Data.formData.state">
35
+ <TRadio :value="1">正常</TRadio>
36
+ <TRadio :value="2">禁用</TRadio>
37
+ </TRadioGroup>
38
+ </TFormItem>
39
+ </TForm>
40
+ <template #footer>
41
+ <TButton @click="$Method.onClose">取消</TButton>
42
+ <TButton theme="primary" :loading="$Data.submitting" @click="$Method.onSubmit">确定</TButton>
43
+ </template>
44
+ </TDialog>
45
+ </template>
46
+
47
+ <script setup>
48
+ import { watch } from 'vue';
49
+ import { Dialog as TDialog, Form as TForm, FormItem as TFormItem, Input as TInput, Textarea as TTextarea, InputNumber as TInputNumber, Select as TSelect, Option as TOption, RadioGroup as TRadioGroup, Radio as TRadio, Button as TButton, MessagePlugin } from 'tdesign-vue-next';
50
+ import { $Http } from '@/plugins/http';
51
+
52
+ const $Prop = defineProps({
53
+ modelValue: {
54
+ type: Boolean,
55
+ default: false
56
+ },
57
+ actionType: {
58
+ type: String,
59
+ default: 'add'
60
+ },
61
+ rowData: {
62
+ type: Object,
63
+ default: () => ({})
64
+ }
65
+ });
66
+
67
+ const $Emit = defineEmits(['update:modelValue', 'success']);
68
+
69
+ // 表单引用
70
+ const $Form = $shallowRef({
71
+ form: null
72
+ });
73
+
74
+ const $Data = $ref({
75
+ visible: false,
76
+ submitting: false,
77
+ isSystem: false,
78
+ formData: {
79
+ id: 0,
80
+ name: '',
81
+ code: '',
82
+ value: '',
83
+ valueType: 'string',
84
+ group: '',
85
+ sort: 0,
86
+ description: '',
87
+ state: 1
88
+ }
89
+ });
90
+
91
+ const $Data2 = $shallowRef({
92
+ formRules: {
93
+ name: [{ required: true, message: '请输入配置名称', trigger: 'blur' }],
94
+ code: [
95
+ { required: true, message: '请输入配置代码', trigger: 'blur' },
96
+ { pattern: /^[a-zA-Z0-9_]+$/, message: '配置代码只能包含字母、数字和下划线', trigger: 'blur' }
97
+ ],
98
+ value: [{ required: true, message: '请输入配置值', trigger: 'blur' }],
99
+ valueType: [{ required: true, message: '请选择值类型', trigger: 'change' }]
100
+ },
101
+ groupOptions: ['基础配置', '邮件配置', '存储配置', '安全配置', '其他']
102
+ });
103
+
104
+ // 方法集合
105
+ const $Method = {
106
+ async initData() {
107
+ $Method.onShow();
108
+ },
109
+
110
+ onShow() {
111
+ $Data.visible = true;
112
+ if ($Prop.actionType === 'upd' && $Prop.rowData) {
113
+ $Data.formData.id = $Prop.rowData.id || 0;
114
+ $Data.formData.name = $Prop.rowData.name || '';
115
+ $Data.formData.code = $Prop.rowData.code || '';
116
+ $Data.formData.value = $Prop.rowData.value || '';
117
+ $Data.formData.valueType = $Prop.rowData.valueType || 'string';
118
+ $Data.formData.group = $Prop.rowData.group || '';
119
+ $Data.formData.sort = $Prop.rowData.sort || 0;
120
+ $Data.formData.description = $Prop.rowData.description || '';
121
+ $Data.formData.state = $Prop.rowData.state || 1;
122
+ $Data.isSystem = $Prop.rowData.isSystem === 1;
123
+ } else {
124
+ $Data.formData = {
125
+ id: 0,
126
+ name: '',
127
+ code: '',
128
+ value: '',
129
+ valueType: 'string',
130
+ group: '',
131
+ sort: 0,
132
+ description: '',
133
+ state: 1
134
+ };
135
+ $Data.isSystem = false;
136
+ }
137
+ },
138
+
139
+ onClose() {
140
+ $Data.visible = false;
141
+ $Emit('update:modelValue', false);
142
+ },
143
+
144
+ async onSubmit() {
145
+ const valid = await $Form.form?.validate();
146
+ if (valid !== true) return;
147
+
148
+ $Data.submitting = true;
149
+ try {
150
+ const api = $Prop.actionType === 'upd' ? '/addon/admin/sysConfig/upd' : '/addon/admin/sysConfig/ins';
151
+ const res = await $Http(api, $Data.formData);
152
+
153
+ if (res.code === 0) {
154
+ MessagePlugin.success($Prop.actionType === 'upd' ? '编辑成功' : '添加成功');
155
+ $Emit('success');
156
+ $Method.onClose();
157
+ } else {
158
+ MessagePlugin.error(res.msg || '操作失败');
159
+ }
160
+ } catch (error) {
161
+ MessagePlugin.error('操作失败');
162
+ } finally {
163
+ $Data.submitting = false;
164
+ }
165
+ }
166
+ };
167
+
168
+ watch(
169
+ () => $Prop.modelValue,
170
+ (val) => {
171
+ if (val) {
172
+ $Method.initData();
173
+ }
174
+ },
175
+ { immediate: true }
176
+ );
177
+ </script>
178
+
179
+ <style scoped lang="scss"></style>