devicePhoto.vue 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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. // if (this.originalW >= 5000) {
  497. // this.baseScale = 0.25;
  498. // } else if (this.originalW >= 4000) {
  499. // this.baseScale = 0.31;
  500. // } else {
  501. // this.baseScale = 0.4;
  502. // }
  503. let scaleRatio = 3.07;
  504. if (this.imageWidth >= 5000) {
  505. scaleRatio = 4;
  506. } else if (this.imageWidth >= 4000) {
  507. scaleRatio = 100/31;
  508. } else {
  509. scaleRatio = 2.5;
  510. }
  511. // const pestArr = new Map()
  512. this.currentImg.mark.map((item, index) => {
  513. // if(pestArr.has(item.text)){
  514. // pestArr.set(item.text,{
  515. // value: pestArr.get(item.text).value+=1,
  516. // text: item.text
  517. // })
  518. // }else{
  519. // pestArr.set(item.text, {
  520. // value: 1,
  521. // text: item.text
  522. // })
  523. // }
  524. // const pestList = []
  525. // for(let key of pestArr){
  526. // pestList.push(key)
  527. // }
  528. // this.pestList = pestList
  529. this.is_mark = 1
  530. const { startX, startY,text } = item;
  531. // 使用缩放比例计算标记位置和尺寸
  532. const x = item.width > 0 ? (startX * scaleRatio / this.imageWidth) * 100 : ((startX + item.width) * scaleRatio / this.imageWidth) * 100;
  533. const y = item.height > 0 ? (startY * scaleRatio / this.imageHeight) * 100 : ((startY + item.height) * scaleRatio / this.imageHeight) * 100;
  534. const width = (item.width > 0 ? item.width : -item.width) * scaleRatio / this.imageWidth * 100;
  535. const height = (item.height > 0 ? item.height : -item.height) * scaleRatio / this.imageHeight * 100;
  536. // 从字典中获取虫子名字(尝试字符串和数字两种类型)
  537. const pestName = text;
  538. const color = this.getPestColor(text);
  539. markers.push({
  540. id: pestName, // 显示虫子名字
  541. x,
  542. y,
  543. width,
  544. height,
  545. color
  546. });
  547. });
  548. this.bugMarkers = markers;
  549. }
  550. },
  551. async drawAnnotatedImage(localImagePath) {
  552. if (!localImagePath || !this.bugMarkers.length) {
  553. return;
  554. }
  555. try {
  556. // 计算画布尺寸(匹配显示区域)
  557. const sysInfo = uni.getSystemInfoSync();
  558. const displayWidth = sysInfo.windowWidth - 24;
  559. const displayHeight = (displayWidth / this.imageWidth) * this.imageHeight;
  560. this.canvasWidth = Math.round(displayWidth);
  561. this.canvasHeight = Math.round(displayHeight);
  562. // 等待画布尺寸更新
  563. await this.$nextTick();
  564. const ctx = uni.createCanvasContext('annotatedCanvas', this);
  565. // 绘制原始图片
  566. ctx.drawImage(localImagePath, 0, 0, this.canvasWidth, this.canvasHeight);
  567. // 绘制虫子标记
  568. this.bugMarkers.forEach(marker => {
  569. const x = (marker.x / 100) * this.canvasWidth;
  570. const y = (marker.y / 100) * this.canvasHeight;
  571. const w = (marker.width / 100) * this.canvasWidth;
  572. const h = (marker.height / 100) * this.canvasHeight;
  573. // 绘制矩形框
  574. ctx.setStrokeStyle(marker.color);
  575. ctx.setLineWidth(1);
  576. ctx.strokeRect(x, y, w, h);
  577. // 绘制标签(上方优先,超出画布上边界时放到框下方)
  578. const pestName = this.getPestName(marker.id);
  579. const fontSize = 12;
  580. ctx.setFontSize(fontSize);
  581. ctx.setFillStyle(marker.color);
  582. if (y - fontSize - 4 < 0) {
  583. ctx.fillText(pestName, x + 4, y + h + fontSize + 4);
  584. } else {
  585. ctx.fillText(pestName, x + 4, y - 4);
  586. }
  587. });
  588. // 提交绘制
  589. await new Promise((resolve) => {
  590. ctx.draw(false, () => {
  591. setTimeout(resolve, 300);
  592. });
  593. });
  594. // 转为临时图片
  595. const tempFile = await new Promise((resolve, reject) => {
  596. uni.canvasToTempFilePath({
  597. canvasId: 'annotatedCanvas',
  598. x: 0,
  599. y: 0,
  600. width: this.canvasWidth,
  601. height: this.canvasHeight,
  602. destWidth: this.canvasWidth * 2,
  603. destHeight: this.canvasHeight * 2,
  604. success: resolve,
  605. fail: reject
  606. }, this);
  607. });
  608. this.canvasImagePath = tempFile.tempFilePath;
  609. } catch (error) {
  610. console.error('绘制标注图片失败:', error);
  611. this.canvasImagePath = '';
  612. }
  613. },
  614. handleBack() {
  615. uni.navigateBack({
  616. delta: 1
  617. });
  618. },
  619. goBack() {
  620. uni.navigateBack();
  621. },
  622. selectThumbnail(item) {
  623. this.img_id = item.ids;
  624. this.getDevicePhotoDetails();
  625. }
  626. }
  627. };
  628. </script>
  629. <style lang="scss" scoped>
  630. ::v-deep .u-calendar__action{
  631. display:flex;
  632. justify-content: space-between;
  633. }
  634. ::v-deep .u-hover-class{
  635. .u-calendar__content__item__inner{
  636. color:#aaa !important;
  637. }
  638. }
  639. .device-photo-page {
  640. background-color: #F5F5F5;
  641. min-height: 100vh;
  642. width: 100%;
  643. padding-top: 112rpx;
  644. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  645. .device-detail__header {
  646. width: 100%;
  647. font-size: 28rpx;
  648. color: #999;
  649. color: #042118;
  650. font-family: 'Source Han Sans CN VF';
  651. font-weight: 700;
  652. position: relative;
  653. text-align: center;
  654. .arrow-left {
  655. position: absolute;
  656. left: 32rpx;
  657. margin-right: 12rpx;
  658. }
  659. }
  660. /* 顶部导航栏 */
  661. .nav-bar {
  662. display: flex;
  663. align-items: center;
  664. justify-content: space-between;
  665. padding: 24rpx;
  666. background-color: #E6F7EF;
  667. .nav-left {
  668. .back-icon {
  669. font-size: 36rpx;
  670. color: #042118;
  671. }
  672. }
  673. .nav-title {
  674. font-size: 32rpx;
  675. font-weight: 700;
  676. color: #042118;
  677. }
  678. .nav-right {
  679. display: flex;
  680. align-items: center;
  681. .more-icon {
  682. font-size: 32rpx;
  683. color: #042118;
  684. margin-right: 24rpx;
  685. }
  686. .eye-icon {
  687. font-size: 32rpx;
  688. }
  689. }
  690. }
  691. .date-container{
  692. padding: 0 20rpx;
  693. display: flex;
  694. align-items: center;
  695. justify-content: center;
  696. .select-year{
  697. width: 150rpx;
  698. height: 80rpx;
  699. display: flex;
  700. align-items: center;
  701. justify-content: space-around;
  702. color: #656565;
  703. font-size: 26rpx;
  704. line-height: 80rpx;
  705. text-align: center;
  706. border-radius: 48rpx;
  707. background-color: #FFFFFF;
  708. margin-right: 10rpx;
  709. padding: 0 26rpx;
  710. .select-year-item{
  711. width: 100%;
  712. display: flex;
  713. align-items: center;
  714. justify-content: space-around;
  715. }
  716. }
  717. }
  718. /* 日期选择器 */
  719. .date-picker {
  720. display: flex;
  721. align-items: center;
  722. padding: 20rpx 24rpx;
  723. background-color: #FFFFFF;
  724. margin-bottom: 24rpx;
  725. width: 100%;
  726. margin:20rpx auto;
  727. border-radius: 48rpx;
  728. position: relative;
  729. .date-input {
  730. display: flex;
  731. flex-direction: column;
  732. width: 100%;
  733. text-align: center;
  734. .date-label {
  735. font-size: 24rpx;
  736. color: #999999;
  737. margin-bottom: 8rpx;
  738. }
  739. .date-value {
  740. font-size: 28rpx;
  741. color: #042118;
  742. font-weight: 500;
  743. }
  744. }
  745. .calendar {
  746. position: absolute;
  747. right: 24rpx;
  748. top: 50%;
  749. transform: translateY(-50%);
  750. font-size: 32rpx;
  751. color: #999999;
  752. }
  753. .date-separator {
  754. margin: 0 24rpx;
  755. font-size: 28rpx;
  756. color: #999999;
  757. }
  758. }
  759. /* 主图片区域 */
  760. .main-photo {
  761. position: relative;
  762. margin: 0 24rpx 24rpx;
  763. background-color: #FFFFFF;
  764. border-radius: 16rpx;
  765. padding: 0;
  766. overflow: hidden;
  767. .movable-area {
  768. width: 100%;
  769. overflow: hidden;
  770. }
  771. .movable-view {
  772. width: 100%;
  773. }
  774. .image-container {
  775. position: relative;
  776. width: 100%;
  777. }
  778. .main-photo-image {
  779. width: 100%;
  780. display: block;
  781. }
  782. /* 虫子标记层 */
  783. .bug-markers {
  784. position: absolute;
  785. top: 0;
  786. left: 0;
  787. width: 100%;
  788. height: 100%;
  789. pointer-events: none;
  790. }
  791. /* 虫子标记 */
  792. .bug-marker {
  793. position: absolute;
  794. border: 2rpx solid;
  795. border-radius: 4rpx;
  796. }
  797. /* 虫子标记标签 */
  798. .bug-label {
  799. position: absolute;
  800. top: -24rpx;
  801. left: 0;
  802. padding: 2rpx 6rpx;
  803. border-radius: 4rpx;
  804. font-size: 20rpx;
  805. color: white;
  806. white-space: nowrap;
  807. }
  808. /* 虫子标记层 */
  809. .bug-markers {
  810. position: absolute;
  811. top: 0;
  812. left: 0;
  813. width: 100%;
  814. height: 100%;
  815. pointer-events: none;
  816. }
  817. /* 虫子标记 */
  818. .bug-marker {
  819. position: absolute;
  820. border: 2rpx solid;
  821. border-radius: 4rpx;
  822. pointer-events: auto;
  823. }
  824. /* 虫子标记标签 */
  825. .bug-label {
  826. position: absolute;
  827. top: -30rpx;
  828. left: 0;
  829. padding: 4rpx 8rpx;
  830. border-radius: 4rpx;
  831. font-size: 20rpx;
  832. font-weight: bold;
  833. }
  834. .photo-timestamp {
  835. position: absolute;
  836. bottom: 0rpx;
  837. left: 0rpx;
  838. width:100%;
  839. background-color: rgba(0, 0, 0, 0.6);
  840. color: #FFFFFF;
  841. padding: 8rpx 16rpx;
  842. border-radius: 8rpx;
  843. font-size: 24rpx;
  844. }
  845. }
  846. /* 缩略图预览 */
  847. .thumbnail-preview {
  848. margin: 0 24rpx 24rpx;
  849. .thumbnail-scroll {
  850. gap: 16rpx;
  851. padding-bottom: 16rpx;
  852. box-sizing: border-box;
  853. white-space: nowrap;
  854. overflow-x: auto;
  855. overflow-y: hidden;
  856. width: 100%;
  857. // 隐藏滚动条
  858. -ms-overflow-style: none;
  859. scrollbar-width: none;
  860. .thumbnail-item {
  861. width: 120rpx;
  862. height: 120rpx;
  863. border-radius: 8rpx;
  864. overflow: hidden;
  865. border: 2rpx solid transparent;
  866. display: inline-block;
  867. box-sizing: border-box;
  868. margin-right: 10rpx;
  869. &.active {
  870. border-color: #0BBC58;
  871. }
  872. .thumbnail-image {
  873. width: 100%;
  874. height: 100%;
  875. object-fit: cover;
  876. }
  877. }
  878. }
  879. }
  880. /* 识别结果 */
  881. .recognition-result {
  882. margin: 0 24rpx 24rpx;
  883. background-color: #FFFFFF;
  884. border-radius: 16rpx;
  885. padding: 24rpx;
  886. .result-title {
  887. font-size: 28rpx;
  888. font-weight: 700;
  889. color: #042118;
  890. margin-bottom: 24rpx;
  891. }
  892. /* 害虫类别 */
  893. .pest-category {
  894. margin-bottom: 32rpx;
  895. border: 1px solid #E4E7ED;
  896. border-radius: 16rpx;
  897. &:last-child {
  898. margin-bottom: 0;
  899. }
  900. .category-header {
  901. display: flex;
  902. justify-content: space-between;
  903. margin-bottom: 16rpx;
  904. background: #F6F8FC;
  905. padding: 18rpx 24rpx;
  906. .category-title {
  907. font-size: 24rpx;
  908. font-weight: 500;
  909. color: #042118;
  910. }
  911. .category-count {
  912. font-size: 24rpx;
  913. color: #999999;
  914. }
  915. }
  916. .pest-item {
  917. display: flex;
  918. justify-content: space-between;
  919. align-items: center;
  920. margin-bottom: 12rpx;
  921. padding: 6rpx 24rpx;
  922. &:last-child {
  923. margin-bottom: 0;
  924. }
  925. .pest-info {
  926. display: flex;
  927. align-items: center;
  928. .pest-color {
  929. width: 16rpx;
  930. height: 16rpx;
  931. border-radius: 50%;
  932. margin-right: 12rpx;
  933. }
  934. .pest-name {
  935. font-size: 24rpx;
  936. color: #042118;
  937. }
  938. }
  939. .pest-count {
  940. font-size: 24rpx;
  941. color: #042118;
  942. }
  943. }
  944. }
  945. }
  946. }
  947. </style>