✨ inverters
This commit is contained in:
parent
660e1cd10b
commit
e801111351
97
app/(defaults)/sungrow/inverters/page.tsx
Normal file
97
app/(defaults)/sungrow/inverters/page.tsx
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
"use client";
|
||||||
|
import IconTrashLines from '@/components/icon/icon-trash-lines';
|
||||||
|
import PanelCodeHighlight from '@/components/panel-code-highlight';
|
||||||
|
import ComponentsTablesSimple from '@/components/tables/components-tables-simple';
|
||||||
|
import { formatUnixTimestamp } from '@/utils/helpers';
|
||||||
|
import Tippy from '@tippyjs/react';
|
||||||
|
import axios from 'axios';
|
||||||
|
import React, { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
type Props = {}
|
||||||
|
|
||||||
|
const SungrowInverters = (props: Props) => {
|
||||||
|
const [inverters, setInverters] = useState<any[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
|
try {
|
||||||
|
const res = await axios.get("https://api-a.fomware.com.cn/asset/v1/list?type=2", {
|
||||||
|
headers: {
|
||||||
|
"Authorization": "Bearer " + process.env.NEXT_PUBLIC_CHINT_TOKEN
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log("res", res.data.data.devices)
|
||||||
|
setInverters(res.data.data.devices)
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchData()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// inverter status 0: initial, 1: standby, 2: fault, 3: running, 5: offline, 9: shutdown, 10: unknown
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{loading ? <p>Loading...</p> : (
|
||||||
|
<PanelCodeHighlight title="Chint Sites">
|
||||||
|
<div className="table-responsive mb-5">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Model</th>
|
||||||
|
<th>Site Name</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Created At</th>
|
||||||
|
<th>Updated At</th>
|
||||||
|
<th className="text-center">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{inverters.map((data) => (
|
||||||
|
<tr key={data.id}>
|
||||||
|
<td>
|
||||||
|
<div className="whitespace-nowrap">{data.model}</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div className="whitespace-nowrap">{data.siteName}</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div className={`whitespace-nowrap ${
|
||||||
|
data.status === 0 ? "text-gray-500" // Initial
|
||||||
|
: data.status === 1 ? "text-green-500" // Standby
|
||||||
|
: data.status === 2 ? "text-red-500" // Fault
|
||||||
|
: data.status === 3 ? "text-blue-500" // Running
|
||||||
|
: data.status === 5 ? "text-yellow-500" // Offline
|
||||||
|
: data.status === 9 ? "text-purple-500" // Shutdown
|
||||||
|
: "text-gray-400" // Unknown (default)
|
||||||
|
}`}>
|
||||||
|
{data.statusLabel}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>{formatUnixTimestamp(data.createdAt)}</td>
|
||||||
|
<td>{formatUnixTimestamp(data.updatedAt)}</td>
|
||||||
|
<td className="text-center">
|
||||||
|
<Tippy content="Delete">
|
||||||
|
<button type="button">
|
||||||
|
<IconTrashLines className="m-auto" />
|
||||||
|
</button>
|
||||||
|
</Tippy>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</PanelCodeHighlight>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SungrowInverters
|
@ -6,19 +6,19 @@ import axios from "axios";
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
const SungrowAssets = () => {
|
const SungrowAssets = () => {
|
||||||
const [devices, setDevices] = useState<any[]>([]);
|
const [sites, setSites] = useState<any[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get("https://api-a.fomware.com.cn/asset/v1/list", {
|
const res = await axios.get("https://api-a.fomware.com.cn/site/v1/list", {
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": "Bearer lIywwAMdrOdsRxuWvRoekdxrPtmIPkxA"
|
"Authorization": "Bearer " + process.env.NEXT_PUBLIC_CHINT_TOKEN
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log("res", res.data.data.devices)
|
console.log("res", res.data.data.siteInfos)
|
||||||
setDevices(res.data.data.devices);
|
setSites(res.data.data.siteInfos)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching data:", error);
|
console.error("Error fetching data:", error);
|
||||||
} finally {
|
} finally {
|
||||||
@ -26,12 +26,12 @@ const SungrowAssets = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchData();
|
fetchData()
|
||||||
}, []);
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{loading ? <p>Loading...</p> : <ComponentsTablesSimple tableData={devices} />}
|
{loading ? <p>Loading...</p> : <ComponentsTablesSimple tableData={sites} />}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,9 @@ const Sidebar = () => {
|
|||||||
<li>
|
<li>
|
||||||
<Link href="/sungrow/sites">Sites</Link>
|
<Link href="/sungrow/sites">Sites</Link>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<Link href="/sungrow/inverters">Inverters</Link>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</AnimateHeight>
|
</AnimateHeight>
|
||||||
</li>
|
</li>
|
||||||
|
@ -27,22 +27,17 @@ const ComponentsTablesSimple = ({ tableData = [] }: { tableData: any[] }) => {
|
|||||||
{tableData.map((data) => (
|
{tableData.map((data) => (
|
||||||
<tr key={data.id}>
|
<tr key={data.id}>
|
||||||
<td>
|
<td>
|
||||||
<div className="whitespace-nowrap">{data.siteName}</div>
|
<div className="whitespace-nowrap">{data.name}</div>
|
||||||
</td>
|
</td>
|
||||||
<td>{data.inverter.length}</td>
|
<td>{data.deviceQty.inverterQty}</td>
|
||||||
<td>
|
<td>
|
||||||
<div className={`whitespace-nowrap ${ data.status === 1 ? "text-danger" : "text-success" }`} >
|
<div className={`whitespace-nowrap ${ data.status !== 1 ? "text-danger" : "text-success" }`} >
|
||||||
{data.statusLabel}
|
{data.statusLabel}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>{formatUnixTimestamp(data.createdAt)}</td>
|
<td>{formatUnixTimestamp(data.createdAt)}</td>
|
||||||
<td>{formatUnixTimestamp(data.updatedAt)}</td>
|
<td>{formatUnixTimestamp(data.updatedAt)}</td>
|
||||||
<td className="text-center">
|
<td className="text-center">
|
||||||
<Tippy content="View">
|
|
||||||
<button type="button" className='mr-2'>
|
|
||||||
<IconEye className="m-auto" />
|
|
||||||
</button>
|
|
||||||
</Tippy>
|
|
||||||
<Tippy content="Delete">
|
<Tippy content="Delete">
|
||||||
<button type="button">
|
<button type="button">
|
||||||
<IconTrashLines className="m-auto" />
|
<IconTrashLines className="m-auto" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user