index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { useAjax } from '@/Hook/useAjax';
  2. import { apiDistributorInfoList } from '@/services/distribution/info';
  3. import {
  4. apiShortBookInfoAllList,
  5. apiShortBookInfoBookConfig,
  6. apiShortBookInfoConfigDetail,
  7. apiShortBookInfoList,
  8. } from '@/services/distribution/shortBook';
  9. import {
  10. ActionType,
  11. BetaSchemaForm,
  12. PageContainer,
  13. ProFormInstance,
  14. ProTable,
  15. } from '@ant-design/pro-components';
  16. import { useModel } from '@umijs/max';
  17. import { message } from 'antd';
  18. import { useEffect, useRef, useState } from 'react';
  19. import formConfig from './formConfig';
  20. import { columns } from './tableConfig';
  21. type DataItem = {
  22. name: string;
  23. state: string;
  24. };
  25. const Page: React.FC = () => {
  26. let { state, getLabelAndClassList } = useModel('global');
  27. const formRef = useRef<ProFormInstance>();
  28. const actionRef = useRef<ActionType>();
  29. let [workDirection, setWorkDirection] = useState<any>(null);
  30. let [open, setOpen] = useState<any>(null); //新增作者
  31. let [editValues, setEditValues] = useState<any>({});
  32. // ======================API=======================
  33. let DistributorInfoList = useAjax((params) => apiDistributorInfoList(params)); //分销商列表
  34. let BookInfoList = useAjax((params) => apiShortBookInfoList(params), { type: 'table' }); //获取书籍列表
  35. let BookInfoBookConfig = useAjax((params) => apiShortBookInfoBookConfig(params)); //小说信息配置
  36. let BookInfoChapterAllList = useAjax((id) => apiShortBookInfoAllList(id)); //全部列表无分页
  37. let BookInfoConfigDetail = useAjax((id) => apiShortBookInfoConfigDetail(id)); //小说配置详情
  38. // 获取标签和分类
  39. useEffect(() => {
  40. getLabelAndClassList({ workDirection });
  41. }, [workDirection]);
  42. // 编辑
  43. const edit = (item: any) => {
  44. DistributorInfoList.run();
  45. BookInfoChapterAllList.run(item.bookId).then((res) => {
  46. setOpen(true);
  47. BookInfoConfigDetail.run(item.bookId).then((dres) => {
  48. console.log(dres.data, item);
  49. setEditValues(dres.data);
  50. formRef?.current?.setFieldsValue({ ...dres.data });
  51. });
  52. });
  53. };
  54. //编辑
  55. const submit = async (values: any) => {
  56. if (editValues?.id) {
  57. values.id = editValues?.id;
  58. }
  59. if (values.bookDistributorConfig) {
  60. values.bookDistributorConfig = values.bookDistributorConfig?.map((item: any) => {
  61. return { ...item, bookId: editValues.bookId };
  62. });
  63. }
  64. if (!values?.bookId) {
  65. values.bookId = editValues.bookId
  66. }
  67. BookInfoBookConfig.run(values).then((res) => {
  68. if (res.code === 200) {
  69. actionRef?.current?.reload();
  70. message.success('操作成功!');
  71. closeForm(false);
  72. }
  73. });
  74. console.log(values);
  75. };
  76. // 关闭表单弹窗和重置表单内容
  77. const closeForm = (b: boolean, values?: any) => {
  78. if (!b) {
  79. setEditValues({});
  80. formRef?.current?.resetFields?.();
  81. setOpen(b);
  82. } else {
  83. }
  84. };
  85. return (
  86. <PageContainer>
  87. <ProTable<any, any>
  88. headerTitle={'短篇小说配置信息列表'}
  89. actionRef={actionRef}
  90. rowKey={(r) => r.bookId}
  91. // 搜索的配置
  92. search={{
  93. labelWidth: 90,
  94. searchGutter: [10, 15],
  95. }}
  96. request={async (params) => {
  97. return await BookInfoList.run(params);
  98. }}
  99. scroll={{ x: 'auto' }}
  100. columns={columns({
  101. authList: state?.authList,
  102. labelList: state.labelList,
  103. categoryList: state.categoryList,
  104. enumList: state?.enumList,
  105. setWorkDirection,
  106. edit,
  107. })}
  108. // bordered
  109. />
  110. <BetaSchemaForm<DataItem>
  111. title={"信息配置"}
  112. formRef={formRef}
  113. width={900}
  114. open={open}
  115. onOpenChange={(b) => {
  116. !b && closeForm(b);
  117. }}
  118. layoutType={'ModalForm'}
  119. labelCol={{ span: 8 }}
  120. wrapperCol={{ span: 14 }}
  121. grid={true}
  122. layout="horizontal"
  123. onFinish={submit}
  124. columns={formConfig({
  125. enumList: state?.enumList,
  126. bookList: BookInfoChapterAllList?.data?.data,
  127. distributorInfoList: DistributorInfoList?.data?.data,
  128. })}
  129. loading={BookInfoBookConfig?.loading}
  130. />
  131. </PageContainer>
  132. );
  133. };
  134. export default Page;