123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <template>
- <el-container>
- <el-header>
- <h1>XD</h1>
- <el-divider></el-divider>
- </el-header>
- <el-main>
- <div class="hidden-xs-only">
- <dater-larger :date="date" :anotherDate="anotherDate" :options="options" @calculate="calculate"/>
- </div>
- <div class="hidden-sm-and-up">
- <dater-smaller :date="date" :anotherDate="anotherDate" :options="options" @calculate="calculate"/>
- </div>
- </el-main>
- <el-footer>
- <center style="color:#C0C4CC;">
- © zbLiuLiu {{year}} - 本项目完全开源免费,基于Vue.js、Nuxt.js、Element UI制作。
- </center>
- </el-footer>
- </el-container>
- </template>
- <script>
- import Dater1 from '../components/DaterLarger.vue'
- import DaterSmaller from '../components/DaterSmaller.vue'
- export default {
- components: { Dater1 },
- data(){
- return {
- date: {
- year:0,
- month:0,
- day:0,
- hour:0,
- minute:0,
- second:0
- },
- anotherDate: {
- year:0,
- month:0,
- day:0,
- hour:0,
- minute:0,
- second:0
- },
- options:[
- {label:"加",value:"add", script:function(a,b) {
- return a+b
- }},
- {label:"减",value:"subtract", script:function(a,b) {
- return a-b
- }},
- ],
- option:"",
- year: (new Date()).getFullYear()
- }
- },
- methods:{
- calculate(d,a,o,component){
- var func = function(a){return a};
- for (const index in this.options) {
- if (Object.hasOwnProperty.call(this.options, index)) {
- const option = this.options[index];
- if(option.value==o){
- func = option.script;
- break;
- }
- }
- }
- var date = this.dater(d);
- var anotherDate = this.dater(a);
- // console.log(date,anotherDate)
- var year = func(date.getFullYear(),anotherDate.getFullYear()),
- month = func(date.getMonth(),anotherDate.getMonth()),
- day = func(date.getDate()-1,anotherDate.getDate()-1),
- hour = func(date.getHours(),anotherDate.getHours()),
- minute = func(date.getMinutes(),anotherDate.getMinutes()),
- second = func(date.getSeconds(),anotherDate.getSeconds());
- var thirdDate = new Date();
- thirdDate.setTime(0);
- thirdDate.setFullYear(year);
- thirdDate.setMonth(month);
- thirdDate.setDate(day+1);
- thirdDate.setHours(hour);
- thirdDate.setMinutes(minute);
- thirdDate.setSeconds(second);
- // console.log(thirdDate)
- this.date.year = thirdDate.getFullYear()
- this.date.month = thirdDate.getMonth()
- this.date.day = thirdDate.getDate()-1
- this.date.hour = thirdDate.getHours()
- this.date.minute = thirdDate.getMinutes()
- this.date.second = thirdDate.getSeconds()
- component.focus('anotherDateYear')
- },
- dater(date){
- var year = date.year||0,
- month = date.month||0,
- day = date.day+1||0,
- hour = date.hour||0,
- minute = date.minute||0,
- second = date.second||0;
- var dateObj = new Date();
- dateObj.setTime(0);
- dateObj.setFullYear(year);
- dateObj.setMonth(month);
- dateObj.setDate(day);
- dateObj.setHours(hour);
- dateObj.setMinutes(minute);
- dateObj.setSeconds(second);
- return dateObj;
- }
- },
- mounted(){
- setInterval(()=>{
- this.year = (new Date()).getFullYear()
- },100)
- }
- }
- </script>
|