calendar.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. "use strict";
  2. const uni_modules_uniDatetimePicker_components_uniDatetimePicker_util = require("./util.js");
  3. const common_vendor = require("../../../../common/vendor.js");
  4. const uni_modules_uniDatetimePicker_components_uniDatetimePicker_i18n_index = require("./i18n/index.js");
  5. const calendarItem = () => "./calendar-item.js";
  6. const timePicker = () => "./time-picker.js";
  7. const {
  8. t
  9. } = common_vendor.initVueI18n(uni_modules_uniDatetimePicker_components_uniDatetimePicker_i18n_index.messages);
  10. const _sfc_main = {
  11. components: {
  12. calendarItem,
  13. timePicker
  14. },
  15. props: {
  16. date: {
  17. type: String,
  18. default: ""
  19. },
  20. defTime: {
  21. type: [String, Object],
  22. default: ""
  23. },
  24. selectableTimes: {
  25. type: [Object],
  26. default() {
  27. return {};
  28. }
  29. },
  30. selected: {
  31. type: Array,
  32. default() {
  33. return [];
  34. }
  35. },
  36. lunar: {
  37. type: Boolean,
  38. default: false
  39. },
  40. startDate: {
  41. type: String,
  42. default: ""
  43. },
  44. endDate: {
  45. type: String,
  46. default: ""
  47. },
  48. range: {
  49. type: Boolean,
  50. default: false
  51. },
  52. typeHasTime: {
  53. type: Boolean,
  54. default: false
  55. },
  56. insert: {
  57. type: Boolean,
  58. default: true
  59. },
  60. showMonth: {
  61. type: Boolean,
  62. default: true
  63. },
  64. clearDate: {
  65. type: Boolean,
  66. default: true
  67. },
  68. left: {
  69. type: Boolean,
  70. default: true
  71. },
  72. right: {
  73. type: Boolean,
  74. default: true
  75. },
  76. checkHover: {
  77. type: Boolean,
  78. default: true
  79. },
  80. hideSecond: {
  81. type: [Boolean],
  82. default: false
  83. },
  84. pleStatus: {
  85. type: Object,
  86. default() {
  87. return {
  88. before: "",
  89. after: "",
  90. data: [],
  91. fulldate: ""
  92. };
  93. }
  94. }
  95. },
  96. data() {
  97. return {
  98. show: false,
  99. weeks: [],
  100. calendar: {},
  101. nowDate: "",
  102. aniMaskShow: false,
  103. firstEnter: true,
  104. time: "",
  105. timeRange: {
  106. startTime: "",
  107. endTime: ""
  108. },
  109. tempSingleDate: "",
  110. tempRange: {
  111. before: "",
  112. after: ""
  113. }
  114. };
  115. },
  116. watch: {
  117. date: {
  118. immediate: true,
  119. handler(newVal, oldVal) {
  120. if (!this.range) {
  121. this.tempSingleDate = newVal;
  122. setTimeout(() => {
  123. this.init(newVal);
  124. }, 100);
  125. }
  126. }
  127. },
  128. defTime: {
  129. immediate: true,
  130. handler(newVal, oldVal) {
  131. if (!this.range) {
  132. this.time = newVal;
  133. } else {
  134. this.timeRange.startTime = newVal.start;
  135. this.timeRange.endTime = newVal.end;
  136. }
  137. }
  138. },
  139. startDate(val) {
  140. this.cale.resetSatrtDate(val);
  141. this.cale.setDate(this.nowDate.fullDate);
  142. this.weeks = this.cale.weeks;
  143. },
  144. endDate(val) {
  145. this.cale.resetEndDate(val);
  146. this.cale.setDate(this.nowDate.fullDate);
  147. this.weeks = this.cale.weeks;
  148. },
  149. selected(newVal) {
  150. this.cale.setSelectInfo(this.nowDate.fullDate, newVal);
  151. this.weeks = this.cale.weeks;
  152. },
  153. pleStatus: {
  154. immediate: true,
  155. handler(newVal, oldVal) {
  156. const {
  157. before,
  158. after,
  159. fulldate,
  160. which
  161. } = newVal;
  162. this.tempRange.before = before;
  163. this.tempRange.after = after;
  164. setTimeout(() => {
  165. if (fulldate) {
  166. this.cale.setHoverMultiple(fulldate);
  167. if (before && after) {
  168. this.cale.lastHover = true;
  169. if (this.rangeWithinMonth(after, before))
  170. return;
  171. this.setDate(before);
  172. } else {
  173. this.cale.setMultiple(fulldate);
  174. this.setDate(this.nowDate.fullDate);
  175. this.calendar.fullDate = "";
  176. this.cale.lastHover = false;
  177. }
  178. } else {
  179. this.cale.setDefaultMultiple(before, after);
  180. if (which === "left") {
  181. this.setDate(before);
  182. this.weeks = this.cale.weeks;
  183. } else {
  184. this.setDate(after);
  185. this.weeks = this.cale.weeks;
  186. }
  187. this.cale.lastHover = true;
  188. }
  189. }, 16);
  190. }
  191. }
  192. },
  193. computed: {
  194. reactStartTime() {
  195. const activeDate = this.range ? this.tempRange.before : this.calendar.fullDate;
  196. const res = activeDate === this.startDate ? this.selectableTimes.start : "";
  197. return res;
  198. },
  199. reactEndTime() {
  200. const activeDate = this.range ? this.tempRange.after : this.calendar.fullDate;
  201. const res = activeDate === this.endDate ? this.selectableTimes.end : "";
  202. return res;
  203. },
  204. /**
  205. * for i18n
  206. */
  207. selectDateText() {
  208. return t("uni-datetime-picker.selectDate");
  209. },
  210. startDateText() {
  211. return this.startPlaceholder || t("uni-datetime-picker.startDate");
  212. },
  213. endDateText() {
  214. return this.endPlaceholder || t("uni-datetime-picker.endDate");
  215. },
  216. okText() {
  217. return t("uni-datetime-picker.ok");
  218. },
  219. monText() {
  220. return t("uni-calender.MON");
  221. },
  222. TUEText() {
  223. return t("uni-calender.TUE");
  224. },
  225. WEDText() {
  226. return t("uni-calender.WED");
  227. },
  228. THUText() {
  229. return t("uni-calender.THU");
  230. },
  231. FRIText() {
  232. return t("uni-calender.FRI");
  233. },
  234. SATText() {
  235. return t("uni-calender.SAT");
  236. },
  237. SUNText() {
  238. return t("uni-calender.SUN");
  239. }
  240. },
  241. created() {
  242. this.cale = new uni_modules_uniDatetimePicker_components_uniDatetimePicker_util.Calendar({
  243. // date: new Date(),
  244. selected: this.selected,
  245. startDate: this.startDate,
  246. endDate: this.endDate,
  247. range: this.range
  248. // multipleStatus: this.pleStatus
  249. });
  250. this.init(this.date);
  251. },
  252. methods: {
  253. leaveCale() {
  254. this.firstEnter = true;
  255. },
  256. handleMouse(weeks) {
  257. if (weeks.disable)
  258. return;
  259. if (this.cale.lastHover)
  260. return;
  261. let {
  262. before,
  263. after
  264. } = this.cale.multipleStatus;
  265. if (!before)
  266. return;
  267. this.calendar = weeks;
  268. this.cale.setHoverMultiple(this.calendar.fullDate);
  269. this.weeks = this.cale.weeks;
  270. if (this.firstEnter) {
  271. this.$emit("firstEnterCale", this.cale.multipleStatus);
  272. this.firstEnter = false;
  273. }
  274. },
  275. rangeWithinMonth(A, B) {
  276. const [yearA, monthA] = A.split("-");
  277. const [yearB, monthB] = B.split("-");
  278. return yearA === yearB && monthA === monthB;
  279. },
  280. // 取消穿透
  281. clean() {
  282. this.close();
  283. },
  284. clearCalender() {
  285. if (this.range) {
  286. this.timeRange.startTime = "";
  287. this.timeRange.endTime = "";
  288. this.tempRange.before = "";
  289. this.tempRange.after = "";
  290. this.cale.multipleStatus.before = "";
  291. this.cale.multipleStatus.after = "";
  292. this.cale.multipleStatus.data = [];
  293. this.cale.lastHover = false;
  294. } else {
  295. this.time = "";
  296. this.tempSingleDate = "";
  297. }
  298. this.calendar.fullDate = "";
  299. this.setDate();
  300. },
  301. bindDateChange(e) {
  302. const value = e.detail.value + "-1";
  303. this.init(value);
  304. },
  305. /**
  306. * 初始化日期显示
  307. * @param {Object} date
  308. */
  309. init(date) {
  310. this.cale.setDate(date);
  311. this.weeks = this.cale.weeks;
  312. this.nowDate = this.calendar = this.cale.getInfo(date);
  313. },
  314. // choiceDate(weeks) {
  315. // if (weeks.disable) return
  316. // this.calendar = weeks
  317. // // 设置多选
  318. // this.cale.setMultiple(this.calendar.fullDate, true)
  319. // this.weeks = this.cale.weeks
  320. // this.tempSingleDate = this.calendar.fullDate
  321. // this.tempRange.before = this.cale.multipleStatus.before
  322. // this.tempRange.after = this.cale.multipleStatus.after
  323. // this.change()
  324. // },
  325. /**
  326. * 打开日历弹窗
  327. */
  328. open() {
  329. if (this.clearDate && !this.insert) {
  330. this.cale.cleanMultipleStatus();
  331. this.init(this.date);
  332. }
  333. this.show = true;
  334. this.$nextTick(() => {
  335. setTimeout(() => {
  336. this.aniMaskShow = true;
  337. }, 50);
  338. });
  339. },
  340. /**
  341. * 关闭日历弹窗
  342. */
  343. close() {
  344. this.aniMaskShow = false;
  345. this.$nextTick(() => {
  346. setTimeout(() => {
  347. this.show = false;
  348. this.$emit("close");
  349. }, 300);
  350. });
  351. },
  352. /**
  353. * 确认按钮
  354. */
  355. confirm() {
  356. this.setEmit("confirm");
  357. this.close();
  358. },
  359. /**
  360. * 变化触发
  361. */
  362. change() {
  363. if (!this.insert)
  364. return;
  365. this.setEmit("change");
  366. },
  367. /**
  368. * 选择月份触发
  369. */
  370. monthSwitch() {
  371. let {
  372. year,
  373. month
  374. } = this.nowDate;
  375. this.$emit("monthSwitch", {
  376. year,
  377. month: Number(month)
  378. });
  379. },
  380. /**
  381. * 派发事件
  382. * @param {Object} name
  383. */
  384. setEmit(name) {
  385. let {
  386. year,
  387. month,
  388. date,
  389. fullDate,
  390. lunar,
  391. extraInfo
  392. } = this.calendar;
  393. this.$emit(name, {
  394. range: this.cale.multipleStatus,
  395. year,
  396. month,
  397. date,
  398. time: this.time,
  399. timeRange: this.timeRange,
  400. fulldate: fullDate,
  401. lunar,
  402. extraInfo: extraInfo || {}
  403. });
  404. },
  405. /**
  406. * 选择天触发
  407. * @param {Object} weeks
  408. */
  409. choiceDate(weeks) {
  410. if (weeks.disable)
  411. return;
  412. this.calendar = weeks;
  413. this.calendar.userChecked = true;
  414. this.cale.setMultiple(this.calendar.fullDate, true);
  415. this.weeks = this.cale.weeks;
  416. this.tempSingleDate = this.calendar.fullDate;
  417. this.tempRange.before = this.cale.multipleStatus.before;
  418. this.tempRange.after = this.cale.multipleStatus.after;
  419. this.change();
  420. },
  421. /**
  422. * 回到今天
  423. */
  424. backtoday() {
  425. let date = this.cale.getDate(/* @__PURE__ */ new Date()).fullDate;
  426. this.init(date);
  427. this.change();
  428. },
  429. /**
  430. * 比较时间大小
  431. */
  432. dateCompare(startDate, endDate) {
  433. startDate = new Date(startDate.replace("-", "/").replace("-", "/"));
  434. endDate = new Date(endDate.replace("-", "/").replace("-", "/"));
  435. if (startDate <= endDate) {
  436. return true;
  437. } else {
  438. return false;
  439. }
  440. },
  441. /**
  442. * 上个月
  443. */
  444. pre() {
  445. const preDate = this.cale.getDate(this.nowDate.fullDate, -1, "month").fullDate;
  446. this.setDate(preDate);
  447. this.monthSwitch();
  448. },
  449. /**
  450. * 下个月
  451. */
  452. next() {
  453. const nextDate = this.cale.getDate(this.nowDate.fullDate, 1, "month").fullDate;
  454. this.setDate(nextDate);
  455. this.monthSwitch();
  456. },
  457. /**
  458. * 设置日期
  459. * @param {Object} date
  460. */
  461. setDate(date) {
  462. this.cale.setDate(date);
  463. this.weeks = this.cale.weeks;
  464. this.nowDate = this.cale.getInfo(date);
  465. }
  466. }
  467. };
  468. if (!Array) {
  469. const _component_calendar_item = common_vendor.resolveComponent("calendar-item");
  470. const _component_time_picker = common_vendor.resolveComponent("time-picker");
  471. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  472. (_component_calendar_item + _component_time_picker + _easycom_uni_icons2)();
  473. }
  474. const _easycom_uni_icons = () => "../../../uni-icons/components/uni-icons/uni-icons.js";
  475. if (!Math) {
  476. _easycom_uni_icons();
  477. }
  478. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  479. return common_vendor.e({
  480. a: !$props.insert && $data.show
  481. }, !$props.insert && $data.show ? {
  482. b: $data.aniMaskShow ? 1 : "",
  483. c: common_vendor.o((...args) => $options.clean && $options.clean(...args))
  484. } : {}, {
  485. d: $props.insert || $data.show
  486. }, $props.insert || $data.show ? common_vendor.e({
  487. e: $props.left
  488. }, $props.left ? {
  489. f: common_vendor.o((...args) => $options.pre && $options.pre(...args))
  490. } : {}, {
  491. g: common_vendor.t(($data.nowDate.year || "") + " 年 " + ($data.nowDate.month || "") + " 月"),
  492. h: $props.date,
  493. i: common_vendor.o((...args) => $options.bindDateChange && $options.bindDateChange(...args)),
  494. j: $props.right
  495. }, $props.right ? {
  496. k: common_vendor.o((...args) => $options.next && $options.next(...args))
  497. } : {}, {
  498. l: !$props.insert
  499. }, !$props.insert ? {
  500. m: common_vendor.o((...args) => $options.clean && $options.clean(...args))
  501. } : {}, {
  502. n: !$props.insert ? 1 : "",
  503. o: $props.showMonth
  504. }, $props.showMonth ? {
  505. p: common_vendor.t($data.nowDate.month)
  506. } : {}, {
  507. q: common_vendor.t($options.SUNText),
  508. r: common_vendor.t($options.monText),
  509. s: common_vendor.t($options.TUEText),
  510. t: common_vendor.t($options.WEDText),
  511. v: common_vendor.t($options.THUText),
  512. w: common_vendor.t($options.FRIText),
  513. x: common_vendor.t($options.SATText),
  514. y: common_vendor.f($data.weeks, (item, weekIndex, i0) => {
  515. return {
  516. a: common_vendor.f(item, (weeks, weeksIndex, i1) => {
  517. return {
  518. a: common_vendor.o($options.choiceDate, weeksIndex),
  519. b: common_vendor.o($options.handleMouse, weeksIndex),
  520. c: "92faa71e-0-" + i0 + "-" + i1,
  521. d: common_vendor.p({
  522. weeks,
  523. calendar: $data.calendar,
  524. selected: $props.selected,
  525. lunar: $props.lunar,
  526. checkHover: $props.range
  527. }),
  528. e: weeksIndex
  529. };
  530. }),
  531. b: weekIndex
  532. };
  533. }),
  534. z: !$props.insert && !$props.range && $props.typeHasTime
  535. }, !$props.insert && !$props.range && $props.typeHasTime ? {
  536. A: common_vendor.t($data.tempSingleDate ? $data.tempSingleDate : $options.selectDateText),
  537. B: common_vendor.o(($event) => $data.time = $event),
  538. C: common_vendor.p({
  539. type: "time",
  540. start: $options.reactStartTime,
  541. end: $options.reactEndTime,
  542. disabled: !$data.tempSingleDate,
  543. border: false,
  544. ["hide-second"]: $props.hideSecond,
  545. modelValue: $data.time
  546. })
  547. } : {}, {
  548. D: !$props.insert && $props.range && $props.typeHasTime
  549. }, !$props.insert && $props.range && $props.typeHasTime ? {
  550. E: common_vendor.t($data.tempRange.before ? $data.tempRange.before : $options.startDateText),
  551. F: common_vendor.o(($event) => $data.timeRange.startTime = $event),
  552. G: common_vendor.p({
  553. type: "time",
  554. start: $options.reactStartTime,
  555. border: false,
  556. ["hide-second"]: $props.hideSecond,
  557. disabled: !$data.tempRange.before,
  558. modelValue: $data.timeRange.startTime
  559. }),
  560. H: common_vendor.p({
  561. type: "arrowthinright",
  562. color: "#999"
  563. }),
  564. I: common_vendor.t($data.tempRange.after ? $data.tempRange.after : $options.endDateText),
  565. J: common_vendor.o(($event) => $data.timeRange.endTime = $event),
  566. K: common_vendor.p({
  567. type: "time",
  568. end: $options.reactEndTime,
  569. border: false,
  570. ["hide-second"]: $props.hideSecond,
  571. disabled: !$data.tempRange.after,
  572. modelValue: $data.timeRange.endTime
  573. })
  574. } : {}, {
  575. L: !$props.insert
  576. }, !$props.insert ? {
  577. M: common_vendor.o((...args) => $options.confirm && $options.confirm(...args))
  578. } : {}, {
  579. N: !$props.insert ? 1 : "",
  580. O: $data.aniMaskShow ? 1 : "",
  581. P: $data.aniMaskShow ? 1 : ""
  582. }) : {}, {
  583. Q: common_vendor.o((...args) => $options.leaveCale && $options.leaveCale(...args))
  584. });
  585. }
  586. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/uni_modules/uni-datetime-picker/components/uni-datetime-picker/calendar.vue"]]);
  587. wx.createComponent(Component);