|
|
@@ -0,0 +1,209 @@
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
+import styles from './index.module.scss'
|
|
|
+import { AddTxtType } from '@/pages/A2video/data'
|
|
|
+import { Button, DatePicker, Form, FormInstance, Input, InputNumber, Select } from 'antd'
|
|
|
+import { A5_APIgetInfo, A5_APIsave } from '@/store/action/A5share'
|
|
|
+import dayjs from 'dayjs'
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
+import { A5typeSelectType } from '../data'
|
|
|
+import ZupOne from '@/components/ZupOne'
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ txt: AddTxtType
|
|
|
+ _id: string
|
|
|
+ closeFu: () => void
|
|
|
+ addTableFu: () => void
|
|
|
+ editTableFu: () => void
|
|
|
+}
|
|
|
+
|
|
|
+function A5add({ txt, _id, closeFu, addTableFu, editTableFu }: Props) {
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null)
|
|
|
+ // 封面图的ref
|
|
|
+ const ZupThumbRef = useRef<any>(null)
|
|
|
+ const ZupVideoRef = useRef<any>(null)
|
|
|
+
|
|
|
+ const getInfoFu = useCallback(async (_id: string) => {
|
|
|
+ const res = await A5_APIgetInfo(_id)
|
|
|
+ if (res.code === 0) {
|
|
|
+ const info = res.data
|
|
|
+
|
|
|
+ if (info.releaseDate) info.releaseDate = dayjs(info.releaseDate)
|
|
|
+
|
|
|
+ FormBoxRef.current?.setFieldsValue(info)
|
|
|
+ // 设置封面图
|
|
|
+ ZupThumbRef.current?.setFileComFileFu({
|
|
|
+ originalName: '',
|
|
|
+ originalUrl: info.cover,
|
|
|
+ compressedUrl: info.coverSmall
|
|
|
+ })
|
|
|
+ // 设置视频
|
|
|
+ ZupVideoRef.current?.setFileComFileFu({
|
|
|
+ originalName: info.videoName,
|
|
|
+ originalUrl: info.videoUrl,
|
|
|
+ compressedUrl: ''
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (_id) getInfoFu(_id)
|
|
|
+ else FormBoxRef.current?.setFieldsValue({ releaseDate: dayjs() })
|
|
|
+ }, [_id, getInfoFu])
|
|
|
+
|
|
|
+ // 有没有点击确定,检验图片和视频
|
|
|
+ const [fileCheck, setFileCheck] = useState(false)
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {
|
|
|
+ setFileCheck(true)
|
|
|
+ // return MessageFu.warning("有表单不符号规则!");
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 通过校验点击确定
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (values: any) => {
|
|
|
+ setFileCheck(true)
|
|
|
+ // 封面图
|
|
|
+ const coverUrl = ZupThumbRef.current?.fileComFileResFu()
|
|
|
+ if (!coverUrl.originalUrl) return MessageFu.warning('请上传封面图')
|
|
|
+
|
|
|
+ // 视频
|
|
|
+ const videoUrl = ZupVideoRef.current?.fileComFileResFu()
|
|
|
+ if (!videoUrl.originalUrl) return MessageFu.warning('请上传视频')
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ ...values,
|
|
|
+ _id: txt === '新增' ? null : _id,
|
|
|
+ releaseDate: values.releaseDate ? dayjs(values.releaseDate).format('YYYY-MM-DD') : '',
|
|
|
+ cover: coverUrl.originalUrl || '',
|
|
|
+ coverSmall: coverUrl.compressedUrl || '',
|
|
|
+ videoUrl: videoUrl.originalUrl || '',
|
|
|
+ videoName: videoUrl.originalName
|
|
|
+ }
|
|
|
+
|
|
|
+ const res: any = await A5_APIsave(obj)
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ if (txt === '新增') addTableFu()
|
|
|
+ else editTableFu()
|
|
|
+ MessageFu.success(txt === '新增' ? '新增成功' : '编辑成功')
|
|
|
+ closeFu()
|
|
|
+ }
|
|
|
+ // console.log("通过校验,点击确定");
|
|
|
+ },
|
|
|
+ [addTableFu, closeFu, editTableFu, _id, txt]
|
|
|
+ )
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.A5add}>
|
|
|
+ <Form
|
|
|
+ scrollToFirstError={true}
|
|
|
+ ref={FormBoxRef}
|
|
|
+ name='basic'
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete='off'
|
|
|
+ >
|
|
|
+ <Form.Item
|
|
|
+ label='标题'
|
|
|
+ name='name'
|
|
|
+ rules={[{ required: true, message: '请输入标题' }]}
|
|
|
+ getValueFromEvent={e => e.target.value.trim()}
|
|
|
+ >
|
|
|
+ <Input readOnly={txt === '查看'} maxLength={30} showCount placeholder='请输入内容' />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ label='发布日期'
|
|
|
+ name='releaseDate'
|
|
|
+ rules={[{ required: true, message: '请选择发布日期' }]}
|
|
|
+ >
|
|
|
+ <DatePicker disabled={txt === '查看'} allowClear={false} />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item label='类别' name='type' rules={[{ required: true, message: '请选择类别' }]}>
|
|
|
+ <Select
|
|
|
+ disabled={txt === '查看'}
|
|
|
+ style={{ width: 150 }}
|
|
|
+ options={A5typeSelectType}
|
|
|
+ placeholder='请选择'
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <div className='formBox'>
|
|
|
+ <div className='formBoxll'>
|
|
|
+ <span>* </span>封面:
|
|
|
+ </div>
|
|
|
+ <div className='formBoxrr'>
|
|
|
+ <ZupOne
|
|
|
+ ref={ZupThumbRef}
|
|
|
+ isLook={txt === '查看'}
|
|
|
+ fileCheck={fileCheck}
|
|
|
+ myUrl='file/upload?upPath=A5share'
|
|
|
+ format={['image/jpeg', 'image/png']}
|
|
|
+ formatTxt='png、jpg和jpeg'
|
|
|
+ checkTxt='请上传封面图'
|
|
|
+ upTxt='最多1张'
|
|
|
+ myType='thumb'
|
|
|
+ size={5}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className='formBox'>
|
|
|
+ <div className='formBoxll'>
|
|
|
+ <span>* </span>视频:
|
|
|
+ </div>
|
|
|
+ <div className='formBoxrr'>
|
|
|
+ <ZupOne
|
|
|
+ ref={ZupVideoRef}
|
|
|
+ isLook={txt === '查看'}
|
|
|
+ fileCheck={fileCheck}
|
|
|
+ myUrl='file/upload?upPath=A5share'
|
|
|
+ format={['video/mp4']}
|
|
|
+ formatTxt='mp4'
|
|
|
+ checkTxt='请上传视频'
|
|
|
+ upTxt='最多1个'
|
|
|
+ myType='video'
|
|
|
+ size={500}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className='sortForm'>
|
|
|
+ <Form.Item
|
|
|
+ label='排序值'
|
|
|
+ name='sort'
|
|
|
+ initialValue={999}
|
|
|
+ rules={[{ required: true, message: '请输入排序值' }]}
|
|
|
+ >
|
|
|
+ <InputNumber readOnly={txt === '查看'} min={1} max={999} placeholder='请输入' />
|
|
|
+ </Form.Item>
|
|
|
+ <div className='fromRowTit'>
|
|
|
+ 请输入1~999的数字。数字越大,排序越靠前。数字相同时,更新发布的内容排在前面
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {/* 确定和取消按钮 */}
|
|
|
+ <div className='BtnForm'>
|
|
|
+ <Form.Item>
|
|
|
+ {txt === '查看' ? (
|
|
|
+ <Button onClick={closeFu}>返回</Button>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Button type='primary' htmlType='submit'>
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+ <MyPopconfirm txtK='取消' onConfirm={closeFu} />
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA5add = React.memo(A5add)
|
|
|
+
|
|
|
+export default MemoA5add
|