mpvue-calendar.vue 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. <template>
  2. <div class="mpvue-calendar" ref="calendar">
  3. <div class="calendar-tools" v-if="!isMonthRange">
  4. <div class="calendar-prev" @click="prev">
  5. <image :src="arrowLeft" v-if="!!arrowLeft">
  6. <i class="iconfont icon-arrow-left" v-else></i>
  7. </div>
  8. <div class="calendar-next" @click="next">
  9. <image :src="arrowRight" v-if="!!arrowRight">
  10. <i class="iconfont icon-arrow-right" v-else></i>
  11. </div>
  12. <div class="calendar-info" @click.stop="changeYear">
  13. <div class="mc-month">
  14. <div :class="['mc-month-inner', oversliding ? '' : 'month-transition']" :style="{'top': monthPosition + unit}" v-if="isIos">
  15. <span v-for="(m, i) in monthsLoop" :key="i" >{{m}}</span>
  16. </div>
  17. <div class="mc-month-text" v-else>{{monthText}}</div>
  18. </div>
  19. <div class="mc-year">{{year}}</div>
  20. </div>
  21. </div>
  22. <table cellpadding="5">
  23. <div class="mc-head" :class="['mc-head', {'mc-month-range-mode-head': isMonthRange}]">
  24. <div class="mc-head-box">
  25. <div v-for="(week, index) in weeks" :key="index" class="mc-week">{{week}}</div>
  26. </div>
  27. </div>
  28. <div :class="['mc-body', {'mc-range-mode': range, 'week-switch': weekSwitch && !isMonthRange, 'month-range-mode': isMonthRange}]" v-for="(days, index) in monthRangeDays" :key='index'>
  29. <div class="month-rang-head" v-if="isMonthRange">{{rangeOfMonths[index][2]}}</div>
  30. <tr v-for="(day,k1) in days" :key="k1" :class="{'gregorianStyle': !lunar}">
  31. <td v-for="(child,k2) in day" :key="k2" :class="[{'selected': child.selected, 'mc-today-element': child.isToday, 'disabled': child.disabled, 'mc-range-select-one': rangeBgHide && child.selected, 'lunarStyle': lunar, 'mc-range-row-first': k2 === 0 && child.selected, 'month-last-date': child.lastDay, 'month-first-date': 1 === child.day, 'mc-range-row-last': k2 === 6 && child.selected, 'mc-last-month': child.lastMonth, 'mc-next-month': child.nextMonth}, child.className, child.rangeClassName]" @click="select(k1, k2, child, $event, index)" class="mc-day" :style="itemStyle">
  32. <span v-if="showToday.show && child.isToday" class="mc-today calendar-date">{{showToday.text}}</span>
  33. <span :class="[{'mc-date-red': k2 === (monFirst ? 5 : 0) || k2 === 6}, 'calendar-date']" v-else>{{child.day}}</span>
  34. <div class="slot-element" v-if="!!child.content">{{child.content}}</div>
  35. <div class="mc-text remark-text" v-if="child.eventName && !clean">{{child.eventName}}</div>
  36. <div class="mc-dot" v-if="child.eventName && clean"></div>
  37. <div class="mc-text" :class="{'isLunarFestival': child.isAlmanac || child.isLunarFestival,'isGregorianFestival': child.isGregorianFestival,'isTerm': child.isTerm}" v-if="lunar && (!child.eventName || clean)">{{child.almanac || child.lunar}}</div>
  38. <div class="mc-range-bg" v-if="range && child.selected"/>
  39. </td>
  40. </tr>
  41. </div>
  42. </table>
  43. <div class="mpvue-calendar-change" :class="{'show': yearsShow}">
  44. <div class="calendar-years" v-if="!weekSwitch">
  45. <span v-for="y in years" :key="y" @click.stop="selectYear(y)" :class="{'active': y === year}">{{y}}</span>
  46. </div>
  47. <div :class="['calendar-months', {'calendar-week-switch-months': weekSwitch}]">
  48. <span v-for="(m, i) in months" :key="m" @click.stop="changeMonth(i)" :class="{'active': i === month}">{{m}}</span>
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. // +----------------------------------------------------------------------
  55. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  56. // +----------------------------------------------------------------------
  57. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  58. // +----------------------------------------------------------------------
  59. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  60. // +----------------------------------------------------------------------
  61. // | Author: CRMEB Team <admin@crmeb.com>
  62. // +----------------------------------------------------------------------
  63. import calendar from './calendarinit.js';
  64. import './icon.css';
  65. const isBrowser = !!window;
  66. const now = new Date();
  67. const todayString = [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('-');
  68. export default {
  69. props: {
  70. multi: {
  71. type: Boolean,
  72. default: false
  73. },
  74. arrowLeft: {
  75. type: String,
  76. default: ''
  77. },
  78. arrowRight: {
  79. type: String,
  80. default: ''
  81. },
  82. clean: {
  83. type: Boolean,
  84. default: false
  85. },
  86. now: {
  87. type: [String, Boolean],
  88. default: true
  89. },
  90. range:{
  91. type: Boolean,
  92. default: false
  93. },
  94. completion:{
  95. type: Boolean,
  96. default: false
  97. },
  98. value: {
  99. type: Array,
  100. default: function(){
  101. return []
  102. }
  103. },
  104. begin: {
  105. type: Array,
  106. default: function(){
  107. return []
  108. }
  109. },
  110. end: {
  111. type: Array,
  112. default: function(){
  113. return []
  114. }
  115. },
  116. zero:{
  117. type: Boolean,
  118. default: false
  119. },
  120. disabled:{
  121. type: Array,
  122. default: function(){
  123. return []
  124. }
  125. },
  126. almanacs:{
  127. type: Object,
  128. default: function(){
  129. return {}
  130. }
  131. },
  132. tileContent:{
  133. type: Array,
  134. default: function(){
  135. return []
  136. }
  137. },
  138. lunar: {
  139. type: Boolean,
  140. default: false
  141. },
  142. monFirst: {
  143. type: Boolean,
  144. default: false
  145. },
  146. weeks: {
  147. type: Array,
  148. default:function(){
  149. return this.monFirst ? ['一', '二', '三', '四', '五', '六', '日'] : ['日', '一', '二', '三', '四', '五', '六']
  150. }
  151. },
  152. months:{
  153. type: Array,
  154. default:function(){
  155. return ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
  156. }
  157. },
  158. events: {
  159. type: Object,
  160. default: function(){
  161. return {}
  162. }
  163. },
  164. weekSwitch: {
  165. type: Boolean,
  166. default: false
  167. },
  168. monthRange: {
  169. type: Array,
  170. default: function(){
  171. return []
  172. }
  173. },
  174. responsive: {
  175. type: Boolean,
  176. default: false
  177. },
  178. rangeMonthFormat: {
  179. type: String,
  180. default: ''
  181. }
  182. },
  183. data() {
  184. return {
  185. years:[],
  186. yearsShow:false,
  187. year: 0,
  188. month: 0,
  189. monthPosition: 0,
  190. day: 0,
  191. days: [],
  192. multiDays:[],
  193. today: [],
  194. handleMultiDay: [],
  195. firstRender: true,
  196. isIos: true,
  197. showToday: {},
  198. monthText: '',
  199. festival:{
  200. lunar:{
  201. "1-1":"春节",
  202. "1-15":"元宵节",
  203. "2-2":"龙头节",
  204. "5-5":"端午节",
  205. "7-7":"七夕节",
  206. "7-15":"中元节",
  207. "8-15":"中秋节",
  208. "9-9":"重阳节",
  209. "10-1":"寒衣节",
  210. "10-15":"下元节",
  211. "12-8":"腊八节",
  212. "12-23":"小年",
  213. },
  214. gregorian:{
  215. "1-1":"元旦",
  216. "2-14":"情人节",
  217. "3-8":"妇女节",
  218. "3-12":"植树节",
  219. "5-1":"劳动节",
  220. "5-4":"青年节",
  221. "6-1":"儿童节",
  222. "7-1":"建党节",
  223. "8-1":"建军节",
  224. "9-10":"教师节",
  225. "10-1":"国庆节",
  226. "12-24":"平安夜",
  227. "12-25":"圣诞节",
  228. },
  229. },
  230. rangeBegin: [],
  231. rangeEnd: [],
  232. multiDaysData: [],
  233. monthsLoop: [],
  234. itemWidth: 50,
  235. unit: isBrowser ? 'px' : 'rpx',
  236. positionH: isBrowser ? -24 : -40,
  237. monthIndex: 0,
  238. oversliding: false,
  239. rangeBgHide: false,
  240. monthRangeDays: [],
  241. rangeOfMonths: [],
  242. monthDays: [],
  243. weekIndex: 0,
  244. startWeekIndex: 0,
  245. positionWeek: true,
  246. isMonthRange: false,
  247. }
  248. },
  249. computed: {
  250. itemStyle() {
  251. return {width: this.itemWidth + 'px', height: this.itemWidth + 'px', fontSize: this.itemWidth / 4 + 'px', lineHeight: this.lunar ? (this.itemWidth / 1.5 + 'px') : (this.itemWidth + 'px')}
  252. }
  253. },
  254. watch:{
  255. events() {
  256. if (this.isRendeRangeMode()) return;
  257. this.render(this.year, this.month, '_WATCHRENDER_', 'events');
  258. },
  259. disabled() {
  260. if (this.isRendeRangeMode()) return;
  261. this.render(this.year, this.month, '_WATCHRENDER_', 'disabled');
  262. },
  263. value() {
  264. if (this.isRendeRangeMode('_WATCHRENDERVALUE_')) return;
  265. const value = this.value;
  266. let year = value[0], month = value[1] - 1;
  267. if (this.multi) {
  268. year = value[value.length - 1][0];
  269. month = value[value.length - 1][1] - 1;
  270. } else if (this.range) {
  271. if (this.isUserSelect) {
  272. year = this.year;
  273. month = this.month;
  274. this.isUserSelect = false;
  275. } else {
  276. year = value[0][0];
  277. month = value[0][1] - 1;
  278. const day = value[0][2];
  279. return this.render(year, month, '_WATCHRENDERVALUE_', [year, month, day]);
  280. }
  281. }
  282. this.render(year, month, '_WATCHRENDERVALUE_');
  283. },
  284. tileContent() {
  285. if (this.isRendeRangeMode()) return;
  286. this.render(this.year, this.month, '_WATCHRENDER_', 'tileContent');
  287. },
  288. almanacs() {
  289. if (this.isRendeRangeMode()) return;
  290. this.render(this.year, this.month, '_WATCHRENDER_', 'almanacs');
  291. },
  292. monthRange() {
  293. if (this.isRendeRangeMode()) return;
  294. this.render(this.year, this.month, '_WATCHRENDER_', 'almanacs');
  295. },
  296. responsive() {
  297. if (this.responsive) this.addResponsiveListener();
  298. }
  299. },
  300. created() {
  301. this.isMonthRange = !!this.monthRange.length;
  302. const loopArray = this.months.concat();
  303. loopArray.unshift(this.months[this.months.length - 1]);
  304. loopArray.push(this.months[0]);
  305. this.monthsLoop = loopArray;
  306. this.monthsLoopCopy = this.monthsLoop.concat();
  307. },
  308. mounted() {
  309. const self = this;
  310. this.resize();
  311. if (!isBrowser) {
  312. wx.getSystemInfo({
  313. success: function(res) {
  314. self.isIos = (res.system.split(' ') || [])[0] === 'iOS';
  315. }
  316. });
  317. } else if (this.responsive) {
  318. this.addResponsiveListener();
  319. }
  320. this.oversliding = true;
  321. this.initRender = true;
  322. this.init();
  323. },
  324. beforeDestroy() {
  325. if (isBrowser) {
  326. window.removeEventListener('resize', this.resize)
  327. }
  328. },
  329. methods: {
  330. init() {
  331. let now = new Date();
  332. this.year = now.getFullYear();
  333. this.month = now.getMonth();
  334. this.day = now.getDate();
  335. this.monthIndex = this.month + 1;
  336. if (this.value.length || this.multi) {
  337. if (this.range) {
  338. this.year = Number(this.value[0][0]);
  339. this.month = this.value[0][1] - 1;
  340. this.day = Number(this.value[0][2]);
  341. const yearEnd = Number(this.value[1][0]);
  342. const monthEnd = this.value[1][1] - 1;
  343. const dayEnd = this.value[1][2];
  344. this.rangeBegin = [this.year, this.month, this.day];
  345. this.rangeEnd = [yearEnd, monthEnd, dayEnd];
  346. } else if (this.multi) {
  347. this.multiDays = this.value;
  348. const handleMultiDay = this.handleMultiDay;
  349. if (this.firstRender) {
  350. this.firstRender = false;
  351. const thatYear = (this.value[0] || [])[0];
  352. const thatMonth = (this.value[0] || [])[1];
  353. if (isFinite(thatYear) && isFinite(thatMonth)) {
  354. this.month = parseInt(thatMonth) - 1;
  355. this.year = parseInt(thatYear);
  356. }
  357. } else if (this.handleMultiDay.length) {
  358. this.month = parseInt(handleMultiDay[handleMultiDay.length - 1][1]) - 1;
  359. this.year = parseInt(handleMultiDay[handleMultiDay.length - 1][0]);
  360. this.handleMultiDay = [];
  361. } else {
  362. this.month = parseInt(this.value[this.value.length - 1][1]) - 1;
  363. this.year = parseInt(this.value[this.value.length - 1][0]);
  364. }
  365. this.day = parseInt((this.value[0] || [])[2]);
  366. } else {
  367. this.year = parseInt(this.value[0]);
  368. this.month = parseInt(this.value[1]) - 1;
  369. this.day = parseInt(this.value[2]);
  370. }
  371. }
  372. this.updateHeadMonth();
  373. if (this.isRendeRangeMode()) return;
  374. this.render(this.year, this.month);
  375. },
  376. renderOption(year, month, i, playload) {
  377. const weekSwitch = this.monthRange.length ? false : this.weekSwitch;
  378. const seletSplit = this.value;
  379. const isMonthModeCurrentMonth = !weekSwitch && !playload;
  380. const disabledFilter = (disabled) => {
  381. return disabled.find(v => {
  382. const dayArr = v.split('-');
  383. return year === Number(dayArr[0]) && month === (dayArr[1] - 1) && i === Number(dayArr[2]);
  384. });
  385. };
  386. if (this.range) {
  387. const lastDay = new Date(year, month + 1, 0).getDate() === i ? {lastDay: true} : null;
  388. const options = Object.assign(
  389. {day: i},
  390. this.getLunarInfo(year, month + 1, i),
  391. this.getEvents(year, month + 1, i),
  392. lastDay
  393. );
  394. const {date, day} = options;
  395. const copyRangeBegin = this.rangeBegin.concat();
  396. const copyRangeEnd = this.rangeEnd.concat();
  397. copyRangeBegin[1] = copyRangeBegin[1] + 1;
  398. copyRangeEnd[1] = copyRangeEnd[1] + 1;
  399. if (weekSwitch || isMonthModeCurrentMonth) {
  400. (copyRangeEnd.join('-') === date) && (options.rangeClassName = 'mc-range-end');
  401. (copyRangeBegin.join('-') === date) && (options.rangeClassName = 'mc-range-begin');
  402. }
  403. if (year === copyRangeEnd[0] && (month + 1) === copyRangeEnd[1] && day === (copyRangeEnd[2] - 1)) {
  404. options.rangeClassName = options.rangeClassName ? ['mc-range-begin', 'mc-range-second-to-last'] : 'mc-range-second-to-last';
  405. }
  406. if (this.rangeBegin.length) {
  407. const beginTime = +new Date(this.rangeBegin[0], this.rangeBegin[1], this.rangeBegin[2]);
  408. const endTime = +new Date(this.rangeEnd[0], this.rangeEnd[1], this.rangeEnd[2]);
  409. const stepTime = +new Date(year, month, i);
  410. if (beginTime <= stepTime && endTime >= stepTime) {
  411. options.selected = true;
  412. }
  413. }
  414. if (this.begin.length) {
  415. const beginTime = +new Date(parseInt(this.begin[0]), parseInt(this.begin[1]) - 1, parseInt(this.begin[2]));
  416. if (beginTime > +new Date(year, month, i)) {
  417. options.disabled = true;
  418. }
  419. }
  420. if (this.end.length) {
  421. let endTime = Number(new Date(parseInt(this.end[0]), parseInt(this.end[1]) - 1, parseInt(this.end[2])));
  422. if (endTime < Number(new Date(year, month, i))) {
  423. options.disabled = true;
  424. }
  425. }
  426. if (playload && !weekSwitch) {
  427. options.disabled = true;
  428. } else if (this.disabled.length && disabledFilter(this.disabled)) {
  429. options.disabled = true;
  430. }
  431. const monthFirstDay = year + '-' + (month + 1) + '-' + 1;
  432. const monthLastDay = year + '-' + (month + 1) + '-' + new Date(year, month + 1, 0).getDate();
  433. (monthFirstDay === date && options.selected && !options.rangeClassName) && (options.rangeClassName = 'mc-range-month-first');
  434. (monthLastDay === date && options.selected && !options.rangeClassName) && (options.rangeClassName = 'mc-range-month-last');
  435. this.isCurrentMonthToday(options) && (options.isToday = true);
  436. (!weekSwitch && playload) && (options.selected = false);
  437. return options;
  438. } else if(this.multi) {
  439. let options;
  440. if (this.value.find(v => year === v[0] && month === v[1]-1 && i === v[2])){
  441. options = Object.assign(
  442. {day: i, selected: true},
  443. this.getLunarInfo(year, month + 1, i),
  444. this.getEvents(year, month + 1, i)
  445. );
  446. } else {
  447. options = Object.assign(
  448. {day: i, selected: false},
  449. this.getLunarInfo(year, month + 1, i),
  450. this.getEvents(year, month + 1, i)
  451. );
  452. if (this.begin.length) {
  453. const beginTime = +new Date(parseInt(this.begin[0]), parseInt(this.begin[1]) - 1, parseInt(this.begin[2]));
  454. if (beginTime > +(new Date(year, month, i))) {
  455. options.disabled = true;
  456. }
  457. }
  458. if (this.end.length){
  459. const endTime = +new Date(parseInt(this.end[0]), parseInt(this.end[1]) - 1, parseInt(this.end[2]));
  460. if (endTime < +(new Date(year, month, i))) {
  461. options.disabled = true;
  462. }
  463. }
  464. if (playload && !weekSwitch) {
  465. options.disabled = true;
  466. } else if (this.disabled.length && disabledFilter(this.disabled)) {
  467. options.disabled = true;
  468. }
  469. }
  470. if (options.selected && this.multiDaysData.length !== this.value.length) {
  471. this.multiDaysData.push(options);
  472. }
  473. this.isCurrentMonthToday(options) && (options.isToday = true);
  474. (!weekSwitch && playload) && (options.selected = false);
  475. return options;
  476. } else {
  477. const options = {};
  478. const monthHuman = month + 1;
  479. if (seletSplit[0] === year && seletSplit[1] === monthHuman && seletSplit[2] === i) {
  480. Object.assign(
  481. options,
  482. {day: i, selected: true},
  483. this.getLunarInfo(year, monthHuman, i),
  484. this.getEvents(year, monthHuman, i)
  485. );
  486. } else {
  487. Object.assign(
  488. options,
  489. {day: i, selected: false},
  490. this.getLunarInfo(year, monthHuman, i),
  491. this.getEvents(year, monthHuman, i)
  492. );
  493. if (this.begin.length) {
  494. const beginTime = +new Date(parseInt(this.begin[0]), parseInt(this.begin[1]) - 1, parseInt(this.begin[2]));
  495. if (beginTime > Number(new Date(year, month, i))) {
  496. options.disabled = true;
  497. }
  498. }
  499. if (this.end.length){
  500. const endTime = +new Date(parseInt(this.end[0]), parseInt(this.end[1]) - 1, parseInt(this.end[2]));
  501. if (endTime < +(new Date(year, month, i))) {
  502. options.disabled = true;
  503. }
  504. }
  505. if (playload && !weekSwitch) {
  506. options.disabled = true;
  507. } else if (this.disabled.length && disabledFilter(this.disabled)) {
  508. options.disabled = true;
  509. }
  510. }
  511. this.isCurrentMonthToday(options) && (options.isToday = true);
  512. (!weekSwitch && playload) && (options.selected = false);
  513. return options;
  514. }
  515. },
  516. isCurrentMonthToday(options) {
  517. const isToday = todayString === options.date;
  518. if (!isToday) return false;
  519. return this.weekSwitch ? isToday : (Number(todayString.split('-')[1]) === this.month + 1);
  520. },
  521. watchRender(type) {
  522. const weekSwitch = this.weekSwitch;
  523. const daysDeepCopy = JSON.parse(JSON.stringify(this.monthDays));
  524. if (type === 'events') {
  525. const events = this.events || {};
  526. Object.keys(events).forEach(value => {
  527. daysDeepCopy.some(v => v.some(vv => {
  528. if (vv.date === value) {
  529. vv.eventName = events[value];
  530. return true;
  531. }
  532. }))
  533. });
  534. this.monthDays = daysDeepCopy;
  535. } else if (type === 'disabled') {
  536. const disabled = this.disabled || [];
  537. disabled.forEach(value => {
  538. daysDeepCopy.some(v => v.some(vv => {
  539. if (vv.date === value) {
  540. vv.disabled = true;
  541. return true;
  542. }
  543. }))
  544. });
  545. } else if (type === 'almanacs') {
  546. const almanacs = this.almanacs || {};
  547. Object.keys(almanacs).forEach(value => {
  548. daysDeepCopy.some(v => v.some(vv => {
  549. if (vv.date.slice(5, 20) === value) {
  550. vv.lunar = almanacs[value];
  551. return true;
  552. }
  553. }))
  554. });
  555. } else if (type === 'tileContent') {
  556. const tileContent = this.tileContent || [];
  557. tileContent.forEach(value => {
  558. daysDeepCopy.some(v => v.some(vv => {
  559. if (vv.date === value.date) {
  560. vv.className = value.className;
  561. vv.content = value.content;
  562. return true;
  563. }
  564. }))
  565. });
  566. }
  567. if (weekSwitch) {
  568. this.monthDays = daysDeepCopy;
  569. this.days = [daysDeepCopy[this.weekIndex]];
  570. this.monthRangeDays = [this.days];
  571. } else {
  572. this.days = daysDeepCopy;
  573. this.monthRangeDays = [this.days];
  574. }
  575. },
  576. render(y, m, renderer, payload) {
  577. const weekSwitch = this.weekSwitch;
  578. const isCustomRender = renderer === 'CUSTOMRENDER';
  579. const isWatchRenderValue = renderer === '_WATCHRENDERVALUE_';
  580. this.year = y;
  581. this.month = m;
  582. if (renderer === '_WATCHRENDER_') return this.watchRender(payload);
  583. if (this.range && isWatchRenderValue) {
  584. if (!Array.isArray((this.value || [])[0])) {
  585. this.rangeBegin = [];
  586. this.rangeEnd = [];
  587. } else {
  588. this.rangeBegin = [this.value[0][0], this.value[0][1] - 1, this.value[0][2]];
  589. this.rangeEnd = [this.value[1][0], this.value[1][1] - 1, this.value[1][2]];
  590. }
  591. }
  592. if (isWatchRenderValue && weekSwitch) {
  593. this.positionWeek = true;
  594. }
  595. if (isCustomRender) {
  596. this.year = y;
  597. this.month = m;
  598. this.positionWeek = true;
  599. if (weekSwitch && !payload) {
  600. this.startWeekIndex = 0;
  601. this.weekIndex = 0;
  602. }
  603. this.updateHeadMonth();
  604. }
  605. let firstDayOfMonth = new Date(y, m, 1).getDay();
  606. const lastDateOfMonth = new Date(y, m + 1, 0).getDate();
  607. let lastDayOfLastMonth = new Date(y, m, 0).getDate();
  608. this.year = y;
  609. let i = 1, line = 0, temp = [], nextMonthPushDays = 1;
  610. for (i; i <= lastDateOfMonth; i++) {
  611. let day = new Date(y, m, i).getDay();
  612. let k;
  613. if (day === 0) {
  614. temp[line] = [];
  615. } else if (i === 1) {
  616. temp[line] = [];
  617. k = lastDayOfLastMonth - firstDayOfMonth + 1;
  618. for (let j = 0; j < firstDayOfMonth; j++) { //generate prev month surplus option
  619. temp[line].push(Object.assign(
  620. this.renderOption(this.computedPrevYear(y, m), this.computedPrevMonth(false, m), k, 'prevMonth'),
  621. {lastMonth: true}
  622. ));
  623. k++;
  624. }
  625. }
  626. temp[line].push(this.renderOption(y, m, i)); //generate current month option
  627. if (day === 6 && i < lastDateOfMonth) {
  628. line++;
  629. } else if (i === lastDateOfMonth) {
  630. let k = 1;
  631. const lastDateOfMonthLength = this.monFirst ? 7 : 6;
  632. for (let d = day; d < lastDateOfMonthLength; d++) { //generate next month surplus option
  633. temp[line].push(Object.assign(
  634. this.renderOption(this.computedNextYear(y, m), this.computedNextMonth(false, m), k, 'nextMonth'),
  635. {nextMonth: true}
  636. ));
  637. k++;
  638. }
  639. nextMonthPushDays = k;
  640. }
  641. }
  642. const completion = this.completion;
  643. if (this.monFirst) {
  644. if (!firstDayOfMonth) {
  645. let lastMonthDay = lastDayOfLastMonth;
  646. const LastMonthItems = [];
  647. for (let i = 1; i <= 7; i++) {
  648. LastMonthItems.unshift(Object.assign(
  649. this.renderOption(this.computedPrevYear(y, m), this.computedPrevMonth(false, m), lastMonthDay, 'prevMonth'),
  650. {lastMonth: true}
  651. ));
  652. lastMonthDay --;
  653. }
  654. temp.unshift(LastMonthItems);
  655. }
  656. temp.forEach((item, index) => {
  657. if (!index) {
  658. return item.splice(0, 1);
  659. };
  660. temp[index-1].length < 7 && temp[index-1].push(item.splice(0, 1)[0]);
  661. });
  662. if (this.isMonthRange && temp[temp.length - 1][0].nextMonth) {
  663. temp.splice(temp.length - 1, 1); //if the first day of last line is nextMonth, delete this line
  664. }
  665. if (!completion && !weekSwitch) {
  666. const lastIndex = temp.length - 1;
  667. const secondToLastIndex = lastIndex - 1;
  668. const differentMonth = temp[lastIndex][0].date.split('-')[1] !== temp[secondToLastIndex][6].date.split('-')[1];
  669. differentMonth && temp.splice(lastIndex, 1);
  670. }
  671. }
  672. if (completion && !weekSwitch && temp.length <= 5 && nextMonthPushDays > 0) {
  673. for (let i = temp.length; i<=5; i++) {
  674. temp[i] = [];
  675. let start = nextMonthPushDays + (i - line -1) * 7;
  676. for (let d = start; d <= start + 6; d++) {
  677. temp[i].push(Object.assign(
  678. {day: d, disabled: true, nextMonth: true},
  679. this.getLunarInfo(this.computedNextYear(), this.computedNextMonth(true), d),
  680. this.getEvents(this.computedNextYear(), this.computedNextMonth(true), d)
  681. ));
  682. }
  683. }
  684. }
  685. if (this.tileContent.length) {
  686. temp.forEach((item, index) => {
  687. item.forEach((v, i) => {
  688. const contents = this.tileContent.find(val => val.date === v.date);
  689. if (contents) {
  690. const {className, content} = contents || {};
  691. v.className = className;
  692. v.content = content;
  693. }
  694. });
  695. });
  696. }
  697. if (weekSwitch) {
  698. const tempLength = temp.length;
  699. const lastLineMonth = temp[tempLength - 1][0].date.split('-')[1]; // last line month
  700. const secondLastMonth = temp[tempLength - 2][0].date.split('-')[1]; // second-to-last line month
  701. lastLineMonth !== secondLastMonth && temp.splice(tempLength - 1, 1);
  702. }
  703. this.monthDays = temp;
  704. if (weekSwitch && !this.isMonthRange) {
  705. if (this.positionWeek) {
  706. let payloadDay = '';
  707. let searchIndex = true;
  708. if (Array.isArray(payload)) { //range
  709. payloadDay = [payload[0], payload[1] + 1, payload[2]].join('-');
  710. } else if (this.multi || isWatchRenderValue) {
  711. if (this.thisTimeSelect) {
  712. payloadDay = this.thisTimeSelect;
  713. } else {
  714. payloadDay = this.multi ? this.value[this.value.length - 1].join('-') : this.value.join('-') ;
  715. }
  716. }
  717. if (payload === 'SETTODAY') {
  718. payloadDay = todayString;
  719. } else if (isCustomRender) {
  720. if (typeof payload === 'string') {
  721. payloadDay = [y, Number(m) + 1, payload].join('-');
  722. searchIndex = true;
  723. } else if (typeof payload === 'number') {
  724. const setIndex = payload > temp.length ? temp.length - 1 : payload;
  725. this.startWeekIndex = setIndex;
  726. this.weekIndex = setIndex;
  727. this.positionWeek = false;
  728. searchIndex = false;
  729. }
  730. }
  731. const positionDay = payloadDay || todayString;
  732. if (searchIndex) {
  733. temp.some((v, i) => {
  734. const isWeekNow = v.find(vv => vv.date === positionDay);
  735. if (isWeekNow) {
  736. this.startWeekIndex = i;
  737. this.weekIndex = i;
  738. return true;
  739. }
  740. });
  741. }
  742. this.positionWeek = false;
  743. }
  744. this.days = [temp[this.startWeekIndex]];
  745. if (this.initRender) {
  746. this.setMonthRangeofWeekSwitch();
  747. this.initRender = false;
  748. }
  749. } else {
  750. this.days = temp;
  751. }
  752. const todayText = '今';
  753. if (typeof this.now === 'boolean' && !this.now) {
  754. this.showToday = {show: false};
  755. } else if (typeof this.now === 'string') {
  756. this.showToday = {
  757. show: true,
  758. text: this.now || todayText
  759. };
  760. } else {
  761. this.showToday = {
  762. show: true,
  763. text: todayText
  764. };
  765. }
  766. this.monthRangeDays = [this.days];
  767. isWatchRenderValue && this.updateHeadMonth();
  768. return this.days;
  769. },
  770. rendeRange(renderer) {
  771. const range = [];
  772. const self = this;
  773. const monthRange = this.monthRange;
  774. function formatDateText(fYear, fMonth) {
  775. const reg = /([y]+)(.*?)([M]+)(.*?)$/i;
  776. const rangeMonthFormat = self.rangeMonthFormat || 'yyyy-MM';
  777. reg.exec(rangeMonthFormat);
  778. return String(fYear).substring(4 - RegExp.$1.length) + RegExp.$2 + String(fMonth).substring(2 - RegExp.$3.length) + RegExp.$4;
  779. }
  780. if (monthRange[0] === monthRange[1]) {
  781. const [y, m] = monthRange[0].split('-');
  782. range.push([Number(y), Number(m), formatDateText(y, m)])
  783. } else {
  784. const monthRangeOfStart = monthRange[0].split('-');
  785. const monthRangeOfEnd = monthRange[1].split('-');
  786. let startYear = +monthRangeOfStart[0];
  787. let startMonth = +monthRangeOfStart[1];
  788. let endYear = +monthRangeOfEnd[0];
  789. let endtMonth = +monthRangeOfEnd[1] > 12 ? 12 : +monthRangeOfEnd[1];
  790. while (startYear < endYear || startMonth <= endtMonth) {
  791. range.push([startYear, startMonth, formatDateText(startYear, startMonth)]);
  792. if (startMonth === 12 && startYear !== endYear) {
  793. startYear++;
  794. startMonth = 0;
  795. }
  796. startMonth++;
  797. }
  798. }
  799. this.rangeOfMonths = range;
  800. const monthsRange = range.map(item => {
  801. const [yearParam, monthParam] = item;
  802. return this.render(yearParam, monthParam - 1, renderer);
  803. });
  804. this.monthRangeDays = monthsRange;
  805. },
  806. isRendeRangeMode(renderer) {
  807. this.isMonthRange = !!this.monthRange.length;
  808. if (this.isMonthRange) {
  809. this.rendeRange(renderer);
  810. return true;
  811. }
  812. },
  813. renderer(y, m, w) {
  814. const renderY = y || this.year;
  815. const renderM = typeof parseInt(m) === 'number' ? (m - 1) : this.month;
  816. this.initRender = true;
  817. this.render(renderY, renderM, 'CUSTOMRENDER', w);
  818. !this.weekSwitch && (this.monthsLoop = this.monthsLoopCopy.concat());
  819. },
  820. computedPrevYear(year, month) {
  821. let value = year;
  822. if((month - 1) < 0){
  823. value--;
  824. }
  825. return value;
  826. },
  827. computedPrevMonth(isString, month) {
  828. let value = month;
  829. if((month - 1) < 0){
  830. value = 11;
  831. } else {
  832. value--;
  833. }
  834. if(isString) {
  835. return value + 1;
  836. }
  837. return value;
  838. },
  839. computedNextYear(year, month) {
  840. let value = year;
  841. if((month + 1) > 11){
  842. value++;
  843. }
  844. return value;
  845. },
  846. computedNextMonth(isString, month) {
  847. let value = month;
  848. if((month + 1) > 11){
  849. value = 0;
  850. } else {
  851. value++;
  852. }
  853. if(isString) {
  854. return value + 1;
  855. }
  856. return value;
  857. },
  858. getLunarInfo(y, m, d) {
  859. let lunarInfo = calendar.solar2lunar(y, m, d);
  860. let yearEve = '';
  861. if (lunarInfo.lMonth === 12 && lunarInfo.lDay === calendar.monthDays(lunarInfo.lYear, 12)) {
  862. yearEve = '除夕';
  863. }
  864. let lunarValue = lunarInfo.IDayCn;
  865. let Term = lunarInfo.Term;
  866. let isLunarFestival = false;
  867. let isGregorianFestival = false;
  868. if(this.festival.lunar[lunarInfo.lMonth + "-" + lunarInfo.lDay]) {
  869. lunarValue = this.festival.lunar[lunarInfo.lMonth + "-" + lunarInfo.lDay];
  870. isLunarFestival = true;
  871. } else if(this.festival.gregorian[m + "-" + d]) {
  872. lunarValue = this.festival.gregorian[m + "-" + d];
  873. isGregorianFestival = true;
  874. }
  875. const lunarInfoObj = {
  876. date: `${y}-${m}-${d}`,
  877. lunar: yearEve || Term || lunarValue,
  878. isLunarFestival: isLunarFestival,
  879. isGregorianFestival: isGregorianFestival,
  880. isTerm: !!yearEve || lunarInfo.isTerm
  881. };
  882. if (Object.keys(this.almanacs).length) {
  883. Object.assign(lunarInfoObj, {
  884. almanac: this.almanacs[m + "-" + d] || '',
  885. isAlmanac: !!this.almanacs[m + "-" + d]
  886. });
  887. }
  888. return lunarInfoObj;
  889. },
  890. getEvents(y, m, d){
  891. if(Object.keys(this.events).length == 0) return false;
  892. let eventName = this.events[y + "-" + m + "-" + d];
  893. let data = {};
  894. if(eventName!=undefined){
  895. data.eventName = eventName;
  896. }
  897. return data;
  898. },
  899. prev(e) {
  900. e && e.stopPropagation();
  901. if (this.isMonthRange) return;
  902. const weekSwitch = this.weekSwitch;
  903. const changeMonth = (changed) => {
  904. if (this.monthIndex === 1) {
  905. this.oversliding = false;
  906. this.month = 11;
  907. this.year = parseInt(this.year) - 1;
  908. this.monthIndex = this.monthIndex - 1;
  909. } else if (this.monthIndex === 0) {
  910. this.oversliding = true;
  911. this.monthIndex = 12;
  912. setTimeout(() => this.prev(e), 50);
  913. return this.updateHeadMonth('custom');
  914. } else if (this.monthIndex === 13) {
  915. this.month = 11;
  916. this.year = parseInt(this.year) - 1;
  917. this.monthIndex = this.monthIndex - 1;
  918. } else {
  919. this.oversliding = false;
  920. this.month = parseInt(this.month) - 1;
  921. this.monthIndex = this.monthIndex - 1;
  922. }
  923. this.updateHeadMonth('custom');
  924. this.render(this.year, this.month);
  925. (typeof changed === 'function') && changed();
  926. const weekIndex = weekSwitch ? this.weekIndex : undefined;
  927. this.$emit('prev', this.year, this.month + 1, weekIndex);
  928. }
  929. if (!this.weekSwitch) return changeMonth();
  930. const changeWeek = () => {
  931. this.weekIndex = this.weekIndex - 1;
  932. this.days = [this.monthDays[this.weekIndex]];
  933. this.monthRangeDays = [this.days];
  934. this.setMonthRangeofWeekSwitch();
  935. this.$emit('prev', this.year, this.month + 1, this.weekIndex);
  936. }
  937. const currentWeek = (this.days[0] || [])[0] || {};
  938. if (currentWeek.lastMonth || currentWeek.day === 1) {
  939. const monthChenged = () => {
  940. const lastMonthLength = this.monthDays.length;
  941. const startWeekIndex = currentWeek.lastMonth ? lastMonthLength - 1: lastMonthLength;
  942. this.startWeekIndex = startWeekIndex;
  943. this.weekIndex = startWeekIndex;
  944. changeWeek();
  945. }
  946. changeMonth(monthChenged);
  947. } else {
  948. changeWeek();
  949. }
  950. },
  951. next(e) {
  952. e && e.stopPropagation();
  953. if (this.isMonthRange) return;
  954. const weekSwitch = this.weekSwitch;
  955. const changeMonth = () => {
  956. if (this.monthIndex === 12) {
  957. this.oversliding = false;
  958. this.month = 0;
  959. this.year = parseInt(this.year) + 1;
  960. this.monthIndex = this.monthIndex + 1;
  961. } else if (this.monthIndex === 0 && this.month === 11) {
  962. this.oversliding = false;
  963. this.month = 0;
  964. this.year = parseInt(this.year) + 1;
  965. this.monthIndex = this.monthIndex + 1;
  966. } else if (this.monthIndex === 13) {
  967. this.oversliding = true;
  968. this.monthIndex = 1;
  969. setTimeout(() => this.next(e), 50);
  970. return this.updateHeadMonth('custom');
  971. } else {
  972. this.oversliding = false;
  973. this.month = parseInt(this.month) + 1;
  974. this.monthIndex = this.monthIndex + 1;
  975. }
  976. this.updateHeadMonth('custom');
  977. this.render(this.year, this.month);
  978. const weekIndex = weekSwitch ? this.weekIndex : undefined;
  979. this.$emit('next', this.year, this.month + 1, weekIndex);
  980. }
  981. if (!this.weekSwitch) return changeMonth();
  982. const changeWeek = () => {
  983. this.weekIndex = this.weekIndex + 1;
  984. this.days = [this.monthDays[this.weekIndex]];
  985. this.monthRangeDays = [this.days];
  986. this.setMonthRangeofWeekSwitch();
  987. this.$emit('next', this.year, this.month + 1, this.weekIndex);
  988. }
  989. const currentWeek = (this.days[0] || [])[6] || {};
  990. if (currentWeek.nextMonth || currentWeek.day === (new Date(this.year, this.month + 1, 0).getDate())) {
  991. const startWeekIndex = currentWeek.nextMonth ? 1 : 0;
  992. this.startWeekIndex = startWeekIndex;
  993. this.weekIndex = startWeekIndex;
  994. changeMonth();
  995. } else {
  996. changeWeek();
  997. }
  998. },
  999. select(k1, k2, data, e, monthIndex) {
  1000. e && e.stopPropagation();
  1001. const weekSwitch = this.weekSwitch;
  1002. if (data.lastMonth && !weekSwitch) {
  1003. return this.prev(e);
  1004. } else if (data.nextMonth && !weekSwitch) {
  1005. return this.next(e);
  1006. }
  1007. if (data.disabled) return;
  1008. (data || {}).event = (this.events || {})[data.date] || '';
  1009. const {selected, day, date} = data;
  1010. const selectedDates = date.split('-');
  1011. const selectYear = Number(selectedDates[0]);
  1012. const selectMonth = selectedDates[1] - 1;
  1013. const selectMonthHuman = Number(selectedDates[1]);
  1014. const selectDay = Number(selectedDates[2]);;
  1015. if (this.range) {
  1016. this.isUserSelect = true;
  1017. if (this.rangeBegin.length === 0 || this.rangeEndTemp !== 0) {
  1018. this.rangeBegin = [selectYear, selectMonth, selectDay];
  1019. this.rangeBeginTemp = this.rangeBegin;
  1020. this.rangeEnd = [selectYear, selectMonth, selectDay];
  1021. this.thisTimeSelect = this.rangeEnd;
  1022. this.rangeEndTemp = 0;
  1023. } else {
  1024. this.rangeEnd = [selectYear, selectMonth, selectDay];
  1025. this.thisTimeSelect = [selectYear, selectMonth, selectDay];
  1026. if (this.rangeBegin.join('-') === this.rangeEnd.join('-')) {
  1027. return this.rangeEndTemp = 0;
  1028. }
  1029. this.rangeEndTemp = 1;
  1030. if (+new Date(this.rangeEnd[0], this.rangeEnd[1], this.rangeEnd[2]) < +new Date(this.rangeBegin[0], this.rangeBegin[1], this.rangeBegin[2])) {
  1031. this.rangeBegin = this.rangeEnd;
  1032. this.rangeEnd = this.rangeBeginTemp;
  1033. }
  1034. const rangeDate = (date) => {
  1035. return date.map((v, k) =>{
  1036. const value = k === 1 ? v + 1 : v;
  1037. return this.zero ? this.zeroPad(value) : value;
  1038. });
  1039. }
  1040. const begin = rangeDate(this.rangeBegin);
  1041. const end = rangeDate(this.rangeEnd);
  1042. this.value.splice(0, 1, begin)
  1043. this.value.splice(1, 1, end)
  1044. this.$emit('select', begin, end);
  1045. }
  1046. this.rangeBgHide = !this.rangeEndTemp || (this.rangeBegin.join('-') === this.rangeEnd.join('-'));
  1047. this.positionWeek = true;
  1048. if (this.isMonthRange) {
  1049. this.rendeRange();
  1050. } else {
  1051. this.render(this.year, this.month, undefined, this.thisTimeSelect);
  1052. }
  1053. } else if (this.multi) {
  1054. const filterDayIndex = this.value.findIndex(v => v.join('-') === date);
  1055. if(~filterDayIndex) {
  1056. this.handleMultiDay = this.value.splice(filterDayIndex, 1);
  1057. } else {
  1058. this.value.push([Number(Number(selectedDates[0])), Number(selectedDates[1]), day]);
  1059. }
  1060. this.days[k1][k2].selected = !selected;
  1061. if (this.monthDays[k1][k2].selected) {
  1062. this.multiDaysData.push(data);
  1063. } else {
  1064. this.multiDaysData = this.multiDaysData.filter(item => item.date !== date);
  1065. }
  1066. this.thisTimeSelect = date;
  1067. this.$emit('select', this.value, this.multiDaysData);
  1068. } else {
  1069. const currentSelected = this.value.join('-');
  1070. this.monthRangeDays.some(value => value.some(v => !!v.find(vv => {
  1071. if (vv.date === currentSelected) {
  1072. vv.selected = false;
  1073. return true;
  1074. }
  1075. })));
  1076. this.monthRangeDays[monthIndex][k1][k2].selected = true;
  1077. this.day = day;
  1078. const selectDate = [selectYear, selectMonthHuman, selectDay];
  1079. this.value[0] = selectYear;
  1080. this.value[1] = selectMonthHuman;
  1081. this.value[2] = selectDay;
  1082. this.today = [k1, k2];
  1083. this.$emit('select', selectDate, data);
  1084. }
  1085. },
  1086. changeYear() {
  1087. if(this.yearsShow) {
  1088. this.yearsShow = false;
  1089. return false;
  1090. }
  1091. this.yearsShow = true;
  1092. this.years = [];
  1093. for (let i = this.year - 5; i < this.year + 7; i++){
  1094. this.years.push(i);
  1095. }
  1096. },
  1097. changeMonth(value) {
  1098. this.oversliding && (this.oversliding = false);
  1099. this.yearsShow = false;
  1100. this.month = value;
  1101. this.render(this.year, this.month, 'CUSTOMRENDER', 0);
  1102. this.updateHeadMonth();
  1103. this.weekSwitch && this.setMonthRangeofWeekSwitch();
  1104. this.$emit('selectMonth', this.month + 1, this.year);
  1105. },
  1106. selectYear(value) {
  1107. this.yearsShow = false;
  1108. this.year = value;
  1109. this.render(this.year, this.month);
  1110. this.$emit('selectYear', value);
  1111. },
  1112. setToday() {
  1113. const now = new Date();
  1114. this.year = now.getFullYear();
  1115. this.month = now.getMonth();
  1116. this.day = now.getDate();
  1117. this.positionWeek = true;
  1118. this.render(this.year, this.month, undefined, 'SETTODAY');
  1119. this.updateHeadMonth();
  1120. },
  1121. setMonthRangeofWeekSwitch() {
  1122. this.monthsLoop = this.monthsLoopCopy.concat();
  1123. this.days[0].reduce((prev, current) => {
  1124. if (!prev) return;
  1125. const prveDate = ((prev || {}).date || '').split('-');
  1126. const prevYear = prveDate[0];
  1127. const prevMonth = prveDate[1];
  1128. const currentMonth = ((current || {}).date || '').split('-')[1];
  1129. if (prevMonth === currentMonth) {
  1130. return current;
  1131. } else {
  1132. const prevMonthText = this.months[prevMonth - 1];
  1133. const currentMonthText = this.months[currentMonth - 1];
  1134. this.monthsLoop[this.monthIndex] = prevMonthText + '~' + currentMonthText;
  1135. }
  1136. });
  1137. },
  1138. dateInfo(y, m, d) {
  1139. return calendar.solar2lunar(y, m, d);
  1140. },
  1141. zeroPad(n) {
  1142. return String(n < 10 ? '0' + n : n)
  1143. },
  1144. updateHeadMonth(type) {
  1145. if (!type) this.monthIndex = this.month + 1;
  1146. this.monthPosition = this.monthIndex * this.positionH;
  1147. this.monthText = this.months[this.month];
  1148. },
  1149. addResponsiveListener() {
  1150. window.addEventListener('resize', this.resize);
  1151. },
  1152. resize() {
  1153. const calendar = this.$refs.calendar;
  1154. this.itemWidth = (calendar.clientWidth/7 - 4).toFixed(5);
  1155. }
  1156. }
  1157. }
  1158. </script>