diff --git a/src/api/system/oss/index.ts b/src/api/system/oss/index.ts index 3b985f7..1abddae 100644 --- a/src/api/system/oss/index.ts +++ b/src/api/system/oss/index.ts @@ -11,6 +11,37 @@ export function listOss(query: OssQuery): AxiosPromise { }); } +export function preview(ossId: string | number): any { + return request({ + url: '/file/preview/' + ossId, + method: 'post', + responseType: 'blob' + }); +} + +export function previewTxt(ossId: string | number): any { + return request({ + url: '/file/preview/' + ossId, + method: 'post', + responseType: 'blob', + transformResponse: [ + async function (data) { + return await transformData(data) + } + ] + }); +} + +const transformData = (data: any) => { + return new Promise((resolve) => { + let reader = new FileReader() + reader.readAsText(data) + reader.onload = function () { + resolve(reader.result) + } + }) +} + // 查询OSS对象基于id串 export function listByIds(ossId: string | number): AxiosPromise { return request({ diff --git a/src/api/system/oss/types.ts b/src/api/system/oss/types.ts index bc0bc1f..c73dd60 100644 --- a/src/api/system/oss/types.ts +++ b/src/api/system/oss/types.ts @@ -9,6 +9,7 @@ export interface OssVO extends BaseEntity { } export interface OssQuery extends PageQuery { + ossId: string | number; fileName: string; originalName: string; fileSuffix: string; diff --git a/src/views/resourceMgt/catalogTextbookMgt/index.vue b/src/views/resourceMgt/catalogTextbookMgt/index.vue index edad25f..cd9c243 100644 --- a/src/views/resourceMgt/catalogTextbookMgt/index.vue +++ b/src/views/resourceMgt/catalogTextbookMgt/index.vue @@ -108,7 +108,22 @@ - + + + + + + +
{{ txt }} +
+ +
@@ -116,16 +131,27 @@