@befly-addon/admin 1.2.0 → 1.2.2
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/adminViews/403_1/index.vue +75 -0
- package/adminViews/config/dict/components/edit.vue +109 -0
- package/adminViews/config/dict/index.vue +266 -0
- package/adminViews/config/dictType/components/edit.vue +100 -0
- package/adminViews/config/dictType/index.vue +244 -0
- package/adminViews/config/index.vue +12 -0
- package/adminViews/config/system/components/edit.vue +171 -0
- package/adminViews/config/system/index.vue +286 -0
- package/adminViews/index/components/addonList.vue +132 -0
- package/adminViews/index/components/environmentInfo.vue +100 -0
- package/adminViews/index/components/operationLogs.vue +112 -0
- package/adminViews/index/components/performanceMetrics.vue +145 -0
- package/adminViews/index/components/quickActions.vue +30 -0
- package/adminViews/index/components/serviceStatus.vue +192 -0
- package/adminViews/index/components/systemNotifications.vue +137 -0
- package/adminViews/index/components/systemOverview.vue +190 -0
- package/adminViews/index/components/systemResources.vue +111 -0
- package/adminViews/index/components/userInfo.vue +204 -0
- package/adminViews/index/index.vue +74 -0
- package/adminViews/log/email/index.vue +292 -0
- package/adminViews/log/index.vue +12 -0
- package/adminViews/log/login/index.vue +187 -0
- package/adminViews/log/operate/index.vue +249 -0
- package/adminViews/login_1/index.vue +415 -0
- package/adminViews/people/admin/components/edit.vue +168 -0
- package/adminViews/people/admin/index.vue +240 -0
- package/adminViews/people/index.vue +12 -0
- package/adminViews/permission/api/index.vue +149 -0
- package/adminViews/permission/index.vue +12 -0
- package/adminViews/permission/menu/index.vue +130 -0
- package/adminViews/permission/role/components/api.vue +361 -0
- package/adminViews/permission/role/components/edit.vue +142 -0
- package/adminViews/permission/role/components/menu.vue +118 -0
- package/adminViews/permission/role/index.vue +263 -0
- package/package.json +12 -10
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="login-container">
|
|
3
|
+
<!-- 左侧装饰区域 -->
|
|
4
|
+
<div class="left-section">
|
|
5
|
+
<div class="bg-decoration">
|
|
6
|
+
<div class="circle circle-1"></div>
|
|
7
|
+
<div class="circle circle-2"></div>
|
|
8
|
+
<div class="circle circle-3"></div>
|
|
9
|
+
</div>
|
|
10
|
+
<div class="welcome-content">
|
|
11
|
+
<h1 class="brand-title">Befly</h1>
|
|
12
|
+
<p class="brand-subtitle">轻量级业务快速开发框架</p>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<!-- 右侧登录区域 -->
|
|
17
|
+
<div class="right-section">
|
|
18
|
+
<div class="login-box">
|
|
19
|
+
<div class="login-header">
|
|
20
|
+
<h2 class="login-title">欢迎回来</h2>
|
|
21
|
+
<p class="login-subtitle">请登录您的账户</p>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<TForm :model="$Data.formData" :rules="$Data2.formRules" :ref="(el) => ($From.form = el)" class="login-form" :show-message="false" label-width="0">
|
|
25
|
+
<TFormItem prop="account">
|
|
26
|
+
<TInputAdornment>
|
|
27
|
+
<template #prepend>
|
|
28
|
+
<TSelect v-model="$Data.formData.loginType" :style="{ width: '110px' }" size="large" :popup-props="{ overlayClassName: 'login-type-select-popup' }">
|
|
29
|
+
<TOption value="username" label="用户名" />
|
|
30
|
+
<TOption value="email" label="邮箱" />
|
|
31
|
+
<TOption value="phone" label="手机号" />
|
|
32
|
+
</TSelect>
|
|
33
|
+
</template>
|
|
34
|
+
<TInput v-model="$Data.formData.account" :placeholder="$Data.formData.loginType === 'username' ? '请输入用户名' : $Data.formData.loginType === 'email' ? '请输入邮箱' : '请输入手机号'" size="large" clearable @enter="$Method.apiLogin">
|
|
35
|
+
<template #prefix-icon>
|
|
36
|
+
<ILucideUser />
|
|
37
|
+
</template>
|
|
38
|
+
</TInput>
|
|
39
|
+
</TInputAdornment>
|
|
40
|
+
</TFormItem>
|
|
41
|
+
|
|
42
|
+
<TFormItem prop="password">
|
|
43
|
+
<TInput v-model="$Data.formData.password" type="password" placeholder="密码" size="large" clearable @enter="$Method.apiLogin">
|
|
44
|
+
<template #prefix-icon>
|
|
45
|
+
<ILucideLock />
|
|
46
|
+
</template>
|
|
47
|
+
</TInput>
|
|
48
|
+
</TFormItem>
|
|
49
|
+
|
|
50
|
+
<div class="form-options">
|
|
51
|
+
<TCheckbox v-model="$Data.rememberMe">记住我</TCheckbox>
|
|
52
|
+
<a href="#" class="link-text">忘记密码?</a>
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<TButton theme="primary" class="login-btn" size="large" block :loading="$Data.loading" @click="$Method.apiLogin"> 登录 </TButton>
|
|
56
|
+
</TForm>
|
|
57
|
+
|
|
58
|
+
<div class="login-footer">
|
|
59
|
+
<p class="copyright">© 2024 Befly. All rights reserved.</p>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</template>
|
|
65
|
+
|
|
66
|
+
<script setup>
|
|
67
|
+
import { useRouter } from "vue-router";
|
|
68
|
+
import { Form as TForm, FormItem as TFormItem, Input as TInput, Button as TButton, Checkbox as TCheckbox, InputAdornment as TInputAdornment, Select as TSelect, Option as TOption, MessagePlugin } from "tdesign-vue-next";
|
|
69
|
+
import ILucideUser from "~icons/lucide/user";
|
|
70
|
+
import ILucideLock from "~icons/lucide/lock";
|
|
71
|
+
import { $Http } from "@/plugins/http";
|
|
72
|
+
import { $Storage } from "@/plugins/storage";
|
|
73
|
+
import { hashPassword } from "befly-vite/utils/hashPassword";
|
|
74
|
+
|
|
75
|
+
definePage({
|
|
76
|
+
meta: {
|
|
77
|
+
title: "登录页",
|
|
78
|
+
order: 100
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const router = useRouter();
|
|
83
|
+
|
|
84
|
+
// 表单引用
|
|
85
|
+
const $From = $shallowRef({
|
|
86
|
+
form: null
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// 数据定义
|
|
90
|
+
const $Data = $ref({
|
|
91
|
+
loading: false,
|
|
92
|
+
rememberMe: false,
|
|
93
|
+
formData: {
|
|
94
|
+
loginType: "username",
|
|
95
|
+
account: "",
|
|
96
|
+
password: ""
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const $Data2 = $shallowRef({
|
|
101
|
+
formRules: {
|
|
102
|
+
account: [{ required: true, message: "请输入账号", trigger: "blur" }],
|
|
103
|
+
password: [{ required: true, message: "请输入密码", trigger: "blur" }]
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// 方法定义
|
|
108
|
+
const $Method = {
|
|
109
|
+
async apiLogin() {
|
|
110
|
+
try {
|
|
111
|
+
const valid = await $From.form.validate();
|
|
112
|
+
|
|
113
|
+
$Data.loading = true;
|
|
114
|
+
|
|
115
|
+
// 对密码进行 SHA-256 加密
|
|
116
|
+
const hashedPassword = await hashPassword($Data.formData.password);
|
|
117
|
+
|
|
118
|
+
const res = await $Http("/addon/admin/auth/login", {
|
|
119
|
+
loginType: $Data.formData.loginType,
|
|
120
|
+
account: $Data.formData.account,
|
|
121
|
+
password: hashedPassword
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// 先保存 token
|
|
125
|
+
$Storage.local.set("token", res.data.token);
|
|
126
|
+
|
|
127
|
+
// 如果返回用户信息,也可以存储
|
|
128
|
+
if (res.data.userInfo) {
|
|
129
|
+
$Storage.local.set("userInfo", res.data.userInfo);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
MessagePlugin.success(res.msg || "登录成功");
|
|
133
|
+
|
|
134
|
+
// 跳转到首页,路由守卫会自动加载菜单
|
|
135
|
+
await router.push("/");
|
|
136
|
+
} catch (error) {
|
|
137
|
+
MessagePlugin.error("登录失败");
|
|
138
|
+
} finally {
|
|
139
|
+
$Data.loading = false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
</script>
|
|
144
|
+
|
|
145
|
+
<style scoped lang="scss">
|
|
146
|
+
.login-container {
|
|
147
|
+
display: flex;
|
|
148
|
+
width: 100%;
|
|
149
|
+
min-height: 100vh;
|
|
150
|
+
background: var(--login-bg);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 左侧装饰区域
|
|
154
|
+
.left-section {
|
|
155
|
+
flex: 1;
|
|
156
|
+
position: relative;
|
|
157
|
+
display: flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
justify-content: center;
|
|
160
|
+
background: linear-gradient(135deg, var(--login-left-gradient-start) 0%, var(--login-left-gradient-end) 100%);
|
|
161
|
+
overflow: hidden;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.bg-decoration {
|
|
165
|
+
position: absolute;
|
|
166
|
+
width: 100%;
|
|
167
|
+
height: 100%;
|
|
168
|
+
overflow: hidden;
|
|
169
|
+
|
|
170
|
+
.circle {
|
|
171
|
+
position: absolute;
|
|
172
|
+
border-radius: 50%;
|
|
173
|
+
background: var(--login-circle-bg);
|
|
174
|
+
animation: float 20s infinite ease-in-out;
|
|
175
|
+
|
|
176
|
+
&.circle-1 {
|
|
177
|
+
width: 400px;
|
|
178
|
+
height: 400px;
|
|
179
|
+
top: -100px;
|
|
180
|
+
left: -100px;
|
|
181
|
+
animation-delay: 0s;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
&.circle-2 {
|
|
185
|
+
width: 300px;
|
|
186
|
+
height: 300px;
|
|
187
|
+
bottom: -50px;
|
|
188
|
+
right: -50px;
|
|
189
|
+
animation-delay: 7s;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
&.circle-3 {
|
|
193
|
+
width: 200px;
|
|
194
|
+
height: 200px;
|
|
195
|
+
top: 50%;
|
|
196
|
+
right: 10%;
|
|
197
|
+
animation-delay: 14s;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@keyframes float {
|
|
203
|
+
0%,
|
|
204
|
+
100% {
|
|
205
|
+
transform: translateY(0) scale(1);
|
|
206
|
+
}
|
|
207
|
+
50% {
|
|
208
|
+
transform: translateY(-20px) scale(1.05);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.welcome-content {
|
|
213
|
+
position: relative;
|
|
214
|
+
z-index: 1;
|
|
215
|
+
color: #fff;
|
|
216
|
+
text-align: center;
|
|
217
|
+
padding: 2rem;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.brand-title {
|
|
221
|
+
font-size: 4rem;
|
|
222
|
+
font-weight: 700;
|
|
223
|
+
margin-bottom: 1rem;
|
|
224
|
+
letter-spacing: 2px;
|
|
225
|
+
color: var(--login-brand-title);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.brand-subtitle {
|
|
229
|
+
font-size: 1.25rem;
|
|
230
|
+
margin-bottom: 3rem;
|
|
231
|
+
color: var(--login-brand-subtitle);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 右侧登录区域
|
|
235
|
+
.right-section {
|
|
236
|
+
flex: 1;
|
|
237
|
+
display: flex;
|
|
238
|
+
align-items: center;
|
|
239
|
+
justify-content: center;
|
|
240
|
+
padding: 2rem;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.login-box {
|
|
244
|
+
width: 100%;
|
|
245
|
+
max-width: 440px;
|
|
246
|
+
background: var(--login-card-bg);
|
|
247
|
+
border: 1px solid var(--login-card-border);
|
|
248
|
+
border-radius: 16px;
|
|
249
|
+
box-shadow: 0 10px 40px var(--login-card-shadow);
|
|
250
|
+
padding: 3rem 2.5rem;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.login-header {
|
|
254
|
+
text-align: center;
|
|
255
|
+
margin-bottom: 2.5rem;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.login-title {
|
|
259
|
+
font-size: 2rem;
|
|
260
|
+
font-weight: 600;
|
|
261
|
+
color: var(--login-title);
|
|
262
|
+
margin-bottom: 0.5rem;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.login-subtitle {
|
|
266
|
+
font-size: 1rem;
|
|
267
|
+
color: var(--login-subtitle);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.login-footer {
|
|
271
|
+
margin-top: 2rem;
|
|
272
|
+
text-align: center;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.copyright {
|
|
276
|
+
font-size: 0.875rem;
|
|
277
|
+
color: var(--login-subtitle);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.login-form {
|
|
281
|
+
width: 100%;
|
|
282
|
+
|
|
283
|
+
:deep(.t-form__item) {
|
|
284
|
+
margin-bottom: 1.25rem;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
:deep(.t-form__controls) {
|
|
288
|
+
width: 100%;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
:deep(.t-input-adornment) {
|
|
292
|
+
width: 100%;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
:deep(.t-input-adornment__prepend) {
|
|
296
|
+
padding: 0;
|
|
297
|
+
border-right: 1px solid var(--login-card-border);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
:deep(.t-input) {
|
|
301
|
+
width: 100%;
|
|
302
|
+
border-radius: 8px;
|
|
303
|
+
transition: all 0.3s;
|
|
304
|
+
|
|
305
|
+
&:hover {
|
|
306
|
+
border-color: #667eea;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
&:focus-within {
|
|
310
|
+
border-color: #667eea;
|
|
311
|
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
:deep(.t-input__wrap) {
|
|
316
|
+
width: 100%;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.form-options {
|
|
321
|
+
display: flex;
|
|
322
|
+
justify-content: space-between;
|
|
323
|
+
align-items: center;
|
|
324
|
+
margin-bottom: 1.5rem;
|
|
325
|
+
font-size: 0.875rem;
|
|
326
|
+
|
|
327
|
+
.link-text {
|
|
328
|
+
color: var(--login-link);
|
|
329
|
+
text-decoration: none;
|
|
330
|
+
transition: color 0.3s;
|
|
331
|
+
|
|
332
|
+
&:hover {
|
|
333
|
+
color: var(--login-link-hover);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.login-btn {
|
|
339
|
+
width: 100%;
|
|
340
|
+
height: 48px;
|
|
341
|
+
border-radius: 8px;
|
|
342
|
+
font-size: 1rem;
|
|
343
|
+
font-weight: 600;
|
|
344
|
+
background: linear-gradient(135deg, var(--login-btn-gradient-start) 0%, var(--login-btn-gradient-end) 100%);
|
|
345
|
+
border: none;
|
|
346
|
+
transition: all 0.3s;
|
|
347
|
+
|
|
348
|
+
&:hover {
|
|
349
|
+
transform: translateY(-2px);
|
|
350
|
+
box-shadow: 0 8px 20px var(--login-btn-shadow);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
&:active {
|
|
354
|
+
transform: translateY(0);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
:deep(.t-button__text) {
|
|
358
|
+
color: #fff;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 响应式设计
|
|
363
|
+
@media (max-width: 1024px) {
|
|
364
|
+
.login-container {
|
|
365
|
+
flex-direction: column;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.left-section {
|
|
369
|
+
min-height: 300px;
|
|
370
|
+
flex: none;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.brand-title {
|
|
374
|
+
font-size: 3rem;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
.right-section {
|
|
378
|
+
flex: 1;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
@media (max-width: 768px) {
|
|
383
|
+
.left-section {
|
|
384
|
+
min-height: 200px;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.brand-title {
|
|
388
|
+
font-size: 2.5rem;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.brand-subtitle {
|
|
392
|
+
font-size: 1rem;
|
|
393
|
+
margin-bottom: 2rem;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.login-box {
|
|
397
|
+
padding: 2rem 1.5rem;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
.login-title {
|
|
401
|
+
font-size: 1.75rem;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
@media (max-width: 480px) {
|
|
406
|
+
.right-section {
|
|
407
|
+
padding: 1rem;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
.login-box {
|
|
411
|
+
padding: 1.5rem 1rem;
|
|
412
|
+
border-radius: 12px;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
</style>
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<TDialog v-model:visible="$Data.visible" :header="$Prop.actionType === 'upd' ? '编辑管理员' : '添加管理员'" width="600px" :append-to-body="true" :show-footer="true" :esc-closable="false" top="10vh" @close="$Method.onClose">
|
|
3
|
+
<div class="dialog-wrapper">
|
|
4
|
+
<TForm :model="$Data.formData" label-width="80px" label-position="left" label-align="left" :rules="$Data2.formRules" :ref="(el) => ($From.form = el)">
|
|
5
|
+
<TFormItem label="角色" prop="roleCode">
|
|
6
|
+
<TSelect v-model="$Data.formData.roleCode" :options="$Data.allRoleLists" :keys="$Data.keys" placeholder="请选择角色" />
|
|
7
|
+
</TFormItem>
|
|
8
|
+
<TFormItem label="用户名" prop="username">
|
|
9
|
+
<TInput v-model="$Data.formData.username" placeholder="请输入用户名" :disabled="$Prop.actionType === 'upd'" />
|
|
10
|
+
</TFormItem>
|
|
11
|
+
<TFormItem v-if="$Prop.actionType === 'add'" label="密码" prop="password">
|
|
12
|
+
<TInput v-model="$Data.formData.password" type="password" placeholder="请输入密码,至少6位" />
|
|
13
|
+
</TFormItem>
|
|
14
|
+
<TFormItem label="昵称" prop="nickname">
|
|
15
|
+
<TInput v-model="$Data.formData.nickname" placeholder="请输入昵称" />
|
|
16
|
+
</TFormItem>
|
|
17
|
+
<TFormItem v-if="$Prop.actionType === 'upd'" label="状态" prop="state">
|
|
18
|
+
<TRadioGroup v-model="$Data.formData.state">
|
|
19
|
+
<TRadio :label="1">正常</TRadio>
|
|
20
|
+
<TRadio :label="2">禁用</TRadio>
|
|
21
|
+
</TRadioGroup>
|
|
22
|
+
</TFormItem>
|
|
23
|
+
</TForm>
|
|
24
|
+
</div>
|
|
25
|
+
<template #footer>
|
|
26
|
+
<div class="dialog-footer">
|
|
27
|
+
<t-space>
|
|
28
|
+
<TButton theme="default" @click="$Method.onClose">取消</TButton>
|
|
29
|
+
<TButton theme="primary" :loading="$Data.submitting" @click="$Method.onSubmit">确定</TButton>
|
|
30
|
+
</t-space>
|
|
31
|
+
</div>
|
|
32
|
+
</template>
|
|
33
|
+
</TDialog>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script setup>
|
|
37
|
+
import {
|
|
38
|
+
//
|
|
39
|
+
Dialog as TDialog,
|
|
40
|
+
Form as TForm,
|
|
41
|
+
FormItem as TFormItem,
|
|
42
|
+
Input as TInput,
|
|
43
|
+
Select as TSelect,
|
|
44
|
+
RadioGroup as TRadioGroup,
|
|
45
|
+
Radio as TRadio,
|
|
46
|
+
Button as TButton,
|
|
47
|
+
MessagePlugin
|
|
48
|
+
} from "tdesign-vue-next";
|
|
49
|
+
import { $Http } from "@/plugins/http";
|
|
50
|
+
import { fieldClear } from "befly-vite/utils/fieldClear";
|
|
51
|
+
import { hashPassword } from "befly-vite/utils/hashPassword";
|
|
52
|
+
|
|
53
|
+
const $Prop = defineProps({
|
|
54
|
+
modelValue: {
|
|
55
|
+
type: Boolean,
|
|
56
|
+
default: false
|
|
57
|
+
},
|
|
58
|
+
actionType: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: "add"
|
|
61
|
+
},
|
|
62
|
+
rowData: {
|
|
63
|
+
type: Object,
|
|
64
|
+
default: {}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const $Emit = defineEmits(["update:modelValue", "success"]);
|
|
69
|
+
|
|
70
|
+
// 表单引用
|
|
71
|
+
const $From = $shallowRef({
|
|
72
|
+
form: null
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const $Data = $ref({
|
|
76
|
+
visible: false,
|
|
77
|
+
submitting: false,
|
|
78
|
+
allRoleLists: [],
|
|
79
|
+
keys: {
|
|
80
|
+
label: "name",
|
|
81
|
+
value: "code"
|
|
82
|
+
},
|
|
83
|
+
formData: {
|
|
84
|
+
id: null,
|
|
85
|
+
username: "",
|
|
86
|
+
password: "",
|
|
87
|
+
nickname: "",
|
|
88
|
+
roleCode: null,
|
|
89
|
+
state: 1
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const $Data2 = $shallowRef({
|
|
94
|
+
formRules: {
|
|
95
|
+
username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
|
|
96
|
+
password: [
|
|
97
|
+
{ required: true, message: "请输入密码", trigger: "blur" },
|
|
98
|
+
{ min: 6, message: "密码至少6位", trigger: "blur" }
|
|
99
|
+
],
|
|
100
|
+
roleCode: [{ required: true, message: "请选择角色", trigger: "change" }],
|
|
101
|
+
nickname: [{ min: 2, max: 50, message: "昵称长度在 2 到 50 个字符", trigger: "blur" }]
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// 方法集合
|
|
106
|
+
const $Method = {
|
|
107
|
+
async initData() {
|
|
108
|
+
$Method.onShow();
|
|
109
|
+
await $Method.apiRoleLists();
|
|
110
|
+
if ($Prop.actionType === "upd" && $Prop.rowData.id) {
|
|
111
|
+
$Data.formData = { ...$Prop.rowData };
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
onShow() {
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
$Data.visible = $Prop.modelValue;
|
|
118
|
+
}, 100);
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
onClose() {
|
|
122
|
+
$Data.visible = false;
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
$Emit("update:modelValue", false);
|
|
125
|
+
}, 300);
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
async apiRoleLists() {
|
|
129
|
+
try {
|
|
130
|
+
const result = await $Http("/addon/admin/role/all");
|
|
131
|
+
$Data.allRoleLists = result.data || [];
|
|
132
|
+
} catch (error) {
|
|
133
|
+
MessagePlugin.error("加载角色列表失败");
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
async onSubmit() {
|
|
138
|
+
try {
|
|
139
|
+
const valid = await $From.form.validate();
|
|
140
|
+
if (!valid) return;
|
|
141
|
+
|
|
142
|
+
$Data.submitting = true;
|
|
143
|
+
const formData = $Prop.actionType === "add" ? fieldClear($Data.formData, { omitKeys: ["id", "state"] }) : fieldClear($Data.formData, { omitKeys: ["password"] });
|
|
144
|
+
|
|
145
|
+
// 添加管理员时,对密码进行 SHA-256 加密
|
|
146
|
+
if ($Prop.actionType === "add" && formData.password) {
|
|
147
|
+
formData.password = await hashPassword(formData.password);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const result = await $Http($Prop.actionType === "upd" ? "/addon/admin/admin/upd" : "/addon/admin/admin/ins", formData);
|
|
151
|
+
|
|
152
|
+
MessagePlugin.success(result.msg);
|
|
153
|
+
$Emit("success");
|
|
154
|
+
$Method.onClose();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
MessagePlugin.error(error.msg || "提交失败");
|
|
157
|
+
} finally {
|
|
158
|
+
$Data.submitting = false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
$Method.initData();
|
|
164
|
+
</script>
|
|
165
|
+
|
|
166
|
+
<style scoped lang="scss">
|
|
167
|
+
// 可根据需要添加样式
|
|
168
|
+
</style>
|