befly-admin-ui 1.9.5 → 1.9.7
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.
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<TDialog v-model:visible="innerVisible" :header="props.title === '' ? true : props.title" :width="props.width" placement="center" attach="body" :close-btn="false" :footer="true" :confirm-loading="props.confirmLoading" :close-on-overlay-click="false" :close-on-esc-keydown="false" @close="onDialogClose" @confirm="onDialogConfirm" @cancel="onDialogCancel">
|
|
2
|
+
<TDialog v-model:visible="innerVisible" :header="props.title === '' ? true : props.title" :width="props.width" :dialog-class-name="props.dialogClassName" placement="center" attach="body" :close-btn="false" :footer="true" :confirm-loading="props.confirmLoading" :close-on-overlay-click="false" :close-on-esc-keydown="false" @close="onDialogClose" @confirm="onDialogConfirm" @cancel="onDialogCancel">
|
|
3
3
|
<template #footer>
|
|
4
4
|
<div class="dialog-footer">
|
|
5
5
|
<TButton variant="outline" @click="onFooterClose">关闭</TButton>
|
|
6
|
-
<
|
|
7
|
-
<TButton theme="primary" :loading="props.confirmLoading">确定</TButton>
|
|
8
|
-
</TPopconfirm>
|
|
6
|
+
<TButton v-if="props.isConfirm" theme="primary" :loading="props.confirmLoading" @click="onFooterConfirm">确定</TButton>
|
|
9
7
|
</div>
|
|
10
8
|
</template>
|
|
11
9
|
<div class="dialog-wrapper">
|
|
@@ -17,7 +15,7 @@
|
|
|
17
15
|
<script setup>
|
|
18
16
|
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
19
17
|
|
|
20
|
-
import { Button as TButton, Dialog as TDialog
|
|
18
|
+
import { Button as TButton, Dialog as TDialog } from "tdesign-vue-next";
|
|
21
19
|
|
|
22
20
|
defineOptions({
|
|
23
21
|
inheritAttrs: false
|
|
@@ -39,6 +37,10 @@ const props = defineProps({
|
|
|
39
37
|
type: String,
|
|
40
38
|
default: "600px"
|
|
41
39
|
},
|
|
40
|
+
dialogClassName: {
|
|
41
|
+
type: String,
|
|
42
|
+
default: ""
|
|
43
|
+
},
|
|
42
44
|
confirmLoading: {
|
|
43
45
|
type: Boolean,
|
|
44
46
|
default: false
|
|
@@ -190,6 +192,7 @@ defineExpose({
|
|
|
190
192
|
background-color: var(--bg-color-page);
|
|
191
193
|
padding: var(--spacing-md);
|
|
192
194
|
border-radius: var(--border-radius);
|
|
195
|
+
max-height: 80vh;
|
|
193
196
|
}
|
|
194
197
|
.dialog-footer {
|
|
195
198
|
width: 100%;
|
package/layouts/default.vue
CHANGED
|
@@ -83,10 +83,11 @@ import { reactive, watch } from "vue";
|
|
|
83
83
|
import { useRoute, useRouter } from "vue-router";
|
|
84
84
|
import { $Http } from "@/plugins/http.js";
|
|
85
85
|
import { $Config } from "@/plugins/config.js";
|
|
86
|
+
import { $Store } from "@/plugins/store.js";
|
|
86
87
|
|
|
87
88
|
const router = useRouter();
|
|
88
89
|
const route = useRoute();
|
|
89
|
-
const uploadHeaders = { Authorization: `Bearer ${
|
|
90
|
+
const uploadHeaders = { Authorization: `Bearer ${$Store.local.get($Config.tokenName, "")}` };
|
|
90
91
|
|
|
91
92
|
function isString(value) {
|
|
92
93
|
return typeof value === "string";
|
|
@@ -243,7 +244,7 @@ async function handleLogout() {
|
|
|
243
244
|
}
|
|
244
245
|
|
|
245
246
|
try {
|
|
246
|
-
|
|
247
|
+
$Store.local.remove($Config.tokenName);
|
|
247
248
|
await router.push($Config.loginPath);
|
|
248
249
|
MessagePlugin.success("退出成功");
|
|
249
250
|
destroy();
|
package/package.json
CHANGED
package/views/login_1/index.vue
CHANGED
|
@@ -70,6 +70,7 @@ import { LockOnIcon, UserIcon } from "tdesign-icons-vue-next";
|
|
|
70
70
|
import { hashPassword } from "befly-admin-ui/utils/hashPassword";
|
|
71
71
|
import { $Http } from "@/plugins/http.js";
|
|
72
72
|
import { $Config } from "@/plugins/config.js";
|
|
73
|
+
import { $Store } from "@/plugins/store.js";
|
|
73
74
|
|
|
74
75
|
const router = useRouter();
|
|
75
76
|
|
|
@@ -109,7 +110,7 @@ async function apiLogin() {
|
|
|
109
110
|
password: hashedPassword
|
|
110
111
|
});
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
$Store.local.set($Config.tokenName, res.data.token);
|
|
113
114
|
|
|
114
115
|
MessagePlugin.success(res.msg || "登录成功");
|
|
115
116
|
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<PageDialog v-model="dialogVisible" :title="$
|
|
2
|
+
<PageDialog v-model="$Computed.dialogVisible" :title="$Computed.dialogTitle" :confirm-loading="$Data.submitting" @confirm="$Method.onSubmit">
|
|
3
3
|
<div class="dialog-wrapper">
|
|
4
|
-
<TForm :model="$Data.formData" label-width="80px" label-position="left" label-align="left" :rules="$
|
|
4
|
+
<TForm :model="$Data.formData" label-width="80px" label-position="left" label-align="left" :rules="$Const.formRules" :ref="(el) => ($From.formRef = el)">
|
|
5
5
|
<TFormItem label="角色" prop="roleCode">
|
|
6
|
-
<TSelect v-model="$Data.formData.roleCode" :options="$
|
|
6
|
+
<TSelect v-model="$Data.formData.roleCode" :options="$Type.roleOptions" placeholder="请选择角色" />
|
|
7
7
|
</TFormItem>
|
|
8
8
|
<TFormItem label="用户名" prop="username">
|
|
9
|
-
<TInput v-model="$Data.formData.username" placeholder="请输入用户名" :disabled="$
|
|
9
|
+
<TInput v-model="$Data.formData.username" placeholder="请输入用户名" :disabled="$Computed.isUpdate" />
|
|
10
10
|
</TFormItem>
|
|
11
|
-
<TFormItem v-if="$
|
|
11
|
+
<TFormItem v-if="$Computed.isAdd" label="密码" prop="password">
|
|
12
12
|
<TInput v-model="$Data.formData.password" type="password" placeholder="请输入密码,至少6位" />
|
|
13
13
|
</TFormItem>
|
|
14
14
|
<TFormItem label="昵称" prop="nickname">
|
|
15
15
|
<TInput v-model="$Data.formData.nickname" placeholder="请输入昵称" />
|
|
16
16
|
</TFormItem>
|
|
17
|
-
<TFormItem v-if="$
|
|
17
|
+
<TFormItem v-if="$Computed.isUpdate" label="状态" prop="state">
|
|
18
18
|
<TRadioGroup v-model="$Data.formData.state">
|
|
19
|
-
<TRadio :
|
|
20
|
-
<TRadio :label="2">禁用</TRadio>
|
|
19
|
+
<TRadio v-for="item in $Type.stateOptions" :key="item.value" :value="item.value">{{ item.label }}</TRadio>
|
|
21
20
|
</TRadioGroup>
|
|
22
21
|
</TFormItem>
|
|
23
22
|
</TForm>
|
|
@@ -26,7 +25,7 @@
|
|
|
26
25
|
</template>
|
|
27
26
|
|
|
28
27
|
<script setup>
|
|
29
|
-
import { computed, reactive
|
|
28
|
+
import { computed, reactive } from "vue";
|
|
30
29
|
|
|
31
30
|
import {
|
|
32
31
|
//
|
|
@@ -54,40 +53,27 @@ const $Prop = defineProps({
|
|
|
54
53
|
},
|
|
55
54
|
rowData: {
|
|
56
55
|
type: Object,
|
|
57
|
-
default: {}
|
|
56
|
+
default: () => ({})
|
|
58
57
|
}
|
|
59
58
|
});
|
|
60
59
|
|
|
61
60
|
const $Emit = defineEmits(["update:modelValue", "success"]);
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
label: "name",
|
|
78
|
-
value: "code"
|
|
62
|
+
const $Const = {
|
|
63
|
+
actionTitleMap: {
|
|
64
|
+
add: "添加管理员",
|
|
65
|
+
upd: "编辑管理员"
|
|
66
|
+
},
|
|
67
|
+
createDefaultFormData() {
|
|
68
|
+
return {
|
|
69
|
+
id: null,
|
|
70
|
+
username: "",
|
|
71
|
+
password: "",
|
|
72
|
+
nickname: "",
|
|
73
|
+
roleCode: "",
|
|
74
|
+
state: 1
|
|
75
|
+
};
|
|
79
76
|
},
|
|
80
|
-
formData: {
|
|
81
|
-
id: null,
|
|
82
|
-
username: "",
|
|
83
|
-
password: "",
|
|
84
|
-
nickname: "",
|
|
85
|
-
roleCode: null,
|
|
86
|
-
state: 1
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const $Data2 = reactive({
|
|
91
77
|
formRules: {
|
|
92
78
|
username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
|
|
93
79
|
password: [
|
|
@@ -97,60 +83,111 @@ const $Data2 = reactive({
|
|
|
97
83
|
roleCode: [{ required: true, message: "请选择角色", trigger: "change" }],
|
|
98
84
|
nickname: [{ min: 2, max: 50, message: "昵称长度在 2 到 50 个字符", trigger: "blur" }]
|
|
99
85
|
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const $Type = reactive({
|
|
89
|
+
roleOptions: [],
|
|
90
|
+
stateOptions: [
|
|
91
|
+
{ label: "正常", value: 1 },
|
|
92
|
+
{ label: "禁用", value: 2 }
|
|
93
|
+
]
|
|
100
94
|
});
|
|
101
95
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
async function apiRoleLists() {
|
|
110
|
-
try {
|
|
111
|
-
const result = await $Http("/core/role/all", {}, [""]);
|
|
112
|
-
$Data.allRoleLists = result.data || [];
|
|
113
|
-
} catch (error) {
|
|
114
|
-
MessagePlugin.error(error.msg || error.message || "加载角色列表失败");
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function onSubmit(context) {
|
|
119
|
-
try {
|
|
120
|
-
const form = formRef.value;
|
|
121
|
-
if (!form) {
|
|
122
|
-
MessagePlugin.warning("表单未就绪");
|
|
123
|
-
return;
|
|
96
|
+
const $Computed = reactive({
|
|
97
|
+
isAdd: computed(() => $Prop.actionType === "add"),
|
|
98
|
+
isUpdate: computed(() => $Prop.actionType === "upd"),
|
|
99
|
+
dialogVisible: computed({
|
|
100
|
+
get: () => $Prop.modelValue,
|
|
101
|
+
set: (value) => {
|
|
102
|
+
$Emit("update:modelValue", value);
|
|
124
103
|
}
|
|
104
|
+
}),
|
|
105
|
+
dialogTitle: computed(() => $Const.actionTitleMap[$Prop.actionType] || "添加管理员")
|
|
106
|
+
});
|
|
125
107
|
|
|
126
|
-
|
|
127
|
-
|
|
108
|
+
const $From = {
|
|
109
|
+
formRef: null
|
|
110
|
+
};
|
|
128
111
|
|
|
129
|
-
|
|
130
|
-
|
|
112
|
+
const $Data = reactive({
|
|
113
|
+
submitting: false,
|
|
114
|
+
formData: $Const.createDefaultFormData()
|
|
115
|
+
});
|
|
131
116
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
117
|
+
const $Method = {
|
|
118
|
+
resetFormData() {
|
|
119
|
+
Object.assign($Data.formData, $Const.createDefaultFormData());
|
|
120
|
+
},
|
|
121
|
+
assignFormData(rowData) {
|
|
122
|
+
Object.assign($Data.formData, $Const.createDefaultFormData(), {
|
|
123
|
+
id: rowData.id ?? null,
|
|
124
|
+
username: rowData.username || "",
|
|
125
|
+
nickname: rowData.nickname || "",
|
|
126
|
+
roleCode: rowData.roleCode || "",
|
|
127
|
+
state: typeof rowData.state === "number" ? rowData.state : 1
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
async apiRoleLists() {
|
|
131
|
+
try {
|
|
132
|
+
const result = await $Http("/core/role/all", {}, [""]);
|
|
133
|
+
const roleList = Array.isArray(result.data?.lists) ? result.data.lists : [];
|
|
134
|
+
$Type.roleOptions = roleList.map((item) => {
|
|
135
|
+
return {
|
|
136
|
+
label: item.name || item.code || "",
|
|
137
|
+
value: item.code || ""
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
} catch (error) {
|
|
141
|
+
MessagePlugin.error(error.msg || error.message || "加载角色列表失败");
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
buildSubmitData() {
|
|
145
|
+
return $Computed.isAdd ? fieldClear($Data.formData, { omitKeys: ["id", "state"] }) : fieldClear($Data.formData, { omitKeys: ["password"] });
|
|
146
|
+
},
|
|
147
|
+
async initData() {
|
|
148
|
+
await $Method.apiRoleLists();
|
|
149
|
+
if ($Computed.isUpdate && $Prop.rowData.id) {
|
|
150
|
+
$Method.assignFormData($Prop.rowData);
|
|
151
|
+
return;
|
|
135
152
|
}
|
|
136
153
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
154
|
+
$Method.resetFormData();
|
|
155
|
+
},
|
|
156
|
+
async onSubmit(context) {
|
|
157
|
+
try {
|
|
158
|
+
const form = $From.formRef;
|
|
159
|
+
if (!form) {
|
|
160
|
+
MessagePlugin.warning("表单未就绪");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const valid = await form.validate();
|
|
165
|
+
if (!valid) return;
|
|
166
|
+
|
|
167
|
+
$Data.submitting = true;
|
|
168
|
+
const formData = $Method.buildSubmitData();
|
|
169
|
+
|
|
170
|
+
const password = typeof formData.password === "string" ? String(formData.password) : "";
|
|
171
|
+
if ($Computed.isAdd && password) {
|
|
172
|
+
formData.password = await hashPassword(password);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const result = await $Http($Computed.isUpdate ? "/core/admin/upd" : "/core/admin/ins", formData);
|
|
176
|
+
|
|
177
|
+
MessagePlugin.success(result.msg);
|
|
178
|
+
$Emit("success");
|
|
179
|
+
if (context && typeof context.close === "function") {
|
|
180
|
+
context.close();
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
MessagePlugin.error(error.msg || error.message || "提交失败");
|
|
184
|
+
} finally {
|
|
185
|
+
$Data.submitting = false;
|
|
143
186
|
}
|
|
144
|
-
} catch (error) {
|
|
145
|
-
MessagePlugin.error(error.msg || error.message || "提交失败");
|
|
146
|
-
} finally {
|
|
147
|
-
$Data.submitting = false;
|
|
148
187
|
}
|
|
149
|
-
}
|
|
188
|
+
};
|
|
150
189
|
|
|
151
|
-
initData();
|
|
190
|
+
$Method.initData();
|
|
152
191
|
</script>
|
|
153
192
|
|
|
154
|
-
<style scoped lang="scss">
|
|
155
|
-
// 可根据需要添加样式
|
|
156
|
-
</style>
|
|
193
|
+
<style scoped lang="scss"></style>
|
|
@@ -91,9 +91,10 @@ import DetailPanel from "befly-admin-ui/components/detailPanel.vue";
|
|
|
91
91
|
import PageTableDetail from "befly-admin-ui/components/pageTableDetail.vue";
|
|
92
92
|
import { withDefaultColumns } from "befly-admin-ui/utils/withDefaultColumns";
|
|
93
93
|
import { $Config } from "@/plugins/config.js";
|
|
94
|
+
import { $Store } from "@/plugins/store.js";
|
|
94
95
|
|
|
95
96
|
const uploadHeaders = {
|
|
96
|
-
Authorization: `Bearer ${
|
|
97
|
+
Authorization: `Bearer ${$Store.local.get($Config.tokenName, "")}`
|
|
97
98
|
};
|
|
98
99
|
|
|
99
100
|
const $Data = reactive({
|