no message

This commit is contained in:
kuaifan 2022-06-11 22:55:47 +08:00
parent 2dbdc3b780
commit 0150b41e17
6 changed files with 81 additions and 47 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Models\File; use App\Models\File;
use App\Models\FileContent;
use App\Models\ProjectTask; use App\Models\ProjectTask;
use App\Models\ProjectTaskFile; use App\Models\ProjectTaskFile;
use App\Models\User; use App\Models\User;
@ -13,6 +14,7 @@ use App\Models\WebSocketDialogUser;
use App\Module\Base; use App\Module\Base;
use Carbon\Carbon; use Carbon\Carbon;
use DB; use DB;
use Redirect;
use Request; use Request;
use Response; use Response;
@ -531,7 +533,10 @@ class DialogController extends AbstractController
* @apiGroup dialog * @apiGroup dialog
* @apiName msg__download * @apiName msg__download
* *
* @apiParam {Number} msg_id 消息ID * @apiParam {Number} msg_id 消息ID
* @apiParam {String} down 直接下载
* - yes: 下载(默认)
* - preview: 转预览地址
* *
* @apiSuccess {Number} ret 返回状态码1正确、0错误 * @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述) * @apiSuccess {String} msg 返回信息(错误描述)
@ -542,6 +547,7 @@ class DialogController extends AbstractController
User::auth(); User::auth();
// //
$msg_id = intval(Request::input('msg_id')); $msg_id = intval(Request::input('msg_id'));
$down = Request::input('down', 'yes');
// //
$msg = WebSocketDialogMsg::whereId($msg_id)->first(); $msg = WebSocketDialogMsg::whereId($msg_id)->first();
if (empty($msg)) { if (empty($msg)) {
@ -552,6 +558,10 @@ class DialogController extends AbstractController
} }
$array = Base::json2array($msg->getRawOriginal('msg')); $array = Base::json2array($msg->getRawOriginal('msg'));
// //
if ($down === 'preview') {
return Redirect::to(FileContent::toPreviewUrl($array));
}
//
return Response::download(public_path($array['path']), $array['name']); return Response::download(public_path($array['path']), $array['name']);
} }

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
use App\Exceptions\ApiException; use App\Exceptions\ApiException;
use App\Models\AbstractModel; use App\Models\AbstractModel;
use App\Models\File; use App\Models\File;
use App\Models\FileContent;
use App\Models\Project; use App\Models\Project;
use App\Models\ProjectColumn; use App\Models\ProjectColumn;
use App\Models\ProjectFlow; use App\Models\ProjectFlow;
@ -22,6 +23,7 @@ use App\Module\BillExport;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Madzipper; use Madzipper;
use Redirect;
use Request; use Request;
use Response; use Response;
use Session; use Session;
@ -1306,6 +1308,9 @@ class ProjectController extends AbstractController
* @apiName task__filedown * @apiName task__filedown
* *
* @apiParam {Number} file_id 文件ID * @apiParam {Number} file_id 文件ID
* @apiParam {String} down 直接下载
* - yes: 下载(默认)
* - preview: 转预览地址
* *
* @apiSuccess {Number} ret 返回状态码1正确、0错误 * @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述) * @apiSuccess {String} msg 返回信息(错误描述)
@ -1316,6 +1321,7 @@ class ProjectController extends AbstractController
User::auth(); User::auth();
// //
$file_id = intval(Request::input('file_id')); $file_id = intval(Request::input('file_id'));
$down = Request::input('down', 'yes');
// //
$file = ProjectTaskFile::find($file_id); $file = ProjectTaskFile::find($file_id);
if (empty($file)) { if (empty($file)) {
@ -1328,6 +1334,14 @@ class ProjectController extends AbstractController
abort(403, $e->getMessage() ?: "This file not support download."); abort(403, $e->getMessage() ?: "This file not support download.");
} }
// //
if ($down === 'preview') {
return Redirect::to(FileContent::toPreviewUrl([
'ext' => $file->ext,
'name' => $file->name,
'path' => $file->getRawOriginal('path'),
]));
}
//
return Response::download(public_path($file->getRawOriginal('path')), $file->name); return Response::download(public_path($file->getRawOriginal('path')), $file->name);
} }

View File

