devicePhoto.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <view class="device-photo-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="device-detail__header">
  5. <u-icon
  6. size="36"
  7. class="arrow-left"
  8. name="arrow-left"
  9. @click="handleBack"
  10. ></u-icon>
  11. {{ title }}
  12. </view>
  13. <!-- 日期选择器 -->
  14. <view class="date-container">
  15. <view class="select-year">
  16. <view class="select-year-item" @click="showPicker = true">
  17. {{ currentYear }}
  18. <u-icon name="arrow-down" size="18" class="arrow-down"></u-icon>
  19. </view>
  20. </view>
  21. <view class="date-picker" @click="show = true">
  22. <view class="date-input">
  23. <text class="date-label">{{ time_begin || '-' }}</text>
  24. </view>
  25. <view class="date-separator">-</view>
  26. <view class="date-input">
  27. <text class="date-label">{{ time_end || '-' }}</text>
  28. </view>
  29. <u-icon name="calendar" class="calendar"></u-icon>
  30. </view>
  31. </view>
  32. <!-- 主图片区域 -->
  33. <view class="main-photo">
  34. <image
  35. :src="currentImg.addr"
  36. class="main-photo-image"
  37. />
  38. <view class="photo-timestamp">{{ formatDate(currentImg.addtime) }}</view>
  39. </view>
  40. <!-- 缩略图预览 -->
  41. <view class="thumbnail-preview">
  42. <view class="thumbnail-scroll">
  43. <view
  44. class="thumbnail-item"
  45. v-for="(item, index) in thumbnails"
  46. :key="index"
  47. :class="{ active: img_id == item.ids }"
  48. @click="selectThumbnail(item)"
  49. >
  50. <image
  51. :src="item.addr"
  52. class="thumbnail-image"
  53. />
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 识别结果 -->
  58. <view class="recognition-result">
  59. <view class="result-title">当前图片识别结果</view>
  60. <!-- 一类害虫 -->
  61. <view class="pest-category" v-for="(pest,index) in pestList" :key="index">
  62. <view class="category-header">
  63. <text class="category-title">{{ pest[0] }}</text>
  64. <text class="category-count">数量</text>
  65. </view>
  66. <view class="pest-item" v-for="(p, i) in pest[1]" :key="i">
  67. <view class="pest-info">
  68. <view class="pest-color" :style="{ backgroundColor: getRandomColor() }"></view>
  69. <text class="pest-name">{{ p.pest_name }}</text>
  70. </view>
  71. <text class="pest-count">{{ p.pest_num }}</text>
  72. </view>
  73. </view>
  74. </view>
  75. <u-calendar v-model="show" :mode="mode" @change="handleChange" :max-date="maxDate" :min-date="minDate"></u-calendar>
  76. <u-picker v-model="showPicker" mode="selector" :range="selectorRange" range-key="id" :default-selector="[0]" @confirm="confirmHandler"></u-picker>
  77. </view>
  78. </template>
  79. <script>
  80. export default {
  81. data() {
  82. return {
  83. show: false,
  84. mode: 'range',
  85. maxDate: this.formatTime(new Date()),
  86. minDate: this.formatTime(new Date(new Date().getFullYear(), 0, 1)),
  87. showPicker: false,
  88. selectorRange: [],
  89. title: '查看图片',
  90. currentThumbnail: 2,
  91. pestYype:{},
  92. device_id: '',
  93. time_begin: this.formatTime(new Date(new Date().getFullYear(), 0, 1)),
  94. time_end: this.formatTime(new Date()),
  95. img_id: '',
  96. pest_list:[],
  97. pestList:[],
  98. colors:[
  99. '#FF5951',
  100. '#66EDED',
  101. '#E67B3E',
  102. '#6DE28B',
  103. '#FFC97A',
  104. '#E7EB4B',
  105. '#1561F3',
  106. '#FA73F5',
  107. '#159AFF',
  108. '#FA73F5'
  109. ],
  110. currentYear:'',
  111. pest_list_arr:[],
  112. thumbnails: [],
  113. currentImg:{},
  114. };
  115. },
  116. onLoad(options) {
  117. const {id,img_id,currentYear} = options
  118. this.device_id = id
  119. this.img_id = img_id
  120. this.currentYear = currentYear
  121. this.time_begin = this.currentYear + '-01-01'
  122. this.time_end = this.currentYear + '-12-31'
  123. this.maxDate = this.formatTime(new Date())
  124. this.minDate = this.formatTime(new Date(new Date().getFullYear(), 0, 1))
  125. this.selectorRange = [];
  126. const nowYear = new Date().getFullYear();
  127. for(let i = 0;i<50;i++){
  128. const item = {
  129. label: nowYear - i,
  130. id: nowYear - i
  131. }
  132. this.selectorRange.push(item);
  133. }
  134. this.getPestLevelMap();
  135. this.getPestList();
  136. this.getDevicePhotoDetails();
  137. },
  138. methods: {
  139. confirmHandler(e){
  140. this.currentYear = this.selectorRange[e].id;
  141. if(this.currentYear == new Date().getFullYear()){
  142. this.time_begin = this.formatTime(new Date(new Date().getFullYear(), 0, 1));
  143. this.time_end = this.formatTime(new Date());
  144. this.maxDate = this.formatTime(new Date());
  145. this.minDate = this.formatTime(new Date(new Date().getFullYear(), 0, 1));
  146. }else{
  147. this.time_begin = this.formatTime(new Date(this.currentYear, 0, 1));
  148. this.time_end = this.formatTime(new Date(this.currentYear, 11, 31));
  149. this.maxDate = this.formatTime(new Date(this.currentYear, 11, 31));
  150. this.minDate = this.formatTime(new Date(this.currentYear, 0, 1));
  151. }
  152. this.showPicker = false;
  153. },
  154. handleChange(e){
  155. console.log(e,'e')
  156. this.time_begin = e.startDate;
  157. this.time_begin = e.endDate;
  158. this.getPestList()
  159. },
  160. getRandomColor(){
  161. return this.colors[Math.floor(Math.random() * this.colors.length)]
  162. },
  163. getLevelDisplayName(level) {
  164. const levelMap = {
  165. '-1': '其他害虫',
  166. 1: '一类害虫',
  167. 2: '二类害虫',
  168. 3: '三类害虫',
  169. 4: '四类害虫',
  170. 5: '五类害虫'
  171. };
  172. return levelMap[String(level)] || `${level}`;
  173. },
  174. async getPestList() {
  175. const res = await this.$myRequest({
  176. url: '/api/api_gateway?method=forecast.new_cbd.photo_list',
  177. method: 'POST',
  178. data: {
  179. identify_model:'B',
  180. cmd:'cbd',
  181. time_begin: this.time_begin + ' 00:00:00',
  182. time_end: this.time_end + ' 23:59:59',
  183. identify_model:'B',
  184. device_id: this.device_id,
  185. },
  186. });
  187. this.thumbnails = res?.data || [];
  188. console.log(this.thumbnails,'resres2222res')
  189. },
  190. formatTime(dateString) {
  191. const date = new Date(dateString);
  192. const year = date.getFullYear();
  193. const month = String(date.getMonth() + 1).padStart(2, '0');
  194. const day = String(date.getDate()).padStart(2, '0');
  195. return `${year}-${month}-${day}`;
  196. },
  197. async getPestLevelMap() {
  198. const res = await this.$myRequest({
  199. url: '/api/api_gateway?method=forecast.new_cbd.pest_level_map',
  200. method: 'POST',
  201. });
  202. const pestYype = {}
  203. for(let key in res){
  204. pestYype[this.getLevelDisplayName(key)] = res[key]
  205. }
  206. this.pestYype = pestYype
  207. },
  208. formatDate(dateString) {
  209. const date = new Date(dateString*1000);
  210. const year = date.getFullYear();
  211. const month = String(date.getMonth() + 1).padStart(2, '0');
  212. const day = String(date.getDate()).padStart(2, '0');
  213. const hour = String(date.getHours()).padStart(2, '0');
  214. const minute = String(date.getMinutes()).padStart(2, '0');
  215. const second = String(date.getSeconds()).padStart(2, '0');
  216. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  217. },
  218. async getDevicePhotoDetails() {
  219. const res = await this.$myRequest({
  220. url: '/api/api_gateway?method=forecast.forecast_system.device_photo_details',
  221. method: 'POST',
  222. data: {
  223. identify_model:'B',
  224. cmd:'cbd',
  225. img_id: this.img_id,
  226. },
  227. });
  228. this.currentImg = res;
  229. const pest_list = res.pest_list
  230. const pestArr = new Map()
  231. for(let key in this.pestYype){
  232. for(let j in this.pestYype[key]){
  233. const pestName = this.pestYype[key][j]
  234. pest_list.forEach(item => {
  235. if(item.pest_name == pestName){
  236. if(pestArr.has(item.level)){
  237. pestArr.get(key).push(item)
  238. }else{
  239. pestArr.set(key, [item])
  240. }
  241. }
  242. })
  243. }
  244. }
  245. const pestList = []
  246. for(let key of pestArr){
  247. pestList.push(key)
  248. }
  249. this.pestList = pestList
  250. },
  251. handleBack() {
  252. uni.navigateBack({
  253. delta: 1
  254. });
  255. },
  256. goBack() {
  257. uni.navigateBack();
  258. },
  259. selectThumbnail(item) {
  260. this.img_id = item.ids;
  261. this.getDevicePhotoDetails();
  262. }
  263. }
  264. };
  265. </script>
  266. <style lang="scss" scoped>
  267. .device-photo-page {
  268. background-color: #F5F5F5;
  269. min-height: 100vh;
  270. width: 100%;
  271. padding-top: 112rpx;
  272. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  273. .device-detail__header {
  274. width: 100%;
  275. font-size: 28rpx;
  276. color: #999;
  277. color: #042118;
  278. font-family: 'Source Han Sans CN VF';
  279. font-weight: 700;
  280. position: relative;
  281. text-align: center;
  282. .arrow-left {
  283. position: absolute;
  284. left: 32rpx;
  285. margin-right: 12rpx;
  286. }
  287. }
  288. /* 顶部导航栏 */
  289. .nav-bar {
  290. display: flex;
  291. align-items: center;
  292. justify-content: space-between;
  293. padding: 24rpx;
  294. background-color: #E6F7EF;
  295. .nav-left {
  296. .back-icon {
  297. font-size: 36rpx;
  298. color: #042118;
  299. }
  300. }
  301. .nav-title {
  302. font-size: 32rpx;
  303. font-weight: 700;
  304. color: #042118;
  305. }
  306. .nav-right {
  307. display: flex;
  308. align-items: center;
  309. .more-icon {
  310. font-size: 32rpx;
  311. color: #042118;
  312. margin-right: 24rpx;
  313. }
  314. .eye-icon {
  315. font-size: 32rpx;
  316. }
  317. }
  318. }
  319. .date-container{
  320. padding: 0 20rpx;
  321. display: flex;
  322. align-items: center;
  323. justify-content: center;
  324. .select-year{
  325. width: 150rpx;
  326. height: 80rpx;
  327. display: flex;
  328. align-items: center;
  329. justify-content: space-around;
  330. color: #656565;
  331. font-size: 26rpx;
  332. line-height: 80rpx;
  333. text-align: center;
  334. border-radius: 48rpx;
  335. background-color: #FFFFFF;
  336. margin-right: 10rpx;
  337. padding: 0 26rpx;
  338. .select-year-item{
  339. width: 100%;
  340. display: flex;
  341. align-items: center;
  342. justify-content: space-around;
  343. }
  344. }
  345. }
  346. /* 日期选择器 */
  347. .date-picker {
  348. display: flex;
  349. align-items: center;
  350. padding: 20rpx 24rpx;
  351. background-color: #FFFFFF;
  352. margin-bottom: 24rpx;
  353. width: 90%;
  354. margin:20rpx auto;
  355. border-radius: 48rpx;
  356. position: relative;
  357. .date-input {
  358. display: flex;
  359. flex-direction: column;
  360. width: 35%;
  361. .date-label {
  362. font-size: 24rpx;
  363. color: #999999;
  364. margin-bottom: 8rpx;
  365. }
  366. .date-value {
  367. font-size: 28rpx;
  368. color: #042118;
  369. font-weight: 500;
  370. }
  371. }
  372. .calendar {
  373. position: absolute;
  374. right: 24rpx;
  375. top: 50%;
  376. transform: translateY(-50%);
  377. font-size: 32rpx;
  378. color: #999999;
  379. }
  380. .date-separator {
  381. margin: 0 24rpx;
  382. font-size: 28rpx;
  383. color: #999999;
  384. }
  385. }
  386. /* 主图片区域 */
  387. .main-photo {
  388. position: relative;
  389. margin: 0 24rpx 24rpx;
  390. background-color: #FFFFFF;
  391. border-radius: 16rpx;
  392. padding: 0;
  393. overflow: hidden;
  394. .main-photo-image {
  395. width: 100%;
  396. height: 400rpx;
  397. object-fit: cover;
  398. border-radius: 8rpx;
  399. }
  400. .photo-timestamp {
  401. position: absolute;
  402. bottom: 0rpx;
  403. left: 0rpx;
  404. width:100%;
  405. background-color: rgba(0, 0, 0, 0.6);
  406. color: #FFFFFF;
  407. padding: 8rpx 16rpx;
  408. border-radius: 8rpx;
  409. font-size: 24rpx;
  410. }
  411. }
  412. /* 缩略图预览 */
  413. .thumbnail-preview {
  414. margin: 0 24rpx 24rpx;
  415. .thumbnail-scroll {
  416. gap: 16rpx;
  417. padding-bottom: 16rpx;
  418. box-sizing: border-box;
  419. white-space: nowrap;
  420. overflow-x: auto;
  421. overflow-y: hidden;
  422. width: 100%;
  423. // 隐藏滚动条
  424. -ms-overflow-style: none;
  425. scrollbar-width: none;
  426. .thumbnail-item {
  427. width: 120rpx;
  428. height: 120rpx;
  429. border-radius: 8rpx;
  430. overflow: hidden;
  431. border: 2rpx solid transparent;
  432. display: inline-block;
  433. box-sizing: border-box;
  434. margin-right: 10rpx;
  435. &.active {
  436. border-color: #0BBC58;
  437. }
  438. .thumbnail-image {
  439. width: 100%;
  440. height: 100%;
  441. object-fit: cover;
  442. }
  443. }
  444. }
  445. }
  446. /* 识别结果 */
  447. .recognition-result {
  448. margin: 0 24rpx 24rpx;
  449. background-color: #FFFFFF;
  450. border-radius: 16rpx;
  451. padding: 24rpx;
  452. .result-title {
  453. font-size: 28rpx;
  454. font-weight: 700;
  455. color: #042118;
  456. margin-bottom: 24rpx;
  457. }
  458. /* 害虫类别 */
  459. .pest-category {
  460. margin-bottom: 32rpx;
  461. border: 1px solid #E4E7ED;
  462. border-radius: 16rpx;
  463. &:last-child {
  464. margin-bottom: 0;
  465. }
  466. .category-header {
  467. display: flex;
  468. justify-content: space-between;
  469. margin-bottom: 16rpx;
  470. background: #F6F8FC;
  471. padding: 18rpx 24rpx;
  472. .category-title {
  473. font-size: 24rpx;
  474. font-weight: 500;
  475. color: #042118;
  476. }
  477. .category-count {
  478. font-size: 24rpx;
  479. color: #999999;
  480. }
  481. }
  482. .pest-item {
  483. display: flex;
  484. justify-content: space-between;
  485. align-items: center;
  486. margin-bottom: 12rpx;
  487. padding: 6rpx 24rpx;
  488. &:last-child {
  489. margin-bottom: 0;
  490. }
  491. .pest-info {
  492. display: flex;
  493. align-items: center;
  494. .pest-color {
  495. width: 16rpx;
  496. height: 16rpx;
  497. border-radius: 50%;
  498. margin-right: 12rpx;
  499. }
  500. .pest-name {
  501. font-size: 24rpx;
  502. color: #042118;
  503. }
  504. }
  505. .pest-count {
  506. font-size: 24rpx;
  507. color: #042118;
  508. }
  509. }
  510. }
  511. }
  512. }
  513. </style>