Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6636068b
authored
Mar 05, 2025
by
dylanmay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 设备配置接口对接
parent
c65c056c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
20 deletions
+60
-20
src/views/iot/device/device/detail/DeviceDetailConfig.vue
+58
-18
src/views/iot/device/device/detail/index.vue
+2
-2
No files found.
src/views/iot/device/device/detail/DeviceDetailConfig.vue
View file @
6636068b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
<Vue3Jsoneditor
<Vue3Jsoneditor
ref=
"editor"
ref=
"editor"
v-if=
"isEditing"
v-if=
"isEditing"
v-model=
"deviceConfig"
v-model=
"deviceConfig
State
"
:options=
"editorOptions"
:options=
"editorOptions"
height=
"500px"
height=
"500px"
currentMode=
"code"
currentMode=
"code"
...
@@ -23,13 +23,14 @@
...
@@ -23,13 +23,14 @@
<Vue3Jsoneditor
<Vue3Jsoneditor
ref=
"editor"
ref=
"editor"
v-else
v-else
v-model=
"deviceConfig"
v-model=
"deviceConfig
State
"
:options=
"editorOptions"
:options=
"editorOptions"
height=
"500px"
height=
"500px"
currentMode=
"view"
currentMode=
"view"
v-loading
.
fullscreen
.
lock=
"loading"
@
error=
"onError"
@
error=
"onError"
/>
/>
<div
class=
"
button-group
"
>
<div
class=
"
flex justify-center mt-24
"
>
<el-button
v-if=
"isEditing"
@
click=
"cancelEdit"
>
取消
</el-button>
<el-button
v-if=
"isEditing"
@
click=
"cancelEdit"
>
取消
</el-button>
<el-button
v-if=
"isEditing"
type=
"primary"
@
click=
"saveConfig"
>
保存
</el-button>
<el-button
v-if=
"isEditing"
type=
"primary"
@
click=
"saveConfig"
>
保存
</el-button>
<el-button
v-else
@
click=
"enableEdit"
>
编辑
</el-button>
<el-button
v-else
@
click=
"enableEdit"
>
编辑
</el-button>
...
@@ -39,11 +40,43 @@
...
@@ -39,11 +40,43 @@
<
script
lang=
"ts"
setup
>
<
script
lang=
"ts"
setup
>
import
{
ref
,
computed
}
from
'vue'
import
{
ref
,
computed
}
from
'vue'
// import Vue3Jsoneditor from 'v3-jsoneditor/src/Vue3Jsoneditor.vue'
import
Vue3Jsoneditor
from
'v3-jsoneditor/src/Vue3Jsoneditor.vue'
import
{
DeviceApi
}
from
'@/api/iot/device/device/index'
import
{
useTagsViewStore
}
from
'@/store/modules/tagsView'
import
{
DeviceVO
}
from
'../../../../../api/iot/device/device/index'
;
const
route
=
useRoute
()
const
message
=
useMessage
()
const
{
delView
}
=
useTagsViewStore
()
// 视图操作
const
{
currentRoute
}
=
useRouter
()
// 路由
const
id
=
Number
(
route
.
params
.
id
)
// 将字符串转换为数字
const
loading
=
ref
(
true
)
// 加载中
const
deviceConfigState
=
ref
({})
// 设置配置
// 获取设备配置
const
getDeviceConfig
=
async
(
id
:
number
)
=>
{
try
{
loading
.
value
=
true
const
res
=
await
DeviceApi
.
getDevice
(
id
)
deviceConfigState
.
value
=
res
}
catch
(
error
)
{
console
.
error
(
error
)
}
finally
{
loading
.
value
=
false
}
}
onMounted
(
async
()
=>
{
if
(
!
id
)
{
message
.
warning
(
'参数错误,产品不能为空!'
)
delView
(
unref
(
currentRoute
))
return
}
await
getDeviceConfig
(
id
)
})
const
deviceConfig
=
ref
({
name
:
'dyla1n'
})
// 定义设备配置 TODO @dylan:从后端读取
const
isEditing
=
ref
(
false
)
// 编辑状态
const
isEditing
=
ref
(
false
)
// 编辑状态
const
editorOptions
=
computed
(()
=>
({
const
editorOptions
=
computed
(()
=>
({
mainMenuBar
:
false
,
mainMenuBar
:
false
,
...
@@ -64,23 +97,30 @@ const cancelEdit = () => {
...
@@ -64,23 +97,30 @@ const cancelEdit = () => {
}
}
/** 保存配置的函数 */
/** 保存配置的函数 */
const
saveConfig
=
()
=>
{
const
saveConfig
=
async
()
=>
{
const
params
=
{
...
deviceConfigState
.
value
}
as
DeviceVO
await
updateDeviceConfig
(
params
)
isEditing
.
value
=
false
isEditing
.
value
=
false
// 逻辑代码
console
.
log
(
'保存配置'
)
}
}
/** 处理 JSON 编辑器错误的函数 */
/** 处理 JSON 编辑器错误的函数 */
const
onError
=
(
e
:
any
)
=>
{
const
onError
=
(
e
:
any
)
=>
{
console
.
log
(
'onError'
,
e
)
console
.
log
(
'onError'
,
e
)
}
}
</
script
>
<!-- TODO dylan:建议使用 unocss 替代哈,AI 模型友好 -->
// 更新设备配置
<
style
scoped
>
const
updateDeviceConfig
=
async
(
params
:
DeviceVO
)
=>
{
.button-group
{
try
{
display
:
flex
;
loading
.
value
=
true
justify-content
:
center
;
await
DeviceApi
.
updateDevice
(
params
)
margin-top
:
20px
;
await
getDeviceConfig
(
id
)
message
.
success
(
'更新成功!'
)
}
catch
(
error
)
{
console
.
error
(
error
)
}
finally
{
loading
.
value
=
false
}
}
}
</
s
tyle
>
</
s
cript
>
src/views/iot/device/device/detail/index.vue
View file @
6636068b
...
@@ -26,9 +26,9 @@
...
@@ -26,9 +26,9 @@
:device=
"device"
:device=
"device"
/>
/>
</el-tab-pane>
</el-tab-pane>
<
!--
<
el-tab-pane
label=
"设备配置"
name=
"config"
>
<el-tab-pane
label=
"设备配置"
name=
"config"
>
<DeviceDetailConfig
/>
<DeviceDetailConfig
/>
</el-tab-pane>
-->
</el-tab-pane>
</el-tabs>
</el-tabs>
</el-col>
</el-col>
</
template
>
</
template
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment