HomeSearch.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view class="home-search">
  3. <!-- 搜索悬浮按钮 -->
  4. <view class="home-search__search">
  5. <view
  6. :duration="300"
  7. mode="fade-right"
  8. :timing-function="'ease-in-out'"
  9. customStyle="flex:1 1 auto;"
  10. style="width:100%"
  11. v-show="showSearch"
  12. ><view class="search-bar" :animation="searchAnim">
  13. <view class="search-bar-btn">
  14. <view
  15. class="search-select"
  16. @click="handleTypeClick"
  17. >
  18. <text>{{ searchTypeName }}</text>
  19. <u-icon name="arrow-down" size="24" class="icon"></u-icon>
  20. </view>
  21. <u-input
  22. style="width:80%"
  23. v-model="searchText"
  24. :auto-blur="true"
  25. placeholder="搜索"
  26. class="search-input"
  27. @confirm="onSearch"
  28. >
  29. </u-input>
  30. </view>
  31. </view>
  32. </view>
  33. <view v-if="!showSearch"></view>
  34. <button class="layer-btn" @click="openSearch">
  35. <!-- <u-icon name="search" size="40rpx" color="#364D46"></u-icon> -->
  36. <image
  37. mode="aspectFit"
  38. src="/static/images/home/search.png"
  39. class="icon"
  40. />
  41. <view class="layer-btn__text">搜索</view>
  42. </button>
  43. </view>
  44. <view class="home-search__layer">
  45. <view></view>
  46. <button class="layer-btn" @click="handleLayerClick">
  47. <!-- <u-icon name="search" size="40rpx" color="#364D46"></u-icon> -->
  48. <!-- <text class="cuIcon-copy icon"></text> -->
  49. <image
  50. mode="aspectFit"
  51. src="/static/images/home/layer.png"
  52. class="icon"
  53. />
  54. <view class="layer-btn__text">图层</view>
  55. </button>
  56. </view>
  57. <view class="home-search__layer">
  58. <view class="layer-device-status">
  59. <view class="status-options">
  60. <view
  61. class="status-item"
  62. :class="{ active: deviceStatusCheckedList.includes('1') }"
  63. @click="toggleDeviceStatus('1')"
  64. >
  65. <view class="checkbox">
  66. <view class="checkbox-inner" v-if="deviceStatusCheckedList.includes('1')">
  67. <text class="checkmark">
  68. <u-icon name="checkmark" />
  69. </text>
  70. </view>
  71. </view>
  72. <text class="status-text">在线</text>
  73. </view>
  74. <view
  75. class="status-item"
  76. :class="{ active: deviceStatusCheckedList.includes('0') }"
  77. @click="toggleDeviceStatus('0')"
  78. >
  79. <view class="checkbox">
  80. <view class="checkbox-inner" v-if="deviceStatusCheckedList.includes('0')">
  81. <text class="checkmark">
  82. <u-icon name="checkmark" />
  83. </text>
  84. </view>
  85. </view>
  86. <text class="status-text">离线</text>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </template>
  93. <script>
  94. import { isEmpty } from 'lodash-es';
  95. export default {
  96. props: {
  97. layerVisible: {
  98. type: Boolean,
  99. default: false
  100. },
  101. inputTypeVisible: {
  102. type: Boolean,
  103. default: false
  104. },
  105. searchTypeName: {
  106. type: String,
  107. default: '设备/ID'
  108. },
  109. searchType: {
  110. type: String,
  111. default: 'device'
  112. },
  113. warningData: {
  114. type: Object,
  115. default() {
  116. return {};
  117. }
  118. }
  119. },
  120. data() {
  121. return {
  122. show: false,
  123. showSearch: true,
  124. searchTypes: [
  125. [
  126. {
  127. label: '设备/ID',
  128. value: 'device'
  129. },
  130. {
  131. label: '基地',
  132. value: 'land'
  133. },
  134. {
  135. label: '地块',
  136. value: 'block'
  137. }
  138. ]
  139. ],
  140. searchTypeIndex: 0,
  141. searchText: '',
  142. layerDialogVisible: false,
  143. layerStatus: 'online',
  144. searchAnim: {},
  145. currentType: 'land',
  146. currentTypeName: '基地',
  147. deviceStatusCheckedList: ['0', '1'],
  148. title: '',
  149. description: '',
  150. layerContainerVisible: true
  151. };
  152. },
  153. computed: {
  154. hasWarning() {
  155. return false;
  156. // return !isEmpty(this.warningData);
  157. }
  158. },
  159. watch: {
  160. inputTypeVisible(newVal) {
  161. if (newVal !== this.show) {
  162. this.show = newVal;
  163. }
  164. },
  165. layerVisible(newVal) {
  166. if (newVal !== this.layerDialogVisible) {
  167. this.layerDialogVisible = newVal;
  168. }
  169. }
  170. },
  171. methods: {
  172. clickAlert() {
  173. const msgExtra = JSON.parse(this.warningData.msgExtra);
  174. const handleId = msgExtra.handleId || '';
  175. // 跳转消息详情
  176. uni.navigateTo({
  177. url:
  178. '/pages/views/message/detail?msgId=' +
  179. this.warningData.msgId +
  180. '&handleId=' +
  181. handleId
  182. });
  183. },
  184. openSearch() {
  185. this.showSearch = !this.showSearch;
  186. this.$nextTick(() => {
  187. this.searchAnim = uni
  188. .createAnimation({
  189. duration: 300,
  190. timingFunction: 'ease'
  191. })
  192. .opacity(1)
  193. .translateX(0)
  194. .step()
  195. .export();
  196. });
  197. },
  198. closeSearch() {
  199. this.showSearch = false;
  200. },
  201. onTypeChange(e) {
  202. this.searchTypeIndex = e.detail.value;
  203. },
  204. onSearch() {
  205. // 触发搜索逻辑
  206. this.$emit('search', this.searchText);
  207. },
  208. onLayerChange(e) {
  209. this.layerStatus = e.detail.value;
  210. },
  211. openSearchType() {
  212. this.show = true;
  213. },
  214. closeHandler() {
  215. this.show = false;
  216. },
  217. confirmHandler(item) {
  218. const { value } = item;
  219. this.currentType = value[0]?.value;
  220. this.currentTypeName = value[0]?.label;
  221. this.closeHandler();
  222. },
  223. handleLayerClick() {
  224. this.layerDialogVisible = !this.layerDialogVisible;
  225. this.$emit('layerChange', this.layerDialogVisible);
  226. },
  227. handleTypeClick() {
  228. this.show = !this.show;
  229. this.$emit('inputTypeChange', this.show);
  230. },
  231. closeAlert() {
  232. this.layerContainerVisible = false;
  233. setTimeout(() => {
  234. this.layerContainerVisible = true;
  235. });
  236. },
  237. handleDeviceStatusChange() {
  238. this.$nextTick(() => {
  239. this.$emit('deviceStatusChecked', this.deviceStatusCheckedList);
  240. });
  241. },
  242. toggleDeviceStatus(status) {
  243. const index = this.deviceStatusCheckedList.indexOf(status);
  244. if (index > -1) {
  245. this.deviceStatusCheckedList.splice(index, 1);
  246. } else {
  247. this.deviceStatusCheckedList.push(status);
  248. }
  249. this.handleDeviceStatusChange();
  250. }
  251. }
  252. };
  253. </script>
  254. <style scoped lang="scss">
  255. .home-search {
  256. position: relative;
  257. width: 100%;
  258. pointer-events: none;
  259. z-index: 401;
  260. margin-top: 100rpx;
  261. &__search {
  262. display: flex;
  263. align-items: center;
  264. justify-content: space-between;
  265. margin-bottom: 16rpx;
  266. height: 88rpx;
  267. overflow: hidden;
  268. width: calc(100% - 60rpx);
  269. }
  270. &__layer {
  271. display: flex;
  272. align-items: center;
  273. justify-content: flex-end;
  274. text-align: right;
  275. pointer-events: none;
  276. margin-bottom: 16rpx;
  277. width: calc(100% - 60rpx);
  278. ::v-deep .u-radio {
  279. margin-bottom: 16rpx;
  280. }
  281. }
  282. }
  283. .search-bar {
  284. display: flex;
  285. align-items: center;
  286. background: rgba(255, 255, 255, 0.6);
  287. border-top-left-radius: 16rpx;
  288. border-top-right-radius: 16rpx;
  289. border-bottom-left-radius: 16rpx;
  290. border-bottom-right-radius: 16rpx;
  291. padding: 12rpx 16rpx;
  292. margin-right: 16rpx;
  293. height: 60rpx;
  294. pointer-events: auto;
  295. .search-bar-btn{
  296. background: rgba(255, 255, 255, 1);
  297. border-top-left-radius: 8rpx;
  298. border-top-right-radius: 8rpx;
  299. border-bottom-left-radius: 8rpx;
  300. border-bottom-right-radius: 8rpx;
  301. display: flex;
  302. align-items: center;
  303. height: 60rpx;
  304. }
  305. }
  306. .search-type {
  307. width: 160rpx;
  308. margin-right: 16rpx;
  309. }
  310. .search-input {
  311. flex: 1;
  312. width: 100%;
  313. height: 100%;
  314. line-height: 60rpx;
  315. border: none;
  316. background: #fff;
  317. font-size: 28rpx;
  318. }
  319. .search-btn,
  320. .close-btn {
  321. background: none;
  322. border: none;
  323. margin-left: 16rpx;
  324. }
  325. .fab {
  326. position: absolute;
  327. pointer-events: auto;
  328. box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15);
  329. background: #fff;
  330. border-radius: 50%;
  331. width: 88rpx;
  332. height: 88rpx;
  333. display: flex;
  334. align-items: center;
  335. justify-content: center;
  336. }
  337. .search-fab {
  338. top: 32rpx;
  339. left: 32rpx;
  340. }
  341. .layer-fab {
  342. top: 32rpx;
  343. right: 32rpx;
  344. }
  345. ::v-deep .u-checkbox__label {
  346. font-size: 28rpx;
  347. color: #fff;
  348. margin-right: 0;
  349. }
  350. .layer-popover {
  351. position: absolute;
  352. top: 120rpx;
  353. right: 32rpx;
  354. background: #fff;
  355. border-radius: 16rpx;
  356. box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.08);
  357. padding: 24rpx;
  358. z-index: 20;
  359. }
  360. .layer-radio {
  361. display: block;
  362. margin-bottom: 16rpx;
  363. font-size: 28rpx;
  364. }
  365. .layer-btn {
  366. flex: 0 0 auto;
  367. display: flex;
  368. flex-direction: column;
  369. justify-content: center;
  370. width: 80rpx;
  371. height: 80rpx;
  372. padding: 0;
  373. margin: 0;
  374. align-items: center;
  375. text-align: center;
  376. background: #fff;
  377. border-radius: 16rpx;
  378. font-size: 16rpx;
  379. color: #364d46;
  380. pointer-events: auto;
  381. .icon {
  382. width: 32rpx;
  383. height: 32rpx;
  384. font-size: 40rpx;
  385. line-height: 1;
  386. color: #364d46;
  387. margin-bottom: 8rpx;
  388. }
  389. &__text {
  390. font-size: 24rpx;
  391. line-height: 1;
  392. }
  393. }
  394. .search-select {
  395. position: relative;
  396. width: 200rpx;
  397. font-size: 28rpx;
  398. color: #042118;
  399. padding: 0 16rpx;
  400. margin-right: 16rpx;
  401. border-right: 1px solid #e4e7ed;
  402. .icon {
  403. position: absolute;
  404. right: 32rpx;
  405. top: 50%;
  406. transform: translateY(-50%);
  407. font-size: 32rpx;
  408. }
  409. }
  410. .layer-device-status {
  411. pointer-events: auto;
  412. .status-options {
  413. display: flex;
  414. flex-direction: column;
  415. gap: 16rpx;
  416. }
  417. .status-item {
  418. display: flex;
  419. align-items: center;
  420. gap: 12rpx;
  421. cursor: pointer;
  422. .checkbox {
  423. width: 34rpx;
  424. height: 34rpx;
  425. border-radius: 10rpx;
  426. border: 3rpx solid rgba(255, 255, 255, 0.8);
  427. display: flex;
  428. align-items: center;
  429. justify-content: center;
  430. background: #fff;
  431. transition: all 0.3s ease;
  432. .checkbox-inner {
  433. width: 100%;
  434. height: 100%;
  435. border-radius: 50%;
  436. background: #4CAF50;
  437. display: flex;
  438. align-items: center;
  439. justify-content: center;
  440. .checkmark {
  441. color: white;
  442. font-size: 24rpx;
  443. font-weight: bold;
  444. }
  445. }
  446. }
  447. .status-text {
  448. font-size: 32rpx;
  449. color: white;
  450. text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.3);
  451. }
  452. &.active {
  453. .checkbox {
  454. border-color: #4CAF50;
  455. background: #4CAF50;
  456. }
  457. }
  458. }
  459. }
  460. </style>