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;
use App\Models\File;
use App\Models\FileContent;
use App\Models\ProjectTask;
use App\Models\ProjectTaskFile;
use App\Models\User;
@ -13,6 +14,7 @@ use App\Models\WebSocketDialogUser;
use App\Module\Base;
use Carbon\Carbon;
use DB;
use Redirect;
use Request;
use Response;
@ -531,7 +533,10 @@ class DialogController extends AbstractController
* @apiGroup dialog
* @apiName msg__download
*
* @apiParam {Number} msg_id 消息ID
* @apiParam {Number} msg_id 消息ID
* @apiParam {String} down 直接下载
* - yes: 下载(默认)
* - preview: 转预览地址
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
@ -542,6 +547,7 @@ class DialogController extends AbstractController
User::auth();
//
$msg_id = intval(Request::input('msg_id'));
$down = Request::input('down', 'yes');
//
$msg = WebSocketDialogMsg::whereId($msg_id)->first();
if (empty($msg)) {
@ -552,6 +558,10 @@ class DialogController extends AbstractController
}
$array = Base::json2array($msg->getRawOriginal('msg'));
//
if ($down === 'preview') {
return Redirect::to(FileContent::toPreviewUrl($array));
}
//
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\Models\AbstractModel;
use App\Models\File;
use App\Models\FileContent;
use App\Models\Project;
use App\Models\ProjectColumn;
use App\Models\ProjectFlow;
@ -22,6 +23,7 @@ use App\Module\BillExport;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Madzipper;
use Redirect;
use Request;
use Response;
use Session;
@ -1306,6 +1308,9 @@ class ProjectController extends AbstractController
* @apiName task__filedown
*
* @apiParam {Number} file_id 文件ID
* @apiParam {String} down 直接下载
* - yes: 下载(默认)
* - preview: 转预览地址
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
@ -1316,6 +1321,7 @@ class ProjectController extends AbstractController
User::auth();
//
$file_id = intval(Request::input('file_id'));
$down = Request::input('down', 'yes');
//
$file = ProjectTaskFile::find($file_id);
if (empty($file)) {
@ -1328,6 +1334,14 @@ class ProjectController extends AbstractController
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);
}

View File

@ -42,22 +42,14 @@ class FileContent extends AbstractModel
/**
* 转预览地址
* @param File $file
* @param $content
* @param array $array
* @return string
*/
public static function formatPreview($file, $content)
public static function toPreviewUrl($array)
{
$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);
}
}
$fileExt = $file->ext;
$fileName = $file->name;
$fileSize = $file->size;
$fileExt = $array['ext'];
$fileName = $array['name'];
$filePath = $array['path'];
if (in_array($fileExt, File::localExt)) {
$url = Base::fillUrl($filePath);
} else {
@ -73,6 +65,28 @@ class FileContent extends AbstractModel
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

View File

@ -124,10 +124,17 @@ export default {
},
fileUrl() {
const codeId = this.code || this.value.id;
let fileUrl = `file/content/?id=${codeId}&token=${this.userToken}`;
if (this.historyId > 0) {
fileUrl += `&history_id=${this.historyId}`
let codeId = this.code || this.value.id;
let fileUrl
if ($A.leftExists(codeId, "msgFile_")) {
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;
},
@ -251,11 +258,6 @@ export default {
if (/\/hideenOfficeTitle\//.test(window.navigator.userAgent)) {
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) {
config.editorConfig.mode = "view";
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/>
</template>
<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>
</template>
</div>
</template>
<style lang="scss" scoped>
<style lang="scss">
.single-file-msg {
display: flex;
align-items: center;
@ -43,6 +43,11 @@
float: none;
max-width: none;
}
.teditor-wrapper {
.teditor-box {
height: 100%;
}
}
.view-code {
white-space: pre-wrap;
word-wrap: break-word;
@ -56,20 +61,12 @@
}
}
</style>
<style lang="scss">
.single-file-msg {
.teditor-wrapper {
.teditor-box {
height: 100%;
}
}
}
</style>
<script>
import Vue from 'vue'
import Minder from '../../components/Minder'
import {textMsgFormat} from "../../functions/utils";
import {mapState} from "vuex";
import IFrame from "../manage/components/IFrame";
Vue.use(Minder)
const MDPreview = () => import('../../components/MDEditor/preview');
@ -79,7 +76,7 @@ const OnlyOffice = () => import('../../components/OnlyOffice');
const Drawio = () => import('../../components/Drawio');
export default {
components: {AceEditor, TEditor, MDPreview, OnlyOffice, Drawio},
components: {IFrame, AceEditor, TEditor, MDPreview, OnlyOffice, Drawio},
data() {
return {
loadIng: 0,

View File

@ -9,13 +9,13 @@
<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/>
<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>
</template>
</div>
</template>
<style lang="scss" scoped>
<style lang="scss">
.single-file-task {
display: flex;
align-items: center;
@ -39,6 +39,11 @@
float: none;
max-width: none;
}
.teditor-wrapper {
.teditor-box {
height: 100%;
}
}
.view-editor,
.no-support {
display: flex;
@ -47,18 +52,10 @@
}
}
</style>
<style lang="scss">
.single-file-task {
.teditor-wrapper {
.teditor-box {
height: 100%;
}
}
}
</style>
<script>
import Vue from 'vue'
import Minder from '../../components/Minder'
import IFrame from "../manage/components/IFrame";
Vue.use(Minder)
const MDPreview = () => import('../../components/MDEditor/preview');
@ -68,7 +65,7 @@ const OnlyOffice = () => import('../../components/OnlyOffice');
const Drawio = () => import('../../components/Drawio');
export default {
components: {AceEditor, TEditor, MDPreview, OnlyOffice, Drawio},
components: {IFrame, AceEditor, TEditor, MDPreview, OnlyOffice, Drawio},
data() {
return {
loadIng: 0,