perf: 该文件版本已经改变了。该页面将被重新加载

This commit is contained in:
kuaifan 2022-02-10 20:12:17 +08:00
parent bc3932c8b8
commit 96580e2284
8 changed files with 131 additions and 24 deletions

View File

@ -9,6 +9,7 @@ use App\Models\WebSocketDialog;
use App\Models\WebSocketDialogMsg;
use App\Models\WebSocketDialogMsgRead;
use App\Module\Base;
use Carbon\Carbon;
use Request;
use Response;
@ -349,6 +350,9 @@ class DialogController extends AbstractController
* @apiName msg__detail
*
* @apiParam {Number} msg_id 消息ID
* @apiParam {String} only_update_at 仅获取update_at字段
* - no (默认)
* - yes
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
@ -359,11 +363,20 @@ class DialogController extends AbstractController
User::auth();
//
$msg_id = intval(Request::input('msg_id'));
$only_update_at = Request::input('only_update_at', 'no');
//
$dialogMsg = WebSocketDialogMsg::whereId($msg_id)->first();
if (empty($dialogMsg)) {
return Base::retError("文件不存在");
}
//
if ($only_update_at == 'yes') {
return Base::retSuccess('success', [
'id' => $dialogMsg->id,
'update_at' => Carbon::parse($dialogMsg->updated_at)->toDateTimeString()
]);
}
//
$data = $dialogMsg->toArray();
//
if ($data['type'] == 'file') {

View File

@ -9,12 +9,11 @@ use App\Models\FileContent;
use App\Models\FileLink;
use App\Models\FileUser;
use App\Models\User;
use App\Models\WebSocketDialogMsg;
use App\Module\Base;
use App\Module\Ihttp;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Request;
use Response;
/**
* @apiDefine file
@ -383,7 +382,10 @@ class FileController extends AbstractController
* @apiParam {Number|String} id
* - Number: 文件ID需要登录
* - String: 链接码(不需要登录,用于预览)
* @apiParam {String} down 直接下载
* @apiParam {String} only_update_at 仅获取update_at字段
* - no (默认)
* - yes
* @apiParam {String} down 直接下载
* - no: 浏览(默认)
* - yes: 下载office文件直接下载
*
@ -395,6 +397,7 @@ class FileController extends AbstractController
{
$id = Request::input('id');
$down = Request::input('down', 'no');
$only_update_at = Request::input('only_update_at', 'no');
//
if (Base::isNumber($id)) {
User::auth();
@ -409,6 +412,13 @@ class FileController extends AbstractController
return Base::retError('参数错误');
}
//
if ($only_update_at == 'yes') {
return Base::retSuccess('success', [
'id' => $file->id,
'update_at' => Carbon::parse($file->updated_at)->toDateTimeString()
]);
}
//
$content = FileContent::whereFid($file->id)->orderByDesc('id')->first();
return FileContent::formatContent($file, $content?->content, $down == 'yes');
}

View File

@ -1099,7 +1099,10 @@ class ProjectController extends AbstractController
* @apiGroup project
* @apiName task__filedetail
*
* @apiParam {Number} file_id 文件ID
* @apiParam {Number} file_id 文件ID
* @apiParam {String} only_update_at 仅获取update_at字段
* - no (默认)
* - yes
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
@ -1110,11 +1113,20 @@ class ProjectController extends AbstractController
User::auth();
//
$file_id = intval(Request::input('file_id'));
$only_update_at = Request::input('only_update_at', 'no');
//
$file = ProjectTaskFile::find($file_id);
if (empty($file)) {
return Base::retError("文件不存在");
}
//
if ($only_update_at == 'yes') {
return Base::retSuccess('success', [
'id' => $file->id,
'update_at' => Carbon::parse($file->updated_at)->toDateTimeString()
]);
}
//
$data = $file->toArray();
$data['path'] = $file->getRawOriginal('path');
//

View File

@ -60,6 +60,7 @@ export default {
type: Boolean,
default: false
},
documentKey: Function
},
data() {
@ -91,10 +92,6 @@ export default {
fileName() {
return this.value.name;
},
fileUpdatedAt() {
return this.value.updated_at ? $A.Date(this.value.updated_at, true) : '';
}
},
watch: {
@ -108,8 +105,17 @@ export default {
this.loadIng--;
if (e !== null) {
$A.modalAlert("组件加载失败!");
return;
}
if (!this.documentKey) {
this.handleClose();
return
}
const documentKey = this.documentKey();
if (documentKey && documentKey.then) {
documentKey.then(this.loadFile);
} else {
this.loadFile()
this.loadFile();
}
})
},
@ -130,7 +136,7 @@ export default {
return type;
},
loadFile() {
loadFile(keyAppend = '') {
if (this.docEditor !== null) {
this.docEditor.destroyEditor();
this.docEditor = null;
@ -152,7 +158,7 @@ export default {
const config = {
"document": {
"fileType": this.fileType,
"key": `${this.fileType}-${fileKey}-${this.fileUpdatedAt}`,
"key": `${this.fileType}-${fileKey}-${keyAppend}`,
"title": fileName,
"url": `http://nginx/api/file/content/?id=${fileKey}&token=${this.userToken}`,
},

View File

@ -52,7 +52,7 @@
</template>
<Flow v-else-if="file.type=='flow'" ref="myFlow" v-model="contentDetail" @saveData="handleClick('saveBefore')"/>
<Minder v-else-if="file.type=='mind'" ref="myMind" v-model="contentDetail" @saveData="handleClick('saveBefore')"/>
<OnlyOffice v-else-if="['word', 'excel', 'ppt'].includes(file.type)" v-model="contentDetail"/>
<OnlyOffice v-else-if="['word', 'excel', 'ppt'].includes(file.type)" v-model="contentDetail" :documentKey="documentKey"/>
<AceEditor v-else-if="['code', 'txt'].includes(file.type)" v-model="contentDetail.content" :ext="file.ext" @saveData="handleClick('saveBefore')"/>
</div>
</template>
@ -330,6 +330,22 @@ export default {
this.unsaveTip = false;
},
documentKey() {
return new Promise(resolve => {
this.$store.dispatch("call", {
url: 'file/content',
data: {
id: this.fileId,
only_update_at: 'yes'
},
}).then(({data}) => {
resolve($A.Date(data.update_at, true))
}).catch(() => {
resolve(0)
});
})
},
formatName(file) {
let {name, ext} = file;
if (ext != '') {

View File

@ -29,7 +29,7 @@
</template>
<Flow v-else-if="file.type=='flow'" ref="myFlow" v-model="contentDetail" readOnly/>
<Minder v-else-if="file.type=='mind'" ref="myMind" v-model="contentDetail" readOnly/>
<OnlyOffice v-else-if="['word', 'excel', 'ppt'].includes(file.type)" v-model="contentDetail" :code="code" readOnly/>
<OnlyOffice v-else-if="['word', 'excel', 'ppt'].includes(file.type)" v-model="contentDetail" :code="code" :documentKey="documentKey" readOnly/>
<AceEditor v-else-if="['code', 'txt'].includes(file.type)" v-model="contentDetail.content" :ext="file.ext" readOnly/>
</div>
</template>
@ -144,6 +144,22 @@ export default {
})
},
documentKey() {
return new Promise(resolve => {
this.$store.dispatch("call", {
url: 'file/content',
data: {
id: this.code || this.file.id,
only_update_at: 'yes'
},
}).then(({data}) => {
resolve($A.Date(data.update_at, true))
}).catch(() => {
resolve(0)
});
})
},
exportMenu(act) {
switch (this.file.type) {
case 'mind':

View File

@ -4,7 +4,7 @@
<Loading v-if="loadIng > 0"/>
<template v-else>
<AceEditor v-if="isCode" v-model="codeContent" :ext="codeExt" class="view-editor" readOnly/>
<OnlyOffice v-else-if="isOffice" v-model="officeContent" :code="officeCode" readOnly/>
<OnlyOffice v-else-if="isOffice" v-model="officeContent" :code="officeCode" :documentKey="documentKey" readOnly/>
<iframe v-else-if="isPreview" class="preview-iframe" :src="previewUrl"/>
<div v-else class="no-support">{{$L('不支持单独查看此消息')}}</div>
</template>
@ -68,6 +68,10 @@ export default {
},
},
computed: {
msgId() {
return $A.runNum(this.$route.params.id);
},
title() {
const {msg} = this.msgDetail;
if (msg && msg.name) {
@ -99,7 +103,6 @@ export default {
return {
id: this.isOffice ? this.msgDetail.id : 0,
type: this.msgDetail.msg.ext,
updated_at: this.msgDetail.created_at,
name: this.title,
}
},
@ -122,15 +125,14 @@ export default {
},
methods: {
getInfo() {
let msg_id = $A.runNum(this.$route.params.id);
if (msg_id <= 0) {
if (this.msgId <= 0) {
return;
}
this.loadIng++;
this.$store.dispatch("call", {
url: 'dialog/msg/detail',
data: {
msg_id,
msg_id: this.msgId,
},
}).then(({data}) => {
this.loadIng--;
@ -146,6 +148,21 @@ export default {
}
});
});
},
documentKey() {
return new Promise(resolve => {
this.$store.dispatch("call", {
url: 'dialog/msg/detail',
data: {
msg_id: this.msgId,
only_update_at: 'yes'
},
}).then(({data}) => {
resolve($A.Date(data.update_at, true))
}).catch(() => {
resolve(0)
});
});
}
}
}

View File

@ -4,7 +4,7 @@
<Loading v-if="loadIng > 0"/>
<template v-else>
<AceEditor v-if="isCode" v-model="codeContent" :ext="codeExt" class="view-editor" readOnly/>
<OnlyOffice v-else-if="isOffice" v-model="officeContent" :code="officeCode" readOnly/>
<OnlyOffice v-else-if="isOffice" v-model="officeContent" :code="officeCode" :documentKey="documentKey" readOnly/>
<iframe v-else-if="isPreview" class="preview-iframe" :src="previewUrl"/>
<div v-else class="no-support">{{$L('不支持单独查看此消息')}}</div>
</template>
@ -68,6 +68,10 @@ export default {
},
},
computed: {
fileId() {
return $A.runNum(this.$route.params.id);
},
title() {
const {name} = this.fileDetail;
if (name) {
@ -99,8 +103,7 @@ export default {
return {
id: this.isOffice ? this.fileDetail.id : 0,
type: this.fileDetail.ext,
updated_at: this.fileDetail.created_at,
name: this.title
name: this.title,
}
},
officeCode() {
@ -122,15 +125,14 @@ export default {
},
methods: {
getInfo() {
let file_id = $A.runNum(this.$route.params.id);
if (file_id <= 0) {
if (this.fileId <= 0) {
return;
}
this.loadIng++;
this.$store.dispatch("call", {
url: 'project/task/filedetail',
data: {
file_id,
file_id: this.fileId,
},
}).then(({data}) => {
this.loadIng--;
@ -146,6 +148,21 @@ export default {
}
});
});
},
documentKey() {
return new Promise(resolve => {
this.$store.dispatch("call", {
url: 'project/task/filedetail',
data: {
file_id: this.fileId,
only_update_at: 'yes'
},
}).then(({data}) => {
resolve($A.Date(data.update_at, true))
}).catch(() => {
resolve(0)
});
})
}
}
}