|
@@ -0,0 +1,185 @@
|
|
|
+import { PageContainer, ProTable } from "@ant-design/pro-components"
|
|
|
+import { useAjax } from "@/Hook/useAjax"
|
|
|
+import { useModel } from "@umijs/max"
|
|
|
+import { useEffect, useRef, useState } from "react"
|
|
|
+import styles from './content.less'
|
|
|
+import { Button, Card, message, Popconfirm, Space, Tooltip } from "antd"
|
|
|
+import { MyIcon } from "@/global"
|
|
|
+import { ArrowDownOutlined, ArrowUpOutlined, DeleteOutlined, EyeOutlined, PlusOutlined } from "@ant-design/icons"
|
|
|
+import MyForm from "./content"
|
|
|
+import { corpWelcomeMsgAddOrUpdate, corpWelcomeMsgList } from "@/services/miniApp/entWeChat"
|
|
|
+
|
|
|
+const Page: React.FC = () => {
|
|
|
+ let { initialState } = useModel("@@initialState")
|
|
|
+ let { getEnum } = useModel("global")
|
|
|
+ let [key, setKey] = useState(getEnum("WELCOME_TYPE", 'arr')?.[0]?.value?.toString())
|
|
|
+ let CorpWelcomeMsgList = useAjax((parmas) => corpWelcomeMsgList(parmas))
|
|
|
+ let CorpWelcomeMsgAddOrUpdate = useAjax((parmas) => corpWelcomeMsgAddOrUpdate(parmas))
|
|
|
+ let [arr, setArr] = useState<any[]>([])//存放数据
|
|
|
+ let [mediaContentList, setMediaContentList] = useState<any[]>([])//存放线上数据
|
|
|
+ const childRefs = useRef<any[]>([]);//存放每个MyForm的表单实例用于验证登操作
|
|
|
+ let publicData = {
|
|
|
+ appId: initialState?.selectApp?.id || "",
|
|
|
+ appType: initialState?.selectApp?.appType || ""
|
|
|
+ }
|
|
|
+ // 切换tab获取对应数据
|
|
|
+ useEffect(() => {
|
|
|
+ if (key) {
|
|
|
+ getConfig()
|
|
|
+ }
|
|
|
+ }, [key])
|
|
|
+ // 获取配置
|
|
|
+ let getConfig = () => {
|
|
|
+ CorpWelcomeMsgList.run({ ...publicData, welcomeType: key }).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ let newArr = res?.data?.mediaContentList?.map((item: any) => {
|
|
|
+ let obj: any = {}
|
|
|
+ Object.keys(item).forEach(key => {
|
|
|
+ if (item[key]) {
|
|
|
+ obj[key] = item[key]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return obj
|
|
|
+ })
|
|
|
+ setArr(newArr || [])
|
|
|
+ setMediaContentList(newArr || [])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增
|
|
|
+ let add = () => {
|
|
|
+ setArr([...arr, {}])
|
|
|
+ }
|
|
|
+ // 删除
|
|
|
+ let del = (eq: number) => {
|
|
|
+ let newArr = arr.filter((item, index) => index !== eq)
|
|
|
+ setArr(newArr)
|
|
|
+ }
|
|
|
+ // 移动
|
|
|
+ let move = (moveEq: number, targetEq: number) => {
|
|
|
+ let newArrCopy: any = JSON.parse(JSON.stringify(arr));
|
|
|
+ [newArrCopy[moveEq], newArrCopy[targetEq]] = [newArrCopy[targetEq], newArrCopy[moveEq]];
|
|
|
+ console.log("newArrCopy", newArrCopy)
|
|
|
+ setArr(newArrCopy)
|
|
|
+ }
|
|
|
+ // 提交
|
|
|
+ let submit = async () => {
|
|
|
+ let isOk = true
|
|
|
+ console.log({
|
|
|
+ ...publicData,
|
|
|
+ welcomeType: key,
|
|
|
+ mediaContentList: arr
|
|
|
+ })
|
|
|
+ for (let item of childRefs?.current) {
|
|
|
+ try {
|
|
|
+ // 验证字段,返回 Promise
|
|
|
+ await item?.form?.validateFields();
|
|
|
+ } catch (errorInfo) {
|
|
|
+ console.log(1111111, errorInfo)
|
|
|
+ // 验证失败,errorInfo 会包含错误信息
|
|
|
+ isOk = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isOk) {
|
|
|
+ CorpWelcomeMsgAddOrUpdate.run({
|
|
|
+ ...publicData,
|
|
|
+ welcomeType: key,
|
|
|
+ mediaContentList: arr
|
|
|
+ }).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ message.success("操作成功")
|
|
|
+ getConfig()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ message.error("还有必填数据未填写完成!")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log("mediaContentList", mediaContentList)
|
|
|
+ return <PageContainer
|
|
|
+ title={false}
|
|
|
+ tabList={getEnum("WELCOME_TYPE", 'arr')}
|
|
|
+ onTabChange={async (ak) => {
|
|
|
+ let isOk = true
|
|
|
+ for (let item of childRefs?.current) {
|
|
|
+ try {
|
|
|
+ // 验证字段,返回 Promise
|
|
|
+ await item?.form?.validateFields();
|
|
|
+ } catch (errorInfo) {
|
|
|
+ // 验证失败,errorInfo 会包含错误信息
|
|
|
+ isOk = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isOk) {
|
|
|
+ if (JSON.stringify(mediaContentList) !== JSON.stringify(arr)) {
|
|
|
+ message.warning("请先保存或取消当前未保存配置!!")
|
|
|
+ } else {
|
|
|
+ setKey(ak)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ message.error("请填写完整当前配置,或清除不需要的配置再切换")
|
|
|
+ }
|
|
|
+
|
|
|
+ }}
|
|
|
+ tabActiveKey={key}
|
|
|
+ >
|
|
|
+ <div className={styles.content}>
|
|
|
+ {
|
|
|
+ arr?.map((item, index) => {
|
|
|
+ return <div key={index} className={styles.box}>
|
|
|
+ <Card
|
|
|
+ title={"消息" + (index + 1)}
|
|
|
+ className={styles.card}
|
|
|
+ extra={item.mediaType === 'miniprogram' && <Tooltip
|
|
|
+ title={
|
|
|
+ <div style={{ border: "1px solid #dedee0", borderRadius: 5 }}>
|
|
|
+ <div style={{ color: "#00000073", margin: "0 14px 5px" }}>{initialState?.selectApp?.appName}</div>
|
|
|
+ <div style={{ color: "#000", margin: "0 14px 12px" }}>{item?.miniprogramTitle}</div>
|
|
|
+ <img src={item?.miniprogramPicurl} style={{ width: 200, height: 160, margin: "0 14px 12px" }} />
|
|
|
+ <div style={{ borderTop: "1px solid #ececed", color: "#b0b0b0", padding: "0 12px" }}>
|
|
|
+ <MyIcon type="icon-weixinxiaochengxu" /> 小程序
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ }
|
|
|
+ color={"#fff"}
|
|
|
+ placement="bottom"
|
|
|
+ >
|
|
|
+ <a><EyeOutlined /> 预览</a>
|
|
|
+ </Tooltip>}
|
|
|
+ >
|
|
|
+ <MyForm index={index} arr={arr} set={setArr} appId={initialState?.selectApp?.appKey} ref={(el) => childRefs.current[index] = el} />
|
|
|
+ </Card>
|
|
|
+ <div className={styles.btnBox}>
|
|
|
+ <Popconfirm
|
|
|
+ title="确定要删除!"
|
|
|
+ onConfirm={() => { del(index) }}
|
|
|
+ >
|
|
|
+ <Button><DeleteOutlined /></Button>
|
|
|
+ </Popconfirm>
|
|
|
+ {index > 0 && <Button onClick={() => { move(index, index - 1) }}><ArrowUpOutlined /></Button>}
|
|
|
+ {index !== arr.length - 1 && <Button onClick={() => { move(index, index + 1) }}><ArrowDownOutlined /></Button>}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ <Button type="dashed" className={styles.add} onClick={add}><PlusOutlined />增加一条</Button>
|
|
|
+ <div className={styles.footer}>
|
|
|
+ <Space>
|
|
|
+ <Button type="primary" onClick={submit} disabled={JSON.stringify(mediaContentList) === JSON.stringify(arr)}>保存</Button>
|
|
|
+ <Popconfirm
|
|
|
+ title="是否要取消当前未保存配置!"
|
|
|
+ onConfirm={()=>{
|
|
|
+ setArr(mediaContentList)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Button disabled={JSON.stringify(mediaContentList) === JSON.stringify(arr)}>取消</Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </Space>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </PageContainer>
|
|
|
+
|
|
|
+}
|
|
|
+export default Page
|