index.wxs 1.4 KB

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