qiushang 1 anno fa
parent
commit
e4eb57eaed
2 ha cambiato i file con 63 aggiunte e 94 eliminazioni
  1. 1 1
      src/renderer/components/header.vue
  2. 62 93
      src/renderer/components/home.vue

+ 1 - 1
src/renderer/components/header.vue

@@ -262,7 +262,7 @@
 			})
 			// 接收系统托盘命令 - 帮助中心
 			ipcRenderer.on('help', (event, message) => {
-				electronApi.openExternal("https://images.zhuyou360.com/help");
+				electronApi.openExternal("https://www.xingyousoft.com/help");
 			})
 		},
 		methods: {

+ 62 - 93
src/renderer/components/home.vue

@@ -137,8 +137,8 @@
 							</div>
 							
 							<div class="set-item">
-								<span>保存目录:</span>
-								<el-input :title="handleData.newPath" ref="upload-input" @focus="pickPath" placeholder="请选择输出目录" size="mini" v-model="handleData.newPath" readonly style="width:180px;" prefix-icon="el-icon-folder"></el-input>
+								<span class="set-title">保存目录:</span>
+								<el-input :title="handleData.newPath" ref="upload-input" @focus="pickPath" placeholder="请选择输出目录" size="small" v-model="handleData.newPath" readonly style="width:180px;" prefix-icon="el-icon-folder"></el-input>
 								<el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="打开保存目录">
 									<i class="el-icon-folder-opened" slot="reference" style="padding-left: 5px; cursor: pointer; font-size: 22px; vertical-align: middle;" @click="openFolder()"></i>
 								</el-popover>
@@ -379,12 +379,12 @@
 					let size = fs.statSync(file).size;
 
 					if (!this.$refs.headerRef.authority.isAuthority) {
-						if (size > 1024 * 200) {
-							this.$notify.error({
-								title: '免费版,文件最大不能超过200KB!'
-							});
-							return false;
-						}
+						// if (size > 1024 * 200) {
+						// 	this.$notify.error({
+						// 		title: '免费版,文件最大不能超过200KB!'
+						// 	});
+						// 	return false;
+						// }
 					}
 
 					let fileInfo = {
@@ -490,70 +490,64 @@
 						this.loading = false;
 						return false;
 					}else{
-						
 						let fileList = this.fileList;
 						let authority = this.$refs.headerRef.authority;
-						if (fileList.length > 0) {
-							if (!authority.isAuthority && !flag) {
-								this.$refs.headerRef.memberModel = true;
-								this.$refs.headerRef.isClick = true;
-								return false;
-							} else {
-								this.$refs.headerRef.memberModel = false;
-							}
 						
-							this.loading = true;
-							setTimeout(() => {
-								this.loading = false;
-							}, 3000)
+						if (!authority.isAuthority && !flag) {
+							this.$refs.headerRef.memberModel = true;
+							this.$refs.headerRef.isClick = true;
+							return false;
+						} else {
+							this.$refs.headerRef.memberModel = false;
 						}
 						
 						//percent
 						let taskArr = [];
 						let newPath = '';
-						for (let i = 0; i < fileList.length; i++) {
-							let item = fileList[i];
-							let lastIndex = item.path.lastIndexOf('.');
-							let suffix = this.exportFormat;
+						setTimeout(async() => {
+							for (let i = 0; i < fileList.length; i++) {
+								let item = fileList[i];
+								let lastIndex = item.path.lastIndexOf('.');
+								let suffix = this.exportFormat;
+								
+								if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
+									this.handleData.newPath = this.downloadDir + separator + pjson.softInfo.softName;
+								} else {
+									fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
+									this.handleData.newPath = this.downloadDir + separator + pjson.softInfo.softName;
+								}
 							
-							if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
-								this.handleData.newPath = this.downloadDir + separator + pjson.softInfo.softName;
-							} else {
-								fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
-								this.handleData.newPath = this.downloadDir + separator + pjson.softInfo.softName;
-							}
-						
-							newPath = this.handleData.newPath + separator + item.name.slice(0, item.name.lastIndexOf('.')) + '.' + suffix;
+								newPath = this.handleData.newPath + separator + item.name.slice(0, item.name.lastIndexOf('.')) + '.' + suffix;
+								// 处理文件
+								let task = this.dealFile(i, item, newPath);
+								if (task) {
+									taskArr.push(task);
+								}
 							
-							// 处理文件
-							let task = this.dealFile(i, item, newPath);
-							if (task) {
-								taskArr.push(task);
+								if ((i + 1) % this.execLimit == 0) {
+									await Promise.all(taskArr).then(result => {
+										taskArr = [];
+									}).catch(err => {
+										console.log('err' + i, err)
+									})
+								}
 							}
-						
-							if ((i + 1) % this.execLimit == 0) {
+							
+							if (taskArr.length > 0) {
 								await Promise.all(taskArr).then(result => {
 									taskArr = [];
 								}).catch(err => {
-									console.log('err' + i, err)
+									// 错误文件添加到服务中
+									console.log('err', err)
 								})
 							}
-						}
-						
-						if (taskArr.length > 0) {
-							await Promise.all(taskArr).then(result => {
-								taskArr = [];
-							}).catch(err => {
-								// 错误文件添加到服务中
-								console.log('err', err)
-							})
-						}
-						
-						// 打开文件夹
-						if (fileList.length > 0) {
-							this.$message({message: "恭喜你,任务已完成!", type: 'success'});
-							electronApi.call('showItemInfolder', [newPath])
-						}
+							
+							// 打开文件夹
+							if (fileList.length > 0) {
+								this.$message({message: "恭喜你,任务已完成!", type: 'success'});
+								electronApi.call('showItemInfolder', [this.handleData.newPath + '\\xy.txt'])
+							}
+						}, 300)
 						
 					}
 					
@@ -561,22 +555,17 @@
 						this.loading = false;
 					}, 3000)
 				}
