antd#Rate JavaScript Examples
The following examples show how to use
antd#Rate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From scalable-form-platform with MIT License | 6 votes |
render() {
const {schema, options, value, disabled, readonly} = this.props;
const {currentRateLabel} = this.state;
let enumOptions = options.enumOptions || [];
if (typeof schema.data !== 'undefined' && schema.data.length >= 0) {
enumOptions = schema.data;
}
//解析schema中约定的_errorType字段,用来标识是validate中哪种类型校验不通过
let validateMessage = '';
const _errorType = options._errorType || '';
if (_errorType !== '' && typeof options.validate !== 'undefined') {
validateMessage = this._getValidateMessage(_errorType, options.validate);
}
return (
<div className={classnames({
'ant-form-item-control': true,
'xform-custom-widget': true,
'xform-custom-rate': true,
'has-error': _errorType !== ''
})}>
<div>
<Rate
count={enumOptions.length}
disabled={disabled}
readOnly={readonly}
value={this.getRateNumberFromValue(value)}
onHoverChange={this.handleRateHoverChange}
onChange={this.handleRateNumberChange}
/>
<span>{currentRateLabel}</span>
</div>
<div className="ant-form-explain">{validateMessage}</div>
</div>
);
}
Example #2
Source File: text.jsx From virtuoso-design-system with MIT License | 6 votes |
render() {
const { value } = this.state;
return (
<span>
<Rate tooltips={desc} onChange={this.handleChange} value={value} />
{value ? <span className="ant-rate-text">{desc[value - 1]}</span> : ''}
</span>
);
}
Example #3
Source File: clear.jsx From virtuoso-design-system with MIT License | 6 votes |
storiesOf('antd/rate', module).add('clear', () =>
<>
<Rate defaultValue={3} />
<span className="ant-rate-text">allowClear: true</span>
<br />
<Rate allowClear={false} defaultValue={3} />
<span className="ant-rate-text">allowClear: false</span>
</>,
{ docs: { page: () => (<><h1 id="enus">en-US</h1>
<p>Support set allow to clear star when click again.</p></>) } });
Example #4
Source File: character.jsx From virtuoso-design-system with MIT License | 6 votes |
storiesOf('antd/rate', module).add('character', () =>
<>
<Rate character={<HeartOutlined />} allowHalf />
<br />
<Rate character="A" allowHalf style={{ fontSize: 36 }} />
<br />
<Rate character="好" allowHalf />
</>,
{ docs: { page: () => (<><h1 id="enus">en-US</h1>
<p>Replace the default star to other character like alphabet, digit, iconfont or even Chinese word.</p></>) } });
Example #5
Source File: index.js From gobench with Apache License 2.0 | 6 votes |
render() {
return (
<div>
<h5 className="mb-3">
<strong>Basic</strong>
</h5>
<div className="mb-3">
<Rate defaultValue={3} />
</div>
<div className="mb-3">
<span>
<Rate allowHalf defaultValue={2.5} tooltips="good" />
<span className="ant-rate-text">good</span>
</span>
</div>
<div className="mb-3">
<Rate defaultValue={3} character="W" />
</div>
</div>
)
}
Example #6
Source File: basic.jsx From virtuoso-design-system with MIT License | 5 votes |
storiesOf('antd/rate', module).add('basic', () => <Rate />, { docs: { page: () => (<><h1 id="enus">en-US</h1>
<p>The simplest usage.</p></>) } });
Example #7
Source File: character-function.jsx From virtuoso-design-system with MIT License | 5 votes |
storiesOf('antd/rate', module).add('character-function', () =>
<>
<Rate defaultValue={2} character={({ index }) => index + 1} />
<br />
<Rate defaultValue={3} character={({ index }) => customIcons[index + 1]} />
</>,
{ docs: { page: () => (<><h1 id="enus">en-US</h1>
<p>Can customize each character using <code>(RateProps) => ReactNode</code>.</p></>) } });
Example #8
Source File: Rating.js From label-studio-frontend with Apache License 2.0 | 5 votes |
HtxRating = inject("store")(
observer(({ item, store }) => {
let iconSize;
if (item.size === "small") {
iconSize = 15;
} else if (item.size === "medium") {
iconSize = 25;
} else if (item.size === "large") {
iconSize = 40;
}
const visibleStyle = item.perRegionVisible() ? {} : { display: "none" };
// rc-rate component listens for keypress event and hit the star if the key is Enter
// but it doesn't check for any modifiers, so it removes star during submit (ctrl+enter)
// so we'll just remove focus from component at the moment any modifier pressed
const dontBreakSubmit = e => {
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) {
// should be a star, because that's the only way this event can happen
const star = document.activeElement;
const control = e.currentTarget;
// but we'll check that for sure
if (control.contains(star)) star.blur();
}
};
return (
<div style={visibleStyle} onKeyDownCapture={dontBreakSubmit}>
<Rate
character={<StarOutlined style={{ fontSize: iconSize }} />}
value={item.rating}
count={Number(item.maxrating)}
defaultValue={Number(item.defaultvalue)}
onChange={item.setRating}
/>
{store.settings.enableTooltips && store.settings.enableHotkeys && item.hotkey && (
<sup style={{ fontSize: "9px" }}>[{item.hotkey}]</sup>
)}
</div>
);
}),
)
Example #9
Source File: disabled.jsx From virtuoso-design-system with MIT License | 5 votes |
storiesOf('antd/rate', module).add('disabled', () => <Rate disabled defaultValue={2} />, { docs: { page: () => (<><h1 id="enus">en-US</h1>
<p>Read only, can't use mouse to interact.</p></>) } });
Example #10
Source File: half.jsx From virtuoso-design-system with MIT License | 5 votes |
storiesOf('antd/rate', module).add('half', () => <Rate allowHalf defaultValue={2.5} />, { docs: { page: () => (<><h1 id="enus">en-US</h1>
<p>Support select half star.</p></>) } });
Example #11
Source File: editForm.jsx From react-antd-admin-template with MIT License | 5 votes |
render() {
const {
visible,
onCancel,
onOk,
form,
confirmLoading,
currentRowData,
} = this.props;
const { getFieldDecorator } = form;
const { id, author, date, readings, star, status, title } = currentRowData;
const formItemLayout = {
labelCol: {
sm: { span: 4 },
},
wrapperCol: {
sm: { span: 16 },
},
};
return (
<Modal
title="编辑"
visible={visible}
onCancel={onCancel}
onOk={onOk}
confirmLoading={confirmLoading}
>
<Form {...formItemLayout}>
<Form.Item label="序号:">
{getFieldDecorator("id", {
initialValue: id,
})(<Input disabled />)}
</Form.Item>
<Form.Item label="标题:">
{getFieldDecorator("title", {
rules: [{ required: true, message: "请输入标题!" }],
initialValue: title,
})(<Input placeholder="标题" />)}
</Form.Item>
<Form.Item label="作者:">
{getFieldDecorator("author", {
initialValue: author,
})(<Input disabled />)}
</Form.Item>
<Form.Item label="阅读量:">
{getFieldDecorator("readings", {
initialValue: readings,
})(<Input disabled />)}
</Form.Item>
<Form.Item label="推荐指数:">
{getFieldDecorator("star", {
initialValue: star.length,
})(<Rate count={3} />)}
</Form.Item>
<Form.Item label="状态:">
{getFieldDecorator("status", {
initialValue: status,
})(
<Select style={{ width: 120 }}>
<Select.Option value="published">published</Select.Option>
<Select.Option value="draft">draft</Select.Option>
</Select>
)}
</Form.Item>
<Form.Item label="时间:">
{getFieldDecorator("date", {
rules: [{ type: 'object', required: true, message: '请选择时间!' }],
initialValue: moment(date || "YYYY-MM-DD HH:mm:ss"),
})(<DatePicker showTime format="YYYY-MM-DD HH:mm:ss" />)}
</Form.Item>
</Form>
</Modal>
);
}
Example #12
Source File: index.js From pretty-derby with GNU General Public License v3.0 | 5 votes |
SearchOne = (props) => {
return (
<Form.List name={props.name}>
{(fields, { add, remove }, { errors }) => (
<>
<Row>
{fields.map((field, index) => (
<Col key={field.key} lg={8} md={12} xs={24}>
<Row>
<Form.Item
{...field}
name={[field.name, "attr"]}
fieldKey={[field.fieldKey, "attr"]}
rules={[{ required: true }]}
validateTrigger={["onChange", "onBlur"]}
noStyle
>
<Radio.Group>
<Radio.Button value={"speed"}>{"速度"}</Radio.Button>
<Radio.Button value={"stamina"}>{"耐力"}</Radio.Button>
<Radio.Button value={"power"}>{"力量"}</Radio.Button>
<Radio.Button value={"guts"}>{"根性"}</Radio.Button>
<Radio.Button value={"wisdom"}>{"智力"}</Radio.Button>
<br />
<Radio.Button value={"grass"}>{"草地/芝"}</Radio.Button>
<Radio.Button value={"dirt"}>{"泥地/ダート"}</Radio.Button>
<br />
<Radio.Button value={"shortDistance"}>{"短距离"}</Radio.Button>
<Radio.Button value={"mile"}>{"英里"}</Radio.Button>
<Radio.Button value={"mediumDistance"}>{"中距离"}</Radio.Button>
<Radio.Button value={"longDistance"}>{"长距离"}</Radio.Button>
<br />
<Radio.Button value={"escapeR"}>{"逃"}</Radio.Button>
<Radio.Button value={"leadingR"}>{"先"}</Radio.Button>
<Radio.Button value={"insertR"}>{"差"}</Radio.Button>
<Radio.Button value={"trackingR"}>{"追"}</Radio.Button>
<br />
<Radio.Button value={"uraLevel"}>{"URA"}</Radio.Button>
</Radio.Group>
</Form.Item>
</Row>
<Row>
<Form.Item
{...field}
name={[field.name, "level"]}
fieldKey={[field.fieldKey, "level"]}
rules={[{ required: true }]}
>
<Rate count={props.max} />
</Form.Item>
</Row>
<Col span={5}>
<Button type="dashed" onClick={() => remove(field.name)}>
移除
</Button>
</Col>
</Col>
))}
</Row>
<Row justify="start">
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
// style={{ width: '60%' }}
icon={<PlusOutlined />}
>
添加过滤条件
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</Row>
</>
)}
</Form.List>
);
}
Example #13
Source File: index.js From pretty-derby with GNU General Public License v3.0 | 5 votes |
SearchForm = (props) => {
const [form] = Form.useForm();
const onFinish = async (value) => {
let formData = { attrs: [], levels: [] };
if (value["player0"]) {
formData.attrs.push("playerId0");
formData.levels.push(value["player0"].id);
}
if (value["supportLevel"]) {
formData.attrs.push("supportLevel");
formData.levels.push(value["supportLevel"]);
}
if (value["support"]) {
formData.attrs.push("supportId");
formData.levels.push(value["support"].id);
}
value.p0?.forEach((item) => {
if (SEED_BLUE_LABELS[item.attr]) {
formData["blue0"] = item.attr;
formData.attrs.push("blueLevel0");
formData.levels.push(item.level);
} else if (SEED_RED_LABELS[item.attr]) {
formData["red0"] = item.attr;
formData.attrs.push("redLevel0");
formData.levels.push(item.level);
} else if (item.attr === "uraLevel") {
formData.attrs.push("uraLevel0");
formData.levels.push(item.level);
}
});
value.p1?.forEach((item) => {
formData.attrs.push(item.attr);
formData.levels.push(item.level);
});
props.search(formData);
};
const onReset = () => {
form.resetFields();
};
return (
<Form name="搜索" form={form} onFinish={onFinish} className="seed-form">
<Row>
<Form.Item label="角色" name={`player0`}>
<PlayerInput />
</Form.Item>
</Row>
<SearchOne name="p0" max="3" />
<div>总计:</div>
<SearchOne name="p1" max="9" />
<Row>
<Form.Item label="支援卡" name={"support"}>
<SupportInput />
</Form.Item>
<Form.Item label="突破等级" name={"supportLevel"} initialValue={0}>
<Rate count={4} />
</Form.Item>
</Row>
<Row justify="end">
<Form.Item>
<Button htmlType="button" onClick={() => onReset()}>
重置
</Button>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
搜索
</Button>
</Form.Item>
</Row>
</Form>
);
}
Example #14
Source File: index.js From pretty-derby with GNU General Public License v3.0 | 5 votes |
SearchForm = (props) => {
const { t } = useTranslation();
const [form] = Form.useForm();
const onFinish = async (value) => {
let formData = { attrs: [], levels: [] };
if (value["player0"]) {
formData.attrs.push("playerId0");
formData.levels.push(value["player0"].id);
}
if (value["support"]) {
formData.attrs.push("supportId");
formData.levels.push(value["support"].id);
}
value.p1?.forEach((item) => {
formData.attrs.push(item.attr[0]);
formData.levels.push(item.attr[1]);
});
props.search(formData);
};
const onReset = () => {
form.resetFields();
};
return (
<Form name="搜索" form={form} onFinish={onFinish} className="seed-form w-full">
<SearchOne name="p1" />
<div className="grid grid-cols-4 w-full " align="start">
<div>
{t("角色")}
<Form.Item name={`player0`}>
<PlayerInput />
</Form.Item>
</div>
<div>
{t("支援卡")}
<Form.Item name={"support"}>
<SupportInput />
</Form.Item>
</div>
<div className="col-span-2">
{t("突破等级")}
<Form.Item name={"supportLevel"} initialValue={0}>
<Rate count={4} />
</Form.Item>
</div>
</div>
<div className="flex justify-end">
<Form.Item>
<Button htmlType="button" onClick={() => onReset()}>
{t("重置")}
</Button>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
{t("搜索")}
</Button>
</Form.Item>
</div>
</Form>
);
}
Example #15
Source File: direction.jsx From virtuoso-design-system with MIT License | 4 votes |
// ==== End Badge ====
render() {
const { currentStep } = this.state;
return (
<div className="direction-components">
<Row>
<Col span={24}>
<Divider orientation="left">Cascader example</Divider>
<Cascader
suffixIcon={<SearchIcon />}
options={cascaderOptions}
onChange={this.onCascaderChange}
placeholder="یک مورد انتخاب کنید"
popupPlacement={this.props.popupPlacement}
/>
With search:
<Cascader
suffixIcon={<SmileOutlined />}
options={cascaderOptions}
onChange={this.onCascaderChange}
placeholder="Select an item"
popupPlacement={this.props.popupPlacement}
showSearch={this.cascaderFilter}
/>
</Col>
</Row>
<br />
<Row>
<Col span={12}>
<Divider orientation="left">Switch example</Divider>
<Switch defaultChecked />
<Switch loading defaultChecked />
<Switch size="small" loading />
</Col>
<Col span={12}>
<Divider orientation="left">Radio Group example</Divider>
<Radio.Group defaultValue="c" buttonStyle="solid">
<Radio.Button value="a">تهران</Radio.Button>
<Radio.Button value="b" disabled>
اصفهان
</Radio.Button>
<Radio.Button value="c">فارس</Radio.Button>
<Radio.Button value="d">خوزستان</Radio.Button>
</Radio.Group>
</Col>
</Row>
<br />
<Row>
<Col span={12}>
<Divider orientation="left">Button example</Divider>
<div className="button-demo">
<Button type="primary" icon={<DownloadOutlined />} />
<Button type="primary" shape="circle" icon={<DownloadOutlined />} />
<Button type="primary" shape="round" icon={<DownloadOutlined />} />
<Button type="primary" shape="round" icon={<DownloadOutlined />}>
Download
</Button>
<Button type="primary" icon={<DownloadOutlined />}>
Download
</Button>
<br />
<Button.Group>
<Button type="primary">
<LeftOutlined />
Backward
</Button>
<Button type="primary">
Forward
<RightOutlined />
</Button>
</Button.Group>
<Button type="primary" loading>
Loading
</Button>
<Button type="primary" size="small" loading>
Loading
</Button>
</div>
</Col>
<Col span={12}>
<Divider orientation="left">Tree example</Divider>
<Tree
showLine
checkable
defaultExpandedKeys={['0-0-0', '0-0-1']}
defaultSelectedKeys={['0-0-0', '0-0-1']}
defaultCheckedKeys={['0-0-0', '0-0-1']}
>
<TreeNode title="parent 1" key="0-0">
<TreeNode title="parent 1-0" key="0-0-0" disabled>
<TreeNode title="leaf" key="0-0-0-0" disableCheckbox />
<TreeNode title="leaf" key="0-0-0-1" />
</TreeNode>
<TreeNode title="parent 1-1" key="0-0-1">
<TreeNode title={<span style={{ color: '#1890ff' }}>sss</span>} key="0-0-1-0" />
</TreeNode>
</TreeNode>
</Tree>
</Col>
</Row>
<br />
<Row>
<Col span={24}>
<Divider orientation="left">Input (Input Group) example</Divider>
<InputGroup size="large">
<Row gutter={8}>
<Col span={5}>
<Input defaultValue="0571" />
</Col>
<Col span={8}>
<Input defaultValue="26888888" />
</Col>
</Row>
</InputGroup>
<br />
<InputGroup compact>
<Input style={{ width: '20%' }} defaultValue="0571" />
<Input style={{ width: '30%' }} defaultValue="26888888" />
</InputGroup>
<br />
<InputGroup compact>
<Select defaultValue="Option1">
<Option value="Option1">Option1</Option>
<Option value="Option2">Option2</Option>
</Select>
<Input style={{ width: '50%' }} defaultValue="input content" />
<InputNumber />
</InputGroup>
<br />
<Search placeholder="input search text" enterButton="Search" size="large" />
<br />
<br />
<div style={{ marginBottom: 16 }}>
<Input
addonBefore={this.selectBefore}
addonAfter={this.selectAfter}
defaultValue="mysite"
/>
</div>
<br />
<Row>
<Col span={12}>
<Divider orientation="left">Select example</Divider>
<Select mode="multiple" defaultValue="مورچه" style={{ width: 120 }}>
<Option value="jack">Jack</Option>
<Option value="مورچه">مورچه</Option>
<Option value="disabled" disabled>
Disabled
</Option>
<Option value="Yiminghe">yiminghe</Option>
</Select>
<Select defaultValue="مورچه" style={{ width: 120 }} disabled>
<Option value="مورچه">مورچه</Option>
</Select>
<Select defaultValue="مورچه" style={{ width: 120 }} loading>
<Option value="مورچه">مورچه</Option>
</Select>
<Select
showSearch
style={{ width: 200 }}
placeholder="Select a person"
optionFilterProp="children"
filterOption={(input, option) =>
option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
>
<Option value="jack">Jack</Option>
<Option value="سعید">سعید</Option>
<Option value="tom">Tom</Option>
</Select>
</Col>
<Col span={12}>
<Divider orientation="left">TreeSelect example</Divider>
<div>
<TreeSelect
showSearch
style={{ width: '100%' }}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
placeholder="Please select"
allowClear
treeDefaultExpandAll
>
<TreeNode value="parent 1" title="parent 1" key="0-1">
<TreeNode value="parent 1-0" title="parent 1-0" key="0-1-1">
<TreeNode value="leaf1" title="my leaf" key="random" />
<TreeNode value="leaf2" title="your leaf" key="random1" />
</TreeNode>
<TreeNode value="parent 1-1" title="parent 1-1" key="random2">
<TreeNode
value="sss"
title={<b style={{ color: '#08c' }}>sss</b>}
key="random3"
/>
</TreeNode>
</TreeNode>
</TreeSelect>
</div>
</Col>
</Row>
<br />
<Row>
<Col span={24}>
<Divider orientation="left">Modal example</Divider>
<div>
<Button type="primary" onClick={this.showModal}>
Open Modal
</Button>
<Modal
title="پنچره ساده"
visible={this.state.modalVisible}
onOk={this.handleOk}
onCancel={this.handleCancel}
>
<p>نگاشتههای خود را اینجا قراردهید</p>
<p>نگاشتههای خود را اینجا قراردهید</p>
<p>نگاشتههای خود را اینجا قراردهید</p>
</Modal>
</div>
</Col>
</Row>
<br />
<Row>
<Col span={24}>
<Divider orientation="left">Steps example</Divider>
<div>
<Steps progressDot current={currentStep}>
<Step title="Finished" description="This is a description." />
<Step title="In Progress" description="This is a description." />
<Step title="Waiting" description="This is a description." />
</Steps>
<br />
<Steps current={currentStep} onChange={this.onStepsChange}>
<Step title="Step 1" description="This is a description." />
<Step title="Step 2" description="This is a description." />
<Step title="Step 3" description="This is a description." />
</Steps>
</div>
</Col>
</Row>
<br />
<Row>
<Col span={12}>
<Divider orientation="left">Rate example</Divider>
<div>
<Rate defaultValue={2.5} />
<br />
<strong>* Note:</strong> Half star not implemented in RTL direction, it will be
supported after <a href="https://github.com/react-component/rate">rc-rate</a>{' '}
implement rtl support.
</div>
</Col>
<Col span={12}>
<Divider orientation="left">Badge example</Divider>
<div>
<div>
<Badge count={this.state.badgeCount}>
<a href="#" className="head-example" />
</Badge>
<ButtonGroup>
<Button onClick={this.declineBadge}>
<MinusOutlined />
</Button>
<Button onClick={this.increaseBadge}>
<PlusOutlined />
</Button>
</ButtonGroup>
</div>
<div style={{ marginTop: 10 }}>
<Badge dot={this.state.showBadge}>
<a href="#" className="head-example" />
</Badge>
<Switch onChange={this.onChangeBadge} checked={this.state.showBadge} />
</div>
</div>
</Col>
</Row>
</Col>
</Row>
<br />
<br />
<Row>
<Col span={24}>
<Divider orientation="left">Pagination example</Divider>
<Pagination showSizeChanger defaultCurrent={3} total={500} />
</Col>
</Row>
<br />
<Row>
<Col span={24}>
<Divider orientation="left">Grid System example</Divider>
<div className="grid-demo">
<div className="code-box-demo">
<p>
<strong>* Note:</strong> Every calculation in RTL grid system is from right side
(offset, push, etc.)
</p>
<Row>
<Col span={8}>col-8</Col>
<Col span={8} offset={8}>
col-8
</Col>
</Row>
<Row>
<Col span={6} offset={6}>
col-6 col-offset-6
</Col>
<Col span={6} offset={6}>
col-6 col-offset-6
</Col>
</Row>
<Row>
<Col span={12} offset={6}>
col-12 col-offset-6
</Col>
</Row>
<Row>
<Col span={18} push={6}>
col-18 col-push-6
</Col>
<Col span={6} pull={18}>
col-6 col-pull-18
</Col>
</Row>
</div>
</div>
</Col>
</Row>
</div>
);
}
Example #16
Source File: index.js From pretty-derby with GNU General Public License v3.0 | 4 votes |
SeedInput = (props) => {
const [form] = Form.useForm();
const [seed, setSeed] = useState({});
const onFinish = async (value) => {
let tmpSeed = seed;
tmpSeed = Object.assign({}, seed, value);
setSeed(tmpSeed);
// 修整成需要的数据
const formData = { ...tmpSeed };
formData.userId = userId || dbL.get("userId").value();
let updateTime = new Date().getTime();
formData.updateTime = updateTime;
formData["playerId0"] = value["player0"].id;
formData["playerId1"] = value["player1"].id;
formData["playerId2"] = value["player2"].id;
formData["supportId"] = value["support"].id;
delete formData["support"];
delete formData["player0"];
delete formData["player1"];
delete formData["player2"];
// formData[formData['blue0']]=formData['blueLevel0']
// formData[formData['red0']]=formData['redLevel0']
let list = ["0", "1", "2"];
list.forEach((i) => {
//统计蓝色因子
if (formData[formData[`blue${i}`]] !== undefined) {
formData[formData[`blue${i}`]] += formData[`blueLevel${i}`];
} else {
formData[formData[`blue${i}`]] = formData[`blueLevel${i}`];
}
//统计红色因子
if (formData[formData[`red${i}`]] !== undefined) {
formData[formData[`red${i}`]] += formData[`redLevel${i}`];
} else {
formData[formData[`red${i}`]] = formData[`redLevel${i}`];
}
//统计红色因子
if (formData["white"] !== undefined) {
formData["white"] += formData[`whiteNum${i}`];
} else {
formData["white"] = formData[`whiteNum${i}`];
}
//统计ura
if (formData["uraLevel"] !== undefined) {
formData["uraLevel"] += formData[`uraLevel${i}`];
} else {
formData["uraLevel"] = formData[`uraLevel${i}`];
}
});
const res = await axios.post("https://urarawin.com/api/sqlite/add", formData);
if (res.data && res.data.success) {
message.info("成功添加");
props.onFinish();
} else {
message.info("有地方出错了");
}
};
const list = ["主要", "父辈1", "父辈2"];
const getFields = () => {
const children = [];
for (let i = 0; i < 3; i++) {
children.push(
<Col span={8} key={i}>
<PageHeader title={`${list[i]}`} />
<Row>
<Col span={6} offset={4}>
<Form.Item label="角色" name={`player${i}`} rules={[{ required: true }]}>
<PlayerInput />
</Form.Item>
</Col>
</Row>
<Form.Item label="蓝色因子" name={`blue${i}`} rules={[{ required: true }]}>
<Radio.Group>
<Radio.Button value={"speed"}>{"速度"}</Radio.Button>
<Radio.Button value={"stamina"}>{"耐力"}</Radio.Button>
<Radio.Button value={"power"}>{"力量"}</Radio.Button>
<Radio.Button value={"guts"}>{"根性"}</Radio.Button>
<Radio.Button value={"wisdom"}>{"智力"}</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item label="蓝色因子星数" name={`blueLevel${i}`} rules={[{ required: true }]}>
<Rate count={3} />
</Form.Item>
<Form.Item label="红色因子" name={`red${i}`} rules={[{ required: true }]}>
<Radio.Group>
<Radio.Button value={"grass"}>{"草地/芝"}</Radio.Button>
<Radio.Button value={"dirt"}>{"泥地/ダート"}</Radio.Button>
<hr />
<Radio.Button value={"shortDistance"}>{"短距离"}</Radio.Button>
<Radio.Button value={"mile"}>{"英里"}</Radio.Button>
<Radio.Button value={"mediumDistance"}>{"中距离"}</Radio.Button>
<Radio.Button value={"longDistance"}>{"长距离"}</Radio.Button>
<hr />
<Radio.Button value={"escapeR"}>{"逃"}</Radio.Button>
<Radio.Button value={"leadingR"}>{"先"}</Radio.Button>
<Radio.Button value={"insertR"}>{"差"}</Radio.Button>
<Radio.Button value={"trackingR"}>{"追"}</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item label="红色因子星数" name={`redLevel${i}`} rules={[{ required: true }]}>
<Rate count={3} />
</Form.Item>
<Form.Item label="绿色因子星数" name={`greenLevel${i}`} initialValue={0}>
<Rate count={3} />
</Form.Item>
<Form.Item label="URA因子星数" name={`uraLevel${i}`} initialValue={0}>
<Rate count={3} />
</Form.Item>
<Form.Item label="白色因子个数" name={`whiteNum${i}`} initialValue={0}>
<Slider min={0} max={10} dots={true} tooltipPlacement={"left"} />
</Form.Item>
</Col>
);
}
return children;
};
return (
<Form name={"因子信息"} form={form} onFinish={onFinish}>
<Alert
message="目前每人只能配置一个种子 自觉维护自己的信息;第一次添加前先刷新 否则可能失败"
type="info"
/>
<Row gutter={24}>{getFields()}</Row>
<Row justify="end">
<Col span={3}>
<Form.Item label="辅助卡" name={"support"} rules={[{ required: true }]}>
<SupportInput />
</Form.Item>
</Col>
<Col span={4} offset={1}>
<Form.Item label="辅助卡突破" name={"supportLevel"} initialValue={0}>
<Rate count={4} />
</Form.Item>
</Col>
<Col span={4} offset={1}>
<Form.Item
label="玩家id"
name="gameId"
rules={[
{ required: true },
({ getFieldValue }) => ({
validator(_, value) {
if (value.match(/^[0-9]\d*$/g) && value.length === 9) {
return Promise.resolve();
}
return Promise.reject(new Error("输入正确的9位数id"));
},
}),
]}
>
<Input placeholder="id" style={{ width: "100%" }} />
</Form.Item>
</Col>
<Col span={2} offset={2}>
<Form.Item>
<Button type="primary" htmlType="submit">
提交
</Button>
</Form.Item>
</Col>
</Row>
</Form>
);
}
Example #17
Source File: index.js From pretty-derby with GNU General Public License v3.0 | 4 votes |
Seed = () => {
document.title = TITLE;
useDidRecover(() => {
document.title = TITLE;
});
const [isSeedInputVisible, setIsSeedInputVisible] = useState(false);
const [seedList, setSeedList] = useState([]);
const [total, setTotal] = useState(0);
// const [current, setCurrent] = useState(0)
const [value, setValue] = useState();
const columns = [
{
title: "玩家id",
dataIndex: "gameId",
key: "gameId",
render: (text, seed) => (
<>
<Row>
<p>{text}</p>
<CopyToClipboard text={text} onCopy={() => message.info("成功")}>
<CopyOutlined />
</CopyToClipboard>
</Row>
<Row align="middle">
<SmileOutlined onClick={() => like(seed)} />
<p>{seed.likes}</p>
</Row>
<Row align="middle">
<FrownOutlined onClick={() => dislike(seed)} />
<p>{seed.dislikes}</p>
</Row>
{seed.userId === userId && (
<Row align="middle">
<DeleteOutlined onClick={() => deleteSeed(seed)} />
</Row>
)}
</>
),
},
{
title: "主要",
dataIndex: "playerId0",
key: "playerId0",
render: (text) => <PlayerImage id={text} />,
},
{
title: "蓝色因子",
dataIndex: "blue0",
key: "blue0",
render: (text, record) => (
<span className="rate-label">{`${SEED_BLUE_LABELS[text]}\xa0\xa0${record["blueLevel0"]}`}</span>
),
},
{
title: "红色因子",
dataIndex: "red0",
key: "red0",
render: (text, record) => (
<span className="rate-label">{`${SEED_RED_LABELS[text]}\xa0\xa0${record["redLevel0"]}`}</span>
),
},
{
title: "绿色因子",
dataIndex: "greenLevel0",
key: "greenLevel0",
render: (text, record) => (
<span className="rate-label">{`固有\xa0\xa0${record["greenLevel0"]}`}</span>
),
},
{
title: "URA",
dataIndex: "uraLevel0",
key: "uraLevel0",
render: (text, record) => (
<span className="rate-label">
{`${record["uraLevel0"] ? `URA ${record["uraLevel0"]}` : ""}`}
</span>
),
},
{
title: "父辈1",
dataIndex: "playerId1",
key: "playerId1",
render: (text) => <PlayerImage id={text} />,
},
{
title: "父辈2",
dataIndex: "playerId2",
key: "playerId2",
render: (text) => <PlayerImage id={text} />,
},
{
title: "总计蓝色",
key: "allBlue",
render: (text, record) =>
Object.keys(SEED_BLUE_LABELS).map((key) => {
if (record[key]) {
return (
<span
key={key}
className="rate-label"
>{`${SEED_BLUE_LABELS[key]}\xa0\xa0${record[key]}`}</span>
);
} else {
return null;
}
}),
},
{
title: "总计红色",
key: "allRed",
render: (text, record) =>
Object.keys(SEED_RED_LABELS).map((key) => {
if (record[key]) {
return (
<span
key={key}
className="rate-label"
>{`${SEED_RED_LABELS[key]}\xa0\xa0${record[key]}`}</span>
);
} else {
return null;
}
}),
},
{ title: "总计URA", dataIndex: "uraLevel", key: "uraLevel", render: (text) => text },
{ title: "总计白色", dataIndex: "white", key: "white", render: (text) => text },
{
title: "支援卡",
dataIndex: "supportId",
key: "supportId",
render: (text) => <SupportImage id={text} />,
},
{
title: "突破等级",
dataIndex: "supportLevel",
key: "supportLevel",
render: (text, record) => (
<Row>
<Rate count={4} value={record["supportLevel"]} disabled />
</Row>
),
},
];
const showSeedInput = (index) => {
setIsSeedInputVisible(true);
};
const closeSeedInput = () => {
setIsSeedInputVisible(false);
};
const showMySeed = () => {
search({ attrs: ["userId"], levels: [userId] });
};
const deleteSeed = async (value) => {
const res = await axios.post("https://urarawin.com/api/sqlite/delete", value);
if (res.data) {
message.info("成功删除");
} else {
message.info("出错了");
}
};
const search = async (value) => {
setValue(value);
const res = await axios.post("https://urarawin.com/api/sqlite/search", value);
// setCurrent(0)
if (res.data) {
if (res.data.count) {
setSeedList([...res.data.list]);
setTotal(res.data.count);
} else {
setSeedList([]);
setTotal(0);
message.info("暂无数据");
}
} else {
message.info("出错了");
}
};
const like = async (seed) => {
if (!userId) {
message.info("刷新后重试");
return;
}
let id = seed.id;
const res = await axios.post("https://urarawin.com/api/sqlite/like", { id, userId });
if (res.data) {
message.info("成功");
seed.likes += 1;
}
setSeedList([...seedList]);
};
const dislike = async (seed) => {
if (!userId) {
message.info("刷新后重试");
return;
}
let id = seed.id;
const res = await axios.post("https://urarawin.com/api/sqlite/dislike", { id, userId });
if (res.data) {
message.info("成功");
seed.dislikes += 1;
}
setSeedList([...seedList]);
};
const onChange = (e) => {
search({
...value,
count: e.total,
offset: e.current * 10 - 10,
});
};
return (
<>
<div className="seed-container">
<Card className="card" title="过滤条件">
<SearchForm search={search} />
<Button onClick={() => showSeedInput()}>配置我的种子</Button>
<Button onClick={() => showMySeed()}>查看我的种子</Button>
</Card>
<Card className="card" title="结果">
<Table
columns={columns}
dataSource={seedList}
onChange={onChange}
pagination={{
pageSize: 10,
total: total,
simple: true,
showQuickJumper: false,
position: ["topRight", "bottomRight"],
}}
rowKey={"id"}
/>
</Card>
</div>
<Modal
visible={isSeedInputVisible}
onOk={closeSeedInput}
onCancel={closeSeedInput}
footer={null}
width={"80%"}
>
<SeedInput onFinish={closeSeedInput} />
</Modal>
</>
);
}