|
@@ -219,36 +219,19 @@ export function getAddYear(year: number = 0) {
|
|
return new Date(y + '/' + m)
|
|
return new Date(y + '/' + m)
|
|
}
|
|
}
|
|
|
|
|
|
-/**
|
|
|
|
- *
|
|
|
|
- * 获取上一个月,日期格式yyyyMM
|
|
|
|
- */
|
|
|
|
-export function getPreMonth(formatType: any = '') {
|
|
|
|
- const nowdays = new Date()
|
|
|
|
- let year = nowdays.getFullYear()
|
|
|
|
- let month: any = nowdays.getMonth()
|
|
|
|
- if (month === 0) {
|
|
|
|
- month = 12
|
|
|
|
- year = year - 1
|
|
|
|
- }
|
|
|
|
- if (month < 10) {
|
|
|
|
- month = '0' + month
|
|
|
|
- }
|
|
|
|
- if (formatType === 'YYYY.MM') {
|
|
|
|
- return year + '.' + month
|
|
|
|
- } else if (formatType === 'YYYY年MM月') {
|
|
|
|
- return year + '年' + month + '月'
|
|
|
|
- } else {
|
|
|
|
- return year + '' + month
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 格式化日期 3月21日
|
|
* 格式化日期 3月21日
|
|
*/
|
|
*/
|
|
-export const formatEnergyDate = function (time: any) {
|
|
|
|
|
|
+export const formatEnergyDate = function (type: any = 1) {
|
|
//三目运算符
|
|
//三目运算符
|
|
- const dates = time ? new Date(time) : new Date()
|
|
|
|
|
|
+ let dates: any = null
|
|
|
|
+ if (type == 2) {
|
|
|
|
+ dates = new Date(new Date().setHours(new Date().getHours() + 1))
|
|
|
|
+ } else {
|
|
|
|
+ dates = new Date()
|
|
|
|
+ }
|
|
//月份下标是0-11
|
|
//月份下标是0-11
|
|
const months: any = (dates.getMonth() + 1) < 10 ? '0' + (dates.getMonth() + 1) : (dates.getMonth() + 1)
|
|
const months: any = (dates.getMonth() + 1) < 10 ? '0' + (dates.getMonth() + 1) : (dates.getMonth() + 1)
|
|
//具体的天数
|
|
//具体的天数
|
|
@@ -257,409 +240,37 @@ export const formatEnergyDate = function (time: any) {
|
|
const hours = dates.getHours() < 10 ? '0' + dates.getHours() : dates.getHours()
|
|
const hours = dates.getHours() < 10 ? '0' + dates.getHours() : dates.getHours()
|
|
// //分钟
|
|
// //分钟
|
|
const minutes = dates.getMinutes() < 10 ? '0' + dates.getMinutes() : dates.getMinutes()
|
|
const minutes = dates.getMinutes() < 10 ? '0' + dates.getMinutes() : dates.getMinutes()
|
|
|
|
+ const seconds = dates.getSeconds() < 10 ? '0' + dates.getSeconds() : dates.getSeconds()
|
|
//返回数据格式
|
|
//返回数据格式
|
|
return [
|
|
return [
|
|
- year + '年' + months + '月',
|
|
|
|
|
|
+ year + '年' + months + '月' + day + '日',
|
|
months + '月' + day + '日',
|
|
months + '月' + day + '日',
|
|
- hours + ':' + minutes
|
|
|
|
|
|
+ hours + ':' + minutes + ":" + seconds
|
|
]
|
|
]
|
|
}
|
|
}
|
|
|
|
|
|
-export const setSession = function (key: any = '', obj: any = '') {
|
|
|
|
- if (obj) {
|
|
|
|
- let str = JSON.stringify(obj)
|
|
|
|
- sessionStorage.setItem(key, str)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const getSession = function (key: any = '') {
|
|
|
|
- if (key) {
|
|
|
|
- let obj: any = sessionStorage.getItem(key)
|
|
|
|
- if (obj) {
|
|
|
|
- return JSON.parse(obj)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return ''
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 本地存储localStorage
|
|
|
|
- * @param key
|
|
|
|
- * @param obj
|
|
|
|
- */
|
|
|
|
-export const setLocalStorage = function (key: any = '', obj: any = '') {
|
|
|
|
- if (obj) {
|
|
|
|
- if (obj instanceof Object) {
|
|
|
|
- let str = JSON.stringify(obj)
|
|
|
|
- localStorage.setItem(key, str)
|
|
|
|
- } else {
|
|
|
|
- localStorage.setItem(key, obj)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 获取本地存储
|
|
|
|
- * @param key
|
|
|
|
- */
|
|
|
|
-export const getLocalStorage = function (key: any) {
|
|
|
|
- if (key) {
|
|
|
|
- let obj: any = localStorage.getItem(key)
|
|
|
|
- if (obj) {
|
|
|
|
- return JSON.parse(obj)
|
|
|
|
- } else {
|
|
|
|
- return ''
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return ''
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 存储最新的空间信息
|
|
|
|
- * @param spaceInfo
|
|
|
|
- */
|
|
|
|
-export const setLocalNewSpaceInfo = function (spaceInfo: any) {
|
|
|
|
- setLocalStorage(Keys.storageSpaceInfoKey, spaceInfo)
|
|
|
|
|
|
+// 获取当前时间是周几
|
|
|
|
+export const getWeek = function () {
|
|
|
|
+ let week:any = new Date().getDay();
|
|
|
|
+ let str:any=''
|
|
|
|
+ if (week == 0) {
|
|
|
|
+ str = "星期日";
|
|
|
|
+ } else if (week == 1) {
|
|
|
|
+ str = "星期一";
|
|
|
|
+ } else if (week == 2) {
|
|
|
|
+ str = "星期二";
|
|
|
|
+ } else if (week == 3) {
|
|
|
|
+ str = "星期三";
|
|
|
|
+ } else if (week == 4) {
|
|
|
|
+ str = "星期四";
|
|
|
|
+ } else if (week == 5) {
|
|
|
|
+ str = "星期五";
|
|
|
|
+ } else if (week == 6) {
|
|
|
|
+ str = "星期六";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-/**
|
|
|
|
- * 获取最新的空间信息
|
|
|
|
- */
|
|
|
|
-export const getLocalNewSpaceInfo = function () {
|
|
|
|
- let spaceInfo: any = getLocalStorage(Keys.storageSpaceInfoKey)
|
|
|
|
- return spaceInfo
|
|
|
|
-}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
- * 本地缓存建筑,楼层,空间
|
|
|
|
- */
|
|
|
|
-export const localStorageSpaceId = function (buildingId: any, floorId: any, spaceId: any) {
|
|
|
|
- let spaceMap: any = getLocalStorage(Keys.storageSpaceKey) ? getLocalStorage(Keys.storageSpaceKey) : {}
|
|
|
|
- let key: any = `${buildingId},${floorId}`
|
|
|
|
- spaceMap[key] = spaceId
|
|
|
|
- setLocalStorage(Keys.storageSpaceKey, spaceMap)
|
|
|
|
-}
|
|
|
|
-export const getStorageSpaceId = function () {
|
|
|
|
- let spaceMap: any = getLocalStorage(Keys.storageSpaceKey)
|
|
|
|
- return spaceMap
|
|
|
|
-}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
- * 本地缓存建筑对应的楼层
|
|
|
|
- */
|
|
|
|
-export const localStorageFloor = function (buildingId: any, floorId: any) {
|
|
|
|
- let floorMap: any = getLocalStorage(Keys.storageFloorKey) ? getLocalStorage(Keys.storageFloorKey) : {}
|
|
|
|
- floorMap[buildingId] = floorId
|
|
|
|
- setLocalStorage(Keys.storageFloorKey, floorMap)
|
|
|
|
-}
|
|
|
|
-/**
|
|
|
|
- * 获取本地存储的建筑对应的关系
|
|
|
|
- * @param buildingId
|
|
|
|
- * @param floorId
|
|
|
|
- */
|
|
|
|
-export const getLocalStorageFloor = function () {
|
|
|
|
- let floorMap: any = getLocalStorage(Keys.storageFloorKey)
|
|
|
|
- return floorMap
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 缓存搜索页面最近查找的数据
|
|
|
|
- * @param item
|
|
|
|
- */
|
|
|
|
-export const setLocalSearchSpace = function (item: any) {
|
|
|
|
- let historySearch: any = getLocalStorage(Keys.historySearchSpaceKey)
|
|
|
|
- let flag = false
|
|
|
|
- historySearch = historySearch ? historySearch : []
|
|
|
|
- historySearch.map((historyItem: any) => {
|
|
|
|
- if (historyItem.id === item.id) {
|
|
|
|
- flag = true
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- if (!flag) {
|
|
|
|
- historySearch.push(item)
|
|
|
|
- }
|
|
|
|
- setLocalStorage(Keys.historySearchSpaceKey, historySearch)
|
|
|
|
-}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
- * 获取搜索页面最近查找的数据
|
|
|
|
- */
|
|
|
|
-export const getLocalSearchSpace = function () {
|
|
|
|
- return getLocalStorage(Keys.historySearchSpaceKey) ? getLocalStorage(Keys.historySearchSpaceKey) : []
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- *存储当前项目id
|
|
|
|
- */
|
|
|
|
-export const setLocalProjectId = function (projectId: any) {
|
|
|
|
- setLocalStorage(Keys.projectId, projectId)
|
|
|
|
-}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
- * 获取当前项目id
|
|
|
|
- * @param projectId
|
|
|
|
- */
|
|
|
|
-export const getLocalProjectId = function () {
|
|
|
|
- return localStorage.getItem(Keys.projectId)
|
|
|
|
-}
|
|
|
|
-/**
|
|
|
|
- * 清楚当前所有的存储数据
|
|
|
|
- */
|
|
|
|
-export const clearAllLocalData = function () {
|
|
|
|
- localStorage.clear()
|
|
|
|
- Cookies.remove('userInfo')
|
|
|
|
- Cookies.remove('projectId')
|
|
|
|
- Cookies.remove('accessToken')
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const doHandleMonth = function (month: any) {
|
|
|
|
- let m: any = month
|
|
|
|
- if (month.toString().length == 1) {
|
|
|
|
- m = '0' + month
|
|
|
|
- }
|
|
|
|
- return m
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const getWeekDate = function (day: any) {
|
|
|
|
- let weeks: any = new Array(
|
|
|
|
- '周日',
|
|
|
|
- '周一',
|
|
|
|
- '周二',
|
|
|
|
- '周三',
|
|
|
|
- '周四',
|
|
|
|
- '周五',
|
|
|
|
- '周六'
|
|
|
|
- )
|
|
|
|
- let week: any = weeks[day]
|
|
|
|
- return week
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const getNowWeek = function () {
|
|
|
|
- let date: any = new Date()
|
|
|
|
- let day: any = date.getDay()
|
|
|
|
- let nowWeek: any = getWeekDate(day)
|
|
|
|
- return nowWeek
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const getDate = function (date: any) {
|
|
|
|
- return date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 初始化24:00
|
|
|
|
- */
|
|
|
|
-export const getTimers = function () {
|
|
|
|
- let timers: any = new Array()
|
|
|
|
- for (let i = 0; i <= 24; i++) {
|
|
|
|
- let str: any = '00'
|
|
|
|
- if (i < 10) {
|
|
|
|
- str = '0' + i
|
|
|
|
- } else {
|
|
|
|
- str = i
|
|
|
|
- }
|
|
|
|
- timers.push(str + ':00')
|
|
|
|
- if (i < 24) {
|
|
|
|
- timers.push(str + ':30')
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- console.log("timers====")
|
|
|
|
- console.log(timers)
|
|
|
|
- return timers
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const getNowTime = function () {
|
|
|
|
- let date: any = new Date()
|
|
|
|
- let hours: any = date.getHours()
|
|
|
|
- let minute: any = date.getMinutes()
|
|
|
|
- let index: any = date.getHours()
|
|
|
|
- if (minute < 30) {
|
|
|
|
- hours = hours + ':' + '00'
|
|
|
|
- index = index * 2
|
|
|
|
- } else {
|
|
|
|
- hours = hours + ':' + '30'
|
|
|
|
- index = index * 2 + 1
|
|
|
|
- }
|
|
|
|
- return [hours, index]
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 获取当前真实时间
|
|
|
|
-export const getRelNowTime = function () {
|
|
|
|
- let date: any = new Date()
|
|
|
|
- let hours: any = date.getHours()
|
|
|
|
- let minute: any = date.getMinutes()
|
|
|
|
- if (hours < 10) {
|
|
|
|
- hours = "0" + hours
|
|
|
|
- }
|
|
|
|
- if (minute < 10) {
|
|
|
|
- minute = "0" + minute
|
|
|
|
- }
|
|
|
|
- return hours + "" + minute + "00"
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 19000转成19:00
|
|
|
|
- */
|
|
|
|
-export const formatTimerStr = function (timer: any) {
|
|
|
|
- if (timer) {
|
|
|
|
- let str: any = (timer / 10000).toFixed(2)
|
|
|
|
- str = str.replace(".", ":")
|
|
|
|
- return str
|
|
|
|
- } else {
|
|
|
|
- return ''
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const newNumber = function (start: any, end: any, masAddess: any) {
|
|
|
|
- return masAddess + "" + Math.round(Math.random() * (end - start) + start);//生成在[start,end]范围内的随机数值,只支持不小于0的合法范围
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const formateTimeContinuous: any = function (index: any = 1,
|
|
|
|
- startTime: any,
|
|
|
|
- endTime: any,
|
|
|
|
- type: any = 1, data: any = [], that: any) {
|
|
|
|
- let todayDate: any = new Date()
|
|
|
|
- let tomorrowData = new Date(todayDate.setTime(todayDate.getTime() + 24 * 60 * 60 * 1000))
|
|
|
|
- let nowDate: any = formatDate("YYYY-MM-DD");
|
|
|
|
- let tomorrowDate: any = formatDate("YYYY-MM-DD", tomorrowData);
|
|
|
|
- data.map((item: any) => {
|
|
|
|
- // debugger
|
|
|
|
- let date: any = formatDateStr(item.date);
|
|
|
|
- let week: any = getWeekDate(new Date(date).getDay());
|
|
|
|
- if (date == nowDate) {
|
|
|
|
- week = '今日'
|
|
|
|
- } else if (date == tomorrowDate) {
|
|
|
|
- week = '次日'
|
|
|
|
- }
|
|
|
|
- item.week = week;
|
|
|
|
- });
|
|
|
|
- // debugger
|
|
|
|
- let text: any = "";
|
|
|
|
- // 工作时间和第二天连续的问题
|
|
|
|
- // 工作时间连续的问题
|
|
|
|
- let cusStartTime: any = data[index].cusStartTime;
|
|
|
|
- let cusEndTime: any = data[index].cusEndTime;
|
|
|
|
- if (type === 1) {
|
|
|
|
- // debugger;
|
|
|
|
- if (endTime === "240000") {
|
|
|
|
- // 处理时间连续的问题
|
|
|
|
- let customSceneList: any = data[index]?.customSceneList ?? [];
|
|
|
|
- if (cusStartTime === "000000") {
|
|
|
|
- text = data[index].week;
|
|
|
|
- endTime = cusEndTime;
|
|
|
|
- }
|
|
|
|
- customSceneList.map((item: any) => {
|
|
|
|
- if (item.startTime === "000000") {
|
|
|
|
- text = data[index].week;
|
|
|
|
- endTime = item.endTime;
|
|
|
|
- } else if (endTime === item.startTime) {
|
|
|
|
- text = data[index].week;
|
|
|
|
- endTime = item.endTime;
|
|
|
|
- }
|
|
|
|
- if (endTime === cusStartTime) {
|
|
|
|
- text = data[index].week;
|
|
|
|
- endTime = cusEndTime;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (text) {
|
|
|
|
- let nowIndex: any = index + 1;
|
|
|
|
- that.text = text
|
|
|
|
- if (nowIndex < data.length - 1) {
|
|
|
|
- return formateTimeContinuous(nowIndex, startTime, endTime, 1, data, that);
|
|
|
|
- } else {
|
|
|
|
- return {
|
|
|
|
- text: that.text,
|
|
|
|
- startTime: startTime,
|
|
|
|
- endTime: endTime,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- return {
|
|
|
|
- text: that.text,
|
|
|
|
- startTime: startTime,
|
|
|
|
- endTime: endTime,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- return {
|
|
|
|
- text: that.text,
|
|
|
|
- startTime: startTime,
|
|
|
|
- endTime: endTime,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- // 预约时候后找最近的一段预约时间
|
|
|
|
- let nowTime: any = (getNowTime()[0]).replace(":", "") + "00"
|
|
|
|
- let customSceneList: any = data[index]?.customSceneList ?? [];
|
|
|
|
- customSceneList.map((item: any) => {
|
|
|
|
- if (index === 0) {
|
|
|
|
- if (nowTime < item.startTime) {
|
|
|
|
- if (!startTime || !endTime) {
|
|
|
|
- startTime = item.startTime
|
|
|
|
- endTime = item.endTime
|
|
|
|
- text = data[index].week
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (!startTime || !endTime) {
|
|
|
|
- startTime = item.startTime
|
|
|
|
- endTime = item.endTime
|
|
|
|
- text = data[index].week
|
|
|
|
- } else {
|
|
|
|
- // debugger
|
|
|
|
- // debugger
|
|
|
|
- if (endTime == '240000') {
|
|
|
|
- if (item.startTime == "000000") {
|
|
|
|
- endTime = item.endTime
|
|
|
|
- text = data[index].week
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (endTime === item.startTime) {
|
|
|
|
- endTime = item.endTime
|
|
|
|
- text = data[index].week
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (that.text) {
|
|
|
|
- let startText: any = that.text.split("~")[0]
|
|
|
|
- that.text = startText
|
|
|
|
- if (text && text != startText) {
|
|
|
|
- that.text = startText + "~" + text
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- that.text = text
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- if (startTime && endTime) {
|
|
|
|
- if (endTime == '240000') {
|
|
|
|
- let nowIndex: any = index + 1
|
|
|
|
- if (nowIndex < data.length - 1) {
|
|
|
|
- return formateTimeContinuous(nowIndex, startTime, endTime, 2, data, that);
|
|
|
|
- } else {
|
|
|
|
- return {
|
|
|
|
- text: that.text,
|
|
|
|
- startTime: startTime,
|
|
|
|
- endTime: endTime,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- return {
|
|
|
|
- text: that.text,
|
|
|
|
- startTime: startTime,
|
|
|
|
- endTime: endTime,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- let nowIndex: any = index + 1
|
|
|
|
- if (nowIndex < data.length - 1) {
|
|
|
|
- return formateTimeContinuous(nowIndex, startTime, endTime, 2, data, that);
|
|
|
|
- } else {
|
|
|
|
- return {
|
|
|
|
- text: that.text,
|
|
|
|
- startTime: startTime,
|
|
|
|
- endTime: endTime,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|