| 1 | import { Button, Radio, Select, SelectProps } from 'antd'; |
| 2 | import styles from './commonComponents.module.scss'; |
| 3 | import React, { useEffect, useState } from 'react'; |
| 4 | import { Outlet } from 'react-router-dom'; |
| 5 | import { PlusOutlined, UserAddOutlined } from '@ant-design/icons'; |
| 6 | |
| 7 | import { AccountInfo } from '../../../account/comment'; |
| 8 | import { AccountStatus } from '../../../../../commont/AccountEnum'; |
| 9 | import { VisibleTypeEnum } from '../../../../../commont/publish/PublishEnum'; |
| 10 | import { icpGetMixList } from '../../../../icp/publish'; |
| 11 | import { accountFailureDispose } from '../../comment'; |
| 12 | import { onAccountLoginFinish } from '../../../../icp/receiveMsg'; |
| 13 | import { IMixItem } from '../../../../../electron/main/plat/plat.type'; |
| 14 | |
| 15 | // 本地上传、素材上传展示的块 |
| 16 | export const ChooseChunk = ({ |
| 17 | onClick, |
| 18 | imgUrl, |
| 19 | color, |
| 20 | text, |
| 21 | hoverColor, |
| 22 | style, |
| 23 | }: { |
| 24 | onClick?: () => void; |
| 25 | imgUrl: string; |
| 26 | hoverColor?: string; |
| 27 | color: string; |
| 28 | text: string; |
| 29 | style?: React.CSSProperties; |
| 30 | }) => { |
| 31 | const [isHovered, setIsHovered] = useState(false); |
| 32 | |
| 33 | return ( |
| 34 | <> |
| 35 | <div |
| 36 | className={styles.chooseChunk} |
| 37 | onClick={() => { |
| 38 | if (onClick) onClick(); |
| 39 | }} |
| 40 | style={ |
| 41 | isHovered |
| 42 | ? { |
| 43 | borderColor: hoverColor || color, |
| 44 | ...(style || {}), |
| 45 | } |
| 46 | : style || {} |
| 47 | } |
| 48 | onMouseEnter={() => setIsHovered(true)} |
| 49 | onMouseLeave={() => setIsHovered(false)} |
| 50 | > |
| 51 | <img src={imgUrl} /> |
| 52 | <Button type="primary" size="large" style={{ background: color }}> |
| 53 | {text} |
| 54 | </Button> |
| 55 | </div> |
| 56 | </> |
| 57 | ); |
| 58 | }; |
| 59 | |
| 60 | // 选择账户展示的块 |
| 61 | export const ChooseAccountChunk = ({ onClick }: { onClick: () => void }) => { |
| 62 | return ( |
| 63 | <div className={styles.chooseAccountChunk} onClick={onClick}> |
| 64 | <UserAddOutlined className="chooseAccountChunk-user" /> |
| 65 | <Button icon={<PlusOutlined />} type="primary"> |
| 66 | 选择发布账号 |
| 67 | </Button> |
| 68 | <Outlet /> |
| 69 | </div> |
| 70 | ); |
| 71 | }; |
| 72 | |
| 73 | export interface PubPermissionProps { |
| 74 | onChange?: (visibleType: VisibleTypeEnum) => void; |
| 75 | value?: VisibleTypeEnum; |
| 76 | title?: string; |
| 77 | style?: React.CSSProperties; |
| 78 | } |
| 79 | |
| 80 | // 权限设置 |
| 81 | export const PubPermission = ({ |
| 82 | onChange, |
| 83 | value, |
| 84 | style, |
| 85 | title = '权限设置', |
| 86 | }: PubPermissionProps) => { |
| 87 | return ( |
| 88 | <> |
| 89 | <h1>{title}</h1> |
| 90 | <Radio.Group |
| 91 | style={style} |
| 92 | options={[ |
| 93 | { |
| 94 | label: '公开(所有人可见)', |
| 95 | value: VisibleTypeEnum.Public, |
| 96 | }, |
| 97 | { label: '好友可见', value: VisibleTypeEnum.Friend }, |
| 98 | { |
| 99 | label: '私密(仅自己可见)', |
| 100 | value: VisibleTypeEnum.Private, |
| 101 | }, |
| 102 | ]} |
| 103 | onChange={(e) => { |
| 104 | if (onChange) onChange(e.target.value); |
| 105 | }} |
| 106 | value={value} |
| 107 | /> |
| 108 | </> |
| 109 | ); |
| 110 | }; |
| 111 | |
| 112 | // 账户重新登录 |
| 113 | export const AccountRestartLogin = ({ |
| 114 | account, |
| 115 | onAccountRestart, |
| 116 | }: { |
| 117 | account?: AccountInfo; |
| 118 | onAccountRestart: () => void; |
| 119 | }) => { |
| 120 | return ( |
| 121 | <> |
| 122 | {account?.status === AccountStatus.DISABLE && ( |
| 123 | <div className={styles.accountRestartLogin}> |
| 124 | 账户已失效, |
| 125 | <Button |
| 126 | type="link" |
| 127 | onClick={() => { |
| 128 | onAccountRestart(); |
| 129 | }} |
| 130 | > |
| 131 | 重新登录 |
| 132 | </Button> |
| 133 | 后可获取 |
| 134 | </div> |
| 135 | )} |
| 136 | </> |
| 137 | ); |
| 138 | }; |
| 139 | |
| 140 | // 合集 |
| 141 | export const CommonMixSelect = ({ |
| 142 | account, |
| 143 | onAccountChange, |
| 144 | children, |
| 145 | ...props |
| 146 | }: { |
| 147 | account?: AccountInfo; |
| 148 | children?: React.ReactNode; |
| 149 | onAccountChange?: (account: AccountInfo) => void; |
| 150 | } & SelectProps) => { |
| 151 | if (!account || !onAccountChange) return ''; |
| 152 | |
| 153 | const [options, setOptions] = useState<IMixItem[]>([]); |
| 154 | |
| 155 | const getList = async () => { |
| 156 | const res = await icpGetMixList(account!); |
| 157 | const data = await accountFailureDispose(res, account!, onAccountChange); |
| 158 | setOptions(data); |
| 159 | }; |
| 160 | |
| 161 | useEffect(() => { |
| 162 | getList(); |
| 163 | return onAccountLoginFinish((newAccount) => { |
| 164 | account = newAccount; |
| 165 | getList(); |
| 166 | }); |
| 167 | }, []); |
| 168 | |
| 169 | return ( |
| 170 | <> |
| 171 | <h1>合集</h1> |
| 172 | <Select |
| 173 | options={options} |
| 174 | allowClear |
| 175 | style={{ width: '100%' }} |
| 176 | placeholder="选择合集" |
| 177 | fieldNames={{ |
| 178 | label: 'name', |
| 179 | value: 'id', |
| 180 | }} |
| 181 | optionRender={({ data }) => { |
| 182 | return ( |
| 183 | <div className={styles.mixSelectItem}> |
| 184 | <div className="mixSelectItem-left"> |
| 185 | {data.coverImg && <img src={data.coverImg} />} |
| 186 | {data.name} |
| 187 | </div> |
| 188 | <div className="mixSelectItem-right"> |
| 189 | 共{data.feedCount}个作品 |
| 190 | </div> |
| 191 | </div> |
| 192 | ); |
| 193 | }} |
| 194 | {...props} |
| 195 | /> |
| 196 | {children} |
| 197 | </> |
| 198 | ); |
| 199 | }; |
| 200 |