wuheng 1 year ago
parent
commit
81bbb51ece

+ 9 - 0
src/views/archives/students/component/api.ts

@@ -113,3 +113,12 @@ export function addArchives(params: AddArchivesParams): Promise<Service.RequestR
 export function deleteArchives(id: number): Promise<Service.RequestResult<ArchivesRes>> {
 export function deleteArchives(id: number): Promise<Service.RequestResult<ArchivesRes>> {
   return request.delete(`/student/delArchives/${id}`);
   return request.delete(`/student/delArchives/${id}`);
 }
 }
+
+/**
+ * 下载学员档案
+ * @param {string} studentNumber
+ * @returns
+ */
+export function downloadArchives(studentNumber: string): Promise<Service.RequestResult<ArchivesRes>> {
+  return request.post(`/student/downloadArchives?studentNumber=${studentNumber}`);
+}

+ 24 - 2
src/views/archives/students/component/crud.ts

@@ -5,7 +5,7 @@ import { dict } from '@fast-crud/fast-crud';
 import axios from 'axios';
 import axios from 'axios';
 import { getServiceEnvConfig } from '~/.env-config';
 import { getServiceEnvConfig } from '~/.env-config';
 import type { AddArchivesParams } from './api';
 import type { AddArchivesParams } from './api';
-import { getArchives, getFile, addArchives, deleteArchives } from './api';
+import { getArchives, getFile, addArchives, deleteArchives, downloadArchives } from './api';
 const { url, proxyPattern } = getServiceEnvConfig(import.meta.env);
 const { url, proxyPattern } = getServiceEnvConfig(import.meta.env);
 const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === 'Y';
 const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === 'Y';
 export default function createCrudOptions(crudOptionsProps: CreateCrudOptionsProps): CreateCrudOptionsRet {
 export default function createCrudOptions(crudOptionsProps: CreateCrudOptionsProps): CreateCrudOptionsRet {
@@ -84,7 +84,29 @@ export default function createCrudOptions(crudOptionsProps: CreateCrudOptionsPro
         show: false
         show: false
       },
       },
       actionbar: {
       actionbar: {
-        show: true
+        show: true,
+        buttons: {
+          download: {
+            text: '打包下载档案',
+            title: '下载当前学员所有档案',
+            circle: false,
+            tooltip: {
+              slots: {
+                default() {
+                  return '下载当前学员所有档案';
+                }
+              }
+            },
+            click: async () => {
+              if (!crudOptionsProps.context) {
+                return;
+              }
+              const { data } = await downloadArchives(crudOptionsProps.context.studentNumber);
+              const fileUrl = `http://localhost:3200/proxy-pattern/archive/getFileByToken?archiveToken=${data}`;
+              window.location.href = fileUrl;
+            }
+          }
+        }
       },
       },
       form: {
       form: {
         wrapper: {
         wrapper: {

+ 13 - 3
src/views/archives/students/component/index.vue

@@ -21,7 +21,10 @@
         <ImageView v-else-if="fileType === 'IMAGE'" :url="fileURL" />
         <ImageView v-else-if="fileType === 'IMAGE'" :url="fileURL" />
         <PdfView v-else-if="fileType === 'PDF'" :url="fileURL" />
         <PdfView v-else-if="fileType === 'PDF'" :url="fileURL" />
         <div v-else :url="fileURL">
         <div v-else :url="fileURL">
-          <h1>当前文件不支持预览, 请下载后查看</h1>
+          <div class="other-file">
+            <h1>当前文件不支持预览, 请下载后查看</h1>
+            <n-button type="primary" dashed @click="downloadFiles"> 点击我下载当前文件 </n-button>
+          </div>
         </div>
         </div>
       </n-drawer-content>
       </n-drawer-content>
     </n-drawer>
     </n-drawer>
@@ -59,7 +62,9 @@ const context = {
     active.value = true;
     active.value = true;
   }
   }
 };
 };
-
+function downloadFiles() {
+  window.location.href = fileURL.value;
+}
 const { crudRef, crudBinding, crudExpose } = useFs({ createCrudOptions, context });
 const { crudRef, crudBinding, crudExpose } = useFs({ createCrudOptions, context });
 watch(
 watch(
   () => props.studentNumber,
   () => props.studentNumber,
@@ -72,4 +77,9 @@ watch(
   }
   }
 );
 );
 </script>
 </script>
-<style scoped lang="scss"></style>
+<style scoped lang="scss">
+.other-file {
+  margin-top: 30%;
+  font-size: 30px;
+}
+</style>