Skip to content

Commit

Permalink
Merge pull request #253 from jamebal/search
Browse files Browse the repository at this point in the history
perf: dwg文件预览友好性提示
  • Loading branch information
jamebal authored Aug 2, 2024
2 parents 97c009b + 1dda5c5 commit 4039bf1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/components/ShowFile/ShowFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@

<message-dialog
title="提示"
content="此文件不支持预览, 是否下载该文件?"
:content="notPreviewDialogMsg"
:show.sync="notPreviewDialogVisible"
button-size="mini"
operatButtonText="取消"
Expand Down Expand Up @@ -1098,6 +1098,7 @@ export default {
drawFlag: false,
fileListScrollTop: 0,
initFileListScrollTop: 0,
notPreviewDialogMsg: '', // 非预览文件提示信息
notPreviewDialogVisible: false,
openingFile: '',
openCompressionVisible: false,
Expand Down Expand Up @@ -1227,6 +1228,7 @@ export default {
break
case 'loadFileFailed':
this.notPreviewDialogVisible = true
this.notPreviewDialogMsg = msg.msg || '此文件不支持预览, 是否下载该文件?'
break
case 'clickMore':
this.$refs.fileListTable.tableSelectData = msg.data
Expand Down Expand Up @@ -1477,7 +1479,6 @@ export default {
}
},
onmessage(msg) {
console.log(msg.url, this.$route.path, msg, this.path)
let fileDoc = msg.body
const url = msg.url
let index = this.fileList.findIndex(file => file.id === fileDoc.id)
Expand Down
33 changes: 25 additions & 8 deletions src/components/preview/CADPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<div>
<div class="top-bar">
<div class="top-left"></div>
<div class="top-center">{{file.name}}</div>
<div class="top-center">{{ file.name }}</div>
<div class="top-right">
<div class="top-right-option">
<el-button title="切换背景色" size="medium" type="primary" @click="changeBackground" :icon="lightTheme?'el-icon-moon':'el-icon-sunny'"></el-button>
<el-button title="显示全部" size="medium" type="primary" @click="reset" icon="el-icon-c-scale-to-original"></el-button>
<el-button title="切换背景色" size="medium" type="primary" @click="changeBackground"
:icon="lightTheme?'el-icon-moon':'el-icon-sunny'"></el-button>
<el-button title="显示全部" size="medium" type="primary" @click="reset"
icon="el-icon-c-scale-to-original"></el-button>
</div>
</div>
</div>
Expand All @@ -17,7 +19,7 @@
</template>

<script>
import { createMxCad, MxCpp } from 'mxcad'
import { createMxCad, loadMxCADassembly, MxCpp } from 'mxcad'
import { MxFun } from 'mxdraw'
export default {
Expand Down Expand Up @@ -57,10 +59,15 @@ export default {
canvas: '#mxCadCanvas',
locateFile: (fileName) => window.location.origin + '/resource/mxcad/wasm/2d-st/' + fileName,
fontspath: window.location.origin + '/resource/mxcad/fonts/',
fileUrl: this.mxwebUrl,
}).then(() => {
fileUrl: '',
onOpenFileComplete: () => {
this.$emit('onReady')
},
}).then((mxcad) => {
this.fetchFile()
MxFun.sendStringToExecute('Mx_Pan')
this.$emit('onReady')
}).catch((error) => {
console.error('加载 MxCAD assembly 时出错:', error)
})
},
methods: {
Expand All @@ -71,6 +78,16 @@ export default {
mxcad.updateDisplay()
mxcad.setViewBackgroundColor(value, value, value)
},
fetchFile() {
const mxcad = this.mxcad()
mxcad.openWebFile(this.mxwebUrl, (iRet) => {
if (iRet === 0) {
this.$emit('onReady')
} else {
this.$emit('loadFileFailed', '文件加载失败, 请稍后再试, 或者对该文件重建索引')
}
})
},
reset() {
const mxcad = this.mxcad()
mxcad.regen()
Expand All @@ -79,7 +96,7 @@ export default {
},
mxcad() {
return MxCpp.getCurrentMxCAD()
}
},
},
}
</script>
Expand Down
6 changes: 3 additions & 3 deletions src/components/preview/IframePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<svg-icon class="preview-close" icon-class="close"/>
</div>
<div class="wrapper">
<CADPreview v-if="fileType === 'cad'" :file="file" :shareId="shareId" :file-url="fileUrl" @onReady="onReady"></CADPreview>
<CADPreview v-if="fileType === 'cad'" :file="file" :shareId="shareId" :file-url="fileUrl" @onReady="onReady" @loadFileFailed="loadFileFailed"></CADPreview>
<pdf-preview v-else-if="fileType === 'pdf'" :file="file" :shareId="shareId" :file-url="fileUrl" @onReady="onReady"></pdf-preview>
<drawio v-else-if="fileType === 'drawio'" v-show="fileReday" :file="file" :shareId="shareId" :read-only="readOnly" @onEdit="onEdit" @onReady="onReady" @onClose="close"></drawio>
<my-mind-editor v-else-if="fileType === 'mind'" :file="file" :shareId="shareId" :read-only="readOnly" @onEdit="onEdit" @onReady="onReady" @onClose="close"></my-mind-editor>
Expand Down Expand Up @@ -157,9 +157,9 @@ export default {
/**
* 加载失败
*/
loadFileFailed() {
loadFileFailed(msg) {
this.close()
this.$store.dispatch('updateMessage', { event: 'loadFileFailed'})
this.$store.dispatch('updateMessage', { event: 'loadFileFailed', msg: msg})
this.readyShow = true
},
/**
Expand Down
1 change: 1 addition & 0 deletions src/icons/svg/file-dwg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/icons/svg/file-epub.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/utils/file-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ iconClass.set('plist','file-plist')
iconClass.set('iso','file-iso')
iconClass.set('glb','file-glb')
iconClass.set('gltf','file-glb')
iconClass.set('epub','epub')
iconClass.set('dwg','dwg')
iconClass.set('epub','file-epub')
iconClass.set('dwg','file-dwg')

export function findIconClass(file){
if(!file){
Expand Down

0 comments on commit 4039bf1

Please sign in to comment.