yh-i18n 2.2.9 → 2.2.11
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/excelTool.ts +68 -48
- package/list.vue +14 -1
- package/package.json +20 -20
package/excelTool.ts
CHANGED
|
@@ -139,7 +139,7 @@ async function getFile() {
|
|
|
139
139
|
id: "importTranslateExcel",
|
|
140
140
|
types: [
|
|
141
141
|
{
|
|
142
|
-
description: "
|
|
142
|
+
description: "请选择之前导出的文件",
|
|
143
143
|
accept: {
|
|
144
144
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [".xlsx", ".xls"],
|
|
145
145
|
},
|
|
@@ -162,6 +162,20 @@ async function getFile() {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
|
|
166
|
+
async function saveData(dataList){
|
|
167
|
+
return await http
|
|
168
|
+
.request({
|
|
169
|
+
url: "/translate/save",
|
|
170
|
+
type: "json",
|
|
171
|
+
method: "POST",
|
|
172
|
+
data: dataList,
|
|
173
|
+
})
|
|
174
|
+
.then((res) => {
|
|
175
|
+
return res?.data?.status === 200
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
165
179
|
export async function importExcel(getDataList) {
|
|
166
180
|
if (!window["showOpenFilePicker"]) {
|
|
167
181
|
ElMessage({
|
|
@@ -178,56 +192,62 @@ export async function importExcel(getDataList) {
|
|
|
178
192
|
});
|
|
179
193
|
return false;
|
|
180
194
|
} else {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
let len = sheet._rows.length - 1;
|
|
197
|
-
let dataList: any[] = [];
|
|
198
|
-
sheet.getRows(2, len)?.forEach((row) => {
|
|
199
|
-
let id = row.getCell(1).value;
|
|
200
|
-
let key = row.getCell(2).value;
|
|
201
|
-
let content: any = {};
|
|
202
|
-
Config.i18nList.forEach((item, index) => {
|
|
203
|
-
content[item] = row.getCell(index + 3).value;
|
|
195
|
+
try {
|
|
196
|
+
const workbook = new ExcelJS.Workbook();
|
|
197
|
+
await workbook.xlsx.load(file);
|
|
198
|
+
if (workbook.keywords !== verificationCode) {
|
|
199
|
+
ElMessage({
|
|
200
|
+
message: "您选择的文件不是系统导出的文件",
|
|
201
|
+
type: "warning",
|
|
202
|
+
});
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const loading = ElLoading.service({
|
|
206
|
+
lock: true,
|
|
207
|
+
text: "开始读取已翻译的字段",
|
|
208
|
+
background: "rgba(255, 255, 255, 0.5)",
|
|
209
|
+
customClass: "yh-i18n-loading"
|
|
204
210
|
});
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
let sheet = workbook.worksheets[0];
|
|
212
|
+
let len = sheet._rows.length - 1;
|
|
213
|
+
let dataList: any[] = [];
|
|
214
|
+
sheet.getRows(2, len)?.forEach((row) => {
|
|
215
|
+
let id = row.getCell(1).value;
|
|
216
|
+
let key = row.getCell(2).value;
|
|
217
|
+
let content: any = {};
|
|
218
|
+
Config.i18nList.forEach((item, index) => {
|
|
219
|
+
content[item] = row.getCell(index + 3).value;
|
|
220
|
+
});
|
|
221
|
+
dataList.push({
|
|
222
|
+
id,
|
|
223
|
+
key,
|
|
224
|
+
content: JSON.stringify(content),
|
|
225
|
+
});
|
|
209
226
|
});
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
getDataList();
|
|
227
|
+
loading.setText("读取完成,正在更新");
|
|
228
|
+
|
|
229
|
+
let dataLen = dataList.length;
|
|
230
|
+
let flag = true;
|
|
231
|
+
let saveLength = 200;
|
|
232
|
+
while (flag) {
|
|
233
|
+
if(dataList.length > saveLength) {
|
|
234
|
+
let perCent = (dataLen - dataList.length)/dataLen
|
|
235
|
+
let fillIndex = parseInt((perCent / 0.5 * 10).toFixed(0));
|
|
236
|
+
let loadingText = new Array(20);
|
|
237
|
+
loadingText.fill('◇',0,20-fillIndex)
|
|
238
|
+
loadingText.fill('◆',20-fillIndex)
|
|
239
|
+
loading.setText(`${(perCent*100).toFixed(2)}% ${loadingText.join('')} 正在更新…………`)
|
|
240
|
+
await saveData(dataList.splice(0,saveLength))
|
|
225
241
|
} else {
|
|
226
|
-
|
|
242
|
+
await saveData(dataList)
|
|
243
|
+
flag = false;
|
|
227
244
|
}
|
|
228
|
-
}
|
|
229
|
-
.
|
|
230
|
-
|
|
231
|
-
|
|
245
|
+
}
|
|
246
|
+
loading.close();
|
|
247
|
+
ElMessage.success("导入数据保存成功")
|
|
248
|
+
getDataList();
|
|
249
|
+
} catch (error) {
|
|
250
|
+
ElMessage.error("导入保存翻译数据遇到错误:",error.message)
|
|
251
|
+
}
|
|
232
252
|
}
|
|
233
253
|
}
|
package/list.vue
CHANGED
|
@@ -468,14 +468,21 @@ onMounted(() => {
|
|
|
468
468
|
display: flex;
|
|
469
469
|
flex-direction: column;
|
|
470
470
|
.yh-i18n-list-actions {
|
|
471
|
-
padding: 16px;
|
|
471
|
+
padding: 8px 16px;
|
|
472
472
|
box-sizing: border-box;
|
|
473
473
|
display: flex;
|
|
474
474
|
.yh-i18n-list-conditions {
|
|
475
475
|
padding: 0 8px;
|
|
476
476
|
flex: 1;
|
|
477
|
+
.el-form--inline .el-form-item {
|
|
478
|
+
margin-bottom: 0;
|
|
479
|
+
margin-right: 18px;
|
|
480
|
+
}
|
|
477
481
|
}
|
|
478
482
|
}
|
|
483
|
+
.yh-i18n-list-actions + .yh-i18n-list-actions {
|
|
484
|
+
padding-top: 0;
|
|
485
|
+
}
|
|
479
486
|
.el-table {
|
|
480
487
|
flex: 1;
|
|
481
488
|
}
|
|
@@ -489,4 +496,10 @@ onMounted(() => {
|
|
|
489
496
|
flex: 1;
|
|
490
497
|
}
|
|
491
498
|
}
|
|
499
|
+
.yh-i18n-loading {
|
|
500
|
+
.el-loading-text {
|
|
501
|
+
font-size: 20px;
|
|
502
|
+
font-weight: 600;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
492
505
|
</style>
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "yh-i18n",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"description": "对于国际化的封装",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"pub:npm": "npm publish --registry https://registry.npmjs.org/ --no-git-checks",
|
|
8
|
-
"pub:aliyun": "npm publish --registry https://packages.aliyun.com/60765e0161a945067837bb5f/npm/npm-registry/ --no-git-checks"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"exceljs": "4.4.0"
|
|
12
|
-
},
|
|
13
|
-
"peerDependencies": {
|
|
14
|
-
"vue-i18n": "9.8.0",
|
|
15
|
-
"vue": "3.2.47",
|
|
16
|
-
"vxe-table": "4.3.10",
|
|
17
|
-
"element-plus": "2.3.8"
|
|
18
|
-
},
|
|
19
|
-
"author": "Liubin"
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "yh-i18n",
|
|
3
|
+
"version": "2.2.11",
|
|
4
|
+
"description": "对于国际化的封装",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"pub:npm": "npm publish --registry https://registry.npmjs.org/ --no-git-checks",
|
|
8
|
+
"pub:aliyun": "npm publish --registry https://packages.aliyun.com/60765e0161a945067837bb5f/npm/npm-registry/ --no-git-checks"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"exceljs": "4.4.0"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"vue-i18n": "9.8.0",
|
|
15
|
+
"vue": "3.2.47",
|
|
16
|
+
"vxe-table": "4.3.10",
|
|
17
|
+
"element-plus": "2.3.8"
|
|
18
|
+
},
|
|
19
|
+
"author": "Liubin"
|
|
20
|
+
}
|