From c9c263dc43ad90f95f24a036cee9e6b47afb596c Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期六, 21 十二月 2024 18:44:20 +0800
Subject: [PATCH] 新建盐城德森项目
---
uni_modules/uni-calendar/components/uni-calendar/util.js | 708 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 354 insertions(+), 354 deletions(-)
diff --git a/uni_modules/uni-calendar/components/uni-calendar/util.js b/uni_modules/uni-calendar/components/uni-calendar/util.js
index bae9273..526c34d 100644
--- a/uni_modules/uni-calendar/components/uni-calendar/util.js
+++ b/uni_modules/uni-calendar/components/uni-calendar/util.js
@@ -1,354 +1,354 @@
-import CALENDAR from './calendar.js'
-
-class Calendar {
- constructor({
- date,
- selected,
- startDate,
- endDate,
- range
- } = {}) {
- // 褰撳墠鏃ユ湡
- this.date = this.getDate(new Date()) // 褰撳墠鍒濆叆鏃ユ湡
- // 鎵撶偣淇℃伅
- this.selected = selected || [];
- // 鑼冨洿寮�濮�
- this.startDate = startDate
- // 鑼冨洿缁撴潫
- this.endDate = endDate
- this.range = range
- // 澶氶�夌姸鎬�
- this.cleanMultipleStatus()
- // 姣忓懆鏃ユ湡
- this.weeks = {}
- // this._getWeek(this.date.fullDate)
- }
- /**
- * 璁剧疆鏃ユ湡
- * @param {Object} date
- */
- setDate(date) {
- this.selectDate = this.getDate(date)
- this._getWeek(this.selectDate.fullDate)
- }
-
- /**
- * 娓呯悊澶氶�夌姸鎬�
- */
- cleanMultipleStatus() {
- this.multipleStatus = {
- before: '',
- after: '',
- data: []
- }
- }
-
- /**
- * 閲嶇疆寮�濮嬫棩鏈�
- */
- resetSatrtDate(startDate) {
- // 鑼冨洿寮�濮�
- this.startDate = startDate
-
- }
-
- /**
- * 閲嶇疆缁撴潫鏃ユ湡
- */
- resetEndDate(endDate) {
- // 鑼冨洿缁撴潫
- this.endDate = endDate
- }
-
- /**
- * 鑾峰彇浠绘剰鏃堕棿
- */
- getDate(date, AddDayCount = 0, str = 'day') {
- if (!date) {
- date = new Date()
- }
- if (typeof date !== 'object') {
- date = date.replace(/-/g, '/')
- }
- const dd = new Date(date)
- switch (str) {
- case 'day':
- dd.setDate(dd.getDate() + AddDayCount) // 鑾峰彇AddDayCount澶╁悗鐨勬棩鏈�
- break
- case 'month':
- if (dd.getDate() === 31) {
- dd.setDate(dd.getDate() + AddDayCount)
- } else {
- dd.setMonth(dd.getMonth() + AddDayCount) // 鑾峰彇AddDayCount澶╁悗鐨勬棩鏈�
- }
- break
- case 'year':
- dd.setFullYear(dd.getFullYear() + AddDayCount) // 鑾峰彇AddDayCount澶╁悗鐨勬棩鏈�
- break
- }
- const y = dd.getFullYear()
- const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 鑾峰彇褰撳墠鏈堜唤鐨勬棩鏈燂紝涓嶈冻10琛�0
- const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 鑾峰彇褰撳墠鍑犲彿锛屼笉瓒�10琛�0
- return {
- fullDate: y + '-' + m + '-' + d,
- year: y,
- month: m,
- date: d,
- day: dd.getDay()
- }
- }
-
-
- /**
- * 鑾峰彇涓婃湀鍓╀綑澶╂暟
- */
- _getLastMonthDays(firstDay, full) {
- let dateArr = []
- for (let i = firstDay; i > 0; i--) {
- const beforeDate = new Date(full.year, full.month - 1, -i + 1).getDate()
- dateArr.push({
- date: beforeDate,
- month: full.month - 1,
- lunar: this.getlunar(full.year, full.month - 1, beforeDate),
- disable: true
- })
- }
- return dateArr
- }
- /**
- * 鑾峰彇鏈湀澶╂暟
- */
- _currentMonthDys(dateData, full) {
- let dateArr = []
- let fullDate = this.date.fullDate
- for (let i = 1; i <= dateData; i++) {
- let isinfo = false
- let nowDate = full.year + '-' + (full.month < 10 ?
- full.month : full.month) + '-' + (i < 10 ?
- '0' + i : i)
- // 鏄惁浠婂ぉ
- let isDay = fullDate === nowDate
- // 鑾峰彇鎵撶偣淇℃伅
- let info = this.selected && this.selected.find((item) => {
- if (this.dateEqual(nowDate, item.date)) {
- return item
- }
- })
-
- // 鏃ユ湡绂佺敤
- let disableBefore = true
- let disableAfter = true
- if (this.startDate) {
- // let dateCompBefore = this.dateCompare(this.startDate, fullDate)
- // disableBefore = this.dateCompare(dateCompBefore ? this.startDate : fullDate, nowDate)
- disableBefore = this.dateCompare(this.startDate, nowDate)
- }
-
- if (this.endDate) {
- // let dateCompAfter = this.dateCompare(fullDate, this.endDate)
- // disableAfter = this.dateCompare(nowDate, dateCompAfter ? this.endDate : fullDate)
- disableAfter = this.dateCompare(nowDate, this.endDate)
- }
- let multiples = this.multipleStatus.data
- let checked = false
- let multiplesStatus = -1
- if (this.range) {
- if (multiples) {
- multiplesStatus = multiples.findIndex((item) => {
- return this.dateEqual(item, nowDate)
- })
- }
- if (multiplesStatus !== -1) {
- checked = true
- }
- }
- let data = {
- fullDate: nowDate,
- year: full.year,
- date: i,
- multiple: this.range ? checked : false,
- beforeMultiple: this.dateEqual(this.multipleStatus.before, nowDate),
- afterMultiple: this.dateEqual(this.multipleStatus.after, nowDate),
- month: full.month,
- lunar: this.getlunar(full.year, full.month, i),
- disable: !(disableBefore && disableAfter),
- isDay
- }
- if (info) {
- data.extraInfo = info
- }
-
- dateArr.push(data)
- }
- return dateArr
- }
- /**
- * 鑾峰彇涓嬫湀澶╂暟
- */
- _getNextMonthDays(surplus, full) {
- let dateArr = []
- for (let i = 1; i < surplus + 1; i++) {
- dateArr.push({
- date: i,
- month: Number(full.month) + 1,
- lunar: this.getlunar(full.year, Number(full.month) + 1, i),
- disable: true
- })
- }
- return dateArr
- }
-
- /**
- * 鑾峰彇褰撳墠鏃ユ湡璇︽儏
- * @param {Object} date
- */
- getInfo(date) {
- if (!date) {
- date = new Date()
- }
- const dateInfo = this.canlender.find(item => item.fullDate === this.getDate(date).fullDate)
- return dateInfo
- }
-
- /**
- * 姣旇緝鏃堕棿澶у皬
- */
- dateCompare(startDate, endDate) {
- // 璁$畻鎴鏃堕棿
- startDate = new Date(startDate.replace('-', '/').replace('-', '/'))
- // 璁$畻璇︾粏椤圭殑鎴鏃堕棿
- endDate = new Date(endDate.replace('-', '/').replace('-', '/'))
- if (startDate <= endDate) {
- return true
- } else {
- return false
- }
- }
-
- /**
- * 姣旇緝鏃堕棿鏄惁鐩哥瓑
- */
- dateEqual(before, after) {
- // 璁$畻鎴鏃堕棿
- before = new Date(before.replace('-', '/').replace('-', '/'))
- // 璁$畻璇︾粏椤圭殑鎴鏃堕棿
- after = new Date(after.replace('-', '/').replace('-', '/'))
- if (before.getTime() - after.getTime() === 0) {
- return true
- } else {
- return false
- }
- }
-
-
- /**
- * 鑾峰彇鏃ユ湡鑼冨洿鍐呮墍鏈夋棩鏈�
- * @param {Object} begin
- * @param {Object} end
- */
- geDateAll(begin, end) {
- var arr = []
- var ab = begin.split('-')
- var ae = end.split('-')
- var db = new Date()
- db.setFullYear(ab[0], ab[1] - 1, ab[2])
- var de = new Date()
- de.setFullYear(ae[0], ae[1] - 1, ae[2])
- var unixDb = db.getTime() - 24 * 60 * 60 * 1000
- var unixDe = de.getTime() - 24 * 60 * 60 * 1000
- for (var k = unixDb; k <= unixDe;) {
- k = k + 24 * 60 * 60 * 1000
- arr.push(this.getDate(new Date(parseInt(k))).fullDate)
- }
- return arr
- }
- /**
- * 璁$畻闃村巻鏃ユ湡鏄剧ず
- */
- getlunar(year, month, date) {
- return CALENDAR.solar2lunar(year, month, date)
- }
- /**
- * 璁剧疆鎵撶偣
- */
- setSelectInfo(data, value) {
- this.selected = value
- this._getWeek(data)
- }
-
- /**
- * 鑾峰彇澶氶�夌姸鎬�
- */
- setMultiple(fullDate) {
- let {
- before,
- after
- } = this.multipleStatus
-
- if (!this.range) return
- if (before && after) {
- this.multipleStatus.before = ''
- this.multipleStatus.after = ''
- this.multipleStatus.data = []
- } else {
- if (!before) {
- this.multipleStatus.before = fullDate
- } else {
- this.multipleStatus.after = fullDate
- if (this.dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
- this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
- } else {
- this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
- }
- }
- }
- this._getWeek(fullDate)
- }
-
- /**
- * 鑾峰彇姣忓懆鏁版嵁
- * @param {Object} dateData
- */
- _getWeek(dateData) {
- const {
- fullDate,
- year,
- month,
- date,
- day
- } = this.getDate(dateData)
- let firstDay = new Date(year, month - 1, 1).getDay()
- let currentDay = new Date(year, month, 0).getDate()
- let dates = {
- lastMonthDays: this._getLastMonthDays(firstDay, this.getDate(dateData)), // 涓婁釜鏈堟湯灏惧嚑澶�
- currentMonthDys: this._currentMonthDys(currentDay, this.getDate(dateData)), // 鏈湀澶╂暟
- nextMonthDays: [], // 涓嬩釜鏈堝紑濮嬪嚑澶�
- weeks: []
- }
- let canlender = []
- const surplus = 42 - (dates.lastMonthDays.length + dates.currentMonthDys.length)
- dates.nextMonthDays = this._getNextMonthDays(surplus, this.getDate(dateData))
- canlender = canlender.concat(dates.lastMonthDays, dates.currentMonthDys, dates.nextMonthDays)
- let weeks = {}
- // 鎷兼帴鏁扮粍 涓婁釜鏈堝紑濮嬪嚑澶� + 鏈湀澶╂暟+ 涓嬩釜鏈堝紑濮嬪嚑澶�
- for (let i = 0; i < canlender.length; i++) {
- if (i % 7 === 0) {
- weeks[parseInt(i / 7)] = new Array(7)
- }
- weeks[parseInt(i / 7)][i % 7] = canlender[i]
- }
- this.canlender = canlender
- this.weeks = weeks
- }
-
- //闈欐�佹柟娉�
- // static init(date) {
- // if (!this.instance) {
- // this.instance = new Calendar(date);
- // }
- // return this.instance;
- // }
-}
-
-
-export default Calendar
+import CALENDAR from './calendar.js'
+
+class Calendar {
+ constructor({
+ date,
+ selected,
+ startDate,
+ endDate,
+ range
+ } = {}) {
+ // 褰撳墠鏃ユ湡
+ this.date = this.getDate(new Date()) // 褰撳墠鍒濆叆鏃ユ湡
+ // 鎵撶偣淇℃伅
+ this.selected = selected || [];
+ // 鑼冨洿寮�濮�
+ this.startDate = startDate
+ // 鑼冨洿缁撴潫
+ this.endDate = endDate
+ this.range = range
+ // 澶氶�夌姸鎬�
+ this.cleanMultipleStatus()
+ // 姣忓懆鏃ユ湡
+ this.weeks = {}
+ // this._getWeek(this.date.fullDate)
+ }
+ /**
+ * 璁剧疆鏃ユ湡
+ * @param {Object} date
+ */
+ setDate(date) {
+ this.selectDate = this.getDate(date)
+ this._getWeek(this.selectDate.fullDate)
+ }
+
+ /**
+ * 娓呯悊澶氶�夌姸鎬�
+ */
+ cleanMultipleStatus() {
+ this.multipleStatus = {
+ before: '',
+ after: '',
+ data: []
+ }
+ }
+
+ /**
+ * 閲嶇疆寮�濮嬫棩鏈�
+ */
+ resetSatrtDate(startDate) {
+ // 鑼冨洿寮�濮�
+ this.startDate = startDate
+
+ }
+
+ /**
+ * 閲嶇疆缁撴潫鏃ユ湡
+ */
+ resetEndDate(endDate) {
+ // 鑼冨洿缁撴潫
+ this.endDate = endDate
+ }
+
+ /**
+ * 鑾峰彇浠绘剰鏃堕棿
+ */
+ getDate(date, AddDayCount = 0, str = 'day') {
+ if (!date) {
+ date = new Date()
+ }
+ if (typeof date !== 'object') {
+ date = date.replace(/-/g, '/')
+ }
+ const dd = new Date(date)
+ switch (str) {
+ case 'day':
+ dd.setDate(dd.getDate() + AddDayCount) // 鑾峰彇AddDayCount澶╁悗鐨勬棩鏈�
+ break
+ case 'month':
+ if (dd.getDate() === 31) {
+ dd.setDate(dd.getDate() + AddDayCount)
+ } else {
+ dd.setMonth(dd.getMonth() + AddDayCount) // 鑾峰彇AddDayCount澶╁悗鐨勬棩鏈�
+ }
+ break
+ case 'year':
+ dd.setFullYear(dd.getFullYear() + AddDayCount) // 鑾峰彇AddDayCount澶╁悗鐨勬棩鏈�
+ break
+ }
+ const y = dd.getFullYear()
+ const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 鑾峰彇褰撳墠鏈堜唤鐨勬棩鏈燂紝涓嶈冻10琛�0
+ const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 鑾峰彇褰撳墠鍑犲彿锛屼笉瓒�10琛�0
+ return {
+ fullDate: y + '-' + m + '-' + d,
+ year: y,
+ month: m,
+ date: d,
+ day: dd.getDay()
+ }
+ }
+
+
+ /**
+ * 鑾峰彇涓婃湀鍓╀綑澶╂暟
+ */
+ _getLastMonthDays(firstDay, full) {
+ let dateArr = []
+ for (let i = firstDay; i > 0; i--) {
+ const beforeDate = new Date(full.year, full.month - 1, -i + 1).getDate()
+ dateArr.push({
+ date: beforeDate,
+ month: full.month - 1,
+ lunar: this.getlunar(full.year, full.month - 1, beforeDate),
+ disable: true
+ })
+ }
+ return dateArr
+ }
+ /**
+ * 鑾峰彇鏈湀澶╂暟
+ */
+ _currentMonthDys(dateData, full) {
+ let dateArr = []
+ let fullDate = this.date.fullDate
+ for (let i = 1; i <= dateData; i++) {
+ let isinfo = false
+ let nowDate = full.year + '-' + (full.month < 10 ?
+ full.month : full.month) + '-' + (i < 10 ?
+ '0' + i : i)
+ // 鏄惁浠婂ぉ
+ let isDay = fullDate === nowDate
+ // 鑾峰彇鎵撶偣淇℃伅
+ let info = this.selected && this.selected.find((item) => {
+ if (this.dateEqual(nowDate, item.date)) {
+ return item
+ }
+ })
+
+ // 鏃ユ湡绂佺敤
+ let disableBefore = true
+ let disableAfter = true
+ if (this.startDate) {
+ // let dateCompBefore = this.dateCompare(this.startDate, fullDate)
+ // disableBefore = this.dateCompare(dateCompBefore ? this.startDate : fullDate, nowDate)
+ disableBefore = this.dateCompare(this.startDate, nowDate)
+ }
+
+ if (this.endDate) {
+ // let dateCompAfter = this.dateCompare(fullDate, this.endDate)
+ // disableAfter = this.dateCompare(nowDate, dateCompAfter ? this.endDate : fullDate)
+ disableAfter = this.dateCompare(nowDate, this.endDate)
+ }
+ let multiples = this.multipleStatus.data
+ let checked = false
+ let multiplesStatus = -1
+ if (this.range) {
+ if (multiples) {
+ multiplesStatus = multiples.findIndex((item) => {
+ return this.dateEqual(item, nowDate)
+ })
+ }
+ if (multiplesStatus !== -1) {
+ checked = true
+ }
+ }
+ let data = {
+ fullDate: nowDate,
+ year: full.year,
+ date: i,
+ multiple: this.range ? checked : false,
+ beforeMultiple: this.dateEqual(this.multipleStatus.before, nowDate),
+ afterMultiple: this.dateEqual(this.multipleStatus.after, nowDate),
+ month: full.month,
+ lunar: this.getlunar(full.year, full.month, i),
+ disable: !(disableBefore && disableAfter),
+ isDay
+ }
+ if (info) {
+ data.extraInfo = info
+ }
+
+ dateArr.push(data)
+ }
+ return dateArr
+ }
+ /**
+ * 鑾峰彇涓嬫湀澶╂暟
+ */
+ _getNextMonthDays(surplus, full) {
+ let dateArr = []
+ for (let i = 1; i < surplus + 1; i++) {
+ dateArr.push({
+ date: i,
+ month: Number(full.month) + 1,
+ lunar: this.getlunar(full.year, Number(full.month) + 1, i),
+ disable: true
+ })
+ }
+ return dateArr
+ }
+
+ /**
+ * 鑾峰彇褰撳墠鏃ユ湡璇︽儏
+ * @param {Object} date
+ */
+ getInfo(date) {
+ if (!date) {
+ date = new Date()
+ }
+ const dateInfo = this.canlender.find(item => item.fullDate === this.getDate(date).fullDate)
+ return dateInfo
+ }
+
+ /**
+ * 姣旇緝鏃堕棿澶у皬
+ */
+ dateCompare(startDate, endDate) {
+ // 璁$畻鎴鏃堕棿
+ startDate = new Date(startDate.replace('-', '/').replace('-', '/'))
+ // 璁$畻璇︾粏椤圭殑鎴鏃堕棿
+ endDate = new Date(endDate.replace('-', '/').replace('-', '/'))
+ if (startDate <= endDate) {
+ return true
+ } else {
+ return false
+ }
+ }
+
+ /**
+ * 姣旇緝鏃堕棿鏄惁鐩哥瓑
+ */
+ dateEqual(before, after) {
+ // 璁$畻鎴鏃堕棿
+ before = new Date(before.replace('-', '/').replace('-', '/'))
+ // 璁$畻璇︾粏椤圭殑鎴鏃堕棿
+ after = new Date(after.replace('-', '/').replace('-', '/'))
+ if (before.getTime() - after.getTime() === 0) {
+ return true
+ } else {
+ return false
+ }
+ }
+
+
+ /**
+ * 鑾峰彇鏃ユ湡鑼冨洿鍐呮墍鏈夋棩鏈�
+ * @param {Object} begin
+ * @param {Object} end
+ */
+ geDateAll(begin, end) {
+ var arr = []
+ var ab = begin.split('-')
+ var ae = end.split('-')
+ var db = new Date()
+ db.setFullYear(ab[0], ab[1] - 1, ab[2])
+ var de = new Date()
+ de.setFullYear(ae[0], ae[1] - 1, ae[2])
+ var unixDb = db.getTime() - 24 * 60 * 60 * 1000
+ var unixDe = de.getTime() - 24 * 60 * 60 * 1000
+ for (var k = unixDb; k <= unixDe;) {
+ k = k + 24 * 60 * 60 * 1000
+ arr.push(this.getDate(new Date(parseInt(k))).fullDate)
+ }
+ return arr
+ }
+ /**
+ * 璁$畻闃村巻鏃ユ湡鏄剧ず
+ */
+ getlunar(year, month, date) {
+ return CALENDAR.solar2lunar(year, month, date)
+ }
+ /**
+ * 璁剧疆鎵撶偣
+ */
+ setSelectInfo(data, value) {
+ this.selected = value
+ this._getWeek(data)
+ }
+
+ /**
+ * 鑾峰彇澶氶�夌姸鎬�
+ */
+ setMultiple(fullDate) {
+ let {
+ before,
+ after
+ } = this.multipleStatus
+
+ if (!this.range) return
+ if (before && after) {
+ this.multipleStatus.before = ''
+ this.multipleStatus.after = ''
+ this.multipleStatus.data = []
+ } else {
+ if (!before) {
+ this.multipleStatus.before = fullDate
+ } else {
+ this.multipleStatus.after = fullDate
+ if (this.dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
+ this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
+ } else {
+ this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
+ }
+ }
+ }
+ this._getWeek(fullDate)
+ }
+
+ /**
+ * 鑾峰彇姣忓懆鏁版嵁
+ * @param {Object} dateData
+ */
+ _getWeek(dateData) {
+ const {
+ fullDate,
+ year,
+ month,
+ date,
+ day
+ } = this.getDate(dateData)
+ let firstDay = new Date(year, month - 1, 1).getDay()
+ let currentDay = new Date(year, month, 0).getDate()
+ let dates = {
+ lastMonthDays: this._getLastMonthDays(firstDay, this.getDate(dateData)), // 涓婁釜鏈堟湯灏惧嚑澶�
+ currentMonthDys: this._currentMonthDys(currentDay, this.getDate(dateData)), // 鏈湀澶╂暟
+ nextMonthDays: [], // 涓嬩釜鏈堝紑濮嬪嚑澶�
+ weeks: []
+ }
+ let canlender = []
+ const surplus = 42 - (dates.lastMonthDays.length + dates.currentMonthDys.length)
+ dates.nextMonthDays = this._getNextMonthDays(surplus, this.getDate(dateData))
+ canlender = canlender.concat(dates.lastMonthDays, dates.currentMonthDys, dates.nextMonthDays)
+ let weeks = {}
+ // 鎷兼帴鏁扮粍 涓婁釜鏈堝紑濮嬪嚑澶� + 鏈湀澶╂暟+ 涓嬩釜鏈堝紑濮嬪嚑澶�
+ for (let i = 0; i < canlender.length; i++) {
+ if (i % 7 === 0) {
+ weeks[parseInt(i / 7)] = new Array(7)
+ }
+ weeks[parseInt(i / 7)][i % 7] = canlender[i]
+ }
+ this.canlender = canlender
+ this.weeks = weeks
+ }
+
+ //闈欐�佹柟娉�
+ // static init(date) {
+ // if (!this.instance) {
+ // this.instance = new Calendar(date);
+ // }
+ // return this.instance;
+ // }
+}
+
+
+export default Calendar
--
Gitblit v1.9.1