seeder-st2110-components 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useState, useCallback, useEffect, memo, useMemo, useRef, forwardRef, useContext, createContext } from 'react';
2
2
  import { useWebSocket, useInterval } from 'ahooks';
3
- import { Tooltip, Space, Flex, Divider, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Popover, Button, Popconfirm, Typography, Empty, ConfigProvider, Tree, InputNumber, Badge, Switch, Select, List, Checkbox, Row, Col } from 'antd';
3
+ import { Tooltip, Space, Divider, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Popover, Flex as Flex$1, Button, Popconfirm, Typography, Empty, ConfigProvider, Tree, InputNumber, Badge, Switch, Select, List, Checkbox, Row, Col } from 'antd';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import { LoadingOutlined, ExclamationCircleFilled, FolderOpenOutlined, FolderOutlined, PlusOutlined } from '@ant-design/icons';
6
6
  import axios from 'axios';
@@ -50,20 +50,28 @@ const useHardwareWebSocket = socketUrl => {
50
50
  };
51
51
  var useHardwareWebSocket$1 = useHardwareWebSocket;
52
52
 
53
+ const formatBytes = function (bytes) {
54
+ let decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
55
+ if (bytes === 0 || !bytes) return '0 Bytes';
56
+ const k = 1024;
57
+ const dm = decimals < 0 ? 0 : decimals;
58
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
59
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
60
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
61
+ };
53
62
  const UsageItem = /*#__PURE__*/memo(_ref => {
54
63
  let {
64
+ title,
55
65
  iconClass,
56
- text,
57
66
  children,
58
- showRam,
59
- ramValue
67
+ memTotal
60
68
  } = _ref;
61
- const tooltipContent = useMemo(() => /*#__PURE__*/jsx(Tooltip, {
69
+ return /*#__PURE__*/jsx(Tooltip, {
62
70
  title: /*#__PURE__*/jsxs(Fragment, {
63
71
  children: [/*#__PURE__*/jsx("div", {
64
- children: text
65
- }), showRam && /*#__PURE__*/jsxs("div", {
66
- children: ["Total Memory: ", ramValue, "GB"]
72
+ children: title
73
+ }), title === 'Memory Usage' && memTotal !== undefined && /*#__PURE__*/jsxs("div", {
74
+ children: ["Total Memory: ", formatBytes(memTotal)]
67
75
  })]
68
76
  }),
69
77
  destroyOnHidden: false,
@@ -76,59 +84,100 @@ const UsageItem = /*#__PURE__*/memo(_ref => {
76
84
  children: children
77
85
  })]
78
86
  })
79
- }), [text, iconClass, children]);
80
- return /*#__PURE__*/jsxs(Flex, {
81
- align: "center",
82
- children: [tooltipContent, /*#__PURE__*/jsx(Divider, {
83
- type: "vertical"
84
- })]
85
87
  });
86
88
  });
87
89
  var UsageItem$1 = UsageItem;
88
90
 
