devicePhoto.vue 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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" v-if="currentImg.addr">
  34. <movable-area class="movable-area" :style="{ height: containerHeight }">
  35. <movable-view
  36. class="movable-view"
  37. direction="all"
  38. scale="true"
  39. scale-min="1"
  40. scale-max="5"
  41. :style="{ height: containerHeight }"
  42. >
  43. <view class="image-container">
  44. <image
  45. :src="canvasImagePath || currentImg.addr"
  46. class="main-photo-image"
  47. mode="widthFix"
  48. @load="onImageLoad"
  49. />
  50. </view>
  51. </movable-view>
  52. </movable-area>
  53. <view class="photo-timestamp">{{ formatDate(currentImg.addtime) }}</view>
  54. </view>
  55. <!-- 隐藏画布,用于绘制标注图 -->
  56. <canvas
  57. canvas-id="annotatedCanvas"
  58. :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }"
  59. style="position: fixed; left: -9999px; top: -9999px;"
  60. ></canvas>
  61. <!-- 缩略图预览 -->
  62. <view class="thumbnail-preview">
  63. <view class="thumbnail-scroll">
  64. <view
  65. class="thumbnail-item"
  66. v-for="(item, index) in thumbnails"
  67. :key="index"
  68. :class="{ active: img_id == item.ids }"
  69. @click="selectThumbnail(item)"
  70. >
  71. <image
  72. :src="item.addr"
  73. class="thumbnail-image"
  74. />
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 识别结果 -->
  79. <view class="recognition-result" v-if="pestList.length">
  80. <view class="result-title">当前图片识别结果</view>
  81. <!-- 一类害虫 -->
  82. <view>
  83. <view class="pest-category" v-for="(pest,index) in pestList" :key="index">
  84. <view class="category-header">
  85. <text class="category-title">{{ pest[0] }}</text>
  86. <text class="category-count">数量</text>
  87. </view>
  88. <view class="pest-item" v-for="(p, i) in pest[1]" :key="i">
  89. <view class="pest-info">
  90. <view class="pest-color" :style="{ backgroundColor: getPestColor(p.pest_name) }"></view>
  91. <text class="pest-name">{{ p.pest_name }}</text>
  92. </view>
  93. <text class="pest-count">{{ p.pest_num }}</text>
  94. </view>
  95. </view>
  96. </view>
  97. <!-- <view v-else>
  98. <view class="pest-category" v-for="(pest,index) in pestList" :key="index">
  99. <view class="pest-item">
  100. <view class="pest-info">
  101. <view class="pest-color" :style="{ backgroundColor: getPestColor(pest[1].text) }"></view>
  102. <text class="pest-name">{{ pest[1].text }}</text>
  103. </view>
  104. <text class="pest-count">{{ pest[1].value }}</text>
  105. </view>
  106. </view>
  107. </view> -->
  108. </view>
  109. <u-empty v-else text="暂无数据"></u-empty>
  110. <u-calendar
  111. v-model="show"
  112. :mode="mode"
  113. @change="handleChange"
  114. range-color="#999"
  115. btn-type="success"
  116. active-bg-color="#0BBC58"
  117. range-bg-color="rgba(11,188,88,0.13)"
  118. :defaultDate="defaultDate"
  119. ></u-calendar>
  120. <u-picker v-model="showPicker" mode="selector" :range="selectorRange" range-key="id" :default-selector="[0]" @confirm="confirmHandler"></u-picker>
  121. </view>
  122. </template>
  123. <script>
  124. export default {
  125. data() {
  126. return {
  127. show: false,
  128. mode: 'date',
  129. maxDate: this.formatTime(new Date()),
  130. minDate: this.formatTime(new Date(new Date().getFullYear(), 0, 1)),
  131. defaultDate: this.formatTime(new Date(new Date().getFullYear(), 0, 1)),
  132. showPicker: false,
  133. selectorRange: [],
  134. title: '查看图片',
  135. currentThumbnail: 2,
  136. pestYype:{},
  137. is_mark:0,
  138. device_id: '',
  139. time_begin: this.formatTime(new Date(new Date().getFullYear(), 0, 1)),
  140. time_end: this.formatTime(new Date()),
  141. img_id: '',
  142. pest_list:[],
  143. pestList:[],
  144. colors:[
  145. '#FF5951',
  146. '#66EDED',
  147. '#E67B3E',
  148. '#6DE28B',
  149. '#FFC97A',
  150. '#E7EB4B',
  151. '#1561F3',
  152. '#FA73F5',
  153. '#159AFF',
  154. '#FA73F5'
  155. ],
  156. currentYear:'',
  157. pest_list_arr:[],
  158. thumbnails: [],
  159. addtime:'',
  160. currentImg:{},
  161. bugMarkers: [],
  162. imageWidth: 0,
  163. imageHeight: 0,
  164. imgOld_id:'',
  165. canvasImagePath: '',
  166. canvasWidth: 375,
  167. canvasHeight: 300,
  168. containerHeight: '300px',
  169. device_type_id:'',
  170. cmd:'sy',
  171. pestDict: {}, // 虫子字典 {id: name}
  172. pestColorMap: {}, // 害虫颜色映射 {pestName: color}
  173. };
  174. },
  175. async onLoad(options) {
  176. const {cmd,img_id,currentYear,addtime,device_type_id,device_id} = options
  177. this.device_id = device_id
  178. this.imgOld_id = img_id
  179. this.currentYear = currentYear
  180. this.addtime = addtime;
  181. this.device_type_id = device_type_id;
  182. this.time_begin = this.addtime;
  183. this.defaultDate = this.addtime;
  184. this.time_end = this.addtime;
  185. this.selectorRange = [];
  186. this.cmd = cmd;
  187. const nowYear = new Date().getFullYear();
  188. for(let i = 0;i<50;i++){
  189. const item = {
  190. label: nowYear - i,
  191. id: nowYear - i
  192. }
  193. this.selectorRange.push(item);
  194. }
  195. this.pestList = [];
  196. await this.getPestDict();
  197. await this.getPestLevelMap();
  198. await this.getPestList();
  199. // this.getDevicePhotoDetails();
  200. },
  201. methods: {
  202. getPestName(id){
  203. if(this.is_mark == 0){
  204. return this.pestDict[id] || id;
  205. }
  206. return id;
  207. },
  208. async confirmHandler(e){
  209. this.currentYear = this.selectorRange[e].id;
  210. if(this.currentYear == new Date().getFullYear()){
  211. this.time_begin = this.formatTime(new Date(new Date().getFullYear(), 0, 1));
  212. this.time_end = this.formatTime(new Date());
  213. this.maxDate = this.formatTime(new Date());
  214. this.minDate = this.formatTime(new Date(new Date().getFullYear(), 0, 1));
  215. }else{
  216. this.time_begin = this.formatTime(new Date(this.currentYear, 0, 1));
  217. this.time_end = this.formatTime(new Date(this.currentYear, 11, 31));
  218. this.maxDate = this.formatTime(new Date(this.currentYear, 11, 31));
  219. this.minDate = this.formatTime(new Date(this.currentYear, 0, 1));
  220. this.defaultDate = this.minDate;
  221. }
  222. this.showPicker = false;
  223. this.pestList = [];
  224. this.thumbnails = [];
  225. await this.getPestList();
  226. },
  227. async handleChange(e){
  228. console.log(e,'e')
  229. this.time_begin = e.result;
  230. this.time_end = e.result;
  231. this.pestList = [];
  232. await this.getPestList()
  233. this.currentImg = {};
  234. },
  235. getPestColor(pestName) {
  236. // 如果该害虫已有颜色,直接返回
  237. if (this.pestColorMap[pestName]) {
  238. return this.pestColorMap[pestName];
  239. }
  240. // 为新害虫分配颜色
  241. const usedColors = Object.values(this.pestColorMap);
  242. // 找一个未使用的颜色
  243. let color;
  244. for (const c of this.colors) {
  245. if (!usedColors.includes(c)) {
  246. color = c;
  247. break;
  248. }
  249. }
  250. // 如果所有颜色都用完了,使用哈希值确定颜色
  251. if (!color) {
  252. const hash = pestName.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
  253. color = this.colors[hash % this.colors.length];
  254. }
  255. this.pestColorMap[pestName] = color;
  256. return color;
  257. },
  258. getLevelDisplayName(level) {
  259. const levelMap = {
  260. '-1': '其他害虫',
  261. 1: '一类害虫',
  262. 2: '二类害虫',
  263. 3: '三类害虫',
  264. 4: '四类害虫',
  265. 5: '五类害虫'
  266. };
  267. return levelMap[String(level)] || `${level}`;
  268. },
  269. formatMinute(date,type){
  270. // 转成毫秒数
  271. if(type == 'start'){
  272. //转成开始时间的毫秒数
  273. date.setHours(0, 0, 0, 0);
  274. }else{
  275. //转成结束时间的毫秒数
  276. date.setHours(23, 59, 59, 999);
  277. }
  278. const minute = Math.floor(date.getTime() / 1000);
  279. return minute;
  280. },
  281. async getPestList() {
  282. const res = await this.$myRequest({
  283. url: '/api/api_gateway?method=new_gateway.photo_info.photo_list',
  284. method: 'POST',
  285. data: {
  286. page:1,
  287. page_size:500,
  288. id: this.device_id,
  289. start: this.formatMinute(new Date(this.time_begin),'start'),
  290. end: this.formatMinute(new Date(this.time_end),'end'),
  291. device_type_id: this.device_type_id,
  292. },
  293. });
  294. this.thumbnails = res?.data || [];
  295. this.currentImg = {};
  296. //如果和旧的id相同,就用旧的id不然就用第一个
  297. if(this.thumbnails.find(item => item.ids == this.imgOld_id)){
  298. this.img_id = this.imgOld_id
  299. }else{
  300. this.img_id = this.thumbnails[0].ids
  301. }
  302. this.getDevicePhotoDetails();
  303. },
  304. formatTime(dateString) {
  305. const date = new Date(dateString);
  306. const year = date.getFullYear();
  307. const month = String(date.getMonth() + 1).padStart(2, '0');
  308. const day = String(date.getDate()).padStart(2, '0');
  309. return `${year}-${month}-${day}`;
  310. },
  311. async getPestLevelMap() {
  312. const res = await this.$myRequest({
  313. url: '/api/api_gateway?method=forecast.new_cbd.pest_level_map',
  314. method: 'POST',
  315. });
  316. const pestYype = {}
  317. for(let key in res){
  318. pestYype[this.getLevelDisplayName(key)] = res[key]
  319. }
  320. this.pestYype = pestYype
  321. },
  322. // 获取虫子字典
  323. async getPestDict() {
  324. try {
  325. const res = await this.$myRequest({
  326. url: '/api/api_gateway?method=forecast.pest_info.pest_dict',
  327. method: 'POST',
  328. data:{
  329. type_name: '1'
  330. }
  331. });
  332. this.pestDict = res || {};
  333. } catch (error) {
  334. console.error('获取虫子字典失败:', error);
  335. this.pestDict = {};
  336. }
  337. },
  338. formatDate(dateString) {
  339. const date = new Date(dateString*1000);
  340. const year = date.getFullYear();
  341. const month = String(date.getMonth() + 1).padStart(2, '0');
  342. const day = String(date.getDate()).padStart(2, '0');
  343. const hour = String(date.getHours()).padStart(2, '0');
  344. const minute = String(date.getMinutes()).padStart(2, '0');
  345. const second = String(date.getSeconds()).padStart(2, '0');
  346. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  347. },
  348. async getDevicePhotoDetails() {
  349. const res = await this.$myRequest({
  350. url: '/api/api_gateway?method=forecast.forecast_system.device_photo_details',
  351. method: 'POST',
  352. data: {
  353. identify_model:'B',
  354. cmd:this.cmd,
  355. img_id: this.img_id,
  356. },
  357. });
  358. this.currentImg = res;
  359. this.canvasImagePath = '';
  360. // 获取图片信息和本地路径
  361. let localImagePath = '';
  362. try {
  363. const imageInfo = await new Promise((resolve, reject) => {
  364. uni.getImageInfo({
  365. src: res.addr,
  366. success: resolve,
  367. fail: reject
  368. });
  369. });
  370. this.imageWidth = imageInfo.width;
  371. this.imageHeight = imageInfo.height;
  372. localImagePath = imageInfo.path;
  373. // 计算容器高度
  374. const systemInfo = uni.getSystemInfoSync();
  375. const screenWidth = systemInfo.windowWidth;
  376. const containerWidth = screenWidth - 24;
  377. const displayHeight = (containerWidth / this.imageWidth) * this.imageHeight;
  378. this.containerHeight = displayHeight + 'px';
  379. } catch(e) {
  380. console.error('获取图片信息失败:', e);
  381. this.imageWidth = 1000;
  382. this.imageHeight = 1000;
  383. }
  384. // 处理label参数生成bugMarkers
  385. this.processBugMarkers();
  386. const pest_list = res.pest_list
  387. const pestArr = new Map()
  388. const pesAlltList = []
  389. for(let key in this.pestYype){
  390. for(let j in this.pestYype[key]){
  391. const pestName = this.pestYype[key][j]
  392. pesAlltList.push(pestName)
  393. pest_list.forEach(item => {
  394. if(item.pest_name == pestName){
  395. if(pestArr.has(key)){
  396. pestArr.get(key).push(item)
  397. }else{
  398. pestArr.set(key, [item])
  399. }
  400. }
  401. })
  402. }
  403. }
  404. pest_list.forEach(item => {
  405. if(!pesAlltList.includes(item.pest_name)){
  406. if(pestArr.has('其他害虫')){
  407. pestArr.get('其他害虫').push(item)
  408. }else{
  409. pestArr.set('其他害虫', [item])
  410. }
  411. }
  412. })
  413. const pestList = []
  414. for(let key of pestArr){
  415. pestList.push(key)
  416. }
  417. if (this.currentImg.is_mark != 0) {
  418. this.processBugMarkers();
  419. }
  420. // 绘制标注图片(异步,不阻塞)
  421. if (localImagePath) {
  422. this.drawAnnotatedImage(localImagePath);
  423. }
  424. this.pestList = pestList
  425. },
  426. onImageLoad(e) {
  427. // 仅在容器高度未计算时更新
  428. if (!this.containerHeight || this.containerHeight === '300px') {
  429. const systemInfo = uni.getSystemInfoSync();
  430. const screenWidth = systemInfo.windowWidth;
  431. const containerWidth = screenWidth - 24;
  432. const displayHeight = (containerWidth / e.detail.width) * e.detail.height;
  433. this.containerHeight = displayHeight + 'px';
  434. }
  435. },
  436. processBugMarkers() {
  437. if (this.currentImg.is_mark === 0) {
  438. if (!this.currentImg.label) {
  439. console.log('没有label参数');
  440. this.bugMarkers = [];
  441. return;
  442. }
  443. // 如果没有图片尺寸,先设置默认值
  444. if (!this.imageWidth || !this.imageHeight) {
  445. console.log('没有图片尺寸,使用默认值');
  446. this.imageWidth = 1000;
  447. this.imageHeight = 1000;
  448. }
  449. try {
  450. // 根据原图宽度计算缩放比例
  451. let scaleRatio;
  452. if (this.imageWidth >= 5000) {
  453. scaleRatio = 1;
  454. } else if (this.imageWidth >= 4000) {
  455. scaleRatio = 1;
  456. } else {
  457. scaleRatio = 1;
  458. }
  459. // 处理label参数,将单引号替换为双引号
  460. let labelStr = this.currentImg.label;
  461. labelStr = labelStr.replace(/'/g, '"');
  462. console.log(labelStr,'labelStrlabelStr')
  463. const label = JSON.parse(labelStr);
  464. const markers = [];
  465. console.log('原图宽度:', this.imageWidth, '缩放比例:', scaleRatio);
  466. label.forEach(item => {
  467. for (let key in item) {
  468. const [x1, y1, x2, y2] = item[key];
  469. // 使用缩放比例计算标记位置和尺寸
  470. const x = (x1 * scaleRatio / this.imageWidth) * 100;
  471. const y = (y1 * scaleRatio / this.imageHeight) * 100;
  472. const width = ((x2 - x1) * scaleRatio / this.imageWidth) * 100;
  473. const height = ((y2 - y1) * scaleRatio / this.imageHeight) * 100;
  474. // 从字典中获取虫子名字(尝试字符串和数字两种类型)
  475. const pestName = this.pestDict[key] || this.pestDict[String(key)] || key;
  476. const color = this.getPestColor(pestName);
  477. markers.push({
  478. id: pestName, // 显示虫子名字
  479. x,
  480. y,
  481. width,
  482. height,
  483. color
  484. });
  485. }
  486. });
  487. this.bugMarkers = markers;
  488. } catch (error) {
  489. console.error('处理label参数失败:', error);
  490. this.bugMarkers = [];
  491. }
  492. } else {
  493. // this.pestList = [];
  494. const markers = [];
  495. // 根据原图宽度计算缩放比例
  496. let scaleRatio = 3.07;
  497. // if (this.imageWidth >= 5000) {
  498. // scaleRatio = 4;
  499. // } else if (this.imageWidth >= 4000) {
  500. // scaleRatio = 1;
  501. // } else {
  502. // scaleRatio = 2.5;
  503. // }
  504. // const pestArr = new Map()
  505. this.currentImg.mark.map((item, index) => {
  506. // if(pestArr.has(item.text)){
  507. // pestArr.set(item.text,{
  508. // value: pestArr.get(item.text).value+=1,
  509. // text: item.text
  510. // })
  511. // }else{
  512. // pestArr.set(item.text, {
  513. // value: 1,
  514. // text: item.text
  515. // })
  516. // }
  517. // const pestList = []
  518. // for(let key of pestArr){
  519. // pestList.push(key)
  520. // }
  521. // this.pestList = pestList
  522. this.is_mark = 1
  523. const { startX, startY,text } = item;
  524. // 使用缩放比例计算标记位置和尺寸
  525. const x = item.width > 0 ? (startX * scaleRatio / this.imageWidth) * 105 : ((startX + item.width) * scaleRatio / this.imageWidth) * 105;
  526. const y = item.height > 0 ? (startY * scaleRatio / this.imageHeight) * 105 : ((startY + item.height) * scaleRatio / this.imageHeight) * 105;
  527. const width = (item.width > 0 ? item.width : -item.width) * scaleRatio / this.imageWidth * 100;
  528. const height = (item.height > 0 ? item.height : -item.height) * scaleRatio / this.imageHeight * 100;
  529. // 从字典中获取虫子名字(尝试字符串和数字两种类型)
  530. const pestName = text;
  531. const color = this.getPestColor(text);
  532. markers.push({
  533. id: pestName, // 显示虫子名字
  534. x,
  535. y,
  536. width,
  537. height,
  538. color
  539. });
  540. });
  541. this.bugMarkers = markers;
  542. }
  543. },
  544. async drawAnnotatedImage(localImagePath) {
  545. if (!localImagePath || !this.bugMarkers.length) {
  546. return;
  547. }
  548. try {
  549. // 计算画布尺寸(匹配显示区域)
  550. const sysInfo = uni.getSystemInfoSync();
  551. const displayWidth = sysInfo.windowWidth - 24;
  552. const displayHeight = (displayWidth / this.imageWidth) * this.imageHeight;
  553. this.canvasWidth = Math.round(displayWidth);
  554. this.canvasHeight = Math.round(displayHeight);
  555. // 等待画布尺寸更新
  556. await this.$nextTick();
  557. const ctx = uni.createCanvasContext('annotatedCanvas', this);
  558. // 绘制原始图片
  559. ctx.drawImage(localImagePath, 0, 0, this.canvasWidth, this.canvasHeight);
  560. // 绘制虫子标记
  561. this.bugMarkers.forEach(marker => {
  562. const x = (marker.x / 100) * this.canvasWidth;
  563. const y = (marker.y / 100) * this.canvasHeight;
  564. const w = (marker.width / 100) * this.canvasWidth;
  565. const h = (marker.height / 100) * this.canvasHeight;
  566. // 绘制矩形框
  567. ctx.setStrokeStyle(marker.color);
  568. ctx.setLineWidth(1);
  569. ctx.strokeRect(x, y, w, h);
  570. // 绘制标签(上方优先,超出画布上边界时放到框下方)
  571. const pestName = this.getPestName(marker.id);
  572. const fontSize = 12;
  573. ctx.setFontSize(fontSize);
  574. ctx.setFillStyle(marker.color);
  575. if (y - fontSize - 4 < 0) {
  576. ctx.fillText(pestName, x + 4, y + h + fontSize + 4);
  577. } else {
  578. ctx.fillText(pestName, x + 4, y - 4);
  579. }
  580. });
  581. // 提交绘制
  582. await new Promise((resolve) => {
  583. ctx.draw(false, () => {
  584. setTimeout(resolve, 300);
  585. });
  586. });
  587. // 转为临时图片
  588. const tempFile = await new Promise((resolve, reject) => {
  589. uni.canvasToTempFilePath({
  590. canvasId: 'annotatedCanvas',
  591. x: 0,
  592. y: 0,
  593. width: this.canvasWidth,
  594. height: this.canvasHeight,
  595. destWidth: this.canvasWidth * 2,
  596. destHeight: this.canvasHeight * 2,
  597. success: resolve,
  598. fail: reject
  599. }, this);
  600. });
  601. this.canvasImagePath = tempFile.tempFilePath;
  602. } catch (error) {
  603. console.error('绘制标注图片失败:', error);
  604. this.canvasImagePath = '';
  605. }
  606. },
  607. handleBack() {
  608. uni.navigateBack({
  609. delta: 1
  610. });
  611. },
  612. goBack() {
  613. uni.navigateBack();
  614. },
  615. selectThumbnail(item) {
  616. this.img_id = item.ids;
  617. this.getDevicePhotoDetails();
  618. }
  619. }
  620. };
  621. </script>
  622. <style lang="scss" scoped>
  623. ::v-deep .u-calendar__action{
  624. display:flex;
  625. justify-content: space-between;
  626. }
  627. ::v-deep .u-hover-class{
  628. .u-calendar__content__item__inner{
  629. color:#aaa !important;
  630. }
  631. }
  632. .device-photo-page {
  633. background-color: #F5F5F5;
  634. min-height: 100vh;
  635. width: 100%;
  636. padding-top: 112rpx;
  637. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  638. .device-detail__header {
  639. width: 100%;
  640. font-size: 28rpx;
  641. color: #999;
  642. color: #042118;
  643. font-family: 'Source Han Sans CN VF';
  644. font-weight: 700;
  645. position: relative;
  646. text-align: center;
  647. .arrow-left {
  648. position: absolute;
  649. left: 32rpx;
  650. margin-right: 12rpx;
  651. }
  652. }
  653. /* 顶部导航栏 */
  654. .nav-bar {
  655. display: flex;
  656. align-items: center;
  657. justify-content: space-between;
  658. padding: 24rpx;
  659. background-color: #E6F7EF;
  660. .nav-left {
  661. .back-icon {
  662. font-size: 36rpx;
  663. color: #042118;
  664. }
  665. }
  666. .nav-title {
  667. font-size: 32rpx;
  668. font-weight: 700;
  669. color: #042118;
  670. }
  671. .nav-right {
  672. display: flex;
  673. align-items: center;
  674. .more-icon {
  675. font-size: 32rpx;
  676. color: #042118;
  677. margin-right: 24rpx;
  678. }
  679. .eye-icon {
  680. font-size: 32rpx;
  681. }
  682. }
  683. }
  684. .date-container{
  685. padding: 0 20rpx;
  686. display: flex;
  687. align-items: center;
  688. justify-content: center;
  689. .select-year{
  690. width: 150rpx;
  691. height: 80rpx;
  692. display: flex;
  693. align-items: center;
  694. justify-content: space-around;
  695. color: #656565;
  696. font-size: 26rpx;
  697. line-height: 80rpx;
  698. text-align: center;
  699. border-radius: 48rpx;
  700. background-color: #FFFFFF;
  701. margin-right: 10rpx;
  702. padding: 0 26rpx;
  703. .select-year-item{
  704. width: 100%;
  705. display: flex;
  706. align-items: center;
  707. justify-content: space-around;
  708. }
  709. }
  710. }
  711. /* 日期选择器 */
  712. .date-picker {
  713. display: flex;
  714. align-items: center;
  715. padding: 20rpx 24rpx;
  716. background-color: #FFFFFF;
  717. margin-bottom: 24rpx;
  718. width: 100%;
  719. margin:20rpx auto;
  720. border-radius: 48rpx;
  721. position: relative;
  722. .date-input {
  723. display: flex;
  724. flex-direction: column;
  725. width: 100%;
  726. text-align: center;
  727. .date-label {
  728. font-size: 24rpx;
  729. color: #999999;
  730. margin-bottom: 8rpx;
  731. }
  732. .date-value {
  733. font-size: 28rpx;
  734. color: #042118;
  735. font-weight: 500;
  736. }
  737. }
  738. .calendar {
  739. position: absolute;
  740. right: 24rpx;
  741. top: 50%;
  742. transform: translateY(-50%);
  743. font-size: 32rpx;
  744. color: #999999;
  745. }
  746. .date-separator {
  747. margin: 0 24rpx;
  748. font-size: 28rpx;
  749. color: #999999;
  750. }
  751. }
  752. /* 主图片区域 */
  753. .main-photo {
  754. position: relative;
  755. margin: 0 24rpx 24rpx;
  756. background-color: #FFFFFF;
  757. border-radius: 16rpx;
  758. padding: 0;
  759. overflow: hidden;
  760. .movable-area {
  761. width: 100%;
  762. overflow: hidden;
  763. }
  764. .movable-view {
  765. width: 100%;
  766. }
  767. .image-container {
  768. position: relative;
  769. width: 100%;
  770. }
  771. .main-photo-image {
  772. width: 100%;
  773. display: block;
  774. }
  775. /* 虫子标记层 */
  776. .bug-markers {
  777. position: absolute;
  778. top: 0;
  779. left: 0;
  780. width: 100%;
  781. height: 100%;
  782. pointer-events: none;
  783. }
  784. /* 虫子标记 */
  785. .bug-marker {
  786. position: absolute;
  787. border: 2rpx solid;
  788. border-radius: 4rpx;
  789. }
  790. /* 虫子标记标签 */
  791. .bug-label {
  792. position: absolute;
  793. top: -24rpx;
  794. left: 0;
  795. padding: 2rpx 6rpx;
  796. border-radius: 4rpx;
  797. font-size: 20rpx;
  798. color: white;
  799. white-space: nowrap;
  800. }
  801. /* 虫子标记层 */
  802. .bug-markers {
  803. position: absolute;
  804. top: 0;
  805. left: 0;
  806. width: 100%;
  807. height: 100%;
  808. pointer-events: none;
  809. }
  810. /* 虫子标记 */
  811. .bug-marker {
  812. position: absolute;
  813. border: 2rpx solid;
  814. border-radius: 4rpx;
  815. pointer-events: auto;
  816. }
  817. /* 虫子标记标签 */
  818. .bug-label {
  819. position: absolute;
  820. top: -30rpx;
  821. left: 0;
  822. padding: 4rpx 8rpx;
  823. border-radius: 4rpx;
  824. font-size: 20rpx;
  825. font-weight: bold;
  826. }
  827. .photo-timestamp {
  828. position: absolute;
  829. bottom: 0rpx;
  830. left: 0rpx;
  831. width:100%;
  832. background-color: rgba(0, 0, 0, 0.6);
  833. color: #FFFFFF;
  834. padding: 8rpx 16rpx;
  835. border-radius: 8rpx;
  836. font-size: 24rpx;
  837. }
  838. }
  839. /* 缩略图预览 */
  840. .thumbnail-preview {
  841. margin: 0 24rpx 24rpx;
  842. .thumbnail-scroll {
  843. gap: 16rpx;
  844. padding-bottom: 16rpx;
  845. box-sizing: border-box;
  846. white-space: nowrap;
  847. overflow-x: auto;
  848. overflow-y: hidden;
  849. width: 100%;
  850. // 隐藏滚动条
  851. -ms-overflow-style: none;
  852. scrollbar-width: none;
  853. .thumbnail-item {
  854. width: 120rpx;
  855. height: 120rpx;
  856. border-radius: 8rpx;
  857. overflow: hidden;
  858. border: 2rpx solid transparent;
  859. display: inline-block;
  860. box-sizing: border-box;
  861. margin-right: 10rpx;
  862. &.active {
  863. border-color: #0BBC58;
  864. }
  865. .thumbnail-image {
  866. width: 100%;
  867. height: 100%;
  868. object-fit: cover;
  869. }
  870. }
  871. }
  872. }
  873. /* 识别结果 */
  874. .recognition-result {
  875. margin: 0 24rpx 24rpx;
  876. background-color: #FFFFFF;
  877. border-radius: 16rpx;
  878. padding: 24rpx;
  879. .result-title {
  880. font-size: 28rpx;
  881. font-weight: 700;
  882. color: #042118;
  883. margin-bottom: 24rpx;
  884. }
  885. /* 害虫类别 */
  886. .pest-category {
  887. margin-bottom: 32rpx;
  888. border: 1px solid #E4E7ED;
  889. border-radius: 16rpx;
  890. &:last-child {
  891. margin-bottom: 0;
  892. }
  893. .category-header {
  894. display: flex;
  895. justify-content: space-between;
  896. margin-bottom: 16rpx;
  897. background: #F6F8FC;
  898. padding: 18rpx 24rpx;
  899. .category-title {
  900. font-size: 24rpx;
  901. font-weight: 500;
  902. color: #042118;
  903. }
  904. .category-count {
  905. font-size: 24rpx;
  906. color: #999999;
  907. }
  908. }
  909. .pest-item {
  910. display: flex;
  911. justify-content: space-between;
  912. align-items: center;
  913. margin-bottom: 12rpx;
  914. padding: 6rpx 24rpx;
  915. &:last-child {
  916. margin-bottom: 0;
  917. }
  918. .pest-info {
  919. display: flex;
  920. align-items: center;
  921. .pest-color {
  922. width: 16rpx;
  923. height: 16rpx;
  924. border-radius: 50%;
  925. margin-right: 12rpx;
  926. }
  927. .pest-name {
  928. font-size: 24rpx;
  929. color: #042118;
  930. }
  931. }
  932. .pest-count {
  933. font-size: 24rpx;
  934. color: #042118;
  935. }
  936. }
  937. }
  938. }
  939. }
  940. </style>