vue2-client 1.3.19 → 1.3.20

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 (96) hide show
  1. package/CHANGELOG.md +318 -315
  2. package/index.js +30 -30
  3. package/package.json +76 -76
  4. package/src/base-client/components/common/AddressSearchCombobox/AddressSearchCombobox.vue +225 -225
  5. package/src/base-client/components/common/CreateQuery/CreateQuery.vue +551 -551
  6. package/src/base-client/components/common/CreateQuery/CreateQueryItem.vue +777 -777
  7. package/src/base-client/components/common/CreateSimpleFormQuery/CreateSimpleFormQueryItem.vue +553 -553
  8. package/src/base-client/components/common/CustomColumnsDrawer/index.md +46 -46
  9. package/src/base-client/components/common/FormGroupQuery/FormGroupQuery.vue +165 -165
  10. package/src/base-client/components/common/JSONToTree/jsontotree.vue +275 -275
  11. package/src/base-client/components/common/Upload/Upload.vue +162 -165
  12. package/src/base-client/components/common/XAddForm/XAddForm.vue +354 -354
  13. package/src/base-client/components/common/XAddNativeForm/XAddNativeForm.vue +327 -327
  14. package/src/base-client/components/common/XCard/XCard.vue +64 -64
  15. package/src/base-client/components/common/XForm/XForm.vue +274 -274
  16. package/src/base-client/components/common/XForm/XFormItem.vue +389 -389
  17. package/src/base-client/components/common/XFormTable/index.md +96 -96
  18. package/src/base-client/components/common/XTable/XTable.vue +278 -278
  19. package/src/base-client/components/system/LogDetailsView/LogDetailsView.vue +376 -376
  20. package/src/base-client/components/system/QueryParamsDetailsView/QueryParamsDetailsView.vue +281 -281
  21. package/src/base-client/components/ticket/TicketDetailsView/TicketDetailsView.vue +807 -807
  22. package/src/base-client/components/ticket/TicketDetailsView/index.md +29 -29
  23. package/src/base-client/components/ticket/TicketDetailsView/part/TicketDetailsFlow.vue +260 -260
  24. package/src/base-client/components/ticket/TicketSubmitSuccessView/TicketSubmitSuccessView.vue +532 -532
  25. package/src/base-client/components/ticket/TicketSubmitSuccessView/index.md +29 -29
  26. package/src/base-client/plugins/AppData.js +69 -69
  27. package/src/base-client/plugins/GetLoginInfoService.js +179 -179
  28. package/src/base-client/plugins/PagedList.js +177 -177
  29. package/src/base-client/plugins/compatible/LoginServiceOA.js +20 -20
  30. package/src/base-client/plugins/i18n-extend.js +32 -32
  31. package/src/components/Ellipsis/index.md +38 -38
  32. package/src/components/NumberInfo/index.md +43 -43
  33. package/src/components/STable/README.md +341 -341
  34. package/src/components/STable/index.js +318 -318
  35. package/src/components/Trend/index.md +45 -45
  36. package/src/components/checkbox/ColorCheckbox.vue +157 -157
  37. package/src/components/checkbox/ImgCheckbox.vue +163 -163
  38. package/src/components/exception/ExceptionPage.vue +70 -70
  39. package/src/components/form/FormRow.vue +52 -52
  40. package/src/components/index.js +36 -36
  41. package/src/components/menu/SideMenu.vue +62 -62
  42. package/src/components/menu/menu.js +273 -273
  43. package/src/components/setting/Setting.vue +235 -235
  44. package/src/components/table/StandardTable.vue +141 -141
  45. package/src/components/table/advance/ActionColumns.vue +158 -158
  46. package/src/components/table/advance/SearchArea.vue +355 -355
  47. package/src/components/tool/AStepItem.vue +60 -60
  48. package/src/components/tool/AvatarList.vue +68 -68
  49. package/src/components/tool/Drawer.vue +142 -142
  50. package/src/components/tool/TagSelect.vue +83 -83
  51. package/src/components/transition/PageToggleTransition.vue +97 -97
  52. package/src/config/default/setting.config.js +41 -41
  53. package/src/config/replacer/resolve.config.js +67 -67
  54. package/src/layouts/AdminLayout.vue +174 -174
  55. package/src/layouts/header/AdminHeader.vue +104 -104
  56. package/src/layouts/header/HeaderNotice.vue +167 -167
  57. package/src/layouts/header/HeaderSearch.vue +67 -67
  58. package/src/layouts/header/InstitutionDetail.vue +181 -181
  59. package/src/layouts/tabs/TabsHead.vue +190 -190
  60. package/src/layouts/tabs/TabsView.vue +379 -379
  61. package/src/mock/goods/index.js +108 -108
  62. package/src/pages/CreateQueryPage.vue +65 -65
  63. package/src/pages/login/Login.vue +277 -277
  64. package/src/pages/report/ReportTable.js +124 -124
  65. package/src/pages/report/ReportTableHome.vue +28 -28
  66. package/src/pages/resourceManage/orgListManage.vue +98 -98
  67. package/src/pages/system/dictionary/index.vue +43 -43
  68. package/src/pages/system/file/index.vue +317 -317
  69. package/src/pages/system/queryParams/index.vue +43 -43
  70. package/src/pages/system/ticket/index.vue +489 -461
  71. package/src/pages/system/ticket/submitTicketSuccess.vue +206 -206
  72. package/src/router/async/config.async.js +27 -27
  73. package/src/router/async/router.map.js +56 -56
  74. package/src/router/index.js +27 -27
  75. package/src/services/api/DictionaryDetailsViewApi.js +6 -6
  76. package/src/services/api/LogDetailsViewApi.js +10 -10
  77. package/src/services/api/QueryParamsDetailsViewApi.js +6 -6
  78. package/src/services/api/TicketDetailsViewApi.js +34 -34
  79. package/src/services/api/common.js +58 -58
  80. package/src/services/api/commonTempTable.js +10 -10
  81. package/src/services/api/index.js +17 -17
  82. package/src/services/api/manage.js +8 -8
  83. package/src/store/mutation-types.js +2 -2
  84. package/src/theme/default/nprogress.less +76 -76
  85. package/src/theme/default/style.less +47 -47
  86. package/src/utils/colors.js +103 -103
  87. package/src/utils/excel/Blob.js +180 -180
  88. package/src/utils/excel/Export2Excel.js +141 -141
  89. package/src/utils/formatter.js +68 -68
  90. package/src/utils/i18n.js +80 -80
  91. package/src/utils/request.js +225 -225
  92. package/src/utils/routerUtil.js +364 -364
  93. package/src/utils/theme-color-replacer-extend.js +91 -91
  94. package/src/utils/themeUtil.js +100 -100
  95. package/src/utils/util.js +230 -230
  96. package/vue.config.js +99 -99
