New file |
| | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { |
| | | ProForm, |
| | | ProFormDigit, |
| | | ProFormText, |
| | | ProFormSelect, |
| | | ProFormDateTimePicker |
| | | } from '@ant-design/pro-components'; |
| | | import { Form, Modal } from 'antd'; |
| | | import moment from 'moment'; |
| | | import Http from '@/utils/http'; |
| | | |
| | | const Edit = (props) => { |
| | | const [form] = Form.useForm(); |
| | | const { } = props; |
| | | |
| | | useEffect(() => { |
| | | form.resetFields(); |
| | | form.setFieldsValue({ |
| | | ...props.values |
| | | }) |
| | | }, [form, props]) |
| | | |
| | | const handleCancel = () => { |
| | | props.onCancel(); |
| | | }; |
| | | |
| | | const handleOk = () => { |
| | | form.submit(); |
| | | } |
| | | |
| | | const handleFinish = async (values) => { |
| | | props.onSubmit({ ...values }); |
| | | } |
| | | |
| | | return ( |
| | | <> |
| | | <Modal |
| | | title="Edit" |
| | | width={640} |
| | | forceRender |
| | | destroyOnClose |
| | | open={props.open} |
| | | onCancel={handleCancel} |
| | | onOk={handleOk} |
| | | > |
| | | <ProForm |
| | | form={form} |
| | | submitter={false} |
| | | onFinish={handleFinish} |
| | | layout="horizontal" |
| | | grid={true} |
| | | > |
| | | <ProFormDigit |
| | | name="id" |
| | | disabled |
| | | hidden={true} |
| | | /> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="name" |
| | | label="名称" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | rules={[{ required: true, message: "名称不能为空!" }]} |
| | | /> |
| | | <ProFormSelect |
| | | name="status" |
| | | label="状态" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | options={[ |
| | | { label: '正常', value: 1 }, |
| | | { label: '禁用', value: 0 }, |
| | | ]} |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormDateTimePicker |
| | | name="createTime" |
| | | label="添加时间" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | transform={(value) => moment(value).toISOString()} |
| | | /> |
| | | <ProFormDateTimePicker |
| | | name="updateTime" |
| | | label="修改时间" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | transform={(value) => moment(value).toISOString()} |
| | | /> |
| | | </ProForm.Group> |
| | | |
| | | </ProForm> |
| | | </Modal> |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | export default Edit; |
| | |
| | | import { EllipsisOutlined, SearchOutlined } from '@ant-design/icons'; |
| | | import { ProTable, TableDropdown } from '@ant-design/pro-components'; |
| | | import { Button, Dropdown, Input } from 'antd'; |
| | | |
| | | const valueEnum = { |
| | | 0: 'close', |
| | | 1: 'running', |
| | | 2: 'online', |
| | | 3: 'error', |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { Button, message, Modal } from 'antd'; |
| | | import { |
| | | FooterToolbar, |
| | | PageContainer, |
| | | ProTable, |
| | | LightFilter, |
| | | } from '@ant-design/pro-components'; |
| | | import { PlusOutlined, ExportOutlined } from '@ant-design/icons'; |
| | | import Http from '@/utils/http'; |
| | | import Edit from './components/edit' |
| | | import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch' |
| | | |
| | | const handleSave = async (val) => { |
| | | const hide = message.loading('正在添加'); |
| | | try { |
| | | const resp = await Http.doPost('api/host/save', val); |
| | | if (resp.code === 200) { |
| | | message.success('添加成功'); |
| | | return true; |
| | | } else { |
| | | message.error(resp.msg); |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | message.error('添加失败请重试!'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | const tableListDataSource = []; |
| | | const handleUpdate = async (val) => { |
| | | const hide = message.loading('正在更新'); |
| | | try { |
| | | const resp = await Http.doPost('api/host/update', val); |
| | | if (resp.code === 200) { |
| | | message.success('更新成功'); |
| | | return true; |
| | | } else { |
| | | message.error(resp.msg); |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | message.error('配置失败请重试!'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | const creators = ['付小小', '曲丽丽', '林东东', '陈帅帅', '兼某某']; |
| | | const handleRemove = async (rows) => { |
| | | if (!rows) return true; |
| | | const hide = message.loading('正在删除'); |
| | | try { |
| | | const resp = await Http.doPost('api/host/remove/' + rows.map((row) => row.id).join(',')); |
| | | if (resp.code === 200) { |
| | | message.success('删除成功'); |
| | | return true; |
| | | } else { |
| | | message.error(resp.msg); |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | message.error('删除失败,请重试'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | for (let i = 0; i < 5; i += 1) { |
| | | tableListDataSource.push({ |
| | | key: i, |
| | | name: 'AppName', |
| | | containers: Math.floor(Math.random() * 20), |
| | | creator: creators[Math.floor(Math.random() * creators.length)], |
| | | status: valueEnum[((Math.floor(Math.random() * 10) % 4) + '')], |
| | | createdAt: Date.now() - Math.floor(Math.random() * 2000), |
| | | money: Math.floor(Math.random() * 2000) * i, |
| | | progress: Math.ceil(Math.random() * 100) + 1, |
| | | memo: |
| | | i % 2 === 1 |
| | | ? '很长很长很长很长很长很长很长的文字要展示但是要留下尾巴' |
| | | : '简短备注文案', |
| | | }); |
| | | } |
| | | const handleExport = async () => { |
| | | const hide = message.loading('正在导出'); |
| | | try { |
| | | const resp = await Http.doPostBlob('api/host/export'); |
| | | const blob = new Blob([resp], { type: 'application/vnd.ms-excel' }); |
| | | window.location.href = window.URL.createObjectURL(blob); |
| | | message.success('导出成功'); |
| | | return true; |
| | | } catch (error) { |
| | | message.error('导出失败,请重试'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | const columns = [ |
| | | { |
| | | title: '排序', |
| | | dataIndex: 'index', |
| | | valueType: 'indexBorder', |
| | | width: 48, |
| | | }, |
| | | { |
| | | title: '应用名称', |
| | | dataIndex: 'name', |
| | | render: (_) => <a>{_}</a>, |
| | | // 自定义筛选项功能具体实现请参考 https://ant.design/components/table-cn/#components-table-demo-custom-filter-panel |
| | | filterDropdown: () => ( |
| | | <div style={{ padding: 8 }}> |
| | | <Input style={{ width: 188, marginBlockEnd: 8, display: 'block' }} /> |
| | | </div> |
| | | ), |
| | | filterIcon: (filtered) => ( |
| | | <SearchOutlined style={{ color: filtered ? '#1890ff' : undefined }} /> |
| | | ), |
| | | }, |
| | | { |
| | | title: '创建者', |
| | | dataIndex: 'creator', |
| | | valueEnum: { |
| | | all: { text: '全部' }, |
| | | 付小小: { text: '付小小' }, |
| | | 曲丽丽: { text: '曲丽丽' }, |
| | | 林东东: { text: '林东东' }, |
| | | 陈帅帅: { text: '陈帅帅' }, |
| | | 兼某某: { text: '兼某某' }, |
| | | }, |
| | | }, |
| | | { |
| | | title: '状态', |
| | | dataIndex: 'status', |
| | | initialValue: 'all', |
| | | filters: true, |
| | | onFilter: true, |
| | | valueEnum: { |
| | | all: { text: '全部', status: 'Default' }, |
| | | close: { text: '关闭', status: 'Default' }, |
| | | running: { text: '运行中', status: 'Processing' }, |
| | | online: { text: '已上线', status: 'Success' }, |
| | | error: { text: '异常', status: 'Error' }, |
| | | }, |
| | | }, |
| | | { |
| | | title: '备注', |
| | | dataIndex: 'memo', |
| | | ellipsis: true, |
| | | copyable: true, |
| | | }, |
| | | { |
| | | title: '操作', |
| | | width: 180, |
| | | key: 'option', |
| | | valueType: 'option', |
| | | render: () => [ |
| | | <a key="link">链路</a>, |
| | | <a key="link2">报警</a>, |
| | | <a key="link3">监控</a>, |
| | | <TableDropdown |
| | | key="actionGroup" |
| | | menus={[ |
| | | { key: 'copy', name: '复制' }, |
| | | { key: 'delete', name: '删除' }, |
| | | ]} |
| | | />, |
| | | ], |
| | | }, |
| | | ]; |
| | | |
| | | export default () => { |
| | | return ( |
| | | <ProTable |
| | | columns={columns} |
| | | request={(params, sorter, filter) => { |
| | | // 表单搜索项会从 params 传入,传递给后端接口。 |
| | | console.log(params, sorter, filter); |
| | | return Promise.resolve({ |
| | | data: tableListDataSource, |
| | | success: true, |
| | | }); |
| | | }} |
| | | rowKey="key" |
| | | pagination={{ |
| | | showQuickJumper: true, |
| | | }} |
| | | search={{ |
| | | layout: 'vertical', |
| | | defaultCollapsed: false, |
| | | }} |
| | | dateFormatter="string" |
| | | toolbar={{ |
| | | title: '高级表格', |
| | | tooltip: '这是一个标题提示', |
| | | }} |
| | | toolBarRender={() => [ |
| | | <Button key="danger" danger> |
| | | 危险按钮 |
| | | </Button>, |
| | | <Button key="show">查看日志</Button>, |
| | | <Button type="primary" key="primary"> |
| | | 创建应用 |
| | | </Button>, |
| | | const Main = () => { |
| | | const formTableRef = useRef(); |
| | | const actionRef = useRef(); |
| | | const [selectedRows, setSelectedRows] = useState([]); |
| | | const [modalVisible, setModalVisible] = useState(false); |
| | | const [currentRow, setCurrentRow] = useState(); |
| | | const [searchParam, setSearchParam] = useState({}); |
| | | |
| | | <Dropdown |
| | | key="menu" |
| | | menu={{ |
| | | items: [ |
| | | { |
| | | label: '1st item', |
| | | key: '1', |
| | | }, |
| | | { |
| | | label: '2nd item', |
| | | key: '2', |
| | | }, |
| | | { |
| | | label: '3rd item', |
| | | key: '3', |
| | | }, |
| | | useEffect(() => { |
| | | |
| | | }, []); |
| | | |
| | | const columns = [ |
| | | { |
| | | title: 'No', |
| | | dataIndex: 'index', |
| | | valueType: 'indexBorder', |
| | | width: 48, |
| | | }, |
| | | { |
| | | title: '名称', |
| | | dataIndex: 'name', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | copyable: true, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='name' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '状态', |
| | | dataIndex: 'status$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <SelectFilter |
| | | name='status' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | data={[ |
| | | { label: '正常', value: 1 }, |
| | | { label: '禁用', value: 0 }, |
| | | ]} |
| | | />, |
| | | }, |
| | | { |
| | | title: '添加时间', |
| | | dataIndex: 'createTime$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <DatetimeRangeFilter |
| | | name='createTime' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '修改时间', |
| | | dataIndex: 'updateTime$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <DatetimeRangeFilter |
| | | name='updateTime' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '备注', |
| | | dataIndex: 'memo', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='memo' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | |
| | | { |
| | | title: '操作', |
| | | dataIndex: 'option', |
| | | width: 140, |
| | | valueType: 'option', |
| | | render: (_, record) => [ |
| | | <Button |
| | | type="link" |
| | | key="edit" |
| | | onClick={() => { |
| | | setModalVisible(true); |
| | | setCurrentRow(record); |
| | | }} |
| | | > |
| | | 编辑 |
| | | </Button>, |
| | | <Button |
| | | type="link" |
| | | danger |
| | | key="batchRemove" |
| | | onClick={async () => { |
| | | Modal.confirm({ |
| | | title: '删除', |
| | | content: '确定删除该项吗?', |
| | | onOk: async () => { |
| | | const success = await handleRemove([record]); |
| | | if (success) { |
| | | if (actionRef.current) { |
| | | actionRef.current.reload(); |
| | | } |
| | | } |
| | | }, |
| | | }); |
| | | }} |
| | | > |
| | | 删除 |
| | | </Button>, |
| | | ], |
| | | }} |
| | | > |
| | | <Button> |
| | | <EllipsisOutlined /> |
| | | </Button> |
| | | </Dropdown>, |
| | | ]} |
| | | /> |
| | | ); |
| | | }; |
| | | }, |
| | | ]; |
| | | |
| | | return ( |
| | | <PageContainer> |
| | | <div style={{ width: '100%', float: 'right' }}> |
| | | <ProTable |
| | | key="host" |
| | | rowKey="id" |
| | | actionRef={actionRef} |
| | | formRef={formTableRef} |
| | | columns={columns} |
| | | cardBordered |
| | | scroll={{ x: 1300 }} |
| | | dateFormatter="string" |
| | | pagination={{ pageSize: 20 }} |
| | | search={false} |
| | | toolbar={{ |
| | | search: { |
| | | onSearch: (value) => { |
| | | setSearchParam(prevState => ({ |
| | | ...prevState, |
| | | condition: value |
| | | })); |
| | | actionRef.current?.reload(); |
| | | }, |
| | | }, |
| | | filter: ( |
| | | <LightFilter |
| | | onValuesChange={(val) => { |
| | | }} |
| | | > |
| | | </LightFilter> |
| | | ), |
| | | actions: [ |
| | | <Button |
| | | type="primary" |
| | | key="save" |
| | | onClick={async () => { |
| | | setModalVisible(true) |
| | | }} |
| | | > |
| | | <PlusOutlined /> |
| | | 添加 |
| | | </Button>, |
| | | <Button |
| | | key="export" |
| | | onClick={async () => { |
| | | handleExport(); |
| | | }} |
| | | > |
| | | <ExportOutlined /> |
| | | 导出 |
| | | </Button>, |
| | | ], |
| | | }} |
| | | request={(params, sorter, filter) => |
| | | Http.doPostPromise('/api/host/page', { ...params, ...searchParam }, (res) => { |
| | | return { |
| | | data: res.data.records, |
| | | total: res.data.total, |
| | | success: true, |
| | | } |
| | | }) |
| | | } |
| | | rowSelection={{ |
| | | onChange: (ids, rows) => { |
| | | setSelectedRows(rows); |
| | | } |
| | | }} |
| | | columnsState={{ |
| | | persistenceKey: 'pro-table-host', |
| | | persistenceType: 'localStorage', |
| | | defaultValue: { |
| | | option: { fixed: 'right', disable: true }, |
| | | }, |
| | | onChange(value) { |
| | | }, |
| | | }} |
| | | /> |
| | | </div> |
| | | |
| | | {selectedRows?.length > 0 && ( |
| | | <FooterToolbar |
| | | extra={ |
| | | <div> |
| | | 已选择 |
| | | <a style={{ fontWeight: 600 }}>{selectedRows.length}</a> |
| | | 项 |
| | | </div> |
| | | } |
| | | > |
| | | <Button |
| | | key="remove" |
| | | danger |
| | | onClick={async () => { |
| | | Modal.confirm({ |
| | | title: '删除', |
| | | content: '确定删除该项吗?', |
| | | onOk: async () => { |
| | | const success = await handleRemove(selectedRows); |
| | | if (success) { |
| | | setSelectedRows([]); |
| | | actionRef.current?.reloadAndRest?.(); |
| | | } |
| | | }, |
| | | }); |
| | | }} |
| | | > |
| | | 批量删除 |
| | | </Button> |
| | | </FooterToolbar> |
| | | )} |
| | | |
| | | <Edit |
| | | open={modalVisible} |
| | | values={currentRow || {}} |
| | | onCancel={ |
| | | () => { |
| | | setModalVisible(false); |
| | | setCurrentRow(undefined); |
| | | } |
| | | } |
| | | onSubmit={async (values) => { |
| | | let ok = false; |
| | | if (values.id) { |
| | | ok = await handleUpdate({ ...values }) |
| | | } else { |
| | | ok = await handleSave({ ...values }) |
| | | } |
| | | if (ok) { |
| | | setModalVisible(false); |
| | | setCurrentRow(undefined); |
| | | if (actionRef.current) { |
| | | actionRef.current.reload(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /> |
| | | </PageContainer> |
| | | ); |
| | | }; |
| | | |
| | | export default Main; |
| | |
| | | // generator.username="sa"; |
| | | // generator.password="Zoneyung@zy56$"; |
| | | |
| | | generator.table="sys_user"; |
| | | generator.tableName="用户"; |
| | | generator.table="sys_host"; |
| | | generator.tableName="机构"; |
| | | generator.packagePath="com.zy.asrs.wcs.system"; |
| | | |
| | | generator.build(); |
New file |
| | |
| | | -- save host record |
| | | -- mysql |
| | | insert into `sys_menu` ( `name`, `parent_id`, `route`, `type`, `sort`, `host_id`, `status`) values ( '机构管理', '0', '/system/host', '0' , '0', '1' , '1'); |
| | | |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '查询机构', '', '1', 'system:host:list', '0', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '添加机构', '', '1', 'system:host:save', '1', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '修改机构', '', '1', 'system:host:update', '2', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '删除机构', '', '1', 'system:host:remove', '3', '1', '1'); |
| | | |