|
|
@@ -6,7 +6,17 @@ import React, {
|
|
|
useState,
|
|
|
} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
-import { Button, Form, Input, Modal, Popconfirm, Table } from "antd";
|
|
|
+import {
|
|
|
+ Button,
|
|
|
+ Form,
|
|
|
+ Input,
|
|
|
+ Modal,
|
|
|
+ Popconfirm,
|
|
|
+ Radio,
|
|
|
+ RadioChangeEvent,
|
|
|
+ Select,
|
|
|
+ Table,
|
|
|
+} from "antd";
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
import { RootState } from "@/store";
|
|
|
import { RulesTableType } from "@/types";
|
|
|
@@ -36,6 +46,31 @@ function A1Rule() {
|
|
|
|
|
|
const [surScoreLimit, setSurScoreLimit] = useState({} as any);
|
|
|
|
|
|
+ const addMonths = useCallback((date: any, months: string) => {
|
|
|
+ // 复制传入的日期对象以避免修改原始对象
|
|
|
+ var result = new Date(date.getTime());
|
|
|
+ console.log(timestampToDate(result));
|
|
|
+
|
|
|
+ // 增加月份,同时处理由于增加月份可能导致的日期溢出问题
|
|
|
+ result.setDate(result.getDate() + parseInt(months));
|
|
|
+
|
|
|
+ // // 如果日期溢出(比如2月29日加上1个月),则手动调整到正确的最后一天
|
|
|
+ // if (result.getDate() < date.getDate()) {
|
|
|
+ // result.setDate(0);
|
|
|
+ // }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const changeClearMonth = useCallback(
|
|
|
+ (e: any) => {
|
|
|
+ // @ts-ignore
|
|
|
+ setNewDate(timestampToDate(addMonths(new Date(), e.target.value)));
|
|
|
+ setClearMonth(e.target.value);
|
|
|
+ },
|
|
|
+ [addMonths]
|
|
|
+ );
|
|
|
+
|
|
|
const getList = useCallback(async () => {
|
|
|
dispatch(getRuleAPI("game"));
|
|
|
const onlineRes = await getOnlineRuleAPI("online");
|
|
|
@@ -45,9 +80,13 @@ function A1Rule() {
|
|
|
const res = await getScoreLimitAPI(1);
|
|
|
if (res.code === 0) {
|
|
|
setSurScoreLimit(res.data);
|
|
|
- // alert(res.data)
|
|
|
+ let resetScoreData = JSON.parse(res.data.description);
|
|
|
+ console.log(resetScoreData);
|
|
|
+ setIsClear(resetScoreData.hasReset ? 1 : 2);
|
|
|
+ setClearMonth(resetScoreData.period);
|
|
|
+ changeClearMonth({ target: { value: resetScoreData.period } });
|
|
|
}
|
|
|
- }, [dispatch]);
|
|
|
+ }, [changeClearMonth, dispatch]);
|
|
|
|
|
|
// 积分上限窗口开关
|
|
|
const [limitScoreShow, setLimitScoreShow] = useState(false);
|
|
|
@@ -56,26 +95,70 @@ function A1Rule() {
|
|
|
const editId = useRef(0);
|
|
|
// 编辑模式 1是游戏规则 2是线上展厅
|
|
|
const editMode = useRef(1);
|
|
|
- const openEditPageFu = useCallback(
|
|
|
- (type: number, id: number) => {
|
|
|
- // alert('编辑2')
|
|
|
- editMode.current = type;
|
|
|
- editId.current = id;
|
|
|
- setEditPageShow(true);
|
|
|
- // console.log(editPageShow, editMode.current);
|
|
|
- },
|
|
|
- [editPageShow]
|
|
|
- );
|
|
|
+ const openEditPageFu = useCallback((type: number, id: number) => {
|
|
|
+ // alert('编辑2')
|
|
|
+ editMode.current = type;
|
|
|
+ editId.current = id;
|
|
|
+ setEditPageShow(true);
|
|
|
+ // console.log(editPageShow, editMode.current);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 积分是否清除相关
|
|
|
+ const [isClear, setIsClear] = useState(2);
|
|
|
+ const onChange = (e: RadioChangeEvent) => {
|
|
|
+ // 从转换成是
|
|
|
+ if (e.target.value === 1 && clearMonth === "null") {
|
|
|
+ setClearMonth(undefined);
|
|
|
+ }
|
|
|
+ setIsClear(e.target.value);
|
|
|
+ };
|
|
|
+
|
|
|
+ const [clearMonth, setClearMonth] = useState(undefined);
|
|
|
+ const [newDate, setNewDate] = useState();
|
|
|
+
|
|
|
+ const timestampToDate = (timestamp: any) => {
|
|
|
+ var date = new Date(timestamp);
|
|
|
+ var year = date.getFullYear();
|
|
|
+ var month = ("0" + (date.getMonth() + 1)).slice(-2);
|
|
|
+ var day = ("0" + date.getDate()).slice(-2);
|
|
|
+
|
|
|
+ return year + "年" + month + "月" + day + "日";
|
|
|
+ };
|
|
|
+
|
|
|
+ function getFirstDayOfMonth() {
|
|
|
+ var now = new Date(); // 获取当前时间
|
|
|
+ var year = now.getFullYear(); // 获取当前年份
|
|
|
+ var month = now.getMonth(); // 获取当前月份(注意:月份从0开始,0表示一月)
|
|
|
+
|
|
|
+ return `${year}-${month + 1}-1 00:00:01`; // 返回时间戳
|
|
|
+ }
|
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
- const [form2] = Form.useForm();
|
|
|
|
|
|
const onFinish = useCallback(
|
|
|
async (values: any) => {
|
|
|
+ if (isClear === 1) {
|
|
|
+ if (!clearMonth) {
|
|
|
+ MessageFu.error("积分清零的日数不能为空!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (clearMonth <= 0 || clearMonth > 301) {
|
|
|
+ MessageFu.error("积分清零的日数范围为1-300!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
if (values.numberVal) {
|
|
|
+ let desc = {
|
|
|
+ hasReset: isClear === 1 ? true : false,
|
|
|
+ createTime: isClear === 1 ? getFirstDayOfMonth() : "null",
|
|
|
+ period:
|
|
|
+ isClear === 1 ? parseInt(clearMonth ? clearMonth : "null") : "null",
|
|
|
+ };
|
|
|
+ console.log(desc);
|
|
|
const data = {
|
|
|
...surScoreLimit,
|
|
|
score: values.numberVal,
|
|
|
+ description: JSON.stringify(desc),
|
|
|
};
|
|
|
const res: any = await scoreLimitSaveAPI(data);
|
|
|
if (res.code === 0) {
|
|
|
@@ -85,7 +168,7 @@ function A1Rule() {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- [getList, surScoreLimit]
|
|
|
+ [clearMonth, getList, isClear, surScoreLimit]
|
|
|
);
|
|
|
|
|
|
const columns = useMemo(() => {
|
|
|
@@ -185,7 +268,9 @@ function A1Rule() {
|
|
|
<>
|
|
|
<div className={styles.A1Rule}>
|
|
|
<div className="ruleTop">
|
|
|
- <div className="pageTitle">游戏规则 <span>游戏规则需用户刷新浏览器后生效</span></div>
|
|
|
+ <div className="pageTitle">
|
|
|
+ 游戏规则 <span>游戏规则需用户刷新浏览器后生效</span>
|
|
|
+ </div>
|
|
|
<button
|
|
|
className="scoreLimitBtn"
|
|
|
onClick={() => {
|
|
|
@@ -193,7 +278,8 @@ function A1Rule() {
|
|
|
setLimitScoreShow(true);
|
|
|
}}
|
|
|
>
|
|
|
- 单日可获得积分上限:<span>{surScoreLimit.score}</span>
|
|
|
+ {/* 单日可获得积分上限:<span>{surScoreLimit.score}</span> */}
|
|
|
+ 其他规则设置
|
|
|
</button>
|
|
|
{/* 表格主体 */}
|
|
|
<div className="tableBox1">
|
|
|
@@ -265,6 +351,80 @@ function A1Rule() {
|
|
|
placeholder="请输入正整数,不超过999999999"
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ label="积分清零"
|
|
|
+ name="isClear"
|
|
|
+ style={{ marginTop: "40px" }}
|
|
|
+ initialValue={isClear}
|
|
|
+ rules={[{ required: true, message: "不能为空!" }]}
|
|
|
+ hide-required-asterisk={true}
|
|
|
+ >
|
|
|
+ <Radio.Group onChange={onChange} value={isClear}>
|
|
|
+ <Radio value={1}>是</Radio>
|
|
|
+ <Radio value={2}>否</Radio>
|
|
|
+ </Radio.Group>
|
|
|
+ </Form.Item>
|
|
|
+ {isClear === 1 ? (
|
|
|
+ <Form.Item
|
|
|
+ label=""
|
|
|
+ name="clearMonth"
|
|
|
+ style={{ marginTop: "-15px", marginLeft: "30%" }}
|
|
|
+ hide-required-asterisk={true}
|
|
|
+ getValueFromEvent={(e) =>
|
|
|
+ e.target.value.replace(/^(0+)|[^\d]+/g, "")
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <span style={{ color: "red", marginRight: "10px" }}>*</span>每
|
|
|
+ {/* <Select
|
|
|
+ value={clearMonth}
|
|
|
+ onChange={changeClearMonth}
|
|
|
+ placeholder="请选择"
|
|
|
+ options={[
|
|
|
+ { value: "1", label: "1" },
|
|
|
+ { value: "2", label: "2" },
|
|
|
+ { value: "3", label: "3" },
|
|
|
+ { value: "4", label: "4" },
|
|
|
+ { value: "5", label: "5" },
|
|
|
+ { value: "6", label: "6" },
|
|
|
+ { value: "7", label: "7" },
|
|
|
+ { value: "8", label: "8" },
|
|
|
+ { value: "9", label: "9" },
|
|
|
+ { value: "10", label: "10" },
|
|
|
+ { value: "11", label: "11" },
|
|
|
+ { value: "12", label: "12" },
|
|
|
+ ]}
|
|
|
+ style={{
|
|
|
+ width: "130px",
|
|
|
+ height: "30px",
|
|
|
+ margin: "0 5px",
|
|
|
+ }}
|
|
|
+ /> */}
|
|
|
+ <Input
|
|
|
+ style={{
|
|
|
+ width: "150px",
|
|
|
+ height: "30px",
|
|
|
+ margin: "0 5px",
|
|
|
+ }}
|
|
|
+ defaultValue={clearMonth}
|
|
|
+ maxLength={3}
|
|
|
+ onChange={changeClearMonth}
|
|
|
+ placeholder="请选择数字,1-300"
|
|
|
+ />
|
|
|
+ 个自然日清空一次
|
|
|
+ {clearMonth ? (
|
|
|
+ <div
|
|
|
+ style={{
|
|
|
+ color: "gray",
|
|
|
+ marginTop: "10px",
|
|
|
+ marginLeft: "5%",
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 将在{newDate}清空积分
|
|
|
+ </div>
|
|
|
+ ) : null}
|
|
|
+ </Form.Item>
|
|
|
+ ) : null}
|
|
|
{/* 确定和取消按钮 */}
|
|
|
<br />
|
|
|
<Form.Item wrapperCol={{ offset: 9, span: 16 }}>
|
|
|
@@ -278,6 +438,7 @@ function A1Rule() {
|
|
|
cancelText="取消"
|
|
|
onConfirm={() => {
|
|
|
setLimitScoreShow(false);
|
|
|
+ getList();
|
|
|
}}
|
|
|
okButtonProps={{ loading: false }}
|
|
|
>
|