qiushang 1 年間 前
コミット
625f4b8ece
3 ファイル変更133 行追加51 行削除
  1. 1 1
      package.json
  2. 119 37
      src/renderer/components/home.vue
  3. 13 13
      yarn.lock

+ 1 - 1
package.json

@@ -42,7 +42,7 @@
 		"jsdom": "21.0.0",
 		"pdfkit": "^0.15.0",
 		"pdfmake": "^0.2.10",
-		"pinyin-pro": "^3.19.6",
+		"pinyin-pro": "^3.20.0",
 		"regedit": "^5.0.0",
 		"request": "^2.88.2",
 		"vue": "^2.5.2",

+ 119 - 37
src/renderer/components/home.vue

@@ -31,7 +31,8 @@
 								<el-input style="height: 100%; font-size: 20px;" type="textarea" placeholder="请输入文字内容" v-model="txt1" @input="inputChange"></el-input>
 							</el-col>
 							<el-col :span="12" style="height: 100%;">
-								<div style="height: 100%; border: 1px solid #DCDFE6;background-color: #fff; padding: 15px;font-size: 20px;overflow: hidden auto;" v-html="txtHtml"></div>
+								<div class="outarea" v-html="txtHtml" v-if="pinBuild == 1"></div>
+								<el-input class="outtext" v-if="pinBuild == 2" type="textarea" placeholder="请输入文字内容" v-model="txtHtml"></el-input>
 							</el-col>
 						</el-row>
 						
@@ -145,7 +146,7 @@
 								</el-popover>
 							</div>
 							
-							<el-button type="danger" class="export-btn" @click="exportFile()" :loading="loading">开始转换</el-button>
+							<el-button type="danger" class="export-btn" @click="exportFile()" :loading="loading">开始注音</el-button>
 						</el-row>
 					</div>
 
@@ -264,17 +265,6 @@
 			this.initDrop();
 		},
 		methods: {
-			inputChange(val){
-				this.pinSetting.separator = this.separator == '' ? ' ' : this.separator;
-				if(this.pinBuild == 1){ // 上下结构
-					this.txtHtml = html(val, {toneType : this.pinSetting.toneType});
-				}else{
-					this.txtHtml = pinyin(val, this.pinSetting);
-				}
-			},
-			dataChange(){
-				this.inputChange(this.txt1);
-			},
 			// 加载拖拽监听事件
 			initDrop() {
 				const dragWrapper = document.getElementById("drag-compress");
@@ -395,7 +385,7 @@
 						}
 					}
 
