|
@@ -1,231 +0,0 @@
|
|
|
-import { Card, Tabs, Input, Typography, Space, Form, Button, Table, Tag, Modal } from 'antd';
|
|
|
-import type { ColumnsType } from 'antd/es/table';
|
|
|
-import React from 'react';
|
|
|
-import { useState } from 'react';
|
|
|
-import { postData, getData } from '@/services/demo';
|
|
|
-import { ExclamationCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
|
|
|
-import moment from 'moment';
|
|
|
-
|
|
|
-const { Text } = Typography;
|
|
|
-const { Search } = Input;
|
|
|
-
|
|
|
-interface DataType {
|
|
|
- key: string;
|
|
|
- name: string;
|
|
|
- age: number;
|
|
|
- address: string;
|
|
|
- record_id: string;
|
|
|
- tags: string[];
|
|
|
-}
|
|
|
-
|
|
|
-const DemoPage: React.FC = () => {
|
|
|
- const [currentKey, setCurrentKey] = useState('1');
|
|
|
- const [tabText1, setTabText1] = useState('Tab1');
|
|
|
- const [tabText2, setTabText2] = useState('Tab2');
|
|
|
- const [tabText3, setTabText3] = useState('Tab3');
|
|
|
- const [form] = Form.useForm();
|
|
|
-
|
|
|
- // tab标签切换
|
|
|
- const handleOnChange = (key: string) => {
|
|
|
- setCurrentKey(key);
|
|
|
- };
|
|
|
-
|
|
|
- // tab下的搜索
|
|
|
- async function onSearch(text: string) {
|
|
|
- switch (currentKey) {
|
|
|
- case '1': {
|
|
|
- const result = await postData(text);
|
|
|
- const res = result.data.text;
|
|
|
- setTabText1(res);
|
|
|
- break;
|
|
|
- }
|
|
|
- case '2': {
|
|
|
- const result = await getData(text);
|
|
|
- const res = result.data.text;
|
|
|
- setTabText2(res);
|
|
|
- break;
|
|
|
- }
|
|
|
- case '3': {
|
|
|
- const result = await postData(text);
|
|
|
- const res = result.data.text;
|
|
|
- setTabText3(res);
|
|
|
- break;
|
|
|
- }
|
|
|
- default: {
|
|
|
- console.log('On Search: Error Key');
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 删除
|
|
|
- const toDelete = (record: DataType) => {
|
|
|
- Modal.confirm({
|
|
|
- title: '确认删除吗?',
|
|
|
- icon: <ExclamationCircleOutlined />,
|
|
|
- okText: '确认',
|
|
|
- okType: 'danger',
|
|
|
- cancelText: '取消',
|
|
|
- onOk() {
|
|
|
- console.log('OK');
|
|
|
- },
|
|
|
- onCancel() {
|
|
|
- console.log('Cancel', record);
|
|
|
- },
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- const columns: ColumnsType<DataType> = [
|
|
|
- {
|
|
|
- title: '序号',
|
|
|
- align: 'center',
|
|
|
- key: 'index',
|
|
|
- render: (_: any, row: any, index: number) => index + 1,
|
|
|
- },
|
|
|
- {
|
|
|
- title: '名称',
|
|
|
- dataIndex: 'name',
|
|
|
- key: 'name',
|
|
|
- render: (
|
|
|
- text:
|
|
|
- | boolean
|
|
|
- | React.ReactChild
|
|
|
- | React.ReactFragment
|
|
|
- | React.ReactPortal
|
|
|
- | null
|
|
|
- | undefined,
|
|
|
- ) => <a>{text}</a>,
|
|
|
- },
|
|
|
- {
|
|
|
- title: '数字',
|
|
|
- dataIndex: 'age',
|
|
|
- key: 'age',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '地址',
|
|
|
- dataIndex: 'address',
|
|
|
- key: 'address',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '日期',
|
|
|
- dataIndex: 'date',
|
|
|
- key: 'date',
|
|
|
- render: (data) => data && moment(data).format('YYYY-MM-DD HH:ss:mm'),
|
|
|
- },
|
|
|
- {
|
|
|
- title: '标签们',
|
|
|
- key: 'tags',
|
|
|
- dataIndex: 'tags',
|
|
|
- render: (_, { tags }) => (
|
|
|
- <>
|
|
|
- {tags.map((tag) => {
|
|
|
- let color = tag.length > 5 ? 'geekblue' : 'green';
|
|
|
- if (tag === 'loser') {
|
|
|
- color = 'volcano';
|
|
|
- }
|
|
|
- return (
|
|
|
- <Tag color={color} key={tag}>
|
|
|
- {tag.toUpperCase()}
|
|
|
- </Tag>
|
|
|
- );
|
|
|
- })}
|
|
|
- </>
|
|
|
- ),
|
|
|
- },
|
|
|
- {
|
|
|
- title: '操作',
|
|
|
- key: 'action',
|
|
|
- render: (_, record) => (
|
|
|
- <Space size="middle">
|
|
|
- <a>编辑</a>
|
|
|
- <a
|
|
|
- onClick={() => {
|
|
|
- toDelete(record);
|
|
|
- }}
|
|
|
- >
|
|
|
- 删除
|
|
|
- </a>
|
|
|
- </Space>
|
|
|
- ),
|
|
|
- },
|
|
|
- ];
|
|
|
-
|
|
|
- const data = [
|
|
|
- {
|
|
|
- record_id: '1',
|
|
|
- key: '1',
|
|
|
- name: '111',
|
|
|
- age: 31,
|
|
|
- address: '地址地址地址1',
|
|
|
- date: '2022-10-07T10:44:21',
|
|
|
- tags: ['loser', 'xixixi'],
|
|
|
- },
|
|
|
- {
|
|
|
- record_id: '2',
|
|
|
- key: '2',
|
|
|
- name: '222',
|
|
|
- age: 32,
|
|
|
- address: '地址地址地址2',
|
|
|
- date: '2022-10-07T10:44:21',
|
|
|
- tags: ['loser', 'hahaha'],
|
|
|
- },
|
|
|
- ];
|
|
|
-
|
|
|
- return (
|
|
|
- <div className="site-card-border-less-wrapper">
|
|
|
- <Card title="demo">
|
|
|
- <Form form={form} layout="inline">
|
|
|
- <Form.Item name="first" label="第一个">
|
|
|
- <Input placeholder="请输入..." />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="first" label="第二个">
|
|
|
- <Input placeholder="请输入..." />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item style={{ marginBottom: '10px' }}>
|
|
|
- <Space>
|
|
|
- <Button type="primary" htmlType="submit">
|
|
|
- <SearchOutlined />
|
|
|
- 查询
|
|
|
- </Button>
|
|
|
- <Button htmlType="button">
|
|
|
- <ReloadOutlined />
|
|
|
- 重置
|
|
|
- </Button>
|
|
|
- </Space>
|
|
|
- </Form.Item>
|
|
|
- </Form>
|
|
|
- <Tabs defaultActiveKey="1" activeKey={currentKey} onChange={handleOnChange}>
|
|
|
- <Tabs.TabPane tab="Demo_Tab_1" key="1" />
|
|
|
- <Tabs.TabPane tab="Demo_Tab_2" key="2" />
|
|
|
- <Tabs.TabPane tab="Demo_Tab_3" key="3" />
|
|
|
- </Tabs>
|
|
|
- {currentKey === '1' && (
|
|
|
- <Space direction="vertical">
|
|
|
- <Search placeholder="input search text1" onSearch={onSearch} enterButton />
|
|
|
- <Text> {tabText1} </Text>
|
|
|
- </Space>
|
|
|
- )}
|
|
|
- {currentKey === '2' && (
|
|
|
- <Space direction="vertical">
|
|
|
- <Search placeholder="input search text2" onSearch={onSearch} enterButton />
|
|
|
- <Text> {tabText2} </Text>
|
|
|
- </Space>
|
|
|
- )}
|
|
|
- {currentKey === '3' && (
|
|
|
- <Space direction="vertical">
|
|
|
- <Search placeholder="input search text3" onSearch={onSearch} enterButton />
|
|
|
- <Text> {tabText3} </Text>
|
|
|
- </Space>
|
|
|
- )}
|
|
|
- <Table
|
|
|
- columns={columns}
|
|
|
- dataSource={data}
|
|
|
- pagination={false}
|
|
|
- rowKey={(record) => record.record_id}
|
|
|
- />
|
|
|
- </Card>
|
|
|
- </div>
|
|
|
- );
|
|
|
-};
|
|
|
-
|
|
|
-export default DemoPage;
|