张延森 3 anni fa
parent
commit
a0a2b00edd

+ 12
- 14
src/pages/Student/School/Edit/Specialty.jsx Vedi File

@@ -7,7 +7,6 @@ import request, { queryTable } from '@/utils/request';
7 7
 import SpecialtyModel from './components/SpecialtyModel';
8 8
 
9 9
 const Specialty = (props) => {
10
-  console.log(props, 'props');
11 10
   const [, setLoading] = useState(false);
12 11
   const [visible, setVisible] = useState(false);
13 12
 
@@ -49,18 +48,17 @@ const Specialty = (props) => {
49 48
   //       });
50 49
   //   };
51 50
 
52
-  const deleteSchoolClick = () => {
53
-
54
-    ref.current.reload();
55
-    //   request(`/specialty/${id}`, { method: 'delete' })
56
-    //     .then(() => {
57
-    //       notification.success({ message: '删除成功' });
58
-    //       ref.current.submit();
59
-    //     })
60
-    //     .catch((e) => {
61
-
62
-    //       notification.error({ message: e.message });
63
-    //     });
51
+  const deleteSpecialty = (record) => {
52
+    const { specialtyId } = record
53
+    
54
+    request(`/specialty/${specialtyId}`, { method: 'delete' })
55
+      .then(() => {
56
+        notification.success({ message: '删除成功' });
57
+        ref.current.reload();
58
+      })
59
+      .catch((e) => {
60
+        notification.error({ message: e.message });
61
+      });
64 62
   };
65 63
 
66 64
   const columns = [
@@ -97,7 +95,7 @@ const Specialty = (props) => {
97 95
           <Popconfirm
98 96
             key="popconfirm"
99 97
             title={`确认删除吗?`}
100
-            onConfirm={() => deleteSchoolClick(record.specialtyId)}
98
+            onConfirm={() => deleteSpecialty(record)}
101 99
             okText="是"
102 100
             cancelText="否"
103 101
           >

+ 14
- 7
src/pages/Student/Student/List/index.jsx Vedi File

@@ -1,6 +1,7 @@
1 1
 import React, { useCallback, useState } from 'react';
2 2
 import { history } from 'umi';
3 3
 import { Space } from 'antd';
4
+import moment from 'moment';
4 5
 import { PageContainer } from '@ant-design/pro-layout';
5 6
 import ProTable from '@ant-design/pro-table';
6 7
 import School from '@/components/School';
@@ -18,13 +19,13 @@ const StudentList = () => {
18 19
   }, []);
19 20
 
20 21
   const columns = [
21
-    {
22
-      title: '编号',
23
-      dataIndex: 'studentId',
24
-      align: 'center',
25
-      width: 300,
26
-      hideInSearch: true,
27
-    },
22
+    // {
23
+    //   title: '编号',
24
+    //   dataIndex: 'studentId',
25
+    //   align: 'center',
26
+    //   width: 300,
27
+    //   hideInSearch: true,
28
+    // },
28 29
     {
29 30
       title: '姓名',
30 31
       dataIndex: 'name',
@@ -67,6 +68,12 @@ const StudentList = () => {
67 68
       dataIndex: 'studentNo',
68 69
       align: 'center',
69 70
     },
71
+    {
72
+      title: '注册时间',
73
+      dataIndex: 'createDate',
74
+      align: 'center',
75
+      render: t => moment(t).format('YYYY-MM-DD HH:mm')
76
+    },
70 77
     {
71 78
       title: '操作',
72 79
       dataIndex: 'action',

+ 40
- 0
src/utils/download.js Vedi File

@@ -0,0 +1,40 @@
1
+
2
+/**
3
+ * 获取 query string
4
+ * @param {*} params 
5
+ * @returns string
6
+ */
7
+function getQueryString(params) {
8
+  if (!params) return ;
9
+
10
+  const keys = Object.keys(params)
11
+  const arr = keys.map((key) => {
12
+    const val = params[key]
13
+    if (val === null || val === undefined) return false;
14
+
15
+    return `${key}=${encodeURIComponent(val)}`
16
+  })
17
+
18
+  // eslint-disable-next-line consistent-return
19
+  return arr.filter(Boolean).join('&')
20
+}
21
+
22
+export function fetchBlob(url, opt) {
23
+  const { params, ...initArgs } = opt || {}
24
+  const resource = params ? `${url}?${getQueryString(params)}` : url
25
+
26
+  return window.fetch(resource, initArgs).then(response => response.blob())
27
+}
28
+
29
+export function downloadBlob(fileName, blob) {
30
+  const url = window.URL.createObjectURL(blob);
31
+  const link = document.createElement('a');
32
+  link.href = url;
33
+  link.setAttribute('download', fileName);
34
+  link.click();
35
+  window.URL.revokeObjectURL(url);
36
+}
37
+
38
+export function downloadUrl(fileName, url, opt) {
39
+  return fetchBlob(url, opt).then(blob => downloadBlob(fileName, blob))
40
+};

+ 2
- 2
src/utils/request.js Vedi File

@@ -1,7 +1,7 @@
1 1
 /** Request 网络请求工具 更详细的 api 文档: https://github.com/umijs/umi-request */
2 2
 import { extend } from 'umi-request';
3 3
 import { notification } from 'antd';
4
-import { downloadFile } from './utils'
4
+import { downloadBlob } from './download';
5 5
 
6 6
 const codeMessage = {
7 7
   200: '服务器成功返回请求的数据。',
@@ -88,7 +88,7 @@ request.interceptors.response.use(async (response) => {
88 88
     const data = await response.clone().blob();
89 89
     const content = response.headers.get('content-disposition');
90 90
     const fileName = content.replace('attachment;filename=', '')
91
-    downloadFile(data, decodeURIComponent(fileName))
91
+    downloadBlob(decodeURIComponent(fileName), data)
92 92
   }
93 93
 
94 94
   return response;

+ 0
- 9
src/utils/utils.js Vedi File

@@ -46,12 +46,3 @@ export function getCurrentRoute(pathname) {
46 46
 
47 47
 export const defaultAvatar = 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
48 48
 
49
-export function downloadFile(data, fileName) {
50
-  const url = window.URL.createObjectURL(new Blob([data]))
51
-  const link = document.createElement('a')
52
-  link.style.display = 'none'
53
-  link.href = url
54
-  link.setAttribute('download', fileName)
55
-  document.body.append(link)
56
-  link.click()
57
-}