txt文件预览提交
This commit is contained in:
parent
fc32e0fecd
commit
bdac9db39a
@ -186,7 +186,6 @@ export default function useFileData() {
|
||||
case 'audio': openAudio(row); break;
|
||||
default: tishi(row);
|
||||
}
|
||||
|
||||
// clearSelection();
|
||||
} else {
|
||||
if (row.type === 'ROOT') {
|
||||
|
@ -31,6 +31,10 @@ const props = defineProps({
|
||||
type: String,
|
||||
default: false
|
||||
},
|
||||
fileUrl: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
});
|
||||
const statusMessage = ref('')
|
||||
onMounted(() => {
|
||||
@ -49,14 +53,27 @@ const editor = useEditor({
|
||||
})
|
||||
const txtloading = ref(false)
|
||||
// 加载文件内容
|
||||
const loadContent = () => {
|
||||
txtloading.value = true
|
||||
apicontent({ id: props.rowId }).then((res) => {
|
||||
// debugger
|
||||
editor.value.commands.setContent(convertNewlinesToParagraphs(res.data))
|
||||
txtloading.value = false
|
||||
|
||||
})
|
||||
// const loadContent = () => {
|
||||
// txtloading.value = true
|
||||
// apicontent({ id: props.rowId }).then((res) => {
|
||||
// // debugger
|
||||
// editor.value.commands.setContent(convertNewlinesToParagraphs(res.data))
|
||||
// txtloading.value = false
|
||||
// })
|
||||
// }
|
||||
const loadContent = async () => {
|
||||
txtloading.value = true;
|
||||
try {
|
||||
const response = await fetch(props.fileUrl);
|
||||
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
||||
const text = await response.text();
|
||||
editor.value.commands.setContent(convertNewlinesToParagraphs(text));
|
||||
// ElMessage.success('内容加载成功');
|
||||
} catch (error) {
|
||||
ElMessage.error(`加载失败: ${error.message}`);
|
||||
} finally {
|
||||
txtloading.value = false;
|
||||
}
|
||||
}
|
||||
function convertNewlinesToParagraphs(text) {
|
||||
return text.split('\n').map(line => `<p>${line}</p>`).join('');
|
||||
@ -70,10 +87,7 @@ function convertParagraphsToNewlines(html) {
|
||||
|
||||
// 保存文件内容
|
||||
const saveCcontent = () => {
|
||||
// debugger
|
||||
console.log(editor.value.getHTML())
|
||||
const content = convertParagraphsToNewlines(editor.value.getHTML())
|
||||
console.log(content)
|
||||
saveContent({ id: props.rowId, content: content }).then((res) => {
|
||||
loadContent()
|
||||
ElMessage.success('保存成功')
|
||||
|
@ -774,7 +774,6 @@ function copyMove(type: any) {
|
||||
// tableIdarr.value
|
||||
}
|
||||
function paste() {
|
||||
debugger
|
||||
let norepeat = []
|
||||
let repeatObj: any = {
|
||||
newPath: '',
|
||||
@ -1506,10 +1505,12 @@ function handleCustomEvent(row: any) {
|
||||
//编辑文本设置
|
||||
const textedit = ref(false)
|
||||
const rowId = ref('')
|
||||
const fileUrl1 = ref('')
|
||||
function testClick(row: any) {
|
||||
rowId.value = row.id
|
||||
textedit.value = true
|
||||
title.value = '编辑 - ' + row.workPath + row.fileName
|
||||
fileUrl1.value = row.url
|
||||
}
|
||||
function textClose() {
|
||||
textedit.value = false
|
||||
@ -1959,7 +1960,7 @@ function texexceltClose() {
|
||||
@update="CloseView" />
|
||||
<el-dialog :title="title" v-model="textedit" :before-close="textClose" top="30px" draggable width="60%"
|
||||
destroy-on-close>
|
||||
<textEdit :rowId="rowId" />
|
||||
<textEdit :rowId="rowId" :fileUrl="fileUrl1"/>
|
||||
|
||||
<!-- <txtexl :file-url="fileUrl" /> -->
|
||||
</el-dialog>
|
||||
|
@ -12,6 +12,7 @@ import { tstaskList, getTsNodesTree, tsFilesPage, deleteTsFilesByIds } from "@/a
|
||||
import { listLocalAndBackup, compare, uploadToBackup, downloadToLocal, deleteTsFilesById } from "@/api/fileSynchronization";
|
||||
//text文件编辑功能
|
||||
import textEdit from '@/components/textEditing/index.vue'
|
||||
import txtexl from '@/components/textEditing/txtexl.vue'
|
||||
// 文件预览相关
|
||||
import useFileUpload from "@/components/file/file/useFileUpload";
|
||||
import useHeaderStorageList from "@/components/header/useHeaderStorageList";
|
||||
@ -149,13 +150,13 @@ function gettreedata() {
|
||||
getTsNodesTree(treeForm.value).then((res: any) => {
|
||||
treedata.value = res.data
|
||||
treeloading.value = false
|
||||
if(treedata.value[0].nodeId ){
|
||||
if (treedata.value[0].nodeId) {
|
||||
pathid.value = treedata.value[0].nodeId
|
||||
nextTick(() => {
|
||||
treeRef.value?.setCurrentKey(pathid.value);
|
||||
});
|
||||
getWorkData()
|
||||
}else{
|
||||
nextTick(() => {
|
||||
treeRef.value?.setCurrentKey(pathid.value);
|
||||
});
|
||||
getWorkData()
|
||||
} else {
|
||||
workdata.value.length = 0
|
||||
backupsdata.value.length = 0
|
||||
}
|
||||
@ -478,7 +479,6 @@ function delhuifu() {
|
||||
restoreArr.value.forEach((item: any) => {
|
||||
ids.value.push(item.id)
|
||||
})
|
||||
// debugger
|
||||
deleteTsFilesByIds({ ids: ids.value.join(','), type: 'minio' }).then((res: any) => {
|
||||
if (res.code == '0') {
|
||||
ElMessage.success("删除成功")
|
||||
@ -598,16 +598,12 @@ const title1 = ref('')
|
||||
const isViewfile = ref(false)
|
||||
const fileType = ref('')
|
||||
function openPreview(row: any) {
|
||||
// debugger
|
||||
if (getFileExtension(row.fileName) == 'pdf' || getFileExtension(row.fileName) == 'pptx' || getFileExtension(row.fileName) == 'xlsx' || getFileExtension(row.fileName) == 'xls' || getFileExtension(row.fileName) == 'docx' || getFileExtension(row.fileName) == 'doc' || getFileExtension(row.fileName) == 'bin') {
|
||||
// debugger
|
||||
title1.value = row.fileName
|
||||
ViewfileUrl.value = row.url
|
||||
isViewfile.value = true
|
||||
fileType.value = getFileExtension(row.fileName)
|
||||
|
||||
} else if (getFileExtension(row.fileName) == 'txt') {
|
||||
testClick(row)
|
||||
} else {
|
||||
row.fileType = getFileType(row.fileName)
|
||||
filePreview.value = row
|
||||
@ -615,17 +611,32 @@ function openPreview(row: any) {
|
||||
openRow(row)
|
||||
}
|
||||
}
|
||||
|
||||
const textedit = ref(false)
|
||||
const rowId = ref('')
|
||||
const title = ref('')
|
||||
const fileUrl1 = ref('')
|
||||
function testClick(row: any) {
|
||||
rowId.value = row.id
|
||||
textedit.value = true
|
||||
title.value = '编辑 - ' + row.fileName
|
||||
fileUrl1.value = row.url
|
||||
}
|
||||
function textClose() {
|
||||
textedit.value = false
|
||||
}
|
||||
//文本以表格形式预览
|
||||
const textedit1 = ref(false)
|
||||
const fileUrl = ref('')
|
||||
function testexcelClick(row: any) {
|
||||
rowId.value = row.id
|
||||
textedit1.value = true
|
||||
title.value = row.fileName
|
||||
fileUrl.value = row.url
|
||||
}
|
||||
function texexceltClose() {
|
||||
textedit1.value = false
|
||||
}
|
||||
function getFileExtension(filename: any) {
|
||||
// 获取点号在文件名中的位置(从后往前查找)
|
||||
const lastIndex = filename.lastIndexOf('.');
|
||||
@ -732,7 +743,7 @@ function CloseView() {
|
||||
}">
|
||||
<div class="menu-item" @click="handleMenuClick('backups', 'local')">备份</div>
|
||||
<div class="menu-item" @click="handleMenuClick('delete', 'local')">删除</div>
|
||||
<div class="menu-item" @click="handleMenuClick('preview', 'local')">预览</div>
|
||||
<div v-if="currentNode && currentNode.isFile == 'FILE'" class="menu-item" @click="handleMenuClick('preview', 'local')">预览</div>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
|
||||
@ -765,7 +776,7 @@ function CloseView() {
|
||||
}">
|
||||
<div class="menu-item" @click="handleMenuClick('restore', 'minio')">恢复</div>
|
||||
<div class="menu-item" @click="handleMenuClick('delete', 'minio')">删除</div>
|
||||
<div class="menu-item" @click="handleMenuClick('preview', 'minio')">预览</div>
|
||||
<div v-if="currentNode && currentNode.isFile == 'FILE'" class="menu-item" @click="handleMenuClick('preview', 'minio')">预览</div>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
|
||||
@ -931,9 +942,13 @@ function CloseView() {
|
||||
@update="CloseView" />
|
||||
<el-dialog :title="title" v-model="textedit" :before-close="textClose" top="30px" draggable width="60%"
|
||||
destroy-on-close>
|
||||
<textEdit :rowId="rowId" />
|
||||
<textEdit :rowId="rowId" :fileUrl="fileUrl1" />
|
||||
<!-- </el-scrollbar> -->
|
||||
</el-dialog>
|
||||
<el-dialog :title="title" v-model="textedit1" :before-close="texexceltClose" top="30px" draggable
|
||||
width="60%" destroy-on-close>
|
||||
<txtexl :file-url="fileUrl" :rowId="rowId" />
|
||||
</el-dialog>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user