function.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="device-function">
  3. <el-tabs tab-position="left">
  4. <el-tab-pane :label="item.name" v-for="item in list" :key="item.key">
  5. <div class="table-wrapper">
  6. <el-table :data="item.inputs || []" border>
  7. <el-table-column prop="name" label="参数名称" />
  8. <el-table-column prop="valueType.type" label="输入类型" />
  9. <el-table-column prop="name" label="值" min-width="200">
  10. <template #default="{ row }">
  11. <el-input v-model="row.value" clearable>
  12. <template v-if="row.valueType.unit" #append>{{ row.valueType.unit }}</template>
  13. </el-input>
  14. </template>
  15. </el-table-column>
  16. </el-table>
  17. <el-input type="textarea" :value="item.result" class="result"> </el-input>
  18. </div>
  19. <div class="btn">
  20. <el-button type="primary" :loading="item.loading" @click="run(item)">执行</el-button>
  21. <el-button @click="clear(item)">清空</el-button>
  22. </div>
  23. </el-tab-pane>
  24. </el-tabs>
  25. </div>
  26. </template>
  27. <script setup lang="ts">
  28. import { ref } from 'vue'
  29. import { ElMessage } from 'element-plus'
  30. import api from '/@/api/device'
  31. const props = defineProps({
  32. productKey: String,
  33. deviceKey: String,
  34. })
  35. interface IListItem {
  36. key: string
  37. name: string
  38. inputs: any[]
  39. result: string
  40. loading: boolean
  41. }
  42. const list = ref<IListItem[]>([])
  43. api.tabDeviceFucntion.getList({ key: props.productKey }).then((res: IListItem[]) => {
  44. res.forEach((item) => (item.result = ''))
  45. list.value = res
  46. })
  47. function run(row: IListItem) {
  48. row.result = ''
  49. const notValid = row.inputs.some((item) => !item.value)
  50. if (notValid) return ElMessage.info('请输入完整参数')
  51. row.loading = true
  52. const params: any = {}
  53. row.inputs.forEach(({ key, value }) => (params[key] = value))
  54. api.tabDeviceFucntion
  55. .do({
  56. deviceKey: props.deviceKey,
  57. funcKey: row.key,
  58. params,
  59. })
  60. .then((res: any) => {
  61. // console.log(res)
  62. row.result = JSON.stringify(res, null, 2)
  63. })
  64. .finally(() => (row.loading = false))
  65. }
  66. function clear(row: IListItem) {
  67. row.result = ''
  68. }
  69. </script>
  70. <style scoped lang="scss">
  71. .table-wrapper {
  72. width: 100%;
  73. padding: 10px;
  74. display: flex;
  75. align-items: stretch;
  76. justify-content: space-between;
  77. gap: 20px;
  78. .el-table {
  79. flex: 3;
  80. }
  81. .result {
  82. flex: 2;
  83. }
  84. ::v-deep(.el-textarea__inner) {
  85. height: 100%;
  86. }
  87. }
  88. </style>