feat: uploadCover
This commit is contained in:
@@ -22,8 +22,9 @@ export interface UploadCoverProps {
|
||||
value: CoverImageValue[]
|
||||
onChange: (value: CoverImageValue[] | ((prev: CoverImageValue[]) => CoverImageValue[])
|
||||
) => void
|
||||
source: source
|
||||
maxCount: number
|
||||
source?: source
|
||||
maxCount?: number
|
||||
align?: 'center' | 'left'
|
||||
}
|
||||
|
||||
// const values = [
|
||||
@@ -51,9 +52,11 @@ export default function UploadCover(props: UploadCoverProps) {
|
||||
const {
|
||||
value = [],
|
||||
onChange = () => void 0,
|
||||
source = ['album', 'history', 'preset'],
|
||||
source = ['album', 'history', 'preset'] as source,
|
||||
maxCount = 9,
|
||||
align = 'center',
|
||||
} = props
|
||||
|
||||
const [visible, setVisible] = useState(false)
|
||||
|
||||
const onAdd = useCallback((images: CoverImageValue[]) => {
|
||||
@@ -64,7 +67,6 @@ export default function UploadCover(props: UploadCoverProps) {
|
||||
const onWxAdd = useCallback((images: CoverImageValue[], onFileUploaded: Promise<{ id: string, data: uploadFileResponseData }[]>) => {
|
||||
onAdd(images)
|
||||
onFileUploaded.then(res => {
|
||||
console.log(res, 11111)
|
||||
onAdd(res.map(item => ({
|
||||
id: item.id,
|
||||
url: item.data.file_path,
|
||||
@@ -102,7 +104,7 @@ export default function UploadCover(props: UploadCoverProps) {
|
||||
}
|
||||
</View>
|
||||
</CommonPopup>
|
||||
<div className={`upload-cover-root ${value.length === 0 ? 'upload-cover-act-center' : ''}`}>
|
||||
<div className={`upload-cover-root ${value.length === 0 && align === 'center' ? 'upload-cover-act-center' : ''}`}>
|
||||
{value.length < maxCount && (
|
||||
<div className="upload-cover-act" onClick={() => setVisible(true)}>
|
||||
<Image className='upload-cover-act-icon' src={img.ICON_ADD} />
|
||||
|
||||
@@ -33,9 +33,9 @@ export default function UploadFromWx(props: UploadFromWxProps) {
|
||||
id: (Date.now() + count++).toString(),
|
||||
}))
|
||||
const onFileUploaded = uploadApi.batchUpload(files)
|
||||
onAdd(res.tempFiles.map(item => ({
|
||||
id: Date.now().toString(),
|
||||
url: item.path,
|
||||
onAdd(files.map(item => ({
|
||||
id: item.id,
|
||||
url: item.filePath,
|
||||
})), onFileUploaded) // TODO: add loading state
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ import Taro from '@tarojs/taro'
|
||||
import { View, Text, Image } from '@tarojs/components'
|
||||
import images from '@/config/images'
|
||||
import TextareaTag from '@/components/TextareaTag'
|
||||
import CoverImageUpload, { type CoverImage } from '@/components/ImageUpload'
|
||||
// import CoverImageUpload, { type CoverImage } from '@/components/ImageUpload'
|
||||
import UploadCover, { type CoverImageValue } from '@/components/UploadCover'
|
||||
import { useDictionaryActions } from '@/store/dictionaryStore'
|
||||
import './StadiumDetail.scss'
|
||||
|
||||
@@ -18,7 +19,7 @@ export interface Stadium {
|
||||
court_surface?: string
|
||||
description?: string
|
||||
description_tag?: string[]
|
||||
venue_image_list?: CoverImage[]
|
||||
venue_image_list?: CoverImageValue[]
|
||||
}
|
||||
|
||||
interface StadiumDetailProps {
|
||||
@@ -103,7 +104,7 @@ const StadiumDetail = forwardRef<StadiumDetailRef, StadiumDetailProps>(({
|
||||
court_type: court_type[0] || '',
|
||||
court_surface: court_surface[0] || '',
|
||||
additionalInfo: '',
|
||||
venue_image_list: [] as CoverImage[],
|
||||
venue_image_list: [] as CoverImageValue[],
|
||||
description:{
|
||||
description: '',
|
||||
description_tag: []
|
||||
@@ -208,9 +209,21 @@ const StadiumDetail = forwardRef<StadiumDetailRef, StadiumDetailProps>(({
|
||||
if (item.type === 'image') {
|
||||
return (
|
||||
<SectionContainer key={item.label} title={item.label} prop={item.prop}>
|
||||
<CoverImageUpload
|
||||
images={formData[item.prop]}
|
||||
onChange={(images) => updateFormData(item.prop, images)}
|
||||
<UploadCover
|
||||
value={formData[item.prop]}
|
||||
onChange={(value) => {
|
||||
console.log(value, 'value')
|
||||
if (value instanceof Function) {
|
||||
const newValue = value(formData[item.prop])
|
||||
console.log(newValue, 'newValue')
|
||||
updateFormData(item.prop, newValue)
|
||||
} else {
|
||||
updateFormData(item.prop, value)
|
||||
}
|
||||
}}
|
||||
maxCount={9}
|
||||
source={['album', 'history', 'preset']}
|
||||
align='left'
|
||||
/>
|
||||
</SectionContainer>
|
||||
)
|
||||
@@ -222,4 +235,4 @@ const StadiumDetail = forwardRef<StadiumDetailRef, StadiumDetailProps>(({
|
||||
)
|
||||
})
|
||||
|
||||
export default StadiumDetail
|
||||
export default StadiumDetail
|
||||
Reference in New Issue
Block a user