fdb2 1.0.0
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/.dockerignore +21 -0
- package/.editorconfig +11 -0
- package/.eslintrc.cjs +14 -0
- package/.eslintrc.json +7 -0
- package/.prettierrc.js +3 -0
- package/.tpl.env +22 -0
- package/README.md +260 -0
- package/bin/build.sh +28 -0
- package/bin/deploy.sh +8 -0
- package/bin/dev.sh +10 -0
- package/bin/docker/.env +4 -0
- package/bin/docker/dev-docker-compose.yml +43 -0
- package/bin/docker/dev.Dockerfile +24 -0
- package/bin/docker/prod-docker-compose.yml +17 -0
- package/bin/docker/prod.Dockerfile +29 -0
- package/bin/fdb2.js +142 -0
- package/data/connections.demo.json +32 -0
- package/env.d.ts +1 -0
- package/nw-build.js +120 -0
- package/nw-dev.js +65 -0
- package/package.json +114 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +9 -0
- package/public/modules/header.tpl +14 -0
- package/public/modules/initial_state.tpl +55 -0
- package/server/index.ts +677 -0
- package/server/model/connection.entity.ts +66 -0
- package/server/model/database.entity.ts +246 -0
- package/server/service/connection.service.ts +334 -0
- package/server/service/database/base.service.ts +363 -0
- package/server/service/database/database.service.ts +510 -0
- package/server/service/database/index.ts +7 -0
- package/server/service/database/mssql.service.ts +723 -0
- package/server/service/database/mysql.service.ts +761 -0
- package/server/service/database/oracle.service.ts +839 -0
- package/server/service/database/postgres.service.ts +744 -0
- package/server/service/database/sqlite.service.ts +559 -0
- package/server/service/session.service.ts +158 -0
- package/server.js +128 -0
- package/src/adapter/ajax.ts +135 -0
- package/src/assets/base.css +1 -0
- package/src/assets/database.css +950 -0
- package/src/assets/images/collapse.png +0 -0
- package/src/assets/images/no-login.png +0 -0
- package/src/assets/images/svg/illustrations/illustration-1.svg +1 -0
- package/src/assets/images/svg/illustrations/illustration-2.svg +2 -0
- package/src/assets/images/svg/illustrations/illustration-3.svg +50 -0
- package/src/assets/images/svg/illustrations/illustration-4.svg +1 -0
- package/src/assets/images/svg/illustrations/illustration-5.svg +73 -0
- package/src/assets/images/svg/illustrations/illustration-6.svg +89 -0
- package/src/assets/images/svg/illustrations/illustration-7.svg +39 -0
- package/src/assets/images/svg/illustrations/illustration-8.svg +1 -0
- package/src/assets/images/svg/separators/curve-2.svg +3 -0
- package/src/assets/images/svg/separators/curve.svg +3 -0
- package/src/assets/images/svg/separators/line.svg +3 -0
- package/src/assets/images/theme/light/screen-1-1000x800.jpg +0 -0
- package/src/assets/images/theme/light/screen-2-1000x800.jpg +0 -0
- package/src/assets/login/bg.jpg +0 -0
- package/src/assets/login/bg.png +0 -0
- package/src/assets/login/left.jpg +0 -0
- package/src/assets/logo.svg +73 -0
- package/src/assets/logo.webp +0 -0
- package/src/assets/main.css +1 -0
- package/src/base/config.ts +20 -0
- package/src/base/detect.ts +134 -0
- package/src/base/entity.ts +92 -0
- package/src/base/eventBus.ts +37 -0
- package/src/base//345/237/272/347/241/200/345/261/202.md +7 -0
- package/src/components/connection-editor/index.vue +590 -0
- package/src/components/dataGrid/index.vue +105 -0
- package/src/components/dataGrid/pagination.vue +106 -0
- package/src/components/loading/index.vue +43 -0
- package/src/components/modal/index.ts +181 -0
- package/src/components/modal/index.vue +560 -0
- package/src/components/toast/index.ts +44 -0
- package/src/components/toast/toast.vue +58 -0
- package/src/components/user/name.vue +104 -0
- package/src/components/user/selector.vue +416 -0
- package/src/domain/SysConfig.ts +74 -0
- package/src/platform/App.vue +8 -0
- package/src/platform/database/components/connection-detail.vue +1154 -0
- package/src/platform/database/components/data-editor.vue +478 -0
- package/src/platform/database/components/data-import-export.vue +1602 -0
- package/src/platform/database/components/database-detail.vue +1173 -0
- package/src/platform/database/components/database-monitor.vue +1086 -0
- package/src/platform/database/components/db-tools.vue +577 -0
- package/src/platform/database/components/query-history.vue +1349 -0
- package/src/platform/database/components/sql-executor.vue +738 -0
- package/src/platform/database/components/sql-query-editor.vue +1046 -0
- package/src/platform/database/components/table-detail.vue +1376 -0
- package/src/platform/database/components/table-editor.vue +690 -0
- package/src/platform/database/explorer.vue +1840 -0
- package/src/platform/database/index.vue +1193 -0
- package/src/platform/database/layout.vue +367 -0
- package/src/platform/database/router.ts +37 -0
- package/src/platform/database/styles/common.scss +602 -0
- package/src/platform/database/types/common.ts +445 -0
- package/src/platform/database/utils/export.ts +232 -0
- package/src/platform/database/utils/helpers.ts +437 -0
- package/src/platform/index.ts +33 -0
- package/src/platform/router.ts +41 -0
- package/src/service/base.ts +128 -0
- package/src/service/database.ts +500 -0
- package/src/service/login.ts +121 -0
- package/src/shims-vue.d.ts +7 -0
- package/src/stores/connection.ts +266 -0
- package/src/stores/session.ts +87 -0
- package/src/typings/database-types.ts +413 -0
- package/src/typings/database.ts +364 -0
- package/src/typings/global.d.ts +58 -0
- package/src/typings/pinia.d.ts +8 -0
- package/src/utils/clipboard.ts +30 -0
- package/src/utils/database-types.ts +243 -0
- package/src/utils/modal.ts +124 -0
- package/src/utils/request.ts +55 -0
- package/src/utils/sleep.ts +4 -0
- package/src/utils/toast.ts +73 -0
- package/src/utils/util.ts +171 -0
- package/src/utils/xlsx.ts +228 -0
- package/tsconfig.json +33 -0
- package/tsconfig.server.json +19 -0
- package/view/index.html +9 -0
- package/view/modules/header.tpl +14 -0
- package/view/modules/initial_state.tpl +20 -0
- package/vite.config.ts +384 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span v-if="loading" class="text-muted">
|
|
3
|
+
<i class="bi bi-hourglass-split"></i> 加载中...
|
|
4
|
+
</span>
|
|
5
|
+
<span v-else-if="error" class="text-danger">
|
|
6
|
+
<i class="bi bi-exclamation-circle"></i> 加载失败
|
|
7
|
+
</span>
|
|
8
|
+
<span v-else-if="userInfo" class="user-info" :title="userInfo.id">
|
|
9
|
+
<span class="user-name">{{ userInfo.name }}</span>
|
|
10
|
+
<span class="user-phone ms-2 text-secondary" v-if="userInfo.mobile">({{ formatPhone(userInfo.mobile) }})</span>
|
|
11
|
+
</span>
|
|
12
|
+
<span v-else class="text-secondary">未知用户</span>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { ref, watch, onMounted } from 'vue';
|
|
17
|
+
import * as userServer from '@/service/account'; // 假设用户服务路径
|
|
18
|
+
|
|
19
|
+
// 接收父组件传入的用户ID
|
|
20
|
+
const props = defineProps<{
|
|
21
|
+
userId?: number | null
|
|
22
|
+
}>();
|
|
23
|
+
|
|
24
|
+
// 组件内部状态
|
|
25
|
+
const userInfo = ref<any>(null);
|
|
26
|
+
const loading = ref(false);
|
|
27
|
+
const error = ref(false);
|
|
28
|
+
|
|
29
|
+
// 缓存已查询过的用户信息,避免重复请求
|
|
30
|
+
const userCache = new Map<number, any>();
|
|
31
|
+
|
|
32
|
+
// 格式化手机号(13800138000 -> 138****8000)
|
|
33
|
+
const formatPhone = (phone: string) => {
|
|
34
|
+
// if (phone.length === 11) {
|
|
35
|
+
// return `${phone.slice(0, 3)}****${phone.slice(7)}`;
|
|
36
|
+
// }
|
|
37
|
+
return phone;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// 根据用户ID获取用户信息
|
|
41
|
+
const fetchUserInfo = async (userId: number | null | undefined) => {
|
|
42
|
+
// 如果没有用户ID,直接清空显示
|
|
43
|
+
if (!userId || userId <= 0) {
|
|
44
|
+
userInfo.value = null;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 检查缓存,如果有直接使用
|
|
49
|
+
if (userCache.has(userId)) {
|
|
50
|
+
userInfo.value = userCache.get(userId) || null;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 发起请求获取用户信息
|
|
55
|
+
loading.value = true;
|
|
56
|
+
error.value = false;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const res = await userServer.getUserDetail(userId);
|
|
60
|
+
if (res.ret === 0 && res.data) {
|
|
61
|
+
const user = res.data;
|
|
62
|
+
userInfo.value = user;
|
|
63
|
+
userCache.set(userId, user); // 存入缓存
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error(res.msg || '获取用户信息失败');
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error('获取用户信息失败:', err);
|
|
69
|
+
error.value = true;
|
|
70
|
+
userInfo.value = null;
|
|
71
|
+
} finally {
|
|
72
|
+
loading.value = false;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// 当用户ID变化时重新获取信息
|
|
77
|
+
watch(
|
|
78
|
+
() => props.userId,
|
|
79
|
+
(newUserId) => {
|
|
80
|
+
fetchUserInfo(newUserId);
|
|
81
|
+
},
|
|
82
|
+
{ immediate: true } // 组件初始化时立即执行
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// 组件挂载时执行一次
|
|
86
|
+
onMounted(() => {
|
|
87
|
+
fetchUserInfo(props.userId);
|
|
88
|
+
});
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<style scoped>
|
|
92
|
+
.user-name {
|
|
93
|
+
color: var(--bs-primary);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.user-name:hover {
|
|
97
|
+
text-decoration: underline;
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.user-phone {
|
|
102
|
+
font-size: 0.875rem;
|
|
103
|
+
}
|
|
104
|
+
</style>
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="user-permission-selector">
|
|
3
|
+
<div class="dropdown" :class="{ show: isOpen }">
|
|
4
|
+
<button
|
|
5
|
+
class="btn btn-light w-100 text-start border rounded-md d-flex align-items-center justify-content-between"
|
|
6
|
+
type="button"
|
|
7
|
+
@click="toggleDropdown"
|
|
8
|
+
:aria-expanded="isOpen"
|
|
9
|
+
>
|
|
10
|
+
<div class="d-flex align-items-center flex-grow-1 overflow-hidden">
|
|
11
|
+
<i class="bi bi-search me-2 text-muted"></i>
|
|
12
|
+
|
|
13
|
+
<!-- 选中的用户或占位文本 -->
|
|
14
|
+
<div class="flex-grow-1 overflow-hidden">
|
|
15
|
+
<span
|
|
16
|
+
v-if="selectedUser"
|
|
17
|
+
class="text-body"
|
|
18
|
+
>
|
|
19
|
+
{{ selectedUser.account }}
|
|
20
|
+
</span>
|
|
21
|
+
|
|
22
|
+
<!-- 占位文本 -->
|
|
23
|
+
<span
|
|
24
|
+
v-else
|
|
25
|
+
class="text-muted flex-grow-1"
|
|
26
|
+
>
|
|
27
|
+
{{ placeholder || '选择用户' }}
|
|
28
|
+
</span>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<!-- 下拉箭头 -->
|
|
33
|
+
<i class="bi" :class="isOpen ? 'bi-chevron-up' : 'bi-chevron-down'"></i>
|
|
34
|
+
</button>
|
|
35
|
+
|
|
36
|
+
<!-- 下拉菜单 -->
|
|
37
|
+
<div
|
|
38
|
+
class="dropdown-menu w-100 p-2 shadow-lg border rounded-md"
|
|
39
|
+
:class="{ show: isOpen }"
|
|
40
|
+
@click.stop
|
|
41
|
+
>
|
|
42
|
+
<!-- 搜索框 -->
|
|
43
|
+
<div class="mb-2">
|
|
44
|
+
<input
|
|
45
|
+
type="text"
|
|
46
|
+
class="form-control"
|
|
47
|
+
ref="searchInput"
|
|
48
|
+
:placeholder="searchPlaceholder || '搜索用户...'"
|
|
49
|
+
v-model="searchQuery"
|
|
50
|
+
@input="handleSearchInput"
|
|
51
|
+
@keydown="handleKeydown"
|
|
52
|
+
>
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<!-- 搜索结果组 -->
|
|
56
|
+
<div class="mb-1">
|
|
57
|
+
<div class="dropdown-header d-flex justify-content-between align-items-center">
|
|
58
|
+
<span>搜索结果</span>
|
|
59
|
+
<div v-if="loading" class="w-20">
|
|
60
|
+
<div class="progress" style="height: 2px;">
|
|
61
|
+
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 100%"></div>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<!-- 结果列表 -->
|
|
67
|
+
<div class="mt-1">
|
|
68
|
+
<button
|
|
69
|
+
v-for="user in userList"
|
|
70
|
+
:key="user.userId"
|
|
71
|
+
class="dropdown-item d-block w-100 text-start mb-1 rounded"
|
|
72
|
+
:class="{ 'active': selectedUser?.userId === user.userId }"
|
|
73
|
+
@click.prevent.stop="handleSelectUser(user)"
|
|
74
|
+
>
|
|
75
|
+
{{ user.account }}
|
|
76
|
+
</button>
|
|
77
|
+
|
|
78
|
+
<div
|
|
79
|
+
v-if="!loading && userList.length === 0"
|
|
80
|
+
class="text-center text-muted py-2"
|
|
81
|
+
>
|
|
82
|
+
没有找到匹配的用户
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<!-- 清除按钮 -->
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
class="btn btn-link text-danger w-100 mt-1"
|
|
91
|
+
@click="handleClear"
|
|
92
|
+
:disabled="!selectedUser"
|
|
93
|
+
>
|
|
94
|
+
<i class="bi bi-trash me-1"></i> 清除选择
|
|
95
|
+
</button>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
</template>
|
|
100
|
+
|
|
101
|
+
<script setup lang="ts">
|
|
102
|
+
import { ref, watch, nextTick, onMounted, onUnmounted } from 'vue';
|
|
103
|
+
import * as userService from '@/service/account';
|
|
104
|
+
import { modal } from '@/utils/modal';
|
|
105
|
+
|
|
106
|
+
interface User {
|
|
107
|
+
userId: number; // 用户ID,number类型
|
|
108
|
+
account: string; // 账号,用于显示
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface ApiResponse<T> {
|
|
113
|
+
ret: number;
|
|
114
|
+
msg: string;
|
|
115
|
+
data?: T;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface UserListResponseData {
|
|
119
|
+
data: User[];
|
|
120
|
+
total: number;
|
|
121
|
+
page: number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const props = defineProps<{
|
|
125
|
+
modelValue?: number; // 现在绑定的是number类型的userId
|
|
126
|
+
placeholder?: string;
|
|
127
|
+
searchPlaceholder?: string;
|
|
128
|
+
}>();
|
|
129
|
+
|
|
130
|
+
const emit = defineEmits<{
|
|
131
|
+
(e: 'update:modelValue', value: number | undefined): void;
|
|
132
|
+
(e: 'clear'): void;
|
|
133
|
+
}>();
|
|
134
|
+
|
|
135
|
+
// 组件引用
|
|
136
|
+
const searchInput = ref<HTMLInputElement | null>(null);
|
|
137
|
+
|
|
138
|
+
// 下拉框状态
|
|
139
|
+
const isOpen = ref(false);
|
|
140
|
+
|
|
141
|
+
// 搜索相关
|
|
142
|
+
const searchQuery = ref('');
|
|
143
|
+
const loading = ref(false);
|
|
144
|
+
const userList = ref<User[]>([]);
|
|
145
|
+
const page = ref(1);
|
|
146
|
+
const pageSize = ref(20);
|
|
147
|
+
const totalUsers = ref(0);
|
|
148
|
+
|
|
149
|
+
// 内部维护的选中用户对象(包含userId和account)
|
|
150
|
+
const selectedUser = ref<User | undefined>(undefined);
|
|
151
|
+
const isUpdating = ref(false);
|
|
152
|
+
|
|
153
|
+
// 防抖函数
|
|
154
|
+
function debounce<T extends (...args: any[]) => any>(fn: T, delay: number): (...args: Parameters<T>) => void {
|
|
155
|
+
let timer: NodeJS.Timeout | null = null;
|
|
156
|
+
return function(...args: Parameters<T>) {
|
|
157
|
+
if (timer) clearTimeout(timer);
|
|
158
|
+
timer = setTimeout(() => {
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
fn.apply(this, args);
|
|
161
|
+
}, delay);
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 处理搜索输入
|
|
166
|
+
const handleSearchInput = debounce(async (e: Event) => {
|
|
167
|
+
if (isUpdating.value) return;
|
|
168
|
+
|
|
169
|
+
const input = e.target as HTMLInputElement;
|
|
170
|
+
const value = input.value.trim();
|
|
171
|
+
|
|
172
|
+
searchQuery.value = value;
|
|
173
|
+
page.value = 1;
|
|
174
|
+
|
|
175
|
+
if (value) {
|
|
176
|
+
await fetchUsers(value);
|
|
177
|
+
} else {
|
|
178
|
+
userList.value = [];
|
|
179
|
+
}
|
|
180
|
+
}, 150);
|
|
181
|
+
|
|
182
|
+
// 处理选择用户
|
|
183
|
+
const handleSelectUser = async (user: User) => {
|
|
184
|
+
if (isUpdating.value || selectedUser.value?.userId === user.userId) return;
|
|
185
|
+
|
|
186
|
+
//isUpdating.value = true;
|
|
187
|
+
try {
|
|
188
|
+
selectedUser.value = user;
|
|
189
|
+
searchQuery.value = '';
|
|
190
|
+
await nextTick();
|
|
191
|
+
if (searchInput.value) {
|
|
192
|
+
searchInput.value.focus();
|
|
193
|
+
}
|
|
194
|
+
// 选择后关闭下拉框
|
|
195
|
+
closeDropdown();
|
|
196
|
+
} finally {
|
|
197
|
+
//isUpdating.value = false;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// 清除输入框内容
|
|
202
|
+
const clearInput = async () => {
|
|
203
|
+
searchQuery.value = '';
|
|
204
|
+
userList.value = [];
|
|
205
|
+
await nextTick();
|
|
206
|
+
if (searchInput.value) {
|
|
207
|
+
searchInput.value.focus();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// 处理选择变化事件 - 向外传递userId
|
|
212
|
+
watch(
|
|
213
|
+
() => selectedUser.value,
|
|
214
|
+
(newVal) => {
|
|
215
|
+
const id = newVal?.userId || 0;
|
|
216
|
+
if (props.modelValue !== id) {
|
|
217
|
+
emit('update:modelValue', id);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
// 处理键盘事件
|
|
223
|
+
const handleKeydown = async (e: KeyboardEvent) => {
|
|
224
|
+
if (isUpdating.value) return;
|
|
225
|
+
|
|
226
|
+
// 处理删除键
|
|
227
|
+
if (e.key === 'Backspace' && searchQuery.value === '' && selectedUser.value) {
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
handleClear();
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// 处理回车选中第一个
|
|
234
|
+
if (e.key === 'Enter' && userList.value.length > 0) {
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
|
|
237
|
+
const firstUser = userList.value[0];
|
|
238
|
+
if (firstUser) {
|
|
239
|
+
await handleSelectUser(firstUser);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 处理ESC关闭下拉框
|
|
244
|
+
if (e.key === 'Escape') {
|
|
245
|
+
closeDropdown();
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// 切换下拉框显示状态
|
|
250
|
+
const toggleDropdown = async (e: MouseEvent) => {
|
|
251
|
+
|
|
252
|
+
isOpen.value = !isOpen.value;
|
|
253
|
+
|
|
254
|
+
e.stopPropagation?.();
|
|
255
|
+
e.preventDefault?.();
|
|
256
|
+
|
|
257
|
+
if (isOpen.value) {
|
|
258
|
+
await nextTick();
|
|
259
|
+
if (searchInput.value) {
|
|
260
|
+
searchInput.value.focus();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (searchQuery.value.trim()) {
|
|
264
|
+
await fetchUsers(searchQuery.value.trim());
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// 关闭下拉框
|
|
270
|
+
const closeDropdown = () => {
|
|
271
|
+
isOpen.value = false;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// 处理清除选中
|
|
275
|
+
const handleClear = async () => {
|
|
276
|
+
if (isUpdating.value || !selectedUser.value) return;
|
|
277
|
+
|
|
278
|
+
isUpdating.value = true;
|
|
279
|
+
try {
|
|
280
|
+
selectedUser.value = undefined;
|
|
281
|
+
//await clearInput();
|
|
282
|
+
emit('clear');
|
|
283
|
+
} finally {
|
|
284
|
+
isUpdating.value = false;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// 获取用户列表
|
|
289
|
+
const fetchUsers = async (filter: string) => {
|
|
290
|
+
try {
|
|
291
|
+
loading.value = true;
|
|
292
|
+
const response: ApiResponse<UserListResponseData> = await userService.queryUser({
|
|
293
|
+
query: { filter: filter || '' },
|
|
294
|
+
page: page.value,
|
|
295
|
+
size: pageSize.value
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
if (response.ret !== 0) {
|
|
299
|
+
modal.error(response.msg || '获取用户失败', {
|
|
300
|
+
operation: 'GET_USER_LIST',
|
|
301
|
+
code: response.ret
|
|
302
|
+
});
|
|
303
|
+
userList.value = [];
|
|
304
|
+
totalUsers.value = 0;
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
userList.value = response.data || [];
|
|
309
|
+
totalUsers.value = response.total || 0;
|
|
310
|
+
} catch (error) {
|
|
311
|
+
console.error('获取用户列表失败:', error);
|
|
312
|
+
|
|
313
|
+
modal.error(error.message || '获取用户列表失败', {
|
|
314
|
+
operation: 'GET_USER_LIST',
|
|
315
|
+
stack: error.stack
|
|
316
|
+
});
|
|
317
|
+
userList.value = [];
|
|
318
|
+
totalUsers.value = 0;
|
|
319
|
+
} finally {
|
|
320
|
+
loading.value = false;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// 同步外部传入的userId到内部状态
|
|
325
|
+
const syncWithExternalValue = (userId?: number) => {
|
|
326
|
+
if (isUpdating.value) return;
|
|
327
|
+
|
|
328
|
+
isUpdating.value = true;
|
|
329
|
+
try {
|
|
330
|
+
if (userId === undefined) {
|
|
331
|
+
selectedUser.value = undefined;
|
|
332
|
+
} else if (!selectedUser.value || selectedUser.value.userId !== userId) {
|
|
333
|
+
// 如果当前列表中没有该用户,可能需要重新获取或保持ID
|
|
334
|
+
const existingUser = userList.value.find(u => u.userId === userId);
|
|
335
|
+
selectedUser.value = existingUser;
|
|
336
|
+
// 注意:如果用户不在当前列表中,这里只会设置userId,不会显示用户名
|
|
337
|
+
// 实际应用中可能需要额外处理这种情况
|
|
338
|
+
}
|
|
339
|
+
} finally {
|
|
340
|
+
setTimeout(() => {
|
|
341
|
+
isUpdating.value = false;
|
|
342
|
+
}, 0);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// 监听外部传入的modelValue变化
|
|
347
|
+
watch(
|
|
348
|
+
() => props.modelValue,
|
|
349
|
+
(newVal) => {
|
|
350
|
+
syncWithExternalValue(newVal);
|
|
351
|
+
},
|
|
352
|
+
{ immediate: true }
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
// 点击外部关闭下拉框
|
|
356
|
+
const handleClickOutside = (e: MouseEvent) => {
|
|
357
|
+
const dropdown = document.querySelector('.user-permission-selector .dropdown');
|
|
358
|
+
if (dropdown && !dropdown.contains(e.target as Node) && isOpen.value) {
|
|
359
|
+
closeDropdown();
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
onMounted(() => {
|
|
364
|
+
syncWithExternalValue(props.modelValue);
|
|
365
|
+
fetchUsers('');
|
|
366
|
+
document.addEventListener('click', handleClickOutside);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
onUnmounted(() => {
|
|
370
|
+
document.removeEventListener('click', handleClickOutside);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
defineExpose({
|
|
374
|
+
selectedUser,
|
|
375
|
+
totalUsers
|
|
376
|
+
});
|
|
377
|
+
</script>
|
|
378
|
+
|
|
379
|
+
<style scoped>
|
|
380
|
+
.user-permission-selector {
|
|
381
|
+
width: 100%;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.dropdown-item.active {
|
|
385
|
+
background-color: #0d6efd;
|
|
386
|
+
color: white;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.dropdown-menu.show {
|
|
390
|
+
display: block;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/* 自定义滚动条 */
|
|
394
|
+
.dropdown-menu {
|
|
395
|
+
max-height: 300px;
|
|
396
|
+
overflow-y: auto;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
.dropdown-menu::-webkit-scrollbar {
|
|
400
|
+
width: 6px;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.dropdown-menu::-webkit-scrollbar-track {
|
|
404
|
+
background: #f1f1f1;
|
|
405
|
+
border-radius: 3px;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.dropdown-menu::-webkit-scrollbar-thumb {
|
|
409
|
+
background: #ccc;
|
|
410
|
+
border-radius: 3px;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.dropdown-menu::-webkit-scrollbar-thumb:hover {
|
|
414
|
+
background: #aaa;
|
|
415
|
+
}
|
|
416
|
+
</style>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import Entity from '../base/entity';
|
|
2
|
+
import config from '@/base/config';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 系统配置Domain
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface SysConfigState {
|
|
9
|
+
title?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
config?: {
|
|
12
|
+
prefix?: string;
|
|
13
|
+
apiUrl?: string;
|
|
14
|
+
adapter?: string;
|
|
15
|
+
};
|
|
16
|
+
sso?: any;
|
|
17
|
+
user?: UserInfo;
|
|
18
|
+
session?: any;
|
|
19
|
+
isManager: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default class SysConfig extends Entity<SysConfigState> {
|
|
23
|
+
constructor(state?: any) {
|
|
24
|
+
super(state);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 获取系统标题
|
|
29
|
+
*/
|
|
30
|
+
get title() {
|
|
31
|
+
return this.state.title;
|
|
32
|
+
}
|
|
33
|
+
get url() {
|
|
34
|
+
return this.state?.url;
|
|
35
|
+
}
|
|
36
|
+
get sso() {
|
|
37
|
+
return this.state?.sso;
|
|
38
|
+
}
|
|
39
|
+
get config() {
|
|
40
|
+
return this.state?.config;
|
|
41
|
+
}
|
|
42
|
+
get user() {
|
|
43
|
+
return this.state.session?.user;
|
|
44
|
+
}
|
|
45
|
+
get session() {
|
|
46
|
+
return this.state.session;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get isManager() {
|
|
50
|
+
return this.state.isManager;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get rootUrl() {
|
|
54
|
+
return location.origin + (this.config?.prefix || '');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get baseUrl() {
|
|
58
|
+
if(this.sso?.baseUrl) return this.sso.baseUrl;
|
|
59
|
+
else {
|
|
60
|
+
return this.rootUrl;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getLoginUrl(redirectUrl = location.href) {
|
|
65
|
+
if(this.baseUrl === this.rootUrl) return this.baseUrl + '/login';
|
|
66
|
+
return this.baseUrl + '/login?url=' + encodeURIComponent(redirectUrl);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getLogoutUrl(redirectUrl = location.href) {
|
|
70
|
+
if(this.baseUrl === this.rootUrl) return this.baseUrl + '/logout';
|
|
71
|
+
return this.baseUrl + '/logout?url=' + encodeURIComponent(redirectUrl);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export const sysConfig = new SysConfig(config.state);
|