index.vue 4.3 KB

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