| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <template>
- <div>
- <h1>月份选择器</h1>
- <div class="demo-component">
- <vue-monthly-picker
- v-model="selectedMonth"
- :input-class="{'input': isDisplayInput}"
- :disabled="isDisable"
- :month-labels="locale"
- :clear-option="clearOption"
- :min="min"
- :max="max"
- :alignment="alignment"
- :selected-background-color="selectedBackgroundColor"
- @selected="handleSelect"
- />
- </div>
- <div>选择的月份: {{ selectedMonth }}</div>
- <div>
- <div class="form-group">
- <label>只读</label>
- <div class="input-group">
- <Switches v-model="isDisable" />
- {{ isDisable ? 'Disabled': 'Enable' }}
- </div>
- </div>
- <div class="form-group">
- <label>限制范围</label>
- <div class="input-group">
- <Switches v-model="isLimitRange" />
- {{ rangeDisplay }}
- </div>
- </div>
- <div class="form-group">
- <label>显示</label>
- <div class="input-group">
- <Switches
- v-model="isDisplayInput"
- true-value="Input"
- false-value="Label"
- />
- {{ isDisplayInput? 'Input': 'Label' }}
- </div>
- </div>
- <div class="form-group">
- <label>清空</label>
- <div class="input-group">
- <Switches v-model="clearOption" />
- {{ clearOption ? 'Enable': 'Disabled' }}
- </div>
- </div>
- <div class="form-group">
- <label>国际化</label>
- <select
- v-model="locale"
- placeholder="Select a language"
- class="form-control"
- >
- <option
- v-for="option in options"
- :key="option.id"
- :value="option.monthLabels"
- >
- {{ option.title }}
- </option>
- </select>
- </div>
- <div class="form-group">
- <label>对齐</label>
- <select
- v-model="alignment"
- placeholder="Select an alignment"
- class="form-control"
- >
- <option
- v-for="alignment1 in alignments"
- :key="alignment1"
- :value="alignment1"
- >
- {{ alignment1 }}
- </option>
- </select>
- </div>
- <div class="form-group">
- <label>背景色</label>
- <select
- v-model="selectedBackgroundColor"
- placeholder="Select an color"
- class="form-control"
- >
- <option
- v-for="color in colorExamples"
- :key="color"
- :value="color"
- >
- {{ color }}
- </option>
- </select>
- </div>
- </div>
- </div>
- </template>
- <script>
- import moment from 'moment';
- import VueMonthlyPicker from '@/vue-monthly-picker/index.js';
- import Switches from '@/switches/index.js';
- export default {
- name: 'App',
- components: {
- VueMonthlyPicker, Switches,
- },
- data() {
- return {
- selectedMonth: moment(),
- isDisable: false,
- isDisplayInput: true,
- locale: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
- alignment: 'left',
- selectedBackgroundColor: 'blue',
- options: [
- {
- id: 1,
- title: 'English',
- monthLabels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
- },
- {
- id: 2,
- title: '中文',
- monthLabels: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
- },
- {
- id: 3,
- title: 'Korean',
- monthLabels: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
- },
- ],
- alignments: ['left', 'center', 'right'],
- colorExamples: ['blue', 'red', 'black'],
- min: null,
- max: null,
- isLimitRange: false,
- clearOption: true,
- };
- },
- computed: {
- rangeDisplay() {
- if (!this.min || !this.max) {
- return 'Disabled';
- }
- return this.min.format('YYYY/MM') + '-' + this.max.format('YYYY/MM');
- },
- },
- watch: {
- isLimitRange(newValue) {
- if (newValue) {
- this.setSelectRange(moment().subtract(6, 'months'), moment().add(6, 'months'));
- } else {
- this.setSelectRange(null, null);
- }
- },
- },
- methods: {
- handleSelect(value) {
- console.log('Select', value);
- },
- setSelectRange(min, max) {
- this.min = min;
- this.max = max;
- },
- },
- };
- </script>
- <style scoped>
- #app {
- font-family: "Avenir", Helvetica, Arial, sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- text-align: center;
- color: #2c3e50;
- margin-top: 60px;
- }
- .demo-component {
- width: 250px;
- margin: auto;
- }
- .control-group {
- margin-top: 100px;
- }
- .control {
- text-align: center;
- }
- .option-list {
- margin-top: 20px;
- }
- </style>
|