index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <div class="p-10px device-manager-box">
  4. <!-- 配置预警设备 -->
  5. <a-button class="vent-margin-b-5 mr-5px" type="primary" @click="handleDisplay()">批量下发</a-button>
  6. <a-popconfirm title="停止播放" @confirm="handleStop()">
  7. <a-button class="vent-margin-b-5 mr-5px" type="primary">批量停止</a-button>
  8. </a-popconfirm>
  9. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  10. <template #operation="{ record }">
  11. <a class="action-link" @click="handleChange(record)">切换节目</a>
  12. <a class="action-link ml-10px" @click="handleDisplay(record)">下发</a>
  13. <a-popconfirm title="停止播放" @confirm="handleStop(record)">
  14. <a class="action-link ml-10px">停止播放</a>
  15. </a-popconfirm>
  16. </template>
  17. </BasicTable>
  18. <BasicModal title="节目表单" @register="register1" @ok="onSubmit1">
  19. <BasicForm @register="registerForm1" />
  20. </BasicModal>
  21. <BasicModal title="下发内容表单" @register="register2" @ok="onSubmit2">
  22. <BasicForm @register="registerForm2" />
  23. </BasicModal>
  24. </div>
  25. </template>
  26. <script lang="ts" setup>
  27. import { onMounted, nextTick } from 'vue';
  28. import { programSchema, displaySchema } from './led.data';
  29. // import BaseModal from './BaseModal.vue';
  30. import { message } from 'ant-design-vue';
  31. import { BasicForm, useForm } from '/@/components/Form';
  32. import { BasicModal, useModal } from '/@/components/Modal';
  33. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  34. import { BasicTable } from '/@/components/Table';
  35. import { useListPage } from '/@/hooks/system/useListPage';
  36. import { changeProgram, inputDisplay, list, stopVoice } from './led.api';
  37. import { get } from 'lodash-es';
  38. /** 等待操作的led屏幕列表 */
  39. let ledList: any[] = [];
  40. const [register1, modalContext1] = useModal();
  41. const [register2, modalContext2] = useModal();
  42. const [registerForm1, formContext1] = useForm({
  43. schemas: programSchema,
  44. showActionButtonGroup: false,
  45. });
  46. const [registerForm2, formContext2] = useForm({
  47. schemas: displaySchema,
  48. showActionButtonGroup: false,
  49. });
  50. const { tableContext } = useListPage({
  51. tableProps: {
  52. api: list,
  53. showActionColumn: true,
  54. actionColumn: {
  55. dataIndex: 'operation',
  56. title: '操作',
  57. width: 120,
  58. slots: { customRender: 'operation' },
  59. },
  60. rowSelection: { type: 'checkbox' },
  61. useSearchForm: false,
  62. title: 'LED列表',
  63. },
  64. });
  65. const [registerTable, { setColumns, reload, getSelectRows }, { rowSelection }] = tableContext;
  66. /** 切换节目 */
  67. function handleChange(record) {
  68. modalContext1.openModal();
  69. nextTick(() => {
  70. formContext1.setFieldsValue({
  71. deviceId: record.deviceId,
  72. id: record.other1,
  73. });
  74. // 根据每个显示屏的节目初始化节目下拉框
  75. formContext1.updateSchema({
  76. field: 'id',
  77. componentProps: {
  78. options: get(record, 'programList', []).map((e) => {
  79. return {
  80. value: e.id,
  81. label: e.programName,
  82. programType: e.programType,
  83. };
  84. }),
  85. },
  86. });
  87. });
  88. }
  89. async function onSubmit1() {
  90. await formContext1.validateFields();
  91. const values = formContext1.getFieldsValue();
  92. await changeProgram(values);
  93. reload();
  94. modalContext1.closeModal();
  95. }
  96. /** 内容下发 */
  97. function handleDisplay(record?: any) {
  98. if (record) {
  99. ledList = [record];
  100. modalContext2.openModal();
  101. nextTick(() => {
  102. formContext2.setFieldsValue(record);
  103. });
  104. } else {
  105. const selection = getSelectRows();
  106. if (!selection.length) return message.info('未选择项目');
  107. ledList = selection;
  108. modalContext2.openModal();
  109. nextTick(() => {
  110. formContext2.resetFields();
  111. });
  112. }
  113. }
  114. async function onSubmit2() {
  115. await formContext2.validateFields();
  116. const values = formContext2.getFieldsValue();
  117. inputDisplay({
  118. deviceIdList: ledList.map((e) => e.deviceId), //设备id,可以传多个
  119. ...values,
  120. });
  121. reload();
  122. modalContext2.closeModal();
  123. }
  124. /** 停止播放 */
  125. function handleStop(record?: any) {
  126. if (record) {
  127. ledList = [record];
  128. } else {
  129. const selection = getSelectRows();
  130. if (!selection.length) return message.info('未选择项目');
  131. ledList = selection;
  132. }
  133. stopVoice(ledList.map((e) => e.deviceId));
  134. }
  135. onMounted(async () => {
  136. setColumns(getTableHeaderColumns(`led_list`));
  137. });
  138. </script>