Skip to content

Commit

Permalink
perf(web): 实时告警支持页面表格颜色展示,按钮可控
Browse files Browse the repository at this point in the history
  • Loading branch information
梧桐 committed Apr 1, 2024
1 parent 7833c85 commit f8a4eff
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
4 changes: 3 additions & 1 deletion web/src/apis/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ export enum ActionKey {
/** 测试告警模板 */
TEST_ALARM_TEMPLATE = '__test_alarm_template__',
/** 绑定通知模板 */
STRATEGY_BIND_NOTIFY_TEMPLATE = '__strategy_bind_notify_template__'
STRATEGY_BIND_NOTIFY_TEMPLATE = '__strategy_bind_notify_template__',
/** 展示告警行颜色 */
ALARM_ROW_COLOR = '__alarm_row_color__'
}

export {
Expand Down
2 changes: 2 additions & 0 deletions web/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type GlobalContextType = {
redirectPathName?: string
setRedirectPathName?: (redirectPathName: string) => void
ws?: WebSocket
reltimeAlarmShowRowColor?: boolean
setReltimeAlarmShowRowColor?: (reltimeAlarmShowRowColor: boolean) => void
}

export const GlobalContext = createContext<GlobalContextType>({
Expand Down
53 changes: 31 additions & 22 deletions web/src/pages/home/monitor/alarm-realtime/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const article = '默认展示告警时间前一小时到告警恢复时间段内
let fetchTimer: NodeJS.Timeout | null = null
const AlarmRealtime: FC = () => {
const [queryForm] = Form.useForm()
const { size } = useContext(GlobalContext)
const { size, reltimeAlarmShowRowColor, setReltimeAlarmShowRowColor } =
useContext(GlobalContext)

const [alarmPageList, setAlarmPageList] = useState<DictListItem[]>([])
const [dataSource, setDataSource] = useState<AlarmRealtimeItem[]>([])
Expand Down Expand Up @@ -99,17 +100,14 @@ const AlarmRealtime: FC = () => {
if (alarmPageIds.length === 0) {
return
}
const params = queryParams
if (!params.alarmPageId) {
params.alarmPageId = alarmPageIds[0]
}

if (fetchTimer) {
clearTimeout(fetchTimer)
}
fetchTimer = setTimeout(() => {
setLoading(true)
alarmRealtimeApi
.getAlarmRealtimeList({ ...params })
.getAlarmRealtimeList({ ...queryParams })
.then((res) => {
setDataSource(res.list)
setTotal(res.page.total)
Expand All @@ -128,9 +126,8 @@ const AlarmRealtime: FC = () => {
setLoading(true)
setQueryParams({
...queryParams,
alarmPageId: +key || 1
alarmPageId: +key
})
handleRefresh()
}

const buildTabsItems = () => {
Expand Down Expand Up @@ -169,6 +166,11 @@ const AlarmRealtime: FC = () => {
case ActionKey.RESET:
setQueryParams(defaultAlarmRealtimeListRequest)
break
case ActionKey.ALARM_ROW_COLOR:
setReltimeAlarmShowRowColor?.(!reltimeAlarmShowRowColor)
break
default:
break
}
}

Expand Down Expand Up @@ -228,27 +230,31 @@ const AlarmRealtime: FC = () => {
}
delete requestValues.eventAt
setQueryParams(requestValues)
handleRefresh()
}

// const onRow = (record?: AlarmRealtimeItem) => {
// if (!record || !record.level) return {}
// const {
// level: { color }
// } = record
// return {
// style: {
// background: color || ''
// }
// }
// }
const onRow = (record?: AlarmRealtimeItem) => {
if (!record || !record.level || !reltimeAlarmShowRowColor) return {}
const {
level: { color }
} = record
return {
style: {
background: color || ''
}
}
}

useEffect(() => {
handleRefresh()
}, [queryParams])

useEffect(() => {
handleCountAlarmByPageIds()
const params = queryParams
if (!params.alarmPageId) {
params.alarmPageId = alarmPageIds[0]
setQueryParams(params)
}
}, [alarmPageIds])

useEffect(() => {
Expand Down Expand Up @@ -304,7 +310,10 @@ const AlarmRealtime: FC = () => {
<HeightLine />
<DataOption
queryForm={queryForm}
rightOptions={rightOptions(handleGetAlarmPageList)}
rightOptions={rightOptions({
refresh: handleGetAlarmPageList,
reltimeAlarmShowRowColor: reltimeAlarmShowRowColor
})}
action={handleOptionClick}
// showAdd={false}
/>
Expand All @@ -327,7 +336,7 @@ const AlarmRealtime: FC = () => {
loading={loading}
operationItems={operationItems}
action={handlerTableAction}
// onRow={onRow}
onRow={onRow}
pageSize={queryParams?.page?.size}
current={queryParams?.page?.curr}
/>
Expand Down
26 changes: 23 additions & 3 deletions web/src/pages/home/monitor/alarm-realtime/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DictSelectItem } from '@/apis/home/system/dict/types'
import { Map } from '@/apis/types'
import { DataOptionItem } from '@/components/Data/DataOption/DataOption'
// import { IconFont } from '@/components/IconFont/IconFont'
import { Badge, Button, MenuProps, Tooltip } from 'antd'
import { Badge, Button, MenuProps, Space, Switch, Tooltip } from 'antd'
import { ColumnGroupProps } from 'antd/es/table/ColumnGroup'
import dayjs from 'dayjs'
import { SelectAalrmPageModal } from './child/SelectAlarmPageModal'
Expand Down Expand Up @@ -146,14 +146,34 @@ export const searchFormItems: SearchFormItem[] = [
}
]

export const rightOptions = (refresh: () => void): DataOptionItem[] => [
export type refreshHandleFun = () => void

export type rightOptionsType = {
refresh: refreshHandleFun
reltimeAlarmShowRowColor?: boolean
}

export const rightOptions = (params: rightOptionsType): DataOptionItem[] => [
{
label: (
<Space>
告警行颜色:
<Switch
checked={params?.reltimeAlarmShowRowColor}
checkedChildren="开"
unCheckedChildren="关"
/>
</Space>
),
key: ActionKey.ALARM_ROW_COLOR
},
{
key: ActionKey.REFRESH,
label: <Button type="primary">刷新</Button>
},
{
key: ActionKey.BIND_MY_ALARM_PAGES,
label: <SelectAalrmPageModal refresh={refresh} />
label: <SelectAalrmPageModal refresh={params.refresh} />
}
]

Expand Down
8 changes: 7 additions & 1 deletion web/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const Index: React.FC = () => {
'redirectPathName',
''
)
const [reltimeAlarmShowRowColor, setReltimeAlarmShowRowColor] = useStorage(
'reltimeAlarmShowRowColor',
false
)
const [sysTheme, setSysTheme] = useStorage<ThemeType>('theme', 'light')
const [intervalId, setIntervalId] = useState<any>()
const [ws] = useState(createWebSocket(getWsURL()))
Expand All @@ -84,7 +88,9 @@ const Index: React.FC = () => {
setSysTheme: setSysTheme,
redirectPathName: redirectPathName,
setRedirectPathName: setRedirectPathName,
ws: ws
ws: ws,
reltimeAlarmShowRowColor: reltimeAlarmShowRowColor,
setReltimeAlarmShowRowColor: setReltimeAlarmShowRowColor
}

return (
Expand Down

0 comments on commit f8a4eff

Please sign in to comment.