|
@@ -0,0 +1,244 @@
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
+import styles from './index.module.scss'
|
|
|
+import { A1EditInfoType } from '@/pages/A1goods/data'
|
|
|
+import { Button, DatePicker, Form, FormInstance, Input, InputNumber } from 'antd'
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
+import classNames from 'classnames'
|
|
|
+import ZupOne from '@/components/ZupOne'
|
|
|
+import TextArea from 'antd/es/input/TextArea'
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
+import { A5_APIgetInfo, A5_APIsave } from '@/store/action/A5story'
|
|
|
+import dayjs from 'dayjs'
|
|
|
+import { A5topType } from '../data'
|
|
|
+import ZupTypes from '@/components/ZupTypes'
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ editInfo: A1EditInfoType
|
|
|
+ closeFu: () => void
|
|
|
+ addTableFu: () => void
|
|
|
+ editTableFu: () => void
|
|
|
+ type: A5topType
|
|
|
+}
|
|
|
+
|
|
|
+function A5add({ editInfo, closeFu, addTableFu, editTableFu, type }: Props) {
|
|
|
+ // 表单的ref
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null)
|
|
|
+
|
|
|
+ // 多张图片的ref
|
|
|
+ const ZupImgsRef = useRef<any>(null)
|
|
|
+
|
|
|
+ // 附件的ref
|
|
|
+ const ZupAudioRef = useRef<any>(null)
|
|
|
+
|
|
|
+ // 编辑/查看 进入页面 获取信息
|
|
|
+ const getInfoFu = useCallback(async (id: number) => {
|
|
|
+ const res = await A5_APIgetInfo(id)
|
|
|
+ if (res.code === 0) {
|
|
|
+ const info = res.data.entity
|
|
|
+ const obj = {
|
|
|
+ ...info,
|
|
|
+ myTime: dayjs(info.publishDay)
|
|
|
+ }
|
|
|
+
|
|
|
+ FormBoxRef.current?.setFieldsValue(obj)
|
|
|
+
|
|
|
+ // 设置附件
|
|
|
+ if (info.filePath) {
|
|
|
+ ZupAudioRef.current?.setFileComFileFu({
|
|
|
+ fileName: info.fileName,
|
|
|
+ filePath: info.filePath
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const file = res.data.file || []
|
|
|
+
|
|
|
+ // 传给 附件 组件的
|
|
|
+ const sonInfo = {
|
|
|
+ type: 'img',
|
|
|
+ fileList: file
|
|
|
+ }
|
|
|
+ ZupImgsRef.current?.setFileComFileFu(sonInfo)
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 附件 是否 已经点击过确定
|
|
|
+ const [fileCheck, setFileCheck] = useState(false)
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (editInfo.id > 0) {
|
|
|
+ getInfoFu(editInfo.id)
|
|
|
+ } else {
|
|
|
+ FormBoxRef.current?.setFieldsValue({
|
|
|
+ sort: 999,
|
|
|
+ myTime: dayjs(Date.now())
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }, [editInfo.id, getInfoFu])
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {
|
|
|
+ setFileCheck(true)
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 通过校验点击确定
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (values: any) => {
|
|
|
+ setFileCheck(true)
|
|
|
+
|
|
|
+ // 没有传视频附件
|
|
|
+ let fileName = ''
|
|
|
+ let filePath = ''
|
|
|
+ // txt附件
|
|
|
+ const ZupAudioRefObj = ZupAudioRef.current?.fileComFileResFu()
|
|
|
+ fileName = ZupAudioRefObj.fileName
|
|
|
+ filePath = ZupAudioRefObj.filePath
|
|
|
+ // if (!filePath) return MessageFu.warning('请上传附件!')
|
|
|
+
|
|
|
+ // 附件组件的 type 数组 和 附件id数组
|
|
|
+ const { sonFileIds, sonIsOk } = ZupImgsRef.current?.fileComFileResFu()
|
|
|
+ if (sonIsOk) return
|
|
|
+
|
|
|
+ // 发布日期
|
|
|
+ const publishDay = dayjs(values.myTime).format('YYYY-MM-DD')
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ ...values,
|
|
|
+ id: editInfo.id > 0 ? editInfo.id : null,
|
|
|
+ fileName,
|
|
|
+ filePath,
|
|
|
+ publishDay,
|
|
|
+ type,
|
|
|
+ fileIds: sonFileIds ? sonFileIds.join(',') : null
|
|
|
+ }
|
|
|
+
|
|
|
+ const res = await A5_APIsave(obj)
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success(editInfo.txt + '成功!')
|
|
|
+ editInfo.id > 0 ? editTableFu() : addTableFu()
|
|
|
+ closeFu()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [addTableFu, closeFu, editInfo.id, editInfo.txt, editTableFu, type]
|
|
|
+ )
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.A5add}>
|
|
|
+ <div className={classNames('A5aMain', editInfo.txt === '查看' ? 'A5aMainLook' : '')}>
|
|
|
+ <Form
|
|
|
+ ref={FormBoxRef}
|
|
|
+ name='basic'
|
|
|
+ labelCol={{ span: 3 }}
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete='off'
|
|
|
+ scrollToFirstError
|
|
|
+ >
|
|
|
+ <Form.Item label='标题' name='name' rules={[{ required: true, message: '请输入标题!' }]}>
|
|
|
+ <Input
|
|
|
+ readOnly={editInfo.txt === '查看'}
|
|
|
+ placeholder='请输入内容'
|
|
|
+ maxLength={20}
|
|
|
+ showCount
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ label='发布日期'
|
|
|
+ name='myTime'
|
|
|
+ rules={[{ required: true, message: '请选择发布日期!' }]}
|
|
|
+ >
|
|
|
+ <DatePicker />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ {/* 音频 */}
|
|
|
+ <div className='formRow'>
|
|
|
+ <div className='formLeft' style={{ marginTop: 3 }}>
|
|
|
+ 音频:
|
|
|
+ </div>
|
|
|
+ <div className='formRight'>
|
|
|
+ <ZupOne
|
|
|
+ ref={ZupAudioRef}
|
|
|
+ isLook={editInfo.txt === '查看'}
|
|
|
+ fileCheck={false}
|
|
|
+ size={20}
|
|
|
+ dirCode='A5story'
|
|
|
+ myUrl='cms/audio/upload'
|
|
|
+ format={['audio/mpeg']}
|
|
|
+ formatTxt='mp3'
|
|
|
+ checkTxt='请上传mp3附件!'
|
|
|
+ upTxt='最多1个'
|
|
|
+ myType='audio'
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {editInfo.txt === '查看' ? <br /> : null}
|
|
|
+
|
|
|
+ {/* 图片 */}
|
|
|
+ <div className='formRow formRow2'>
|
|
|
+ <div className='formLeft'>
|
|
|
+ <span>* </span>
|
|
|
+ 图片:
|
|
|
+ </div>
|
|
|
+ <div className='formRight'>
|
|
|
+ <ZupTypes
|
|
|
+ ref={ZupImgsRef}
|
|
|
+ isLook={editInfo.txt === '查看'}
|
|
|
+ fileCheck={fileCheck}
|
|
|
+ selecFlag='图片'
|
|
|
+ imgSize={5}
|
|
|
+ dirCode={'A5story'}
|
|
|
+ myUrl='cms/audio/upload'
|
|
|
+ isTypeShow={true}
|
|
|
+ imgLength={20}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {editInfo.txt === '查看' ? <br /> : null}
|
|
|
+
|
|
|
+ <Form.Item label='正文' name='remark'>
|
|
|
+ <TextArea
|
|
|
+ readOnly={editInfo.txt === '查看'}
|
|
|
+ maxLength={1000}
|
|
|
+ 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' hidden={editInfo.txt === '查看'}>
|
|
|
+ 请输入1~999的数字。数字越小,排序越靠前。数字相同时,更新发布的内容排在前面
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 确定和取消按钮 */}
|
|
|
+ <Form.Item className='A5abtn'>
|
|
|
+ {editInfo.txt === '查看' ? (
|
|
|
+ <Button onClick={closeFu}>返回</Button>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Button type='primary' htmlType='submit'>
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+ <br />
|
|
|
+ <br />
|
|
|
+ <MyPopconfirm txtK='取消' onConfirm={closeFu} />
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA5add = React.memo(A5add)
|
|
|
+
|
|
|
+export default MemoA5add
|