|
@@ -0,0 +1,160 @@
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
+import styles from './index.module.scss'
|
|
|
+import { A5tableType } from '../data'
|
|
|
+import { Button, Form, FormInstance, InputNumber, Modal } from 'antd'
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
+import { A5_APIsave } from '@/store/action/A5photoWall'
|
|
|
+import TextArea from 'antd/es/input/TextArea'
|
|
|
+import ZupOne from '@/components/ZupOne'
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ info: A5tableType
|
|
|
+ closeFu: () => void
|
|
|
+ addTableFu: () => void
|
|
|
+ upTableFu: () => void
|
|
|
+}
|
|
|
+
|
|
|
+function A5add({ info, closeFu, addTableFu, upTableFu }: Props) {
|
|
|
+ // 表单的ref
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null)
|
|
|
+
|
|
|
+ // 封面图的ref
|
|
|
+ const ZupThumbRef = useRef<any>(null)
|
|
|
+
|
|
|
+ // 编辑进来获取详情
|
|
|
+ const getInfoFu = useCallback(
|
|
|
+ (id: number) => {
|
|
|
+ FormBoxRef.current?.setFieldsValue(info)
|
|
|
+ // 设置封面图
|
|
|
+ ZupThumbRef.current?.setFileComFileFu({
|
|
|
+ fileName: '',
|
|
|
+ filePath: info.thumbPc,
|
|
|
+ thumb: info.thumb
|
|
|
+ })
|
|
|
+ },
|
|
|
+ [info]
|
|
|
+ )
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (info.id > 0) getInfoFu(info.id)
|
|
|
+ else FormBoxRef.current?.setFieldsValue({ sort: 999 })
|
|
|
+ }, [getInfoFu, info.id])
|
|
|
+
|
|
|
+ // 附件 是否 已经点击过确定
|
|
|
+ const [fileCheck, setFileCheck] = useState(false)
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {
|
|
|
+ setFileCheck(true)
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 通过校验点击确定
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (values: any) => {
|
|
|
+ setFileCheck(true)
|
|
|
+
|
|
|
+ const coverUrl1 = ZupThumbRef.current?.fileComFileResFu()
|
|
|
+ // 没有传 封面图
|
|
|
+ if (!coverUrl1.filePath) return MessageFu.warning('请上传图片')
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ ...values,
|
|
|
+ id: info.id > 0 ? info.id : null,
|
|
|
+ thumb: coverUrl1.thumb || '',
|
|
|
+ thumbPc: coverUrl1.filePath || ''
|
|
|
+ }
|
|
|
+
|
|
|
+ // if (1 + 1 === 2) {
|
|
|
+ // console.log('------222', obj)
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+
|
|
|
+ const res = await A5_APIsave(obj)
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success(`${info.id > 0 ? '编辑' : '新增'}成功`)
|
|
|
+ if (info.id > 0) upTableFu()
|
|
|
+ else addTableFu()
|
|
|
+ closeFu()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [addTableFu, closeFu, info.id, upTableFu]
|
|
|
+ )
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Modal
|
|
|
+ wrapClassName={styles.A5add}
|
|
|
+ open={true}
|
|
|
+ title={info.id > 0 ? '编辑图片' : '新增图片'}
|
|
|
+ footer={
|
|
|
+ [] // 设置footer为空,去掉 取消 确定默认按钮
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <div className='A5aMain'>
|
|
|
+ <Form
|
|
|
+ ref={FormBoxRef}
|
|
|
+ name='basic'
|
|
|
+ labelCol={{ span: 2 }}
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete='off'
|
|
|
+ scrollToFirstError
|
|
|
+ >
|
|
|
+ {/* 图片 */}
|
|
|
+ <div className='formRow'>
|
|
|
+ <div className='formLeft'>
|
|
|
+ <span>* </span>
|
|
|
+ 图片:
|
|
|
+ </div>
|
|
|
+ <div className='formRight'>
|
|
|
+ <ZupOne
|
|
|
+ ref={ZupThumbRef}
|
|
|
+ isLook={false}
|
|
|
+ fileCheck={fileCheck}
|
|
|
+ size={5}
|
|
|
+ dirCode='A5photoWall'
|
|
|
+ myUrl='cms/img/upload'
|
|
|
+ format={['image/jpeg', 'image/png']}
|
|
|
+ formatTxt='png、jpg和jpeg'
|
|
|
+ checkTxt='请上传图片'
|
|
|
+ upTxt='最多1张'
|
|
|
+ myType='thumb'
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <Form.Item label='介绍' name='intro'>
|
|
|
+ <TextArea maxLength={200} showCount placeholder='请输入内容' />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <div className='A5fromRow'>
|
|
|
+ <Form.Item
|
|
|
+ label='排序值'
|
|
|
+ name='sort'
|
|
|
+ rules={[{ required: true, message: '请输入排序值' }]}
|
|
|
+ >
|
|
|
+ <InputNumber min={1} max={999} precision={0} placeholder='请输入' />
|
|
|
+ </Form.Item>
|
|
|
+ <div className='A5_6Frow'>
|
|
|
+ 请输入1~999的数字。数字越小,排序越靠前。数字相同时,更新发布的内容排在前面
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 确定和取消按钮 */}
|
|
|
+ <Form.Item className='A5aBtn'>
|
|
|
+ <Button type='primary' htmlType='submit'>
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <MyPopconfirm txtK='取消' onConfirm={closeFu} />
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ </Modal>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA5add = React.memo(A5add)
|
|
|
+
|
|
|
+export default MemoA5add
|