From 7a3b86d2c63fa3698f6860487817c5e5ace07dfe Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 11 九月 2024 22:25:24 +0800
Subject: [PATCH] 2024-09-11

---
 src/menu/datasource/verifycard/excelout/index.jsx  |   76 ++++++++++++++++++++++++++++++++++++++
 src/menu/datasource/verifycard/excelout/index.scss |    0 
 src/menu/datasource/verifycard/index.scss          |   23 +++++++++++
 src/menu/datasource/verifycard/index.jsx           |    4 ++
 4 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/src/menu/datasource/verifycard/excelout/index.jsx b/src/menu/datasource/verifycard/excelout/index.jsx
new file mode 100644
index 0000000..32adf68
--- /dev/null
+++ b/src/menu/datasource/verifycard/excelout/index.jsx
@@ -0,0 +1,76 @@
+import React, { Component } from 'react'
+import { notification } from 'antd'
+import * as XLSX from 'sheetjs-style'
+import { DownloadOutlined } from '@ant-design/icons'
+import moment from 'moment'
+
+// import './index.scss'
+
+class ExcelOutColumns extends Component {
+  /**
+   * @description 瀵煎嚭瀛楁闆�
+   */
+  actionTrigger = () => {
+    const { data, setting } = this.props
+
+    if (data.length === 0) {
+      notification.warning({
+        top: 92,
+        message: '瀛楁闆嗕笉鍙负绌猴紒',
+        duration: 5
+      })
+      return
+    }
+
+    let columns = [{
+      Column: 'label',
+      Text: '鍚嶇О'
+    }, {
+      Column: 'field',
+      Text: '瀛楁'
+    }, {
+      Column: 'datatype',
+      Text: '鏁版嵁绫诲瀷'
+    }]
+    
+    let table = []
+    let _header = []
+    let _topRow = {}
+    let colwidth = []
+
+    columns.forEach(col => {
+      _header.push(col.Column)
+      _topRow[col.Column] = col.Text
+      colwidth.push({wch: 25})
+    })
+
+    table.push(_topRow)
+
+    data.forEach((item) => {
+      let _row = {}
+
+      columns.forEach((col) => {
+        let val = item[col.Column]
+        _row[col.Column] = val
+      })
+
+      table.push(_row)
+    })
+
+    const ws = XLSX.utils.json_to_sheet(table, {header: _header, skipHeader: true})
+
+    ws['!cols'] = colwidth
+    ws['!rows'] = Array(table.length).fill({hpx: 18})
+
+    const wb = XLSX.utils.book_new()
+    XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
+
+    XLSX.writeFile(wb, `${setting.tableName || ''}${moment().format('YYYYMMDDHHmmss')}.xlsx`)
+  }
+
+  render() {
+    return (<DownloadOutlined className="columns-out" onClick={this.actionTrigger}/>)
+  }
+}
+
+export default ExcelOutColumns
\ No newline at end of file
diff --git a/src/menu/datasource/verifycard/excelout/index.scss b/src/menu/datasource/verifycard/excelout/index.scss
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/menu/datasource/verifycard/excelout/index.scss
diff --git a/src/menu/datasource/verifycard/index.jsx b/src/menu/datasource/verifycard/index.jsx
index c7c6806..a2f6111 100644
--- a/src/menu/datasource/verifycard/index.jsx
+++ b/src/menu/datasource/verifycard/index.jsx
@@ -23,6 +23,7 @@
 const { Search } = Input
 const { confirm } = Modal
 
+const ExcelOut = asyncComponent(() => import('./excelout'))
 const CodeMirror = asyncComponent(() => import('@/templates/zshare/codemirror'))
 const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
 const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
@@ -1232,6 +1233,7 @@
               type="fields"
               updatefield={this.updatefields}
             />
+            <ExcelOut data={columns} setting={setting}/>
             <EditTable actions={['edit', 'move', 'copy', 'del', 'clear']} searchKey={searchKey} type="datasourcefield" wrappedComponentRef={(inst) => this.datasource = inst} data={columns} columns={colColumns} onChange={(columns) => this.setState({columns})}/>
           </TabPane> : <TabPane tab={
             <span>
@@ -1240,6 +1242,7 @@
             </span>
           } key="columns">
             <div className="base-table-columns"></div>
+            <ExcelOut data={columns} setting={setting}/>
             <EditTable actions={[]} searchKey={searchKey} type="datasourcefield" data={columns} columns={colColumns}/>
           </TabPane>}
           {config.subtype === 'dualdatacard' ? <TabPane tab={
@@ -1254,6 +1257,7 @@
               type="fields"
               updatefield={this.updateSubfields}
             />
+            <ExcelOut data={subColumns} setting={setting}/>
             <EditTable actions={['edit', 'move', 'copy', 'del', 'clear']} searchKey={searchKey} type="datasourcefield" wrappedComponentRef={(inst) => this.subdatasource = inst} data={subColumns} columns={colColumns} onChange={(subColumns) => this.setState({subColumns})}/>
           </TabPane> : null}
           <TabPane tab={
diff --git a/src/menu/datasource/verifycard/index.scss b/src/menu/datasource/verifycard/index.scss
index 308bfb9..3239de2 100644
--- a/src/menu/datasource/verifycard/index.scss
+++ b/src/menu/datasource/verifycard/index.scss
@@ -146,6 +146,29 @@
       margin-right: 5px;
       cursor: pointer;
     }
+    .columns-out {
+      float: right;
+      position: relative;
+      z-index: 2;
+      right: 5px;
+      height: 0px;
+      top: -15px;
+      color: rgb(24, 144, 255);
+    }
+    .columns-out + .modal-edit-table {
+      .ant-table-thead {
+        .copy-control {
+          top: -18px;
+          right: 30px;
+          .anticon-copy {
+            margin-right: 12px;
+          }
+          .anticon-delete {
+            margin-left: 12px;
+          }
+        }
+      }
+    }
   }
   .full-scripts {
     position: absolute;

--
Gitblit v1.8.0