import React from 'react';
import { app, use } from 'xadmin';
const TestComponent = () => {
return <a>hello world</a >
}
const TestButton = () => {
const [state, setState] = React.useState('')
const { user } = use('auth.user')
const userToken = user?.token
const userName = user?.username
const { onData, subscribe } = use('ws')
onData(data => {
setState(`${data.tableData?.name}:${data.desc}`)
})
React.useEffect(() => {
const where = {
"tableDataSetting": [
{ "table": { "id": "sbb1" }, "selectRecord": [{ "id": "bjsb" }] },
{ "table": { "id": "cj" }, "selectRecord": [{ "id": "33" }] },
]
}
return subscribe('warning', {})
}, [])
return (
<>
<p>当前用户:{userName}</p >
<p>{state}</p >
</>
)
}
const TestWidget = {
title: '测试按钮',
category: ['通用组件', '自定义组件'],
component: TestButton,
initLayout: { width: 40, height: 20 },
}
app.use({
name: 'airiot.test',
routers: {
'/app/': {
path: 'myTest',
breadcrumbName: '我的测试组件页',
component: TestComponent
},
},
dashboardWidgets: {
'test.widget': TestWidget
}
})