import { PickerView, PickerViewColumn, View, Text } from "@tarojs/components"; import './PickerViews.scss' import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { useTranslation } from "react-i18next"; import { rpxToPx } from "@/utils/tools"; // export default function Component(props: { value: any, onChange: Function, items: any, height?: number, showBtns?: boolean, onCancel?: Function, }) { let detailValue const Component = forwardRef((props: { value: any, onChange: Function, items: any, height?: number, showBtns?: boolean, onCancel?: Function, themeColor?: string, title?: string, hideTitle?: boolean }, ref) => { const { t } = useTranslation() const [v, setV] = useState(props.value) var color = props.themeColor ? props.themeColor : '#ff0000' var alpha = alphaToHex(0.4) useEffect(() => { setV(props.value) }, [props.value]) function onPickerChange(e) { setV(e.detail.value) // detailValue = e.detail.value if (props.showBtns) { return; } props.onChange(e.detail.value) } function alphaToHex(alpha) { var alphaValue = Math.round(alpha * 255); // 将透明度乘以255并四舍五入 var hexValue = alphaValue.toString(16); // 将整数转换为十六进制字符串 if (hexValue.length === 1) { hexValue = "0" + hexValue; // 如果十六进制字符串只有一位,补零 } return hexValue; } function confirm(e) { if (process.env.TARO_ENV == 'weapp') { e.stopPropagation() } props.onChange(v) } useImperativeHandle(ref, () => ({ getConfirmData: confirm })); return { !props.hideTitle && {props.title ? props.title : '测试标题 '} } { props.items.map((item, index) => { return {item.map((obj, j) => { return ( {obj} ); })} }) } { props.showBtns && { if (process.env.TARO_ENV == 'weapp') { e.stopPropagation() }; props.onCancel!() }}> {t('feature.common.picker_cancel_btn')} {t('feature.common.picker_confirm_btn')} } }) export default Component;