-				
+			},
+			showPercent(num, index, item){
+				item.percent = num;
+				this.fileList.splice(index, 1, item);
 			},
 			// 处理文件
 			dealFile(index, item, newPath) {
-				return new Promise(async (resolve, reject) => {
+				return new Promise((resolve, reject) => {
 					let path = item.path;
 					
-					item.percent = 5;
-					this.fileList[index].setInt = setInterval(() => {
-						if(item.percent < 70){
-							item.percent += 2;
-						}else if(item.percent < 99){
-							item.percent += 1;
-						}
-						this.fileList.splice(index, 1, item);
-					}, 600);
+					this.showPercent(5, index, item);
 					
 					fs.readFile(path, 'utf8', async(err, data) => {
 						if (err) {
@@ -585,12 +574,8 @@
 								title: '错误',
 								message: "出现错误,请重试!" + filePath
 							});
-							clearInterval(this.fileList[index].setInt);
 							reject(false);
-							return;
 						}
-						let startTime = new Date().getTime();
-						console.log("文件内字符长度", data.length);
 						
 						let outContent = '';
 						this.pinSetting.separator = this.separator == '' ? ' ' : this.separator;
@@ -607,6 +592,8 @@
 							outContent = pinyin(data, this.pinSetting);
 						}
 						
+						this.showPercent(50, index, item);
+						
 						let buffer;
 						if(this.pinBuild == 1){ // 上下结构
 							let blob = htmlDocx.asBlob(outContent);
@@ -614,7 +601,8 @@
 						}else{
 							buffer = outContent;
 						}
-						console.log('--out内容长度---',outContent.length,'--buffer的长度---',buffer.length);
+						
+						this.showPercent(70, index, item);
 						
 						let filePath = newPath;
 						fs.writeFile(filePath, buffer, (err) => {
@@ -624,32 +612,13 @@
 									title: '错误',
 									message: "出现错误,请重试!" + filePath
 								});
-								clearInterval(this.fileList[index].setInt);
 								reject(false);
 								throw err;
 							}
-							item.percent = 100;
-							let endTime = new Date().getTime();
-							console.log('耗时:', endTime - startTime);
-							clearInterval(this.fileList[index].setInt);
+							this.showPercent(100, index, item);
+							resolve(true);
 						});
-						
-						
-						// let writerStream = fs.createWriteStream(filePath);
-						// writerStream.write(buffer, 'utf8');
-						// writerStream.on('finish', () => {  
-						// 	item.percent = 100;
-						// 	let endTime = new Date().getTime();
-						// 	clearInterval(this.fileList[index].setInt);
-						// 	console.log('耗时:', endTime - startTime);
-						//     console.log('All writes are now complete.');  
-						// });
-						// writerStream.on('error', (err) => {
-						//     console.error('An error occurred:', err);  
-						// });
-						// writerStream.end();
 					});
-					resolve(true);
 				});
 			},