| | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import moment from 'moment'; |
| | | import { Col, Form, Input, Row, Checkbox, Slider, Select, Drawer, Space, Button, InputNumber, Switch } from 'antd'; |
| | | import { Col, Form, Input, Row, Checkbox, Slider, Select, Drawer, Space, Button, InputNumber, Card } from 'antd'; |
| | | import { FormattedMessage, useIntl, useModel } from '@umijs/max'; |
| | | import * as PIXI from 'pixi.js'; |
| | | import { |
| | | BranchesOutlined, |
| | | BorderOuterOutlined, |
| | | } from '@ant-design/icons'; |
| | | import { createStyles } from 'antd-style'; |
| | | import './index.css'; |
| | | import * as Utils from '../utils' |
| | | import Http from '@/utils/http'; |
| | | import MapSettings from './mapSettings'; |
| | | import ConfigSettings from './configSettings'; |
| | | |
| | | const useStyles = createStyles(({ token, css }) => { |
| | | |
| | | }) |
| | | |
| | | const SpriteSettings = (props) => { |
| | | const Settings = (props) => { |
| | | const intl = useIntl(); |
| | | const { styles } = useStyles(); |
| | | const { curSprite } = props; |
| | | const [form] = Form.useForm(); |
| | | const [activeTabKey, setActiveTabKey] = useState('map'); |
| | | |
| | | useEffect(() => { |
| | | const [mapForm] = Form.useForm(); |
| | | const [configForm] = Form.useForm(); |
| | | |
| | | }, []); |
| | | |
| | | useEffect(() => { |
| | | form.resetFields(); |
| | | form.setFieldsValue({ |
| | | ...props.values |
| | | }) |
| | | }, [form, props]) |
| | | const contentList = { |
| | | map: ( |
| | | <MapSettings |
| | | refCurr={props.refCurr} |
| | | curSprite={props.curSprite} |
| | | setSpriteBySettings={props.setSpriteBySettings} |
| | | setDidClickSprite={props.setDidClickSprite} |
| | | onSubmit={props.onSubmit} |
| | | mapForm={mapForm} |
| | | /> |
| | | ), |
| | | config: ( |
| | | <ConfigSettings |
| | | refCurr={props.refCurr} |
| | | curSprite={props.curSprite} |
| | | setSpriteBySettings={props.setSpriteBySettings} |
| | | setDidClickSprite={props.setDidClickSprite} |
| | | onSubmit={props.onSubmit} |
| | | configForm={configForm} |
| | | /> |
| | | ), |
| | | }; |
| | | |
| | | const handleCancel = () => { |
| | | props.onCancel(); |
| | | }; |
| | | |
| | | const handleOk = () => { |
| | | form.submit(); |
| | | } |
| | | |
| | | const handleFinish = async (values) => { |
| | | props.onSubmit({ ...values }); |
| | | } |
| | | |
| | | const formValuesChange = (value) => { |
| | | switch (value) { |
| | | case 'male': |
| | | break; |
| | | default: |
| | | break; |
| | | if (activeTabKey === 'map') { |
| | | mapForm.submit(); |
| | | } |
| | | if (activeTabKey === 'config') { |
| | | configForm.submit(); |
| | | } |
| | | } |
| | | |
| | | const onFinishFailed = (errorInfo) => { |
| | | }; |
| | | |
| | | |
| | | |
| | | const prefixSelector = ( |
| | | <Form.Item name="prefix" noStyle> |
| | | <Select |
| | | style={{ |
| | | width: 70, |
| | | }} |
| | | > |
| | | <Option value="86">+86</Option> |
| | | <Option value="87">+87</Option> |
| | | </Select> |
| | | </Form.Item> |
| | | ); |
| | | |
| | | return ( |
| | | <> |
| | |
| | | <Button onClick={handleCancel}> |
| | | <FormattedMessage id='common.cancel' defaultMessage='取消' /> |
| | | </Button> |
| | | <Button onClick={handleOk} type="primary"> |
| | | <Button hidden={activeTabKey === 'map' || activeTabKey === 'config'} onClick={handleOk} type="primary"> |
| | | <FormattedMessage id='common.submit' defaultMessage='保存' /> |
| | | </Button> |
| | | </Space> |
| | | } |
| | | > |
| | | <Form |
| | | form={form} |
| | | onFieldsChange={formValuesChange} |
| | | initialValues={{ |
| | | <Card |
| | | hoverable |
| | | bordered={false} |
| | | type='inner' |
| | | tabList={[ |
| | | { |
| | | key: 'map', |
| | | tab: intl.formatMessage({ id: 'map.settings.map.param', defaultMessage: '地图参数' }), |
| | | icon: <BorderOuterOutlined /> |
| | | |
| | | }, |
| | | { |
| | | key: 'config', |
| | | tab: intl.formatMessage({ id: 'map.settings.config.param', defaultMessage: '系统参数' }), |
| | | icon: <BranchesOutlined /> |
| | | }, |
| | | ]} |
| | | activeTabKey={activeTabKey} |
| | | onTabChange={(key) => { |
| | | setActiveTabKey(key) |
| | | }} |
| | | onFinish={handleFinish} |
| | | onFinishFailed={onFinishFailed} |
| | | autoComplete="off" |
| | | style={{ |
| | | maxWidth: 600, |
| | | tabProps={{ |
| | | centered: true, |
| | | size: 'large', |
| | | type: "card", |
| | | style: { |
| | | } |
| | | }} |
| | | size='default' // small | default | large |
| | | variant='filled' // outlined | borderless | filled |
| | | labelWrap // label 换行 |
| | | disabled={false} |
| | | > |
| | | <Row gutter={24}> |
| | | <Col span={6}> |
| | | <Form.Item label="Plain Text"> |
| | | <span className="ant-form-text">China</span> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={12}> |
| | | <Form.Item |
| | | label="Username" |
| | | name="username" |
| | | hasFeedback |
| | | validateTrigger="onBlur" |
| | | validateDebounce={1000} |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | } |
| | | ]} |
| | | > |
| | | <Input disabled={false} /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={24}> |
| | | <Form.Item |
| | | label="InputNumber" |
| | | > |
| | | <InputNumber /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={24}> |
| | | <Form.Item |
| | | label="Switch" |
| | | valuePropName="checked" |
| | | > |
| | | <Switch /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={24}> |
| | | <Form.Item name="slider" label="Slider"> |
| | | <Slider |
| | | marks={{ |
| | | 0: 'A', |
| | | 20: 'B', |
| | | 40: 'C', |
| | | 60: 'D', |
| | | 80: 'E', |
| | | 100: 'F', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={24}> |
| | | <Form.Item label="Memo"> |
| | | <Input.TextArea /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={24}> |
| | | <Form.Item label="Address"> |
| | | <Space.Compact> |
| | | <Form.Item |
| | | name={['address', 'province']} |
| | | noStyle |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | message: 'Province is required', |
| | | }, |
| | | ]} |
| | | > |
| | | <Select placeholder="Select province"> |
| | | <Option value="Zhejiang">Zhejiang</Option> |
| | | <Option value="Jiangsu">Jiangsu</Option> |
| | | </Select> |
| | | </Form.Item> |
| | | <Form.Item |
| | | name={['address', 'street']} |
| | | noStyle |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | message: 'Street is required', |
| | | }, |
| | | ]} |
| | | > |
| | | <Input |
| | | style={{ |
| | | width: '50%', |
| | | }} |
| | | placeholder="Input street" |
| | | /> |
| | | </Form.Item> |
| | | </Space.Compact> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={24}> |
| | | <Form.Item |
| | | name="phone" |
| | | label="Phone Number" |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | message: 'Please input your phone number!', |
| | | }, |
| | | ]} |
| | | > |
| | | <Input |
| | | addonBefore={prefixSelector} |
| | | style={{ |
| | | width: '100%', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | {contentList[activeTabKey]} |
| | | </Card> |
| | | |
| | | |
| | | |
| | | </Row> |
| | | </Form> |
| | | </Drawer> |
| | | </Drawer > |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | export default SpriteSettings; |
| | | export default Settings; |