张延森 преди 3 години
родител
ревизия
a0a2b00edd
променени са 5 файла, в които са добавени 68 реда и са изтрити 32 реда
  1. 12
    14
      src/pages/Student/School/Edit/Specialty.jsx
  2. 14
    7
      src/pages/Student/Student/List/index.jsx
  3. 40
    0
      src/utils/download.js
  4. 2
    2
      src/utils/request.js
  5. 0
    9
      src/utils/utils.js

+ 12
- 14
src/pages/Student/School/Edit/Specialty.jsx Целия файл

7
 import SpecialtyModel from './components/SpecialtyModel';
7
 import SpecialtyModel from './components/SpecialtyModel';
8
 
8
 
9
 const Specialty = (props) => {
9
 const Specialty = (props) => {
10
-  console.log(props, 'props');
11
   const [, setLoading] = useState(false);
10
   const [, setLoading] = useState(false);
12
   const [visible, setVisible] = useState(false);
11
   const [visible, setVisible] = useState(false);
13
 
12
 
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
   const columns = [
64
   const columns = [
97
           <Popconfirm
95
           <Popconfirm
98
             key="popconfirm"
96
             key="popconfirm"
99
             title={`确认删除吗?`}
97
             title={`确认删除吗?`}
100
-            onConfirm={() => deleteSchoolClick(record.specialtyId)}
98
+            onConfirm={() => deleteSpecialty(record)}
101
             okText="是"
99
             okText="是"
102
             cancelText="否"
100
             cancelText="否"
103
           >
101
           >

+ 14
- 7
src/pages/Student/Student/List/index.jsx Целия файл

1
 import React, { useCallback, useState } from 'react';
1
 import React, { useCallback, useState } from 'react';
2
 import { history } from 'umi';
2
 import { history } from 'umi';
3
 import { Space } from 'antd';
3
 import { Space } from 'antd';
4
+import moment from 'moment';
4
 import { PageContainer } from '@ant-design/pro-layout';
5
 import { PageContainer } from '@ant-design/pro-layout';
5
 import ProTable from '@ant-design/pro-table';
6
 import ProTable from '@ant-design/pro-table';
6
 import School from '@/components/School';
7
 import School from '@/components/School';
18
   }, []);
19
   }, []);
19
 
20
 
20
   const columns = [
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
       title: '姓名',
30
       title: '姓名',
30
       dataIndex: 'name',
31
       dataIndex: 'name',
67
       dataIndex: 'studentNo',
68
       dataIndex: 'studentNo',
68
       align: 'center',
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
       title: '操作',
78
       title: '操作',
72
       dataIndex: 'action',
79
       dataIndex: 'action',

+ 40
- 0
src/utils/download.js Целия файл

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 Целия файл

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

+ 0
- 9
src/utils/utils.js Целия файл

46
 
46
 
47
 export const defaultAvatar = 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
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
-}