2018-03-12 14:13:59 +00:00
|
|
|
<script>
|
2019-02-01 09:23:00 +00:00
|
|
|
/* eslint react/no-multi-comp:0, no-console:0, no-unused-vars:0 */
|
2018-03-12 14:13:59 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
import '../assets/index.less';
|
|
|
|
import '@/components/vc-time-picker/assets/index.less';
|
|
|
|
import Picker from '../src/Picker';
|
|
|
|
import zhCN from '../src/locale/zh_CN';
|
|
|
|
import enUS from '../src/locale/en_US';
|
|
|
|
import '../../vc-time-picker/assets/index.less';
|
|
|
|
import TimePickerPanel from '../../vc-time-picker/Panel';
|
|
|
|
import BaseMixin from '@/components/_util/BaseMixin';
|
2018-03-12 14:13:59 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
import RangeCalendar from '../src/RangeCalendar';
|
2018-03-12 14:13:59 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
import 'moment/locale/zh-cn';
|
|
|
|
import 'moment/locale/en-gb';
|
2018-03-12 14:13:59 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const cn = window.location.search.indexOf('cn') !== -1;
|
2018-03-12 14:13:59 +00:00
|
|
|
|
|
|
|
if (cn) {
|
2019-01-12 03:33:27 +00:00
|
|
|
moment.locale('zh-cn');
|
2018-03-12 14:13:59 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
moment.locale('en-gb');
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const now = moment();
|
2018-03-12 14:13:59 +00:00
|
|
|
if (cn) {
|
2019-01-12 03:33:27 +00:00
|
|
|
now.utcOffset(8);
|
2018-03-12 14:13:59 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
now.utcOffset(0);
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const defaultCalendarValue = now.clone();
|
|
|
|
defaultCalendarValue.add(-1, 'month');
|
2018-03-12 14:13:59 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const timePickerElement = (h) => <TimePickerPanel defaultValue={[moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')]}/>;
|
2018-03-12 14:13:59 +00:00
|
|
|
|
|
|
|
function newArray (start, end) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const result = [];
|
2018-03-12 14:13:59 +00:00
|
|
|
for (let i = start; i < end; i++) {
|
2019-01-12 03:33:27 +00:00
|
|
|
result.push(i);
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return result;
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function disabledDate (current) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const date = moment();
|
|
|
|
date.hour(0);
|
|
|
|
date.minute(0);
|
|
|
|
date.second(0);
|
|
|
|
return current.isBefore(date); // can not select days before today
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function disabledTime (time, type) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log('disabledTime', time, type);
|
2018-03-12 14:13:59 +00:00
|
|
|
if (type === 'start') {
|
|
|
|
return {
|
|
|
|
disabledHours () {
|
2019-01-12 03:33:27 +00:00
|
|
|
const hours = newArray(0, 60);
|
|
|
|
hours.splice(20, 4);
|
|
|
|
return hours;
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
|
|
|
disabledMinutes (h) {
|
|
|
|
if (h === 20) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return newArray(0, 31);
|
2018-03-12 14:13:59 +00:00
|
|
|
} else if (h === 23) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return newArray(30, 60);
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return [];
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
|
|
|
disabledSeconds () {
|
2019-01-12 03:33:27 +00:00
|
|
|
return [55, 56];
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
disabledHours () {
|
2019-01-12 03:33:27 +00:00
|
|
|
const hours = newArray(0, 60);
|
|
|
|
hours.splice(2, 6);
|
|
|
|
return hours;
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
|
|
|
disabledMinutes (h) {
|
|
|
|
if (h === 20) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return newArray(0, 31);
|
2018-03-12 14:13:59 +00:00
|
|
|
} else if (h === 23) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return newArray(30, 60);
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return [];
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
|
|
|
disabledSeconds () {
|
2019-01-12 03:33:27 +00:00
|
|
|
return [55, 56];
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const formatStr = 'YYYY-MM-DD HH:mm:ss';
|
2018-03-12 14:13:59 +00:00
|
|
|
function format (v) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return v ? v.format(formatStr) : '';
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isValidRange (v) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return v && v[0] && v[1];
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onStandaloneChange (value) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log('onChange');
|
|
|
|
console.log(value[0] && format(value[0]), value[1] && format(value[1]));
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onStandaloneSelect (value) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log('onSelect');
|
|
|
|
console.log(format(value[0]), format(value[1]));
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Demo = {
|
|
|
|
mixins: [BaseMixin],
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
value: [],
|
|
|
|
hoverValue: [],
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onChange (value) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log('onChange', value);
|
|
|
|
this.setState({ value });
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onHoverChange (hoverValue) {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.setState({ hoverValue });
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
render (h) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const state = this.$data;
|
2018-03-12 14:13:59 +00:00
|
|
|
const calendar = (
|
|
|
|
<RangeCalendar
|
|
|
|
hoverValue={state.hoverValue}
|
|
|
|
onHoverChange={this.onHoverChange}
|
|
|
|
showWeekNumber={false}
|
|
|
|
dateInputPlaceholder={['start', 'end']}
|
|
|
|
defaultValue={[now, now.clone().add(1, 'months')]}
|
|
|
|
locale={cn ? zhCN : enUS}
|
|
|
|
disabledTime={disabledTime}
|
|
|
|
timePicker={timePickerElement(h)}
|
2018-10-29 12:48:23 +00:00
|
|
|
renderFooter={() => 'extra footer'}
|
2018-03-12 14:13:59 +00:00
|
|
|
/>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-03-12 14:13:59 +00:00
|
|
|
return (
|
|
|
|
<Picker
|
|
|
|
value={state.value}
|
|
|
|
onChange={this.onChange}
|
|
|
|
animation='slide-up'
|
|
|
|
calendar={calendar}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
({ value }) => {
|
|
|
|
return (<span>
|
|
|
|
<input
|
|
|
|
placeholder='please select'
|
|
|
|
style={{ width: '350px' }}
|
|
|
|
disabled={state.disabled}
|
|
|
|
readOnly
|
|
|
|
className='ant-calendar-picker-input ant-input'
|
|
|
|
value={isValidRange(value) && `${format(value[0])} - ${format(value[1])}` || ''}
|
|
|
|
/>
|
2019-01-12 03:33:27 +00:00
|
|
|
</span>);
|
2018-03-12 14:13:59 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
</Picker>);
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-12 14:13:59 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
render (h) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h2>calendar</h2>
|
|
|
|
<div style={{ margin: '10px' }}>
|
|
|
|
<RangeCalendar
|
|
|
|
showToday={false}
|
|
|
|
showWeekNumber
|
|
|
|
dateInputPlaceholder={['start', 'end']}
|
|
|
|
locale={cn ? zhCN : enUS}
|
|
|
|
showOk={false}
|
|
|
|
showClear
|
|
|
|
format={formatStr}
|
|
|
|
onChange={onStandaloneChange}
|
|
|
|
onSelect={onStandaloneSelect}
|
|
|
|
disabledDate={disabledDate}
|
|
|
|
timePicker={timePickerElement(h)}
|
|
|
|
disabledTime={disabledTime}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<br />
|
|
|
|
|
|
|
|
<div style={{ margin: '20px' }}>
|
|
|
|
<Demo />
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-03-12 14:13:59 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-12 14:13:59 +00:00
|
|
|
|
|
|
|
</script>
|