@ -42,22 +42,14 @@ class FileContent extends AbstractModel
/** /**
* 转预览地址 * 转预览地址
* @param File $file * @param array $array
* @param $content
* @return string * @return string
*/ */
public static function formatPreview($file, $content) public static function toPreviewUrl($array)
{ {
$content = Base::json2array($content ?: []); $fileExt = $array['ext'];
$filePath = $content['url']; $fileName = $array['name'];
if (in_array($file->type, ['word', 'excel', 'ppt'])) { $filePath = $array['path'];
if (empty($content)) {
$filePath = 'assets/office/empty.' . str_replace(['word', 'excel', 'ppt'], ['docx', 'xlsx', 'pptx'], $file->type);
}
}
$fileExt = $file->ext;
$fileName = $file->name;
$fileSize = $file->size;
if (in_array($fileExt, File::localExt)) { if (in_array($fileExt, File::localExt)) {
$url = Base::fillUrl($filePath); $url = Base::fillUrl($filePath);
} else { } else {
@ -73,6 +65,28 @@ class FileContent extends AbstractModel
return Base::fillUrl("fileview/onlinePreview?url=" . urlencode(base64_encode($url))); return Base::fillUrl("fileview/onlinePreview?url=" . urlencode(base64_encode($url)));
} }
/**
* 转预览地址
* @param File $file
* @param $content
* @return string
*/
public static function formatPreview($file, $content)
{
$content = Base::json2array($content ?: []);
$filePath = $content['url'];
if (in_array($file->type, ['word', 'excel', 'ppt'])) {
if (empty($content)) {
$filePath = 'assets/office/empty.' . str_replace(['word', 'excel', 'ppt'], ['docx', 'xlsx', 'pptx'], $file->type);
}
}
return self::toPreviewUrl([
'ext' => $file->ext,
'name' => $file->name,
'path' => $filePath,
]);
}
/** /**
* 获取格式内容(或下载) * 获取格式内容(或下载)
* @param File $file * @param File $file

View File

@ -124,10 +124,17 @@ export default {
}, },
fileUrl() { fileUrl() {
const codeId = this.code || this.value.id; let codeId = this.code || this.value.id;
let fileUrl = `file/content/?id=${codeId}&token=${this.userToken}`; let fileUrl
if (this.historyId > 0) { if ($A.leftExists(codeId, "msgFile_")) {
fileUrl += `&history_id=${this.historyId}` fileUrl = `dialog/msg/download/?msg_id=${$A.leftDelete(codeId, "msgFile_")}&token=${this.userToken}`;
} else if ($A.leftExists(codeId, "taskFile_")) {
fileUrl = `project/task/filedown/?file_id=${$A.leftDelete(codeId, "taskFile_")}&token=${this.userToken}`;
} else {
fileUrl = `file/content/?id=${codeId}&token=${this.userToken}`;
if (this.historyId > 0) {
fileUrl += `&history_id=${this.historyId}`
}
} }
return fileUrl; return fileUrl;
}, },
@ -251,11 +258,6 @@ export default {
if (/\/hideenOfficeTitle\//.test(window.navigator.userAgent)) { if (/\/hideenOfficeTitle\//.test(window.navigator.userAgent)) {
config.document.title = " "; config.document.title = " ";
} }
if ($A.leftExists(codeId, "msgFile_")) {
config.document.url = `http://nginx/api/dialog/msg/download/?msg_id=${$A.leftDelete(codeId, "msgFile_")}&token=${this.userToken}`;
} else if ($A.leftExists(codeId, "taskFile_")) {
config.document.url = `http://nginx/api/project/task/filedown/?file_id=${$A.leftDelete(codeId, "taskFile_")}&token=${this.userToken}`;
}
if (this.readOnly || this.historyId > 0) { if (this.readOnly || this.historyId > 0) {
config.editorConfig.mode = "view"; config.editorConfig.mode = "view";
config.editorConfig.callbackUrl = null; config.editorConfig.callbackUrl = null;

View File

@ -12,13 +12,13 @@
<AceEditor v-else v-model="msgDetail.content.content" :ext="msgDetail.msg.ext" class="view-editor" readOnly/> <AceEditor v-else v-model="msgDetail.content.content" :ext="msgDetail.msg.ext" class="view-editor" readOnly/>
</template> </template>
<OnlyOffice v-else-if="isType('office')" v-model="officeContent" :code="officeCode" :documentKey="documentKey" readOnly/> <OnlyOffice v-else-if="isType('office')" v-model="officeContent" :code="officeCode" :documentKey="documentKey" readOnly/>
<iframe v-else-if="isType('preview')" class="preview-iframe" :src="previewUrl"/> <IFrame v-else-if="isType('preview')" class="preview-iframe" :src="previewUrl"/>
<div v-else class="no-support">{{$L('不支持单独查看此消息')}}</div> <div v-else class="no-support">{{$L('不支持单独查看此消息')}}</div>
</template> </template>
</div> </div>
</template> </template>
<style lang="scss" scoped> <style lang="scss">
.single-file-msg { .single-file-msg {
display: flex; display: flex;
align-items: center; align-items: center;
@ -43,6 +43,11 @@
float: none; float: none;
max-width: none; max-width: none;
} }
.teditor-wrapper {
.teditor-box {
height: 100%;
}
}
.view-code { .view-code {
white-space: pre-wrap; white-space: pre-wrap;
word-wrap: break-word; word-wrap: break-word;
@ -56,20 +61,12 @@
} }
} }
</style> </style>
<style lang="scss">
.single-file-msg {
.teditor-wrapper {
.teditor-box {
height: 100%;
}
}
}
</style>
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import Minder from '../../components/Minder' import Minder from '../../components/Minder'
import {textMsgFormat} from "../../functions/utils"; import {textMsgFormat} from "../../functions/utils";
import {mapState} from "vuex"; import {mapState} from "vuex";
import IFrame from "../manage/components/IFrame";
Vue.use(Minder) Vue.use(Minder)
const MDPreview = () => import('../../components/MDEditor/preview'); const MDPreview = () => import('../../components/MDEditor/preview');
@ -79,7 +76,7 @@ const OnlyOffice = () => import('../../components/OnlyOffice');
const Drawio = () => import('../../components/Drawio'); const Drawio = () => import('../../components/Drawio');
export default { export default {
components: {AceEditor, TEditor, MDPreview, OnlyOffice, Drawio}, components: {IFrame, AceEditor, TEditor, MDPreview, OnlyOffice, Drawio},
data() { data() {
return { return {
loadIng: 0, loadIng: 0,

View File

@ -9,13 +9,13 @@
<Minder v-else-if="isType('mind')" :value="fileDetail.content" readOnly/> <Minder v-else-if="isType('mind')" :value="fileDetail.content" readOnly/>
<AceEditor v-else-if="isType('code')" v-model="fileDetail.content.content" :ext="fileDetail.ext" class="view-editor" readOnly/> <AceEditor v-else-if="isType('code')" v-model="fileDetail.content.content" :ext="fileDetail.ext" class="view-editor" readOnly/>
<OnlyOffice v-else-if="isType('office')" v-model="officeContent" :code="officeCode" :documentKey="documentKey" readOnly/> <OnlyOffice v-else-if="isType('office')" v-model="officeContent" :code="officeCode" :documentKey="documentKey" readOnly/>
<iframe v-else-if="isType('preview')" class="preview-iframe" :src="previewUrl"/> <IFrame v-else-if="isType('preview')" class="preview-iframe" :src="previewUrl"/>
<div v-else class="no-support">{{$L('不支持单独查看此消息')}}</div> <div v-else class="no-support">{{$L('不支持单独查看此消息')}}</div>
</template> </template>
</div> </div>
</template> </template>
<style lang="scss" scoped> <style lang="scss">
.single-file-task { .single-file-task {
display: flex; display: flex;
align-items: center; align-items: center;
@ -39,6 +39,11 @@
float: none; float: none;
max-width: none; max-width: none;
} }
.teditor-wrapper {
.teditor-box {
height: 100%;
}
}
.view-editor, .view-editor,
.no-support { .no-support {
display: flex; display: flex;
@ -47,18 +52,10 @@
} }
} }
</style> </style>
<style lang="scss">
.single-file-task {
.teditor-wrapper {
.teditor-box {
height: 100%;
}
}
}
</style>
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import Minder from '../../components/Minder' import Minder from '../../components/Minder'
import IFrame from "../manage/components/IFrame";
Vue.use(Minder) Vue.use(Minder)
const MDPreview = () => import('../../components/MDEditor/preview'); const MDPreview = () => import('../../components/MDEditor/preview');
@ -68,7 +65,7 @@ const OnlyOffice = () => import('../../components/OnlyOffice');
const Drawio = () => import('../../components/Drawio'); const Drawio = () => import('../../components/Drawio');
export default { export default {
components: {AceEditor, TEditor, MDPreview, OnlyOffice, Drawio}, components: {IFrame, AceEditor, TEditor, MDPreview, OnlyOffice, Drawio},
data() { data() {
return { return {
loadIng: 0, loadIng: 0,