|
@@ -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>
|