index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. import { getAutoScrollContainer } from '/@/utils/common/compUtils';
  30. const { currentRoute } = useRouter();
  31. const formSchema = ref<FormSchema[]>([]);
  32. const isRefresh = ref(false);
  33. const deviceType = ref('');
  34. const columns = ref<any[]>([]);
  35. const arrToFormColumns = (tableHeaderColumns = []) => {
  36. const columnList: any[] = [];
  37. tableHeaderColumns.forEach((item: any) => {
  38. let columnsItem;
  39. if (item.type == 1 || item.type == 10) {
  40. columnsItem = {
  41. label: item.des, //_dictText
  42. field: item.monitorcode,
  43. component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
  44. };
  45. } else {
  46. if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
  47. columnsItem = {
  48. label: item.des, //_dictText
  49. field: item.monitorcode,
  50. component: 'ApiSelect',
  51. componentProps: {
  52. api: substationList,
  53. labelField: 'strname',
  54. valueField: 'id',
  55. },
  56. };
  57. }
  58. if (item.type == 3) {
  59. columnsItem = {
  60. label: item.des, //_dictText
  61. field: item.monitorcode,
  62. component: 'RadioGroup',
  63. defaultValue: 1,
  64. componentProps: () => {
  65. return {
  66. options: [
  67. { label: '是', value: 1, key: '1' },
  68. { label: '否', value: 0, key: '2' },
  69. ],
  70. stringToNumber: true,
  71. };
  72. },
  73. };
  74. }
  75. if (item.type == 4) {
  76. columnsItem = {
  77. label: item.des, //_dictText
  78. field: item.monitorcode,
  79. component: 'JDictSelectTag',
  80. componentProps: {
  81. dictCode: item.dict,
  82. placeholder: '请选择',
  83. // stringToNumber: true,
  84. },
  85. };
  86. }
  87. // date日期
  88. if (item.type == 8) {
  89. columnsItem = {
  90. label: item.des, //_dictText
  91. field: item.monitorcode,
  92. component: 'DatePicker',
  93. componentProps: {
  94. showTime: false,
  95. valueFormat: 'YYYY-MM-DD',
  96. getPopupContainer: getAutoScrollContainer,
  97. },
  98. };
  99. }
  100. // 日期+时间
  101. if (item.type == 9) {
  102. columnsItem = {
  103. label: item.des, //_dictText
  104. field: item.monitorcode,
  105. component: 'DatePicker',
  106. componentProps: {
  107. showTime: true,
  108. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  109. getPopupContainer: getAutoScrollContainer,
  110. },
  111. };
  112. }
  113. }
  114. columnList.push(columnsItem);
  115. });
  116. formSchema.value = columnList;
  117. formSchema.value.unshift(
  118. {
  119. label: '设备id', //_dictText
  120. field: 'id',
  121. component: 'Input',
  122. componentProps: {
  123. disabled: true,
  124. },
  125. },
  126. {
  127. label: '点表',
  128. field: 'strtype',
  129. component: 'JDictSelectTag',
  130. componentProps: {
  131. dictCode: `${deviceType.value}kind`,
  132. placeholder: '请选择点表',
  133. // stringToNumber: true,
  134. },
  135. }
  136. );
  137. formSchema.value.push(
  138. {
  139. label: '备用分站',
  140. field: 'stationids',
  141. component: 'ApiSelect',
  142. componentProps: {
  143. api: substationList,
  144. labelField: 'strname',
  145. valueField: 'id',
  146. },
  147. },
  148. {
  149. label: '是否显示',
  150. field: 'linkId',
  151. component: 'RadioGroup',
  152. defaultValue: 1,
  153. componentProps: () => {
  154. return {
  155. options: [
  156. { label: '是', value: 1, key: '1' },
  157. { label: '否', value: 0, key: '2' },
  158. ],
  159. stringToNumber: true,
  160. };
  161. },
  162. }
  163. );
  164. };
  165. onMounted(() => {
  166. const route = unref(currentRoute);
  167. const pageType = route.name;
  168. deviceType.value = pageType;
  169. searchFormSchema[0].componentProps['dictCode'] = `${deviceType.value}kind`;
  170. columns.value = getTableHeaderColumns(`${deviceType.value}_list`) || [];
  171. const formSchemaColumns = getFormSchemaColumns(`${deviceType.value}_edit`) || [];
  172. arrToFormColumns(formSchemaColumns);
  173. isRefresh.value = true;
  174. });
  175. </script>
  176. <style scoped></style>