|
@@ -3,10 +3,27 @@ import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
|
import './LimitPickers.scss'
|
|
import './LimitPickers.scss'
|
|
|
import Taro from "@tarojs/taro";
|
|
import Taro from "@tarojs/taro";
|
|
|
// export default function Component(props: { limit: number, onChange: Function, onCancel: Function,isRealTime?:boolean,limitDay?:number,time?:number,ref?:any }) {
|
|
// export default function Component(props: { limit: number, onChange: Function, onCancel: Function,isRealTime?:boolean,limitDay?:number,time?:number,ref?:any }) {
|
|
|
-const Component = forwardRef((props: { limit: number, onChange: Function, onCancel: Function, isRealTime?: boolean, limitDay?: number, time?: number }, ref) => {
|
|
|
|
|
|
|
+const Component = forwardRef((props: {
|
|
|
|
|
+ limit: number, onChange: Function, onCancel: Function,
|
|
|
|
|
+ isRealTime?: boolean, limitDay?: number, time?: number, themeColor?: string, title?: string
|
|
|
|
|
+}, ref) => {
|
|
|
const days: string[] = [];
|
|
const days: string[] = [];
|
|
|
const today = new Date();
|
|
const today = new Date();
|
|
|
|
|
+ var color = props.themeColor ? props.themeColor : '#ff0000'
|
|
|
|
|
+ var alpha = alphaToHex(0.4)
|
|
|
const [values, setValues] = useState([props.limitDay ? props.limitDay - 1 : 6, today.getHours(), today.getMinutes()])
|
|
const [values, setValues] = useState([props.limitDay ? props.limitDay - 1 : 6, today.getHours(), today.getMinutes()])
|
|
|
|
|
+ const [isDisableConfirm, setIsDisableConfirm] = useState(false)
|
|
|
|
|
+
|
|
|
|
|
+ function alphaToHex(alpha) {
|
|
|
|
|
+ var alphaValue = Math.round(alpha * 255); // 将透明度乘以255并四舍五入
|
|
|
|
|
+ var hexValue = alphaValue.toString(16); // 将整数转换为十六进制字符串
|
|
|
|
|
+ if (hexValue.length === 1) {
|
|
|
|
|
+ hexValue = "0" + hexValue; // 如果十六进制字符串只有一位,补零
|
|
|
|
|
+ }
|
|
|
|
|
+ return hexValue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
global.picker_time = global.set_time
|
|
global.picker_time = global.set_time
|
|
|
if (props.time) {
|
|
if (props.time) {
|
|
@@ -103,6 +120,7 @@ const Component = forwardRef((props: { limit: number, onChange: Function, onCanc
|
|
|
title: '不能更大了',
|
|
title: '不能更大了',
|
|
|
})
|
|
})
|
|
|
setValues([list[0], (new Date(global.set_time)).getHours(), (new Date(global.set_time)).getMinutes()])
|
|
setValues([list[0], (new Date(global.set_time)).getHours(), (new Date(global.set_time)).getMinutes()])
|
|
|
|
|
+ disableConfirm()
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
var limitDate = new Date(props.limit)
|
|
var limitDate = new Date(props.limit)
|
|
@@ -121,6 +139,7 @@ const Component = forwardRef((props: { limit: number, onChange: Function, onCanc
|
|
|
title: '不能更小了',
|
|
title: '不能更小了',
|
|
|
})
|
|
})
|
|
|
setValues([(props.limitDay ? props.limitDay - 1 : 6) - getDaysDiff(limitDate), limitDate.getHours(), limitDate.getMinutes()])
|
|
setValues([(props.limitDay ? props.limitDay - 1 : 6) - getDaysDiff(limitDate), limitDate.getHours(), limitDate.getMinutes()])
|
|
|
|
|
+ disableConfirm()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -132,6 +151,13 @@ const Component = forwardRef((props: { limit: number, onChange: Function, onCanc
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function disableConfirm(){
|
|
|
|
|
+ setIsDisableConfirm(true)
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ setIsDisableConfirm(false)
|
|
|
|
|
+ },2000);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function expandZero(num: number): string {
|
|
function expandZero(num: number): string {
|
|
|
return num < 10 ? `0${num}` : `${num}`;
|
|
return num < 10 ? `0${num}` : `${num}`;
|
|
|
}
|
|
}
|
|
@@ -140,17 +166,20 @@ const Component = forwardRef((props: { limit: number, onChange: Function, onCanc
|
|
|
props.onCancel()
|
|
props.onCancel()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // function confirm() {
|
|
|
|
|
- // var date = new Date();
|
|
|
|
|
- // if (!props.isRealTime) {
|
|
|
|
|
- // date = new Date(global.set_time);
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ function confirm() {
|
|
|
|
|
+ if (isDisableConfirm){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ var date = new Date();
|
|
|
|
|
+ if (!props.isRealTime) {
|
|
|
|
|
+ date = new Date(global.set_time);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // date.setDate(today.getDate() - ((props.limitDay ? props.limitDay - 1 : 6) - values[0]));
|
|
|
|
|
- // date.setHours(values[1])
|
|
|
|
|
- // date.setMinutes(values[2])
|
|
|
|
|
- // props.onChange(date.getTime())
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ date.setDate(today.getDate() - ((props.limitDay ? props.limitDay - 1 : 6) - values[0]));
|
|
|
|
|
+ date.setHours(values[1])
|
|
|
|
|
+ date.setMinutes(values[2])
|
|
|
|
|
+ props.onChange(date.getTime())
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
function setPickerTime() {
|
|
function setPickerTime() {
|
|
|
|
|
|
|
@@ -175,38 +204,52 @@ const Component = forwardRef((props: { limit: number, onChange: Function, onCanc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- return <View style={{ backgroundColor: 'transparent', position: 'relative' }}>
|
|
|
|
|
- <PickerView value={values}
|
|
|
|
|
- className="picker"
|
|
|
|
|
- maskClass="picker-mask"
|
|
|
|
|
- onChange={onPickerChange}
|
|
|
|
|
- immediateChange={true}
|
|
|
|
|
- indicatorStyle='height: 50px;'>
|
|
|
|
|
- <PickerViewColumn style='flex:0 0 45%'>
|
|
|
|
|
- {days.map(item => {
|
|
|
|
|
- return (
|
|
|
|
|
- <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{item}</View>
|
|
|
|
|
- );
|
|
|
|
|
- })}
|
|
|
|
|
- </PickerViewColumn>
|
|
|
|
|
- <PickerViewColumn>
|
|
|
|
|
- {hours.map(item => {
|
|
|
|
|
- return (
|
|
|
|
|
- <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{item < 10 ? `0${item}` : item}</View>
|
|
|
|
|
- );
|
|
|
|
|
- })}
|
|
|
|
|
- </PickerViewColumn>
|
|
|
|
|
- <PickerViewColumn>
|
|
|
|
|
- {minutes.map(item => {
|
|
|
|
|
- return (
|
|
|
|
|
- <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{item < 10 ? `0${item}` : item}</View>
|
|
|
|
|
- );
|
|
|
|
|
- })}
|
|
|
|
|
- </PickerViewColumn>
|
|
|
|
|
- </PickerView>
|
|
|
|
|
-
|
|
|
|
|
- <View className="point_bg1 ">
|
|
|
|
|
- <Text style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>:</Text>
|
|
|
|
|
|
|
+ return <View style={{display:'flex',flexDirection:'column'}}>
|
|
|
|
|
+ <Text className='modal_title' style={{ color: color }}>{props.title ? props.title : '测试标题 '}</Text>
|
|
|
|
|
+ <View style={{ backgroundColor: 'transparent', position: 'relative' }}>
|
|
|
|
|
+ <PickerView value={values}
|
|
|
|
|
+ className="picker"
|
|
|
|
|
+ maskClass="picker-mask"
|
|
|
|
|
+ onChange={onPickerChange}
|
|
|
|
|
+ immediateChange={true}
|
|
|
|
|
+ indicatorStyle='height: 50px;'>
|
|
|
|
|
+ <PickerViewColumn style='flex:0 0 45%'>
|
|
|
|
|
+ {days.map(item => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{item}</View>
|
|
|
|
|
+ );
|
|
|
|
|
+ })}
|
|
|
|
|
+ </PickerViewColumn>
|
|
|
|
|
+ <PickerViewColumn>
|
|
|
|
|
+ {hours.map(item => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{item < 10 ? `0${item}` : item}</View>
|
|
|
|
|
+ );
|
|
|
|
|
+ })}
|
|
|
|
|
+ </PickerViewColumn>
|
|
|
|
|
+ <PickerViewColumn>
|
|
|
|
|
+ {minutes.map(item => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{item < 10 ? `0${item}` : item}</View>
|
|
|
|
|
+ );
|
|
|
|
|
+ })}
|
|
|
|
|
+ </PickerViewColumn>
|
|
|
|
|
+ </PickerView>
|
|
|
|
|
+
|
|
|
|
|
+ <View className="point_bg1 ">
|
|
|
|
|
+ <Text style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>:</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ <View className='modal_operate'>
|
|
|
|
|
+ <View className='modal_btn' style={{ backgroundColor: color + alpha }} onClick={cancel}>
|
|
|
|
|
+ <Text className='modal_cancel_text' style={{ color: color }}>取消</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ <View className='btn_space' />
|
|
|
|
|
+ <View className='modal_btn' style={{ backgroundColor: color }} onClick={confirm}>
|
|
|
|
|
+ <Text className='modal_confirm_text' style={{ color: '#000' }}>确定</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
</View>
|
|
</View>
|
|
|
</View>
|
|
</View>
|
|
|
})
|
|
})
|