ci-plus 1.7.4 → 1.7.6

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/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ## 历史更新
2
2
 
3
3
  ```js
4
+ 1.7.6
5
+ 1、调整语言文件中翻译对象
6
+ 1.7.5
7
+ 1、表头筛选组件新增语言切换功能
4
8
  1.7.0
5
9
  1、更新ajaxBox.ts函数的downFileFetchV3中文件名称匹配逻辑
6
10
  1.6.9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ci-plus",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "description": "ci组件库",
5
5
  "main": "./index.ts",
6
6
  "scripts": {
@@ -19,7 +19,9 @@
19
19
  "email": "10000@qq.com"
20
20
  },
21
21
  "license": "ISC",
22
- "dependencies": {},
22
+ "dependencies": {
23
+ "vue-i18n": "^11.1.3"
24
+ },
23
25
  "devDependencies": {},
24
26
  "peerDependencies": {},
25
27
  "peerDependenciesMeta": {}
@@ -62,7 +62,7 @@
62
62
  v-if="props.type !== 'select' && props.showConnector"
63
63
  v-model="operator"
64
64
  class="m-2 input-select"
65
- placeholder="请选择查询类型"
65
+ :placeholder="t('public.placeholders')"
66
66
  size="default"
67
67
  >
68
68
  <!-- clearable -->
@@ -136,9 +136,9 @@
136
136
  v-model="value"
137
137
  type="daterange"
138
138
  unlink-panels
139
- range-separator=""
140
- start-placeholder="开始日期"
141
- end-placeholder="结束日期"
139
+ :range-separator="t('sortableTable.datepicker.rangeseparator')"
140
+ :start-placeholder="t('sortableTable.datepicker.startplaceholder')"
141
+ :end-placeholder="t('sortableTable.datepicker.endplaceholder')"
142
142
  :shortcuts="shortcuts"
143
143
  size="default"
144
144
  :style="{ width: '100%' }"
@@ -169,8 +169,16 @@ import SvgIcon from '../svgIcon/svgicon.vue'
169
169
  import { computed, ref, watch, PropType, onMounted } from 'vue'
170
170
  import lodash, { debounce } from 'lodash-es'
171
171
  import headerPopover from './utils/headerPopover.vue'
172
- import { TooltipTriggerType,ElSelect,ElOption,ElInput,ElSelectV2,ElPagination,ElDatePicker } from 'element-plus'
173
-
172
+ import {
173
+ TooltipTriggerType,
174
+ ElSelect,
175
+ ElOption,
176
+ ElInput,
177
+ ElSelectV2,
178
+ ElPagination,
179
+ ElDatePicker
180
+ } from 'element-plus'
181
+ import t from '../utils/lang/index'
174
182
  // 定义 props 的类型
175
183
  interface SelectConfig {
176
184
  options: any[]
@@ -267,7 +275,7 @@ const props = defineProps({
267
275
  selectConfig: {
268
276
  type: Object as PropType<SelectConfig>,
269
277
  default: () => ({
270
- placeholder: '请选择', // 输入框的placeholder提示
278
+ placeholder: t('public.placeholders'), //'请选择', // 输入框的placeholder提示
271
279
  selectSize: 'default', // 输入框的大小
272
280
  selectDisabled: false, // 输入框的disabled属性
273
281
  clearable: true, // 是否有清除按钮
@@ -280,8 +288,8 @@ const props = defineProps({
280
288
  popperClass: '', // popper的class类名
281
289
  selectStyle: '', // 输入框的style样式
282
290
  selectAll: false, // 是否显示全选按钮
283
- selectAllLabel: '全选', // 全选按钮的文本
284
- selectAllPlaceholder: '请选择', // 全选按钮的placeholder提示
291
+ selectAllLabel: t('public.selectAll'), //'全选', // 全选按钮的文本
292
+ selectAllPlaceholder: t('public.placeholders'), // '请选择', // 全选按钮的placeholder提示
285
293
  options: [], //select下拉选项时的 列表数据
286
294
  optionValue: 'value', // 选项的默认value值
287
295
  optionLabel: 'label', // 选项的默认label值
@@ -312,7 +320,7 @@ const props = defineProps({
312
320
  // 根据传参重置下拉列配置参数的默认值
313
321
  const _selectConfig = computed((): SelectConfig => {
314
322
  let obj = {
315
- placeholder: '请选择', // 输入框的placeholder提示
323
+ placeholder: t('public.placeholders'), // '请选择', // 输入框的placeholder提示
316
324
  selectSize: 'default', // 输入框的大小
317
325
  selectDisabled: false, // 输入框的disabled属性
318
326
  clearable: true, // 是否有清除按钮
@@ -325,8 +333,8 @@ const _selectConfig = computed((): SelectConfig => {
325
333
  popperClass: '', // popper的class类名
326
334
  selectStyle: '', // 输入框的style样式
327
335
  selectAll: false, // 是否显示全选按钮
328
- selectAllLabel: '全选', // 全选按钮的文本
329
- selectAllPlaceholder: '请选择', // 全选按钮的placeholder提示
336
+ selectAllLabel: t('public.selectAll'), //'全选', // 全选按钮的文本
337
+ selectAllPlaceholder: t('public.placeholders'), //'请选择', // 全选按钮的placeholder提示
330
338
  options: [], //select下拉选项时的 列表数据
331
339
  optionValue: 'value', // 选项的默认value值
332
340
  optionLabel: 'label', // 选项的默认label值
@@ -361,36 +369,36 @@ const operatorOptions = ref<
361
369
  >([
362
370
  {
363
371
  value: 'like',
364
- label: '包含'
372
+ label: t('sortableTable.operatorOptions.like') //'包含'
365
373
  },
366
374
  {
367
375
  value: '=',
368
- label: '等于'
376
+ label: t('sortableTable.operatorOptions.equals') //'等于'
369
377
  },
370
378
  {
371
379
  value: '>',
372
- label: '大于'
380
+ label: t('sortableTable.operatorOptions.greaterThan') //'大于'
373
381
  },
374
382
  {
375
383
  value: '>=',
376
- label: '大于等于'
384
+ label: t('sortableTable.operatorOptions.greaterThanOrEqualTo') //'大于等于'
377
385
  },
378
386
  {
379
387
  value: '<',
380
- label: '小于'
388
+ label: t('sortableTable.operatorOptions.lessThan') //'小于'
381
389
  },
382
390
  {
383
391
  value: '<=',
384
- label: '小于等于'
392
+ label: t('sortableTable.operatorOptions.lessThanOrEqualTo') //'小于等于'
385
393
  },
386
394
  {
387
395
  value: '<>',
388
- label: '不等于'
396
+ label: t('sortableTable.operatorOptions.notEqualTo') //'不等于'
389
397
  },
390
398
  {
391
399
  // 数组的第8个元素必须是介于,后面再日期的时候会禁用第8个
392
400
  value: 'between',
393
- label: '介于'
401
+ label: t('sortableTable.operatorOptions.between') //'介于'
394
402
  }
395
403
  ])
396
404
 
@@ -450,7 +458,7 @@ if (props.type === 'date') {
450
458
  // 判断是否是日期范围
451
459
  shortcuts.value = [
452
460
  {
453
- text: '前一周',
461
+ text: t('sortableTable.datepicker.aweekAgo'), //'前一周',
454
462
  value: () => {
455
463
  const end = new Date()
456
464
  const start = new Date()
@@ -459,7 +467,7 @@ if (props.type === 'date') {
459
467
  }
460
468
  },
461
469
  {
462
- text: '前一月',
470
+ text: t('sortableTable.datepicker.lastMonth'), //'前一月',
463
471
  value: () => {
464
472
  const end = new Date()
465
473
  const start = new Date()
@@ -468,7 +476,7 @@ if (props.type === 'date') {
468
476
  }
469
477
  },
470
478
  {
471
- text: '最近3个月',
479
+ text: t('sortableTable.datepicker.last3Month'), //'最近3个月',
472
480
  value: () => {
473
481
  const end = new Date()
474
482
  const start = new Date()
@@ -479,11 +487,11 @@ if (props.type === 'date') {
479
487
  ]
480
488
  shortcutsDay.value = [
481
489
  {
482
- text: '今天',
490
+ text: t('sortableTable.datepicker.Today'), //'今天',
483
491
  value: new Date()
484
492
  },
485
493
  {
486
- text: '昨天',
494
+ text: t('sortableTable.datepicker.Yesterday'), //'昨天',
487
495
  value: () => {
488
496
  const date = new Date()
489
497
  date.setTime(date.getTime() - 3600 * 1000 * 24)
@@ -491,7 +499,7 @@ if (props.type === 'date') {
491
499
  }
492
500
  },
493
501
  {
494
- text: '一周前',
502
+ text: t('sortableTable.datepicker.aweekAgo'), //'一周前',
495
503
  value: () => {
496
504
  const date = new Date()
497
505
  date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
@@ -12,16 +12,18 @@
12
12
  <template #reference>
13
13
  <slot name="reference" :open="open" :close="close" :toggle="toggle" />
14
14
  </template>
15
- <div style="display: flex; align-items: center; justify-content: center" >
15
+ <div style="display: flex; align-items: center; justify-content: center">
16
16
  <div style="flex-grow: 1">
17
17
  <slot :closeF="close" />
18
18
  </div>
19
19
  <div style="margin-left: 5px">
20
20
  <div>
21
- <el-button type="primary" size="small" @click="submit"> 确认 </el-button>
21
+ <el-button type="primary" size="small" @click="submit">
22
+ {{ t('public.confirm') }}
23
+ </el-button>
22
24
  </div>
23
25
  <div style="margin-top: 5px">
24
- <el-button size="small" @click="emits('clear')"> 清空 </el-button>
26
+ <el-button size="small" @click="emits('clear')"> {{ t('public.clear') }} </el-button>
25
27
  </div>
26
28
  <!-- <div style="margin-top: 5px">
27
29
  <el-button
@@ -39,7 +41,8 @@
39
41
 
40
42
  <script setup lang="ts">
41
43
  import { onMounted, ref } from 'vue'
42
- import { ElPopover,ElButton, TooltipTriggerType } from 'element-plus'
44
+ import { ElPopover, ElButton, TooltipTriggerType } from 'element-plus'
45
+ import t from '../../utils/lang/index'
43
46
  const popoverRef = ref<InstanceType<typeof ElPopover>>()
44
47
  const props = defineProps<{
45
48
  popperStyle: any // el-popover的自定义样式
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @module downFile
3
- * @author : 卖女孩的小火柴
4
- * !description : 下载文件方法
5
- * @version : 1.0.2
6
- * @since : 创建时间 2024-07-09 10:46:11
7
- */
2
+ * @module downFile
3
+ * @author : 卖女孩的小火柴
4
+ * !description : 下载文件方法
5
+ * @version : 1.0.2
6
+ * @since : 创建时间 2024-07-09 10:46:11
7
+ */
8
8
  import { ElMessage } from 'element-plus'
9
9
 
10
10
  /**
@@ -15,10 +15,15 @@ import { ElMessage } from 'element-plus'
15
15
  * 如果blob对象是JSON格式,则尝试解析为JavaScript对象,并显示相应的错误消息。
16
16
  * 如果解析失败,则直接以原始格式下载blob对象。
17
17
  */
18
- const downFileFn = function (blob: Blob | BlobPart, fileName: string, resolve?: Function, reject?: Function) {
18
+ const downFileFn = function (
19
+ blob: Blob | BlobPart,
20
+ fileName: string,
21
+ resolve?: Function,
22
+ reject?: Function
23
+ ) {
19
24
  // 创建一个新的Blob对象,指定类型为application/json,假设blob是我们需要转换的Blob对象
20
25
  let b = new Blob([blob], {
21
- type: 'application/json',
26
+ type: 'application/json'
22
27
  })
23
28
 
24
29
  // 创建一个FileReader对象用于读取Blob对象,创建一个新的FileReader实例
@@ -39,9 +44,7 @@ const downFileFn = function (blob: Blob | BlobPart, fileName: string, resolve?:
39
44
  } catch (error) {
40
45
  // 如果解析失败,将Blob对象转换为URL并创建下载链接
41
46
  // console.error('Error parsing JSON', error)
42
- const url = URL.createObjectURL(
43
- new Blob([b]),
44
- )
47
+ const url = URL.createObjectURL(new Blob([b]))
45
48
  let link: HTMLAnchorElement | null = document.createElement('a')
46
49
  link.href = url
47
50
  link.setAttribute('download', fileName)
@@ -57,7 +60,6 @@ const downFileFn = function (blob: Blob | BlobPart, fileName: string, resolve?:
57
60
  reader.onerror = function () {
58
61
  console.error('读取过程中出错.')
59
62
  }
60
-
61
63
  }
62
64
 
63
65
  type Obj = {
@@ -65,16 +67,16 @@ type Obj = {
65
67
  }
66
68
 
67
69
  interface Config {
68
- method?: string, // 请求方法,默认为 GET | POST
69
- headers?: Object, // 请求头
70
- cbpercentage?: Function // 获取下载进度的回调函数
71
- fileName?: string, // 下载后的文件名
72
- chunkSize?: number, // 每次下载的块大小,默认为 10KB
73
- body?: string, // 请求体
70
+ method?: string // 请求方法,默认为 GET | POST
71
+ headers?: Object // 请求头
72
+ cbpercentage?: Function // 获取下载进度的回调函数
73
+ fileName?: string // 下载后的文件名
74
+ chunkSize?: number // 每次下载的块大小,默认为 10KB
75
+ body?: string // 请求体
74
76
  }
75
77
  const ajaxBox = {
76
78
  downFile: function (blob: Blob | BlobPart, fileName: string) {
77
- downFileFn(blob, fileName);
79
+ downFileFn(blob, fileName)
78
80
  },
79
81
 
80
82
  // 下载文件
@@ -90,19 +92,25 @@ const ajaxBox = {
90
92
  * 如果解析失败,则直接以原始格式下载blob对象。
91
93
  */
92
94
 
93
- downFileFetch: function (fillAddress: string, fileName: string, method?: string, headers?: Obj, params?: Obj, cbpercentage?: Function) {
95
+ downFileFetch: function (
96
+ fillAddress: string,
97
+ fileName: string,
98
+ method?: string,
99
+ headers?: Obj,
100
+ params?: Obj,
101
+ cbpercentage?: Function
102
+ ) {
94
103
  let options = {
95
- method: method || 'GET',
104
+ method: method || 'GET'
96
105
  }
97
106
  let _headers
98
107
  if (options.method === 'GET' || method === 'get') {
99
108
  _headers = {
100
- 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
109
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
101
110
  }
102
-
103
111
  } else if (options.method === 'POST' || method === 'post') {
104
112
  _headers = {
105
- 'Content-Type': 'application/json', //设置为json格式
113
+ 'Content-Type': 'application/json' //设置为json格式
106
114
  }
107
115
  }
108
116
  // 判断请求是否为get请求,若是get请求,则将params参数拼接在url后面
@@ -149,10 +157,10 @@ const ajaxBox = {
149
157
  // 累加已下载的字节数
150
158
  // downloaded += reader.result.byteLength
151
159
  if (typeof reader.result === 'string' || reader.result === null) {
152
- console.log('reader.result不为 ArrayBuffer');
160
+ console.log('reader.result不为 ArrayBuffer')
153
161
  // 处理字符串的情况,可能需要转换为 ArrayBuffer 或者其他处理逻辑
154
162
  } else {
155
- downloaded += reader.result.byteLength;
163
+ downloaded += reader.result.byteLength
156
164
  }
157
165
  // 计算下载进度百分比
158
166
  const total = blob.size
@@ -195,18 +203,17 @@ const ajaxBox = {
195
203
 
196
204
  downFileFetchV2: function (url: string, params?: Obj, config?: Config) {
197
205
  let options = {
198
- method: config?.method || 'GET',
206
+ method: config?.method || 'GET'
199
207
  }
200
208
  let _headers
201
209
  let _fileName = config?.fileName || '附件'
202
210
  if (options.method === 'GET' || options.method === 'get') {
203
211
  _headers = {
204
- 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
212
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
205
213
  }
206
-
207
214
  } else if (options.method === 'POST' || options.method === 'post') {
208
215
  _headers = {
209
- 'Content-Type': 'application/json', // 设置为json格式
216
+ 'Content-Type': 'application/json' // 设置为json格式
210
217
  }
211
218
  }
212
219
  // 数组请求头: 优先使用传递的请求头,如果没有传递,则使用默认的请求头
@@ -252,10 +259,10 @@ const ajaxBox = {
252
259
  // 累加已下载的字节数
253
260
  // downloaded += reader.result.byteLength
254
261
  if (typeof reader.result === 'string' || reader.result === null) {
255
- console.log('reader.result不为 ArrayBuffer');
262
+ console.log('reader.result不为 ArrayBuffer')
256
263
  // 处理字符串的情况,可能需要转换为 ArrayBuffer 或者其他处理逻辑
257
264
  } else {
258
- downloaded += reader.result.byteLength;
265
+ downloaded += reader.result.byteLength
259
266
  }
260
267
  // 计算下载进度百分比
261
268
  const total = blob.size
@@ -274,7 +281,8 @@ const ajaxBox = {
274
281
  }
275
282
  }
276
283
  readBlobInChunks()
277
- }).catch((error) => {
284
+ })
285
+ .catch((error) => {
278
286
  console.error('下载文件时出错:', error)
279
287
  reject(error)
280
288
  })
@@ -284,17 +292,17 @@ const ajaxBox = {
284
292
  // 下载文件:3.0版本:优先使用传递的文件名,若不传递文件问就使用后端返回的文件名
285
293
  downFileFetchV3: function (url: string, params?: Obj, config?: Config) {
286
294
  let options: any = {
287
- method: config?.method || 'GET',
295
+ method: config?.method || 'GET'
288
296
  }
289
297
  let _headers
290
298
  let _fileName = ''
291
299
  if (options.method === 'GET' || options.method === 'get') {
292
300
  _headers = {
293
- 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
301
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
294
302
  }
295
303
  } else if (options.method === 'POST' || options.method === 'post') {
296
304
  _headers = {
297
- 'Content-Type': 'application/json', // 设置为json格式
305
+ 'Content-Type': 'application/json' // 设置为json格式
298
306
  }
299
307
  }
300
308
  // 数组请求头: 优先使用传递的请求头,如果没有传递,则使用默认的请求头
@@ -332,11 +340,18 @@ const ajaxBox = {
332
340
  console.log('后端返回的文件名字符串: ', contentDisposition)
333
341
  if (contentDisposition) {
334
342
  // 解析文件名
335
- const fileNameMatch = contentDisposition.match(/filename="(.+)"/) || contentDisposition.match(/filename\*=utf-8''(.+)/);
343
+ const fileNameMatch =
344
+ contentDisposition.match(/filename="(.+)"/) || // attachment; filename="文件名.xlsx" 匹配文件名带双引号
345
+ contentDisposition.match(/filename='(.+)'/) || // attachment; filename='文件名.xlsx' 匹配文件名带单引号
346
+ contentDisposition.match(/filename=(?:([^;]+))/) || // attachment; filename=文件名.xlsx 匹配文件名不带引号
347
+ contentDisposition.match(/filename\*=utf-8''(.+)/) || // attachment; filename*=utf-8''文件名.xlsx
348
+ contentDisposition.match(/filename=(?:"([^"]+)"|'([^']+)'|([^;]+))/) //匹配文件名带双引号、单引号、不带引号
336
349
  // console.log('文件名数组: ', fileNameMatch)
337
350
  if (fileNameMatch.length > 1) {
338
351
  // 匹配到文件名,则将文件名解码并赋值给 _fileName
339
- _fileName = decodeURIComponent(fileNameMatch[1])
352
+ _fileName = decodeURIComponent(
353
+ fileNameMatch[1] || fileNameMatch[2] || fileNameMatch[3]
354
+ )
340
355
  console.log('后端返回的文件名: ', _fileName)
341
356
  return res.blob().then((blob: Blob) => ({ blob, _fileName }))
342
357
  }
@@ -391,9 +406,7 @@ const ajaxBox = {
391
406
  reject(error)
392
407
  })
393
408
  })
394
- },
395
-
396
-
409
+ }
397
410
 
398
411
  /*
399
412
  sendJSONP: function (url, callbackName, callback) {
@@ -413,13 +426,8 @@ const ajaxBox = {
413
426
  };
414
427
  },
415
428
  */
416
-
417
-
418
-
419
-
420
429
  }
421
- export default ajaxBox;
422
-
430
+ export default ajaxBox
423
431
 
424
432
  /**
425
433
  * 使用下载示例 get
@@ -1,13 +1,24 @@
1
- export { default as withInstall } from './withinstall/index';
1
+ export { default as withInstall } from './withinstall/index'
2
2
 
3
3
  // export { default as setCardList } from './cardPrint'; // 导入默认的导出
4
4
  // export * from './cardPrint'; // 导入所有导出(不包含默认导出)
5
- import withInstall from './withinstall/index';
6
- import { cardPrint, setCardList } from "./cardPrint";
7
- import apis from "./baseApi";
8
- import { setDate, setDateTime } from "./Dayjs";
9
- import dayjs from "./Dayjs";
10
- import ajaxBox from "./ajaxBox"; // 处理文件下载方法
5
+ import withInstall from './withinstall/index'
6
+ import { cardPrint, setCardList } from './cardPrint'
7
+ import apis from './baseApi'
8
+ import { setDate, setDateTime } from './Dayjs'
9
+ import dayjs from './Dayjs'
10
+ import ajaxBox from './ajaxBox' // 处理文件下载方法
11
+ import t from './lang/index' // 中英文切换
11
12
 
12
13
  // 导出 cardPrint 和 apis
13
- export default { apis, cardPrint, setCardList, withInstall, dayjs, setDate, setDateTime, ajaxBox };
14
+ export default {
15
+ apis,
16
+ cardPrint,
17
+ setCardList,
18
+ withInstall,
19
+ dayjs,
20
+ setDate,
21
+ setDateTime,
22
+ ajaxBox,
23
+ t
24
+ }
@@ -0,0 +1,42 @@
1
+ const en = {
2
+ sortableTable: {
3
+ operatorOptions: {
4
+ like: 'like',
5
+ equals: 'Equals',
6
+ greaterThan: 'Greater than',
7
+ greaterThanOrEqualTo: 'Greater than or equal to',
8
+ lessThan: 'Less than',
9
+ lessThanOrEqualTo: 'Less than or equal to',
10
+ notEqualTo: 'Not equal to',
11
+ between: 'Between'
12
+ },
13
+ datepicker: {
14
+ rangeseparator: ' - ',
15
+ startplaceholder: 'Start date',
16
+ endplaceholder: 'End date',
17
+ Today: 'Today',
18
+ Yesterday: 'Yesterday', // 昨天
19
+ aweekAgo: 'A week ago', // 前一周
20
+ lastMonth: 'Last Month', // 前一月,
21
+ last3Month: 'Last 3 Month' // 最近3个月
22
+ }
23
+ },
24
+ public: {
25
+ placeholders: 'Please choose', // 请选择
26
+ placeholderi: 'Please fill in', // 请填写
27
+ loading: 'Loading in progress ...', // 加载中···
28
+ confirm: 'Confirm', // 确定
29
+ clear: 'clear', // '清空',
30
+ cancel: 'Cancel', // 取消
31
+ search: 'Search', // 搜索
32
+ reset: 'Reset', // 重置
33
+ add: 'Add', // 新增
34
+ edit: 'Edit', // 编辑
35
+ delete: 'Delete', // 删除
36
+ save: 'Save', // 保存
37
+ close: 'Close', // 关闭
38
+ submit: 'Submit', // 提交
39
+ selectAll: 'Select All' // 全选
40
+ }
41
+ }
42
+ export default en
@@ -0,0 +1,26 @@
1
+ import { createI18n, I18nOptions } from 'vue-i18n'
2
+ import en from './en'
3
+ import zh from './zh'
4
+ import { computed } from 'vue'
5
+ // 本地缓存的语言用计算属性获取
6
+ export let lang = computed({
7
+ get() {
8
+ return localStorage.getItem('language') || 'zh'
9
+ },
10
+ set(val) {
11
+ return val
12
+ }
13
+ })
14
+ const i18n = createI18n({
15
+ locale: lang.value, // 设置默认语言, // 设置默认语言
16
+ messages: { en, zh }
17
+ })
18
+ const t = (key: string, langs?: 'zh' | 'en') => {
19
+ if (langs) {
20
+ i18n.global.locale = langs
21
+ } else {
22
+ i18n.global.locale = lang.value as 'zh' | 'en'
23
+ }
24
+ return i18n.global.t(key)
25
+ }
26
+ export default t
@@ -0,0 +1,42 @@
1
+ const zh = {
2
+ sortableTable: {
3
+ operatorOptions: {
4
+ like: '包含',
5
+ equals: '等于',
6
+ greaterThan: '大于',
7
+ greaterThanOrEqualTo: '大于等于',
8
+ lessThan: '小于',
9
+ lessThanOrEqualTo: '小于等于',
10
+ notEqualTo: '不等于',
11
+ between: '介于'
12
+ },
13
+ datepicker: {
14
+ rangeseparator: ' 至 ',
15
+ startplaceholder: '开始日期',
16
+ endplaceholder: '结束日期',
17
+ Today: '今天',
18
+ Yesterday: '昨天',
19
+ aweekAgo: '一周前',
20
+ lastMonth: '前一月',
21
+ last3Month: '最近3个月'
22
+ }
23
+ },
24
+ public: {
25
+ placeholders: '请选择',
26
+ placeholderi: '请填写',
27
+ loading: '加载中...',
28
+ confirm: '确定',
29
+ clear: '清空',
30
+ cancel: '取消',
31
+ search: '搜索',
32
+ reset: '重置',
33
+ add: '新增',
34
+ edit: '编辑',
35
+ delete: '删除',
36
+ save: '保存',
37
+ close: '关闭',
38
+ submit: '提交',
39
+ selectAll: '全选'
40
+ }
41
+ }
42
+ export default zh