@befly-addon/admin 1.0.10 → 1.0.12

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 (38) hide show
  1. package/apis/api/all.ts +6 -11
  2. package/apis/menu/all.ts +9 -15
  3. package/apis/menu/list.ts +1 -1
  4. package/apis/menu/upd.ts +1 -2
  5. package/package.json +15 -4
  6. package/tables/menu.json +0 -13
  7. package/util.ts +1 -150
  8. package/views/403/index.vue +68 -0
  9. package/views/admin/components/edit.vue +150 -0
  10. package/views/admin/components/role.vue +138 -0
  11. package/views/admin/index.vue +179 -0
  12. package/views/dict/components/edit.vue +159 -0
  13. package/views/dict/index.vue +162 -0
  14. package/views/index/components/addonList.vue +127 -0
  15. package/views/index/components/environmentInfo.vue +99 -0
  16. package/views/index/components/operationLogs.vue +114 -0
  17. package/views/index/components/performanceMetrics.vue +150 -0
  18. package/views/index/components/quickActions.vue +27 -0
  19. package/views/index/components/serviceStatus.vue +183 -0
  20. package/views/index/components/systemNotifications.vue +132 -0
  21. package/views/index/components/systemOverview.vue +190 -0
  22. package/views/index/components/systemResources.vue +106 -0
  23. package/views/index/components/userInfo.vue +206 -0
  24. package/views/index/index.vue +29 -0
  25. package/views/login/components/emailLoginForm.vue +167 -0
  26. package/views/login/components/registerForm.vue +170 -0
  27. package/views/login/components/welcomePanel.vue +61 -0
  28. package/views/login/index.vue +191 -0
  29. package/views/menu/components/edit.vue +144 -0
  30. package/views/menu/index.vue +171 -0
  31. package/views/news/detail/index.vue +26 -0
  32. package/views/news/index.vue +26 -0
  33. package/views/role/components/api.vue +283 -0
  34. package/views/role/components/edit.vue +132 -0
  35. package/views/role/components/menu.vue +146 -0
  36. package/views/role/index.vue +179 -0
  37. package/views/user/index.vue +322 -0
  38. package/apis/dashboard/addonList.ts +0 -47
