shenwu 8 mesi fa
parent
commit
8ed95f9c32

+ 6 - 1
src/pages/MiniApp/Consume/index.tsx

@@ -6,6 +6,11 @@ import { useModel } from "@umijs/max"
 
 const Page: React.FC = () => {
     let { initialState } = useModel("@@initialState")
+    let { enumList } = useModel("global", (global) => {
+        return {
+            enumList: global.state.enumList
+        }
+    })
     let getList = useAjax((params) => bookCoinList(params), { type: 'table' })
     return <PageContainer
         tabProps={{ type: 'card' }}
@@ -24,7 +29,7 @@ const Page: React.FC = () => {
             request={async (params) => {
                 return await getList.run(params)
             }}
-            columns={columns()}
+            columns={columns(enumList)}
         // bordered
         />
     </PageContainer>

+ 4 - 12
src/pages/MiniApp/Consume/tableConfig.tsx

@@ -1,7 +1,7 @@
 import { ProColumns } from "@ant-design/pro-components";
 
-export const columns = (): ProColumns<any>[] => {
-    let obj: any = { '1': '书币充值', '2': '参加活动获取', '3': '抽奖获取', '-1': '阅读长篇小说消费', '-2': '阅读短篇小说消费' };
+export const columns = (enumList:any): ProColumns<any>[] => {
+    let arr: any =enumList?.CHANGE_TYPE.values
     return [
         {
             title: "ID",
@@ -66,7 +66,7 @@ export const columns = (): ProColumns<any>[] => {
             hideInSearch: true,
             align: "center",
             render: (a: any) => {
-                return obj[a]
+                return arr[a]?.description ||'-'
             }
         },
         {
@@ -77,20 +77,12 @@ export const columns = (): ProColumns<any>[] => {
             align: "center",
         },
         // 搜索条件
-        // {
-        //     hideInTable: true,
-        //     dataIndex: 'appType',
-        //     title:"小程序类型",
-        //     valueType:'select',
-        //     initialValue:'1',
-        //     valueEnum:{"1":"微信小程序","2":"抖音小程序"}
-        // },
         {
             hideInTable: true,
             dataIndex: 'changeType',
             title:"书币变更类型",
             valueType:'select',
-            valueEnum:{ '1': '书币充值', '2': '参加活动获取', '3': '抽奖获取', '-1': '阅读长篇小说消费', '-2': '阅读短篇小说消费' }
+            valueEnum:new Map(arr?.map((item: { value: any; description: any; })=>[item.value,item.description]))
         },
         {
             title: "开始时间",

+ 4 - 2
src/pages/MiniApp/ModuleConfig/formConfig.tsx

@@ -1,9 +1,11 @@
+import { convertEnumArr } from "@/utils";
 import { ProFormColumnsType } from "@ant-design/pro-components";
 
-function formConfig(): ProFormColumnsType<{
+function formConfig(enumList?:any): ProFormColumnsType<{
     name: string;
     state: string;
 }>[] {
+    let templateTypeEnum = enumList?.TEMPLATE_TYPE?.values || []
     return [
         {
             title: '模板名称',
@@ -21,7 +23,7 @@ function formConfig(): ProFormColumnsType<{
             title: '充值模板类型',
             dataIndex: 'templateType',
             valueType: 'select',
-            valueEnum: { '0': "书币充值", '1': "vip充值" },
+            valueEnum:  convertEnumArr(templateTypeEnum),
             formItemProps: {
                 rules: [
                     {

+ 7 - 2
src/pages/MiniApp/ModuleConfig/index.tsx

@@ -34,6 +34,11 @@ type DataItem = {
 const Page: React.FC = () => {
     let { token } = useToken()
     let { initialState } = useModel("@@initialState")
+    let { enumList } = useModel("global", (global) => {
+        return {
+            enumList: global.state.enumList
+        }
+    })
     let [open, setOpen] = useState<any>(null)
     let [editValues, setEditValues] = useState<any>({})
     let [activeT, setActiveT] = useState<any>()
@@ -167,7 +172,7 @@ const Page: React.FC = () => {
                     return <Col key={item.id} style={{ cursor: 'pointer' }} onClick={() => { switchTemplate(item.id) }}>
                         <Card className={activeT === item.id ? styles.active : ""} style={{ background: activeT === item.id ? token.colorPrimaryBgHover : token.colorFillAlter }} hoverable>
                             <h3 style={{ fontSize: 16, fontWeight: 500, color: token.colorText, fontFamily: 'PingFang SC' }}>{item.templateName}</h3>
-                            <Template list={item.rechargeConfigList} isVip={!!item.templateType} />
+                            <Template list={item.rechargeConfigList} isVip={item.templateType === 2} />
                             <p style={{ marginTop: 20, color: token.colorTextSecondary, fontSize: 12 }}>{item.templateDescription}</p>
                             <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'end' }}>
                                 <Space>
@@ -198,7 +203,7 @@ const Page: React.FC = () => {
             }}
             grid={true}
             onFinish={submit}
-            columns={formConfig()}
+            columns={formConfig(enumList)}
             loading={add?.loading}
         />
     </PageContainer>

+ 27 - 26
src/pages/MiniApp/ModuleConfig/template.tsx

@@ -4,41 +4,42 @@ import vip from '../../../../public//vip.png';
 import top from '../../../../public//top-r1.png';
 import { createStyles } from "antd-style";
 
-const useStyles = (isVip: any) => createStyles((props) => {
-    let { token } = props
-    return {
-        cardBox: {
-            position: 'relative'
-        },
-        isOne: {
-            backgroundImage: isVip ? "linear-gradient(180deg, #fff1dc 60%, #fffdfa 100%)" : 'linear-gradient(180deg, #ffeced 60%, #fffafa 100%)',
-        },
-        topRight: {
-            lineHeight: '20px',
-            background: isVip ? "#ffd89d" : "#ff2441",
-            position: 'absolute',
-            top: 0,
-            right: 0,
-            fontSize: 12,
-            borderRadius: isVip ? '0 8px 0 8px' : "8px 8px 0 8px",
-            padding: isVip ? '0 5px' : 0,
-        },
-        topRightSpan1: { display: 'inline-block', background: `url(${top}) no-repeat`, minWidth: 40, height: 20, padding: "0 10px 0 6px", backgroundSize: "100% 100%", color: "#fff" },
-        topRightSpan2: { color: "#fff", display: 'inline-block', transform: 'translateX(-4px)' },
-        del:{ fontSize: 14, textDecoration: 'line-through',marginLeft:7,color:token.colorTextTertiary,fontWeight:"500" }
-    }
-});
 
 export function Template(params: { list: any[], isVip: boolean }) {
     let { list, isVip } = params
-    let { styles } = useStyles(isVip)()
+    const useStyles = createStyles((props) => {
+        let { token } = props
+        return {
+            cardBox: {
+                position: 'relative'
+            },
+            isOne: {
+                backgroundImage: isVip ? "linear-gradient(180deg, #fff1dc 60%, #fffdfa 100%)" : 'linear-gradient(180deg, #ffeced 60%, #fffafa 100%)',
+            },
+            topRight: {
+                lineHeight: '20px',
+                background: isVip ? "#ffd89d" : "#ff2441",
+                position: 'absolute',
+                top: 0,
+                right: 0,
+                fontSize: 12,
+                borderRadius: isVip ? '0 8px 0 8px' : "8px 8px 0 8px",
+                padding: isVip ? '0 5px' : 0,
+            },
+            topRightSpan1: { display: 'inline-block', background: `url(${top}) no-repeat`, minWidth: 40, height: 20, padding: "0 10px 0 6px", backgroundSize: "100% 100%", color: "#fff" },
+            topRightSpan2: { color: "#fff", display: 'inline-block', transform: 'translateX(-4px)' },
+            del: { fontSize: 14, textDecoration: 'line-through', marginLeft: 7, color: token.colorTextTertiary, fontWeight: "500" }
+        }
+    });
+    let { styles } = useStyles(isVip)
+
     return <Card bordered={false} style={{ width: 420 }}>
         <Row gutter={[0, 15]}>
             {
                 list?.map((item, index) => {
                     let isOne = index === 0
                     return <Col key={index} span={11} offset={index % 2 === 0 ? 0 : 1} >
-                        <Card className={`${styles.cardBox} ${isOne ? styles.isOne : ""}`} styles={{ body:{maxHeight: 90, padding: '20px 15px'} }}>
+                        <Card className={`${styles.cardBox} ${isOne ? styles.isOne : ""}`} styles={{ body: { maxHeight: 90, padding: '20px 15px' } }}>
                             <div className={styles.topRight}>
                                 {
                                     isVip ? <> <span>{item.description}</span></> : <>

+ 2 - 2
src/utils/index.ts

@@ -16,13 +16,13 @@ export function getDescriptions(enumArr: any[], arr: any[]) {
  * @param {Array} customParams 要插入数据的目标可以不传  { 0: { disabled: true } } 第0个数据内插入disabled: true
  * */
 export function convertEnumArr(enumArr: any, customParams: any = {}, config?: { key: string, value: string }) {
-    let result: { [key: string]: { text: string, disabled?: boolean } } = {};
+    let result: { [key: string|number]: { text: string, disabled?: boolean } } = {};
     for (let item of enumArr) {
         let newItem = { text: config ? item[config.value] : item.description };
         if (customParams[item.value]) {
             Object.assign(newItem, customParams[item.value]);
         }
-        result[config ? item[config.key] : item.value] = newItem;
+        result[config ? Number(item[config.key]) : Number(item.value)] = newItem;
     }
     return result;
 }