RenameFolderDialog.vue
3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<template>
<div class="dialog-mask">
<div class="dialog-panel">
<div class="dialog-title">{{ $t("KnowledgeBase.renameFolder") }}</div>
<input
v-model="folderName"
class="dialog-input"
:class="{ error: errorMessage }"
:placeholder="$t('KnowledgeBase.folderNamePlaceholder')"
@keyup.enter="onRename"
@input="errorMessage = ''"
/>
<div v-if="errorMessage" class="error-message">
{{ errorMessage }}
</div>
<div class="dialog-actions">
<button class="dialog-btn" @click="onCancel">
{{ $t("common.cancel") }}
</button>
<button
class="dialog-btn primary"
:disabled="!folderName.trim()"
@click="onRename"
>
{{ $t("common.save") }}
</button>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, watch } from "vue";
import { useI18n } from "vue-i18n";
interface FolderItem {
id: string | number;
name: string;
[key: string]: any;
}
interface Props {
folder: FolderItem;
}
const props = defineProps<Props>();
const emit = defineEmits<{
(e: "close"): void;
(e: "rename", data: { id: string | number; name: string }): void;
}>();
const { t } = useI18n();
const folderName = ref(props.folder?.name || "");
const errorMessage = ref("");
watch(
() => props.folder,
(newVal) => {
folderName.value = newVal?.name || "";
},
);
const validateFolderName = (name: string): string | null => {
// 检查长度限制
if (name.length > 30) {
return t("KnowledgeBase.folderNameTooLong") || "文件夹名最长不超过30个字符";
}
// 检查禁用字符
const forbiddenChars = /[/\\:*"<>|?]/;
if (forbiddenChars.test(name)) {
return (
t("KnowledgeBase.folderNameInvalidChars") ||
'文件夹名不能包含以下字符:/ \\ : * " < > | ?'
);
}
return null;
};
const onCancel = () => {
emit("close");
};
const onRename = () => {
if (folderName.value.trim()) {
const folderNameValue = folderName.value.trim();
// 验证文件夹名
const error = validateFolderName(folderNameValue);
if (error) {
errorMessage.value = error;
return;
}
// 清除错误信息
errorMessage.value = "";
// 直接触发重命名事件,不显示确认对话框
emit("rename", {
id: props.folder.id,
name: folderNameValue,
});
}
};
</script>
<style scoped lang="scss">
.dialog-mask {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.35);
display: flex;
align-items: center;
justify-content: center;
z-index: 2000;
}
.dialog-panel {
background: var(--color-card);
border-radius: 10px;
padding: 28px 32px 20px 32px;
min-width: 320px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
display: flex;
flex-direction: column;
gap: 18px;
}
.dialog-title {
font-size: 18px;
font-weight: 700;
color: var(--color-text);
margin-bottom: 6px;
}
.dialog-input {
padding: 8px 12px;
border: 1px solid var(--color-border);
border-radius: 6px;
background: var(--color-bg);
color: var(--color-text);
font-size: 15px;
margin-bottom: 8px;
&:focus {
border-color: var(--color-primary);
outline: none;
}
&.error {
border-color: var(--color-danger);
}
}
.error-message {
color: var(--color-danger);
font-size: 13px;
margin-top: -8px;
margin-bottom: 8px;
}
.dialog-actions {
display: flex;
justify-content: flex-end;
gap: 12px;
}
.dialog-btn {
padding: 7px 18px;
border-radius: 6px;
border: none;
background: var(--color-card);
color: var(--color-text);
font-size: 15px;
font-weight: 400;
cursor: pointer;
transition:
background 0.2s,
color 0.2s;
&.primary {
background: var(--color-primary);
color: #fff;
}
&:disabled {
opacity: 0.5;
cursor: not-allowed;
}
}
</style>