mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-13 01:28:11 +00:00
perf: 优化pdf浏览方式
This commit is contained in:
parent
d0bc85346e
commit
045d585df4
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Module\Base;
|
||||
use App\Module\Ihttp;
|
||||
use App\Module\RandomColor;
|
||||
@ -276,6 +277,40 @@ class IndexController extends InvokeController
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览文件
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function online__preview()
|
||||
{
|
||||
$key = trim(Request::input('key'));
|
||||
//
|
||||
$data = parse_url($key);
|
||||
$path = Arr::get($data, 'path');
|
||||
$file = public_path($path);
|
||||
//
|
||||
if (file_exists($file)) {
|
||||
parse_str($data['query'], $query);
|
||||
$name = Arr::get($query, 'name');
|
||||
$ext = strtolower(Arr::get($query, 'ext'));
|
||||
if ($ext === 'pdf') {
|
||||
return response()->download($file, $name, [], 'inline');
|
||||
}
|
||||
//
|
||||
if (in_array($ext, File::localExt)) {
|
||||
$url = Base::fillUrl($path);
|
||||
} else {
|
||||
$url = 'http://' . env('APP_IPPR') . '.3/' . $path;
|
||||
}
|
||||
$url = Base::urlAddparameter($url, [
|
||||
'fullfilename' => $name
|
||||
]);
|
||||
$toUrl = Base::fillUrl("fileview/onlinePreview?url=" . urlencode(base64_encode($url)));
|
||||
return Redirect::to($toUrl, 301);
|
||||
}
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置语言和皮肤
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
|
||||
@ -455,21 +455,14 @@ class File extends AbstractModel
|
||||
else
|
||||
{
|
||||
// 其他预览
|
||||
if (in_array($fileExt, File::localExt)) {
|
||||
$url = Base::fillUrl($filePath);
|
||||
} else {
|
||||
$url = 'http://' . env('APP_IPPR') . '.3/' . $filePath;
|
||||
}
|
||||
if ($fileExt != 'pdf') {
|
||||
$fileDotExt = ".{$fileExt}";
|
||||
$fullFileName = Base::rightDelete($fileName, $fileDotExt) . $fileDotExt;
|
||||
$url = Base::urlAddparameter($url, [
|
||||
'fullfilename' => $fullFileName
|
||||
]);
|
||||
}
|
||||
$name = Base::rightDelete($fileName, ".{$fileExt}") . ".{$fileExt}";
|
||||
$data['content'] = [
|
||||
'preview' => true,
|
||||
'url' => base64_encode($url),
|
||||
'name' => $name,
|
||||
'key' => urlencode(Base::urlAddparameter($filePath, [
|
||||
'name' => $name,
|
||||
'ext' => $fileExt
|
||||
])),
|
||||
];
|
||||
$data['file_mode'] = 'preview';
|
||||
}
|
||||
|
||||
@ -50,19 +50,12 @@ class FileContent extends AbstractModel
|
||||
$fileExt = $array['ext'];
|
||||
$fileName = $array['name'];
|
||||
$filePath = $array['path'];
|
||||
if (in_array($fileExt, File::localExt)) {
|
||||
$url = Base::fillUrl($filePath);
|
||||
} else {
|
||||
$url = 'http://' . env('APP_IPPR') . '.3/' . $filePath;
|
||||
}
|
||||
if ($fileExt != 'pdf') {
|
||||
$fileDotExt = ".{$fileExt}";
|
||||
$fullFileName = Base::rightDelete($fileName, $fileDotExt) . $fileDotExt;
|
||||
$url = Base::urlAddparameter($url, [
|
||||
'fullfilename' => $fullFileName
|
||||
]);
|
||||
}
|
||||
return Base::fillUrl("fileview/onlinePreview?url=" . urlencode(base64_encode($url)));
|
||||
$name = Base::rightDelete($fileName, ".{$fileExt}") . ".{$fileExt}";
|
||||
$key = urlencode(Base::urlAddparameter($filePath, [
|
||||
'name' => $name,
|
||||
'ext' => $fileExt
|
||||
]));
|
||||
return Base::fillUrl("online/preview/{$name}?key={$key}");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<Alert v-if="loadError" class="load-error" type="error" show-icon>{{$L('组件加载失败!')}}</Alert>
|
||||
<div :id="id" class="placeholder"></div>
|
||||
</template>
|
||||
<IFrame v-else class="preview-iframe" :src="previewUrl" @on-message="onMessage"/>
|
||||
<IFrame v-else class="preview-iframe" :src="previewUrl" @on-load="onFrameLoad"/>
|
||||
<div v-if="loading" class="office-loading"><Loading/></div>
|
||||
</div>
|
||||
</template>
|
||||
@ -187,12 +187,8 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
onMessage(data) {
|
||||
switch (data.action) {
|
||||
case 'ready':
|
||||
this.loading = false;
|
||||
break
|
||||
}
|
||||
onFrameLoad() {
|
||||
this.loading = false;
|
||||
},
|
||||
|
||||
getType(type) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div v-if="ready" class="file-content">
|
||||
<IFrame v-if="isPreview" class="preview-iframe" :src="previewUrl" @on-message="onMessage"/>
|
||||
<IFrame v-if="isPreview" class="preview-iframe" :src="previewUrl" @on-load="onFrameLoad"/>
|
||||
<template v-else-if="contentDetail">
|
||||
<EPopover
|
||||
v-if="['word', 'excel', 'ppt'].includes(file.type)"
|
||||
@ -278,10 +278,10 @@ export default {
|
||||
|
||||
previewUrl() {
|
||||
if (this.isPreview) {
|
||||
return $A.apiUrl("../fileview/onlinePreview?url=" + encodeURIComponent(this.contentDetail.url))
|
||||
} else {
|
||||
return '';
|
||||
const {name, key} = this.contentDetail;
|
||||
return $A.apiUrl(`../online/preview/${name}?key=${key}`)
|
||||
}
|
||||
return '';
|
||||
},
|
||||
},
|
||||
|
||||
@ -311,12 +311,8 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
onMessage(data) {
|
||||
switch (data.action) {
|
||||
case 'ready':
|
||||
this.loadPreview = false;
|
||||
break
|
||||
}
|
||||
onFrameLoad() {
|
||||
this.loadPreview = false;
|
||||
},
|
||||
|
||||
keySave(e) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="file-preview">
|
||||
<IFrame v-if="isPreview" class="preview-iframe" :src="previewUrl" @on-message="onMessage"/>
|
||||
<IFrame v-if="isPreview" class="preview-iframe" :src="previewUrl" @on-load="onFrameLoad"/>
|
||||
<template v-else-if="contentDetail">
|
||||
<div v-show="headerShow && !['word', 'excel', 'ppt'].includes(file.type)" class="edit-header">
|
||||
<div class="header-title">
|
||||
@ -110,20 +110,16 @@ export default {
|
||||
|
||||
previewUrl() {
|
||||
if (this.isPreview) {
|
||||
return $A.apiUrl("../fileview/onlinePreview?url=" + encodeURIComponent(this.contentDetail.url))
|
||||
} else {
|
||||
return '';
|
||||
const {name, key} = this.contentDetail;
|
||||
return $A.apiUrl(`../online/preview/${name}?key=${key}`)
|
||||
}
|
||||
return '';
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
onMessage(data) {
|
||||
switch (data.action) {
|
||||
case 'ready':
|
||||
this.loadPreview = false;
|
||||
break
|
||||
}
|
||||
onFrameLoad() {
|
||||
this.loadPreview = false;
|
||||
},
|
||||
|
||||
getContent() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<iframe v-if="src" ref="iframe" :src="src"></iframe>
|
||||
<iframe v-show="src" ref="iframe" :src="src"></iframe>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@ -13,14 +13,20 @@ export default {
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.$refs.iframe.addEventListener('load', this.handleLoad)
|
||||
window.addEventListener('message', this.handleMessage)
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.$refs.iframe.removeEventListener('load', this.handleLoad)
|
||||
window.removeEventListener('message', this.handleMessage)
|
||||
},
|
||||
|
||||
methods: {
|
||||
handleLoad() {
|
||||
this.$emit("on-load")
|
||||
},
|
||||
|
||||
handleMessage({data, source}) {
|
||||
if (source !== this.$refs.iframe?.contentWindow) {
|
||||
return;
|
||||
|
||||
@ -132,7 +132,8 @@ export default {
|
||||
},
|
||||
|
||||
previewUrl() {
|
||||
return $A.apiUrl("../fileview/onlinePreview?url=" + encodeURIComponent(this.msgDetail.content.url))
|
||||
const {name, key} = this.msgDetail.content;
|
||||
return $A.apiUrl(`../online/preview/${name}?key=${key}`)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
@ -119,7 +119,8 @@ export default {
|
||||
},
|
||||
|
||||
previewUrl() {
|
||||
return $A.apiUrl("../fileview/onlinePreview?url=" + encodeURIComponent(this.fileDetail.content.url))
|
||||
const {name, key} = this.fileDetail.content;
|
||||
return $A.apiUrl(`../online/preview/${name}?key=${key}`)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user