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: "名称不能为空!" }]} |
| | | /> |
| | | <ProFormDigit |
| | | name="parentId" |
| | | label="上级部门" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="parentName" |
| | | label="上级部门名" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormText |
| | | name="path" |
| | | label="关联路径" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="pathName" |
| | | label="关联路径名" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormText |
| | | name="fullName" |
| | | label="全称" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="brief" |
| | | label="简述" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormText |
| | | name="code" |
| | | label="标识" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormDigit |
| | | name="type" |
| | | label="类型" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormText |
| | | name="leader" |
| | | label="负责人" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormDigit |
| | | name="count" |
| | | label="数量" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormDigit |
| | | name="sort" |
| | | label="排序" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormSelect |
| | | name="status" |
| | | label="状态" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | options={[ |
| | | { label: '正常', value: 1 }, |
| | | { label: '禁用', value: 0 }, |
| | | ]} |
| | | /> |
| | | <ProFormDateTimePicker |
| | | name="createTime" |
| | | label="添加时间" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | transform={(value) => moment(value).toISOString()} |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormSelect |
| | | name="createBy" |
| | | label="添加人员" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请选择" |
| | | showSearch |
| | | debounceTime={300} |
| | | request={async ({ keyWords }) => { |
| | | const resp = await Http.doPostForm('api/user/query', { condition: keyWords }); |
| | | return resp.data; |
| | | }} |
| | | /> |
| | | <ProFormDateTimePicker |
| | | name="updateTime" |
| | | label="修改时间" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | transform={(value) => moment(value).toISOString()} |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormSelect |
| | | name="updateBy" |
| | | label="修改人员" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请选择" |
| | | showSearch |
| | | debounceTime={300} |
| | | request={async ({ keyWords }) => { |
| | | const resp = await Http.doPostForm('api/user/query', { condition: keyWords }); |
| | | return resp.data; |
| | | }} |
| | | /> |
| | | </ProForm.Group> |
| | | |
| | | </ProForm> |
| | | </Modal> |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | export default Edit; |
New file |
| | |
| | | |
| | | 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/dept/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 handleUpdate = async (val) => { |
| | | const hide = message.loading('正在更新'); |
| | | try { |
| | | const resp = await Http.doPost('api/dept/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 handleRemove = async (rows) => { |
| | | if (!rows) return true; |
| | | const hide = message.loading('正在删除'); |
| | | try { |
| | | const resp = await Http.doPost('api/dept/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(); |
| | | } |
| | | }; |
| | | |
| | | const handleExport = async () => { |
| | | const hide = message.loading('正在导出'); |
| | | try { |
| | | const resp = await Http.doPostBlob('api/dept/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 Main = () => { |
| | | const formTableRef = useRef(); |
| | | const actionRef = useRef(); |
| | | const [selectedRows, setSelectedRows] = useState([]); |
| | | const [modalVisible, setModalVisible] = useState(false); |
| | | const [currentRow, setCurrentRow] = useState(); |
| | | const [searchParam, setSearchParam] = useState({}); |
| | | |
| | | 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: 'parentId', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='parentId' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '上级部门名', |
| | | dataIndex: 'parentName', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='parentName' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '关联路径', |
| | | dataIndex: 'path', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='path' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '关联路径名', |
| | | dataIndex: 'pathName', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='pathName' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '全称', |
| | | dataIndex: 'fullName', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='fullName' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '简述', |
| | | dataIndex: 'brief', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='brief' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '标识', |
| | | dataIndex: 'code', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='code' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '类型', |
| | | dataIndex: 'type', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='type' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '负责人', |
| | | dataIndex: 'leader', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='leader' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '数量', |
| | | dataIndex: 'count', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='count' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '排序', |
| | | dataIndex: 'sort', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='sort' |
| | | {...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: 'createBy$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='createBy' |
| | | major='user' |
| | | {...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: 'updateBy$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='updateBy' |
| | | major='user' |
| | | {...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>, |
| | | ], |
| | | }, |
| | | ]; |
| | | |
| | | return ( |
| | | <PageContainer> |
| | | <div style={{ width: '100%', float: 'right' }}> |
| | | <ProTable |
| | | key="dept" |
| | | 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/dept/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-dept', |
| | | 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; |
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="username" |
| | | label="账号" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | rules={[{ required: true, message: "账号不能为空!" }]} |
| | | /> |
| | | <ProFormText |
| | | name="password" |
| | | label="密码" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="nickname" |
| | | label="昵称" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormText |
| | | name="avatar" |
| | | label="头像" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="code" |
| | | label="工号" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormSelect |
| | | name="sex" |
| | | label="性别" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | options={[ |
| | | { label: '未知', value: 0 }, |
| | | { label: '男', value: 1 }, |
| | | { label: '女', value: 2 }, |
| | | ]} |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="phone" |
| | | label="手机号" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormText |
| | | name="email" |
| | | label="邮箱" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormSelect |
| | | name="emailVerified" |
| | | label="邮箱验证" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | options={[ |
| | | { label: '否', value: 0 }, |
| | | { label: '是', value: 1 }, |
| | | ]} |
| | | /> |
| | | <ProFormSelect |
| | | name="deptId" |
| | | label="所属部门" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请选择" |
| | | showSearch |
| | | debounceTime={300} |
| | | request={async ({ keyWords }) => { |
| | | const resp = await Http.doPostForm('api/dept/query', { condition: keyWords }); |
| | | return resp.data; |
| | | }} |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="realName" |
| | | label="真实姓名" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormText |
| | | name="idCard" |
| | | label="身份证号" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="birthday" |
| | | label="出生日期" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | <ProFormText |
| | | name="introduction" |
| | | label="个人简介" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请输入" |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormSelect |
| | | name="status" |
| | | label="状态" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | options={[ |
| | | { label: '正常', value: 1 }, |
| | | { label: '禁用', value: 0 }, |
| | | ]} |
| | | /> |
| | | <ProFormDateTimePicker |
| | | name="createTime" |
| | | label="添加时间" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | transform={(value) => moment(value).toISOString()} |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormSelect |
| | | name="createBy" |
| | | label="添加人员" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请选择" |
| | | showSearch |
| | | debounceTime={300} |
| | | request={async ({ keyWords }) => { |
| | | const resp = await Http.doPostForm('api/user/query', { condition: keyWords }); |
| | | return resp.data; |
| | | }} |
| | | /> |
| | | <ProFormDateTimePicker |
| | | name="updateTime" |
| | | label="修改时间" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | placeholder="请选择" |
| | | transform={(value) => moment(value).toISOString()} |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormSelect |
| | | name="updateBy" |
| | | label="修改人员" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | fieldProps={{ precision: 0 }} |
| | | placeholder="请选择" |
| | | showSearch |
| | | debounceTime={300} |
| | | request={async ({ keyWords }) => { |
| | | const resp = await Http.doPostForm('api/user/query', { condition: keyWords }); |
| | | return resp.data; |
| | | }} |
| | | /> |
| | | </ProForm.Group> |
| | | |
| | | </ProForm> |
| | | </Modal> |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | export default Edit; |
| | |
| | | import React, { useState } from 'react'; |
| | | import { |
| | | PageContainer, |
| | | } from '@ant-design/pro-components'; |
| | | 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/user/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/user/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/user/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 < 25; 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/user/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: '兼某某' }, |
| | | |
| | | 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({}); |
| | | |
| | | useEffect(() => { |
| | | |
| | | }, []); |
| | | |
| | | const columns = [ |
| | | { |
| | | title: 'No', |
| | | dataIndex: 'index', |
| | | valueType: 'indexBorder', |
| | | width: 48, |
| | | }, |
| | | }, |
| | | { |
| | | 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: 'username', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='username' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | }, |
| | | { |
| | | 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: '删除' }, |
| | | { |
| | | title: '密码', |
| | | dataIndex: 'password', |
| | | valueType: 'password', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='password' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '昵称', |
| | | dataIndex: 'nickname', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | copyable: true, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='nickname' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '头像', |
| | | dataIndex: 'avatar', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='avatar' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '工号', |
| | | dataIndex: 'code', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='code' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '性别', |
| | | dataIndex: 'sex$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <SelectFilter |
| | | name='sex' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | data={[ |
| | | { label: '未知', value: 0 }, |
| | | { label: '男', value: 1 }, |
| | | { label: '女', value: 2 }, |
| | | ]} |
| | | />, |
| | | ], |
| | | }, |
| | | ]; |
| | | }, |
| | | { |
| | | title: '手机号', |
| | | dataIndex: 'phone', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='phone' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '邮箱', |
| | | dataIndex: 'email', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='email' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '邮箱验证', |
| | | dataIndex: 'emailVerified$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <SelectFilter |
| | | name='emailVerified' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | data={[ |
| | | { label: '否', value: 0 }, |
| | | { label: '是', value: 1 }, |
| | | ]} |
| | | />, |
| | | }, |
| | | { |
| | | title: '所属部门', |
| | | dataIndex: 'deptId$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='deptId' |
| | | major='dept' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '真实姓名', |
| | | dataIndex: 'realName', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='realName' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '身份证号', |
| | | dataIndex: 'idCard', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='idCard' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '出生日期', |
| | | dataIndex: 'birthday', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='birthday' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '个人简介', |
| | | dataIndex: 'introduction', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='introduction' |
| | | {...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: 'createBy$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='createBy' |
| | | major='user' |
| | | {...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: 'updateBy$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='updateBy' |
| | | major='user' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '备注', |
| | | dataIndex: 'memo', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='memo' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | |
| | | const App = () => { |
| | | { |
| | | 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>, |
| | | ], |
| | | }, |
| | | ]; |
| | | |
| | | return ( |
| | | <> |
| | | <PageContainer> |
| | | <div style={{ width: '100%', float: 'right' }}> |
| | | <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>, |
| | | |
| | | <Dropdown |
| | | key="menu" |
| | | menu={{ |
| | | items: [ |
| | | { |
| | | label: '1st item', |
| | | key: '1', |
| | | }, |
| | | { |
| | | label: '2nd item', |
| | | key: '2', |
| | | }, |
| | | { |
| | | label: '3rd item', |
| | | key: '3', |
| | | }, |
| | | ], |
| | | <PageContainer> |
| | | <div style={{ width: '100%', float: 'right' }}> |
| | | <ProTable |
| | | key="user" |
| | | 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) => { |
| | | }} |
| | | > |
| | | <Button> |
| | | <EllipsisOutlined /> |
| | | </Button> |
| | | </Dropdown>, |
| | | ]} |
| | | /> |
| | | </div> |
| | | </PageContainer> |
| | | </> |
| | | </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/user/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-user', |
| | | 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> |
| | | ); |
| | | }; |
| | | |
| | | const User = () => { |
| | | return ( |
| | | <> |
| | | <PageContainer> |
| | | <h1>User Hello world</h1> |
| | | </PageContainer> |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | export default App; |
| | | export default Main; |
| | |
| | | .append(" debounceTime={300}\n") |
| | | .append(" request={async ({ keyWords }) => {\n") |
| | | .append(" const resp = await Http.doPostForm('api/").append(GeneratorUtils.firstCharConvert(column.getForeignKey())).append("/query', { condition: keyWords });\n") |
| | | .append(" return resp.data;\n") |
| | | .append(" }}\n"); |
| | | } |
| | | |
New file |
| | |
| | | package com.zy.asrs.wcs.system.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.wcs.common.annotation.OperationLog; |
| | | import com.zy.asrs.wcs.common.domain.BaseParam; |
| | | import com.zy.asrs.wcs.common.domain.KeyValVo; |
| | | import com.zy.asrs.wcs.common.domain.PageParam; |
| | | import com.zy.asrs.wcs.system.entity.Dept; |
| | | import com.zy.asrs.wcs.system.service.DeptService; |
| | | import com.zy.asrs.wcs.utils.ExcelUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | public class DeptController extends BaseController { |
| | | |
| | | @Autowired |
| | | private DeptService deptService; |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:list')") |
| | | @PostMapping("/dept/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Dept, BaseParam> pageParam = new PageParam<>(baseParam, Dept.class); |
| | | return R.ok().add(deptService.page(pageParam, pageParam.buildWrapper(true))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:list')") |
| | | @PostMapping("/dept/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(deptService.list()); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:list')") |
| | | @GetMapping("/dept/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(deptService.getById(id)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:save')") |
| | | @OperationLog("添加Dept") |
| | | @PostMapping("/dept/save") |
| | | public R save(@RequestBody Dept dept) { |
| | | if (!deptService.save(dept)) { |
| | | return R.error("添加失败"); |
| | | } |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:update')") |
| | | @OperationLog("修改Dept") |
| | | @PostMapping("/dept/update") |
| | | public R update(@RequestBody Dept dept) { |
| | | if (!deptService.updateById(dept)) { |
| | | return R.error("修改失败"); |
| | | } |
| | | return R.ok("修改成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:remove')") |
| | | @OperationLog("删除Dept") |
| | | @PostMapping("/dept/remove/{ids}") |
| | | public R remove(@PathVariable Long[] ids) { |
| | | if (!deptService.removeByIds(Arrays.asList(ids))) { |
| | | return R.error("删除失败"); |
| | | } |
| | | return R.ok("删除成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:list')") |
| | | @PostMapping("/dept/query") |
| | | public R query(@RequestParam(required = false) String condition) { |
| | | List<KeyValVo> vos = new ArrayList<>(); |
| | | LambdaQueryWrapper<Dept> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(Dept::getName, condition); |
| | | } |
| | | deptService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:list')") |
| | | @PostMapping("/dept/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(deptService.list(), Dept.class), response); |
| | | } |
| | | |
| | | } |
| | |
| | | @Autowired |
| | | private RoleService roleService; |
| | | |
| | | @PreAuthorize("hasAuthority('sys:role:list')") |
| | | @PreAuthorize("hasAuthority('system:role:list')") |
| | | @PostMapping("/role/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | |
| | | return R.ok().add(roleService.page(pageParam, pageParam.buildWrapper(true))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('sys:role:list')") |
| | | @PreAuthorize("hasAuthority('system:role:list')") |
| | | @PostMapping("/role/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(roleService.list()); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('sys:role:list')") |
| | | @PreAuthorize("hasAuthority('system:role:list')") |
| | | @GetMapping("/role/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(roleService.getById(id)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('sys:role:save')") |
| | | @PreAuthorize("hasAuthority('system:role:save')") |
| | | @OperationLog("添加角色") |
| | | @PostMapping("/role/save") |
| | | public R save(@RequestBody Role role) { |
| | |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('sys:role:update')") |
| | | @PreAuthorize("hasAuthority('system:role:update')") |
| | | @OperationLog("修改角色") |
| | | @PostMapping("/role/update") |
| | | public R update(@RequestBody Role role) { |
| | |
| | | return R.ok("修改成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('sys:role:remove')") |
| | | @PreAuthorize("hasAuthority('system:role:remove')") |
| | | @OperationLog("删除角色") |
| | | @PostMapping("/role/remove/{ids}") |
| | | public R remove(@PathVariable Long[] ids) { |
| | |
| | | return R.ok("删除成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('sys:role:list')") |
| | | @PreAuthorize("hasAuthority('system:role:list')") |
| | | @PostMapping("/role/query") |
| | | public R query(@RequestParam(required = false) String condition) { |
| | | List<KeyValVo> vos = new ArrayList<>(); |
| | |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('sys:role:list')") |
| | | @PreAuthorize("hasAuthority('system:role:list')") |
| | | @PostMapping("/role/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(roleService.list(), Role.class), response); |
New file |
| | |
| | | package com.zy.asrs.wcs.system.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.wcs.common.annotation.OperationLog; |
| | | import com.zy.asrs.wcs.common.domain.BaseParam; |
| | | import com.zy.asrs.wcs.common.domain.KeyValVo; |
| | | import com.zy.asrs.wcs.common.domain.PageParam; |
| | | import com.zy.asrs.wcs.system.entity.User; |
| | | import com.zy.asrs.wcs.system.service.UserService; |
| | | import com.zy.asrs.wcs.utils.ExcelUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | public class UserController extends BaseController { |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:list')") |
| | | @PostMapping("/user/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<User, BaseParam> pageParam = new PageParam<>(baseParam, User.class); |
| | | return R.ok().add(userService.page(pageParam, pageParam.buildWrapper(true))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:list')") |
| | | @PostMapping("/user/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(userService.list()); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:list')") |
| | | @GetMapping("/user/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(userService.getById(id)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:save')") |
| | | @OperationLog("添加User") |
| | | @PostMapping("/user/save") |
| | | public R save(@RequestBody User user) { |
| | | if (!userService.save(user)) { |
| | | return R.error("添加失败"); |
| | | } |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:update')") |
| | | @OperationLog("修改User") |
| | | @PostMapping("/user/update") |
| | | public R update(@RequestBody User user) { |
| | | if (!userService.updateById(user)) { |
| | | return R.error("修改失败"); |
| | | } |
| | | return R.ok("修改成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:remove')") |
| | | @OperationLog("删除User") |
| | | @PostMapping("/user/remove/{ids}") |
| | | public R remove(@PathVariable Long[] ids) { |
| | | if (!userService.removeByIds(Arrays.asList(ids))) { |
| | | return R.error("删除失败"); |
| | | } |
| | | return R.ok("删除成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:list')") |
| | | @PostMapping("/user/query") |
| | | public R query(@RequestParam(required = false) String condition) { |
| | | List<KeyValVo> vos = new ArrayList<>(); |
| | | LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(User::getNickname, condition); |
| | | } |
| | | userService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getNickname())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:list')") |
| | | @PostMapping("/user/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(userService.list(), User.class), response); |
| | | } |
| | | |
| | | } |
| | |
| | | UserService service = SpringUtils.getBean(UserService.class); |
| | | User user = service.getById(this.createBy); |
| | | if (!Cools.isEmpty(user)){ |
| | | return String.valueOf(user.getId()); |
| | | return String.valueOf(user.getNickname()); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | UserService service = SpringUtils.getBean(UserService.class); |
| | | User user = service.getById(this.updateBy); |
| | | if (!Cools.isEmpty(user)){ |
| | | return String.valueOf(user.getId()); |
| | | return String.valueOf(user.getNickname()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.SpringUtils; |
| | | import com.zy.asrs.wcs.system.service.DeptService; |
| | | import com.zy.asrs.wcs.system.service.HostService; |
| | | import com.zy.asrs.wcs.system.service.UserService; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | |
| | | } |
| | | } |
| | | |
| | | // public String getDeptId$(){ |
| | | // DeptService service = SpringUtils.getBean(DeptService.class); |
| | | // Dept dept = service.getById(this.deptId); |
| | | // if (!Cools.isEmpty(dept)){ |
| | | // return String.valueOf(dept.getName()); |
| | | // } |
| | | // return null; |
| | | // } |
| | | public String getDeptId$(){ |
| | | DeptService service = SpringUtils.getBean(DeptService.class); |
| | | Dept dept = service.getById(this.deptId); |
| | | if (!Cools.isEmpty(dept)){ |
| | | return String.valueOf(dept.getName()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public String getHostId$(){ |
| | | HostService service = SpringUtils.getBean(HostService.class); |
| | |
| | | UserService service = SpringUtils.getBean(UserService.class); |
| | | User user = service.getById(this.createBy); |
| | | if (!Cools.isEmpty(user)){ |
| | | return String.valueOf(user.getId()); |
| | | return String.valueOf(user.getNickname()); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | UserService service = SpringUtils.getBean(UserService.class); |
| | | User user = service.getById(this.updateBy); |
| | | if (!Cools.isEmpty(user)){ |
| | | return String.valueOf(user.getId()); |
| | | return String.valueOf(user.getNickname()); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | // generator.username="sa"; |
| | | // generator.password="Zoneyung@zy56$"; |
| | | |
| | | generator.table="sys_dept"; |
| | | generator.tableName="部门"; |
| | | generator.table="sys_user"; |
| | | generator.tableName="用户"; |
| | | generator.packagePath="com.zy.asrs.wcs.system"; |
| | | |
| | | generator.build(); |
New file |
| | |
| | | -- save dept record |
| | | -- mysql |
| | | insert into `sys_menu` ( `name`, `parent_id`, `route`, `type`, `sort`, `host_id`, `status`) values ( '部门管理', '0', '/system/dept', '0' , '0', '1' , '1'); |
| | | |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '查询部门', '', '1', 'system:dept:list', '0', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '添加部门', '', '1', 'system:dept:save', '1', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '修改部门', '', '1', 'system:dept:update', '2', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '删除部门', '', '1', 'system:dept:remove', '3', '1', '1'); |
| | | |
New file |
| | |
| | | -- save user record |
| | | -- mysql |
| | | insert into `sys_menu` ( `name`, `parent_id`, `route`, `type`, `sort`, `host_id`, `status`) values ( '用户管理', '0', '/system/user', '0' , '0', '1' , '1'); |
| | | |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '查询用户', '', '1', 'system:user:list', '0', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '添加用户', '', '1', 'system:user:save', '1', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '修改用户', '', '1', 'system:user:update', '2', '1', '1'); |
| | | insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '删除用户', '', '1', 'system:user:remove', '3', '1', '1'); |
| | | |