Sign.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {ProForm, ProFormInstance, ProFormSelect, ProFormText} from '@ant-design/pro-components';
  2. import {message} from 'antd';
  3. import React, {useRef} from 'react';
  4. import {getConfigGetApi, postConfigSaveApi} from "@/services/swagger/configAdmin";
  5. const options = [
  6. {
  7. value: '1',
  8. label: '紫币',
  9. },
  10. {
  11. value: '2',
  12. label: '紫晶',
  13. },
  14. ]
  15. type SignSetting = {
  16. dayCnt: number;
  17. awardCnt: number;
  18. awardType: number;
  19. };
  20. export default () => {
  21. const formRef = useRef<ProFormInstance>();
  22. const days = Array.from({length: 7}, (_, i) => i + 1);
  23. return (
  24. <ProForm
  25. layout="horizontal"
  26. title="签到设置"
  27. formRef={formRef}
  28. submitter={{}}
  29. request={async () => {
  30. const res = await getConfigGetApi({"code": "platform.sign.award"})
  31. if (res.success && res.data.content) {
  32. const result: SignSetting[] = JSON.parse(res.data.content)
  33. return result.reduce((acc: any, item: SignSetting) => {
  34. acc[`day${item.dayCnt}AwardCnt`] = item.awardCnt;
  35. acc[`day${item.dayCnt}AwardType`] = item.awardType.toString();
  36. return acc;
  37. }, {});
  38. }
  39. return Promise.resolve({});
  40. }}
  41. onFinish={async (values) => {
  42. const result: SignSetting[] = days.map(day => ({
  43. dayCnt: day,
  44. awardCnt: values[`day${day}AwardCnt`],
  45. awardType: values[`day${day}AwardType`],
  46. }));
  47. console.log("value " + values);
  48. console.log("result " + result);
  49. const res = await postConfigSaveApi({
  50. "type": "json",
  51. "code": "platform.sign.award",
  52. "remark": "签到奖励配置",
  53. "content": JSON.stringify(result)
  54. })
  55. if (res.success) {
  56. message.success('提交成功');
  57. } else {
  58. message.error(res.errorMessage)
  59. }
  60. return res.success;
  61. }}
  62. >
  63. {days.map(day => (
  64. <ProForm.Group key={day}>
  65. <ProFormText name={`day${day}AwardCnt`} width="md" label={`第${day}天`}/>
  66. <ProFormSelect name={`day${day}AwardType`} options={options} initialValue="1" width="xs"/>
  67. </ProForm.Group>
  68. ))}
  69. </ProForm>
  70. );
  71. };