|
@@ -2,8 +2,8 @@ import { ActionType, BetaSchemaForm, PageContainer, ProFormInstance, ProTable }
|
|
|
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 { useEffect, useMemo, useRef, useState } from "react"
|
|
|
+import { shortBookInfoList, shortBookInfoParagraphList, shortBookInfoBookConfig, shortBookInfoConfig, shortBookInfoParagraphAllList, sysRechargeGetInfo, sysRechargeAddOrEdit } from "@/services/miniApp/bookManage"
|
|
|
+import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
|
import { Drawer, message, Space, Tag } from "antd"
|
|
|
import ReadText from "../components/readText"
|
|
|
import formConfig from "./formConfig"
|
|
@@ -30,7 +30,9 @@ const Page: React.FC = () => {
|
|
|
let { state, getLabelAndClassList } = useModel('global')
|
|
|
let [open, setOpen] = useState<any>(null)//付费配置
|
|
|
let [editValues, setEditValues] = useState<any>({})
|
|
|
- let paymentType = useState([])
|
|
|
+ let paymentType = useState(0)//付费方式
|
|
|
+ let paymentCategory = useState(0)//收费货币
|
|
|
+ let [isGlobalConfig, setIsGlobalConfig] = useState(false)//
|
|
|
let [workDirection, setWorkDirection] = useState<any>(null)
|
|
|
const [openBook, setOpneBook] = useState<any>(null)//阅读小说
|
|
|
let getList = useAjax((params) => shortBookInfoList(params), { type: 'table' })//获取书列表
|
|
@@ -38,22 +40,30 @@ const Page: React.FC = () => {
|
|
|
let getParagraphAllList = useAjax((params) => shortBookInfoParagraphAllList(params))//获取全部段落
|
|
|
let add = useAjax((params) => shortBookInfoBookConfig(params))//新增配置
|
|
|
let configInfo = useAjax((params) => shortBookInfoConfig(params))//获取配置信息
|
|
|
+ let globaleConfig = useAjax((params) => sysRechargeGetInfo(params))//获取全局配置信息
|
|
|
+ let globaleAddOrEdit = useAjax((params) => sysRechargeAddOrEdit(params))//全局配置信息修改
|
|
|
const formRef = useRef<ProFormInstance>();
|
|
|
const actionRef = useRef<ActionType>();
|
|
|
|
|
|
// 获取标签和分类
|
|
|
useEffect(() => {
|
|
|
getLabelAndClassList({ workDirection })
|
|
|
+ getGlobalInfo()
|
|
|
}, [workDirection])
|
|
|
// 接口公共参数
|
|
|
let publicData = useMemo(() => {
|
|
|
return {
|
|
|
- miniappId: initialState?.selectApp?.id || "",
|
|
|
+ appId: initialState?.selectApp?.id || "",
|
|
|
distributorId: initialState?.currentUser?.distributorId,
|
|
|
appType: initialState?.selectApp?.appType || ""
|
|
|
}
|
|
|
}, [initialState?.selectApp, initialState?.currentUser?.distributorId])
|
|
|
-
|
|
|
+ //获取全局收费配置
|
|
|
+ const getGlobalInfo = useCallback(() => {
|
|
|
+ globaleConfig.run(publicData).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
+ }, [publicData])
|
|
|
// 看小说
|
|
|
const lookBook = (params: any) => {
|
|
|
let { id, pageNum, pageSize } = params
|
|
@@ -64,25 +74,53 @@ const Page: React.FC = () => {
|
|
|
}
|
|
|
// 提交表单
|
|
|
const submit = async (values: any) => {
|
|
|
- if (editValues?.id) {
|
|
|
- values.id = editValues?.id
|
|
|
- }
|
|
|
- if (editValues?.bookId) {
|
|
|
- values.bookId = editValues?.bookId
|
|
|
+ let api = isGlobalConfig ? globaleAddOrEdit : add
|
|
|
+ let newValue = { ...values, ...publicData }
|
|
|
+ if (isGlobalConfig) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (editValues?.id) {
|
|
|
+ newValue.id = editValues?.id
|
|
|
+ }
|
|
|
+ if (editValues?.bookId) {
|
|
|
+ newValue.bookId = editValues?.bookId
|
|
|
+ }
|
|
|
+ if (values.paymentType === 0) {//假如免费,设置vip也免费
|
|
|
+ newValue.vipFree = true
|
|
|
+ }
|
|
|
}
|
|
|
- add.run({ ...values, ...publicData }).then(res => {
|
|
|
+
|
|
|
+ api.run(newValue).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
- actionRef?.current?.reload()
|
|
|
+ if (isGlobalConfig) {
|
|
|
+ getGlobalInfo()
|
|
|
+ } else {
|
|
|
+ actionRef?.current?.reload()
|
|
|
+ }
|
|
|
message.success("付费配置成功!")
|
|
|
closeForm(false)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+ // 全局配置弹窗
|
|
|
+ const closeGlobalForm = () => {
|
|
|
+ setIsGlobalConfig(true)
|
|
|
+ setOpen(true)//弹窗开启
|
|
|
+ let data = globaleConfig?.data?.data
|
|
|
+ setEditValues({ ...data })
|
|
|
+ paymentType[1](data?.paymentType || 0)
|
|
|
+ paymentCategory[1](data?.paymentCategory || 0)
|
|
|
+ setTimeout(() => {
|
|
|
+ formRef?.current?.setFieldsValue({ ...data })
|
|
|
+ }, 100)
|
|
|
+ }
|
|
|
// 关闭表单弹窗和重置表单内容
|
|
|
const closeForm = (b: boolean, values?: any) => {
|
|
|
if (!b) {
|
|
|
setEditValues({})
|
|
|
- paymentType[1]([])
|
|
|
+ paymentType[1](0)
|
|
|
+ paymentCategory[1](0)
|
|
|
+ setIsGlobalConfig(false)
|
|
|
formRef?.current?.resetFields?.()
|
|
|
setOpen(b)
|
|
|
} else {
|
|
@@ -94,11 +132,11 @@ const Page: React.FC = () => {
|
|
|
// 获取书付费配置
|
|
|
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)
|
|
|
+ let data = { ...res.data }
|
|
|
+ setEditValues({ ...data, bookName: values?.shortBookInfoVO?.bookName })
|
|
|
+ paymentType[1](data?.paymentType || 0)
|
|
|
+ paymentCategory[1](data?.paymentCategory || 0)
|
|
|
+ formRef?.current?.setFieldsValue({ ...data, paymentType: data?.paymentType || 0 })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -108,6 +146,7 @@ const Page: React.FC = () => {
|
|
|
}
|
|
|
return <PageContainer title={false}
|
|
|
tabProps={{ type: 'card' }}
|
|
|
+ loading={globaleConfig?.loading}
|
|
|
>
|
|
|
<ProTable<any, any>
|
|
|
params={publicData}
|
|
@@ -115,11 +154,23 @@ const Page: React.FC = () => {
|
|
|
headerTitle={"小说列表"}
|
|
|
rowKey={(r) => r.bookId}
|
|
|
rowSelection={{ alwaysShowAlert: true, hideSelectAll: true, columnWidth: 0, columnTitle: '', renderCell: () => null }}
|
|
|
- tableAlertRender={() => <Space>
|
|
|
- <Tag bordered={false} color="processing" style={{cursor:'pointer'}}>收费价格:短篇¥2/千字,中长篇¥2/千字<EditFilled /></Tag>
|
|
|
- <Tag bordered={false} color="processing" style={{cursor:'pointer'}}>收费起始章节:短篇2,中长篇21<EditFilled /></Tag>
|
|
|
- <Tag bordered={false} color="processing" style={{cursor:'pointer'}}>整本价格:短篇19.9元,中长篇99元<EditFilled /></Tag>
|
|
|
- </Space>}
|
|
|
+ tableAlertRender={() => {
|
|
|
+ let { paymentType, paymentOption, paymentCategory, paymentAmount, paymentCoin, beginPayNo } = globaleConfig?.data?.data || {}
|
|
|
+ let enumList: any = state?.enumList
|
|
|
+ let PAYMENT_TYPE_Map: Map<any, any> = new Map(enumList?.PAYMENT_TYPE?.values?.map(({ value, description }: any) => [value, description]))
|
|
|
+ let PAYMENT_OPTION_Map: Map<any, any> = new Map(enumList?.PAYMENT_OPTION?.values?.map(({ value, description }: any) => [value, description]))
|
|
|
+ return <Tag bordered={false} style={{ cursor: 'pointer' }} onClick={closeGlobalForm}>
|
|
|
+ <Space>
|
|
|
+ <Tag bordered={false} color="processing" style={{ cursor: 'pointer' }}>收费类型:<span style={{ color: '#f64747' }}>{PAYMENT_TYPE_Map?.get(paymentType)}</span></Tag>
|
|
|
+ <Tag bordered={false} color="processing" style={{ cursor: 'pointer' }}>付费起始段落/章节:<span style={{ color: "#f64747" }}>{beginPayNo}</span></Tag>
|
|
|
+ {paymentType === 2 && <Tag bordered={false} color="processing" style={{ cursor: 'pointer' }}>段落/章节收费类型:<span style={{ color: '#f64747' }}>{PAYMENT_OPTION_Map?.get(paymentOption)}</span></Tag>}
|
|
|
+ <Tag bordered={false} color="processing" style={{ cursor: 'pointer' }}>付费价格:
|
|
|
+ <span style={{ color: "#f64747" }}>{paymentCategory === 0 && '¥'}{paymentCategory === 0 ? paymentAmount : paymentCoin}</span>
|
|
|
+ {paymentCategory === 1 && '书币'}</Tag>
|
|
|
+ </Space>
|
|
|
+ <EditFilled />
|
|
|
+ </Tag>
|
|
|
+ }}
|
|
|
tableAlertOptionRender={false}
|
|
|
search={{
|
|
|
labelWidth: 90,
|
|
@@ -151,7 +202,7 @@ const Page: React.FC = () => {
|
|
|
/>
|
|
|
{/* 付费配置 */}
|
|
|
<BetaSchemaForm<DataItem>
|
|
|
- title={"付费配置"}
|
|
|
+ title={(isGlobalConfig ? "全局" : "《" + editValues?.bookName + "》") + "付费配置"}
|
|
|
formRef={formRef}
|
|
|
open={open}
|
|
|
onOpenChange={(b) => { !b && closeForm(b) }}
|
|
@@ -161,8 +212,8 @@ const Page: React.FC = () => {
|
|
|
// grid={true}
|
|
|
layout='horizontal'
|
|
|
onFinish={submit}
|
|
|
- columns={formConfig({ enumList: state?.enumList, paymentType, paragraphList: getParagraphAllList?.data?.data?.map((item: { paragraphInfo: any }) => item.paragraphInfo) })}
|
|
|
- loading={add?.loading}
|
|
|
+ columns={formConfig({ isGlobalConfig, enumList: state?.enumList, paymentType, paymentCategory, paragraphList: getParagraphAllList?.data?.data?.map((item: { paragraphInfo: any }) => item.paragraphInfo) })}
|
|
|
+ loading={add?.loading || globaleAddOrEdit?.loading}
|
|
|
/>
|
|
|
{/* 阅读小说 */}
|
|
|
<Drawer
|