nitrogenBtnList.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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" :checked="btn.isRunning"></a-radio>
  7. <span class="radio-text">
  8. {{ btn.isRunning ? '开启' : '关闭' }}
  9. </span>
  10. </div>
  11. </div>
  12. </div>
  13. <ConfirmModal v-model:visible="modalVisible" @handleCancel="handleCancel" @handleConfirm="handleConfirm" class="btn-confirm-modal"> </ConfirmModal>
  14. </template>
  15. <script setup lang="ts">
  16. import ConfirmModal from '@/views/vent/gas/components/modal/confirmModal1.vue';
  17. import { ref, inject } from 'vue';
  18. import { InputPassword } from 'ant-design-vue';
  19. let props = defineProps({
  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 (password) => {
  54. try {
  55. // 1. 这里写你的密码校验逻辑(比如调用接口、本地验证等)
  56. console.log('用户输入的密码:', password);
  57. console.log('控制按钮信息', currentButton.value);
  58. // 接口请求
  59. await new Promise((resolve) => setTimeout(resolve, 500));
  60. // 2. 密码验证成功的逻辑
  61. if (password === '123456') {
  62. console.log('密码验证成功!');
  63. } else {
  64. // 抛出错误,让子组件捕获并显示错误提示
  65. throw new Error('密码错误,请重新输入');
  66. }
  67. } catch (error) {
  68. // 4. 捕获验证过程中的错误,返回false阻止弹窗关闭
  69. console.error('密码验证失败:', error.message);
  70. // 返回false,子组件会保持打开状态并显示错误信息
  71. return false;
  72. }
  73. };
  74. /**
  75. * 处理弹窗取消回调
  76. */
  77. const handleCancel = () => {
  78. console.log('关闭弹窗');
  79. password.value = '';
  80. inputWarn.value = '';
  81. modalVisible.value = false;
  82. };
  83. </script>
  84. <style lang="less" scoped>
  85. @font-face {
  86. font-family: 'douyuFont';
  87. src: url('../../../../assets/font/douyuFont.otf');
  88. }
  89. /* 外层容器:适配多按钮组的布局(网格/横向排列可选) */
  90. .buttons-wrapper {
  91. display: flex;
  92. flex-wrap: wrap;
  93. justify-content: center;
  94. margin-top: 10px;
  95. }
  96. /* 单个按钮组容器 */
  97. .button-group-container {
  98. height: 80px;
  99. width: 28%;
  100. margin: 6px;
  101. text-align: center;
  102. display: flex;
  103. flex-direction: column;
  104. }
  105. .blue-item {
  106. background: url('/@/assets/images/home-container/configurable/blueBtn.png') no-repeat;
  107. background-size: 100% 100%;
  108. .button-name {
  109. margin-top: 18px;
  110. color: #05beee;
  111. font-family: 'douyuFont';
  112. font-size: 12px;
  113. }
  114. }
  115. .green-item {
  116. background: url('/@/assets/images/home-container/configurable/greenBtn.png') no-repeat;
  117. background-size: 100% 100%;
  118. .button-name {
  119. margin-top: 18px;
  120. color: #2bfedc;
  121. font-family: 'douyuFont';
  122. font-size: 12px;
  123. }
  124. }
  125. .radio-card {
  126. display: flex;
  127. align-items: center;
  128. cursor: pointer;
  129. cursor: pointer;
  130. margin-left: 27px;
  131. margin-top: 5px;
  132. }
  133. .radio-dot {
  134. margin-left: 10px;
  135. margin-right: 5px;
  136. }
  137. .radio-text {
  138. color: #fff;
  139. font-size: 12px;
  140. }
  141. .radio-dot input {
  142. display: none;
  143. }
  144. .btn-confirm-modal {
  145. .zxm-modal-content {
  146. height: 240px !important;
  147. .zxm-modal-body {
  148. height: 187px !important;
  149. padding-top: 33px !important;
  150. }
  151. .zxm-modal-footer {
  152. text-align: center;
  153. }
  154. }
  155. }
  156. .pswInput {
  157. margin-top: 55px;
  158. width: 50%;
  159. margin-left: 25% !important;
  160. }
  161. .warn-text {
  162. color: red;
  163. font-size: 15px;
  164. }
  165. </style>