@@ -1,141 +1,141 @@
1
- /* eslint-disable */
2
- require('script-loader!file-saver');
3
- require('./Blob.js');
4
- require('script-loader!xlsx/dist/xlsx.core.min');
5
-
6
- function generateArray(table) {
7
- const out = [];
8
- const rows = table.querySelectorAll('tr');
9
- const ranges = [];
10
- for (let R = 0; R < rows.length; ++R) {
11
- const outRow = [];
12
- const row = rows[R];
13
- const columns = row.querySelectorAll('td');
14
- for (let C = 0; C < columns.length; ++C) {
15
- const cell = columns[C];
16
- let colspan = cell.getAttribute('colspan');
17
- let rowspan = cell.getAttribute('rowspan');
18
- let cellValue = cell.innerText;
19
- if (cellValue !== "" && cellValue === +cellValue) cellValue = +cellValue;
20
-
21
- //Skip ranges
22
- ranges.forEach(function (range) {
23
- if (R >= range.s.r && R <= range.e.r && outRow.length >= range.s.c && outRow.length <= range.e.c) {
24
- for (let i = 0; i <= range.e.c - range.s.c; ++i) outRow.push(null);
25
- }
26
- });
27
-
28
- //Handle Row Span
29
- if (rowspan || colspan) {
30
- rowspan = rowspan || 1;
31
- colspan = colspan || 1;
32
- ranges.push({s: {r: R, c: outRow.length}, e: {r: R + rowspan - 1, c: outRow.length + colspan - 1}});
33
- }
34
-
35
- //Handle Value
36
- outRow.push(cellValue !== "" ? cellValue : null);
37
-
38
- //Handle Colspan
39
- if (colspan) for (let k = 0; k < colspan - 1; ++k) outRow.push(null);
40
- }
41
- out.push(outRow);
42
- }
43
- return [out, ranges];
44
- }
45
-
46
- function datenum(v, date1904) {
47
- if (date1904) v += 1462;
48
- const epoch = Date.parse(v);
49
- return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
50
- }
51
-
52
- function sheet_from_array_of_arrays(data, opts) {
53
- const ws = {};
54
- const range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}};
55
- for (let R = 0; R !== data.length; ++R) {
56
- for (let C = 0; C !== data[R].length; ++C) {
57
- if (range.s.r > R) range.s.r = R;
58
- if (range.s.c > C) range.s.c = C;
59
- if (range.e.r < R) range.e.r = R;
60
- if (range.e.c < C) range.e.c = C;
61
- const cell = {v: data[R][C]};
62
- if (cell.v == null) continue;
63
- const cell_ref = XLSX.utils.encode_cell({c: C, r: R});
64
-
65
- if (typeof cell.v === 'number') cell.t = 'n';
66
- else if (typeof cell.v === 'boolean') cell.t = 'b';
67
- else if (cell.v instanceof Date) {
68
- cell.t = 'n';
69
- cell.z = XLSX.SSF._table[14];
70
- cell.v = datenum(cell.v);
71
- } else cell.t = 's';
72
-
73
- ws[cell_ref] = cell;
74
- }
75
- }
76
- if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
77
- return ws;
78
- }
79
-
80
- function Workbook() {
81
- if (!(this instanceof Workbook)) return new Workbook();
82
- this.SheetNames = [];
83
- this.Sheets = {};
84
- }
85
-
86
- function s2ab(s) {
87
- const buf = new ArrayBuffer(s.length);
88
- const view = new Uint8Array(buf);
89
- for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
90
- return buf;
91
- }
92
-
93
- export function exportTable(id) {
94
- const theTable = document.getElementById(id);
95
- console.log('a')
96
- const oo = generateArray(theTable);
97
- const ranges = oo[1];
98
-
99
- /* original data */
100
- const data = oo[0];
101
- const ws_name = "SheetJS";
102
- console.log(data);
103
-
104
- const wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
105
-
106
- /* add ranges to worksheet */
107
- // ws['!cols'] = ['apple', 'banan'];
108
- ws['!merges'] = ranges;
109
-
110
- /* add worksheet to workbook */
111
- wb.SheetNames.push(ws_name);
112
- wb.Sheets[ws_name] = ws;
113
-
114
- const wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
115
-
116
- saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx")
117
- }
118
-
119
- function formatJson(jsonData) {
120
- console.log(jsonData)
121
- }
122
-
123
- export function exportJson(th, jsonData, defaultTitle) {
124
-
125
- /* original data */
126
-
127
- const data = jsonData;
128
- data.unshift(th);
129
- const ws_name = "SheetJS";
130
-
131
- const wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
132
-
133
-
134
- /* add worksheet to workbook */
135
- wb.SheetNames.push(ws_name);
136
- wb.Sheets[ws_name] = ws;
137
-
138
- const wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
139
- const title = defaultTitle || '列表';
140
- saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx")
141
- }
1
+ /* eslint-disable */
2
+ require('script-loader!file-saver');
3
+ require('./Blob.js');
4
+ require('script-loader!xlsx/dist/xlsx.core.min');
5
+
6
+ function generateArray(table) {
7
+ const out = [];
8
+ const rows = table.querySelectorAll('tr');
9
+ const ranges = [];
10
+ for (let R = 0; R < rows.length; ++R) {
11
+ const outRow = [];
12
+ const row = rows[R];
13
+ const columns = row.querySelectorAll('td');
14
+ for (let C = 0; C < columns.length; ++C) {
15
+ const cell = columns[C];
16
+ let colspan = cell.getAttribute('colspan');
17
+ let rowspan = cell.getAttribute('rowspan');
18
+ let cellValue = cell.innerText;
19
+ if (cellValue !== "" && cellValue === +cellValue) cellValue = +cellValue;
20
+
21
+ //Skip ranges
22
+ ranges.forEach(function (range) {
23
+ if (R >= range.s.r && R <= range.e.r && outRow.length >= range.s.c && outRow.length <= range.e.c) {
24
+ for (let i = 0; i <= range.e.c - range.s.c; ++i) outRow.push(null);
25
+ }
26
+ });
27
+
28
+ //Handle Row Span
29
+ if (rowspan || colspan) {
30
+ rowspan = rowspan || 1;
31
+ colspan = colspan || 1;
32
+ ranges.push({s: {r: R, c: outRow.length}, e: {r: R + rowspan - 1, c: outRow.length + colspan - 1}});
33
+ }
34
+
35
+ //Handle Value
36
+ outRow.push(cellValue !== "" ? cellValue : null);
37
+
38
+ //Handle Colspan
39
+ if (colspan) for (let k = 0; k < colspan - 1; ++k) outRow.push(null);
40
+ }
41
+ out.push(outRow);
42
+ }
43
+ return [out, ranges];
44
+ }
45
+
46
+ function datenum(v, date1904) {
47
+ if (date1904) v += 1462;
48
+ const epoch = Date.parse(v);
49
+ return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
50
+ }
51
+
52
+ function sheet_from_array_of_arrays(data, opts) {
53
+ const ws = {};
54
+ const range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}};
55
+ for (let R = 0; R !== data.length; ++R) {
56
+ for (let C = 0; C !== data[R].length; ++C) {
57
+ if (range.s.r > R) range.s.r = R;
58
+ if (range.s.c > C) range.s.c = C;
59
+ if (range.e.r < R) range.e.r = R;
60
+ if (range.e.c < C) range.e.c = C;
61
+ const cell = {v: data[R][C]};
62
+ if (cell.v == null) continue;
63
+ const cell_ref = XLSX.utils.encode_cell({c: C, r: R});
64
+
65
+ if (typeof cell.v === 'number') cell.t = 'n';
66
+ else if (typeof cell.v === 'boolean') cell.t = 'b';
67
+ else if (cell.v instanceof Date) {
68
+ cell.t = 'n';
69
+ cell.z = XLSX.SSF._table[14];
70
+ cell.v = datenum(cell.v);
71
+ } else cell.t = 's';
72
+
73
+ ws[cell_ref] = cell;
74
+ }
75
+ }
76
+ if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
77
+ return ws;
78
+ }
79
+
80
+ function Workbook() {
81
+ if (!(this instanceof Workbook)) return new Workbook();
82
+ this.SheetNames = [];
83
+ this.Sheets = {};
84
+ }
85
+
86
+ function s2ab(s) {
87
+ const buf = new ArrayBuffer(s.length);
88
+ const view = new Uint8Array(buf);
89
+ for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
90
+ return buf;
91
+ }
92
+
93
+ export function exportTable(id) {
94
+ const theTable = document.getElementById(id);
95
+ console.log('a')
96
+ const oo = generateArray(theTable);
97
+ const ranges = oo[1];
98
+
99
+ /* original data */
100
+ const data = oo[0];
101
+ const ws_name = "SheetJS";
102
+ console.log(data);
103
+
104
+ const wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
105
+
106
+ /* add ranges to worksheet */
107
+ // ws['!cols'] = ['apple', 'banan'];
108
+ ws['!merges'] = ranges;
109
+
110
+ /* add worksheet to workbook */
111
+ wb.SheetNames.push(ws_name);
112
+ wb.Sheets[ws_name] = ws;
113
+
114
+ const wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
115
+
116
+ saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx")
117
+ }
118
+
119
+ function formatJson(jsonData) {
120
+ console.log(jsonData)
121
+ }
122
+
123
+ export function exportJson(th, jsonData, defaultTitle) {
124
+
125
+ /* original data */
126
+
127
+ const data = jsonData;
128
+ data.unshift(th);
129
+ const ws_name = "SheetJS";
130
+
131
+ const wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
132
+
133
+
134
+ /* add worksheet to workbook */
135
+ wb.SheetNames.push(ws_name);
136
+ wb.Sheets[ws_name] = ws;
137
+
138
+ const wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
139
+ const title = defaultTitle || '列表';
140
+ saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx")
141
+ }
@@ -1,68 +1,68 @@
1
- /**
2
- * 把对象按照 js配置文件的格式进行格式化
3
- * @param obj 格式化的对象
4
- * @param dep 层级,此项无需传值
5
- * @returns {string}
6
- */
7
- function formatConfig (obj, dep) {
8
- dep = dep || 1
9
- const LN = '\n'; const TAB = ' '
10
- let indent = ''
11
- for (let i = 0; i < dep; i++) {
12
- indent += TAB
13
- }
14
- let isArray = false; let arrayLastIsObj = false
15
- let str = ''; let prefix = '{'; let subfix = '}'
16
- if (Array.isArray(obj)) {
17
- isArray = true
18
- prefix = '['
19
- subfix = ']'
20
- str = obj.map((item, index) => {
21
- let format = ''
22
- if (typeof item == 'function') {
23
- //
24
- } else if (typeof item == 'object') {
25
- arrayLastIsObj = true
26
- format = `${LN}${indent}${formatConfig(item, dep + 1)},`
27
- } else if ((typeof item == 'number' && !isNaN(item)) || typeof item == 'boolean') {
28
- format = `${item},`
29
- } else if (typeof item == 'string') {
30
- format = `'${item}',`
31
- }
32
- if (index === obj.length - 1) {
33
- format = format.substring(0, format.length - 1)
34
- } else {
35
- arrayLastIsObj = false
36
- }
37
- return format
38
- }).join('')
39
- } else if (typeof obj != 'function' && typeof obj == 'object') {
40
- str = Object.keys(obj).map((key, index, keys) => {
41
- const val = obj[key]
42
- let format = ''
43
- if (typeof val == 'function') {
44
- //
45
- } else if (typeof val == 'object') {
46
- format = `${LN}${indent}${key}: ${formatConfig(val, dep + 1)},`
47
- } else if ((typeof val == 'number' && !isNaN(val)) || typeof val == 'boolean') {
48
- format = `${LN}${indent}${key}: ${val},`
49
- } else if (typeof val == 'string') {
50
- format = `${LN}${indent}${key}: '${val}',`
51
- }
52
- if (index === keys.length - 1) {
53
- format = format.substring(0, format.length - 1)
54
- }
55
- return format
56
- }).join('')
57
- }
58
- const len = TAB.length
59
- if (indent.length >= len) {
60
- indent = indent.substring(0, indent.length - len)
61
- }
62
- if (!isArray || arrayLastIsObj) {
63
- subfix = LN + indent + subfix
64
- }
65
- return `${prefix}${str}${subfix}`
66
- }
67
-
68
- module.exports = { formatConfig }
1
+ /**
2
+ * 把对象按照 js配置文件的格式进行格式化
3
+ * @param obj 格式化的对象
4
+ * @param dep 层级,此项无需传值
5
+ * @returns {string}
6
+ */
7
+ function formatConfig (obj, dep) {
8
+ dep = dep || 1
9
+ const LN = '\n'; const TAB = ' '
10
+ let indent = ''
11
+ for (let i = 0; i < dep; i++) {
12
+ indent += TAB
13
+ }
14
+ let isArray = false; let arrayLastIsObj = false
15
+ let str = ''; let prefix = '{'; let subfix = '}'
16
+ if (Array.isArray(obj)) {
17
+ isArray = true
18
+ prefix = '['
19
+ subfix = ']'
20
+ str = obj.map((item, index) => {
21
+ let format = ''
22
+ if (typeof item == 'function') {
23
+ //
24
+ } else if (typeof item == 'object') {
25
+ arrayLastIsObj = true
26
+ format = `${LN}${indent}${formatConfig(item, dep + 1)},`
27
+ } else if ((typeof item == 'number' && !isNaN(item)) || typeof item == 'boolean') {
28
+ format = `${item},`
29
+ } else if (typeof item == 'string') {
30
+ format = `'${item}',`
31
+ }
32
+ if (index === obj.length - 1) {
33
+ format = format.substring(0, format.length - 1)
34
+ } else {
35
+ arrayLastIsObj = false
36
+ }
37
+ return format
38
+ }).join('')
39
+ } else if (typeof obj != 'function' && typeof obj == 'object') {
40
+ str = Object.keys(obj).map((key, index, keys) => {
41
+ const val = obj[key]
42
+ let format = ''
43
+ if (typeof val == 'function') {
44
+ //
45
+ } else if (typeof val == 'object') {
46
+ format = `${LN}${indent}${key}: ${formatConfig(val, dep + 1)},`
47
+ } else if ((typeof val == 'number' && !isNaN(val)) || typeof val == 'boolean') {
48
+ format = `${LN}${indent}${key}: ${val},`
49
+ } else if (typeof val == 'string') {
50
+ format = `${LN}${indent}${key}: '${val}',`
51
+ }
52
+ if (index === keys.length - 1) {
53
+ format = format.substring(0, format.length - 1)
54
+ }
55
+ return format
56
+ }).join('')
57
+ }
58
+ const len = TAB.length
59
+ if (indent.length >= len) {
60
+ indent = indent.substring(0, indent.length - len)
61
+ }
62
+ if (!isArray || arrayLastIsObj) {
63
+ subfix = LN + indent + subfix
64
+ }
65
+ return `${prefix}${str}${subfix}`
66
+ }
67
+
68
+ module.exports = { formatConfig }
package/src/utils/i18n.js CHANGED
@@ -1,80 +1,80 @@
1
- import Vue from 'vue'
2
- import VueI18n from 'vue-i18n'
3
- import routesI18n from '@vue2-client/router/i18n'
4
- import './Objects'
5
- import { getI18nKey } from '@vue2-client/utils/routerUtil'
6
-
7
- /**
8
- * 创建 i18n 配置
9
- * @param locale 本地化语言
10
- * @param fallback 回退语言
11
- * @returns {VueI18n}
12
- */
13
- function initI18n (locale, fallback) {
14
- Vue.use(VueI18n)
15
- const i18nOptions = {
16
- locale,
17
- fallbackLocale: fallback,
18
- silentFallbackWarn: true
19
- }
20
- return new VueI18n(i18nOptions)
21
- }
22
-
23
- /**
24
- * 根据 router options 配置生成 国际化语言
25
- * @param lang
26
- * @param routes
27
- * @param valueKey
28
- * @returns {*}
29
- */
30
- function generateI18n (lang, routes, valueKey) {
31
- routes.forEach(route => {
32
- const keys = getI18nKey(route.fullPath).split('.')
33
- const value = valueKey === 'path' ? route[valueKey].split('/').filter(item => !item.startsWith(':') && item !== '').join('.') : route[valueKey]
34
- lang.assignProps(keys, value)
35
- if (route.children) {
36
- generateI18n(lang, route.children, valueKey)
37
- }
38
- })
39
- return lang
40
- }
41
-
42
- /**
43
- * 格式化 router.options.routes,生成 fullPath
44
- * @param routes
45
- * @param parentPath
46
- */
47
- function formatFullPath (routes, parentPath = '') {
48
- routes.forEach(route => {
49
- const isFullPath = route.path.substring(0, 1) === '/'
50
- route.fullPath = isFullPath ? route.path : (parentPath === '/' ? parentPath + route.path : parentPath + '/' + route.path)
51
- if (route.children) {
52
- formatFullPath(route.children, route.fullPath)
53
- }
54
- })
55
- }
56
-
57
- /**
58
- * 从路由提取国际化数据
59
- * @param i18n
60
- * @param routes
61
- */
62
- function mergeI18nFromRoutes (i18n, routes) {
63
- formatFullPath(routes)
64
- // eslint-disable-next-line no-new-object
65
- const CN = generateI18n({}, routes, 'name')
66
- // eslint-disable-next-line no-new-object
67
- const US = generateI18n({}, routes, 'path')
68
- i18n.mergeLocaleMessage('CN', CN)
69
- i18n.mergeLocaleMessage('US', US)
70
- const messages = routesI18n.messages
71
- Object.keys(messages).forEach(lang => {
72
- i18n.mergeLocaleMessage(lang, messages[lang])
73
- })
74
- }
75
-
76
- export {
77
- initI18n,
78
- mergeI18nFromRoutes,
79
- formatFullPath
80
- }
1
+ import Vue from 'vue'
2
+ import VueI18n from 'vue-i18n'
3
+ import routesI18n from '@vue2-client/router/i18n'
4
+ import './Objects'
5
+ import { getI18nKey } from '@vue2-client/utils/routerUtil'
6
+
7
+ /**
8
+ * 创建 i18n 配置
9
+ * @param locale 本地化语言
10
+ * @param fallback 回退语言
11
+ * @returns {VueI18n}
12
+ */
13
+ function initI18n (locale, fallback) {
14
+ Vue.use(VueI18n)
15
+ const i18nOptions = {
16
+ locale,
17
+ fallbackLocale: fallback,
18
+ silentFallbackWarn: true
19
+ }
20
+ return new VueI18n(i18nOptions)
21
+ }
22
+
23
+ /**
24
+ * 根据 router options 配置生成 国际化语言
25
+ * @param lang
26
+ * @param routes
27
+ * @param valueKey
28
+ * @returns {*}
29
+ */
30
+ function generateI18n (lang, routes, valueKey) {
31
+ routes.forEach(route => {
32
+ const keys = getI18nKey(route.fullPath).split('.')
33
+ const value = valueKey === 'path' ? route[valueKey].split('/').filter(item => !item.startsWith(':') && item !== '').join('.') : route[valueKey]
34
+ lang.assignProps(keys, value)
35
+ if (route.children) {
36
+ generateI18n(lang, route.children, valueKey)
37
+ }
38
+ })
39
+ return lang
40
+ }
41
+
42
+ /**
43
+ * 格式化 router.options.routes,生成 fullPath
44
+ * @param routes
45
+ * @param parentPath
46
+ */
47
+ function formatFullPath (routes, parentPath = '') {
48
+ routes.forEach(route => {
49
+ const isFullPath = route.path.substring(0, 1) === '/'
50
+ route.fullPath = isFullPath ? route.path : (parentPath === '/' ? parentPath + route.path : parentPath + '/' + route.path)
51
+ if (route.children) {
52
+ formatFullPath(route.children, route.fullPath)
53
+ }
54
+ })
55
+ }
56
+
57
+ /**
58
+ * 从路由提取国际化数据
59
+ * @param i18n
60
+ * @param routes
61
+ */
62
+ function mergeI18nFromRoutes (i18n, routes) {
63
+ formatFullPath(routes)
64
+ // eslint-disable-next-line no-new-object
65
+ const CN = generateI18n({}, routes, 'name')
66
+ // eslint-disable-next-line no-new-object
67
+ const US = generateI18n({}, routes, 'path')
68
+ i18n.mergeLocaleMessage('CN', CN)
69
+ i18n.mergeLocaleMessage('US', US)
70
+ const messages = routesI18n.messages
71
+ Object.keys(messages).forEach(lang => {
72
+ i18n.mergeLocaleMessage(lang, messages[lang])
73
+ })
74
+ }
75
+
76
+ export {
77
+ initI18n,
78
+ mergeI18nFromRoutes,
79
+ formatFullPath
80
+ }