Record.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import * as React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import { IconButton } from './button';
  4. import ReturnIcon from "../icons/return.svg";
  5. import Excel from 'js-export-excel';
  6. const RecordApp: React.FC = () => {
  7. const [account, setAccount] = React.useState('');
  8. const [password, setPassword] = React.useState('');
  9. // 点击导出
  10. const onClickExport = async (data: { account: string, password: string }) => {
  11. if (data.account && data.password) {
  12. if (data.account === 'root' && password === 'root@2024') {
  13. const res = await fetch('/api/bigModel');
  14. const {data} = await res.json()
  15. // 导出数据到Excel
  16. const option = {
  17. fileName: '聊天记录',
  18. datas: [{
  19. sheetData: data,
  20. sheetName: '聊天记录',
  21. }],
  22. };
  23. // 使用Excel构造函数导出数据
  24. const excel = new Excel(option);
  25. excel.saveExcel();
  26. } else {
  27. alert('账号密码不正确');
  28. }
  29. } else {
  30. alert('请输入账号密码');
  31. }
  32. }
  33. return (
  34. <div>
  35. <div style={{ padding: '14px 20px', borderBottom: '1px solid rgba(0, 0, 0, 0.1)', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
  36. <div>
  37. <div style={{ fontSize: 20, fontWeight: 'bolder' }}>
  38. 建科招聘聊天记录
  39. </div>
  40. <div style={{ fontSize: 14 }}>
  41. 输入账号密码导出聊天记录
  42. </div>
  43. </div>
  44. <div>
  45. <Link to='/'>
  46. <IconButton
  47. icon={<ReturnIcon />}
  48. bordered
  49. title='返回'
  50. aria='返回'
  51. />
  52. </Link>
  53. </div>
  54. </div>
  55. <div style={{ width: '100%', padding: '20px 0', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  56. <input
  57. style={{ width: '50%' }}
  58. type="text"
  59. placeholder="请输入账号"
  60. value={account}
  61. onChange={(e) => {
  62. const value = e.target.value;
  63. setAccount(value);
  64. }}
  65. />
  66. <input
  67. style={{ width: '50%', margin: '20px 0' }}
  68. type="password"
  69. placeholder="请输入密码"
  70. value={password}
  71. onChange={(e) => {
  72. const value = e.target.value;
  73. setPassword(value);
  74. }}
  75. />
  76. <button
  77. style={{
  78. width: '50%',
  79. border: '1px solid rgba(0, 0, 0, 0.1)',
  80. backgroundColor: '#FFFFFF',
  81. borderRadius: '10px',
  82. height: 36,
  83. cursor: 'pointer'
  84. }}
  85. onClick={async () => {
  86. await onClickExport({
  87. account: account,
  88. password: password,
  89. })
  90. }}
  91. >
  92. 导出
  93. </button>
  94. </div>
  95. </div>
  96. );
  97. };
  98. export default RecordApp;