Skip to content

Commit

Permalink
feat: 新增未知状态
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Dec 18, 2023
1 parent 30638a3 commit 3e68ff9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "site-status",
"alia": "SiteStatus",
"private": true,
"version": "1.2.0",
"version": "1.2.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
12 changes: 12 additions & 0 deletions src/components/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ const Header = observer(({ getSiteData }) => {
/>
</span>
</div>
{status.siteOverview?.unknownCount ? (
<div className="unknownCount-count">
<span className="name">未知</span>
<span className="num">
<CountUp
className="num"
end={status.siteOverview.unknownCount}
duration={1}
/>
</span>
</div>
) : null}
</div>
</div>
) : (
Expand Down
22 changes: 16 additions & 6 deletions src/components/siteStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,35 @@ const SiteStatus = ({ siteData, days, status }) => {
className={`site ${
site.status !== "ok" ? "error" : "normal"
}`}
onClick={() => {
showSiteDetails(site);
}}
>
<div className="meta">
<div className="name">{site.name}</div>
<CustomLink iconDom={<LinkTwo />} to={site.url} />
<div
className={`status ${
site.status === "ok" ? "normal" : "error"
site.status === "ok"
? "normal"
: site.status === "unknown"
? "unknown"
: "error"
}`}
>
<div className="icon" />
<span className="tip">
{site.status === "ok" ? "正常访问" : "无法访问"}
{site.status === "ok"
? "正常访问"
: site.status === "unknown"
? "状态未知"
: "无法访问"}
</span>
</div>
</div>
<div className="timeline">
<div
className="timeline"
onClick={() => {
showSiteDetails(site);
}}
>
{site.daily.map((data, index) => {
const { uptime, down, date } = data;
const time = date.format("YYYY-MM-DD");
Expand Down
20 changes: 20 additions & 0 deletions src/style/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ $normal-color: #63ffbd;
$normal-background-color: #3bd672;
$error-color: #ff9595;
$error-background-color: #de484a;
$unknown-color: #4f4f4f;
$unknown-background-color: #2f2f2f;
$allErrors-color: #ff8c8c;
$loading-color: #58d0ff;

Expand Down Expand Up @@ -170,6 +172,15 @@ body {
margin: 0 6px;
}
}
.unknownCount-count {
display: flex;
align-items: center;
&::before {
content: "/";
font-size: 16px;
margin: 0 6px;
}
}
.name {
margin-right: 4px;
}
Expand Down Expand Up @@ -290,6 +301,15 @@ body {
}
}
}
&.unknown {
color: $unknown-background-color;
.icon {
background-color: $unknown-background-color;
&::after {
background-color: $unknown-background-color;
}
}
}
.icon {
position: relative;
width: 12px;
Expand Down
6 changes: 5 additions & 1 deletion src/utils/getSiteData.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dayjs from "dayjs";
export const getSiteData = async (apikey, days, cache, status) => {
try {
status.changeSiteState("loading");

const dates = [];
const today = dayjs(new Date().setHours(0, 0, 0, 0));

Expand Down Expand Up @@ -175,6 +175,9 @@ const changeSite = (data, status) => {
const isAnyStatusOk = data.some((item) => item.status === "ok");
const okCount = data.filter((item) => item.status === "ok").length;
const downCount = data.filter((item) => item.status === "down").length;
const unknownCount = data.filter(
(item) => item.status === "unknown"
).length;

// 更改图标
const faviconLink = document.querySelector('link[rel="shortcut icon"]');
Expand All @@ -196,6 +199,7 @@ const changeSite = (data, status) => {
count: data.length,
okCount,
downCount,
unknownCount,
});
} catch (error) {
console.error("更改站点状态时发生错误:", error);
Expand Down

0 comments on commit 3e68ff9

Please sign in to comment.