yh-i18n 2.3.7 → 2.3.8
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/list.vue +68 -84
- package/package.json +1 -1
package/list.vue
CHANGED
|
@@ -107,14 +107,23 @@
|
|
|
107
107
|
@close="cancelForm"
|
|
108
108
|
draggable
|
|
109
109
|
:title="formData.id ? ct('编辑翻译') : ct('新增翻译')">
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
:
|
|
117
|
-
|
|
110
|
+
<el-form
|
|
111
|
+
ref="formRef"
|
|
112
|
+
:model="formData"
|
|
113
|
+
:rules="formRules"
|
|
114
|
+
label-width="100px"
|
|
115
|
+
label-position="right">
|
|
116
|
+
<el-form-item :label="ct('翻译键值')" prop="name">
|
|
117
|
+
<el-input tabindex="1" v-model="formData.name" class="i18n-form-item" id="i18nFormItem1" />
|
|
118
|
+
</el-form-item>
|
|
119
|
+
<el-form-item
|
|
120
|
+
v-for="(item, index) in langFields"
|
|
121
|
+
:key="item.field"
|
|
122
|
+
:label="ct(item.label)"
|
|
123
|
+
:prop="item.field">
|
|
124
|
+
<el-input ref="langFieldsRef" :tabindex="index + 2" v-model="formData[item.field]" class="i18n-form-item" :id="item.id" />
|
|
125
|
+
</el-form-item>
|
|
126
|
+
</el-form>
|
|
118
127
|
<template #footer>
|
|
119
128
|
<div class="yh-i18n-form-actions">
|
|
120
129
|
<el-button
|
|
@@ -145,14 +154,15 @@
|
|
|
145
154
|
</el-dialog>
|
|
146
155
|
</template>
|
|
147
156
|
<script setup lang="ts">
|
|
148
|
-
import {reactive, ref, onMounted, watch} from 'vue';
|
|
157
|
+
import {reactive, ref, onMounted, onUnmounted, onActivated, onDeactivated, watch} from 'vue';
|
|
149
158
|
import {ElLoadingService, ElMessage, ElMessageBox} from 'element-plus';
|
|
150
159
|
import {useI18nStore, ct} from 'yh-i18n';
|
|
151
160
|
import http from '@/libs/api.request';
|
|
152
|
-
import {
|
|
161
|
+
import type {FormInstance} from 'element-plus';
|
|
153
162
|
import {exportExcel, importExcel} from './excelTool';
|
|
154
163
|
const i18nStore = useI18nStore();
|
|
155
|
-
const
|
|
164
|
+
const formRef = ref<FormInstance>();
|
|
165
|
+
const langFieldsRef = ref<InstanceType<typeof import('element-plus')['ElInput']>>();
|
|
156
166
|
|
|
157
167
|
const insertUrl = '/translate/insert';
|
|
158
168
|
const updateUrl = '/translate/edit';
|
|
@@ -241,10 +251,9 @@ const langList = Object.keys(i18nStore.langList);
|
|
|
241
251
|
const formDataIndex = ref();
|
|
242
252
|
const formData = reactive<any>({});
|
|
243
253
|
const formShow = ref(false);
|
|
244
|
-
let inputs: HTMLInputElement[] = [];
|
|
245
254
|
function cancelForm() {
|
|
246
|
-
|
|
247
|
-
|
|
255
|
+
formRef.value?.resetFields();
|
|
256
|
+
formRef.value?.clearValidate();
|
|
248
257
|
formDataIndex.value = void 0;
|
|
249
258
|
formData.id = null;
|
|
250
259
|
formShow.value = false;
|
|
@@ -272,8 +281,7 @@ function editOne(item, index) {
|
|
|
272
281
|
}
|
|
273
282
|
formShow.value = true;
|
|
274
283
|
setTimeout(() => {
|
|
275
|
-
|
|
276
|
-
inputs = Array.from(document.querySelectorAll('.i18n-form-item input'));
|
|
284
|
+
langFieldsRef.value[0]?.focus();
|
|
277
285
|
}, 500);
|
|
278
286
|
}
|
|
279
287
|
|
|
@@ -286,10 +294,10 @@ function nextOne() {
|
|
|
286
294
|
}
|
|
287
295
|
|
|
288
296
|
function saveOne() {
|
|
289
|
-
let isAdd =
|
|
297
|
+
let isAdd = !!!formData.id;
|
|
290
298
|
let url = updateUrl;
|
|
291
|
-
|
|
292
|
-
if (
|
|
299
|
+
formRef.value?.validate((valid) => {
|
|
300
|
+
if (valid) {
|
|
293
301
|
let data: any = {
|
|
294
302
|
name: formData.name,
|
|
295
303
|
content: {},
|
|
@@ -316,13 +324,13 @@ function saveOne() {
|
|
|
316
324
|
if (res?.data?.status === 200) {
|
|
317
325
|
ElMessage.success(res.data.msg);
|
|
318
326
|
if (isAdd) {
|
|
327
|
+
cancelForm();
|
|
328
|
+
getDataList(true);
|
|
329
|
+
} else {
|
|
319
330
|
dataList.value[formDataIndex.value] = {
|
|
320
331
|
...formData,
|
|
321
332
|
};
|
|
322
333
|
nextOne();
|
|
323
|
-
} else {
|
|
324
|
-
cancelForm();
|
|
325
|
-
getDataList();
|
|
326
334
|
}
|
|
327
335
|
} else {
|
|
328
336
|
ElMessage.error(res.data.msg);
|
|
@@ -391,20 +399,10 @@ function delMore() {
|
|
|
391
399
|
});
|
|
392
400
|
}
|
|
393
401
|
|
|
394
|
-
const
|
|
395
|
-
{
|
|
396
|
-
field: 'name',
|
|
397
|
-
span: 24,
|
|
398
|
-
title: '翻译键值',
|
|
399
|
-
itemRender: {
|
|
400
|
-
name: '$input',
|
|
401
|
-
props: {class: 'i18n-form-item', id: `i18nFormItem${1}`},
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
]);
|
|
402
|
+
const langFields = reactive<{field: string; label: string; id: string}[]>([]);
|
|
405
403
|
|
|
406
|
-
const formRules = reactive
|
|
407
|
-
name: [{required: true,
|
|
404
|
+
const formRules = reactive({
|
|
405
|
+
name: [{required: true, message: '请输入翻译键值', trigger: 'blur'}],
|
|
408
406
|
});
|
|
409
407
|
|
|
410
408
|
let needInit = true;
|
|
@@ -419,14 +417,10 @@ watch(
|
|
|
419
417
|
title: item.label,
|
|
420
418
|
minWidth: '200',
|
|
421
419
|
});
|
|
422
|
-
|
|
420
|
+
langFields.push({
|
|
423
421
|
field: item.value,
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
itemRender: {
|
|
427
|
-
name: '$input',
|
|
428
|
-
props: {class: 'i18n-form-item', id: `i18nFormItem${index + 2}`},
|
|
429
|
-
},
|
|
422
|
+
label: item.label,
|
|
423
|
+
id: `i18nFormItem${index + 2}`,
|
|
430
424
|
});
|
|
431
425
|
});
|
|
432
426
|
}
|
|
@@ -437,51 +431,41 @@ watch(
|
|
|
437
431
|
}
|
|
438
432
|
);
|
|
439
433
|
|
|
434
|
+
function keydownHandler(e: KeyboardEvent) {
|
|
435
|
+
if (!formShow.value) return;
|
|
436
|
+
const {key, ctrlKey, altKey} = e;
|
|
437
|
+
if (key === 's' && ctrlKey) {
|
|
438
|
+
e.preventDefault();
|
|
439
|
+
e.stopPropagation();
|
|
440
|
+
saveOne();
|
|
441
|
+
}
|
|
442
|
+
if (key === 'ArrowRight' && (ctrlKey || altKey)) {
|
|
443
|
+
e.preventDefault();
|
|
444
|
+
e.stopPropagation();
|
|
445
|
+
nextOne();
|
|
446
|
+
}
|
|
447
|
+
if (key === 'ArrowLeft' && (ctrlKey || altKey)) {
|
|
448
|
+
e.preventDefault();
|
|
449
|
+
e.stopPropagation();
|
|
450
|
+
prevOne();
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
440
454
|
onMounted(() => {
|
|
441
455
|
getDataList();
|
|
442
|
-
window.addEventListener('keydown',
|
|
443
|
-
|
|
444
|
-
if (key === 's' && ctrlKey) {
|
|
445
|
-
e.preventDefault();
|
|
446
|
-
e.stopPropagation();
|
|
447
|
-
saveOne();
|
|
448
|
-
}
|
|
449
|
-
if (key === 'ArrowRight' && (ctrlKey || altKey)) {
|
|
450
|
-
e.preventDefault();
|
|
451
|
-
e.stopPropagation();
|
|
452
|
-
nextOne();
|
|
453
|
-
}
|
|
454
|
-
if (key === 'ArrowLeft' && (ctrlKey || altKey)) {
|
|
455
|
-
e.preventDefault();
|
|
456
|
-
e.stopPropagation();
|
|
457
|
-
prevOne();
|
|
458
|
-
}
|
|
459
|
-
if (key === 'Tab') {
|
|
460
|
-
e.preventDefault();
|
|
461
|
-
e.stopPropagation();
|
|
462
|
-
if (
|
|
463
|
-
document.activeElement ||
|
|
464
|
-
// @ts-ignore
|
|
465
|
-
inputs.includes(document.activeElement)
|
|
466
|
-
) {
|
|
467
|
-
// @ts-ignore
|
|
468
|
-
let index = inputs.indexOf(document.activeElement);
|
|
456
|
+
window.addEventListener('keydown', keydownHandler);
|
|
457
|
+
});
|
|
469
458
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
}, 100);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
});
|
|
459
|
+
onUnmounted(() => {
|
|
460
|
+
window.removeEventListener('keydown', keydownHandler);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
onActivated(() => {
|
|
464
|
+
window.addEventListener('keydown', keydownHandler);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
onDeactivated(() => {
|
|
468
|
+
window.removeEventListener('keydown', keydownHandler);
|
|
485
469
|
});
|
|
486
470
|
</script>
|
|
487
471
|
<style lang="scss">
|