|
@@ -786,6 +786,12 @@
|
|
<input type="file" accept="*" style="display: none" v-if="inputShow" @change="beforeUpload2($event, unitIndex, 12, itemTaskIndex)
|
|
<input type="file" accept="*" style="display: none" v-if="inputShow" @change="beforeUpload2($event, unitIndex, 12, itemTaskIndex)
|
|
" />
|
|
" />
|
|
</button> -->
|
|
</button> -->
|
|
|
|
+ <!-- <button
|
|
|
|
+ class="c_pub_button_add pub_btn_add_img"
|
|
|
|
+ @click="uploadZIPFile(0)"
|
|
|
|
+ >
|
|
|
|
+ ZIP文件上传
|
|
|
|
+ </button> -->
|
|
</div>
|
|
</div>
|
|
<div
|
|
<div
|
|
v-if="
|
|
v-if="
|
|
@@ -8211,15 +8217,17 @@ import englishRight from "./commpont/englishRight.vue";
|
|
import EnglishVoice from "../EnglishVoice/index.vue";
|
|
import EnglishVoice from "../EnglishVoice/index.vue";
|
|
import appDialog from "../components/appDialog.vue";
|
|
import appDialog from "../components/appDialog.vue";
|
|
import { myMixin } from "@/mixins/mixin.js"
|
|
import { myMixin } from "@/mixins/mixin.js"
|
|
|
|
+import { uploadFileMixin } from "../../tools/uploadFileMixin.js";
|
|
import CodeEditor from "../components/CodeEditor";
|
|
import CodeEditor from "../components/CodeEditor";
|
|
var OpenCC = require("opencc-js");
|
|
var OpenCC = require("opencc-js");
|
|
let converter = OpenCC.Converter({
|
|
let converter = OpenCC.Converter({
|
|
from: "hk",
|
|
from: "hk",
|
|
to: "cn"
|
|
to: "cn"
|
|
});
|
|
});
|
|
|
|
+import JSZip from 'jszip'
|
|
|
|
|
|
export default {
|
|
export default {
|
|
- mixins: [ myMixin ],
|
|
|
|
|
|
+ mixins: [ myMixin,uploadFileMixin],
|
|
components: {
|
|
components: {
|
|
CodeEditor,
|
|
CodeEditor,
|
|
EditorBar,
|
|
EditorBar,
|
|
@@ -13977,7 +13985,7 @@ export default {
|
|
console.log('addHtmlSuccess',name,url,'type:',type,'unitIndex',unitIndex,'itemTaskIndex',itemTaskIndex,'index1',index1);
|
|
console.log('addHtmlSuccess',name,url,'type:',type,'unitIndex',unitIndex,'itemTaskIndex',itemTaskIndex,'index1',index1);
|
|
if (type == 1) {
|
|
if (type == 1) {
|
|
this.unitJson[unitIndex].chapterInfo[0].taskJson[
|
|
this.unitJson[unitIndex].chapterInfo[0].taskJson[
|
|
- itemTaskIndex
|
|
|
|
|
|
+ itemTaskIndex
|
|
].chapterData.splice(index1,1,{
|
|
].chapterData.splice(index1,1,{
|
|
name: Tname,
|
|
name: Tname,
|
|
url: url,
|
|
url: url,
|
|
@@ -13985,7 +13993,7 @@ export default {
|
|
})
|
|
})
|
|
}else{
|
|
}else{
|
|
this.unitJson[this.unitIndex].chapterInfo[0].taskJson[
|
|
this.unitJson[this.unitIndex].chapterInfo[0].taskJson[
|
|
- itemTaskIndex
|
|
|
|
|
|
+ itemTaskIndex
|
|
].chapterData.push({
|
|
].chapterData.push({
|
|
name: Tname,
|
|
name: Tname,
|
|
url: url,
|
|
url: url,
|
|
@@ -14039,7 +14047,156 @@ export default {
|
|
}
|
|
}
|
|
this.imgChange1(null, null, 8, this.lineCount);
|
|
this.imgChange1(null, null, 8, this.lineCount);
|
|
this.dialogVisible7 = false;
|
|
this.dialogVisible7 = false;
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ // zip压缩文件上传
|
|
|
|
+ uploadZIPFile(i){
|
|
|
|
+ this.lineCount = i;
|
|
|
|
+ // 只支持上传zip文件
|
|
|
|
+ let input = document.createElement('input');
|
|
|
|
+ input.type = 'file';
|
|
|
|
+ input.accept = '.zip';
|
|
|
|
+ input.style.display = 'none';
|
|
|
|
+ // 只允许上传一个文件
|
|
|
|
+ input.multiple = false;
|
|
|
|
+ input.onchange = async (e) => {
|
|
|
|
+ let file = e.target.files[0];
|
|
|
|
+ if (!file) return;
|
|
|
|
+ if (file.type !== 'application/zip' && !file.name.endsWith('.zip')) {
|
|
|
|
+ this.$message.error('只支持上传zip文件');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // this.awsupload({file:file,path:"zip/"+file.name}).then(res=>{
|
|
|
|
+ // console.log('uploadZIPFile', res);
|
|
|
|
+ // // 转成正常的网址
|
|
|
|
+ // let url = res && res.Location ? decodeURIComponent(res.Location) : "";
|
|
|
|
+ // console.log('正常网址:', url);
|
|
|
|
+
|
|
|
|
+ // })
|
|
|
|
+ // 这里可以根据实际需求进行上传处理
|
|
|
|
+ try{
|
|
|
|
+ const zip = new JSZip();
|
|
|
|
+ const content = await zip.loadAsync(file);
|
|
|
|
+ let _fileStructure = this.buildFileStructure(file,content);
|
|
|
|
+ let _time = new Date().getTime();
|
|
|
|
+ let _resultList = await this.uploadZipFile(_fileStructure.files,`${_time}_${_fileStructure.folderName}`);
|
|
|
|
+ console.log("_resultList",_resultList)
|
|
|
|
+
|
|
|
|
+ }catch(e){
|
|
|
|
+ console.log(e)
|
|
|
|
+ this.$message.error("解析zip文件失败")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+ document.body.appendChild(input);
|
|
|
|
+ input.click();
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ document.body.removeChild(input);
|
|
|
|
+ }, 1000);
|
|
|
|
+ },
|
|
|
|
+ // 构建文件结构树
|
|
|
|
+ buildFileStructure(file,zip) {
|
|
|
|
+ const root = {
|
|
|
|
+ folderName: file.name.replace(/\.[^/.]+$/, ""), // 移除扩展名
|
|
|
|
+ files: []
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 遍历ZIP文件中的所有文件/文件夹
|
|
|
|
+ zip.forEach((relativePath, file) => {
|
|
|
|
+ if (file.dir) return; // 跳过目录
|
|
|
|
+
|
|
|
|
+ const parts = relativePath.split('/');
|
|
|
|
+ let currentLevel = root.files;
|
|
|
|
+
|
|
|
|
+ for (let i = 0; i < parts.length; i++) {
|
|
|
|
+ const part = parts[i];
|
|
|
|
+ const isLast = i === parts.length - 1;
|
|
|
|
+
|
|
|
|
+ if (isLast) {
|
|
|
|
+ // 添加文件
|
|
|
|
+ currentLevel.push({fileName:part,file:file});
|
|
|
|
+ } else {
|
|
|
|
+ // 查找或创建文件夹
|
|
|
|
+ let folder = currentLevel.find(item =>
|
|
|
|
+ typeof item === 'object' && item.folderName === part
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (!folder) {
|
|
|
|
+ folder = {
|
|
|
|
+ folderName: part,
|
|
|
|
+ files: []
|
|
|
|
+ };
|
|
|
|
+ currentLevel.push(folder);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ currentLevel = folder.files;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return root;
|
|
|
|
+ },
|
|
|
|
+ //按路径上传文件
|
|
|
|
+ async uploadZipFile(fileList,path){
|
|
|
|
+ return new Promise(async (resolve)=>{
|
|
|
|
+ let _copyFileList = fileList;
|
|
|
|
+
|
|
|
|
+ let promise = [];
|
|
|
|
+ for(let i = 0; i < _copyFileList.length; i++){
|
|
|
|
+ if(_copyFileList[i].folderName){
|
|
|
|
+ let _path = `${path}/${_copyFileList[i].folderName}`;
|
|
|
|
+ promise.push(this.uploadZipFile(_copyFileList[i].files,_path).then(res=>{
|
|
|
|
+ _copyFileList[i].files = res;
|
|
|
|
+ }))
|
|
|
|
+ }else if(_copyFileList[i].fileName){
|
|
|
|
+ // 将 ZIP 条目转换为文件对象
|
|
|
|
+ const blob = await _copyFileList[i].file.async('blob');
|
|
|
|
+ // 根据文件名设置type
|
|
|
|
+ let type = 'text/html';
|
|
|
|
+ if (_copyFileList[i].fileName.endsWith('.js')) {
|
|
|
|
+ type = 'application/javascript';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.css')) {
|
|
|
|
+ type = 'text/css';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.json')) {
|
|
|
|
+ type = 'application/json';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.png')) {
|
|
|
|
+ type = 'image/png';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.jpg') || _copyFileList[i].fileName.endsWith('.jpeg')) {
|
|
|
|
+ type = 'image/jpeg';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.gif')) {
|
|
|
|
+ type = 'image/gif';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.svg')) {
|
|
|
|
+ type = 'image/svg+xml';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.html') || _copyFileList[i].fileName.endsWith('.htm')) {
|
|
|
|
+ type = 'text/html';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.txt')) {
|
|
|
|
+ type = 'text/plain';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.pdf')) {
|
|
|
|
+ type = 'application/pdf';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.mp3')) {
|
|
|
|
+ type = 'audio/mpeg';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.mp4')) {
|
|
|
|
+ type = 'video/mp4';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.zip')) {
|
|
|
|
+ type = 'application/zip';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.xml')) {
|
|
|
|
+ type = 'application/xml';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.csv')) {
|
|
|
|
+ type = 'text/csv';
|
|
|
|
+ } else if (_copyFileList[i].fileName.endsWith('.md')) {
|
|
|
|
+ type = 'text/markdown';
|
|
|
|
+ }
|
|
|
|
+ let _file = new File([blob], _copyFileList[i].fileName, {type: type, lastModified: new Date().getTime()});
|
|
|
|
+ promise.push(this.awsupload({file:_file,path:`${path}/${_copyFileList[i].fileName}`}).then(res=>{
|
|
|
|
+ delete _copyFileList[i].file;
|
|
|
|
+ _copyFileList[i].url = decodeURIComponent(res.Location);
|
|
|
|
+ }))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Promise.all(promise).then(res=>{
|
|
|
|
+ resolve(_copyFileList);
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
},
|
|
},
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
clearTimeout(this.timer);
|
|
clearTimeout(this.timer);
|