From 4683d8882dc5055366dd01eb8cb58a2e74a66fd6 Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Mon, 12 Oct 2020 16:15:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=97=A5=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/router/index.ts | 4 + src/utils/date.ts | 42 ++++++++ src/views/regime/date.vue | 201 ++++++++++++++++++++++++++++++++++++++ yarn.lock | 5 + 5 files changed, 253 insertions(+) create mode 100644 src/utils/date.ts create mode 100644 src/views/regime/date.vue diff --git a/package.json b/package.json index 779f77f..c7de61e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "ant-design-vue": "^2.0.0-beta.9", "axios": "^0.20.0", "core-js": "^3.6.5", + "dayjs": "^1.9.1", "postcss-pxtorem": "^5.1.1", "vue": "^3.0.0-0", "vue-router": "^4.0.0-0", diff --git a/src/router/index.ts b/src/router/index.ts index 0cf92c0..e06afcf 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -92,6 +92,10 @@ const routes: Array = [ { path: "liveing", component: () => import("../views/regime/Liveing.vue") + }, + { + path: "date", + component: () => import("../views/regime/date.vue") } ] }, diff --git a/src/utils/date.ts b/src/utils/date.ts new file mode 100644 index 0000000..3b25b44 --- /dev/null +++ b/src/utils/date.ts @@ -0,0 +1,42 @@ +import dayjs from 'dayjs' + +export function getdate(){ + let now = dayjs() + const day = now.date() // 当前天 + now = now.date(1) + const week = now.day(); // 第一天是星期几 + now = now.month(now.month() + 1); + now = now.date(0); + const month = now.date(); // 当前月有几天 + + + console.log(day,week,month) + let i = 0; + let w = 0; + + interface Date{ + day?: number; + list?: Array; + } + const date: Array> = [[]]; + + while(i < month){ + + for(w = 0; w < week; w++){ + date[0][w] = {}; + } + i++; + w = w == 0 ? 1 : w; + const zhou = Math.floor((i + w - 1) / 7) + const d = { + day: i + } + if(date[zhou] == undefined){ + date[zhou] = [] + } + date[zhou].push(d) + } + console.log(date) + return date; +} + diff --git a/src/views/regime/date.vue b/src/views/regime/date.vue new file mode 100644 index 0000000..0c1c89a --- /dev/null +++ b/src/views/regime/date.vue @@ -0,0 +1,201 @@ + + + \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 207f96c..9ff7b28 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3321,6 +3321,11 @@ dashdash@^1.12.0: dependencies: assert-plus "^1.0.0" +dayjs@^1.9.1: + version "1.9.1" + resolved "https://registry.npm.taobao.org/dayjs/download/dayjs-1.9.1.tgz?cache=0&sync_timestamp=1601296772816&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdayjs%2Fdownload%2Fdayjs-1.9.1.tgz#201a755f7db5103ed6de63ba93a984141c754541" + integrity sha1-IBp1X321ED7W3mO6k6mEFBx1RUE= + debug@2.6.9, debug@^2.2.0, debug@^2.3.3: version "2.6.9" resolved "https://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz?cache=0&sync_timestamp=1600502826356&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdebug%2Fdownload%2Fdebug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" -- 2.47.2 From bbe9e3bcc2df82becf5771ec91a9fe9aebc53634 Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Mon, 12 Oct 2020 16:44:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=97=A5=E5=8E=86=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.ts | 2 +- src/utils/date.ts | 17 ++++++++++++----- src/views/regime/date.vue | 21 ++++++++++++++++----- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 54cd233..d3600a0 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -37,7 +37,7 @@ export async function userinfo(){ const user = await get('personalInfo'); // console.log(user.data?.img) if(user.code == 1001){ - router.push("/") + // router.push("/") return '未登录'; } return { diff --git a/src/utils/date.ts b/src/utils/date.ts index 3b25b44..e07526e 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -1,15 +1,19 @@ import dayjs from 'dayjs' -export function getdate(){ +export function getdate(yue?: number){ let now = dayjs() + if(yue != undefined){ + now = now.month(now.month() + yue); + } + yue = now.month() + 1; const day = now.date() // 当前天 now = now.date(1) const week = now.day(); // 第一天是星期几 now = now.month(now.month() + 1); now = now.date(0); const month = now.date(); // 当前月有几天 - - + const year = now.year() + console.log(day,week,month) let i = 0; let w = 0; @@ -26,7 +30,6 @@ export function getdate(){ date[0][w] = {}; } i++; - w = w == 0 ? 1 : w; const zhou = Math.floor((i + w - 1) / 7) const d = { day: i @@ -36,7 +39,11 @@ export function getdate(){ } date[zhou].push(d) } + while(date[date.length - 1].length < 7){ + date[date.length - 1].push({}) + } console.log(date) - return date; + + return {date, year, yue}; } diff --git a/src/views/regime/date.vue b/src/views/regime/date.vue index 0c1c89a..8717eaa 100644 --- a/src/views/regime/date.vue +++ b/src/views/regime/date.vue @@ -1,15 +1,15 @@