| 1 | /** |
| 2 | * BilibParams - B站平台参数设置 |
| 3 | */ |
| 4 | import type { ForwardedRef } from 'react' |
| 5 | import type { |
| 6 | IPlatsParamsProps, |
| 7 | IPlatsParamsRef, |
| 8 | } from '@/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type' |
| 9 | import { forwardRef, memo, useEffect } from 'react' |
| 10 | import { useShallow } from 'zustand/react/shallow' |
| 11 | import { useTransClient } from '@/app/i18n/client' |
| 12 | import CommonTitleInput from '@/components/PublishDialog/compoents/PlatParamsSetting/common/CommonTitleInput' |
| 13 | import usePlatParamsCommon from '@/components/PublishDialog/compoents/PlatParamsSetting/hooks/usePlatParamsCoomon' |
| 14 | import PubParmasTextarea from '@/components/PublishDialog/compoents/PubParmasTextarea' |
| 15 | import { usePublishDialogData } from '@/components/PublishDialog/usePublishDialogData' |
| 16 | import { Input } from '@/components/ui/input' |
| 17 | import { Label } from '@/components/ui/label' |
| 18 | import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group' |
| 19 | import { cn } from '@/utils/className' |
| 20 | import BilibiliPartitionCascader from './BilibiliPartitionCascader' |
| 21 | |
| 22 | const BilibParams = memo( |
| 23 | forwardRef( |
| 24 | ( |
| 25 | { pubItem, isMobile }: IPlatsParamsProps, |
| 26 | ref: ForwardedRef<IPlatsParamsRef>, |
| 27 | ) => { |
| 28 | const { t } = useTransClient('publish') |
| 29 | const { t: tCommon } = useTransClient('common') |
| 30 | const { pubParmasTextareaCommonParams, setOnePubParams } = usePlatParamsCommon( |
| 31 | pubItem, |
| 32 | isMobile, |
| 33 | ) |
| 34 | const { getBilibiliPartitions, bilibiliPartitions, bilibiliPartitionsLoading } = usePublishDialogData( |
| 35 | useShallow(state => ({ |
| 36 | getBilibiliPartitions: state.getBilibiliPartitions, |
| 37 | bilibiliPartitions: state.bilibiliPartitions, |
| 38 | bilibiliPartitionsLoading: state.bilibiliPartitionsLoading, |
| 39 | })), |
| 40 | ) |
| 41 | |
| 42 | useEffect(() => { |
| 43 | getBilibiliPartitions() |
| 44 | }, [getBilibiliPartitions]) |
| 45 | |
| 46 | // 初始化Bilibili参数 |
| 47 | useEffect(() => { |
| 48 | const option = pubItem.params.option |
| 49 | if (!option.bilibili) { |
| 50 | option.bilibili = {} |
| 51 | } |
| 52 | if (!option.bilibili.copyright) { |
| 53 | option.bilibili.copyright = 1 |
| 54 | setOnePubParams( |
| 55 | { |
| 56 | option, |
| 57 | }, |
| 58 | pubItem.account.id, |
| 59 | ) |
| 60 | } |
| 61 | }, [pubItem.account.id, setOnePubParams]) |
| 62 | |
| 63 | return ( |
| 64 | <> |
| 65 | <PubParmasTextarea |
| 66 | {...pubParmasTextareaCommonParams} |
| 67 | extend={( |
| 68 | <> |
| 69 | <CommonTitleInput pubItem={pubItem} isMobile={isMobile} /> |
| 70 | |
| 71 | {/* 分区选择 */} |
| 72 | <div |
| 73 | className={cn('flex mt-2.5', isMobile ? 'flex-col gap-1.5' : 'items-center h-8')} |
| 74 | > |
| 75 | <div |
| 76 | className={cn('shrink-0', isMobile ? 'text-sm font-medium' : 'w-[90px] mr-2.5')} |
| 77 | > |
| 78 | {t('form.partition')} |
| 79 | </div> |
| 80 | <BilibiliPartitionCascader |
| 81 | partitions={bilibiliPartitions || []} |
| 82 | value={pubItem.params.option.bilibili?.tid} |
| 83 | onValueChange={(value) => { |
| 84 | const option = pubItem.params.option |
| 85 | option.bilibili!.tid = value |
| 86 | setOnePubParams( |
| 87 | { |
| 88 | option, |
| 89 | }, |
| 90 | pubItem.account.id, |
| 91 | ) |
| 92 | }} |
| 93 | placeholder={t('form.partitionPlaceholder')} |
| 94 | searchPlaceholder={t('form.searchPlaceholder')} |
| 95 | emptyText={t('form.noResults')} |
| 96 | loading={bilibiliPartitionsLoading} |
| 97 | loadingText={tCommon('actions.loading')} |
| 98 | className="flex-1" |
| 99 | /> |
| 100 | </div> |
| 101 | |
| 102 | {/* 类型选择 */} |
| 103 | <div |
| 104 | className={cn('flex mt-2.5', isMobile ? 'flex-col gap-1.5' : 'items-center h-8')} |
| 105 | > |
| 106 | <div |
| 107 | className={cn('shrink-0', isMobile ? 'text-sm font-medium' : 'w-[90px] mr-2.5')} |
| 108 | > |
| 109 | {t('form.type')} |
| 110 | </div> |
| 111 | <RadioGroup |
| 112 | value={pubItem.params.option.bilibili?.copyright?.toString() ?? ''} |
| 113 | onValueChange={(value) => { |
| 114 | const option = pubItem.params.option |
| 115 | const numValue = Number(value) |
| 116 | option.bilibili!.copyright = numValue |
| 117 | if (numValue === 1) { |
| 118 | option.bilibili!.source = '' |
| 119 | } |
| 120 | setOnePubParams( |
| 121 | { |
| 122 | option, |
| 123 | }, |
| 124 | pubItem.account.id, |
| 125 | ) |
| 126 | }} |
| 127 | className={cn('flex gap-4', isMobile ? 'flex-col' : 'items-center')} |
| 128 | > |
| 129 | <div className="flex items-center space-x-2"> |
| 130 | <RadioGroupItem value="1" id="bilibili-original" /> |
| 131 | <Label htmlFor="bilibili-original" className="cursor-pointer"> |
| 132 | {t('form.original')} |
| 133 | </Label> |
| 134 | </div> |
| 135 | <div className="flex items-center space-x-2"> |
| 136 | <RadioGroupItem value="2" id="bilibili-reprint" /> |
| 137 | <Label htmlFor="bilibili-reprint" className="cursor-pointer"> |
| 138 | {t('form.reprint')} |
| 139 | </Label> |
| 140 | </div> |
| 141 | </RadioGroup> |
| 142 | </div> |
| 143 | |
| 144 | {/* 来源输入(仅转载时显示) */} |
| 145 | {pubItem.params.option.bilibili?.copyright === 2 && ( |
| 146 | <div |
| 147 | className={cn( |
| 148 | 'flex mt-2.5', |
| 149 | isMobile ? 'flex-col gap-1.5' : 'items-center h-8', |
| 150 | )} |
| 151 | > |
| 152 | <div |
| 153 | className={cn( |
| 154 | 'shrink-0', |
| 155 | isMobile ? 'text-sm font-medium' : 'w-[90px] mr-2.5', |
| 156 | )} |
| 157 | > |
| 158 | {t('form.source')} |
| 159 | </div> |
| 160 | <Input |
| 161 | placeholder={t('form.sourcePlaceholder')} |
| 162 | value={pubItem.params.option.bilibili?.source || ''} |
| 163 | onChange={(e) => { |
| 164 | const option = pubItem.params.option |
| 165 | option.bilibili!.source = e.target.value |
| 166 | setOnePubParams( |
| 167 | { |
| 168 | option, |
| 169 | }, |
| 170 | pubItem.account.id, |
| 171 | ) |
| 172 | }} |
| 173 | /> |
| 174 | </div> |
| 175 | )} |
| 176 | </> |
| 177 | )} |
| 178 | /> |
| 179 | </> |
| 180 | ) |
| 181 | }, |
| 182 | ), |
| 183 | ) |
| 184 | |
| 185 | export default BilibParams |
| 186 |