shenwu 8 kuukautta sitten
vanhempi
commit
3133073a64

+ 14 - 5
src/models/global.tsx

@@ -28,7 +28,7 @@ export function reducer(state: State, action: Action) {
             return state;
     }
 }
-export default (): { state: State, init: () => void } => {
+export default (): { state: State, init: () => void, getLabelAndClassList: (params?: { workDirection: number | string }) => Promise<boolean> } => {
     const [state, dispatch] = useReducer(reducer, {})
     let isLoding = false
     const init = async () => {
@@ -38,8 +38,6 @@ export default (): { state: State, init: () => void } => {
         console.log("初始化")
         isLoding = true
         let enumData: any = await enumDictList().then((res) => res.data).catch((err) => { console.log(err) })
-        let labelList = await queryLabelList().then((res) => res.data).catch((err) => { console.log(err) })
-        let categoryList = await queryCategoryList().then((res) => res.data).catch((err) => { console.log(err) })
         let authList = await queryAuthList().then((res) => res.data).catch((err) => { console.log(err) })
         let enumList: { [key: string]: any[] } = {}
         if (enumData) {
@@ -47,11 +45,22 @@ export default (): { state: State, init: () => void } => {
                 enumList[item.name] = item
             })
         }
-        dispatch({ type: "setAll", params: { enumList, labelList, categoryList, authList } })
+        dispatch({ type: "setAll", params: { enumList, authList } })
         isLoding = false
     }
+    const getLabelAndClassList = async (params?: { workDirection: number | string }) => {
+        let labelList = null
+        let categoryList = null
+        if (typeof params?.workDirection === 'number') {
+            labelList = await queryLabelList(params).then((res) => res.data).catch((err) => { console.log(err) })
+            categoryList = await queryCategoryList(params).then((res) => res.data).catch((err) => { console.log(err) })
+        }
+        dispatch({ type: "setAll", params: { ...state, labelList,categoryList } })
+        return true
+    }
     return {
         state,
-        init
+        init,
+        getLabelAndClassList
     }
 }

+ 8 - 2
src/pages/MiniApp/BookManage/Short/formConfig.tsx

@@ -11,7 +11,9 @@ function formConfig(props: { paragraphList?: any[], enumList?: { [key: string]:
             title: '开始付费段落',
             dataIndex: 'beginPayParagraphNo',
             valueType: 'select',
-            valueEnum: { '0': "书币充值", '1': "vip充值" },
+            fieldProps: {
+                showSearch: true, placeholder: '请选择开始收费段落'
+            },
             formItemProps: {
                 style: { marginBottom: 15 },
                 rules: [
@@ -20,6 +22,9 @@ function formConfig(props: { paragraphList?: any[], enumList?: { [key: string]:
                         message: '此项为必填项',
                     },
                 ],
+            },
+            valueEnum: () => {
+                return new Map(paragraphList?.map(item => [item.paragraphNo, item.content]))
             }
         },
         {
@@ -31,7 +36,7 @@ function formConfig(props: { paragraphList?: any[], enumList?: { [key: string]:
             },
             valueEnum: () => {
                 let arr = enumList?.VIP_FREE?.values
-                return arr ? new Map(arr?.map(({ value, description }: any) => [value, description])) : {}
+                return new Map(arr?.map(({ value, description }: any) => [value, description]))
             }
         },
         {
@@ -40,6 +45,7 @@ function formConfig(props: { paragraphList?: any[], enumList?: { [key: string]:
             valueType: 'checkbox',
             fieldProps: {
                 onChange: (value) => {
+                    console.log(value)
                     paymentType[1](value)
                 }
             },

+ 42 - 34
src/pages/MiniApp/BookManage/Short/index.tsx

@@ -1,10 +1,10 @@
-import { BetaSchemaForm, PageContainer, ProFormInstance, ProTable } from "@ant-design/pro-components"
+import { ActionType, BetaSchemaForm, PageContainer, ProFormInstance, ProTable } from "@ant-design/pro-components"
 import { columns } from "./tableConfig"
 import { useAjax } from "@/Hook/useAjax"
 import { useModel } from "@umijs/max"
 import { shortBookInfoList, shortBookInfoParagraphList, shortBookInfoBookConfig, shortBookInfoConfig, shortBookInfoParagraphAllList } from "@/services/miniApp/bookManage"
-import { useMemo, useRef, useState } from "react"
-import { Drawer } from "antd"
+import { useEffect, useMemo, useRef, useState } from "react"
+import { Drawer, message } from "antd"
 import ReadText from "../components/readText"
 import formConfig from "./formConfig"
 const wordCountRanges: any = {
@@ -26,10 +26,11 @@ type DataItem = {
 };
 const Page: React.FC = () => {
     let { initialState } = useModel("@@initialState")
-    let { state } = useModel('global')
+    let { state, getLabelAndClassList } = useModel('global')
     let [open, setOpen] = useState<any>(null)//付费配置
     let [editValues, setEditValues] = useState<any>({})
     let paymentType = useState([])
+    let [workDirection, setWorkDirection] = useState<any>(null)
     const [openBook, setOpneBook] = useState<any>(null)//阅读小说
     let getList = useAjax((params) => shortBookInfoList(params), { type: 'table' })//获取书列表
     let getParagraphList = useAjax((params) => shortBookInfoParagraphList(params))//获取段落内容信息
@@ -37,7 +38,12 @@ const Page: React.FC = () => {
     let add = useAjax((params) => shortBookInfoBookConfig(params))//新增配置
     let configInfo = useAjax((params) => shortBookInfoConfig(params))//获取配置信息
     const formRef = useRef<ProFormInstance>();
-
+    const actionRef = useRef<ActionType>();
+    // 获取标签和分类
+    useEffect(() => {
+         getLabelAndClassList({ workDirection })
+    }, [workDirection])
+    // 接口公共参数
     let publicData = useMemo(() => {
         return {
             miniappId: initialState?.selectApp?.id || "",
@@ -49,27 +55,26 @@ const Page: React.FC = () => {
     // 看小说
     const lookBook = (params: any) => {
         let { id, pageNum, pageSize } = params
-        return getParagraphList.run({ id, pageNum, pageSize, backContent: 1 }).then(res => {
+        return getParagraphList.run({ bookId: id, pageNum, pageSize, backContent: true }).then(res => {
             setOpneBook({ ...res.data, ...params })
             return res.data
         })
     }
     // 提交表单
     const submit = async (values: any) => {
-        if (!values.activateTemplate) {
-            values.activateTemplate = false
-        }
         if (editValues?.id) {
             values.id = editValues?.id
         }
-        console.log(values)
-        // add.run({ ...values, ...publicData }).then(res => {
-        //     if (res.code === 200) {
-        //         getList.refresh()
-        //         message.success(values.id ? "编辑模板成功" : "新建模板成功!")
-        //         closeForm(false)
-        //     }
-        // })
+        if (editValues?.bookId) {
+            values.bookId = editValues?.bookId
+        }
+        add.run({ ...values, ...publicData }).then(res => {
+            if (res.code === 200) {
+                actionRef?.current?.reload()
+                message.success("付费配置成功!")
+                closeForm(false)
+            }
+        })
     }
     // 关闭表单弹窗和重置表单内容
     const closeForm = (b: boolean, values?: any) => {
@@ -80,21 +85,23 @@ const Page: React.FC = () => {
             setOpen(b)
         } else {
             // 获取书全部段落
-            // getParagraphAllList.run(values.bookId).then(res => {
-            //     if (res.code === 200) {
-            setOpen(b)//弹窗开启
-            if (values) {
-                // 获取书付费配置
-                configInfo.run({ bookId: values.bookId, ...publicData }).then(res => {
-                    if (res.code === 200) {
-                        let data = { ...res.data }
-                        setEditValues(data)
-                        formRef?.current?.setFieldsValue(data)
+            getParagraphAllList.run({ bookId: values.bookId, backContent: true }).then(res => {
+                if (res.code === 200) {
+                    setOpen(b)//弹窗开启
+                    if (values) {
+                        // 获取书付费配置
+                        configInfo.run({ bookId: values.bookId, ...publicData }).then(res => {
+                            if (res.code === 200) {
+                                let paymentTypeArr = res.data?.paymentType?.map((i: string) => i + '')
+                                let data = { ...res.data, paymentType: paymentTypeArr }
+                                setEditValues(data)
+                                paymentType[1](paymentTypeArr)
+                                formRef?.current?.setFieldsValue(data)
+                            }
+                        })
                     }
-                })
-            }
-            // }
-            // })
+                }
+            })
         }
     }
     return <PageContainer title={false}
@@ -102,6 +109,7 @@ const Page: React.FC = () => {
     >
         <ProTable<any, any>
             params={publicData}
+            actionRef={actionRef}
             headerTitle={"短篇小说列表"}
             rowKey={(r) => r.bookId}
             search={{
@@ -128,7 +136,7 @@ const Page: React.FC = () => {
             request={async (params) => {
                 return await getList.run(params)
             }}
-            columns={columns({ authList: state?.authList, enumList: state?.enumList, lookBook, closeForm })}
+            columns={columns({ authList: state?.authList, labelList: state.labelList, categoryList: state.categoryList, enumList: state?.enumList, lookBook, closeForm, setWorkDirection })}
         />
         {/* 付费配置 */}
         <BetaSchemaForm<DataItem>
@@ -142,7 +150,7 @@ const Page: React.FC = () => {
             // grid={true}
             layout='horizontal'
             onFinish={submit}
-            columns={formConfig({ enumList: state?.enumList, paymentType })}
+            columns={formConfig({ enumList: state?.enumList, paymentType, paragraphList: getParagraphAllList?.data?.data?.map((item: { paragraphInfo: any }) => item.paragraphInfo) })}
             loading={add?.loading}
         />
         {/* 阅读小说 */}
@@ -154,7 +162,7 @@ const Page: React.FC = () => {
             width={'65%'}
             destroyOnClose={true}
             // getContainer={false}
-            bodyStyle={{ padding: 0 }}
+            styles={{ body: { padding: 0 } }}
             closeIcon={false}
             title={<div style={{ fontSize: 20 }}>{openBook?.bookName ? openBook?.bookName : ""}</div>}
         >

+ 42 - 10
src/pages/MiniApp/BookManage/Short/tableConfig.tsx

@@ -21,8 +21,8 @@ const brightColors = [
     "#FF69B4", // 热粉红色
     "#FF1493"  // 深粉红色
 ];
-export const columns = (props: { authList?: any[], enumList?: { [key: string]: any }, lookBook: (data: any) => void ,closeForm:(b:boolean,d:any)=>void}): ProColumns<any>[] => {
-    let { authList, enumList, lookBook,closeForm } = props
+export const columns = (props: { authList?: any[], labelList?: any[], enumList?: { [key: string]: any }, categoryList?: any[], lookBook: (data: any) => void, closeForm: (b: boolean, d: any) => void, setWorkDirection: (w: any) => void }): ProColumns<any>[] => {
+    let { authList, labelList, categoryList, enumList, lookBook, closeForm, setWorkDirection } = props
     let { styles } = useStyles()
     return enumList?.BOOK_STATUS ? [
         {
@@ -131,9 +131,9 @@ export const columns = (props: { authList?: any[], enumList?: { [key: string]: a
             hideInSearch: true,
             render: (a: any, b: any) => {
                 let arr = getDescriptions(enumList?.PAYMENT_TYPE?.values || [], b?.paymentType || [])
-                return <Space size={[0,5]} wrap>
+                return <Space size={[0, 5]} wrap>
                     {
-                        arr?.map(str=>{
+                        arr?.map(str => {
                             return <Tag bordered={false} key={str}>{str}</Tag>
                         })
                     }
@@ -149,12 +149,12 @@ export const columns = (props: { authList?: any[], enumList?: { [key: string]: a
             align: 'center',
             hideInSearch: true,
             render: (a: any, b) => {
-                return <Badge text={a ? "是" : "否"} status={a ? "processing" : "default"} />
+                return <Badge text={!b?.vipFree ? "是" : "否"} status={!b?.vipFree ? "processing" : "error"} />
             }
         },
         {
             title: '收费金额',
-            tooltip:"收费金额(整本)",
+            tooltip: "收费金额(整本)",
             dataIndex: 'paymentAmount',
             key: 'paymentAmount',
             width: 100,
@@ -164,7 +164,7 @@ export const columns = (props: { authList?: any[], enumList?: { [key: string]: a
         },
         {
             title: '收费书币',
-            tooltip:"收费书币(/千字、/本、/段|章节)",
+            tooltip: "收费书币(/千字、/本、/段|章节)",
             dataIndex: 'paymentCoin',
             key: 'paymentCoin',
             width: 100,
@@ -189,8 +189,8 @@ export const columns = (props: { authList?: any[], enumList?: { [key: string]: a
             ellipsis: true,
             align: 'center',
             hideInSearch: true,
-            render:(a:any,b:any)=>{
-                return <a onClick={()=>{ closeForm(true, b)}}>付费配置</a>
+            render: (a: any, b: any) => {
+                return <a onClick={() => { closeForm(true, b) }}>付费配置</a>
             }
         },
         // 搜索条件
@@ -216,7 +216,11 @@ export const columns = (props: { authList?: any[], enumList?: { [key: string]: a
             dataIndex: 'workDirection',
             valueType: 'segmented',
             hideInTable: true,
-            fieldProps: { type: 'primary', style: { width: 'auto' } },
+            fieldProps: {
+                type: 'primary', style: { width: 'auto' }, onChange: (value) => {
+                    setWorkDirection(value)
+                }
+            },
             colSize: 3,
             initialValue: '',
             valueEnum: () => {
@@ -224,6 +228,34 @@ export const columns = (props: { authList?: any[], enumList?: { [key: string]: a
                 return arr ? new Map([{ value: '', description: "全部" }, ...arr]?.map(({ value, description }: any) => [value, description])) : {}
             }
         },
+        {
+            title: "分类",
+            dataIndex: 'categoryId',
+            valueType: 'segmented',
+            hideInTable: true,
+            hideInSearch: !labelList,
+            fieldProps: { type: 'primary', style: { width: 'auto' } },
+            colSize: 3,
+            initialValue: '',
+            valueEnum: () => {
+                let arr = categoryList || []
+                return new Map([{id:"",name:"全部"},...arr]?.map(item=>[item.id,item.name]))
+            }
+        },
+        {
+            title: "标签",
+            dataIndex: 'labelIds',
+            valueType: 'segmented',
+            hideInTable: true,
+            hideInSearch: !labelList,
+            fieldProps: { type: 'primary', style: { width: 'auto' } },
+            colSize: 3,
+            initialValue: '',
+            valueEnum: () => {
+                let arr = labelList || []
+                return new Map([{id:"",name:"全部"},...arr]?.map(item=>[item.id,item.name]))
+            },
+        },
         {
             title: "来源",
             dataIndex: 'source',

+ 2 - 2
src/pages/MiniApp/BookManage/components/readText/index.tsx

@@ -89,8 +89,8 @@ function ReadText(props: { next: (data: { pageNum: number, pageSize: number, id:
             >
                 <Spin spinning={!data?.size}>
                     {
-                        newData?.records?.map((item: { shortBookContentVO: { contentId: number, content: string } }) => {
-                            return <div style={{ fontSize: 17, lineHeight: 2 }} key={item.shortBookContentVO.contentId} dangerouslySetInnerHTML={{ __html: item.shortBookContentVO.content.replace(/\n/g, '<br/>') }}></div>
+                        newData?.records?.map((item: { paragraphInfo: { id: number, content: string } }) => {
+                            return <div style={{ fontSize: 17, lineHeight: 2 }} key={item.paragraphInfo.id} dangerouslySetInnerHTML={{ __html: item.paragraphInfo.content.replace(/\n/g, '<br/>') }}></div>
                         })
                     }
                 </Spin>

+ 9 - 10
src/pages/TableList/index.tsx

@@ -1,4 +1,3 @@
-import { addRule, removeRule, rule, updateRule } from '@/services/ant-design-pro/api';
 import { PlusOutlined } from '@ant-design/icons';
 import type { ActionType, ProColumns, ProDescriptionsItemProps } from '@ant-design/pro-components';
 import {
@@ -21,7 +20,7 @@ import UpdateForm from './components/UpdateForm';
  * @zh-CN 添加节点
  * @param fields
  */
-const handleAdd = async (fields: API.RuleListItem) => {
+const handleAdd = async (fields: any) => {
   const hide = message.loading('正在添加');
   try {
     await addRule({ ...fields });
@@ -66,7 +65,7 @@ const handleUpdate = async (fields: FormValueType) => {
  *
  * @param selectedRows
  */
-const handleRemove = async (selectedRows: API.RuleListItem[]) => {
+const handleRemove = async (selectedRows: any[]) => {
   const hide = message.loading('正在删除');
   if (!selectedRows) return true;
   try {
@@ -98,8 +97,8 @@ const TableList: React.FC = () => {
   const [showDetail, setShowDetail] = useState<boolean>(false);
 
   const actionRef = useRef<ActionType>();
-  const [currentRow, setCurrentRow] = useState<API.RuleListItem>();
-  const [selectedRowsState, setSelectedRows] = useState<API.RuleListItem[]>([]);
+  const [currentRow, setCurrentRow] = useState<any>();
+  const [selectedRowsState, setSelectedRows] = useState<any[]>([]);
 
   /**
    * @en-US International configuration
@@ -107,7 +106,7 @@ const TableList: React.FC = () => {
    * */
   const intl = useIntl();
 
-  const columns: ProColumns<API.RuleListItem>[] = [
+  const columns: ProColumns<any>[] = [
     {
       title: (
         <FormattedMessage
@@ -243,7 +242,7 @@ const TableList: React.FC = () => {
 
   return (
     <PageContainer>
-      <ProTable<API.RuleListItem, API.PageParams>
+      <ProTable<any, API.PageParams>
         headerTitle={intl.formatMessage({
           id: 'pages.searchTable.title',
           defaultMessage: 'Enquiry form',
@@ -320,7 +319,7 @@ const TableList: React.FC = () => {
         open={createModalOpen}
         onOpenChange={handleModalOpen}
         onFinish={async (value) => {
-          const success = await handleAdd(value as API.RuleListItem);
+          const success = await handleAdd(value as any);
           if (success) {
             handleModalOpen(false);
             if (actionRef.current) {
@@ -377,7 +376,7 @@ const TableList: React.FC = () => {
         closable={false}
       >
         {currentRow?.name && (
-          <ProDescriptions<API.RuleListItem>
+          <ProDescriptions<any>
             column={2}
             title={currentRow?.name}
             request={async () => ({
@@ -386,7 +385,7 @@ const TableList: React.FC = () => {
             params={{
               id: currentRow?.name,
             }}
-            columns={columns as ProDescriptionsItemProps<API.RuleListItem>[]}
+            columns={columns as ProDescriptionsItemProps<any>[]}
           />
         )}
       </Drawer>

+ 8 - 6
src/services/global.ts

@@ -1,26 +1,28 @@
 import { api } from '@/services/api';
 import { request } from '@umijs/max';
 /**标签列表 */
-export async function queryLabelList() {
-  return request(api+'/admin/query/labelList', {
+export async function queryLabelList(params: { workDirection: number | string }) {
+  return request(api + '/admin/query/labelList', {
     method: 'GET',
+    params
   });
 }
 /**分类列表 */
-export async function queryCategoryList() {
-  return request(api+'/admin/query/categoryList', {
+export async function queryCategoryList(params: { workDirection: number | string }) {
+  return request(api + '/admin/query/categoryList', {
     method: 'GET',
+    params
   });
 }
 /**作者列表 */
 export async function queryAuthList() {
-  return request(api+'/admin/query/authList', {
+  return request(api + '/admin/query/authList', {
     method: 'GET',
   });
 }
 /**枚举列表 */
 export async function enumDictList() {
-  return request(api+'/admin/enumDict/list', {
+  return request(api + '/admin/enumDict/list', {
     method: 'GET',
   });
 }

+ 3 - 1
src/services/miniApp/bookManage/index.tsx

@@ -112,9 +112,11 @@ export async function shortBookInfoParagraphList(params: ShortBookParams) {
   });
 }
 /**小说段落全部列表 */
-export async function shortBookInfoParagraphAllList(bookId: number) {
+export async function shortBookInfoParagraphAllList(data:any) {
+  let {bookId,...params} = data
   return request(api + `/admin/shortBookInfo/paragraphAllList/${bookId}`, {
     method: 'GET',
+    params
   });
 }
 /**小说付费配置 */

+ 7 - 6
src/utils/index.ts

@@ -1,7 +1,7 @@
 /**传入数组枚举数组和key数组 找到在枚举数组中的description值
  * @param {Array} enumArr 枚举数组
  * @param {Array} arr 要查找的数组
- * */ 
+ * */
 export function getDescriptions(enumArr: any[], arr: any[]) {
     // 创建一个字典来存储 value 和 description 的映射
     const valueToDescription = enumArr.reduce((acc, item) => {
@@ -14,15 +14,16 @@ export function getDescriptions(enumArr: any[], arr: any[]) {
 /**传入数组枚举数组和key数组 找到在枚举数组中的description值
  * @param {Array} enumArr 枚举数组
  * @param {Array} customParams 要插入数据的目标可以不传  { 0: { disabled: true } } 第0个数据内插入disabled: true
- * */ 
-export function convertEnumArr(enumArr: any, customParams:any = {}) {
-    let result:{[key:string]:{text:string,disabled?:boolean}} = {};
+ * */
+export function convertEnumArr(enumArr: any, customParams: any = {}, config?: { key: string, value: string }) {
+    let result: { [key: string]: { text: string, disabled?: boolean } } = {};
     for (let item of enumArr) {
-        let newItem = { text: item.description };
+        let newItem = { text: config ? item[config.value] : item.description };
         if (customParams[item.value]) {
             Object.assign(newItem, customParams[item.value]);
         }
-        result[item.value] = newItem;
+        result[config ? item[config.key] : item.value] = newItem;
     }
     return result;
 }
+