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.
Files changed (2) hide show
  1. package/list.vue +68 -84
  2. 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
- <vxe-form
111
- title-align="right"
112
- title-width="100px"
113
- ref="vxeFormRef"
114
- title-colon
115
- :data="formData"
116
- :items="formItems"
117
- :rules="formRules"></vxe-form>
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 {VxeFormInstance, VxeFormPropTypes} from 'vxe-table';
161
+ import type {FormInstance} from 'element-plus';
153
162
  import {exportExcel, importExcel} from './excelTool';
154
163
  const i18nStore = useI18nStore();
155
- const vxeFormRef = ref<VxeFormInstance>();
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
- vxeFormRef?.value?.reset();
247
- vxeFormRef?.value?.clearValidate();
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
- (document.querySelector('#i18nFormItem1 input') as HTMLInputElement)?.focus();
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 = !!formData.id;
297
+ let isAdd = !!!formData.id;
290
298
  let url = updateUrl;
291
- vxeFormRef?.value?.validate().then((errMap) => {
292
- if (!errMap) {
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 formItems = reactive<VxeFormPropTypes.Items>([
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<VxeFormPropTypes.Rules>({
407
- name: [{required: true, type: 'string', message: '请输入翻译键值'}],
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
- formItems.push({
420
+ langFields.push({
423
421
  field: item.value,
424
- span: 24,
425
- title: item.label,
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', (e) => {
443
- let {key, ctrlKey, altKey} = e;
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
- if (index === inputs.length) {
471
- index = 0;
472
- } else {
473
- index++;
474
- }
475
- inputs[index].focus();
476
- } else {
477
- setTimeout(() => {
478
- if (!document.activeElement || !inputs.includes(document.activeElement as HTMLInputElement)) {
479
- (document.querySelector('#i18nFormItem1 input') as HTMLInputElement)?.focus();
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">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yh-i18n",
3
- "version": "2.3.7",
3
+ "version": "2.3.8",
4
4
  "description": "对于国际化的封装",
5
5
  "main": "index.js",
6
6
  "scripts": {