indexnew.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <view class="home-page">
  3. <view
  4. class="home-page__layers"
  5. >
  6. <HomeSearch
  7. :inputTypeVisible="show"
  8. :layerVisible="layerVisible"
  9. :searchTypeName="currentTypeName"
  10. :searchType="currentType"
  11. :warningData="warningData"
  12. @inputTypeChange="handleInputTypeChange"
  13. @layerChange="handleLayerChange"
  14. @search="handleSearch"
  15. @deviceStatusChecked="handleDeviceStatusChange"
  16. />
  17. </view>
  18. <view class="home-page__canvas">
  19. <Map
  20. :deviceList="deviceList"
  21. :landList="landList"
  22. :inputTag="inputTag"
  23. :blockList="blockList"
  24. :inputValue="inputValue"
  25. :inputType="currentType"
  26. :mapRenderTypes="mapRenderTypes"
  27. :isShowSatellite="isShowSatellite"
  28. :deviceStatusCheckedList="deviceStatusCheckedList"
  29. @deviceClick="handleDeviceClick"
  30. @landClick="handleLandClick"
  31. @plotClick="handlePlotClick"
  32. @getLocation="handleGetLocation"
  33. />
  34. </view>
  35. <u-picker
  36. v-model="show"
  37. :range="searchTypes"
  38. mode="selector"
  39. :default-selector="[0]"
  40. range-key="label"
  41. confirmColor="#14A478"
  42. @cancel="closeHandler"
  43. @confirm="confirmHandler"
  44. ></u-picker>
  45. <LayerPopup :visible.sync="layerVisible" @confirm="handleLayerConfirm" />
  46. <DevicePopup
  47. :visible.sync="deviceLayerVisible"
  48. :dataSource="currentSelectedData"
  49. />
  50. <LandPopup
  51. :visible.sync="landLayerVisible"
  52. :dataSource="currentSelectedLandData"
  53. />
  54. <BlockPopup
  55. :visible.sync="blockLayerVisible"
  56. :dataSource="currentSelectedBlockData"
  57. />
  58. <AppPopup :visible.sync="appLayerVisible" />
  59. </view>
  60. </template>
  61. <script>
  62. import { mapGetters } from 'vuex';
  63. import Map from './components/Map.vue';
  64. import LayerPopup from './components/LayerPopup.vue';
  65. import HomeSearch from './components/HomeSearch.vue';
  66. import DevicePopup from './components/DevicePopup.vue';
  67. import LandPopup from './components/LandPopup.vue';
  68. import BlockPopup from './components/BlockPopup.vue';
  69. import AppPopup from './components/AppPopup.vue';
  70. import { cloneDeep, slice, take } from 'lodash-es';
  71. import HeartBeat from '@/libs/HeartBeat';
  72. // #ifdef APP-PLUS
  73. var Color = plus.android.importClass('android.graphics.Color');
  74. plus.android.importClass('android.view.Window');
  75. var mainActivity = plus.android.runtimeMainActivity();
  76. var window_android = mainActivity.getWindow();
  77. window_android.setNavigationBarColor(Color.parseColor('#fff'));
  78. // #endif
  79. export default {
  80. name: 'Home',
  81. components: {
  82. HomeSearch,
  83. Map,
  84. LayerPopup,
  85. DevicePopup,
  86. LandPopup,
  87. BlockPopup,
  88. AppPopup
  89. },
  90. data() {
  91. return {
  92. layerVisible: false,
  93. show: false,
  94. currentType: 'device',
  95. currentTypeName: '设备/ID',
  96. searchTypes: [
  97. {
  98. label: '设备/ID',
  99. id: 'device'
  100. },
  101. {
  102. label: '基地',
  103. id: 'land'
  104. },
  105. {
  106. label: '地块',
  107. id: 'block'
  108. },
  109. {
  110. label: '作物',
  111. id: 'crop'
  112. }
  113. ],
  114. warningText: '',
  115. deviceList: [],
  116. blockList: [],
  117. oldDeviceList: [],
  118. landList: [],
  119. inputValue: '',
  120. deviceLayerVisible: false,
  121. currentSelectedData: {},
  122. appLayerVisible: false,
  123. projectLocation: {},
  124. currentSelectedLandData: {},
  125. currentSelectedBlockData: {},
  126. landLayerVisible: false,
  127. blockLayerVisible: false,
  128. warningData: {},
  129. mapRenderTypes: ['device', 'land', 'block', 'crop'],
  130. isShowSatellite: true,
  131. deviceStatusCheckedList: ['0', '1', '3'],
  132. unReadMessageTotal: 0,
  133. inputTag: false,
  134. warningLatest: [],
  135. weatherWarningData: {}
  136. };
  137. },
  138. onReady() {
  139. plus.navigator.setStatusBarStyle('light'); // 设置状态栏字体为黑色,背景透明(在某些设备上可能无效)
  140. // #ifdef APP-PLUS
  141. var Color = plus.android.importClass('android.graphics.Color');
  142. plus.android.importClass('android.view.Window');
  143. var mainActivity = plus.android.runtimeMainActivity();
  144. var window_android = mainActivity.getWindow();
  145. window_android.setNavigationBarColor(Color.parseColor('#fff'));
  146. // #endif
  147. console.log('on ready');
  148. },
  149. onShow() {
  150. console.log('----------------- onshow ');
  151. // #ifdef APP-PLUS
  152. if (plus) {
  153. // 确保在App环境下运行
  154. plus.navigator.setStatusBarStyle('light'); // 设置状态栏字体为黑色,背景透明(在某些设备上可能无效)
  155. // 注意:直接设置状态栏背景色在某些Android版本上可能不生效,可以考虑使用第三方库或者原生代码来实现更复杂的自定义。
  156. }
  157. var Color = plus.android.importClass('android.graphics.Color');
  158. plus.android.importClass('android.view.Window');
  159. var mainActivity = plus.android.runtimeMainActivity();
  160. var window_android = mainActivity.getWindow();
  161. window_android.setNavigationBarColor(Color.parseColor('#fff'));
  162. // #endif
  163. this.getWarningLatest();
  164. setTimeout(() => {
  165. this.initData();
  166. }, 500);
  167. this.getWeatherWarning();
  168. },
  169. onLoad() {
  170. console.log('----------------- onload ');
  171. // #ifdef APP-PLUS
  172. var Color = plus.android.importClass('android.graphics.Color');
  173. plus.android.importClass('android.view.Window');
  174. var mainActivity = plus.android.runtimeMainActivity();
  175. var window_android = mainActivity.getWindow();
  176. window_android.setNavigationBarColor(Color.parseColor('#fff'));
  177. // #endif
  178. this.updateMessageCount();
  179. },
  180. mounted() {},
  181. methods: {
  182. handleGetLocation(options) {
  183. const { lat, lng } = options;
  184. // lat && this.getWeatherWarning(lng, lat);
  185. },
  186. getWeatherWarning(longitude, latitude) {
  187. // const that = this;
  188. // // 获取当前经纬度
  189. // uni.request({
  190. // url: `https://devapi.qweather.com/v7/warning/now?location=${longitude},${latitude}&lang=zh&key=f55bd03fc95e4155b3c8abee8aa68886`,
  191. // success(res) {
  192. // if (res.statusCode == 200) {
  193. // const data = res.data || {};
  194. // if (data.code === '200') {
  195. // const warningLatest = data.warning || [];
  196. // let warningText = '';
  197. // warningLatest.forEach((item) => {
  198. // warningText += item.text + ',';
  199. // });
  200. // that.warningText = warningText;
  201. // console.log(this.warningText, 'warningTextwarningText');
  202. // }
  203. // }
  204. // }
  205. // });
  206. },
  207. initData() {
  208. Promise.all([
  209. this.getDeviceList(),
  210. this.getLandList(),
  211. this.getBlockList()
  212. ])
  213. .then(([deviceResponse, landResponse, blockResponse]) => {
  214. const deviceList = deviceResponse.data || [];
  215. // const deviceArr = [];
  216. // deviceList.forEach((item) => {
  217. // if (item.devStatus == 0) {
  218. // deviceArr.push(item);
  219. // }
  220. // });
  221. this.deviceList = deviceList || [];
  222. this.blockList = blockResponse.data || [];
  223. this.oldDeviceList = cloneDeep(deviceList);
  224. this.landList = landResponse.data || [];
  225. })
  226. .catch((err) => {
  227. console.log('-------------------------------fffff error', err);
  228. });
  229. },
  230. handleLayerChange(value) {
  231. console.log('handleLayerChange', value);
  232. this.layerVisible = value;
  233. },
  234. openSearchType() {
  235. this.show = true;
  236. },
  237. closeHandler() {
  238. console.log('closeHandler');
  239. this.show = false;
  240. },
  241. handleInputTypeChange(value) {
  242. this.show = value;
  243. },
  244. confirmHandler(index) {
  245. const item = this.searchTypes[index]
  246. const { id,label } = item;
  247. this.currentType = id;
  248. this.currentTypeName = label;
  249. this.closeHandler();
  250. },
  251. getDeviceList() {
  252. },
  253. getBlockList() {
  254. },
  255. getLandList() {
  256. },
  257. handleSearch(val) {
  258. console.log(val, 'handle search 1212121111111111111111');
  259. this.inputValue = val;
  260. this.inputTag = !this.inputTag;
  261. },
  262. handleDeviceClick(row) {
  263. console.log('handleDeviceClick', row);
  264. this.currentSelectedData = row;
  265. this.deviceLayerVisible = true;
  266. },
  267. handleLandClick(row) {
  268. console.log('handleLandClick', row);
  269. this.currentSelectedLandData = row;
  270. this.landLayerVisible = true;
  271. },
  272. handlePlotClick(row) {
  273. console.log('handlePlotClick', row);
  274. // 可以在这里添加地块点击的处理逻辑
  275. // 比如显示地块详情弹窗等
  276. // uni.showToast({
  277. // title: `点击了地块: ${row.blockName}`,
  278. // icon: 'none'
  279. // });
  280. this.currentSelectedBlockData = row;
  281. this.blockLayerVisible = true;
  282. },
  283. // 根据城市查询经纬度
  284. getWarningLatest() {
  285. },
  286. handleLayerConfirm(row = {}) {
  287. this.isShowSatellite = row.isSatellite;
  288. this.mapRenderTypes = row.renderTypes || [];
  289. console.log(
  290. 'handleLayerConfirm',
  291. this.isShowSatellite,
  292. this.mapRenderTypes
  293. );
  294. },
  295. handleDeviceStatusChange(checkList) {
  296. // if (checkList.length === 2) {
  297. // this.deviceList = cloneDeep(this.oldDeviceList);
  298. // } else if (!checkList.length) {
  299. // this.deviceList = cloneDeep(this.oldDeviceList);
  300. // } else {
  301. // const checkId = checkList[0];
  302. // const deviceList = [];
  303. // this.oldDeviceList.forEach((item) => {
  304. // if (item.devStatus == checkId) {
  305. // deviceList.push(item);
  306. // }
  307. // });
  308. // this.deviceList = deviceList;
  309. // }
  310. const newCheckList = slice(checkList || [], 0);
  311. if (newCheckList.includes('0')) {
  312. newCheckList.push('3');
  313. }
  314. this.deviceStatusCheckedList = newCheckList;
  315. },
  316. updateMessageCount() {
  317. HeartBeat.getInstance().handle({
  318. type: 'TASK_MESSAGE_UNREAD',
  319. intervalTimes: 4,
  320. handler: () => {
  321. return this.getMessageUnreadCount();
  322. }
  323. });
  324. },
  325. getMessageUnreadCount() {
  326. }
  327. },
  328. onHide() {}
  329. };
  330. </script>
  331. <style lang="scss" scoped>
  332. page {
  333. background: #f3f3f3;
  334. }
  335. .home-page__tabs {
  336. background: #f3f3f3;
  337. }
  338. .weather-warning {
  339. display: flex;
  340. height: 64rpx;
  341. padding: 0 10rpx;
  342. justify-content: center;
  343. align-items: center;
  344. border-radius: 16rpx;
  345. background: #ffffffcc;
  346. backdrop-filter: blur(3rpx);
  347. margin-bottom: 14rpx;
  348. pointer-events: auto;
  349. &__list {
  350. color: #364d46;
  351. font-family: 'Source Han Sans CN VF';
  352. font-size: 28rpx;
  353. font-weight: 400;
  354. }
  355. }
  356. .home-page {
  357. width: 100%;
  358. // height: calc(100vh - 50px - env(safe-area-inset-bottom));
  359. height: 100%;
  360. &__canvas {
  361. width: 100%;
  362. height: 100%;
  363. }
  364. &__layers {
  365. position: fixed;
  366. width: 100%;
  367. left: 0;
  368. right: 0;
  369. z-index: 401;
  370. padding: 0 32rpx;
  371. pointer-events: none;
  372. transition: all 0.3s ease-in-out;
  373. }
  374. ::v-deep .tdt-bottom {
  375. display: none;
  376. }
  377. &__app {
  378. position: absolute;
  379. width: 180rpx;
  380. height: 60rpx;
  381. display: flex;
  382. justify-content: center;
  383. align-items: center;
  384. bottom: 0rpx;
  385. left: 50%;
  386. transform: translateX(-50%);
  387. z-index: 1000;
  388. padding: 24rpx;
  389. background-color: #fff;
  390. border-radius: 16rpx 16rpx 0 0;
  391. }
  392. }
  393. </style>