nitrogenBtnList.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="buttons-wrapper">
  3. <div class="button-group-container" v-for="(btn, index) in buttonList" :key="index" :class="index % 2 === 0 ? 'green-item' : 'blue-item'">
  4. <div class="button-name">{{ btn.label }}</div>
  5. <div class="radio-card" @click="toggleStatus(btn, index)">
  6. <a-radio class="radio-dot" v-model="btn.value" :value="true"></a-radio>
  7. </div>
  8. </div>
  9. </div>
  10. <ConfirmModal v-model:visible="modalVisible" @cancel="handleCancel" @confirm="handleConfirm" class="btn-confirm-modal"> </ConfirmModal>
  11. </template>
  12. <script setup lang="ts">
  13. import ConfirmModal from '@/views/vent/gas/components/modal/confirmModal1.vue';
  14. import { ref, inject, onMounted } from 'vue';
  15. import { InputPassword, message } from 'ant-design-vue';
  16. import { deviceControlApi } from '/@/api/vent/index';
  17. const globalConfig = inject<any>('globalConfig');
  18. let props = defineProps({
  19. data: Object,
  20. buttonList: {
  21. type: Array,
  22. default: () => {
  23. return [];
  24. },
  25. },
  26. });
  27. // 定义按钮项的类型
  28. interface ButtonItem {
  29. isShowInput: boolean;
  30. inputContent: string;
  31. inputValue: string | number;
  32. value: string | number;
  33. label: string;
  34. content: string;
  35. }
  36. const password = ref('');
  37. const inputWarn = ref('密码错误请重新输入');
  38. const modalVisible = ref(false);
  39. const currentButton = ref({}); // 记录当前点击的按钮
  40. const toggleStatus = (btn: ButtonItem, index) => {
  41. modalVisible.value = !modalVisible.value;
  42. console.log(btn, '按钮信息');
  43. currentButton.value = btn;
  44. };
  45. // 注入祖父组件提供的处理函数
  46. const handleButtonConfirm = inject<(button: ButtonItem) => void>(
  47. 'handleButtonConfirm',
  48. () => console.warn('未提供handleButtonConfirm函数') // 默认值,避免报错
  49. );
  50. /**
  51. * 处理密码确认回调
  52. */
  53. const handleConfirm = async (inputPassword: string) => {
  54. try {
  55. const data = {
  56. paramcode: currentButton.value.value,
  57. password: inputPassword || globalConfig?.simulatedPassword,
  58. devicetype: props.data.deviceType,
  59. value: !currentButton.value.value,
  60. deviceid: props.data.deviceID,
  61. };
  62. deviceControlApi(data).then((res) => {
  63. if (res.success) {
  64. message.success('指令已下发成功!');
  65. } else {
  66. message.error(res.message);
  67. }
  68. modalVisible.value = false;
  69. });
  70. currentButton.value.value = !currentButton.value.value;
  71. message.success('操作成功');
  72. modalVisible.value = false; // 关闭弹窗
  73. return true;
  74. } catch (err: any) {
  75. message.error(err.message);
  76. return false; // 保持弹窗打开
  77. }
  78. };
  79. /**
  80. * 处理弹窗取消回调
  81. */
  82. const handleCancel = () => {
  83. console.log('关闭弹窗');
  84. password.value = '';
  85. inputWarn.value = '';
  86. modalVisible.value = false;
  87. };
  88. onMounted(() => {});
  89. </script>
  90. <style lang="less" scoped>
  91. @font-face {
  92. font-family: 'douyuFont';
  93. src: url('../../../../assets/font/douyuFont.otf');
  94. }
  95. /* 外层容器:适配多按钮组的布局(网格/横向排列可选) */
  96. .buttons-wrapper {
  97. display: flex;
  98. flex-wrap: wrap;
  99. justify-content: center;
  100. margin-top: 10px;
  101. }
  102. /* 单个按钮组容器 */
  103. .button-group-container {
  104. height: 80px;
  105. width: 28%;
  106. margin: 6px;
  107. text-align: center;
  108. display: flex;
  109. flex-direction: column;
  110. }
  111. .blue-item {
  112. background: url('/@/assets/images/home-container/configurable/blueBtn.png') no-repeat;
  113. background-size: 100% 100%;
  114. .button-name {
  115. margin-top: 18px;
  116. color: #05beee;
  117. font-family: 'douyuFont';
  118. font-size: 12px;
  119. }
  120. }
  121. .green-item {
  122. background: url('/@/assets/images/home-container/configurable/greenBtn.png') no-repeat;
  123. background-size: 100% 100%;
  124. .button-name {
  125. margin-top: 18px;
  126. color: #2bfedc;
  127. font-family: 'douyuFont';
  128. font-size: 12px;
  129. }
  130. }
  131. .radio-card {
  132. display: flex;
  133. align-items: center;
  134. cursor: pointer;
  135. cursor: pointer;
  136. margin-left: 27px;
  137. margin-top: 5px;
  138. }
  139. .radio-dot {
  140. margin-left: 30px;
  141. margin-right: 5px;
  142. }
  143. .radio-text {
  144. color: #fff;
  145. font-size: 12px;
  146. }
  147. .radio-dot input {
  148. display: none;
  149. }
  150. .btn-confirm-modal {
  151. .zxm-modal-content {
  152. height: 240px !important;
  153. .zxm-modal-body {
  154. height: 187px !important;
  155. padding-top: 33px !important;
  156. }
  157. .zxm-modal-footer {
  158. text-align: center;
  159. }
  160. }
  161. }
  162. .pswInput {
  163. margin-top: 55px;
  164. width: 50%;
  165. margin-left: 25% !important;
  166. }
  167. .warn-text {
  168. color: red;
  169. font-size: 15px;
  170. }
  171. </style>