Skip to content

Commit 4640d81

Browse files
authored
Merge branch 'imsyy:dev' into dev
2 parents fc134be + 081834c commit 4640d81

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"dayjs": "^1.11.10",
2121
"element-plus": "^2.7.1",
2222
"fetch-jsonp": "^1.3.0",
23+
"lodash-es": "^4.17.21",
2324
"pinia": "^2.1.7",
2425
"pinia-plugin-persistedstate": "^3.2.1",
2526
"swiper": "^11.1.1",

pnpm-lock.yaml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/cursor.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import { isEqual } from "lodash-es";
2+
13
let mainCursor;
24

3-
Math.lerp = (a, b, n) => (1 - n) * a + n * b;
5+
const lerp = (a, b, n) => {
6+
if (Math.round(a) === b) {
7+
return b;
8+
}
9+
return (1 - n) * a + n * b;
10+
};
411

512
const getStyle = (el, attr) => {
613
try {
@@ -49,7 +56,6 @@ class Cursor {
4956
document.body.appendChild((this.scr = document.createElement("style")));
5057
this.scr.innerHTML = `* {cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' width='10px' height='10px'><circle cx='4' cy='4' r='4' fill='white' /></svg>") 4 4, auto !important}`;
5158
}
52-
5359
refresh() {
5460
this.scr.remove();
5561
this.cursor.classList.remove("active");
@@ -72,6 +78,7 @@ class Cursor {
7278
y: e.clientY - 8,
7379
};
7480
this.cursor.classList.remove("hidden");
81+
this.render();
7582
};
7683
document.onmouseenter = () => this.cursor.classList.remove("hidden");
7784
document.onmouseleave = () => this.cursor.classList.add("hidden");
@@ -81,13 +88,15 @@ class Cursor {
8188

8289
render() {
8390
if (this.pos.prev) {
84-
this.pos.prev.x = Math.lerp(this.pos.prev.x, this.pos.curr.x, 0.35);
85-
this.pos.prev.y = Math.lerp(this.pos.prev.y, this.pos.curr.y, 0.35);
91+
this.pos.prev.x = lerp(this.pos.prev.x, this.pos.curr.x, 0.35);
92+
this.pos.prev.y = lerp(this.pos.prev.y, this.pos.curr.y, 0.35);
8693
this.move(this.pos.prev.x, this.pos.prev.y);
8794
} else {
8895
this.pos.prev = this.pos.curr;
8996
}
90-
requestAnimationFrame(() => this.render());
97+
if (!isEqual(this.pos.curr, this.pos.prev)) {
98+
requestAnimationFrame(() => this.render());
99+
}
91100
}
92101
}
93102

src/utils/getTime.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,21 @@ export const checkDays = () => {
124124
// 建站日期统计
125125
export const siteDateStatistics = (startDate) => {
126126
const currentDate = new Date();
127-
const differenceInTime = currentDate.getTime() - startDate.getTime();
128-
const differenceInDays = differenceInTime / (1000 * 3600 * 24);
129-
const differenceInMonths = differenceInDays / 30;
130-
const differenceInYears = differenceInMonths / 12;
131-
if (differenceInYears >= 1) {
132-
return `本站已经苟活了 ${Math.floor(differenceInYears)}${Math.floor(
133-
differenceInMonths % 12,
134-
)}${Math.round(differenceInDays % 30)} 天`;
135-
} else if (differenceInMonths >= 1) {
136-
return `本站已经苟活了 ${Math.floor(differenceInMonths)}${Math.round(
137-
differenceInDays % 30,
138-
)} 天`;
139-
} else {
140-
return `本站已经苟活了 ${Math.round(differenceInDays)} 天`;
127+
let years = currentDate.getFullYear() - startDate.getFullYear();
128+
let months = currentDate.getMonth() - startDate.getMonth();
129+
let days = currentDate.getDate() - startDate.getDate();
130+
131+
// 如果天数或月份为负数,则调整天数和月份
132+
if (days < 0) {
133+
months--;
134+
const lastMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 0);
135+
days += lastMonth.getDate();
141136
}
137+
138+
if (months < 0) {
139+
years--;
140+
months += 12;
141+
}
142+
143+
return `本站已经苟活了 ${years}${months}${days} 天`;
142144
};

0 commit comments

Comments
 (0)