mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
update: 更新替换词数量限制
This commit is contained in:
@@ -86,11 +86,9 @@ export default {
|
||||
RequestService.clearRequestTime()
|
||||
callback(res)
|
||||
})
|
||||
.networkFail((err) => {
|
||||
console.error('更新替换词文件失败:', err)
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.updateFile(data, callback)
|
||||
})
|
||||
.fail((err) => {
|
||||
RequestService.clearRequestTime()
|
||||
callback(err)
|
||||
}).send()
|
||||
},
|
||||
|
||||
|
||||
@@ -49,7 +49,9 @@
|
||||
</div>
|
||||
</el-button>
|
||||
</el-upload>
|
||||
<span class="word-count">{{ wordCount }}{{ $t('replacementDialog.wordCountUnit') }}</span>
|
||||
<span class="word-count" :class="{ 'over-limit': isOverLimit }">
|
||||
{{ wordCountText }}{{ $t('replacementDialog.wordCountUnit') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
@@ -88,12 +90,22 @@ export default {
|
||||
}
|
||||
},
|
||||
data() {
|
||||
const MAX_WORD_COUNT = 4000;
|
||||
|
||||
const validateContent = (rule, value, callback) => {
|
||||
if (!value || !value.trim()) {
|
||||
callback(new Error(this.$t('replacementDialog.requiredContent')));
|
||||
return;
|
||||
}
|
||||
|
||||
const lines = this.getValidLines(value);
|
||||
const lineCount = lines.length;
|
||||
|
||||
if (lineCount > MAX_WORD_COUNT) {
|
||||
callback(new Error(this.$t('replacementDialog.maxWordCountExceeded', { max: MAX_WORD_COUNT })));
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const pipeCount = (lines[i].match(/\|/g) || []).length;
|
||||
if (pipeCount !== 1) {
|
||||
@@ -130,6 +142,7 @@ export default {
|
||||
fileName: '',
|
||||
content: ''
|
||||
},
|
||||
maxWordCount: MAX_WORD_COUNT,
|
||||
rules: {
|
||||
fileName: [
|
||||
{ required: true, message: this.$t('replacementDialog.requiredFileName'), trigger: "blur" }
|
||||
@@ -143,14 +156,22 @@ export default {
|
||||
computed: {
|
||||
wordCount() {
|
||||
if (!this.localForm.content) return 0;
|
||||
const contentStr = Array.isArray(this.localForm.content)
|
||||
? this.localForm.content.join('\n')
|
||||
const contentStr = Array.isArray(this.localForm.content)
|
||||
? this.localForm.content.join('\n')
|
||||
: this.localForm.content;
|
||||
if (!contentStr.trim()) {
|
||||
return 0;
|
||||
}
|
||||
const lines = this.getValidLines();
|
||||
return lines.filter(line => line.includes('|')).length;
|
||||
},
|
||||
|
||||
isOverLimit() {
|
||||
return this.wordCount > this.maxWordCount;
|
||||
},
|
||||
|
||||
wordCountText() {
|
||||
return `${this.wordCount} / ${this.maxWordCount}`;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -170,7 +191,7 @@ export default {
|
||||
|
||||
handleFileChange(file) {
|
||||
if (!file) return;
|
||||
|
||||
|
||||
const rawFile = file.raw;
|
||||
if (!rawFile) return;
|
||||
|
||||
@@ -178,6 +199,14 @@ export default {
|
||||
reader.onload = (e) => {
|
||||
const content = e.target.result;
|
||||
this.localForm.content = content;
|
||||
|
||||
const lines = this.getValidLines(content);
|
||||
if (lines.length > this.maxWordCount) {
|
||||
this.$message.warning(
|
||||
this.$t('replacementDialog.maxWordCountExceeded', { max: this.maxWordCount })
|
||||
);
|
||||
}
|
||||
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.form) {
|
||||
this.$refs.form.clearValidate('content');
|
||||
@@ -193,6 +222,13 @@ export default {
|
||||
submit() {
|
||||
this.$refs.form.validate((valid) => {
|
||||
if (valid) {
|
||||
if (this.isOverLimit) {
|
||||
this.$message.error(
|
||||
this.$t('replacementDialog.maxWordCountExceeded', { max: this.maxWordCount })
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const submitData = {
|
||||
id: this.localForm.id,
|
||||
fileName: this.localForm.fileName,
|
||||
@@ -428,6 +464,12 @@ export default {
|
||||
font-size: 13px;
|
||||
color: #64748b;
|
||||
font-weight: 500;
|
||||
transition: color 0.3s ease;
|
||||
|
||||
&.over-limit {
|
||||
color: #ef4444;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -385,6 +385,7 @@ export default {
|
||||
'replacementDialog.invalidOriginalChar': 'Zeile {line} Originalwort enthält Sonderzeichen',
|
||||
'replacementDialog.invalidReplacementChar': 'Zeile {line} Ersetzungswort enthält Sonderzeichen',
|
||||
'replacementDialog.readFileError': 'Datei konnte nicht gelesen werden',
|
||||
'replacementDialog.maxWordCountExceeded': 'Die Anzahl der Ersetzungswörter darf {max} nicht überschreiten',
|
||||
|
||||
// Ersetzungswortverwaltung Seite Text
|
||||
'replacementWordManagement.getListFailed': 'Liste konnte nicht abgerufen werden',
|
||||
|
||||
@@ -385,6 +385,7 @@ export default {
|
||||
'replacementDialog.invalidOriginalChar': 'Line {line} original word contains special characters',
|
||||
'replacementDialog.invalidReplacementChar': 'Line {line} replacement word contains special characters',
|
||||
'replacementDialog.readFileError': 'Failed to read file',
|
||||
'replacementDialog.maxWordCountExceeded': 'Replacement word count cannot exceed {max}',
|
||||
|
||||
// Replacement Word Management page text
|
||||
'replacementWordManagement.getListFailed': 'Failed to get list',
|
||||
|
||||
@@ -385,6 +385,7 @@ export default {
|
||||
'replacementDialog.invalidOriginalChar': 'Linha {line} palavra original contém caracteres especiais',
|
||||
'replacementDialog.invalidReplacementChar': 'Linha {line} palavra de substituição contém caracteres especiais',
|
||||
'replacementDialog.readFileError': 'Falha ao ler arquivo',
|
||||
'replacementDialog.maxWordCountExceeded': 'A quantidade de palavras de substituição não pode exceder {max}',
|
||||
|
||||
// Página de gerenciamento de palavras de substituição
|
||||
'replacementWordManagement.getListFailed': 'Falha ao obter lista',
|
||||
|
||||
@@ -385,6 +385,7 @@ export default {
|
||||
'replacementDialog.invalidOriginalChar': 'Dòng {line} từ gốc chứa ký tự đặc biệt',
|
||||
'replacementDialog.invalidReplacementChar': 'Dòng {line} từ thay thế chứa ký tự đặc biệt',
|
||||
'replacementDialog.readFileError': 'Không thể đọc tệp',
|
||||
'replacementDialog.maxWordCountExceeded': 'Số lượng từ thay thế không thể vượt quá {max}',
|
||||
|
||||
// Trang quản lý từ thay thế
|
||||
'replacementWordManagement.getListFailed': 'Không thể lấy danh sách',
|
||||
|
||||
@@ -383,6 +383,7 @@ export default {
|
||||
'replacementDialog.invalidOriginalChar': '第{line}行待替换词包含特殊符号',
|
||||
'replacementDialog.invalidReplacementChar': '第{line}行替换词包含特殊符号',
|
||||
'replacementDialog.readFileError': '读取文件失败',
|
||||
'replacementDialog.maxWordCountExceeded': '替换词数量不能超过 {max} 个',
|
||||
|
||||
// 替换词管理页面提示文本
|
||||
'replacementWordManagement.getListFailed': '获取列表失败',
|
||||
|
||||
@@ -385,6 +385,7 @@ export default {
|
||||
'replacementDialog.invalidOriginalChar': '第{line}行待替換詞包含特殊符號',
|
||||
'replacementDialog.invalidReplacementChar': '第{line}行替換詞包含特殊符號',
|
||||
'replacementDialog.readFileError': '讀取檔案失敗',
|
||||
'replacementDialog.maxWordCountExceeded': '替換詞數量不能超過 {max} 個',
|
||||
|
||||
// 替換詞管理頁面提示文本
|
||||
'replacementWordManagement.getListFailed': '獲取列表失敗',
|
||||
|
||||
Reference in New Issue
Block a user