@@ -0,0 +1,144 @@
1
+ <template>
2
+ <tiny-dialog-box v-model:visible="$Data.visible" :title="$Prop.actionType === 'add' ? '添加菜单' : '编辑菜单'" width="600px" :append-to-body="true" :show-footer="true" top="10vh">
3
+ <tiny-form :model="$Data.formData" label-width="120px" label-position="left" :rules="$Data2.formRules" :ref="(el) => ($From.form = el)">
4
+ <tiny-form-item label="菜单名称" prop="name">
5
+ <tiny-input v-model="$Data.formData.name" placeholder="请输入菜单名称" />
6
+ </tiny-form-item>
7
+ <tiny-form-item label="菜单路径" prop="path">
8
+ <tiny-input v-model="$Data.formData.path" placeholder="请输入菜单路径,如:/user" />
9
+ </tiny-form-item>
10
+ <tiny-form-item label="图标" prop="icon">
11
+ <tiny-input v-model="$Data.formData.icon" placeholder="请输入图标名称,如:User" />
12
+ </tiny-form-item>
13
+ <tiny-form-item label="排序" prop="sort">
14
+ <tiny-numeric v-model="$Data.formData.sort" :min="0" :max="9999" />
15
+ </tiny-form-item>
16
+ <tiny-form-item label="状态" prop="state">
17
+ <tiny-radio-group v-model="$Data.formData.state">
18
+ <tiny-radio :label="1">正常</tiny-radio>
19
+ <tiny-radio :label="2">禁用</tiny-radio>
20
+ </tiny-radio-group>
21
+ </tiny-form-item>
22
+ </tiny-form>
23
+ <template #footer>
24
+ <tiny-button @click="$Method.onClose">取消</tiny-button>
25
+ <tiny-button type="primary" @click="$Method.onSubmit">确定</tiny-button>
26
+ </template>
27
+ </tiny-dialog-box>
28
+ </template>
29
+
30
+ <script setup>
31
+ import { ref, watch, shallowRef } from 'vue';
32
+ import { Modal } from '@opentiny/vue';
33
+
34
+ const $Prop = defineProps({
35
+ modelValue: {
36
+ type: Boolean,
37
+ default: false
38
+ },
39
+ actionType: {
40
+ type: String,
41
+ default: 'add'
42
+ },
43
+ rowData: {
44
+ type: Object,
45
+ default: {}
46
+ }
47
+ });
48
+
49
+ const $Emit = defineEmits(['update:modelValue', 'success']);
50
+
51
+ // 表单引用
52
+ const $From = $shallowRef({
53
+ form: null
54
+ });
55
+
56
+ const $Data = $ref({
57
+ visible: false,
58
+ formData: {
59
+ id: 0,
60
+ name: '',
61
+ path: '',
62
+ icon: '',
63
+ sort: 0,
64
+ pid: 0,
65
+ state: 1
66
+ }
67
+ });
68
+
69
+ const $Data2 = $shallowRef({
70
+ formRules: {
71
+ name: [{ required: true, message: '请输入菜单名称', trigger: 'blur' }],
72
+ path: [{ required: true, message: '请输入菜单路径', trigger: 'blur' }]
73
+ }
74
+ });
75
+
76
+ // 方法集合
77
+ const $Method = {
78
+ async initData() {
79
+ $Method.onShow();
80
+ },
81
+
82
+ onShow() {
83
+ $Data.visible = true;
84
+ if ($Prop.actionType === 'upd' && $Prop.rowData) {
85
+ $Data.formData.id = $Prop.rowData.id || 0;
86
+ $Data.formData.name = $Prop.rowData.name || '';
87
+ $Data.formData.path = $Prop.rowData.path ?? '';
88
+ $Data.formData.icon = $Prop.rowData.icon ?? '';
89
+ $Data.formData.sort = $Prop.rowData.sort ?? 0;
90
+ $Data.formData.state = $Prop.rowData.state ?? 1;
91
+ } else {
92
+ // 重置表单
93
+ $Data.formData.id = 0;
94
+ $Data.formData.name = '';
95
+ $Data.formData.path = '';
96
+ $Data.formData.icon = '';
97
+ $Data.formData.sort = 0;
98
+ $Data.formData.state = 1;
99
+ }
100
+ },
101
+
102
+ onClose() {
103
+ $Data.visible = false;
104
+ setTimeout(() => {
105
+ $Emit('update:modelValue', false);
106
+ }, 300);
107
+ },
108
+
109
+ async onSubmit() {
110
+ try {
111
+ const valid = await $From.form.validate();
112
+ if (!valid) return;
113
+
114
+ const res = await $Http($Prop.actionType === 'add' ? '/addon/admin/menuIns' : '/addon/admin/menuUpd', $Data.formData);
115
+
116
+ Modal.message({
117
+ message: $Prop.actionType === 'add' ? '添加成功' : '编辑成功',
118
+ status: 'success'
119
+ });
120
+ $Method.onClose();
121
+ $Emit('success');
122
+ } catch (error) {
123
+ console.error('提交失败:', error);
124
+ }
125
+ }
126
+ };
127
+
128
+ // 监听 modelValue 变化
129
+ watch(
130
+ () => $Prop.modelValue,
131
+ (val) => {
132
+ if (val && !$Data.visible) {
133
+ $Method.initData();
134
+ } else if (!val && $Data.visible) {
135
+ $Data.visible = false;
136
+ }
137
+ },
138
+ { immediate: true }
139
+ );
140
+ </script>
141
+
142
+ <style scoped lang="scss">
143
+ // 可根据需要添加样式
144
+ </style>
@@ -0,0 +1,171 @@
1
+ <template>
2
+ <div class="page-menu page-table">
3
+ <div class="main-tool">
4
+ <div class="left">
5
+ <tiny-button type="primary" @click="$Method.onAction('add', {})">
6
+ <template #icon>
7
+ <i-lucide:plus style="width: 16px; height: 16px" />
8
+ </template>
9
+ 添加菜单
10
+ </tiny-button>
11
+ </div>
12
+ <div class="right">
13
+ <tiny-button @click="$Method.handleRefresh">
14
+ <template #icon>
15
+ <i-lucide:rotate-cw style="width: 16px; height: 16px" />
16
+ </template>
17
+ 刷新
18
+ </tiny-button>
19
+ </div>
20
+ </div>
21
+ <div class="main-table">
22
+ <tiny-grid :data="$Data.menuList" header-cell-class-name="custom-table-cell-class" size="small" height="100%" seq-serial>
23
+ <tiny-grid-column type="index" title="序号" :width="60" />
24
+ <tiny-grid-column field="name" title="菜单名称" />
25
+ <tiny-grid-column field="path" title="路径" :width="200" />
26
+ <tiny-grid-column field="icon" title="图标" :width="100">
27
+ <template #default="{ row }">
28
+ <i-lucide:square v-if="row.icon" style="width: 16px; height: 16px" />
29
+ <span v-else>-</span>
30
+ </template>
31
+ </tiny-grid-column>
32
+ <tiny-grid-column field="sort" title="排序" :width="80" />
33
+ <tiny-grid-column field="state" title="状态" :width="100">
34
+ <template #default="{ row }">
35
+ <tiny-tag v-if="row.state === 1" type="success">正常</tiny-tag>
36
+ <tiny-tag v-else-if="row.state === 2" type="warning">禁用</tiny-tag>
37
+ <tiny-tag v-else type="danger">已删除</tiny-tag>
38
+ </template>
39
+ </tiny-grid-column>
40
+ <tiny-grid-column title="操作" :width="120" align="right">
41
+ <template #default="{ row }">
42
+ <tiny-dropdown title="操作" trigger="click" size="small" border visible-arrow @item-click="(data) => $Method.onAction(data.itemData.command, row)">
43
+ <template #dropdown>
44
+ <tiny-dropdown-menu>
45
+ <tiny-dropdown-item :item-data="{ command: 'upd' }">
46
+ <i-lucide:pencil style="width: 14px; height: 14px; margin-right: 6px" />
47
+ 编辑
48
+ </tiny-dropdown-item>
49
+ <tiny-dropdown-item :item-data="{ command: 'del' }" divided>
50
+ <i-lucide:trash-2 style="width: 14px; height: 14px; margin-right: 6px" />
51
+ 删除
52
+ </tiny-dropdown-item>
53
+ </tiny-dropdown-menu>
54
+ </template>
55
+ </tiny-dropdown>
56
+ </template>
57
+ </tiny-grid-column>
58
+ </tiny-grid>
59
+ </div>
60
+
61
+ <div class="main-page">
62
+ <tiny-pager :current-page="$Data.pagerConfig.currentPage" :page-size="$Data.pagerConfig.pageSize" :total="$Data.pagerConfig.total" @current-change="$Method.onPageChange" @size-change="$Method.handleSizeChange" />
63
+ </div>
64
+
65
+ <!-- 编辑对话框组件 -->
66
+ <EditDialog v-if="$Data.editVisible" v-model="$Data.editVisible" :action-type="$Data.actionType" :row-data="$Data.rowData" @success="$Method.apiMenuList" />
67
+ </div>
68
+ </template>
69
+
70
+ <script setup>
71
+ import { ref } from 'vue';
72
+ import { Modal } from '@opentiny/vue';
73
+
74
+ import EditDialog from './components/edit.vue';
75
+
76
+ // 响应式数据
77
+ const $Data = $ref({
78
+ menuList: [],
79
+ pagerConfig: {
80
+ currentPage: 1,
81
+ pageSize: 30,
82
+ total: 0,
83
+ align: 'right',
84
+ layout: 'total, prev, pager, next, jumper'
85
+ },
86
+ editVisible: false,
87
+ actionType: 'add',
88
+ rowData: {}
89
+ });
90
+
91
+ // 方法
92
+ const $Method = {
93
+ async initData() {
94
+ await $Method.apiMenuList();
95
+ },
96
+
97
+ // 加载菜单列表
98
+ async apiMenuList() {
99
+ try {
100
+ const res = await $Http('/addon/admin/menu/list', {
101
+ page: $Data.pagerConfig.currentPage,
102
+ limit: $Data.pagerConfig.pageSize
103
+ });
104
+ $Data.menuList = res.data.lists || [];
105
+ $Data.pagerConfig.total = res.data.total || 0;
106
+ } catch (error) {
107
+ console.error('加载菜单列表失败:', error);
108
+ Modal.message({
109
+ message: '加载数据失败',
110
+ status: 'error'
111
+ });
112
+ }
113
+ },
114
+
115
+ // 删除菜单
116
+ async apiMenuDel(row) {
117
+ Modal.confirm({
118
+ header: '确认删除',
119
+ body: `确定要删除菜单"${row.name}" 吗?`,
120
+ status: 'warning'
121
+ }).then(async () => {
122
+ try {
123
+ const res = await $Http('/addon/admin/menu/del', { id: row.id });
124
+ if (res.code === 0) {
125
+ Modal.message({ message: '删除成功', status: 'success' });
126
+ $Method.apiMenuList();
127
+ } else {
128
+ Modal.message({ message: res.msg || '删除失败', status: 'error' });
129
+ }
130
+ } catch (error) {
131
+ console.error('删除失败:', error);
132
+ Modal.message({ message: '删除失败', status: 'error' });
133
+ }
134
+ });
135
+ },
136
+
137
+ // 刷新
138
+ handleRefresh() {
139
+ $Method.apiMenuList();
140
+ },
141
+
142
+ // 分页改变
143
+ onPageChange({ currentPage }) {
144
+ $Data.pagerConfig.currentPage = currentPage;
145
+ $Method.apiMenuList();
146
+ },
147
+
148
+ // 操作菜单点击
149
+ onAction(command, rowData) {
150
+ $Data.actionType = command;
151
+ $Data.rowData = rowData;
152
+ if (command === 'add' || command === 'upd') {
153
+ $Data.editVisible = true;
154
+ } else if (command === 'del') {
155
+ $Method.apiMenuDel(rowData);
156
+ }
157
+ }
158
+ };
159
+
160
+ $Method.initData();
161
+ </script>
162
+
163
+ <route lang="yaml">
164
+ meta:
165
+ layout: default
166
+ title: 菜单管理
167
+ </route>
168
+
169
+ <style scoped lang="scss">
170
+ // 样式继承自全局 page-table
171
+ </style>
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <div class="news-page">
3
+ <h1>新闻页面 index</h1>
4
+ <p>这个页面使用布局 1.vue</p>
5
+ <div class="news-content">
6
+ <p>这里是新闻内容...</p>
7
+ </div>
8
+ </div>
9
+ </template>
10
+
11
+ <script setup>
12
+ // 新闻页面逻辑
13
+ </script>
14
+
15
+ <style scoped>
16
+ .news-page {
17
+ padding: 20px;
18
+ }
19
+
20
+ .news-content {
21
+ margin-top: 20px;
22
+ padding: 20px;
23
+ background: #f5f5f5;
24
+ border-radius: 8px;
25
+ }
26
+ </style>
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <div class="news-page">
3
+ <h1>新闻页面</h1>
4
+ <p>这个页面使用布局 1.vue</p>
5
+ <div class="news-content">
6
+ <p>这里是新闻内容...</p>
7
+ </div>
8
+ </div>
9
+ </template>
10
+
11
+ <script setup>
12
+ // 新闻页面逻辑
13
+ </script>
14
+
15
+ <style scoped>
16
+ .news-page {
17
+ padding: 20px;
18
+ }
19
+
20
+ .news-content {
21
+ margin-top: 20px;
22
+ padding: 20px;
23
+ background: #f5f5f5;
24
+ border-radius: 8px;
25
+ }
26
+ </style>
@@ -0,0 +1,283 @@
1
+ <template>
2
+ <tiny-dialog-box v-model:visible="$Data.visible" title="接口权限" width="900px" :append-to-body="true" :show-footer="true" top="5vh" @close="$Method.onClose">
3
+ <div class="comp-role-api">
4
+ <!-- 搜索框 -->
5
+ <div class="search-box">
6
+ <tiny-search v-model="$Data.searchText" placeholder="搜索接口名称或路径" clearable @update:modelValue="$Method.onSearch" />
7
+ </div>
8
+
9
+ <!-- 接口分组列表 -->
10
+ <div class="api-container">
11
+ <div v-for="group in $Data.filteredApiData" :key="group.name" class="api-group">
12
+ <div class="group-header">{{ group.title }}</div>
13
+ <div class="api-checkbox-list">
14
+ <tiny-checkbox-group v-model="$Data.checkedApiIds">
15
+ <tiny-checkbox v-for="api in group.apis" :key="api.id" :label="api.id"> {{ api.label }} </tiny-checkbox>
16
+ </tiny-checkbox-group>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ </div>
21
+
22
+ <template #footer>
23
+ <div class="footer-left">
24
+ <tiny-button size="small" @click="$Method.onCheckAll">全选</tiny-button>
25
+ <tiny-button size="small" @click="$Method.onUncheckAll">取消全选</tiny-button>
26
+ </div>
27
+ <div class="footer-right">
28
+ <tiny-button @click="$Method.onClose">取消</tiny-button>
29
+ <tiny-button type="primary" @click="$Method.onSubmit">保存</tiny-button>
30
+ </div>
31
+ </template>
32
+ </tiny-dialog-box>
33
+ </template>
34
+
35
+ <script setup>
36
+ import { ref } from 'vue';
37
+ import { Modal } from '@opentiny/vue';
38
+
39
+ const $Prop = defineProps({
40
+ modelValue: {
41
+ type: Boolean,
42
+ default: false
43
+ },
44
+ rowData: {
45
+ type: Object,
46
+ default: () => ({})
47
+ }
48
+ });
49
+
50
+ const $Emit = defineEmits(['update:modelValue', 'success']);
51
+
52
+ const $Data = $ref({
53
+ visible: false,
54
+ apiData: [],
55
+ filteredApiData: [],
56
+ searchText: '',
57
+ checkedApiIds: []
58
+ });
59
+
60
+ // 方法集合
61
+ const $Method = {
62
+ async initData() {
63
+ $Method.onShow();
64
+ await Promise.all([$Method.apiApiAll(), $Method.apiRoleApiDetail()]);
65
+ $Data.filteredApiData = $Data.apiData;
66
+ },
67
+
68
+ onShow() {
69
+ setTimeout(() => {
70
+ $Data.visible = $Prop.modelValue;
71
+ }, 100);
72
+ },
73
+
74
+ onClose() {
75
+ $Data.visible = false;
76
+ setTimeout(() => {
77
+ $Emit('update:modelValue', false);
78
+ }, 300);
79
+ },
80
+
81
+ // 加载所有接口
82
+ async apiApiAll() {
83
+ try {
84
+ const res = await $Http('/addon/admin/api/all');
85
+
86
+ // 将接口列表按 addonTitle 分组
87
+ const apiMap = new Map();
88
+
89
+ res.data.lists.forEach((api) => {
90
+ const addonTitle = api.addonTitle || api.addonName || '项目接口';
91
+ const addonName = api.addonName || 'project';
92
+
93
+ if (!apiMap.has(addonName)) {
94
+ apiMap.set(addonName, {
95
+ name: addonName,
96
+ title: addonTitle,
97
+ apis: []
98
+ });
99
+ }
100
+
101
+ apiMap.get(addonName).apis.push({
102
+ id: api.id,
103
+ label: `${api.name}`,
104
+ description: api.description
105
+ });
106
+ });
107
+
108
+ $Data.apiData = Array.from(apiMap.values());
109
+ } catch (error) {
110
+ console.error('加载接口失败:', error);
111
+ Modal.message({ message: '加载接口失败', status: 'error' });
112
+ }
113
+ },
114
+
115
+ // 加载该角色已分配的接口
116
+ async apiRoleApiDetail() {
117
+ if (!$Prop.rowData.id) return;
118
+
119
+ try {
120
+ const res = await $Http('/addon/admin/role/apiDetail', {
121
+ roleId: $Prop.rowData.id
122
+ });
123
+
124
+ $Data.checkedApiIds = res.data.apiIds || [];
125
+ } catch (error) {
126
+ console.error('加载角色接口失败:', error);
127
+ }
128
+ },
129
+
130
+ // 搜索过滤
131
+ onSearch() {
132
+ if (!$Data.searchText) {
133
+ $Data.filteredApiData = $Data.apiData;
134
+ return;
135
+ }
136
+
137
+ const searchLower = $Data.searchText.toLowerCase();
138
+ $Data.filteredApiData = $Data.apiData
139
+ .map((group) => ({
140
+ ...group,
141
+ apis: group.apis.filter((api) => api.label.toLowerCase().includes(searchLower))
142
+ }))
143
+ .filter((group) => group.apis.length > 0);
144
+ },
145
+
146
+ // 全选
147
+ onCheckAll() {
148
+ const allApiIds = [];
149
+ $Data.apiData.forEach((group) => {
150
+ group.apis.forEach((api) => {
151
+ allApiIds.push(api.id);
152
+ });
153
+ });
154
+ $Data.checkedApiIds = allApiIds;
155
+ },
156
+
157
+ // 取消全选
158
+ onUncheckAll() {
159
+ $Data.checkedApiIds = [];
160
+ },
161
+
162
+ // 提交表单
163
+ async onSubmit() {
164
+ try {
165
+ const res = await $Http('/addon/admin/role/apiSave', {
166
+ roleId: $Prop.rowData.id,
167
+ apiIds: $Data.checkedApiIds
168
+ });
169
+
170
+ if (res.code === 0) {
171
+ Modal.message({
172
+ message: '保存成功',
173
+ status: 'success'
174
+ });
175
+ $Data.visible = false;
176
+ $Emit('success');
177
+ } else {
178
+ Modal.message({
179
+ message: res.msg || '保存失败',
180
+ status: 'error'
181
+ });
182
+ }
183
+ } catch (error) {
184
+ console.error('保存失败:', error);
185
+ Modal.message({
186
+ message: '保存失败',
187
+ status: 'error'
188
+ });
189
+ }
190
+ }
191
+ };
192
+
193
+ $Method.initData();
194
+ </script>
195
+
196
+ <style scoped lang="scss">
197
+ .comp-role-api {
198
+ height: 60vh;
199
+ display: flex;
200
+ flex-direction: column;
201
+ gap: 12px;
202
+
203
+ .search-box {
204
+ }
205
+
206
+ .api-container {
207
+ flex: 1;
208
+ overflow-y: auto;
209
+
210
+ .api-group {
211
+ margin-bottom: 16px;
212
+ border: 1px solid $border-color;
213
+ border-radius: $border-radius-small;
214
+ overflow: hidden;
215
+
216
+ &:last-child {
217
+ margin-bottom: 0;
218
+ }
219
+
220
+ .group-header {
221
+ padding: 12px 16px;
222
+ background-color: $bg-color-hover;
223
+ font-weight: 500;
224
+ font-size: $font-size-sm;
225
+ color: $text-primary;
226
+ display: flex;
227
+ align-items: center;
228
+ gap: 8px;
229
+
230
+ &::before {
231
+ content: '';
232
+ width: 8px;
233
+ height: 8px;
234
+ border-radius: 50%;
235
+ background-color: $primary-color;
236
+ opacity: 0.3;
237
+ flex-shrink: 0;
238
+ }
239
+ }
240
+
241
+ .api-checkbox-list {
242
+ padding: 16px;
243
+ background-color: $bg-color-container;
244
+
245
+ :deep(.tiny-checkbox-group) {
246
+ display: flex;
247
+ flex-wrap: wrap;
248
+ gap: 12px;
249
+ width: 100%;
250
+ }
251
+
252
+ :deep(.tiny-checkbox) {
253
+ flex: 0 0 calc(33.333% - 8px);
254
+ margin: 0;
255
+
256
+ .tiny-checkbox__label {
257
+ white-space: nowrap;
258
+ overflow: hidden;
259
+ text-overflow: ellipsis;
260
+ }
261
+ }
262
+ }
263
+ }
264
+ }
265
+ }
266
+
267
+ // 底部操作栏布局
268
+ :deep(.tiny-dialog-box__footer) {
269
+ display: flex;
270
+ justify-content: space-between;
271
+ align-items: center;
272
+
273
+ .footer-left {
274
+ display: flex;
275
+ gap: 8px;
276
+ }
277
+
278
+ .footer-right {
279
+ display: flex;
280
+ gap: 8px;
281
+ }
282
+ }
283
+ </style>