SetInterval.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <script setup lang="ts">
  2. import { ref } from 'vue';
  3. import SvgIcon from '@/components/SvgIcon.vue';
  4. import { t } from '@/i18n';
  5. import type { FormInstance, Rule } from 'ant-design-vue/es/form';
  6. import type { TemperatureRange } from '@/types';
  7. interface Props {
  8. index: number;
  9. form: TemperatureRange;
  10. }
  11. const formRef = ref<FormInstance>();
  12. const emit = defineEmits(['deleteClick', 'addClick']);
  13. const props = defineProps<Props>();
  14. const rules: Record<string, Rule[]> = {
  15. time: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  16. lower: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  17. upper: [{ required: true, message: t('common.cannotEmpty'), trigger: 'change' }],
  18. };
  19. const deleteInterval = () => {
  20. emit('deleteClick', props.index);
  21. };
  22. const formResetFields = () => {
  23. formRef.value?.resetFields();
  24. };
  25. const formRefSubmit = () => {
  26. return formRef.value?.validate() || Promise.resolve();
  27. };
  28. defineExpose({
  29. formRefSubmit,
  30. formResetFields,
  31. });
  32. </script>
  33. <template>
  34. <div>
  35. <AFlex align="center">
  36. <div class="set-content">
  37. <AForm ref="formRef" :model="form" :rules="rules">
  38. <AFlex justify="space-between">
  39. <AFormItem name="time">
  40. <AFlex align="center" class="div-top">
  41. <div class="time-text">{{ $t('algorithmManage.periodTime') }}</div>
  42. <ATimeRangePicker
  43. v-model:value="form.time"
  44. class="time-width"
  45. format="HH:mm"
  46. :separator="$t('common.to')"
  47. show-time
  48. />
  49. </AFlex>
  50. </AFormItem>
  51. <AFlex align="center">
  52. <div class="time-text">{{ $t('algorithmManage.temperatureRange') }}</div>
  53. <AFlex class="temperature-style" align="center">
  54. <AFormItem name="lower" class="input-padding">
  55. <AInputNumber
  56. class="input-width"
  57. v-model:value="form.lower"
  58. :bordered="false"
  59. :min="-99"
  60. :max="999"
  61. :placeholder="t('common.pleaseEnter')"
  62. />
  63. </AFormItem>
  64. <div>{{ $t('common.to') }}</div>
  65. <AFormItem name="upper">
  66. <AInputNumber
  67. class="input-number"
  68. v-model:value="form.upper"
  69. addon-after="℃"
  70. :bordered="false"
  71. :min="-99"
  72. :max="999"
  73. :placeholder="t('common.pleaseEnter')"
  74. />
  75. </AFormItem>
  76. </AFlex>
  77. </AFlex>
  78. </AFlex>
  79. </AForm>
  80. </div>
  81. <div @click="$emit('addClick')">
  82. <AFlex justify="center" align="center" class="add-style">
  83. <SvgIcon name="plus" />
  84. </AFlex>
  85. </div>
  86. <div @click="deleteInterval">
  87. <AFlex v-if="index !== 0" justify="center" align="center" class="add-style">
  88. <SvgIcon name="minus" />
  89. </AFlex>
  90. </div>
  91. </AFlex>
  92. </div>
  93. </template>
  94. <style lang="scss" scoped>
  95. .div-top {
  96. margin-top: 8px;
  97. }
  98. .input-width {
  99. width: 100px;
  100. }
  101. .input-number {
  102. width: 100px;
  103. margin-left: 40px;
  104. }
  105. :deep(.set-content) {
  106. .ant-input-number-group .ant-input-number-group-addon {
  107. background-color: #fff;
  108. border: 0;
  109. border-left: 1px solid #d9d9d9;
  110. }
  111. .ant-form-item .ant-form-item-control-input {
  112. margin-top: -4px;
  113. }
  114. }
  115. :deep(.input-padding) {
  116. .ant-input-number .ant-input-number-input {
  117. padding-left: 40px;
  118. }
  119. }
  120. .temperature-style {
  121. width: 256px;
  122. height: 32px;
  123. background: #fff;
  124. border: 1px solid rgb(0 0 0 / 15%);
  125. border-radius: 4px;
  126. }
  127. .add-style {
  128. width: 24px;
  129. height: 24px;
  130. margin-right: 8px;
  131. cursor: pointer;
  132. background: #fff;
  133. border: 1px solid #d9d9d9;
  134. border-radius: 4px;
  135. }
  136. .time-width {
  137. width: 256px;
  138. }
  139. .time-text {
  140. margin-right: 12px;
  141. font-size: 14px;
  142. font-style: normal;
  143. font-weight: 400;
  144. line-height: 22px;
  145. color: #666;
  146. text-align: left;
  147. }
  148. .set-content {
  149. width: 706px;
  150. height: 64px;
  151. padding: 16px;
  152. margin-right: 12px;
  153. margin-bottom: 8px;
  154. background: #f5f7fa;
  155. border-radius: 4px;
  156. }
  157. </style>