ant-design-vue/components/vc-calendar/demo/antd-month-calendar.vue

157 lines
3.9 KiB
Vue
Raw Normal View History

2018-03-12 14:13:59 +00:00
<script>
/* eslint react/no-multi-comp:0, no-console:0 */
2019-01-12 03:33:27 +00:00
import '../assets/index.less';
import PropTypes from '@/components/_util/vue-types';
import DatePicker 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 BaseMixin from '@/components/_util/BaseMixin';
2018-03-12 14:13:59 +00:00
2019-01-12 03:33:27 +00:00
import MonthCalendar from '../src/MonthCalendar';
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 format = 'YYYY-MM';
const cn = window.location.search.indexOf('cn') !== -1;
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.locale('zh-cn').utcOffset(8);
2018-03-12 14:13:59 +00:00
} else {
2019-01-12 03:33:27 +00:00
now.locale('en-gb').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
const Demo = {
mixins: [BaseMixin],
props: {
defaultValue: PropTypes.object,
},
2019-09-28 12:45:07 +00:00
data() {
2018-03-12 14:13:59 +00:00
return {
showTime: true,
disabled: false,
value: this.defaultValue,
2019-01-12 03:33:27 +00:00
};
2018-03-12 14:13:59 +00:00
},
methods: {
2019-09-28 12:45:07 +00:00
onChange(value) {
2019-01-12 03:33:27 +00:00
console.log(`DatePicker change: ${value && value.format(format)}`);
2018-03-12 14:13:59 +00:00
this.setState({
value,
2019-01-12 03:33:27 +00:00
});
2018-03-12 14:13:59 +00:00
},
2019-09-28 12:45:07 +00:00
onShowTimeChange(e) {
2018-03-12 14:13:59 +00:00
this.setState({
showTime: e.target.checked,
2019-01-12 03:33:27 +00:00
});
2018-03-12 14:13:59 +00:00
},
2019-09-28 12:45:07 +00:00
toggleDisabled() {
2018-03-12 14:13:59 +00:00
this.setState({
disabled: !this.disabled,
2019-01-12 03:33:27 +00:00
});
2018-03-12 14:13:59 +00:00
},
},
2019-09-28 12:45:07 +00:00
render() {
2019-01-12 03:33:27 +00:00
const state = this.$data;
2019-09-28 12:45:07 +00:00
const calendar = <MonthCalendar locale={cn ? zhCN : enUS} style={{ zIndex: 1000 }} />;
return (
<div style={{ width: '240px', margin: '20px' }}>
<div style={{ marginBottom: '10px' }}>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
<input checked={state.disabled} onChange={this.toggleDisabled} type="checkbox" />{' '}
disabled
</label>
</div>
<div
style={{
boxSizing: 'border-box',
position: 'relative',
display: 'block',
lineHeight: 1.5,
marginBottom: '22px',
2018-03-12 14:13:59 +00:00
}}
>
2019-09-28 12:45:07 +00:00
<DatePicker
animation="slide-up"
disabled={state.disabled}
calendar={calendar}
value={state.value}
onChange={this.onChange}
scopedSlots={{
default: ({ value }) => {
return (
<input
style={{ width: '200px' }}
readOnly
disabled={state.disabled}
value={value && value.format(format)}
placeholder="请选择日期"
/>
);
},
}}
></DatePicker>
</div>
2018-03-12 14:13:59 +00:00
</div>
2019-09-28 12:45:07 +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
2019-09-28 12:45:07 +00:00
function onStandaloneSelect(value) {
console.log('month-calendar select', value && value.format(format));
2018-03-12 14:13:59 +00:00
}
2019-09-28 12:45:07 +00:00
function onStandaloneChange(value) {
console.log('month-calendar change', value && value.format(format));
2018-03-12 14:13:59 +00:00
}
2019-09-28 12:45:07 +00:00
function disabledDate(value) {
return value.year() > now.year() || (value.year() === now.year() && value.month() > now.month());
2018-03-12 14:13:59 +00:00
}
2019-09-28 12:45:07 +00:00
function onMonthCellContentRender(value) {
2018-03-12 14:13:59 +00:00
// console.log('month-calendar onMonthCellContentRender', (value && value.format(format)));
2019-01-12 03:33:27 +00:00
return `${value.month() + 1}`;
2018-03-12 14:13:59 +00:00
}
export default {
2019-09-28 12:45:07 +00:00
render() {
2018-03-12 14:13:59 +00:00
return (
<div
style={{
zIndex: 1000,
position: 'relative',
width: '600px',
margin: '0 auto',
}}
>
<MonthCalendar
locale={cn ? zhCN : enUS}
style={{ zIndex: 1000 }}
disabledDate={disabledDate}
onSelect={onStandaloneSelect}
onChange={onStandaloneChange}
monthCellContentRender={onMonthCellContentRender}
defaultValue={defaultCalendarValue}
renderFooter={() => 'extra footer'}
2018-03-12 14:13:59 +00:00
/>
<div style={{ marginTop: '200px' }}>
<Demo defaultValue={now} />
</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>