index.wxs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* eslint-disable */
  2. var utils = require('../../utils.wxs');
  3. function getMark(date) {
  4. return getDate(date).getMonth() + 1;
  5. }
  6. var ROW_HEIGHT = 64;
  7. function getDayStyle(type, index, date, rowHeight, color, firstDayOfWeek) {
  8. var style = [];
  9. var current = getDate(date).getDay() || 7;
  10. var offset = current < firstDayOfWeek ? (7 - firstDayOfWeek + current) :
  11. current === 7 && firstDayOfWeek === 0 ? 0 :
  12. (current - firstDayOfWeek);
  13. if (index === 0) {
  14. style.push(['margin-left', (100 * offset) / 7 + '%']);
  15. }
  16. if (rowHeight !== ROW_HEIGHT) {
  17. style.push(['height', rowHeight + 'px']);
  18. }
  19. if (color) {
  20. if (
  21. type === 'start' ||
  22. type === 'end' ||
  23. type === 'start-end' ||
  24. type === 'multiple-selected' ||
  25. type === 'multiple-middle'
  26. ) {
  27. style.push(['background', color]);
  28. } else if (type === 'middle') {
  29. style.push(['color', color]);
  30. }
  31. }
  32. return style
  33. .map(function(item) {
  34. return item.join(':');
  35. })
  36. .join(';');
  37. }
  38. function formatMonthTitle(date) {
  39. date = getDate(date);
  40. return date.getFullYear() + '年' + (date.getMonth() + 1) + '月';
  41. }
  42. function getMonthStyle(visible, date, rowHeight) {
  43. if (!visible) {
  44. date = getDate(date);
  45. var totalDay = utils.getMonthEndDay(
  46. date.getFullYear(),
  47. date.getMonth() + 1
  48. );
  49. var offset = getDate(date).getDay();
  50. var padding = Math.ceil((totalDay + offset) / 7) * rowHeight;
  51. return 'padding-bottom:' + padding + 'px';
  52. }
  53. }
  54. module.exports = {
  55. getMark: getMark,
  56. getDayStyle: getDayStyle,
  57. formatMonthTitle: formatMonthTitle,
  58. getMonthStyle: getMonthStyle
  59. };