ффффффффффикс
This commit is contained in:
parent
b3b0bd2190
commit
abbdfb41f2
1 changed files with 54 additions and 34 deletions
|
|
@ -28,7 +28,7 @@ import type { ColumnsType } from 'antd/es/table'
|
|||
import dayjs from 'dayjs'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import 'dayjs/locale/ru'
|
||||
import { useMemo, useCallback, useRef, useState } from 'react'
|
||||
import { useMemo, useState } from 'react'
|
||||
import {
|
||||
useSnapshotDashboard,
|
||||
useSnapshotPolicies,
|
||||
|
|
@ -486,6 +486,31 @@ function ObjectDevicesExpanded({
|
|||
)
|
||||
}
|
||||
|
||||
function highlightIni(text: string): React.ReactNode[] {
|
||||
return text.split('\n').map((line, i) => {
|
||||
let node: React.ReactNode
|
||||
if (/^\s*[#;]/.test(line)) {
|
||||
node = <span style={{ color: '#6a9955' }}>{line}</span>
|
||||
} else if (/^\s*\[.+\]/.test(line)) {
|
||||
node = <span style={{ color: '#ce9178', fontWeight: 600 }}>{line}</span>
|
||||
} else if (line.includes('=')) {
|
||||
const eqIdx = line.indexOf('=')
|
||||
const key = line.slice(0, eqIdx)
|
||||
const value = line.slice(eqIdx)
|
||||
node = (
|
||||
<>
|
||||
<span style={{ color: '#9cdcfe' }}>{key}</span>
|
||||
<span style={{ color: '#d4d4d4' }}>{value.charAt(0)}</span>
|
||||
<span style={{ color: '#dcdcaa' }}>{value.slice(1)}</span>
|
||||
</>
|
||||
)
|
||||
} else {
|
||||
node = <span>{line}</span>
|
||||
}
|
||||
return <span key={i}>{node}{'\n'}</span>
|
||||
})
|
||||
}
|
||||
|
||||
function DevicesList({
|
||||
objId,
|
||||
objName,
|
||||
|
|
@ -498,7 +523,6 @@ function DevicesList({
|
|||
const { data: devices, isLoading } = useDashboardDevices(objId, policyId, true)
|
||||
const [viewContent, setViewContent] = useState<string | null>(null)
|
||||
const [viewTitle, setViewTitle] = useState('')
|
||||
const contentRef = useRef<HTMLPreElement>(null)
|
||||
|
||||
const handleCopy = async (snapshotId: number) => {
|
||||
try {
|
||||
|
|
@ -537,18 +561,12 @@ function DevicesList({
|
|||
}
|
||||
}
|
||||
|
||||
const handleSelectAll = useCallback((e: React.KeyboardEvent) => {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
|
||||
e.preventDefault()
|
||||
if (contentRef.current) {
|
||||
const range = document.createRange()
|
||||
range.selectNodeContents(contentRef.current)
|
||||
const sel = window.getSelection()
|
||||
sel?.removeAllRanges()
|
||||
sel?.addRange(range)
|
||||
}
|
||||
const handleViewCopy = async () => {
|
||||
if (viewContent) {
|
||||
await navigator.clipboard.writeText(viewContent)
|
||||
message.success('Скопировано в буфер обмена')
|
||||
}
|
||||
}, [])
|
||||
}
|
||||
|
||||
if (isLoading) return <Typography.Text type="secondary">Загрузка...</Typography.Text>
|
||||
if (!devices || devices.length === 0) return <Typography.Text type="secondary">Нет устройств</Typography.Text>
|
||||
|
|
@ -637,31 +655,33 @@ function DevicesList({
|
|||
title={viewTitle}
|
||||
open={viewContent !== null}
|
||||
onCancel={() => setViewContent(null)}
|
||||
footer={null}
|
||||
footer={
|
||||
<Button icon={<CopyOutlined />} onClick={handleViewCopy}>
|
||||
Скопировать
|
||||
</Button>
|
||||
}
|
||||
width={800}
|
||||
maskClosable
|
||||
destroyOnClose
|
||||
>
|
||||
<div onKeyDown={handleSelectAll} tabIndex={0} style={{ outline: 'none' }}>
|
||||
<pre
|
||||
ref={contentRef}
|
||||
style={{
|
||||
background: '#1e1e1e',
|
||||
color: '#d4d4d4',
|
||||
padding: 16,
|
||||
borderRadius: 6,
|
||||
fontSize: 12,
|
||||
lineHeight: 1.5,
|
||||
maxHeight: '70vh',
|
||||
overflow: 'auto',
|
||||
whiteSpace: 'pre-wrap',
|
||||
wordBreak: 'break-all',
|
||||
margin: 0,
|
||||
}}
|
||||
>
|
||||
{viewContent}
|
||||
</pre>
|
||||
</div>
|
||||
<pre
|
||||
style={{
|
||||
background: '#1e1e1e',
|
||||
color: '#d4d4d4',
|
||||
padding: 16,
|
||||
borderRadius: 6,
|
||||
fontSize: 12,
|
||||
lineHeight: 1.5,
|
||||
maxHeight: '70vh',
|
||||
overflow: 'auto',
|
||||
whiteSpace: 'pre-wrap',
|
||||
wordBreak: 'break-all',
|
||||
margin: 0,
|
||||
fontFamily: "'Consolas', 'Monaco', 'Courier New', monospace",
|
||||
}}
|
||||
>
|
||||
{viewContent && highlightIni(viewContent)}
|
||||
</pre>
|
||||
</Modal>
|
||||
</>
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue