import IconSpin from '@douyinfe/semi-icons/lib/es/icons/IconSpin';
import styles from './sourceList.module.less';
import WaterFull from '@components/water-full';
import classNames from 'classnames';
import type { SourceType } from '@config/types';
import { Progress, Checkbox, Toast, Pagination, Empty } from '@douyinfe/semi-ui';
import { Stretching, Plus, Like, Add } from '@icon-park/react';
import type { SourceItem } from '../../types';
import { language } from '@language/language';
import { pubsub } from '@utils/pubsub';
import { addItem } from '../../components/sources/addItem';
import { stores } from '@stores/index';
export interface IProps {
total: number;
page: number;
pageSize: number;
items: SourceItem[];
item: (a: SourceItem) => JSX.Element;
itemClassName: string;
onPageChange: (page: number) => void;
type: SourceType;
setItems?: (items: SourceItem[]) => void;
checkboxs?: string[];
onChangeCheckboxs?: (n: string) => void;
sType?: string;
callback?: (id: string) => void;
addItem?: any;
loading?: boolean;
}
export interface ChildProps {
children?: any;
className?: string;
item: any;
}
export default function SourceList(props: IProps) {
const { editor } = stores;
const { total, page, pageSize, items, type, checkboxs, onChangeCheckboxs, sType, loading } = props;
if (loading && !items?.length) {
return (
{language.val('common_loading')}
);
}
if (!items?.length) {
return (
);
}
const checkboxStyle: any = {};
if (checkboxs && checkboxs.length) {
checkboxStyle.display = 'block';
}
// 设置缓存数据,用于拖动元素的时候获取数据
editor.setActiveItems(items);
return (
{
const showViewButton = ['image', 'video', 'audio', 'text', 'template'].includes(item.type);
return (
{
if (props.type === 'template') {
props.addItem(item);
}
}}
>
{props.item(item)}
{checkboxs ? (
e.stopPropagation()} className={styles.checkbox} style={checkboxStyle}>
{
onChangeCheckboxs(item.id);
}}
>
) : (
{
const canCollect = !item.is_collected && sType !== 'collect';
if (!canCollect) {
const [res, err] = await editor.apiServer.cancelCollect([item.id], props.type);
if (err) {
Toast.error(err);
return;
}
pubsub.publish(`updateItemCollect_${type}`, { id: item.id, collect: false });
if (props.callback) {
props.callback(item.id);
}
Toast.success(language.val('common_toast_collect_cancel_success'));
return;
}
await editor.apiServer.collect({
source_id: item.id,
type: props.type,
});
pubsub.publish(`updateItemCollect_${type}`, { id: item.id, collect: true });
Toast.success(language.val('common_toast_collect_success'));
}}
className={styles.save}
>
{!item.is_collected && sType !== 'collect' ? (
) : (
)}
)}
{showViewButton && (
<>
{
console.log('预览item--->', item);
e.stopPropagation();
editor.previewSource = {
type: item.type,
name: item.name,
//@ts-ignore 模版才有video
url: item.video || item.urls?.url || item.urls?.thumb || item.thumb,
};
}}
className={styles.preview}
>
{
e.stopPropagation();
await addItem(item, undefined, undefined);
}}
className={styles.add}
>
>
)}
);
}}
/>
{total > pageSize && (
props.onPageChange(page)}
/>
)}
);
}