index.vue 4.1 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. :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 NormalTable from '../comment/NormalTable.vue';
  23. import { list, deleteById, batchDeleteById, saveOrUpdate } from './device.api';
  24. import { list as substationList } from '../substationTabel/substation.api';
  25. import { searchFormSchema } from './device.data';
  26. import { FormSchema } from '/@/components/Table';
  27. import { getFormSchemaColumns, getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  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.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.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.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.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. // stringToNumber: true,
  107. },
  108. }
  109. )
  110. formSchema.value.push(
  111. {
  112. label: '备用分站',
  113. field: 'stationids',
  114. component: 'ApiSelect',
  115. componentProps: {
  116. api: substationList,
  117. labelField: 'strname',
  118. valueField: 'id',
  119. },
  120. },
  121. )
  122. };
  123. onMounted(() => {
  124. const route = unref(currentRoute)
  125. const pageType = route.name
  126. deviceType.value = pageType
  127. searchFormSchema[0].componentProps['dictCode'] = `${deviceType.value}kind`
  128. columns.value = getTableHeaderColumns(`${deviceType.value}_list`) || []
  129. const formSchemaColumns = getFormSchemaColumns(`${deviceType.value}_edit`) || []
  130. arrToFormColumns(formSchemaColumns)
  131. isRefresh.value = true
  132. })
  133. </script>
  134. <style scoped></style>