|
@@ -43,37 +43,35 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <div style="height: calc(100% - 150px);" v-if="pinyinType == 2 && fileList.length > 0">
|
|
|
- <div>
|
|
|
- <p class="title">
|
|
|
- <i class="el-icon-notebook-2"></i>
|
|
|
- 文件列表
|
|
|
- <span style="color: #F22C40;">{{ loadingTips }}</span>
|
|
|
- </p>
|
|
|
- <div class="table-scroll" id="drag-compress">
|
|
|
- <vxe-table
|
|
|
- show-overflow
|
|
|
- class="img-table"
|
|
|
- max-height="100%"
|
|
|
- empty-text="没有更多数据了!"
|
|
|
- :row-config="{isHover: true}"
|
|
|
- :edit-config="{trigger: 'click', mode: 'cell'}"
|
|
|
- :data="fileList"
|
|
|
- :scroll-y="{enabled: true}">
|
|
|
- <vxe-column field="name" title="文件名"></vxe-column>
|
|
|
- <vxe-column field="size" title="大小" width="120"></vxe-column>
|
|
|
- <vxe-column field="progress" title="进度" width="180">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-progress :text-inside="true" :stroke-width="20" :percentage="row.percent"></el-progress>
|
|
|
- </template>
|
|
|
- </vxe-column>
|
|
|
- <vxe-column title="操作" width="80">
|
|
|
- <template #default="{ row, rowIndex }">
|
|
|
- <i class="el-icon-delete cur-pointer" @click="delFile(rowIndex)"></i>
|
|
|
- </template>
|
|
|
- </vxe-column>
|
|
|
- </vxe-table>
|
|
|
- </div>
|
|
|
+ <div style="height: 100%;" v-if="pinyinType == 2 && fileList.length > 0">
|
|
|
+ <p class="title">
|
|
|
+ <i class="el-icon-notebook-2"></i>
|
|
|
+ 文件列表
|
|
|
+ <span style="color: #F22C40;">{{ loadingTips }}</span>
|
|
|
+ </p>
|
|
|
+ <div class="table-scroll" id="drag-compress">
|
|
|
+ <vxe-table
|
|
|
+ show-overflow
|
|
|
+ class="img-table"
|
|
|
+ max-height="100%"
|
|
|
+ empty-text="没有更多数据了!"
|
|
|
+ :row-config="{isHover: true}"
|
|
|
+ :edit-config="{trigger: 'click', mode: 'cell'}"
|
|
|
+ :data="fileList"
|
|
|
+ :scroll-y="{enabled: true}">
|
|
|
+ <vxe-column field="name" title="文件名"></vxe-column>
|
|
|
+ <vxe-column field="size" title="大小" width="120"></vxe-column>
|
|
|
+ <vxe-column field="progress" title="进度" width="180">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-progress :text-inside="true" :stroke-width="20" :percentage="row.percent"></el-progress>
|
|
|
+ </template>
|
|
|
+ </vxe-column>
|
|
|
+ <vxe-column title="操作" width="80">
|
|
|
+ <template #default="{ row, rowIndex }">
|
|
|
+ <i class="el-icon-delete cur-pointer" @click="delFile(rowIndex)"></i>
|
|
|
+ </template>
|
|
|
+ </vxe-column>
|
|
|
+ </vxe-table>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -133,9 +131,9 @@
|
|
|
<el-option label="字符串紧凑输出" value="consecutive"></el-option>
|
|
|
</el-select>
|
|
|
</div>
|
|
|
- <div class="set-item" v-if="pinBuild == 2">
|
|
|
+ <div class="set-item">
|
|
|
<span class="set-title">分隔符:</span>
|
|
|
- <el-input v-model="separator" size="small" placeholder="默认为空格" style="width:100px;" @input="dataChange"></el-input>
|
|
|
+ <el-input type="text" maxlength="5" :show-word-limit="true" v-model="separator" size="small" placeholder="默认为空格" style="width:125px;" @input="dataChange"></el-input>
|
|
|
</div>
|
|
|
|
|
|
<div class="set-item">
|
|
@@ -420,10 +418,10 @@
|
|
|
inputChange(val){
|
|
|
this.pinSetting.separator = this.separator == '' ? ' ' : this.separator;
|
|
|
if(this.pinBuild == 1){ // 上下结构
|
|
|
- this.txtHtml = '';
|
|
|
let htmls = html(val, {toneType : this.pinSetting.toneType, wrapNonChinese: true});
|
|
|
- htmls = htmls.replace(/m"> <\/s/g, 'm"> </s');
|
|
|
- htmls = htmls.replace(/m">\n<\/span>/g, 'm">\n</span><br>');
|
|
|
+ htmls = htmls.replace(/py-non-chinese-item"> <\/span>/g, 'py-non-chinese-item"> </span>');
|
|
|
+ htmls = htmls.replace(/py-non-chinese-item">\n<\/span>/g, 'py-non-chinese-item">\n</span><br>');
|
|
|
+ htmls = htmls.replace(/<\/span><span class="py-result-item">/g, '</span>'+this.separator+'<span class="py-result-item">');
|
|
|
// htmls = htmls.replace(/rp/g, 'span');
|
|
|
// htmls = htmls.replace(/rt/g, 'span');
|
|
|
this.txtHtml = htmls;
|
|
@@ -432,6 +430,9 @@
|
|
|
}
|
|
|
},
|
|
|
dataChange(){
|
|
|
+ if(this.pinBuild == 1 && this.exportFormat == 'txt'){
|
|
|
+ this.exportFormat = 'docx';
|
|
|
+ }
|
|
|
this.inputChange(this.txt1);
|
|
|
},
|
|
|
// 导出
|
|
@@ -479,179 +480,143 @@
|
|
|
this.loading = false;
|
|
|
return false;
|
|
|
}else{
|
|
|
- let path = this.fileList[0].path;
|
|
|
- fs.readFile(path, 'utf8', async (err, data) => {
|
|
|
- if (err) {
|
|
|
- console.error(err);
|
|
|
- return;
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
- 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);
|
|
|
+ this.loading = true;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.loading = false;
|
|
|
+ }, 3000)
|
|
|
+ }
|
|
|
+
|
|
|
+ //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;
|
|
|
+
|
|
|
+ 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;
|
|
|
|
|
|
- let buffer;
|
|
|
- if(this.pinBuild == 1){ // 上下结构
|
|
|
- let blob = htmlDocx.asBlob(outContent);
|
|
|
- buffer = Buffer.from(await blob.arrayBuffer());
|
|
|
- }else{
|
|
|
- buffer = outContent;
|
|
|
+ // 处理文件
|
|
|
+ let task = this.dealFile(i, item, newPath);
|
|
|
+ if (task) {
|
|
|
+ taskArr.push(task);
|
|
|
}
|
|
|
- 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)
|
|
|
-
|
|
|
- });
|
|
|
|
|
|
- });
|
|
|
+ if ((i + 1) % this.execLimit == 0) {
|
|
|
+ await Promise.all(taskArr).then(result => {
|
|
|
+ taskArr = [];
|
|
|
+ }).catch(err => {
|
|
|
+ console.log('err' + i, 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])
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
setTimeout(() => {
|
|
|
this.loading = false;
|
|
|
- }, 2000)
|
|
|
+ }, 3000)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 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.exportLoading = true;
|
|
|
- // setTimeout(() => {
|
|
|
- // this.exportLoading = false;
|
|
|
- // }, 3000)
|
|
|
- // }
|
|
|
-
|
|
|
- // //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.activeName.split('-')[1];
|
|
|
- // newPath = item.path;
|
|
|
-
|
|
|
- // if (this.handleData.pathType == '2') { // 自定义文件架判断有无 “” 文件夹
|
|
|
- // 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;
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // newPath = item.path.slice(0, lastIndex);
|
|
|
- // this.handleData.newPath = newPath;
|
|
|
- // }
|
|
|
-
|
|
|
- // 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);
|
|
|
- // }
|
|
|
-
|
|
|
- // if ((i + 1) % this.execLimit == 0) {
|
|
|
- // await Promise.all(taskArr).then(result => {
|
|
|
- // taskArr = [];
|
|
|
- // }).catch(err => {
|
|
|
- // console.log('err' + i, 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])
|
|
|
- // }
|
|
|
},
|
|
|
// 处理文件
|
|
|
dealFile(index, item, newPath) {
|
|
|
- this.$refs.headerRef.memberModel = false;
|
|
|
- let task = this.dealEbook(index, item, newPath);
|
|
|
- return task;
|
|
|
- },
|
|
|
- // 电子书格式转换
|
|
|
- dealEbook(index, eInfo, outPath) {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
- let filePath = eInfo.path; // 文件路径
|
|
|
- let cmds = [
|
|
|
- 'ebook-convert.exe',
|
|
|
- filePath,
|
|
|
- outPath
|
|
|
- ];
|
|
|
-
|
|
|
- if (this.activeName.split('-')[1] == 'epub') {
|
|
|
- cmds.push('--no-default-epub-cover');
|
|
|
- }
|
|
|
-
|
|
|
- eInfo.percent = 2;
|
|
|
- this[this.activeName.split('-')[0] + 'List'].splice(index, 1, eInfo);
|
|
|
- let times = 1;
|
|
|
- this[this.activeName.split('-')[0] + 'List'][index].setInt = setInterval(() => {
|
|
|
- times++;
|
|
|
- if (eInfo.percent < 10) {
|
|
|
- eInfo.percent += 2;
|
|
|
- } else if (eInfo.percent < 30) {
|
|
|
- eInfo.percent += 1;
|
|
|
- } else if (eInfo.percent < 99 && times % 9 == 0) {
|
|
|
- eInfo.percent += 1;
|
|
|
+ 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[this.activeName.split('-')[0] + 'List'].splice(index, 1, eInfo);
|
|
|
- }, 1000);
|
|
|
-
|
|
|
- electronApi.spawnExec(cmds).then(res => {
|
|
|
- eInfo.percent = 100;
|
|
|
- this[this.activeName.split('-')[0] + 'List'].splice(index, 1, eInfo);
|
|
|
- clearInterval(this[this.activeName.split('-')[0] + 'List'][index].setInt);
|
|
|
-
|
|
|
- resolve(true);
|
|
|
- }).catch(err => {
|
|
|
- clearInterval(this[this.activeName.split('-')[0] + 'List'][index].setInt);
|
|
|
- this.$notify.error({
|
|
|
- title: '错误',
|
|
|
- message: "出现错误,请重试!" + filePath
|
|
|
+ }, 600);
|
|
|
+
|
|
|
+ fs.readFile(path, 'utf8', async (err, data) => {
|
|
|
+ if (err) {
|
|
|
+ console.error(err);
|
|
|
+ this.$notify.error({
|
|
|
+ title: '错误',
|
|
|
+ message: "出现错误,请重试!" + filePath
|
|
|
+ });
|
|
|
+ reject(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let outContent = '';
|
|
|
+ this.pinSetting.separator = this.separator == '' ? ' ' : this.separator;
|
|
|
+ if(this.pinBuild == 1){ // 上下结构
|
|
|
+ let htmls = html(data, {toneType : this.pinSetting.toneType, wrapNonChinese: true});
|
|
|
+ htmls = htmls.replace(/py-non-chinese-item"> <\/span>/g, 'py-non-chinese-item"> </span>');
|
|
|
+ htmls = htmls.replace(/py-non-chinese-item">\n<\/span>/g, 'py-non-chinese-item">\n</span><br>');
|
|
|
+ outContent = htmls;
|
|
|
+ }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 = newPath;
|
|
|
+ fs.writeFile(filePath, buffer, (err) => {
|
|
|
+ if (err){
|
|
|
+ this.loading = false;
|
|
|
+ this.$notify.error({
|
|
|
+ title: '错误',
|
|
|
+ message: "出现错误,请重试!" + filePath
|
|
|
+ });
|
|
|
+ reject(false);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ item.percent = 100;
|
|
|
});
|
|
|
- reject(false);
|
|
|
- })
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ resolve(true);
|
|
|
});
|
|
|
},
|
|
|
|
|
|
+
|
|
|
}
|
|
|
};
|
|
|
</script>
|