feat: 切换城市
This commit is contained in:
72
src/components/Picker/CityPicker.tsx
Normal file
72
src/components/Picker/CityPicker.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
import React, { useState } from "react";
|
||||
import CommonPopup from "@/components/CommonPopup";
|
||||
import Picker from "./Picker";
|
||||
interface PickerOption {
|
||||
text: string | number;
|
||||
value: string | number;
|
||||
}
|
||||
|
||||
interface PickerProps {
|
||||
visible: boolean;
|
||||
setvisible: (visible: boolean) => void;
|
||||
options?: PickerOption[][] | PickerOption[];
|
||||
value?: (string | number)[];
|
||||
type?: "month" | "day" | "hour" | "ntrp" | null;
|
||||
img?: string;
|
||||
onConfirm?: (options: PickerOption[], values: (string | number)[]) => void;
|
||||
onChange?: (value: (string | number)[]) => void;
|
||||
style?: React.CSSProperties;
|
||||
}
|
||||
|
||||
const PopupPicker = ({
|
||||
visible,
|
||||
setvisible,
|
||||
value = [],
|
||||
onConfirm,
|
||||
onChange,
|
||||
options = [],
|
||||
style,
|
||||
}: PickerProps) => {
|
||||
const [defaultValue, setDefaultValue] = useState<(string | number)[]>(value);
|
||||
const changePicker = (_options: any[], values: any, _columnIndex: number) => {
|
||||
setDefaultValue(values);
|
||||
};
|
||||
|
||||
const handleConfirm = () => {
|
||||
console.log(defaultValue, "defaultValue");
|
||||
onChange?.(defaultValue);
|
||||
setvisible(false);
|
||||
};
|
||||
|
||||
const dialogClose = () => {
|
||||
setvisible(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<CommonPopup
|
||||
visible={visible}
|
||||
onClose={dialogClose}
|
||||
showHeader={false}
|
||||
title={null}
|
||||
hideFooter={false}
|
||||
cancelText="取消"
|
||||
confirmText="完成"
|
||||
onConfirm={handleConfirm}
|
||||
position="bottom"
|
||||
round
|
||||
zIndex={1000}
|
||||
style={style}
|
||||
>
|
||||
<Picker
|
||||
visible={visible}
|
||||
options={options}
|
||||
defaultValue={defaultValue}
|
||||
onChange={changePicker}
|
||||
/>
|
||||
</CommonPopup>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default PopupPicker;
|
||||
@@ -3,4 +3,5 @@ export { default as PopupPicker } from './PopupPicker'
|
||||
export { default as PickerCommon } from './PickerCommon'
|
||||
export type { PickerCommonRef } from './PickerCommon'
|
||||
export { default as CalendarUI } from './CalendarUI/CalendarUI'
|
||||
export { default as DialogCalendarCard } from './CalendarDialog/DialogCalendarCard'
|
||||
export { default as DialogCalendarCard } from './CalendarDialog/DialogCalendarCard'
|
||||
export { default as CityPicker } from './CityPicker'
|
||||
Reference in New Issue
Block a user