index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="container">
  3. <!-- 天气控制 -->
  4. <view class="section weather-section">
  5. <view v-for="(weather, index) in weathers" :key="index"
  6. :class="['control-item', { active: currentWeather === weather.type }]"
  7. @click="handleControlChange('weather', weather.type)">
  8. <uni-icons :type="weather.icon" size="30"
  9. :color="currentWeather === weather.type ? activeTextColor : textColor" />
  10. <text class="control-text">{{ weather.name }}</text>
  11. </view>
  12. </view>
  13. <!-- 时区控制 -->
  14. <view class="section time-section">
  15. <view v-for="(time, index) in times" :key="index"
  16. :class="['control-item', { active: currentTime === time.type }]"
  17. @click="handleControlChange('time', time.type)">
  18. <uni-icons :type="time.icon" size="24"
  19. :color="currentTime === time.type ? activeTextColor : textColor" />
  20. <text class="control-text">{{ time.name }}</text>
  21. </view>
  22. </view>
  23. <!-- 模块控制 -->
  24. <view class="module-section">
  25. <view v-for="(module, index) in modules" :key="index" class="module-item"
  26. @click="handleControlChange('module', module.type)">
  27. <view class="module-icon">
  28. <uni-icons :type="module.icon" size="36" :color="iconColor" />
  29. </view>
  30. <text class="module-name">{{ module.name }}</text>
  31. <text class="module-status">{{ module.status }}</text>
  32. </view>
  33. </view>
  34. <view class="initialization">
  35. <button type="primary" @click="handleControlChange('module', 'BacktoOverview')">
  36. 初始化选项
  37. </button>
  38. </view>
  39. </view>
  40. </template>
  41. <script lang="ts" setup>
  42. import { ref } from 'vue';
  43. import { clientPut } from '../../utils/request';
  44. // 类型定义
  45. type WeatherType = 'WeatherSunny' | 'WeatherCloudy' | 'WeatherFoggy' | 'WeatherRain' | 'WeatherSnow';
  46. type TimeType = 'TimeMorning' | 'TimeNoon' | 'TimeNight' | 'TimeRealTime';
  47. type ModuleType = 'BacktoOverview' | 'OpenSmartSecurity' | 'OpenSmartEnergy' | 'OpenSmartFireControl' | 'OpenSmartLamp' | 'OpenSmartParking';
  48. // 响应式状态
  49. const currentWeather = ref<WeatherType>('WeatherSunny');
  50. const currentTime = ref<TimeType>('TimeMorning');
  51. // 样式常量
  52. const activeColor = '#2979ff';
  53. const activeTextColor = '#ffffff';
  54. const textColor = '#333333';
  55. const iconColor = '#2979ff';
  56. // 数据配置
  57. const weathers = [
  58. { type: 'WeatherSunny', name: '晴天', icon: 'sun' },
  59. { type: 'WeatherCloudy', name: '多云', icon: 'cloud' },
  60. { type: 'WeatherFoggy', name: '雾天', icon: 'cloud' },
  61. { type: 'WeatherRain', name: '雨天', icon: 'rain' },
  62. { type: 'WeatherSnow', name: '雪天', icon: 'snow' }
  63. ];
  64. const times = [
  65. { type: 'TimeMorning', name: '早上', icon: 'sun' },
  66. { type: 'TimeNoon', name: '中午', icon: 'sun-filled' },
  67. { type: 'TimeNight', name: '夜晚', icon: 'moon' },
  68. { type: 'TimeRealTime', name: '实时', icon: 'moon' }
  69. ];
  70. const modules = [
  71. { type: 'BacktoOverview', name: '园区总览', icon: 'map', status: '运行正常' },
  72. { type: 'OpenSmartSecurity', name: '智慧安防', icon: 'contact', status: '无异常' },
  73. { type: 'OpenSmartEnergy', name: '智慧能耗', icon: 'list', status: '节能运行' },
  74. { type: 'OpenSmartFireControl', name: '智慧消防', icon: 'fire', status: '系统正常' },
  75. { type: 'OpenSmartLamp', name: '智慧灯杆', icon: 'map-pin-ellipse', status: '照明正常' },
  76. { type: 'OpenSmartParking', name: '智慧通行', icon: 'staff', status: '通行顺畅' }
  77. ];
  78. // 统一处理控制项变化
  79. const handleControlChange = async (category : 'weather' | 'time' | 'module', type : string) => {
  80. try {
  81. // 更新本地状态
  82. if (category === 'weather') {
  83. currentWeather.value = type as WeatherType;
  84. } else if (category === 'time') {
  85. currentTime.value = type as TimeType;
  86. }
  87. uni.request({
  88. method: 'PUT',
  89. url: 'http://192.168.110.96:30010/remote/preset/RemoteControlPreset/function/' + type, //仅为示例,并非真实接口地址。
  90. data: {
  91. "Parameters": {},
  92. "GenerateTransaction": false
  93. },
  94. success: (res) => {
  95. console.log(1111)
  96. }
  97. });
  98. console.log(`${category} 控制请求成功:`, type);
  99. } catch (error) {
  100. console.error(`${category} 控制请求失败:`, error);
  101. // 可以在这里添加错误处理逻辑,例如恢复之前的状态
  102. }
  103. };
  104. </script>
  105. <style>
  106. :root {
  107. --section-bg: #ffffff;
  108. --active-bg: #2979ff;
  109. --text-main: #333333;
  110. --text-secondary: #666666;
  111. --section-radius: 16rpx;
  112. --section-spacing: 30rpx;
  113. }
  114. page {
  115. height: 100%;
  116. background-color: #f5f5f5;
  117. }
  118. .container {
  119. min-height: 100%;
  120. padding: var(--section-spacing);
  121. }
  122. /* 通用控制项样式 */
  123. .section {
  124. padding: 20rpx;
  125. background-color: var(--section-bg);
  126. border-radius: var(--section-radius);
  127. margin-bottom: var(--section-spacing);
  128. display: flex;
  129. justify-content: space-around;
  130. }
  131. .control-item {
  132. display: flex;
  133. flex-direction: column;
  134. align-items: center;
  135. padding: 20rpx 30rpx;
  136. border-radius: 12rpx;
  137. transition: all 0.3s;
  138. }
  139. .control-item.active {
  140. background-color: var(--active-bg);
  141. color: white;
  142. }
  143. .control-text {
  144. margin-top: 10rpx;
  145. font-size: 14px;
  146. color: var(--text-main);
  147. }
  148. .control-item.active .control-text {
  149. color: var(--active-text-color);
  150. }
  151. /* 模块控制样式 */
  152. .module-section {
  153. display: grid;
  154. grid-template-columns: repeat(2, 1fr);
  155. gap: 20rpx;
  156. }
  157. .module-item {
  158. background-color: var(--section-bg);
  159. border-radius: var(--section-radius);
  160. padding: 30rpx;
  161. display: flex;
  162. flex-direction: column;
  163. align-items: center;
  164. transition: transform 0.3s;
  165. }
  166. .module-item:active {
  167. transform: scale(0.98);
  168. }
  169. .module-icon {
  170. width: 80rpx;
  171. height: 80rpx;
  172. display: flex;
  173. justify-content: center;
  174. align-items: center;
  175. margin-bottom: 20rpx;
  176. }
  177. .module-name {
  178. font-size: 16px;
  179. color: var(--text-main);
  180. margin-bottom: 10rpx;
  181. }
  182. .module-status {
  183. font-size: 12px;
  184. color: var(--text-secondary);
  185. }
  186. .initialization {
  187. margin-top: 12px;
  188. }
  189. </style>