| 1 | import { ForwardedRef, forwardRef, memo } from 'react'; |
| 2 | import { Alert, Avatar, Modal, Progress, Tooltip } from 'antd'; |
| 3 | import { PublishProgressRes } from '../../../../../electron/main/plat/pub/PubItemVideo'; |
| 4 | import styles from './pubProgressModule.module.scss'; |
| 5 | import { AccountPlatInfoMap } from '../../../account/comment'; |
| 6 | import { MinusOutlined } from '@ant-design/icons'; |
| 7 | import { AccountModel } from '../../../../../electron/db/models/account'; |
| 8 | import type { AvatarSize } from 'antd/es/avatar/AvatarContext'; |
| 9 | |
| 10 | export interface IPubProgressModuleRef {} |
| 11 | |
| 12 | export interface IPubProgressModuleProps { |
| 13 | pubProgressData: PublishProgressRes[]; |
| 14 | open: boolean; |
| 15 | onClose: () => void; |
| 16 | } |
| 17 | |
| 18 | function getMsg(progressData: PublishProgressRes) { |
| 19 | if (progressData.progress === 100) { |
| 20 | return '发布成功'; |
| 21 | } else if (progressData.progress === -1) { |
| 22 | return '发布错误'; |
| 23 | } else { |
| 24 | return progressData.msg || '正在加载...'; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | export const AvatarPlat = ({ |
| 29 | account, |
| 30 | size = 'default', |
| 31 | }: { |
| 32 | account: AccountModel; |
| 33 | size?: AvatarSize; |
| 34 | }) => { |
| 35 | const plat = AccountPlatInfoMap.get(account.type)!; |
| 36 | return ( |
| 37 | <> |
| 38 | <div className={styles.avatarPlat}> |
| 39 | <Avatar src={account.avatar} size={size} /> |
| 40 | <img |
| 41 | src={plat.icon} |
| 42 | style={{ |
| 43 | width: size === 'large' ? 15 : size === 'default' ? 12.5 : 10, |
| 44 | }} |
| 45 | /> |
| 46 | </div> |
| 47 | </> |
| 48 | ); |
| 49 | }; |
| 50 | |
| 51 | // 发布进度展示 |
| 52 | const PubProgressModule = memo( |
| 53 | forwardRef( |
| 54 | ( |
| 55 | { pubProgressData, open, onClose }: IPubProgressModuleProps, |
| 56 | ref: ForwardedRef<IPubProgressModuleRef>, |
| 57 | ) => { |
| 58 | return ( |
| 59 | <Modal |
| 60 | width={700} |
| 61 | title="内容分发" |
| 62 | maskClosable={false} |
| 63 | open={open} |
| 64 | onCancel={onClose} |
| 65 | footer={null} |
| 66 | closeIcon={<MinusOutlined />} |
| 67 | > |
| 68 | <Alert |
| 69 | message={ |
| 70 | <> |
| 71 | 关闭此弹框和页面不会影响发布流程, |
| 72 | <b>关闭后可在右上角小铃铛查看发布进度</b>,但请不要关闭哎哟赚哦~ |
| 73 | </> |
| 74 | } |
| 75 | type="success" |
| 76 | /> |
| 77 | <div className={styles.pubProgressModule}> |
| 78 | {pubProgressData.map((v) => { |
| 79 | const { account } = v; |
| 80 | const plat = AccountPlatInfoMap.get(account.type); |
| 81 | if (!plat) return; |
| 82 | |
| 83 | return ( |
| 84 | <div className="pubProgressModule-item" key={account.id}> |
| 85 | <div className="pubProgressModule-item-left"> |
| 86 | <AvatarPlat account={account} size="large" /> |
| 87 | <Tooltip title={account.nickname}> |
| 88 | <span className="pubProgressModule-item-left-name"> |
| 89 | {account.nickname} |
| 90 | </span> |
| 91 | </Tooltip> |
| 92 | </div> |
| 93 | |
| 94 | <div className="pubProgressModule-item-right"> |
| 95 | <Progress |
| 96 | percent={v.progress} |
| 97 | status={v.progress === -1 ? 'exception' : undefined} |
| 98 | /> |
| 99 | <p className="pubProgressModule-item-right-msg"> |
| 100 | {getMsg(v)} |
| 101 | </p> |
| 102 | </div> |
| 103 | </div> |
| 104 | ); |
| 105 | })} |
| 106 | </div> |
| 107 | </Modal> |
| 108 | ); |
| 109 | }, |
| 110 | ), |
| 111 | ); |
| 112 | PubProgressModule.displayName = 'PubProgressModule'; |
| 113 | |
| 114 | export default PubProgressModule; |
| 115 |