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