devicePhoto.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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 = 100/31;
  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) * 100 : ((startX + item.width) * scaleRatio / this.imageWidth) * 100;
  526. const y = item.height > 0 ? (startY * scaleRatio / this.imageHeight) * 100 : ((startY + item.height) * scaleRatio / this.imageHeight) * 100;
  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. // 显式高度:movable-view 依赖宽高计算各方向拖动边界,高度缺失会导致放大后无法上下拖动
  767. height: 100%;
  768. }
  769. .image-container {
  770. position: relative;
  771. width: 100%;
  772. }
  773. .main-photo-image {
  774. width: 100%;
  775. display: block;
  776. }
  777. /* 虫子标记层 */
  778. .bug-markers {
  779. position: absolute;
  780. top: 0;
  781. left: 0;
  782. width: 100%;
  783. height: 100%;
  784. pointer-events: none;
  785. }
  786. /* 虫子标记 */
  787. .bug-marker {
  788. position: absolute;
  789. border: 2rpx solid;
  790. border-radius: 4rpx;
  791. }
  792. /* 虫子标记标签 */
  793. .bug-label {
  794. position: absolute;
  795. top: -24rpx;
  796. left: 0;
  797. padding: 2rpx 6rpx;
  798. border-radius: 4rpx;
  799. font-size: 20rpx;
  800. color: white;
  801. white-space: nowrap;
  802. }
  803. /* 虫子标记层 */
  804. .bug-markers {
  805. position: absolute;
  806. top: 0;
  807. left: 0;
  808. width: 100%;
  809. height: 100%;
  810. pointer-events: none;
  811. }
  812. /* 虫子标记 */
  813. .bug-marker {
  814. position: absolute;
  815. border: 2rpx solid;
  816. border-radius: 4rpx;
  817. pointer-events: auto;
  818. }
  819. /* 虫子标记标签 */
  820. .bug-label {
  821. position: absolute;
  822. top: -30rpx;
  823. left: 0;
  824. padding: 4rpx 8rpx;
  825. border-radius: 4rpx;
  826. font-size: 20rpx;
  827. font-weight: bold;
  828. }
  829. .photo-timestamp {
  830. position: absolute;
  831. bottom: 0rpx;
  832. left: 0rpx;
  833. width:100%;
  834. background-color: rgba(0, 0, 0, 0.6);
  835. color: #FFFFFF;
  836. padding: 8rpx 16rpx;
  837. border-radius: 8rpx;
  838. font-size: 24rpx;
  839. }
  840. }
  841. /* 缩略图预览 */
  842. .thumbnail-preview {
  843. margin: 0 24rpx 24rpx;
  844. .thumbnail-scroll {
  845. gap: 16rpx;
  846. padding-bottom: 16rpx;
  847. box-sizing: border-box;
  848. white-space: nowrap;
  849. overflow-x: auto;
  850. overflow-y: hidden;
  851. width: 100%;
  852. // 隐藏滚动条
  853. -ms-overflow-style: none;
  854. scrollbar-width: none;
  855. .thumbnail-item {
  856. width: 120rpx;
  857. height: 120rpx;
  858. border-radius: 8rpx;
  859. overflow: hidden;
  860. border: 2rpx solid transparent;
  861. display: inline-block;
  862. box-sizing: border-box;
  863. margin-right: 10rpx;
  864. &.active {
  865. border-color: #0BBC58;
  866. }
  867. .thumbnail-image {
  868. width: 100%;
  869. height: 100%;
  870. object-fit: cover;
  871. }
  872. }
  873. }
  874. }
  875. /* 识别结果 */
  876. .recognition-result {
  877. margin: 0 24rpx 24rpx;
  878. background-color: #FFFFFF;
  879. border-radius: 16rpx;
  880. padding: 24rpx;
  881. .result-title {
  882. font-size: 28rpx;
  883. font-weight: 700;
  884. color: #042118;
  885. margin-bottom: 24rpx;
  886. }
  887. /* 害虫类别 */
  888. .pest-category {
  889. margin-bottom: 32rpx;
  890. border: 1px solid #E4E7ED;
  891. border-radius: 16rpx;
  892. &:last-child {
  893. margin-bottom: 0;
  894. }
  895. .category-header {
  896. display: flex;
  897. justify-content: space-between;
  898. margin-bottom: 16rpx;
  899. background: #F6F8FC;
  900. padding: 18rpx 24rpx;
  901. .category-title {
  902. font-size: 24rpx;
  903. font-weight: 500;
  904. color: #042118;
  905. }
  906. .category-count {
  907. font-size: 24rpx;
  908. color: #999999;
  909. }
  910. }
  911. .pest-item {
  912. display: flex;
  913. justify-content: space-between;
  914. align-items: center;
  915. margin-bottom: 12rpx;
  916. padding: 6rpx 24rpx;
  917. &:last-child {
  918. margin-bottom: 0;
  919. }
  920. .pest-info {
  921. display: flex;
  922. align-items: center;
  923. .pest-color {
  924. width: 16rpx;
  925. height: 16rpx;
  926. border-radius: 50%;
  927. margin-right: 12rpx;
  928. }
  929. .pest-name {
  930. font-size: 24rpx;
  931. color: #042118;
  932. }
  933. }
  934. .pest-count {
  935. font-size: 24rpx;
  936. color: #042118;
  937. }
  938. }
  939. }
  940. }
  941. }
  942. </style>