befly-admin 3.3.7 → 3.3.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly-admin",
3
- "version": "3.3.7",
3
+ "version": "3.3.8",
4
4
  "description": "Befly Admin - 基于 Vue3 + OpenTiny Vue 的后台管理系统",
5
5
  "type": "module",
6
6
  "private": false,
@@ -39,5 +39,5 @@
39
39
  "node": ">=22.0.0",
40
40
  "pnpm": ">=9.0.0"
41
41
  },
42
- "gitHead": "c15e9bf787cbdf1c4d9bc5296a686a24e79c915e"
42
+ "gitHead": "c9933a45ed268f79ee3428d8c9179fbe885cb888"
43
43
  }
@@ -5,69 +5,127 @@
5
5
  <Icon name="User" :size="32" />
6
6
  </div>
7
7
  <div class="user-basic">
8
- <div class="user-name">{{ userInfo.nickname || userInfo.name || userInfo.username || '未设置' }}</div>
9
- <div class="user-role">{{ userInfo.role?.name || '普通用户' }}</div>
8
+ <div class="user-name">{{ $Data.userInfo.nickname || $Data.userInfo.name || $Data.userInfo.username || '未设置' }}</div>
9
+ <div class="user-role">{{ $Data.userInfo.role?.name || '普通用户' }}</div>
10
10
  </div>
11
11
  </div>
12
12
  <div class="user-details">
13
13
  <div class="detail-item">
14
14
  <Icon name="Mail" :size="14" />
15
- <span>{{ userInfo.email || '未设置' }}</span>
15
+ <span>{{ $Data.userInfo.email || '未设置' }}</span>
16
16
  </div>
17
- <div v-if="userInfo.phone" class="detail-item">
17
+ <div v-if="$Data.userInfo.phone" class="detail-item">
18
18
  <Icon name="Phone" :size="14" />
19
- <span>{{ userInfo.phone }}</span>
19
+ <span>{{ $Data.userInfo.phone }}</span>
20
20
  </div>
21
- <div v-if="userInfo.lastLoginTime" class="detail-item">
21
+ <div v-if="$Data.userInfo.lastLoginTime" class="detail-item">
22
22
  <Icon name="Clock" :size="14" />
23
- <span>{{ formatTime(userInfo.lastLoginTime) }}</span>
23
+ <span>{{ $Method.formatTime($Data.userInfo.lastLoginTime) }}</span>
24
24
  </div>
25
25
  </div>
26
+
27
+ <!-- 仅 dev 角色显示刷新缓存按钮 -->
28
+ <div v-if="$Data.userInfo.roleCode === 'dev'" class="user-actions">
29
+ <tiny-button type="primary" size="mini" :loading="$Data.refreshing" @click="$Method.handleRefreshCache">
30
+ <template #icon>
31
+ <Icon name="RotateCw" :size="14" />
32
+ </template>
33
+ 刷新缓存
34
+ </tiny-button>
35
+ </div>
26
36
  </div>
27
37
  </template>
28
38
 
29
39
  <script setup>
30
- // 组件内部数据
31
- const userInfo = $ref({});
32
-
33
- // 获取数据
34
- const fetchData = async () => {
35
- try {
36
- const { data } = await $Http('/addon/admin/admin/info');
37
- Object.assign(userInfo, data);
38
- } catch (error) {
39
- console.error('获取用户信息失败:', error);
40
- }
41
- };
40
+ // 响应式数据
41
+ const $Data = $ref({
42
+ userInfo: {},
43
+ refreshing: false
44
+ });
42
45
 
43
- // 格式化时间
44
- const formatTime = (timestamp) => {
45
- if (!timestamp) return '';
46
- const date = new Date(Number(timestamp));
47
- const now = new Date();
48
- const diff = now - date;
46
+ // 方法集合
47
+ const $Method = {
48
+ // 获取数据
49
+ async fetchData() {
50
+ try {
51
+ const { data } = await $Http('/addon/admin/admin/info');
52
+ Object.assign($Data.userInfo, data);
53
+ } catch (error) {
54
+ console.error('获取用户信息失败:', error);
55
+ }
56
+ },
49
57
 
50
- // 小于1分钟
51
- if (diff < 60000) {
52
- return '刚刚';
53
- }
54
- // 小于1小时
55
- if (diff < 3600000) {
56
- return `${Math.floor(diff / 60000)}分钟前`;
57
- }
58
- // 小于24小时
59
- if (diff < 86400000) {
60
- return `${Math.floor(diff / 3600000)}小时前`;
61
- }
62
- // 小于7天
63
- if (diff < 604800000) {
64
- return `${Math.floor(diff / 86400000)}天前`;
58
+ // 刷新缓存
59
+ async handleRefreshCache() {
60
+ try {
61
+ $Data.refreshing = true;
62
+ const result = await $Http('/addon/admin/admin/cacheRefresh');
63
+
64
+ if (result.code === 0) {
65
+ const { apis, menus, roles } = result.data;
66
+ const messages = [];
67
+
68
+ if (apis.success) {
69
+ messages.push(`接口缓存: ${apis.count} 个`);
70
+ }
71
+ if (menus.success) {
72
+ messages.push(`菜单缓存: ${menus.count} 个`);
73
+ }
74
+ if (roles.success) {
75
+ messages.push(`角色缓存: ${roles.count} 个`);
76
+ }
77
+
78
+ TinyMessage.success({
79
+ message: `缓存刷新成功!${messages.join(',')}`,
80
+ duration: 3000
81
+ });
82
+ } else {
83
+ TinyMessage.warning({
84
+ message: result.msg || '部分缓存刷新失败',
85
+ duration: 3000
86
+ });
87
+ }
88
+ } catch (error) {
89
+ console.error('刷新缓存失败:', error);
90
+ TinyMessage.error({
91
+ message: '刷新缓存失败,请稍后重试',
92
+ duration: 3000
93
+ });
94
+ } finally {
95
+ $Data.refreshing = false;
96
+ }
97
+ },
98
+
99
+ // 格式化时间
100
+ formatTime(timestamp) {
101
+ if (!timestamp) return '';
102
+ const date = new Date(Number(timestamp));
103
+ const now = new Date();
104
+ const diff = now - date;
105
+
106
+ // 小于1分钟
107
+ if (diff < 60000) {
108
+ return '刚刚';
109
+ }
110
+ // 小于1小时
111
+ if (diff < 3600000) {
112
+ return `${Math.floor(diff / 60000)}分钟前`;
113
+ }
114
+ // 小于24小时
115
+ if (diff < 86400000) {
116
+ return `${Math.floor(diff / 3600000)}小时前`;
117
+ }
118
+ // 小于7天
119
+ if (diff < 604800000) {
120
+ return `${Math.floor(diff / 86400000)}天前`;
121
+ }
122
+ // 超过7天显示具体日期
123
+ return `${date.getMonth() + 1}月${date.getDate()}日`;
65
124
  }
66
- // 超过7天显示具体日期
67
- return `${date.getMonth() + 1}月${date.getDate()}日`;
68
125
  };
69
126
 
70
- fetchData();
127
+ // 初始化
128
+ $Method.fetchData();
71
129
  </script>
72
130
 
73
131
  <style scoped lang="scss">
@@ -132,5 +190,13 @@ fetchData();
132
190
  }
133
191
  }
134
192
  }
193
+
194
+ .user-actions {
195
+ margin-top: 16px;
196
+ padding-top: 12px;
197
+ border-top: 1px solid $border-color;
198
+ display: flex;
199
+ justify-content: center;
200
+ }
135
201
  }
136
202
  </style>