diff --git a/.eslintrc.js b/.eslintrc.js
index 71a1637..12c2a4f 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -1,21 +1,41 @@
module.exports = {
- "env": {
- "browser": true,
- "es2021": true
- },
- "extends": [
- "plugin:vue/essential",
- "airbnb-base"
+ env: {
+ browser: true,
+ es2021: true,
+ },
+ extends: [
+ 'plugin:vue/essential',
+ 'airbnb-base',
+ ],
+ parserOptions: {
+ ecmaVersion: 13,
+ parser: '@typescript-eslint/parser',
+ sourceType: 'module',
+ },
+ plugins: [
+ 'vue',
+ '@typescript-eslint',
+ ],
+ rules: {
+ 'vue/html-self-closing': 'off',
+ 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
+ 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
+ 'no-param-reassign': 'off',
+ 'max-len': ['error', { code: 140, tabWidth: 2 }],
+ 'object-curly-newline': ['error', { multiline: true }],
+ 'arrow-parens': ['error', 'as-needed'],
+ 'linebreak-style': 'off',
+ 'vue/attributes-order': 'off',
+ 'vue/singleline-html-element-content-newline': 'off',
+ 'vue/max-attributes-per-line': 'off',
+ 'vue/multiline-html-element-content-newline': 'off',
+ 'vue/html-indent': 'off',
+ 'vue/html-closing-bracket-newline': [
+ 'error',
+ {
+ singleline: 'never',
+ multiline: 'always',
+ },
],
- "parserOptions": {
- "ecmaVersion": 13,
- "parser": "@typescript-eslint/parser",
- "sourceType": "module"
- },
- "plugins": [
- "vue",
- "@typescript-eslint"
- ],
- "rules": {
- }
+ },
};
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dc55e89..76f4938 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
- | first commit | [8dc26de](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/8dc26de)
- | vue3 | [12ed2ad](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/12ed2ad)
- | 使用uview完成api请求 | [1b3efd8](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/1b3efd8)
+ - | 更新代码 | [392c8cc](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/392c8cc)
范围|描述|commitId
diff --git a/components/Calendar/Calendar - 副本.vue b/components/Calendar/Calendar - 副本.vue
new file mode 100644
index 0000000..57afd47
--- /dev/null
+++ b/components/Calendar/Calendar - 副本.vue
@@ -0,0 +1,473 @@
+
+
+
+ {{ timeStr }}
+
+
+
+
+
+ {{ week }}
+
+
+
+
+
+
+
+
+
+
+
+ {{ item.time.getDate() }}
+
+
+
+
+
+
+
+
+
+ {{ item.time.getDate() }}
+
+
+
+
+
+
+
+ {{ item.time.getDate() }}
+
+
+
+
+
+
+
+
+
+
+
+ 今日
+
+
+
+
+
+
diff --git a/components/Calendar/Calendar.vue b/components/Calendar/Calendar.vue
index 57afd47..212ea2e 100644
--- a/components/Calendar/Calendar.vue
+++ b/components/Calendar/Calendar.vue
@@ -1,14 +1,10 @@
-
- {{ timeStr }}
-
+ {{ timeStr }}
-
- {{ week }}
-
+ {{ week }}
@@ -25,26 +21,18 @@
@change="changeSwp"
:circular="true"
>
-
+
-
-
-
- {{ item.time.getDate() }}
-
-
+
+
+ {{ item.time.getDate() }}
+
-
+
-
- {{ item.time.getDate() }}
-
+ {{ item.time.getDate() }}
@@ -68,9 +54,7 @@
'day-hidden': !item.show,
}"
>
-
- {{ item.time.getDate() }}
-
+ {{ item.time.getDate() }}
@@ -83,274 +67,262 @@
-->
- 今日
+ 今日
-
diff --git a/pages.json b/pages.json
index 1aea851..1c2b2b7 100644
--- a/pages.json
+++ b/pages.json
@@ -3,13 +3,20 @@
{
"path": "pages/index/index",
"style": {
- "navigationBarTitleText": "uni-app"
+ "navigationBarText": "TALL"
}
- }
+ }
+ // {
+ // "path": "pages/project/project",
+ // "style": {
+ // "navigationStyle": "custom",
+ // "navigationBarTextStyle": "white"
+ // }
+ // }
],
"globalStyle": {
"navigationBarTextStyle": "black",
- "navigationBarTitleText": "uni-app",
+ "navigationBarTitleText": "TALL",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
}
diff --git a/pages/index/index.vue b/pages/index/index.vue
index c452e57..ff6215b 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -1,66 +1,97 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pages/project/project.vue b/pages/project/project.vue
new file mode 100644
index 0000000..8c394f6
--- /dev/null
+++ b/pages/project/project.vue
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/store/index.js b/store/index.js
index 87e8357..7529a1d 100644
--- a/store/index.js
+++ b/store/index.js
@@ -1,45 +1,46 @@
-import { createStore } from 'vuex';
-import user from './user/index.js';
-import socket from './socket/index.js';
-
-// 不属于具体模块的 应用级的 store内容
-const state = {
- networkConnected: true, // 网络是否连接
- forceUseStorage: true, // 强制启用storage
- systemInfo: null, // 系统设备信息
-};
-
-const getters = {
- // 是否启用本地存储
- // 设置了强制启用本地存储 或者 没有网络连接的时候
- useStorage({ networkConnected, forceUseStorage }) {
- return forceUseStorage || !networkConnected;
- },
-};
-
-const mutations = {
- /**
- * 设置网络是否连接的变量
- * @param {*} state
- * @param {boolean} networkConnected
- */
- setNetworkConnected(state, networkConnected) {
- state.networkConnected = networkConnected;
- },
-
- /**
- * 设置系统信息的数据
- * @param {object} state
- * @param {object | null} data 获取到的数据
- */
- setSystemInfo(state, data) {
- state.systemInfo = data;
- },
-};
-
-export default createStore({
- state,
- getters,
- mutations,
- modules: {user, socket}
+import { createStore } from 'vuex';
+import user from './user/index.js';
+import socket from './socket/index.js';
+import project from './project/index.js';
+
+// 不属于具体模块的 应用级的 store内容
+const state = {
+ networkConnected: true, // 网络是否连接
+ forceUseStorage: true, // 强制启用storage
+ systemInfo: null, // 系统设备信息
+};
+
+const getters = {
+ // 是否启用本地存储
+ // 设置了强制启用本地存储 或者 没有网络连接的时候
+ useStorage({ networkConnected, forceUseStorage }) {
+ return forceUseStorage || !networkConnected;
+ },
+};
+
+const mutations = {
+ /**
+ * 设置网络是否连接的变量
+ * @param {*} state
+ * @param {boolean} networkConnected
+ */
+ setNetworkConnected(state, networkConnected) {
+ state.networkConnected = networkConnected;
+ },
+
+ /**
+ * 设置系统信息的数据
+ * @param {object} state
+ * @param {object | null} data 获取到的数据
+ */
+ setSystemInfo(state, data) {
+ state.systemInfo = data;
+ },
+};
+
+export default createStore({
+ state,
+ getters,
+ mutations,
+ modules: { user, socket, project },
});
diff --git a/store/project/actions.js b/store/project/actions.js
new file mode 100644
index 0000000..5dfa3d4
--- /dev/null
+++ b/store/project/actions.js
@@ -0,0 +1,3 @@
+const actions = {};
+
+export default actions;
diff --git a/store/project/getters.js b/store/project/getters.js
new file mode 100644
index 0000000..39b22a7
--- /dev/null
+++ b/store/project/getters.js
@@ -0,0 +1,11 @@
+const getters = {
+ /**
+ * 当前项目的id
+ * @param {object} project
+ */
+ projectId({ project }) {
+ return project.id;
+ },
+};
+
+export default getters;
diff --git a/store/project/index.js b/store/project/index.js
new file mode 100644
index 0000000..d22f64a
--- /dev/null
+++ b/store/project/index.js
@@ -0,0 +1,12 @@
+import state from './state';
+import getters from './getters';
+import mutations from './mutations';
+import actions from './actions';
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ mutations,
+ actions,
+};
diff --git a/store/project/mutations.js b/store/project/mutations.js
new file mode 100644
index 0000000..fc5baf3
--- /dev/null
+++ b/store/project/mutations.js
@@ -0,0 +1,62 @@
+const mutations = {
+ /**
+ * 设置state projects书籍
+ * @param {object} state
+ * @param {array} projects 项目列表
+ */
+ setProjects(state, projects) {
+ if (!projects || !projects.length) {
+ state.projects = [];
+ } else {
+ state.projects = [...projects];
+ }
+ },
+
+ /**
+ * 设置子项目收缩展开
+ * @param { object } state
+ * @param { object } options options:{ index,show }
+ */
+ setProjectItemShow(state, options) {
+ if (options.show) {
+ for (var i = 0; i < state.projects.length; i++) {
+ if (i === options.index) {
+ state.projects[i].show = true;
+ } else {
+ state.projects[i].show = false;
+ }
+ }
+ } else {
+ state.projects[options.index].show = false;
+ }
+ },
+
+ /**
+ * 设置当前项目信息
+ * @param { object } state
+ * @param { object } data
+ */
+ setProject(state, data) {
+ state.project = data || { name: '加载中...' };
+ },
+
+ /**
+ * 设置当前项目名称
+ * @param { object } state
+ * @param { string } data
+ */
+ setProjectName(state, data) {
+ state.project.name = data;
+ },
+
+ /**
+ * 设置小红点
+ * @param { object } state
+ * @param { string } data
+ */
+ setDotList(state, data) {
+ state.dotList = data;
+ },
+};
+
+export default mutations;
diff --git a/store/project/state.js b/store/project/state.js
new file mode 100644
index 0000000..d33be86
--- /dev/null
+++ b/store/project/state.js
@@ -0,0 +1,8 @@
+/* eslint-disable */
+const state = {
+ project: { name: '加载中...' }, // 当前项目信息
+ projects: [], // 项目列表
+ dotList: [], // 小红点
+};
+
+export default state;
diff --git a/utils/time.js b/utils/time.js
index 90e02ff..da633b0 100644
--- a/utils/time.js
+++ b/utils/time.js
@@ -1,384 +1,379 @@
-import dayjs from 'dayjs';
-
-// const advancedFormat = require('dayjs/plugin/advancedFormat');
-// const weekOfYear = require('dayjs/plugin/weekOfYear');
-// const duration = require('dayjs/plugin/duration');
-
-// dayjs.extend(advancedFormat);
-// dayjs.extend(weekOfYear);
-// dayjs.extend(duration);
-
-/**
- * 格式化数字
- * @param {*} n
- */
-const formatNumber = n => {
- const str = n.toString();
- return str[1] ? str : `0${str}`;
-};
-
-/**
- * 格式化时间
- * @param {number} beginTime
- */
-const formatTime = beginTime => {
- const date = new Date(beginTime);
- const year = date.getFullYear();
- const month = date.getMonth() + 1;
- const day = date.getDate();
- const hour = date.getHours();
- const minute = date.getMinutes();
- const second = date.getSeconds();
-
- return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`;
-};
-
-/**
- * 添加一定时间的时长
- * @param {number | date} time
- * @param {number} num
- * @param {string} cycle
- */
-const add = (time, num, cycle) => {
- const str = dayjs(time).add(num, cycle);
- return str;
-};
-
-/**
- * 时间转换 08:00 转换成8小时0分钟
- * @param {string} time
- * @returns {{hours: number, minutes: number}}
- */
-const convertTime = time => {
- const arr = time.split(':');
- return {
- hours: parseInt(arr[0], 10),
- minutes: parseInt(arr[1], 10),
- };
-};
-
-/**
- * 将秒 -> 分 秒
- * @param {number} seconds
- */
-const secondToMinute = seconds => {
- const minute = formatNumber(Math.floor(seconds / 60));
- const second = formatNumber(parseInt(seconds % 60, 10));
- return {
- minute,
- second,
- };
-};
-
-/**
- * 将时间戳 -> 时:分
- * @param {Number} timestamp 时间戳
- * @return date:2018/10/09 time: 12:59
- */
-const setTimestampToStr = timestamp => {
- const timeObj = new Date(timestamp);
- const year = timeObj.getFullYear();
- const month = formatNumber(timeObj.getMonth() + 1);
- const day = formatNumber(timeObj.getDate());
- const hour = formatNumber(timeObj.getHours());
- const minute = formatNumber(timeObj.getMinutes());
- const date = `${year}-${month}-${day}`;
- const time = `${hour}:${minute}`;
- return {
- date,
- time,
- };
-};
-
-/**
- * 检测时间(ms)是不是今天
- * @param {Number} time 时间戳
- */
-const validateTimeIsToday = time => {
- const timeDate = new Date(time);
- const date = new Date();
- return timeDate.getFullYear() === date.getFullYear() && timeDate.getMonth() === date.getMonth() && timeDate
- .getDate() === date.getDate();
-};
-
-/**
- * 检测两个日期是否相同
- * @param {number | date} time
- * @param {number | date} value
- * @param {string} cycle 传入 day 将会比较 day、 month和 year
- */
-const isSame = (time, value, cycle) => {
- const str = dayjs(time).isSame(value, cycle);
- return str;
-};
-
-/**
- * 格式化开始时间
- * @param {Number} timestamp 时间戳
- * @return
- * 如果是今天 -> 时:分
- * 如果不是今年 -> 年/月/日 时:分
- * 否则 *月*日 时:分
- */
-const formatBeginTime = timestamp => {
- const timeObj = new Date(timestamp);
- const year = timeObj.getFullYear();
- const month = formatNumber(timeObj.getMonth() + 1);
- const day = formatNumber(timeObj.getDate());
- const hour = formatNumber(timeObj.getHours());
- const minute = formatNumber(timeObj.getMinutes());
- const date = `${year}/${month}/${day}`;
- const time = `${hour}:${minute}`;
- const currentYear = new Date().getFullYear();
-
- if (validateTimeIsToday(timestamp)) {
- // 今天
- return `今天 ${time}`;
- } else if (currentYear !== year) {
- // 不是今年
- return `${date} ${time}`;
- } else {
- return `${month}月${day}日 ${time}`;
- }
-};
-
-/**
- * 格式化时长
- * @param {Number} duration 时长
- * 超过24小时( 24 * 60 * 60 * 1000 ms) 转换成天数 + 小时 + 分钟
- * 小于1分钟( 60 * 1000 ms) 转换成秒钟
- * 其余的显示分钟
- * 超过2小时( 2 * 60 * 60 * 1000 ms) 转换成小时 + 分钟数
- */
-const formatDuration = duration => {
- const minuteTime = 60 * 1000;
- const hourTime = 60 * minuteTime;
- const dayTime = 24 * hourTime;
- const days = Math.floor(duration / dayTime);
- const hours = Math.floor((duration % dayTime) / hourTime);
- const minutes = Math.floor((duration % hourTime) / minuteTime);
- if (duration <= 60 * 1000) {
- // 小于1分钟 返回几秒
- return `${Math.floor(duration / 1000)}秒`;
- } else if (duration > dayTime) {
- // 大于1天
- if (minutes === 0) {
- if (hours === 0) {
- // 分钟数是0 和 小时数是0 返回 几天
- return `${days}天`;
- } else {
- // 分钟是0 小时不是0 返回 几天几小时
- return `${days}天${hours}小时`;
- }
- } else {
- // 分钟不是0 返回几天几时几分
- return `${days}天${hours}时${minutes}分`;
- }
- } else if (duration > 2 * hourTime) {
- // 大于2h
- if (minutes === 0) {
- // 分钟是0 返回几小时
- return `${hours}小时`;
- } else {
- // 分钟不是0 返回几小时几分钟
- return `${hours}小时${minutes}分钟`;
- }
- } else {
- // 其余情况 返回 几分钟
- return `${parseInt(duration / minuteTime)}分钟`;
- }
-};
-
-/**
- * 格式化时长 转换成对象格式
- * @param {Number} duration 时长
- * 超过24小时( 24 * 60 * 60 * 1000 ms) 转换成{days, hours, minutes, seconds: 0}
- * 小于1分钟( 60 * 1000 ms) 转换成秒钟 { days: 0, hours: 0, minutes: 0, seconds }
- * 其余的显示分钟 { days: 0, hours: 0, minutes, seconds: 0 }
- * 超过2小时( 2 * 60 * 60 * 1000 ms) 转换成{ days: 0, hours, minutes, seconds: 0 }
- */
-const formatDurationToObject = duration => {
- const minuteTime = 60 * 1000;
- const hourTime = 60 * minuteTime;
- const dayTime = 24 * hourTime;
- const days = Math.floor(duration / dayTime);
- const hours = Math.floor((duration % dayTime) / hourTime);
- const minutes = Math.floor((duration % hourTime) / minuteTime);
- const result = {
- days: 0,
- hours: 0,
- minutes: 0,
- seconds: 0,
- };
- if (duration <= 60 * 1000) {
- // 小于1分钟 返回几秒
- result.seconds = Math.floor(duration / 1000);
- } else if (duration > dayTime) {
- // 大于1天
- if (minutes === 0) {
- if (hours === 0) {
- // 分钟数是0 和 小时数是0 返回 几天
- result.days = days;
- } else {
- // 分钟是0 小时不是0 返回 几天几小时
- result.days = days;
- result.hours = hours;
- }
- } else {
- // 分钟不是0 返回几天几时几分
- result.days = days;
- result.hours = hours;
- result.minutes = minutes;
- }
- } else if (duration > 2 * hourTime) {
- // 大于2h
- if (minutes === 0) {
- // 分钟是0 返回几小时
- result.hours = hours;
- } else {
- // 分钟不是0 返回几小时几分钟
- result.hours = hours;
- result.minutes = minutes;
- }
- } else {
- // 其余情况 返回 几分钟
- result.minutes = minutes;
- }
- return result;
-};
-
-/**
- * 将对象格式的时间转换成时间戳
- * @param {obj} 对象格式的时间 days, hours, minutes, seconds
- * @return 时长的ms
- */
-const formatObjectTimeToMs = (days = 0, hours = 0, minutes = 0, seconds = 0) => {
- return days * 24 * 60 * 60 * 1000 + hours * 60 * 60 * 1000 + minutes * 60 * 1000 + seconds * 1000;
-};
-
-/**
- * 计算过滤 周期
- * @param {string} time 周期字符串
- * @return {string} cycle 周期英文字符串
- */
-const computeCycle = time => {
- // 加载下一个周期的任务
- let cycle = 'day';
- switch (time) {
- case '天':
- cycle = 'day';
- break;
- case '周':
- cycle = 'week';
- break;
- case '月':
- cycle = 'month';
- break;
- default:
- cycle = '日程';
- break;
- }
- return cycle;
-};
-
-/**
- * 将时间按周期语义化
- * @param {string} cycle 周期
- * @param {number|string} time 时间
- */
-const formatStartTimeToCycleTime = (cycle, time) => {
- let result = '';
- const _time = dayjs(+time);
- switch (cycle) {
- case '天':
- result = _time.format('YYYY年M月D日');
- break;
- case '周':
- result = _time.format('YYYY年w周');
- break;
- case '月':
- result = _time.format('YYYY年M月');
- break;
- case '日程':
- result = _time.format('YYYY年M月D日 HH:mm');
- break;
- default:
- result = _time.format('YYYY年M月D日');
- break;
- }
- return result;
-};
-
-/**
- * 计算进行中状态剩余时间 显示数字
- * @param {number} leftTime 剩余时间ms
- * @returns { num: 显示的数字, time: 演示器演示时长 }
- */
-const computeDurationText = leftTime => {
- try {
- if (leftTime < 0) return {
- num: 0,
- time: null
- };
- const {
- years,
- months,
- days,
- hours,
- minutes,
- seconds,
- milliseconds
- } = dayjs.duration(leftTime).$d;
- let num = 0;
- let time = 1000;
-
- if (years > 0) {
- num = years;
- time = 60 * 60 * 1000; // 按小时
- } else if (months > 0) {
- num = months;
- time = 60 * 60 * 1000; // 按小时
- } else if (days > 0) {
- num = days;
- time = 60 * 60 * 1000; // 按小时
- } else if (hours > 0) {
- num = hours;
- } else if (minutes > 0) {
- num = minutes;
- } else if (seconds > 0) {
- num = seconds;
- } else if (milliseconds > 0) {
- num = milliseconds;
- time = 16;
- } else {
- time = null;
- }
- return {
- num,
- time
- };
- } catch (error) {
- console.log('🚀 ~ file: time.js ~ line 335 ~ computeDurationText ~ error', error);
- return {
- num: 0,
- time: null
- };
- }
-};
-
-export default {
- formatNumber,
- formatTime,
- add,
- convertTime,
- secondToMinute,
- setTimestampToStr,
- isSame,
- formatBeginTime,
- formatDuration,
- formatDurationToObject,
- formatObjectTimeToMs,
- computeCycle,
- formatStartTimeToCycleTime,
- computeDurationText,
+import dayjs from 'dayjs';
+
+// const advancedFormat = require('dayjs/plugin/advancedFormat');
+// const weekOfYear = require('dayjs/plugin/weekOfYear');
+// const duration = require('dayjs/plugin/duration');
+
+// dayjs.extend(advancedFormat);
+// dayjs.extend(weekOfYear);
+// dayjs.extend(duration);
+
+/**
+ * 格式化数字
+ * @param {*} n
+ */
+const formatNumber = (n) => {
+ const str = n.toString();
+ return str[1] ? str : `0${str}`;
+};
+
+/**
+ * 格式化时间
+ * @param {number} beginTime
+ */
+const formatTime = (beginTime) => {
+ const date = new Date(beginTime);
+ const year = date.getFullYear();
+ const month = date.getMonth() + 1;
+ const day = date.getDate();
+ const hour = date.getHours();
+ const minute = date.getMinutes();
+ const second = date.getSeconds();
+
+ return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`;
+};
+
+/**
+ * 添加一定时间的时长
+ * @param {number | date} time
+ * @param {number} num
+ * @param {string} cycle
+ */
+const add = (time, num, cycle) => {
+ const str = dayjs(time).add(num, cycle);
+ return str;
+};
+
+/**
+ * 时间转换 08:00 转换成8小时0分钟
+ * @param {string} time
+ * @returns {{hours: number, minutes: number}}
+ */
+const convertTime = (time) => {
+ const arr = time.split(':');
+ return {
+ hours: parseInt(arr[0], 10),
+ minutes: parseInt(arr[1], 10),
+ };
+};
+
+/**
+ * 将秒 -> 分 秒
+ * @param {number} seconds
+ */
+const secondToMinute = (seconds) => {
+ const minute = formatNumber(Math.floor(seconds / 60));
+ const second = formatNumber(parseInt(seconds % 60, 10));
+ return {
+ minute,
+ second,
+ };
+};
+
+/**
+ * 将时间戳 -> 时:分
+ * @param {Number} timestamp 时间戳
+ * @return date:2018/10/09 time: 12:59
+ */
+const setTimestampToStr = (timestamp) => {
+ const timeObj = new Date(timestamp);
+ const year = timeObj.getFullYear();
+ const month = formatNumber(timeObj.getMonth() + 1);
+ const day = formatNumber(timeObj.getDate());
+ const hour = formatNumber(timeObj.getHours());
+ const minute = formatNumber(timeObj.getMinutes());
+ const date = `${year}-${month}-${day}`;
+ const time = `${hour}:${minute}`;
+ return {
+ date,
+ time,
+ };
+};
+
+/**
+ * 检测时间(ms)是不是今天
+ * @param {Number} time 时间戳
+ */
+const validateTimeIsToday = (time) => {
+ const timeDate = new Date(time);
+ const date = new Date();
+ return timeDate.getFullYear() === date.getFullYear() && timeDate.getMonth() === date.getMonth() && timeDate
+ .getDate() === date.getDate();
+};
+
+/**
+ * 检测两个日期是否相同
+ * @param {number | date} time
+ * @param {number | date} value
+ * @param {string} cycle 传入 day 将会比较 day、 month和 year
+ */
+const isSame = (time, value, cycle) => {
+ const str = dayjs(time).isSame(value, cycle);
+ return str;
+};
+
+/**
+ * 格式化开始时间
+ * @param {Number} timestamp 时间戳
+ * @return
+ * 如果是今天 -> 时:分
+ * 如果不是今年 -> 年/月/日 时:分
+ * 否则 *月*日 时:分
+ */
+const formatBeginTime = (timestamp) => {
+ const timeObj = new Date(timestamp);
+ const year = timeObj.getFullYear();
+ const month = formatNumber(timeObj.getMonth() + 1);
+ const day = formatNumber(timeObj.getDate());
+ const hour = formatNumber(timeObj.getHours());
+ const minute = formatNumber(timeObj.getMinutes());
+ const date = `${year}/${month}/${day}`;
+ const time = `${hour}:${minute}`;
+ const currentYear = new Date().getFullYear();
+
+ if (validateTimeIsToday(timestamp)) {
+ // 今天
+ return `今天 ${time}`;
+ } if (currentYear !== year) {
+ // 不是今年
+ return `${date} ${time}`;
+ }
+ return `${month}月${day}日 ${time}`;
+};
+
+/**
+ * 格式化时长
+ * @param {Number} duration 时长
+ * 超过24小时( 24 * 60 * 60 * 1000 ms) 转换成天数 + 小时 + 分钟
+ * 小于1分钟( 60 * 1000 ms) 转换成秒钟
+ * 其余的显示分钟
+ * 超过2小时( 2 * 60 * 60 * 1000 ms) 转换成小时 + 分钟数
+ */
+const formatDuration = (duration) => {
+ const minuteTime = 60 * 1000;
+ const hourTime = 60 * minuteTime;
+ const dayTime = 24 * hourTime;
+ const days = Math.floor(duration / dayTime);
+ const hours = Math.floor((duration % dayTime) / hourTime);
+ const minutes = Math.floor((duration % hourTime) / minuteTime);
+ if (duration <= 60 * 1000) {
+ // 小于1分钟 返回几秒
+ return `${Math.floor(duration / 1000)}秒`;
+ } if (duration > dayTime) {
+ // 大于1天
+ if (minutes === 0) {
+ if (hours === 0) {
+ // 分钟数是0 和 小时数是0 返回 几天
+ return `${days}天`;
+ }
+ // 分钟是0 小时不是0 返回 几天几小时
+ return `${days}天${hours}小时`;
+ }
+ // 分钟不是0 返回几天几时几分
+ return `${days}天${hours}时${minutes}分`;
+ } if (duration > 2 * hourTime) {
+ // 大于2h
+ if (minutes === 0) {
+ // 分钟是0 返回几小时
+ return `${hours}小时`;
+ }
+ // 分钟不是0 返回几小时几分钟
+ return `${hours}小时${minutes}分钟`;
+ }
+ // 其余情况 返回 几分钟
+ return `${parseInt(duration / minuteTime)}分钟`;
+};
+
+/**
+ * 格式化时长 转换成对象格式
+ * @param {Number} duration 时长
+ * 超过24小时( 24 * 60 * 60 * 1000 ms) 转换成{days, hours, minutes, seconds: 0}
+ * 小于1分钟( 60 * 1000 ms) 转换成秒钟 { days: 0, hours: 0, minutes: 0, seconds }
+ * 其余的显示分钟 { days: 0, hours: 0, minutes, seconds: 0 }
+ * 超过2小时( 2 * 60 * 60 * 1000 ms) 转换成{ days: 0, hours, minutes, seconds: 0 }
+ */
+const formatDurationToObject = (duration) => {
+ const minuteTime = 60 * 1000;
+ const hourTime = 60 * minuteTime;
+ const dayTime = 24 * hourTime;
+ const days = Math.floor(duration / dayTime);
+ const hours = Math.floor((duration % dayTime) / hourTime);
+ const minutes = Math.floor((duration % hourTime) / minuteTime);
+ const result = {
+ days: 0,
+ hours: 0,
+ minutes: 0,
+ seconds: 0,
+ };
+ if (duration <= 60 * 1000) {
+ // 小于1分钟 返回几秒
+ result.seconds = Math.floor(duration / 1000);
+ } else if (duration > dayTime) {
+ // 大于1天
+ if (minutes === 0) {
+ if (hours === 0) {
+ // 分钟数是0 和 小时数是0 返回 几天
+ result.days = days;
+ } else {
+ // 分钟是0 小时不是0 返回 几天几小时
+ result.days = days;
+ result.hours = hours;
+ }
+ } else {
+ // 分钟不是0 返回几天几时几分
+ result.days = days;
+ result.hours = hours;
+ result.minutes = minutes;
+ }
+ } else if (duration > 2 * hourTime) {
+ // 大于2h
+ if (minutes === 0) {
+ // 分钟是0 返回几小时
+ result.hours = hours;
+ } else {
+ // 分钟不是0 返回几小时几分钟
+ result.hours = hours;
+ result.minutes = minutes;
+ }
+ } else {
+ // 其余情况 返回 几分钟
+ result.minutes = minutes;
+ }
+ return result;
+};
+
+/**
+ * 将对象格式的时间转换成时间戳
+ * @param {obj} 对象格式的时间 days, hours, minutes, seconds
+ * @return 时长的ms
+ */
+const formatObjectTimeToMs = (days = 0, hours = 0, minutes = 0, seconds = 0) => days * 24 * 60 * 60 * 1000 + hours * 60 * 60 * 1000 + minutes * 60 * 1000 + seconds * 1000;
+
+/**
+ * 计算过滤 周期
+ * @param {string} time 周期字符串
+ * @return {string} cycle 周期英文字符串
+ */
+const computeCycle = (time) => {
+ // 加载下一个周期的任务
+ let cycle = 'day';
+ switch (time) {
+ case '天':
+ cycle = 'day';
+ break;
+ case '周':
+ cycle = 'week';
+ break;
+ case '月':
+ cycle = 'month';
+ break;
+ default:
+ cycle = '日程';
+ break;
+ }
+ return cycle;
+};
+
+/**
+ * 将时间按周期语义化
+ * @param {string} cycle 周期
+ * @param {number|string} time 时间
+ */
+const formatStartTimeToCycleTime = (cycle, time) => {
+ let result = '';
+ const _time = dayjs(+time);
+ switch (cycle) {
+ case '天':
+ result = _time.format('YYYY年M月D日');
+ break;
+ case '周':
+ result = _time.format('YYYY年w周');
+ break;
+ case '月':
+ result = _time.format('YYYY年M月');
+ break;
+ case '日程':
+ result = _time.format('YYYY年M月D日 HH:mm');
+ break;
+ default:
+ result = _time.format('YYYY年M月D日');
+ break;
+ }
+ return result;
+};
+
+/**
+ * 计算进行中状态剩余时间 显示数字
+ * @param {number} leftTime 剩余时间ms
+ * @returns { num: 显示的数字, time: 演示器演示时长 }
+ */
+const computeDurationText = (leftTime) => {
+ try {
+ if (leftTime < 0) {
+ return {
+ num: 0,
+ time: null,
+ };
+ }
+ const {
+ years,
+ months,
+ days,
+ hours,
+ minutes,
+ seconds,
+ milliseconds,
+ } = dayjs.duration(leftTime).$d;
+ let num = 0;
+ let time = 1000;
+
+ if (years > 0) {
+ num = years;
+ time = 60 * 60 * 1000; // 按小时
+ } else if (months > 0) {
+ num = months;
+ time = 60 * 60 * 1000; // 按小时
+ } else if (days > 0) {
+ num = days;
+ time = 60 * 60 * 1000; // 按小时
+ } else if (hours > 0) {
+ num = hours;
+ } else if (minutes > 0) {
+ num = minutes;
+ } else if (seconds > 0) {
+ num = seconds;
+ } else if (milliseconds > 0) {
+ num = milliseconds;
+ time = 16;
+ } else {
+ time = null;
+ }
+ return {
+ num,
+ time,
+ };
+ } catch (error) {
+ console.log('🚀 ~ file: time.js ~ line 335 ~ computeDurationText ~ error', error);
+ return {
+ num: 0,
+ time: null,
+ };
+ }
+};
+
+export default {
+ formatNumber,
+ formatTime,
+ add,
+ convertTime,
+ secondToMinute,
+ setTimestampToStr,
+ isSame,
+ formatBeginTime,
+ formatDuration,
+ formatDurationToObject,
+ formatObjectTimeToMs,
+ computeCycle,
+ formatStartTimeToCycleTime,
+ computeDurationText,
};