89
- const getTemperature = (supermicro, sensors) => {
90
- return supermicro?.cpu_temperature ?? sensors?.temperatures?.coretemp?.[0]?.current;
91
+ const getMaxNicTemp = function (sensors) {
92
+ let priorityFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ["i350bb", "r8169_0_8300:00"];
93
+ const temps = priorityFields.flatMap(field => sensors?.[field]?.map(item => item.current) || []).filter(temp => typeof temp === 'number');
94
+ return temps.length ? Math.max(...temps) : null;
91
95
  };
92
- const useHardwareUsage = function (ps_status) {
93
- let showRam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
96
+
97
+ // 获取数组类型传感器最高温度(如内存、硬盘)
98
+ const getMaxSensorTemp = sensorData => {
99
+ const temps = (sensorData || []).map(item => item.current).filter(temp => typeof temp === 'number');
100
+ return temps.length ? Math.max(...temps) : null;
101
+ };
102
+ const getDetail = function () {
103
+ let status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
104
+ const {
105
+ cpu_percent,
106
+ mem,
107
+ sensors_temperatures,
108
+ gpu_stats
109
+ } = status;
110
+ return {
111
+ cpu_usage: cpu_percent ?? null,
112
+ cpu_temp: sensors_temperatures?.coretemp?.[0]?.current ?? null,
113
+ mem_total: mem?.total ?? null,
114
+ mem_usage: mem?.percent ?? null,
115
+ mem_temp: getMaxSensorTemp(sensors_temperatures?.spd5118),
116
+ nic_temp: getMaxNicTemp(sensors_temperatures) ?? null,
117
+ hd_temp: getMaxSensorTemp(sensors_temperatures?.nvme),
118
+ gpu_usage: gpu_stats?.[0]?.["utilization.gpu"] ?? null,
119
+ gpu_temp: gpu_stats?.[0]?.["temperature.gpu"] ?? null
120
+ };
121
+ };
122
+
123
+ // 提取公共逻辑
124
+ const createMetricItem = (title, iconClass, value, unit) => {
125
+ const numValue = typeof value === 'string' ? parseFloat(value) : value;
126
+ return {
127
+ title,
128
+ iconClass,
129
+ valueString: `${numValue}${unit}`,
130
+ value: numValue
131
+ };
132
+ };
133
+ const getItems = details => {
134
+ const items = [];
135
+ if (details.cpu_usage !== null && details.cpu_usage !== undefined) {
136
+ items.push(createMetricItem('CPU Usage', 'icon-CPU', details.cpu_usage, '%'));
137
+ }
138
+ if (details.cpu_temp !== null && details.cpu_temp !== undefined) {
139
+ items.push(createMetricItem('CPU Temperature', 'icon-CPUwendu', details.cpu_temp, '℃'));
140
+ }
141
+ if (details.mem_usage !== null && details.mem_usage !== undefined) {
142
+ items.push({
143
+ ...createMetricItem('Memory Usage', 'icon-shiyongshuai', details.mem_usage, '%'),
144
+ memTotal: details.mem_total
145
+ });
146
+ }
147
+ if (details.mem_temp !== null && details.mem_temp !== undefined) {
148
+ items.push(createMetricItem('Memory Temperature', 'icon-wendu', details.mem_temp, '℃'));
149
+ }
150
+ if (details.nic_temp !== null && details.nic_temp !== undefined) {
151
+ items.push(createMetricItem('NIC Temperature', 'icon-wuliwangka', details.nic_temp, '℃'));
152
+ }
153
+ if (details.hd_temp !== null && details.hd_temp !== undefined) {
154
+ items.push(createMetricItem('HD Temperature', 'icon-yingpan', details.hd_temp, '℃'));
155
+ }
156
+ if (details.gpu_usage !== null && details.gpu_usage !== undefined) {
157
+ items.push(createMetricItem('GPU Usage', 'icon-gpufuwu', details.gpu_usage, '%'));
158
+ }
159
+ if (details.gpu_temp !== null && details.gpu_temp !== undefined) {
160
+ items.push(createMetricItem('GPU Temperature', 'icon-CPUwendu', details.gpu_temp, '℃'));
161
+ }
162
+ return items;
163
+ };
164
+ const useHardwareUsage = ps_status => {
94
165
  return useMemo(() => {
95
166
  if (!ps_status || typeof ps_status !== 'object') return null;
96
- const {
97
- cpu_percent,
98
- sensors_temperatures,
99
- mem,
100
- gpu_stats,
101
- supermicro
102
- } = ps_status;
103
- return /*#__PURE__*/jsxs("div", {
167
+ const statusItems = getItems(getDetail(ps_status));
168
+ return /*#__PURE__*/jsx("div", {
104
169
  className: "flex",
105
- children: [/*#__PURE__*/jsxs(UsageItem$1, {
106
- text: "CPU Usage",
107
- iconClass: "icon-CPU",
108
- children: [cpu_percent, "%"]
109
- }), /*#__PURE__*/jsxs(UsageItem$1, {
110
- text: "CPU Temperature",
111
- iconClass: "icon-wendu",
112
- children: [getTemperature(supermicro, sensors_temperatures), "\u2103"]
113
- }), mem && /*#__PURE__*/jsxs(UsageItem$1, {
114
- text: "Memory Usage",
115
- iconClass: "icon-shiyongshuai",
116
- showRam: showRam,
117
- ramValue: (mem.total / (1024 * 1024 * 1024)).toFixed(1),
118
- children: [mem.percent, "%"]
119
- }), supermicro?.nic_temperature && /*#__PURE__*/jsxs(UsageItem$1, {
120
- text: "NIC Temperature",
121
- iconClass: "icon-wuliwangka",
122
- children: [supermicro.nic_temperature, "\u2103"]
123
- }), gpu_stats?.length > 0 && /*#__PURE__*/jsx(UsageItem$1, {
124
- text: "GPU Usage",
125
- iconClass: "icon-gpufuwu",
126
- children: gpu_stats[0]["utilization.gpu"]
127
- }), supermicro?.gpu_temperature && /*#__PURE__*/jsxs(UsageItem$1, {
128
- text: "GPU Temperature",
129
- iconClass: "icon-wendu",
130
- children: [supermicro.gpu_temperature, "\u2103"]
131
- })]
170
+ children: statusItems.map((item, index) => /*#__PURE__*/jsxs(Flex, {
171
+ align: "center",
172
+ children: [/*#__PURE__*/jsx(UsageItem$1, {
173
+ title: item.title,
174
+ iconClass: item.iconClass,
175
+ memTotal: item.memTotal,
176
+ children: item.valueString
177
+ }), index < statusItems.length - 1 && /*#__PURE__*/jsx(Divider, {
178
+ type: "vertical"
179
+ })]
180
+ }, item.title))
132
181
  });
133
182
  }, [ps_status]);
134
183
  };
@@ -703,7 +752,7 @@ const PopoverContent = /*#__PURE__*/forwardRef((_ref, ref) => {
703
752
  },
704
753
  autoFocus: true
705
754
  })
706
- }), /*#__PURE__*/jsxs(Flex, {
755
+ }), /*#__PURE__*/jsxs(Flex$1, {
707
756
  justify: "flex-end",
708
757
  gap: "small",
709
758
  children: [/*#__PURE__*/jsx(Button, {
@@ -840,7 +889,7 @@ const TreeTitleNode = _ref2 => {
840
889
  className: "iconfont icon-bianji"
841
890
  })
842
891
  }), /*#__PURE__*/jsx(Popconfirm, {
843
- title: "Confirm to delete?",
892
+ title: "Confirm deletion?",
844
893
  onConfirm: () => handleDel(nodeData),
845
894
  okText: "Yes",
846
895
  cancelText: "No",
@@ -3347,7 +3396,7 @@ const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
3347
3396
  };
3348
3397
  });
3349
3398
  }, [initialSelected, isEditing, hasCategoryList, fields.category_list]);
3350
- return /*#__PURE__*/jsxs(Flex, {
3399
+ return /*#__PURE__*/jsxs(Flex$1, {
3351
3400
  vertical: true,
3352
3401
  className: "h-full",
3353
3402
  children: [/*#__PURE__*/jsxs(Form, {
@@ -3637,7 +3686,7 @@ const Preset = _ref => {
3637
3686
  saveButton: texts.saveButton
3638
3687
  },
3639
3688
  presetChanged: presetChanged
3640
- }) : /*#__PURE__*/jsx(Flex, {
3689
+ }) : /*#__PURE__*/jsx(Flex$1, {
3641
3690
  vertical: true,
3642
3691
  justify: "center",
3643
3692
  align: "center",