-					let ebookInfo = {
+					let fileInfo = {
 						name: filename,
 						size: this.$utils.handleSize(size),
 						path: file,
@@ -403,23 +393,22 @@
 						percent: 0,
 					};
 
-					if (!ebookInfo.type) {
+					if (!fileInfo.type) {
 						this.$message({message: '不是有效的文件! - ' + file, type: 'warning'});
 					} else {
 						let flag = true;
 						let format = "TXT";
-						if (format.indexOf(ebookInfo.type.toUpperCase()) == -1) {
+						if (format.indexOf(fileInfo.type.toUpperCase()) == -1) {
 							this.$message({message: '不支持该文件格式! - ' + file, type: 'warning'});
 						} else {
 							for (let m = 0; m < this.fileList.length; m++) {
-								if (this.fileList[m].name == ebookInfo.name && this.fileList[m].path ==
-									ebookInfo.path) {
+								if (this.fileList[m].name == fileInfo.name && this.fileList[m].path == fileInfo.path) {
 									flag = false;
 								}
 							}
 
 							if (flag) {
-								this.fileList.push(ebookInfo);
+								this.fileList.push(fileInfo);
 							} else {
 								this.$message({message: '该文件已经在队列中 - ' + file, type: 'warning'});
 							}
@@ -429,6 +418,18 @@
 					}
 				})
 			},
+			// 更改设置
+			inputChange(val){
+				this.pinSetting.separator = this.separator == '' ? ' ' : this.separator;
+				if(this.pinBuild == 1){ // 上下结构
+					this.txtHtml = html(val, {toneType : this.pinSetting.toneType, wrapNonChinese: true});
+				}else{
+					this.txtHtml = pinyin(val, this.pinSetting);
+				}
+			},
+			dataChange(){
+				this.inputChange(this.txt1);
+			},
 			// 导出
 			async exportFile(flag) {
 				this.loading = true;
@@ -439,28 +440,86 @@
 					this.handleData.newPath = this.downloadDir + separator + pjson.softInfo.softName;
 				}
 				
-				let htmlContent = this.txtHtml;
-				let buffer;
-				if(this.pinBuild == 1){ // 上下结构
-					let blob = htmlDocx.asBlob(htmlContent);
-					buffer = Buffer.from(await blob.arrayBuffer());
-				}else{
-					buffer = htmlContent;
-				}
-				let filePath = this.handleData.newPath + "\\" + "注音文档" + this.$utils.formatFileTime() + '.' + this.exportFormat;
-				fs.writeFile(filePath, buffer, (err) => {
-					if (err){
+				
+				if(this.pinyinType == 1){ // 文字注音
+					if(this.txt1.length <= 0){
+						this.$message({message: '请输入需要注音的文字', type: 'warning'});
 						this.loading = false;
-						throw err;
-					} 
+						return false;
+					}
 					
-					setTimeout(() => {
+					let htmlContent = this.txtHtml;
+					let buffer;
+					if(this.pinBuild == 1){ // 上下结构
+						let blob = htmlDocx.asBlob(htmlContent);
+						buffer = Buffer.from(await blob.arrayBuffer());
+					}else{
+						buffer = htmlContent;
+					}
+					let filePath = this.handleData.newPath + "\\" + "注音文档" + this.$utils.formatFileTime() + '.' + this.exportFormat;
+					fs.writeFile(filePath, buffer, (err) => {
+						if (err){
+							this.loading = false;
+							throw err;
+						}
+						setTimeout(() => {
+							this.loading = false;
+							this.$message({message: "注音完成!", type: 'success'});
+							electronApi.call('showItemInfolder', [filePath]);
+						}, 1000)
+						
+					});
+				}else{ // 文件批量注音
+					if(this.fileList.length <= 0){
+						this.$message({message: '请选择需要注音的TXT文档', type: 'warning'});
 						this.loading = false;
-						this.$message({message: "注音完成!", type: 'success'});
-						electronApi.call('showItemInfolder', [filePath]);
-					}, 1000)
+						return false;
+					}else{
+						let path = this.fileList[0].path;
+						fs.readFile(path, 'utf8', async (err, data) => {
+							if (err) {
+								console.error(err);
+								return;
+							}
+							console.log(data);
+						
+							let outContent = '';
+							this.pinSetting.separator = this.separator == '' ? ' ' : this.separator;
+							if(this.pinBuild == 1){ // 上下结构
+								outContent = html(data, {toneType : this.pinSetting.toneType});
+							}else{
+								outContent = pinyin(data, this.pinSetting);
+							}
+							
+							let buffer;
+							if(this.pinBuild == 1){ // 上下结构
+								let blob = htmlDocx.asBlob(outContent);
+								buffer = Buffer.from(await blob.arrayBuffer());
+							}else{
+								buffer = outContent;
+							}
+							let filePath = this.handleData.newPath + "\\" + "注音文档" + this.$utils.formatFileTime() + '.' + this.exportFormat;
+							fs.writeFile(filePath, buffer, (err) => {
+								if (err){
+									this.loading = false;
+									throw err;
+								}
+								setTimeout(() => {
+									this.loading = false;
+									this.$message({message: "注音完成!", type: 'success'});
+									electronApi.call('showItemInfolder', [filePath]);
+								}, 1000)
+								
+							});
+						
+						});
+					}
 					
-				});
+					setTimeout(() => {
+						this.loading = false;
+					}, 2000)
+				}
+				
 				
 
 				
@@ -746,4 +805,27 @@
 		right: 0;
 		bottom: 20px;
 	}
+	
+	.outarea{
+		height: 100%;
+		border: 1px solid #DCDFE6;
+		background-color: #4851a415; 
+		padding: 15px;
+		font-size: 20px;
+		overflow: hidden auto;
+	}
+	
+	.outtext{
+		height: 100%;
+		font-size: 20px;
+		overflow: hidden auto;
+		
+		textarea{
+			background-color: #4851a415; 
+		}
+	}
+	
+	.py-non-chinese-item{
+		// white-space: pre;
+	}
 </style>

+ 13 - 13
yarn.lock

@@ -30,9 +30,9 @@
   integrity sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==
 
 "@babel/parser@^7.23.5":
-  version "7.24.1"
-  resolved "https://registry.npmmirror.com/@babel/parser/-/parser-7.24.1.tgz#1e416d3627393fab1cb5b0f2f1796a100ae9133a"
-  integrity sha512-Zo9c7N3xdOIQrNip7Lc9wvRPzlRtovHVE4lkz8WEDr7uYh/GMQhSiIgFxGIArRHYdJE5kxtZjAf8rT0xhdLCzg==
+  version "7.24.4"
+  resolved "https://registry.npmmirror.com/@babel/parser/-/parser-7.24.4.tgz#234487a110d89ad5a3ed4a8a566c36b9453e8c88"
+  integrity sha512-zTvEBcghmeBma9QIGunWevvBAp4/Qu9Bdq+2k0Ot4fVMD6v3dsC9WOcRSKk7tRRyBM/53yKMJko9xOatGQAwSg==
 
 "@babel/types@^7.24.0":
   version "7.24.0"
@@ -173,9 +173,9 @@
   integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==
 
 "@types/node@*":
-  version "20.12.3"
-  resolved "https://registry.npmmirror.com/@types/node/-/node-20.12.3.tgz#d6658c2c7776c1cad93534bb45428195ed840c65"
-  integrity sha512-sD+ia2ubTeWrOu+YMF+MTAB7E+O7qsMqAbMfW7DG3K1URwhZ5hN1pLlRVGbf4wDFzSfikL05M17EyorS86jShw==
+  version "20.12.4"
+  resolved "https://registry.npmmirror.com/@types/node/-/node-20.12.4.tgz#af5921bd75ccdf3a3d8b3fa75bf3d3359268cd11"
+  integrity sha512-E+Fa9z3wSQpzgYQdYmme5X3OTuejnnTx88A6p6vkkJosR3KBz+HpE3kqNm98VE6cfLFcISx7zW7MsJkH6KwbTw==
   dependencies:
     undici-types "~5.26.4"
 
@@ -3746,9 +3746,9 @@ electron-store@^2.0.0:
     conf "^2.0.0"
 
 electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.47:
-  version "1.4.724"
-  resolved "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.724.tgz#e0a86fe4d3d0e05a4d7b032549d79608078f830d"
-  integrity sha512-RTRvkmRkGhNBPPpdrgtDKvmOEYTrPlXDfc0J/Nfq5s29tEahAwhiX4mmhNzj6febWMleulxVYPh7QwCSL/EldA==
+  version "1.4.726"
+  resolved "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.726.tgz#9ca95f19e9a0d63675e838b24681182203e40a30"
+  integrity sha512-xtjfBXn53RORwkbyKvDfTajtnTp0OJoPOIBzXvkNbb7+YYvCHJflba3L7Txyx/6Fov3ov2bGPr/n5MTixmPhdQ==
 
 electron@6.0.0:
   version "6.0.0"
@@ -7421,10 +7421,10 @@ pinkie@^2.0.0:
   resolved "https://registry.npmmirror.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
   integrity sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==
 
-pinyin-pro@^3.19.6:
-  version "3.19.6"
-  resolved "https://registry.npmmirror.com/pinyin-pro/-/pinyin-pro-3.19.6.tgz#ed5eebcd43d84f8eaa32d40452b2cca55760e58c"
-  integrity sha512-oWb34orr12+DjXf6gtGMB+gIpjRi7DZzyJE66ultbmNzVhpimM/utGtMI8GcbOy/lb26Ph/nogwNYriRPu+SGQ==
+pinyin-pro@^3.20.0:
+  version "3.20.0-beta.3"
+  resolved "https://registry.npmmirror.com/pinyin-pro/-/pinyin-pro-3.20.0-beta.3.tgz#04133eec1ad75b8033fc5fa849027487528c78c2"
+  integrity sha512-j8+yxEVDOCa2fgBuJ1xvCZJc5l+1rM3z5dwvxR3sBdo37QbEVmha1SMwg9hHWYEbRI0dVdbICVWmGuH3MwuJww==
 
 pkg-dir@^2.0.0:
   version "2.0.0"