selectGroup.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="select-group">
  3. <el-select class="custom-select" v-model="farmVal" size="large" v-show="!toggle">
  4. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id" />
  5. </el-select>
  6. <div class="weather-wrap" :class="{'weather-transition':toggle}">
  7. <div class="weather-t">
  8. <div class="weather-l">
  9. <div class="weather-icon">
  10. <i :class="'qi-' + weatherInfo.iconDay + '-fill'"></i>
  11. </div>
  12. <span>{{ weatherInfo.tempAvg }}°C</span>
  13. </div>
  14. <div class="weather-r">
  15. <div class="line"></div>
  16. {{ formattedDate }}
  17. </div>
  18. <div class="arrow" @click="handleToggle">
  19. <el-icon v-show="!toggle" size="12"><ArrowDownBold /></el-icon>
  20. <el-icon v-show="toggle" size="12"><ArrowUpBold /></el-icon>
  21. </div>
  22. </div>
  23. <div class="weather-b">近14天晴天占比80%,温度波动较小,有利于荔枝糖分与风味积累</div>
  24. <div v-if="toggle" class="weather-chart">
  25. <span class="title">14天天气预报</span>
  26. <div class="chart-wrap">
  27. <weather-chart class="chart-dom"></weather-chart>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { onMounted, ref } from "vue";
  35. import { convertPointToArray } from "@/utils/index";
  36. import weatherChart from "./weatherChart.vue"
  37. const toggle = ref(false)
  38. const handleToggle = () =>{
  39. toggle.value = !toggle.value
  40. emit('toggle',toggle.value)
  41. }
  42. const farmVal = ref("");
  43. const options = ref([]);
  44. const emit = defineEmits(['gardenList','toggle'])
  45. const getGardenList = () => {
  46. VE_API.index.fetchGardenList({current: 1, size: 50}).then(res => {
  47. options.value = res.data;
  48. farmVal.value = res.data[0].id
  49. emit('gardenList',res.data)
  50. });
  51. };
  52. const weatherInfo = ref({});
  53. // 气象信息
  54. const fetchData = () => {
  55. VE_API.home.weatherInfo({ point: localStorage.getItem('MINI_USER_LOCATION_POINT') }).then(({ data }) => {
  56. data.tempAvg = (data.tempMin + data.tempMax) / 2;
  57. weatherInfo.value = data || {};
  58. });
  59. };
  60. const currentDate = new Date();
  61. const month = (currentDate.getMonth() + 1).toString().padStart(2, '0');
  62. const day = currentDate.getDate().toString().padStart(2, '0');
  63. // MM/DD
  64. const formattedDate = `${month}/${day}`;
  65. onMounted(() => {
  66. fetchData();
  67. getGardenList()
  68. });
  69. </script>
  70. <style lang="scss" scoped>
  71. .select-group {
  72. width: 100%;
  73. height: 100%;
  74. display: flex;
  75. justify-content: space-between;
  76. align-items: baseline;
  77. .custom-select{
  78. width: 110px;
  79. ::v-deep{
  80. .el-select__wrapper{
  81. box-shadow: none;
  82. background: rgba(0, 0, 0, 0.3);
  83. border: 1px solid rgba(255, 255, 255, 0.4);
  84. border-radius: 20px;
  85. }
  86. .el-select__caret,.el-select__placeholder{
  87. color: #fff;
  88. }
  89. }
  90. }
  91. .weather-wrap {
  92. color: #fff;
  93. background: rgba(0, 0, 0, 0.6);
  94. border: 1px solid rgba(255, 255, 255, 0.4);
  95. border-radius: 10px;
  96. font-size: 12px;
  97. width: calc(100% - 125px);
  98. padding: 8px 10px;
  99. box-sizing: border-box;
  100. transition: all 0.3s;
  101. backdrop-filter: blur(2px);
  102. .weather-t{
  103. display: flex;
  104. align-items: center;
  105. position: relative;
  106. .arrow{
  107. position: absolute;
  108. right: 0;
  109. top: 0;
  110. width: 20px;
  111. height: 20px;
  112. text-align: center;
  113. line-height: 22px;
  114. border-radius: 50%;
  115. background: rgba(255, 255, 255, 0.12);
  116. }
  117. .weather-l,
  118. .weather-r {
  119. display: flex;
  120. align-items: center;
  121. }
  122. .weather-icon {
  123. width: 18px;
  124. height: 18px;
  125. margin-right: 4px;
  126. i {
  127. display: block;
  128. width: 18px;
  129. height: 18px;
  130. font-size: 18px;
  131. left: 1px;
  132. top: 2px;
  133. }
  134. }
  135. .line {
  136. margin: 0 6px 0 6px;
  137. width: 1px;
  138. height: 12px;
  139. background: rgba(255, 255, 255, 0.3);
  140. }
  141. }
  142. .weather-b{
  143. margin-top: 6px;
  144. }
  145. &.weather-transition{
  146. width: 100%;
  147. .weather-b{
  148. border-bottom: 1px solid rgba(255, 255, 255, 0.4);
  149. padding-bottom: 10px;
  150. }
  151. .weather-chart{
  152. margin-top: 12px;
  153. .title{
  154. color: #bbbbbb;
  155. font-size: 11px;
  156. }
  157. .chart-wrap{
  158. width: 100%;
  159. height: 150px;
  160. overflow-x: auto;
  161. .chart-dom{
  162. width: 120%;
  163. height: 100%;
  164. }
  165. }
  166. }
  167. }
  168. }
  169. }
  170. </style>