index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <el-container>
  3. <el-header>
  4. <h1>XD</h1>
  5. <el-divider></el-divider>
  6. </el-header>
  7. <el-main>
  8. <div class="hidden-xs-only">
  9. <dater-larger :date="date" :anotherDate="anotherDate" :options="options" @calculate="calculate"/>
  10. </div>
  11. <div class="hidden-sm-and-up">
  12. <dater-smaller :date="date" :anotherDate="anotherDate" :options="options" @calculate="calculate"/>
  13. </div>
  14. </el-main>
  15. <el-footer>
  16. <div class="footer-line">
  17. <center>
  18. &copy;&nbsp;zbLiuLiu&nbsp;{{year}}&nbsp;-&nbsp;本项目完全开源免费,基于Vue.js、Nuxt.js、Element UI制作。
  19. </center>
  20. </div>
  21. <div class="footer-line">
  22. <center>
  23. <a href="http://git.zbliuliu.top/zbLiuLiu/TimeCalculator">http://git.zbliuliu.top/zbLiuLiu/TimeCalculator</a>
  24. </center>
  25. </div>
  26. </el-footer>
  27. </el-container>
  28. </template>
  29. <script>
  30. import Dater1 from '../components/DaterLarger.vue'
  31. import DaterSmaller from '../components/DaterSmaller.vue'
  32. export default {
  33. components: { Dater1 },
  34. data(){
  35. return {
  36. date: {
  37. year:0,
  38. month:0,
  39. day:0,
  40. hour:0,
  41. minute:0,
  42. second:0
  43. },
  44. anotherDate: {
  45. year:0,
  46. month:0,
  47. day:0,
  48. hour:0,
  49. minute:0,
  50. second:0
  51. },
  52. options:[
  53. {label:"加",value:"add", script:function(a,b) {
  54. return a+b
  55. }},
  56. {label:"减",value:"subtract", script:function(a,b) {
  57. return a-b
  58. }},
  59. ],
  60. option:"",
  61. year: (new Date()).getFullYear()
  62. }
  63. },
  64. methods:{
  65. calculate(d,a,o,component){
  66. var func = function(a){return a};
  67. for (const index in this.options) {
  68. if (Object.hasOwnProperty.call(this.options, index)) {
  69. const option = this.options[index];
  70. if(option.value==o){
  71. func = option.script;
  72. break;
  73. }
  74. }
  75. }
  76. var date = this.dater(d);
  77. var anotherDate = this.dater(a);
  78. // console.log(date,anotherDate)
  79. var year = func(date.getFullYear(),anotherDate.getFullYear()),
  80. month = func(date.getMonth(),anotherDate.getMonth()),
  81. day = func(date.getDate()-1,anotherDate.getDate()-1),
  82. hour = func(date.getHours(),anotherDate.getHours()),
  83. minute = func(date.getMinutes(),anotherDate.getMinutes()),
  84. second = func(date.getSeconds(),anotherDate.getSeconds());
  85. var thirdDate = new Date();
  86. thirdDate.setTime(0);
  87. thirdDate.setFullYear(year);
  88. thirdDate.setMonth(month);
  89. thirdDate.setDate(day+1);
  90. thirdDate.setHours(hour);
  91. thirdDate.setMinutes(minute);
  92. thirdDate.setSeconds(second);
  93. // console.log(thirdDate)
  94. this.date.year = thirdDate.getFullYear()
  95. this.date.month = thirdDate.getMonth()
  96. this.date.day = thirdDate.getDate()-1
  97. this.date.hour = thirdDate.getHours()
  98. this.date.minute = thirdDate.getMinutes()
  99. this.date.second = thirdDate.getSeconds()
  100. component.focus('anotherDateYear')
  101. },
  102. dater(date){
  103. var year = date.year||0,
  104. month = date.month||0,
  105. day = date.day+1||0,
  106. hour = date.hour||0,
  107. minute = date.minute||0,
  108. second = date.second||0;
  109. var dateObj = new Date();
  110. dateObj.setTime(0);
  111. dateObj.setFullYear(year);
  112. dateObj.setMonth(month);
  113. dateObj.setDate(day);
  114. dateObj.setHours(hour);
  115. dateObj.setMinutes(minute);
  116. dateObj.setSeconds(second);
  117. return dateObj;
  118. }
  119. },
  120. mounted(){
  121. setInterval(()=>{
  122. this.year = (new Date()).getFullYear()
  123. },100)
  124. }
  125. }
  126. </script>
  127. <style scoped>
  128. .footer-line{
  129. line-height: 1.8;
  130. color: #C0C4CC;
  131. }
  132. .footer-line *{
  133. color: inherit !important;
  134. text-decoration: inherit !important;
  135. transition: color .5s;
  136. }
  137. .footer-line *[href]:hover,
  138. .footer-line *[href]:focus-visible
  139. {
  140. color: #909399 !important;
  141. text-decoration: underline !important;
  142. }
  143. </style>