You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

439 lines
10 KiB

  1. <style scoped lang="scss">
  2. @media screen and (min-width: 500px) {
  3. .wh_item_date:hover {
  4. background: #538fe9;
  5. cursor: pointer;
  6. color: #fff;
  7. border-radius: 50%;
  8. }
  9. }
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. }
  14. .wh_container {
  15. position: relative;
  16. max-width: 500px;
  17. margin: auto;
  18. }
  19. li {
  20. list-style-type: none;
  21. }
  22. .wh_top_changge {
  23. display: flex;
  24. }
  25. .wh_top_changge li {
  26. cursor: pointer;
  27. display: flex;
  28. /* color: #fff; */
  29. font-size: 18px;
  30. flex: 1;
  31. justify-content: center;
  32. align-items: center;
  33. height: 47px;
  34. }
  35. .wh_top_changge .wh_content_li {
  36. cursor: auto;
  37. flex: 2.5;
  38. }
  39. .wh_content_all {
  40. /* font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
  41. "Helvetica Neue", STHeiti, "Microsoft Yahei", Tahoma, Simsun, sans-serif; */
  42. /* background-color: #0fc37c; */
  43. width: 100%;
  44. overflow: hidden;
  45. /* padding-bottom: 8px; */
  46. border: 1px solid #a1a1a1;
  47. }
  48. .wh_content {
  49. display: flex;
  50. flex-wrap: wrap;
  51. /* justify-content: center; */
  52. /* padding: 0 3% 0 3%; */
  53. width: 107%;
  54. }
  55. .wh_content:first-child .wh_content_item_tag,
  56. .wh_content:first-child .wh_content_item {
  57. color: #ddd;
  58. font-size: 16px;
  59. }
  60. .wh_content_item,
  61. wh_content_item_tag {
  62. font-size: 15px;
  63. width: 13.4%;
  64. text-align: center;
  65. /* color: #fff; */
  66. position: relative;
  67. margin: 0 5px;
  68. }
  69. .wh_content_item {
  70. height: 60px;
  71. border-left: 0.5px solid #a1a1a1;
  72. border-top: 0.5px solid #a1a1a1;
  73. margin-left: 0;
  74. margin-right: 0;
  75. display: flex;
  76. align-items: center;
  77. justify-items: center;
  78. }
  79. .wh_top_tag {
  80. width: 40px;
  81. height: 40px;
  82. line-height: 40px;
  83. margin: auto;
  84. display: flex;
  85. justify-content: center;
  86. align-items: center;
  87. }
  88. .wh_item_date {
  89. width: 40px;
  90. height: 40px;
  91. line-height: 40px;
  92. margin: auto;
  93. display: flex;
  94. justify-content: center;
  95. align-items: center;
  96. }
  97. .wh_jiantou1 {
  98. width: 12px;
  99. height: 12px;
  100. border-top: 2px solid #ccc;
  101. border-left: 2px solid #ccc;
  102. transform: rotate(-45deg);
  103. }
  104. .wh_jiantou1:active,
  105. .wh_jiantou2:active {
  106. border-color: #ddd;
  107. }
  108. .wh_jiantou2 {
  109. width: 12px;
  110. height: 12px;
  111. border-top: 2px solid #ccc;
  112. border-right: 2px solid #ccc;
  113. transform: rotate(45deg);
  114. }
  115. .wh_content_item > .wh_isMark {
  116. margin: auto;
  117. border-radius: 100px;
  118. background: #7d7df5;
  119. color: #fff;
  120. z-index: 2;
  121. }
  122. .wh_content_item .wh_other_dayhide {
  123. color: #bfbfbf;
  124. }
  125. .wh_content_item .wh_want_dayhide {
  126. color: #bfbfbf;
  127. }
  128. .wh_content_item .wh_isToday {
  129. /* background: yellow; */
  130. border-radius: 100px;
  131. }
  132. .wh_content_item .wh_chose_day {
  133. /* background: red; */
  134. border-radius: 100px;
  135. }
  136. .select {
  137. position: absolute;
  138. top: 40%;
  139. right: -170px;
  140. width: 150px;
  141. height: auto;
  142. display: flex;
  143. flex-direction: column;
  144. div {
  145. margin: 0 0 20px 0;
  146. width: 150px;
  147. height: 50px;
  148. border: 1px solid #bfbfbf;
  149. display: flex;
  150. justify-content: center;
  151. align-items: center;
  152. cursor: pointer;
  153. font-size: 18px;
  154. border-radius: 8px;
  155. }
  156. }
  157. </style>
  158. <template>
  159. <section class="wh_container">
  160. <div class="wh_content_all">
  161. <div class="wh_top_changge">
  162. <li @click="PreMonth(myDate, false)">
  163. <div class="wh_jiantou1"></div>
  164. </li>
  165. <li class="wh_content_li">{{ dateTop }}</li>
  166. <li @click="NextMonth(myDate, false)">
  167. <div class="wh_jiantou2"></div>
  168. </li>
  169. </div>
  170. <div class="wh_content">
  171. <div class="wh_content_item" v-for="(tag, i) in textTop" :key="i">
  172. <div class="wh_top_tag">{{ tag }}</div>
  173. </div>
  174. </div>
  175. <div class="wh_content">
  176. <div
  177. class="wh_content_item"
  178. v-for="(item, index) in list"
  179. :key="index"
  180. @click="clickDay(item, index)"
  181. >
  182. <div
  183. class="wh_item_date"
  184. :style="{ background: item.isMark ? theme : '' }"
  185. v-bind:class="[
  186. { wh_isMark: item.isMark },
  187. { wh_other_dayhide: item.otherMonth !== 'nowMonth' },
  188. { wh_want_dayhide: item.dayHide },
  189. { wh_isToday: item.isToday },
  190. { wh_chose_day: item.chooseDay },
  191. setClass(item),
  192. ]"
  193. >
  194. {{ item.id }}
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. <template v-if="selectAll">
  200. <div class="select">
  201. <div @click="selectAllFnc">全选</div>
  202. <div @click="unSelectAllFnc">反选</div>
  203. </div>
  204. </template>
  205. </section>
  206. </template>
  207. <script>
  208. import timeUtil from "./calendar";
  209. import { mapGetters } from "vuex";
  210. const c = console.log.bind(document);
  211. export default {
  212. data() {
  213. return {
  214. myDate: [],
  215. list: [],
  216. historyChose: [],
  217. dateTop: "",
  218. arr: [], // 存放选中的日期
  219. };
  220. },
  221. props: {
  222. markDate: {
  223. type: Array,
  224. default: () => [],
  225. },
  226. markDateMore: {
  227. type: Array,
  228. default: () => [],
  229. },
  230. textTop: {
  231. type: Array,
  232. default: () => ["一", "二", "三", "四", "五", "六", "日"],
  233. },
  234. sundayStart: {
  235. type: Boolean,
  236. default: () => false,
  237. },
  238. agoDayHide: {
  239. type: String,
  240. default: `0`,
  241. },
  242. futureDayHide: {
  243. type: String,
  244. default: `2554387200`,
  245. },
  246. selectAll: {
  247. type: Boolean,
  248. default: false,
  249. },
  250. },
  251. created() {
  252. this.intStart();
  253. this.myDate = new Date();
  254. },
  255. computed: {
  256. ...mapGetters(["theme"]),
  257. },
  258. methods: {
  259. // 全选
  260. selectAllFnc() {
  261. let arr = [];
  262. this.list.map((item) => {
  263. if (item.otherMonth == "nowMonth" && !item.dayHide) {
  264. item.chooseDay = true;
  265. item.isMark = true;
  266. arr.push(item.date);
  267. }
  268. });
  269. this.arr = arr;
  270. this.$emit('changeArr', this.arr)
  271. },
  272. // 全选
  273. unSelectAllFnc() {
  274. this.arr = [];
  275. this.list.map((item) => {
  276. if (item.otherMonth == "nowMonth" && !item.dayHide) {
  277. item.chooseDay = false;
  278. item.isMark = false;
  279. }
  280. });
  281. this.$emit('changeArr', this.arr)
  282. },
  283. intStart() {
  284. timeUtil.sundayStart = this.sundayStart;
  285. },
  286. setClass(data) {
  287. let obj = {};
  288. obj[data.markClassName] = data.markClassName;
  289. return obj;
  290. },
  291. clickDay: function (item, index) {
  292. console.log(item, "123");
  293. if (item.otherMonth === "nowMonth" && !item.dayHide) {
  294. this.getList(this.myDate, item.date);
  295. }
  296. if (item.otherMonth !== "nowMonth") {
  297. item.otherMonth === "preMonth"
  298. ? this.PreMonth(item.date)
  299. : this.NextMonth(item.date);
  300. }
  301. },
  302. ChoseMonth: function (date, isChosedDay = true) {
  303. date = timeUtil.dateFormat(date);
  304. this.myDate = new Date(date);
  305. this.$emit("changeMonth", timeUtil.dateFormat(this.myDate));
  306. if (isChosedDay) {
  307. this.getList(this.myDate, date, isChosedDay);
  308. } else {
  309. this.getList(this.myDate);
  310. }
  311. },
  312. PreMonth: function (date, isChosedDay = true) {
  313. date = timeUtil.dateFormat(date);
  314. this.myDate = timeUtil.getOtherMonth(this.myDate, "preMonth");
  315. this.$emit("changeMonth", timeUtil.dateFormat(this.myDate));
  316. if (isChosedDay) {
  317. this.getList(this.myDate, date, isChosedDay);
  318. } else {
  319. this.getList(this.myDate);
  320. }
  321. },
  322. NextMonth: function (date, isChosedDay = true) {
  323. date = timeUtil.dateFormat(date);
  324. this.myDate = timeUtil.getOtherMonth(this.myDate, "nextMonth");
  325. this.$emit("changeMonth", timeUtil.dateFormat(this.myDate));
  326. if (isChosedDay) {
  327. this.getList(this.myDate, date, isChosedDay);
  328. } else {
  329. this.getList(this.myDate);
  330. }
  331. },
  332. forMatArgs: function () {
  333. let markDate = this.markDate;
  334. let markDateMore = this.markDateMore;
  335. markDate = markDate.map((k) => {
  336. return timeUtil.dateFormat(k);
  337. });
  338. markDateMore = markDateMore.map((k) => {
  339. k.date = timeUtil.dateFormat(k.date);
  340. return k;
  341. });
  342. return [markDate, markDateMore];
  343. },
  344. getList: function (date, chooseDay, isChosedDay = true) {
  345. const [markDate, markDateMore] = this.forMatArgs();
  346. this.dateTop = `${date.getFullYear()}年${date.getMonth() + 1}月`;
  347. let arr = timeUtil.getMonthList(this.myDate);
  348. console.log(this.myDate)
  349. console.log(arr)
  350. for (let i = 0; i < arr.length; i++) {
  351. let markClassName = "";
  352. let k = arr[i];
  353. k.chooseDay = false;
  354. const nowTime = k.date;
  355. const t = new Date(nowTime).getTime() / 1000;
  356. //看每一天的class
  357. for (const c of markDateMore) {
  358. if (c.date === nowTime) {
  359. markClassName = c.className || "";
  360. }
  361. }
  362. //标记选中某些天 设置class
  363. k.markClassName = markClassName;
  364. k.isMark = markDate.indexOf(nowTime) > -1;
  365. //无法选中某天
  366. k.dayHide = t < this.agoDayHide || t > this.futureDayHide;
  367. if (k.isToday) {
  368. this.$emit("isToday", nowTime);
  369. }
  370. let flag = !k.dayHide && k.otherMonth === "nowMonth";
  371. if (chooseDay && chooseDay === nowTime && flag) {
  372. this.$emit("choseDay", nowTime);
  373. this.historyChose.push(nowTime);
  374. k.chooseDay = true;
  375. } else if (
  376. this.historyChose[this.historyChose.length - 1] === nowTime &&
  377. !chooseDay &&
  378. flag
  379. ) {
  380. k.chooseDay = true;
  381. }
  382. }
  383. this.list = arr;
  384. },
  385. },
  386. mounted() {
  387. this.getList(this.myDate);
  388. },
  389. watch: {
  390. markDate: {
  391. handler(val, oldVal) {
  392. this.getList(this.myDate);
  393. },
  394. deep: true,
  395. },
  396. markDateMore: {
  397. handler(val, oldVal) {
  398. this.getList(this.myDate);
  399. },
  400. deep: true,
  401. },
  402. agoDayHide: {
  403. handler(val, oldVal) {
  404. this.getList(this.myDate);
  405. },
  406. deep: true,
  407. },
  408. futureDayHide: {
  409. handler(val, oldVal) {
  410. this.getList(this.myDate);
  411. },
  412. deep: true,
  413. },
  414. sundayStart: {
  415. handler(val, oldVal) {
  416. this.intStart();
  417. this.getList(this.myDate);
  418. },
  419. deep: true,
  420. },
  421. },
  422. };
  423. </script>