SetTempHumidityModal.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <script setup lang="ts">
  2. import { onMounted, ref, watch } from 'vue';
  3. import { useRequest } from '@/hooks/request';
  4. import { t } from '@/i18n';
  5. import {
  6. addBatchMonitorPointAlarm,
  7. getMonitorPointAlarm,
  8. getMonitorPointInfo,
  9. updateBatchMonitorPointAlarm,
  10. updateLimits,
  11. } from '@/api';
  12. import type { FormInstance, Rule } from 'ant-design-vue/es/form';
  13. import type { LimitForm, MonitoringPointData, WarningItem } from '@/types';
  14. const emit = defineEmits(['setClick']);
  15. interface Props {
  16. monitoringId?: number;
  17. monitoringData: MonitoringPointData[];
  18. }
  19. const { handleRequest } = useRequest();
  20. const props = defineProps<Props>();
  21. const limitOpen = ref<boolean>(false);
  22. const warningOpen = ref<boolean>(false);
  23. const warningShow = ref<boolean>(false);
  24. const formRef = ref<FormInstance>();
  25. const limitForm = ref<LimitForm>({
  26. id: undefined,
  27. regionId: undefined,
  28. tempUpper: 0,
  29. tempLower: 0,
  30. tempPreset: 0,
  31. humidityUpper: 0,
  32. humidityLower: 0,
  33. humidityPreset: 0,
  34. batch: false,
  35. });
  36. const warningList = ref<WarningItem[]>([
  37. {
  38. pointId: props.monitoringId,
  39. enabled: false,
  40. type: 1,
  41. val: 0,
  42. duration: 0,
  43. },
  44. {
  45. pointId: props.monitoringId,
  46. enabled: false,
  47. type: 2,
  48. val: 0,
  49. duration: 0,
  50. },
  51. ]);
  52. const rules: Record<string, Rule[]> = {
  53. id: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  54. tempUpper: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  55. tempLower: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  56. tempPreset: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  57. humidityUpper: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  58. humidityLower: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  59. humidityPreset: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  60. };
  61. const addLimit = () => {
  62. limitOpen.value = true;
  63. limitForm.value.batch = false;
  64. };
  65. const addWarning = () => {
  66. getMonitorPointList();
  67. warningOpen.value = true;
  68. };
  69. const getMonitorPointList = () => {
  70. handleRequest(async () => {
  71. if (props.monitoringId) {
  72. const data = await getMonitorPointAlarm(props.monitoringId);
  73. if (data.length) {
  74. warningShow.value = true;
  75. data.forEach((item, i) => {
  76. const { id, pointId, enabled, type, val, duration } = item;
  77. Object.assign(warningList.value[i], {
  78. id,
  79. pointId,
  80. enabled,
  81. type,
  82. val,
  83. duration,
  84. });
  85. });
  86. } else {
  87. warningShow.value = false;
  88. warningList.value = [
  89. {
  90. pointId: props.monitoringId,
  91. enabled: false,
  92. type: 1,
  93. val: 0,
  94. duration: 0,
  95. },
  96. {
  97. pointId: props.monitoringId,
  98. enabled: false,
  99. type: 2,
  100. val: 0,
  101. duration: 0,
  102. },
  103. ];
  104. }
  105. }
  106. });
  107. };
  108. const getLimit = () => {
  109. formRef.value
  110. ?.validate()
  111. .then(() => {
  112. handleRequest(async () => {
  113. await updateLimits(limitForm.value);
  114. getMonitorPoint();
  115. limitOpen.value = false;
  116. emit('setClick');
  117. });
  118. })
  119. .catch(() => {});
  120. };
  121. const getMonitorPoint = () => {
  122. handleRequest(async () => {
  123. if (props.monitoringId) {
  124. const { humidityLower, humidityPreset, humidityUpper, tempLower, tempPreset, tempUpper, id, regionId } =
  125. await getMonitorPointInfo(props.monitoringId);
  126. Object.assign(limitForm.value, {
  127. humidityLower,
  128. humidityPreset,
  129. humidityUpper,
  130. tempLower,
  131. tempPreset,
  132. tempUpper,
  133. id,
  134. regionId,
  135. });
  136. }
  137. });
  138. };
  139. const getWarning = () => {
  140. handleRequest(async () => {
  141. if (warningShow.value) {
  142. await updateBatchMonitorPointAlarm(warningList.value);
  143. } else {
  144. await addBatchMonitorPointAlarm(warningList.value);
  145. }
  146. });
  147. warningOpen.value = false;
  148. };
  149. watch(
  150. () => props.monitoringId,
  151. (count) => {
  152. if (count) {
  153. getMonitorPoint();
  154. getMonitorPointList();
  155. }
  156. },
  157. );
  158. onMounted(() => {
  159. getMonitorPoint();
  160. });
  161. </script>
  162. <template>
  163. <div>
  164. <div>
  165. <AButton type="text" class="icon-button icon-style" @click="addLimit">
  166. <SvgIcon name="setting" />
  167. 设置温湿度限值
  168. </AButton>
  169. <AButton type="text" class="icon-button icon-style" @click="addWarning">
  170. <SvgIcon name="setting" />
  171. 设置温湿度预警
  172. </AButton>
  173. </div>
  174. <AModal
  175. v-model:open="limitOpen"
  176. title="设置温湿度限值"
  177. :footer="null"
  178. width="704px"
  179. :mask-closable="false"
  180. :keyboard="false"
  181. >
  182. <AForm ref="formRef" :model="limitForm" layout="vertical" :rules="rules">
  183. <AFormItem label="请选择监控点名" name="id">
  184. <ASelect
  185. class="select-width"
  186. v-model:value="limitForm.id"
  187. :options="monitoringData"
  188. :field-names="{ label: 'name', value: 'id' }"
  189. placeholder="请选择"
  190. />
  191. </AFormItem>
  192. <AFlex justify="space-between">
  193. <AFormItem label="室内温度设定值" name="tempPreset">
  194. <AInputNumber class="select-width" v-model:value="limitForm.tempPreset" :min="0" :max="40" />
  195. </AFormItem>
  196. <AFormItem label="室内温度上限值" name="tempUpper">
  197. <AInputNumber class="select-width" v-model:value="limitForm.tempUpper" :min="0" :max="40" />
  198. </AFormItem>
  199. <AFormItem label="室内温度下限值" name="tempLower">
  200. <AInputNumber class="select-width" v-model:value="limitForm.tempLower" :min="0" :max="40" />
  201. </AFormItem>
  202. </AFlex>
  203. <AFlex justify="space-between">
  204. <AFormItem label="室内湿度设定值" name="humidityPreset">
  205. <AInputNumber class="select-width" v-model:value="limitForm.humidityPreset" :min="0" :max="100" />
  206. </AFormItem>
  207. <AFormItem label="室内湿度上限值" name="humidityUpper">
  208. <AInputNumber class="select-width" v-model:value="limitForm.humidityUpper" :min="0" :max="100" />
  209. </AFormItem>
  210. <AFormItem label="室内湿度下限值" name="humidityLower">
  211. <AInputNumber class="select-width" v-model:value="limitForm.humidityLower" :min="0" :max="100" />
  212. </AFormItem>
  213. </AFlex>
  214. <ACheckbox v-model:checked="limitForm.batch">批量设置</ACheckbox>
  215. </AForm>
  216. <AFlex justify="flex-end" class="limit-top">
  217. <AButton class="limit-button default-button" @click="limitOpen = false">{{ $t('common.cancel') }}</AButton>
  218. <AButton type="primary" @click="getLimit">{{ $t('common.confirm') }}</AButton>
  219. </AFlex>
  220. </AModal>
  221. <AModal v-model:open="warningOpen" :footer="null" width="704px" :mask-closable="false" :keyboard="false">
  222. <template #title>
  223. <div class="warning-title">设置温湿度预警</div>
  224. </template>
  225. <div v-for="item in warningList" :key="item.id" class="warning-div warning-color">
  226. <ACheckbox v-model:checked="item.enabled" class="warning-color">{{
  227. item.type === 1 ? '启用温度预警' : '启用湿度预警'
  228. }}</ACheckbox>
  229. <AFlex align="center" class="warning-flex">
  230. <div>{{ item.type === 1 ? '室内温度大于' : '室内湿度大于' }}</div>
  231. <AInputNumber class="input-width" v-model:value="item.val" :min="1" :max="9999" />
  232. <div>{{ item.type === 1 ? '℃' : '%' }}</div>
  233. <div>,且持续时间大于</div>
  234. <AInputNumber class="input-width" v-model:value="item.duration" :min="1" :max="9999" />
  235. <div>min时,触发</div>
  236. </AFlex>
  237. </div>
  238. <AFlex justify="flex-end" class="limit-top">
  239. <AButton class="default-button limit-button" @click="warningOpen = false">{{ $t('common.cancel') }}</AButton>
  240. <AButton type="primary" @click="getWarning">{{ $t('common.confirm') }}</AButton>
  241. </AFlex>
  242. </AModal>
  243. </div>
  244. </template>
  245. <style lang="scss" scoped>
  246. .input-width {
  247. width: 120px;
  248. margin: 0 12px;
  249. }
  250. .warning-flex {
  251. margin: 16px 0 32px;
  252. }
  253. .warning-color {
  254. font-size: 14px;
  255. font-style: normal;
  256. font-weight: 400;
  257. line-height: 22px;
  258. color: rgb(0 0 0 / 65%);
  259. text-align: left;
  260. }
  261. .warning-div {
  262. padding-top: 8px;
  263. }
  264. .warning-title {
  265. margin-bottom: 16px;
  266. }
  267. .limit-button {
  268. margin: 0 16px;
  269. }
  270. .limit-top {
  271. margin-top: 24px;
  272. }
  273. .icon-style {
  274. color: var(--antd-color-primary);
  275. }
  276. .select-width {
  277. width: 192px;
  278. }
  279. </style>