基础文件上传核心开发
This commit is contained in:
parent
e8d48d8bd9
commit
6f18bf9344
|
@ -7,6 +7,8 @@ VITE_APP_ENV = 'development'
|
|||
# AIx融合数字管理系统/开发环境
|
||||
VITE_APP_BASE_API = '/dev-api'
|
||||
|
||||
VITE_APP_UPLOAD_API = 'http://192.168.2.52:7863'
|
||||
|
||||
VITE_APP_RES_FILE_PATH = 'https://file.ysaix.com:7868/src/assets/textbook/booktxt/'
|
||||
|
||||
VITE_APP_BUILD_BASE_PATH = 'https://file.ysaix.com:7868/'
|
|
@ -7,6 +7,8 @@ VITE_APP_ENV = 'production'
|
|||
# AIx融合数字管理系统/生产环境
|
||||
VITE_APP_BASE_API = 'http://192.168.2.52:7863'
|
||||
|
||||
VITE_APP_UPLOAD_API = 'https://prev.ysaix.com:7868'
|
||||
|
||||
# 是否在打包时开启压缩,支持 gzip 和 brotli
|
||||
VITE_BUILD_COMPRESS = gzip
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import CryptoJS from 'crypto-js'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import { ElectronDownloadManager } from 'electron-dl-manager'
|
||||
import { dialog } from 'electron'
|
||||
import axios from 'axios'
|
||||
const uploadUrl = import.meta.env.VITE_APP_BASE_API + '/smarttalk/file/upload'
|
||||
console.log(uploadUrl)
|
||||
const uploadUrl = import.meta.env.VITE_APP_UPLOAD_API + '/smarttalk/file/upload'
|
||||
const manager = new ElectronDownloadManager()
|
||||
export default async function ({ app, shell, BrowserWindow, ipcMain }) {
|
||||
const userDataPath = app.getPath('userData')
|
||||
|
@ -46,6 +47,18 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
|
|||
})
|
||||
})
|
||||
|
||||
function getFileMD5(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fileReader = new FileReader()
|
||||
fileReader.onload = (e) => {
|
||||
const buffer = e.target.result
|
||||
let md5 = CryptoJS.MD5(buffer).toString()
|
||||
resolve(md5)
|
||||
}
|
||||
fileReader.readAsArrayBuffer(file)
|
||||
})
|
||||
}
|
||||
|
||||
ipcMain.on('creat-file-default', (e, { name, uploadData, cookie }) => {
|
||||
createFolder('tempFile').then(() => {
|
||||
let path = appTempFilePath + name
|
||||
|
@ -55,50 +68,38 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
|
|||
if (err) {
|
||||
return console.error(err)
|
||||
}
|
||||
console.log(cookie)
|
||||
// 配置上传的请求
|
||||
// const uploadUrl = 'http://192.168.2.52:7863/smarttalk/file/upload' // 你的上传服务URL
|
||||
const config = {
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream', // 或者其他适合上传文件的Content-Type
|
||||
'Content-Type': 'multipart/form-data', // 或者其他适合上传文件的Content-Type
|
||||
Authorization: 'Bearer ' + cookie
|
||||
}
|
||||
}
|
||||
|
||||
let md5 = CryptoJS.MD5(data).toString()
|
||||
let formData = new FormData()
|
||||
// 使用axios上传文件
|
||||
let file = new File([data], name, {
|
||||
type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
||||
})
|
||||
formData.append('file', file)
|
||||
formData.append('md5',md5)
|
||||
|
||||
for (let key in uploadData) {
|
||||
if (uploadData.hasOwnProperty(key)) { // 检查是否是对象自身的属性
|
||||
formData.append(key,uploadData[key])
|
||||
}
|
||||
}
|
||||
formData.append("fileFlag","教案")
|
||||
axios
|
||||
.post(uploadUrl, { ...uploadData, data }, config)
|
||||
.post(uploadUrl, formData, config)
|
||||
.then((response) => {
|
||||
e.reply('creat-file-default-reply', response.data)
|
||||
console.log('File uploaded successfully:', response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error uploading file:', error)
|
||||
})
|
||||
})
|
||||
/*fs.readFile(path, (err, data) => {
|
||||
if (err) {
|
||||
return console.error(err)
|
||||
}
|
||||
let file = new File([data], '111.pptx', {
|
||||
type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
||||
})
|
||||
const headers = {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
Authorization: 'Bearer ' + cookie
|
||||
}
|
||||
axios
|
||||
.post(
|
||||
import.meta.env.VITE_APP_BASE_API + '/smarttalk/file/upload',
|
||||
{
|
||||
file
|
||||
},
|
||||
{ headers }
|
||||
)
|
||||
.then((res) => {
|
||||
console.log(res)
|
||||
})
|
||||
// e.reply('creat-file-default-reply', res)
|
||||
})*/
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ export default {
|
|||
return {
|
||||
timer: null,
|
||||
uploadDatas: {},
|
||||
uploadUrl: import.meta.env.VITE_APP_BASE_API + '/smarttalk/file/upload',
|
||||
uploadUrl: import.meta.env.VITE_APP_UPLOAD_API + '/smarttalk/file/upload',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + getToken()
|
||||
},
|
||||
|
|
|
@ -79,7 +79,6 @@ export default {
|
|||
let ids = this.choose.map((item) => {
|
||||
return { id: item.fileNewName, name: item.fileShowName }
|
||||
})
|
||||
console.log(ids)
|
||||
exportFile(ids).then((res) => {
|
||||
console.log(res)
|
||||
})
|
||||
|
|
|
@ -81,7 +81,6 @@ import { toTimeText } from '@/utils/date'
|
|||
import { ElMessage } from 'element-plus'
|
||||
import { isHaveLocalFile, parseCataByNode, creatPPT } from '@/utils/talkFile'
|
||||
import FileOperBatch from '@/views/prepare/container/file-oper-batch.vue'
|
||||
import fs from 'fs'
|
||||
const { ipcRenderer } = window.electron || {}
|
||||
export default {
|
||||
name: 'Prepare',
|
||||
|
@ -136,7 +135,7 @@ export default {
|
|||
methods: {
|
||||
createFile() {
|
||||
creatPPT('新建ppt文档.pptx',this.uploadData).then((res) => {
|
||||
console.log(res)
|
||||
this.currentFileList.unshift(res.resData)
|
||||
})
|
||||
},
|
||||
onMoveSingleFile(item) {
|
||||
|
|
Loading…
Reference in New Issue