index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="device-manager-box">
  3. <NormalTable
  4. v-if="isRefresh"
  5. :columns="columns"
  6. :searchFormSchema="searchFormSchema"
  7. :list="list"
  8. :formSchema="formSchema"
  9. :deleteById="deleteById"
  10. :batchDelete="batchDeleteById"
  11. :saveOrUpdate="saveOrUpdate"
  12. designScope="device-tabel"
  13. title="设备列表"
  14. :showTab="true"
  15. :deviceType="deviceType"
  16. />
  17. </div>
  18. </template>
  19. <script lang="ts" name="system-user" setup>
  20. //ts语法
  21. import { ref, onMounted, unref } from 'vue'
  22. import { FormSchema } from '/@/components/Table';
  23. import NormalTable from '../comment/NormalTable.vue';
  24. import { searchFormSchema } from './device.data';
  25. import { list, deleteById, batchDeleteById, saveOrUpdate } from './device.api';
  26. import { getFormSchemaColumns, getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  27. import { list as substationList } from '../substationTabel/substation.api';
  28. import { useRouter } from 'vue-router';
  29. const { currentRoute } = useRouter()
  30. const formSchema = ref<FormSchema[]>([])
  31. const isRefresh = ref(false)
  32. const deviceType = ref('')
  33. const columns = ref<any[]>([])
  34. const arrToFormColumns = (tableHeaderColumns = []) => {
  35. const columnList: any[] = [];
  36. tableHeaderColumns.forEach((item: any) => {
  37. let columnsItem;
  38. if (item.type == 1 || item.type == 10) {
  39. columnsItem = {
  40. label: item.unit ? `${item.des}(${item.unit})` : item.des, //_dictText
  41. field: item.monitorcode,
  42. component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
  43. };
  44. } else {
  45. if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
  46. columnsItem = {
  47. label: item.unit ? `${item.des}(${item.unit})` : item.des, //_dictText
  48. field: item.monitorcode,
  49. component: 'ApiSelect',
  50. componentProps: {
  51. api: substationList,
  52. labelField: 'strname',
  53. valueField: 'id',
  54. },
  55. };
  56. }
  57. if (item.type == 3) {
  58. columnsItem = {
  59. label: item.unit ? `${item.des}(${item.unit})` : item.des, //_dictText
  60. field: item.monitorcode,
  61. component: 'RadioGroup',
  62. defaultValue: 1,
  63. componentProps: () => {
  64. return {
  65. options: [
  66. { label: '是', value: 1, key: '1' },
  67. { label: '否', value: 0, key: '2' },
  68. ],
  69. stringToNumber: true,
  70. };
  71. },
  72. };
  73. }
  74. if (item.type == 4) {
  75. columnsItem = {
  76. label: item.unit ? `${item.des}(${item.unit})` : item.des, //_dictText
  77. field: item.monitorcode,
  78. component: 'JDictSelectTag',
  79. componentProps: {
  80. dictCode: item.dict,
  81. placeholder: '请选择',
  82. stringToNumber: true,
  83. },
  84. };
  85. }
  86. }
  87. columnList.push(columnsItem);
  88. });
  89. formSchema.value = columnList
  90. formSchema.value.unshift(
  91. {
  92. label: '设备id', //_dictText
  93. field: 'id',
  94. component: 'Input',
  95. componentProps: {
  96. disabled: true
  97. },
  98. },
  99. {
  100. label: '点表',
  101. field: 'strtype',
  102. component: 'JDictSelectTag',
  103. componentProps: {
  104. dictCode: `${deviceType.value}kind`,
  105. placeholder: '请选择点表',
  106. },
  107. }
  108. )
  109. formSchema.value.push(
  110. {
  111. label: '备用分站',
  112. field: 'stationids',
  113. component: 'ApiSelect',
  114. componentProps: {
  115. api: substationList,
  116. labelField: 'strname',
  117. valueField: 'id',
  118. },
  119. },
  120. )
  121. };
  122. onMounted(() => {
  123. const route = unref(currentRoute)
  124. const pageType = route.name
  125. deviceType.value = pageType
  126. searchFormSchema[0].componentProps['dictCode'] = `${deviceType.value}kind`
  127. columns.value = getTableHeaderColumns(`${deviceType.value}_list`) || []
  128. const formSchemaColumns = getFormSchemaColumns(`${deviceType.value}_edit`) || []
  129. arrToFormColumns(formSchemaColumns)
  130. isRefresh.value = true
  131. })
  132. </script>
  133. <style scoped></style>