Record.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 getChatRecords = () => {
  11. const records = [
  12. { id: 1, timestamp: '2024-08-15 10:00:00', message: '你好,欢迎来到建科招聘!' },
  13. { id: 2, timestamp: '2024-08-15 10:01:00', message: '请问有什么可以帮助您的?' },
  14. { id: 3, timestamp: '2024-08-15 10:02:00', message: '我想了解关于软件工程师的职位详情。' },
  15. ];
  16. return records;
  17. };
  18. // 点击导出
  19. const onClickExport = async (data: { account: string, password: string }) => {
  20. if (data.account && data.password) {
  21. if (data.account === 'root' && password === 'root@2024') {
  22. // const res = await fetch('/api/bigModel');
  23. // 模拟获取数据
  24. const res = getChatRecords();
  25. // 导出数据到Excel
  26. const option = {
  27. fileName: '聊天记录',
  28. datas: [{
  29. sheetData: res,
  30. sheetName: '聊天记录',
  31. }],
  32. };
  33. // 使用Excel构造函数导出数据
  34. const excel = new Excel(option);
  35. excel.saveExcel();
  36. } else {
  37. alert('账号密码不正确');
  38. }
  39. } else {
  40. alert('请输入账号密码');
  41. }
  42. }
  43. return (
  44. <div>
  45. <div style={{ padding: '14px 20px', borderBottom: '1px solid rgba(0, 0, 0, 0.1)', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
  46. <div>
  47. <div style={{ fontSize: 20, fontWeight: 'bolder' }}>
  48. 建科招聘聊天记录
  49. </div>
  50. <div style={{ fontSize: 14 }}>
  51. 输入账号密码导出聊天记录
  52. </div>
  53. </div>
  54. <div>
  55. <Link to='/'>
  56. <IconButton
  57. icon={<ReturnIcon />}
  58. bordered
  59. title='返回'
  60. aria='返回'
  61. />
  62. </Link>
  63. </div>
  64. </div>
  65. <div style={{ width: '100%', padding: '20px 0', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  66. <input
  67. style={{ width: '50%' }}
  68. type="text"
  69. placeholder="请输入账号"
  70. value={account}
  71. onChange={(e) => {
  72. const value = e.target.value;
  73. setAccount(value);
  74. }}
  75. />
  76. <input
  77. style={{ width: '50%', margin: '20px 0' }}
  78. type="password"
  79. placeholder="请输入密码"
  80. value={password}
  81. onChange={(e) => {
  82. const value = e.target.value;
  83. setPassword(value);
  84. }}
  85. />
  86. <button
  87. style={{
  88. width: '50%',
  89. border: '1px solid rgba(0, 0, 0, 0.1)',
  90. backgroundColor: '#FFFFFF',
  91. borderRadius: '10px',
  92. height: 36,
  93. cursor: 'pointer'
  94. }}
  95. onClick={async () => {
  96. await onClickExport({
  97. account: account,
  98. password: password,
  99. })
  100. }}
  101. >
  102. 导出
  103. </button>
  104. </div>
  105. </div>
  106. );
  107. };
  108. export default RecordApp;