import React, { useState, useMemo, useRef } from 'react'; import { Button, Fill, IndexBar, IndexBarGroupItem, IndexBarBaseData, Space, IndexBarValue, IndexBarRef, Toast, } from '@xrnjs/ui'; import { IconXChina1, IconXStar1 } from '../../../icons'; import Card from '_global/Card'; import styles from './style'; import { cityJson } from './cityList'; type CityType = { name: string; code: string; }; // 格式化城市数据 const formatLocationData: IndexBarGroupItem[] = []; cityJson.forEach((i: { initial: string; cityNameList: CityType[] }) => { const { initial, cityNameList } = i; formatLocationData.push({ value: initial, label: initial, data: cityNameList.map((p: CityType) => ({ value: p.code, label: p.name, prefix: , description: p.name, })), }); }); // 自定义数据示例 const customData: IndexBarGroupItem[] = [ { value: 'star', label: '⭐ 特色', data: [ { value: 'vip1', label: 'VIP城市', prefix: , description: '黄金会员专享', }, { value: 'vip2', label: '钻石城市', prefix: , description: '钻石会员专享', }, ], }, { value: 'hot', label: '🔥 热门', data: [ { value: 'hot1', label: '网红城市', prefix: , description: '年轻人最爱', }, { value: 'hot2', label: '旅游胜地', prefix: , description: '度假首选', }, ], }, ]; const onDisabledPress = (v: IndexBarBaseData) => Toast({ position: 'middle', message: `${v.label} 不可操作提示`, forbidPress: true, }); const AdvancedFeatures = () => { // 空数据示例 const emptyRef = useRef(null); const [emptyVisible, setEmptyVisible] = useState(false); const [emptyValue, setEmptyValue] = useState(); // 自定义样式示例 const customStyleRef = useRef(null); const [customStyleVisible, setCustomStyleVisible] = useState(false); const [customStyleValue, setCustomStyleValue] = useState([]); // 自定义空状态示例 const customEmptyRef = useRef(null); const [customEmptyVisible, setCustomEmptyVisible] = useState(false); const [customEmptyValue, setCustomEmptyValue] = useState(); // 底部分割线示例 const splitLineRef = useRef(null); const [splitLineVisible, setSplitLineVisible] = useState(false); const [splitLineValue, setSplitLineValue] = useState([]); const EmptyExample = useMemo(() => { return ( setEmptyVisible(false), showConfirmButton: false, }} onPressOverlay={() => setEmptyVisible(false)} onClosed={() => setEmptyVisible(false)} groups={[]} value={emptyValue} ref={emptyRef} onChange={setEmptyValue} onDisabledPress={onDisabledPress} /> ); }, [emptyVisible, emptyValue]); const CustomStyleExample = useMemo(() => { return ( setCustomStyleVisible(false), showConfirmButton: true, onConfirm: () => setCustomStyleVisible(false), }} onPressOverlay={() => setCustomStyleVisible(false)} onClosed={() => setCustomStyleVisible(false)} groups={customData} mode="multiple" value={customStyleValue} ref={customStyleRef} containerStyle={styles.customContainer} titleStyle={styles.customTitle} descriptionStyle={styles.customDescription} sideBarStyle={styles.customSideBar} valueStyle={styles.customValueStyle} onChange={setCustomStyleValue} footerStyle={styles.footerStyle} footer={ <> } onDisabledPress={onDisabledPress} /> ); }, [customStyleVisible, customStyleValue]); const CustomEmptyExample = useMemo(() => { return ( setCustomEmptyVisible(false), showConfirmButton: false, }} onPressOverlay={() => setCustomEmptyVisible(false)} onClosed={() => setCustomEmptyVisible(false)} groups={[]} value={customEmptyValue} ref={customEmptyRef} emptyProps={{ title: '暂无城市数据', description: '请稍后再试或联系客服', status: 'empty', style: styles.customEmpty, }} onChange={setCustomEmptyValue} onDisabledPress={onDisabledPress} /> ); }, [customEmptyVisible, customEmptyValue]); const SplitLineExample = useMemo(() => { return ( setSplitLineVisible(false), showConfirmButton: true, onConfirm: () => setSplitLineVisible(false), }} onPressOverlay={() => setSplitLineVisible(false)} onClosed={() => setSplitLineVisible(false)} groups={formatLocationData.slice(0, 3)} // 只显示前3组数据 mode="multiple" value={splitLineValue} ref={splitLineRef} splitLine={true} onChange={setSplitLineValue} footerStyle={[styles.footerStyle, styles.splitFooter]} footer={ <> } onDisabledPress={onDisabledPress} /> ); }, [splitLineVisible, splitLineValue]); return ( {EmptyExample} {CustomStyleExample} {Array.isArray(customStyleValue) && customStyleValue.length > 0 && ( )} {CustomEmptyExample} {SplitLineExample} {Array.isArray(splitLineValue) && splitLineValue.length > 0 && ( )} ); }; export default AdvancedFeatures;