detail.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. <template>
  2. <view class="device-detail">
  3. <view class="device-detail__header">
  4. <u-icon
  5. size="36"
  6. class="arrow-left"
  7. name="arrow-left"
  8. @click="handleBack"
  9. ></u-icon>
  10. {{ deviceInfo.name }}
  11. </view>
  12. <view class="operation" @click.stop="isShowOperation = !isShowOperation">操作</view>
  13. <view class="operation-container" v-if="isShowOperation" @click="closeOperationHandler">
  14. <view class="operation-background"></view>
  15. <view class="operation-content">
  16. <view class="operation-item" v-if="isShowPhoto" @click="handlePhotoClick">
  17. <image :src="photoIcon" class="operation-icon"></image>
  18. 拍照
  19. </view>
  20. <!-- <view class="operation-item" @click="handleServiceClick">
  21. <image :src="serviceIcon" class="operation-icon"></image>
  22. 维修
  23. </view> -->
  24. <view class="operation-item" @click="handleSettingClick">
  25. <image :src="settingIcon" class="operation-icon"></image>
  26. 设置
  27. </view>
  28. <view class="operation-item" @click="handleSimClick">
  29. <image :src="simIcon" class="operation-icon"></image>
  30. SIM卡
  31. </view>
  32. <view class="operation-item" @click="modification">
  33. <image :src="editIcon" class="operation-icon"></image>
  34. 修改
  35. </view>
  36. </view>
  37. </view>
  38. <view class="device-detail__body">
  39. <DeviceCard
  40. :dataSource="deviceInfo"
  41. :collectTime="time"
  42. :title="deviceInfo.name"
  43. :deviceType="deviceType"
  44. />
  45. <view class="tabs">
  46. <view class="tab-container" v-if="isShowTab">
  47. <view class="tab-item" :class="activeTab === 'viewImage'?'active':''" @click="handleTabClick('viewImage')">
  48. 查看图片
  49. </view>
  50. <view class="tab-item" :class="activeTab === 'pestAnalysis'?'active':''" @click="handleTabClick('pestAnalysis')">
  51. 孢子分析
  52. </view>
  53. <view class="tab-item" :class="activeTab === 'deviceData'?'active':''" @click="handleTabClick('deviceData')">
  54. 设备数据
  55. </view>
  56. </view>
  57. <view class="select-timer-container">
  58. <view class="select-year">
  59. <view class="select-year-item" @click="showPicker = true">
  60. {{ currentYear }}
  61. <u-icon name="arrow-down" size="18" class="arrow-down"></u-icon>
  62. </view>
  63. </view>
  64. <view class="tabs-timer-container" @click="showCalendar">
  65. <view class="tabs-timer-item">
  66. {{startDate}}
  67. </view>
  68. <view class="tabs-timer-item">
  69. {{endDate}}
  70. </view>
  71. <u-icon name="calendar" size="36" class="calendar-icon"></u-icon>
  72. </view>
  73. </view>
  74. </view>
  75. <view v-show="activeTab === 'viewImage'">
  76. <!-- 孢子仪2.1(device_code=1):文件夹列表,file_fold 作为名称 -->
  77. <view class="tabs-fold" v-if="isSporeTwo && folderList.length">
  78. <view
  79. class="tabs-fold-item"
  80. :class="{ active: index === folderIndex }"
  81. v-for="(item, index) in folderList"
  82. :key="index"
  83. @click="handleFolderSelect(index)"
  84. >
  85. <image src="https://s3.hnyfwlw.com/webstaticimg/bigdata_app/image/file.png" class="tabs-fold-icon" />
  86. <view>{{ formatFold(item.file_fold) }}</view>
  87. </view>
  88. </view>
  89. <photoImage
  90. :images="imageList"
  91. :pestList="pestList"
  92. :disableShow="disableShow"
  93. @changeTab="changeTab"
  94. :currentYear="currentYear"
  95. :deviceInfo="deviceInfo"
  96. :sporeTwo="isSporeTwo"
  97. :folderId="folderList[folderIndex] ? folderList[folderIndex].id : ''"
  98. />
  99. </view>
  100. <view v-show="activeTab === 'deviceData'">
  101. <DeviceData
  102. :deviceStatic="deviceStatic"
  103. :deviceInfo="deviceInfo"
  104. :polylineList="polylineList"
  105. :deviceHistoryList="deviceHistoryList"
  106. :totalPage="totalPage"
  107. :currentPage="page"
  108. :page_size="page_size"
  109. @prevPage="prevPage"
  110. @nextPage="nextPage"
  111. />
  112. </view>
  113. <view v-show="activeTab === 'pestAnalysis'" class="spore-analysis">
  114. <!-- 孢子识别 -->
  115. <view class="analysis-card">
  116. <view class="card-title">孢子识别</view>
  117. <view class="pest-rank">
  118. <view class="pest-rank__item" v-for="(item, index) in pestRankList" :key="index">
  119. <text class="pest-rank__name">{{ item.name }}</text>
  120. <view class="pest-rank__track">
  121. <view class="pest-rank__fill" :style="{ width: rankPercent(item) + '%', background: rankColors[index % rankColors.length] }"></view>
  122. </view>
  123. <text class="pest-rank__count">{{ item.count }}</text>
  124. </view>
  125. </view>
  126. </view>
  127. <!-- 孢子趋势 -->
  128. <view class="analysis-card">
  129. <view class="card-title">孢子趋势</view>
  130. <view class="chart-wrap--spore">
  131. <qiun-data-charts
  132. type="mix"
  133. :chartData="sporeChart"
  134. :opts="sporeOpts"
  135. :reshow="activeTab === 'pestAnalysis'"
  136. :canvas2d="true"
  137. :inScrollView="true"
  138. :ontouch="true"
  139. />
  140. </view>
  141. </view>
  142. </view>
  143. </view>
  144. <u-calendar v-model="show" :mode="mode" range-color="#999" btn-type="success" active-bg-color="#0bbc58" range-bg-color="rgba(11,188,88,0.13)" @change="handleChange" :max-date="maxDate" :min-date="minDate"></u-calendar>
  145. <u-picker v-model="showPicker" mode="selector" :range="selectorRange" range-key="id" :default-selector="[0]" @confirm="confirmHandler"></u-picker>
  146. </view>
  147. </template>
  148. <script>
  149. import DeviceCard from './components/DeviceCard.vue';
  150. import PestDiscern from './components/pestDiscern.vue';
  151. import PestEchart from './components/pestEchart.vue';
  152. import PestArchive from './components/pestArchive.vue';
  153. import photoImage from './components/photoImage.vue';
  154. import photoImage2 from './components/photoImage2.vue';
  155. import DeviceData from './components/deviceData.vue';
  156. export default {
  157. components: {
  158. DeviceCard,
  159. PestDiscern,
  160. PestEchart,
  161. PestArchive,
  162. photoImage,
  163. photoImage2,
  164. DeviceData,
  165. },
  166. data(){
  167. return {
  168. isShowTab:false,
  169. showPicker: false,
  170. disableShow: false,
  171. isShowOperation: false,
  172. photoIcon:'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/newImg/home/photoIcon.png',
  173. editIcon:'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/newImg/home/editIcon.png',
  174. serviceIcon:'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/newImg/home/serviceIcon.png',
  175. simIcon:'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/newImg/home/simIcon.png',
  176. settingIcon:'https://s3.hnyfwlw.com/webstaticimg/bigdata_app/newImg/home/settingIcon.png',
  177. totalPage:0,
  178. currentYear: new Date().getFullYear(),
  179. selectorRange: [],
  180. maxDate: this.formatDate(new Date()),
  181. minDate: this.formatDate(new Date(new Date().getFullYear(), 0, 1)),
  182. show: false,
  183. showSim: false,
  184. // 当前日期向前推30天 格式2026-01-01 月份和日期小于10的时候前面加个0
  185. startDate: this.formatDate(new Date(new Date().getTime() - 30 * 24 * 60 * 60 * 1000)),
  186. endDate: this.formatDate(new Date()),
  187. mode: 'range',
  188. imageList: [],
  189. pest_order:{},
  190. deviceInfo: {},
  191. pestInfo: {},
  192. time: '',
  193. activeTab: 'viewImage',
  194. deviceType: '',
  195. location: '',
  196. total: 0,
  197. day: [],
  198. pest: [],
  199. page:1,
  200. is_pest:'',
  201. page_size:24,
  202. pestList:[],
  203. pest_names:'',
  204. pests:[],
  205. // 孢子分析
  206. rankColors: ['#4FD8E0', '#FF7A45', '#5AD8A6', '#FFC53D', '#F8E71C', '#5B8FF9', '#E8684A', '#6DC8EC', '#FF9DC6', '#7EDB8F'],
  207. pestRankList: [],
  208. // 各物种每日数量/浓度(char_data)
  209. sporeCharData: {},
  210. sporeOpts: {
  211. dataPointShape: true,
  212. // 图例置顶,点击可隐藏/显示对应线(同 PC 图例交互)
  213. legend: {
  214. show: true,
  215. fontSize: 10,
  216. itemGap: 12
  217. },
  218. xAxis: {
  219. disableGrid: false,
  220. gridType: 'dash',
  221. gridColor: '#EEEEEE',
  222. fontSize: 10,
  223. fontColor: '#666666',
  224. itemCount: 4,
  225. scrollShow: true
  226. },
  227. // 双 Y 轴:左轴虫数,右轴浓度
  228. yAxis: {
  229. showTitle: true,
  230. disableGrid: false,
  231. gridType: 'dash',
  232. gridColor: '#EEEEEE',
  233. data: [
  234. {
  235. title: '虫数:头',
  236. titleFontSize: 10,
  237. titleFontColor: '#666666',
  238. position: 'left',
  239. min: 0,
  240. splitNumber: 4,
  241. formatter: val => Math.round(val) + ''
  242. },
  243. {
  244. title: '浓度:个/L',
  245. titleFontSize: 10,
  246. titleFontColor: '#666666',
  247. position: 'right',
  248. min: 0,
  249. splitNumber: 4,
  250. formatter: val => Number(val).toFixed(4)
  251. }
  252. ]
  253. },
  254. extra: {
  255. mix: {
  256. line: { width: 2 }
  257. },
  258. tooltip: { showBox: true }
  259. },
  260. enableScroll: true
  261. },
  262. polylineList:[],
  263. isShowPhoto:false,
  264. deviceHistoryList:[],
  265. deviceStatic:{},
  266. // 孢子仪2.1 文件夹列表
  267. folderList: [],
  268. folderIndex: 0,
  269. // 设备代号:1=孢子仪2.1,其他=2.0(走原接口)
  270. deviceCode: ''
  271. }
  272. },
  273. computed: {
  274. // 孢子仪2.1
  275. isSporeTwo() {
  276. return this.deviceCode == 1;
  277. }
  278. },
  279. onLoad(options){
  280. this.deviceInfo = JSON.parse(options.info);
  281. console.log(this.deviceInfo,'deviceInfod2eviceInfo')
  282. // 列表跳转时带过来的设备代号:1=孢子仪2.1
  283. this.deviceCode = options.device_code || this.deviceInfo.device_code || '';
  284. // 诊断:确认列表带过来的 device_code 是否有值
  285. console.log('[bzy2] device_code =', options.device_code, ', deviceInfo =', JSON.stringify(this.deviceInfo));
  286. // 延迟初始化:等布局稳定后再测 canvas 尺寸
  287. setTimeout(() => {
  288. this.getSporeAnalysis();
  289. }, 300);
  290. // this.getPestAnalysis();
  291. this.isShow();
  292. const currentYear = new Date().getFullYear();
  293. this.selectorRange = [];
  294. for(let i = 0;i<50;i++){
  295. const item = {
  296. label: currentYear - i,
  297. id: currentYear - i
  298. }
  299. this.selectorRange.push(item);
  300. }
  301. },
  302. methods: {
  303. handleSimClick(){
  304. // this.showSim = true;
  305. //`/pages/deviceDetails/weatherStation/${type}?deviceInfo=${encodeURIComponent(JSON.stringify(this.deviceInfo))}`
  306. uni.navigateTo({
  307. url:
  308. '/pages/deviceDetails/weatherStation/simDetail?deviceInfo=' +
  309. encodeURIComponent(JSON.stringify(this.deviceInfo))
  310. });
  311. },
  312. modification() {
  313. uni.navigateTo({
  314. url:
  315. '/pages/equipList2/seabox/modification?data=' +
  316. JSON.stringify(this.deviceInfo) +
  317. '&id=' +
  318. this.deviceInfo.type,
  319. });
  320. },
  321. async handlePhotoClick(){
  322. const res = await this.$myRequest({
  323. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  324. method: 'POST',
  325. data: {
  326. device_type_id: this.deviceInfo.type,
  327. d_id: this.deviceInfo.d_id,
  328. cmd: 'takephoto',
  329. },
  330. });
  331. if(res){
  332. this.$u.toast('拍照成功')
  333. }
  334. },
  335. handleServiceClick(){
  336. uni.navigateTo({
  337. url: '/pages/afterSale/addafter?d_id=' + this.deviceInfo.d_id +'&device_id='+this.deviceInfo.id + '&device_type=' + this.deviceInfo.type,
  338. })
  339. },
  340. handleSettingClick(){
  341. uni.navigateTo({
  342. url: '/pages/bzy/deviceControl?deviceId=' + this.deviceInfo.id + '&d_id=' + this.deviceInfo.d_id + '&device_model=' + this.deviceInfo.device_model,
  343. });
  344. },
  345. closeOperationHandler(){
  346. this.isShowOperation = false;
  347. },
  348. isShow(){
  349. // disable == 0 或者 device_model == 15 表示不可以查看
  350. if(!this.deviceInfo.d_id){
  351. return false;
  352. }
  353. let showStatus = true;
  354. if(this.deviceInfo.device_model == 15 || this.deviceInfo.device_model == 12){
  355. showStatus = false;
  356. }
  357. if(showStatus){
  358. this.activeTab = 'viewImage';
  359. }else{
  360. this.activeTab = 'deviceData';
  361. }
  362. this.initAction();
  363. this.isShowTab = showStatus;
  364. if(this.deviceInfo.disable == 0){
  365. this.disableShow = false;
  366. if(showStatus){
  367. this.activeTab = 'viewImage';
  368. this.handleTabClick('viewImage');
  369. }
  370. }else{
  371. this.disableShow = true;
  372. }
  373. },
  374. prevPage(e){
  375. if(e == 1){
  376. return
  377. }
  378. this.page = e-=1;
  379. this.getDeviceHistoryData();
  380. },
  381. nextPage(e){
  382. if(e * this.page_size >= this.totalPage){
  383. return
  384. }
  385. this.page = e+=1;
  386. this.getDeviceHistoryData();
  387. },
  388. changeTab(pestList){
  389. let pest_names = pestList.map(item => item.pest_name);
  390. this.pest_names = pest_names.join(',');
  391. this.initImageList();
  392. },
  393. confirmHandler(e){
  394. this.currentYear = this.selectorRange[e].id;
  395. if(this.currentYear == new Date().getFullYear()){
  396. // 结束日期为this.endDate的月份和日期加上选择的年份
  397. const timeDate = this.currentYear + '-' + this.endDate.split('-')[1] + '-' + this.endDate.split('-')[2];
  398. this.endDate = this.formatDate(new Date(timeDate));
  399. // 开始日期为结束日期前30天
  400. this.startDate = this.formatDate(new Date(new Date(this.endDate).getTime() - 30 * 24 * 60 * 60 * 1000));
  401. this.maxDate = this.formatDate(new Date());
  402. this.minDate = this.formatDate(new Date(new Date().getFullYear(), 0, 1));
  403. }else{
  404. // 结束日期为this.endDate的月份和日期加上选择的年份
  405. const timeDate = this.currentYear + '-' + this.endDate.split('-')[1] + '-' + this.endDate.split('-')[2];
  406. this.endDate = this.formatDate(new Date(timeDate));
  407. // 开始日期为结束日期前30天
  408. this.startDate = this.formatDate(new Date(new Date(this.endDate).getTime() - 30 * 24 * 60 * 60 * 1000));
  409. this.maxDate = this.formatDate(new Date(this.currentYear, 11, 31));
  410. this.minDate = this.formatDate(new Date(this.currentYear, 0, 1));
  411. }
  412. this.initAction();
  413. this.showPicker = false;
  414. },
  415. getInfo(info){
  416. this.pestInfo = info;
  417. },
  418. // 格式化日期为YYYY-MM-DD格式,月份和日期小于10时前面加0
  419. formatDate(date) {
  420. const year = date.getFullYear();
  421. const month = String(date.getMonth() + 1).padStart(2, '0');
  422. const day = String(date.getDate()).padStart(2, '0');
  423. return `${year}-${month}-${day}`;
  424. },
  425. formatTime(date){
  426. const time = new Date(date).getTime() / 1000;
  427. return time.toFixed(0);
  428. },
  429. handleChange(e){
  430. this.startDate = e.startDate;
  431. this.endDate = e.endDate;
  432. this.page = 1;
  433. this.initAction();
  434. },
  435. showCalendar(){
  436. this.show = true;
  437. },
  438. handleBack() {
  439. uni.navigateBack({
  440. delta: 1
  441. });
  442. },
  443. initAction(){
  444. this.pest_order = {}
  445. if(this.activeTab === 'viewImage'){
  446. // this.initPest();
  447. this.initImageList();
  448. }else if(this.activeTab === 'deviceData'){
  449. // this.getDeviceData();
  450. this.getPolylineData();
  451. this.getDeviceHistoryData();
  452. }else if(this.activeTab === 'pestAnalysis'){
  453. this.getSporeAnalysis();
  454. }
  455. },
  456. handleTabClick(tab) {
  457. this.activeTab = tab;
  458. this.initAction();
  459. },
  460. // 拉取孢子分析数据(虫害识别 + 孢子趋势)
  461. async getSporeAnalysis() {
  462. const res = await this.$myRequest({
  463. url: '/api/api_gateway?method=forecast.bzy.pest_order_and_char',
  464. method: 'POST',
  465. data: {
  466. id: this.deviceInfo.d_id,
  467. hour_st: '00',
  468. hour_ed: '00',
  469. device_type_id: this.deviceInfo.type_id || this.deviceInfo.type,
  470. start: this.formatTime(this.startDate + ' 00:00:00'),
  471. end: this.formatTime(this.endDate + ' 23:59:59')
  472. }
  473. });
  474. // 虫害识别:pest_total 按数量降序
  475. const pestTotal = (res && res.pest_total) || {};
  476. this.pestRankList = Object.keys(pestTotal)
  477. .map(name => ({ name: name, count: pestTotal[name] || 0 }))
  478. .sort((a, b) => b.count - a.count);
  479. // 各物种每日数量/浓度(char_data)
  480. const charData = (res && res.char_data) || {};
  481. const charRows = {};
  482. Object.keys(charData).forEach(name => {
  483. charRows[name] = (charData[name] || []).map(item => ({
  484. date: this.formatDay(item.addtime),
  485. value: item.sum || 0,
  486. ctn: item.ctn || 0
  487. }));
  488. });
  489. this.sporeCharData = charRows;
  490. this.buildSporeChart();
  491. },
  492. // 秒级时间戳 → YYYY-MM-DD
  493. formatDay(seconds) {
  494. return this.formatDate(new Date(Number(seconds) * 1000));
  495. },
  496. // 孢子趋势:所有物种的数量(左轴)+ 浓度(右轴)画在同一张图,点图例可隐藏/显示
  497. buildSporeChart() {
  498. const names = Object.keys(this.sporeCharData);
  499. // 汇总所有日期作为 x 轴
  500. const categories = [];
  501. names.forEach(name => {
  502. this.sporeCharData[name].forEach(row => {
  503. if (categories.indexOf(row.date) === -1) categories.push(row.date);
  504. });
  505. });
  506. categories.sort();
  507. const series = [];
  508. names.forEach(name => {
  509. const map = {};
  510. this.sporeCharData[name].forEach(row => {
  511. map[row.date] = row;
  512. });
  513. series.push({
  514. name: name,
  515. type: 'line',
  516. style: 'curve',
  517. index: 0,
  518. data: categories.map(d => (map[d] ? map[d].value : null))
  519. });
  520. series.push({
  521. name: name + '浓度',
  522. type: 'line',
  523. style: 'curve',
  524. index: 1,
  525. data: categories.map(d => (map[d] ? map[d].ctn : null))
  526. });
  527. });
  528. this.sporeChart = { categories: categories, series: series };
  529. },
  530. // 虫害识别进度条宽度:占总量百分比,保底 4% 便于查看
  531. rankPercent(item) {
  532. const total = this.pestRankList.reduce((sum, cur) => sum + cur.count, 0);
  533. if (!total) return 0;
  534. return Math.max(4, Math.round((item.count / total) * 100));
  535. },
  536. async getDeviceData(){
  537. const res = await this.$myRequest({
  538. url: '/api/api_gateway?method=forecast.worm_lamp.device_status_data',
  539. method: 'POST',
  540. data: {
  541. device_id: this.deviceInfo.id,
  542. },
  543. });
  544. this.deviceStatic = res;
  545. },
  546. async initImageList(){
  547. // 孢子仪2.1(device_code=1)走文件夹列表;2.0 走原接口
  548. if (!this.isSporeTwo) {
  549. const res = await this.$myRequest({
  550. url: '/api/api_gateway?method=forecast.forecast_system.equip_photo',
  551. method: 'POST',
  552. data: {
  553. page:this.page,
  554. page_number:this.page_size,
  555. device_id: this.deviceInfo.id,
  556. ret:'list',
  557. time_begin: this.formatTime(this.formatDate(new Date(this.startDate)) + ' 00:00:00'),// 格式化开始时间YYYY-MM-DD HH:MM:SS
  558. time_end: this.formatTime(this.formatDate(new Date(this.endDate)) + ' 23:59:59'),// 格式化结束时间YYYY-MM-DD HH:MM:SS
  559. },
  560. });
  561. const data = res?.data || [];
  562. this.imageList = data
  563. return;
  564. }
  565. await this.initFolderList();
  566. },
  567. // 孢子仪2.1:拉取文件夹列表,默认选中第一个并加载其图片
  568. async initFolderList(){
  569. uni.showLoading({ title: '加载中' });
  570. try {
  571. const res = await this.$myRequest({
  572. url: '/api/api_gateway?method=forecast.bzy.bzy_file_fold',
  573. method: 'POST',
  574. data: {
  575. device_id: this.deviceInfo.id,
  576. page: 1,
  577. size: 999,
  578. },
  579. });
  580. this.folderList = res?.data || [];
  581. // 默认选中第一个文件夹并加载其图片
  582. this.folderIndex = 0;
  583. if (this.folderList.length) {
  584. await this.loadFolderPhotos();
  585. } else {
  586. this.imageList = [];
  587. }
  588. } catch (e) {
  589. console.log('bzy_file_fold error:', e);
  590. this.folderList = [];
  591. } finally {
  592. uni.hideLoading();
  593. }
  594. },
  595. // 20260905110035 → 2026-09-05 11:00
  596. formatFold(str){
  597. const s = String(str || '');
  598. if (s.length < 12) return s;
  599. return `${s.slice(0, 4)}${s.slice(4, 6)}${s.slice(6, 8)}_${s.slice(8, 10)}${s.slice(10, 12)}`;
  600. },
  601. handleFolderSelect(index){
  602. if (index === this.folderIndex) return;
  603. this.folderIndex = index;
  604. this.loadFolderPhotos();
  605. },
  606. // 孢子仪2.1:拉取选中文件夹内的图片列表
  607. async loadFolderPhotos(){
  608. const folder = this.folderList[this.folderIndex] || {};
  609. if (!folder.id) {
  610. this.imageList = [];
  611. return;
  612. }
  613. uni.showLoading({ title: '加载中' });
  614. try {
  615. const res = await this.$myRequest({
  616. url: '/api/api_gateway?method=forecast.bzy.bzy_two_percent_one_photo',
  617. method: 'POST',
  618. data: {
  619. id: folder.id,
  620. page: 1,
  621. size: 32,
  622. },
  623. });
  624. console.log('bzy_two_percent_one_photo res:', JSON.stringify(res).slice(0, 500));
  625. this.imageList = res?.data || [];
  626. } catch (e) {
  627. console.log('bzy_two_percent_one_photo error:', e);
  628. this.imageList = [];
  629. } finally {
  630. uni.hideLoading();
  631. }
  632. },
  633. async initPest(){
  634. const res = await this.$myRequest({
  635. url: '/api/api_gateway?method=forecast.new_cbd.pest_type_list',
  636. method: 'POST',
  637. data:{
  638. page:1,
  639. page_size:999999,
  640. device_id: this.deviceInfo.id,
  641. identify_model: 'B',
  642. time_begin: this.formatTime(this.formatDate(new Date(this.startDate)) + ' 00:00:00'),// 格式化开始时间YYYY-MM-DD HH:MM:SS
  643. time_end: this.formatTime(this.formatDate(new Date(this.endDate)) + ' 23:59:59'),// 格式化结束时间YYYY-MM-DD HH:MM:SS
  644. },
  645. });
  646. const data = res?.data || [];
  647. this.pestList = data
  648. },
  649. async getPolylineData(){
  650. const res = await this.$myRequest({
  651. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  652. method: 'POST',
  653. data: {
  654. device_type_id: this.deviceInfo.type_id,
  655. d_id: this.deviceInfo.d_id,
  656. start_time: new Date(this.startDate + ' 00:00:00').getTime()/1000,// 转成毫秒
  657. end_time: new Date(this.endDate + ' 23:59:59').getTime()/1000,// 转成毫秒
  658. },
  659. });
  660. const data = res || [];
  661. this.polylineList = data
  662. },
  663. async getDeviceHistoryData(){
  664. const res = await this.$myRequest({
  665. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  666. method: 'POST',
  667. data: {
  668. device_type_id: this.deviceInfo.type_id,
  669. device_id: this.deviceInfo.id,
  670. start_time: new Date(this.startDate + ' 00:00:00').getTime()/1000,
  671. end_time: new Date(this.endDate + ' 23:59:59').getTime()/1000,
  672. page: this.page,
  673. page_size: this.page_size,
  674. },
  675. });
  676. const data = res?.data || [];
  677. this.totalPage = res.counts;
  678. this.deviceHistoryList = data
  679. },
  680. async getPestAnalysis(){
  681. const res = await this.$myRequest({
  682. url: '/api/api_gateway?method=forecast.cbd_analysis.analysis_pest_result',
  683. method: 'POST',
  684. data: {
  685. d_id: this.deviceInfo.d_id,
  686. start: this.startDate,
  687. end: this.endDate,
  688. model: 'B'
  689. },
  690. });
  691. const pest_order = res?.pest_order;
  692. this.getInfo({});
  693. let total = 0;
  694. this.pests = [];
  695. for(let key in pest_order){
  696. total += pest_order[key] || 0;
  697. this.pests.push({
  698. name: key,
  699. percent: (pest_order[key] / total) * 100
  700. })
  701. }
  702. this.pest_order = pest_order;
  703. this.day = res?.day || [];
  704. const pest = res?.pest || [];
  705. this.pest = pest;
  706. // pest.forEach(p =>{
  707. // for(let i = 0;i< p.length;i++){
  708. // this.pest.push(p[i]);
  709. // }
  710. // })
  711. this.total = total;
  712. }
  713. }
  714. }
  715. </script>
  716. <style scoped lang="scss">
  717. ::v-deep .u-calendar__action{
  718. display:flex;
  719. justify-content: space-between;
  720. }
  721. ::v-deep .u-hover-class{
  722. .u-calendar__content__item__inner{
  723. color:#aaa !important;
  724. }
  725. }
  726. .operation-container{
  727. position: fixed;
  728. right: 0;
  729. top: 0;
  730. width: 100%;
  731. height: 100%;
  732. z-index: 99;
  733. }
  734. .operation{
  735. position: fixed;
  736. top: 260rpx;
  737. right: 0;
  738. z-index: 999;
  739. width:48rpx;
  740. height: 100rpx;
  741. line-height: 50rpx;
  742. border-radius: 8px 0 0 8px;
  743. border-top: 4rpx solid #FFF;
  744. border-bottom: 4rpx solid #FFF;
  745. border-left: 4rpx solid #FFF;
  746. background: #dddfe6a3;
  747. color: #515153;
  748. text-align: center;
  749. font-family: "Source Han Sans CN VF";
  750. font-size: 24rpx;
  751. font-weight: 500;
  752. writing-mode: vertical-rl;
  753. }
  754. .operation-background{
  755. position: fixed;
  756. right: 0;
  757. top: 0;
  758. width: 100%;
  759. height: 100%;
  760. z-index: 998;
  761. background: #00000040;
  762. }
  763. .operation-content{
  764. position: fixed;
  765. top: 240rpx;
  766. right: 80rpx;
  767. height: 126rpx;
  768. display: flex;
  769. padding: 16rpx 32rpx;
  770. align-items: center;
  771. gap: 64rpx;
  772. z-index: 999;
  773. border-radius: 32rpx;
  774. border: 2rpx solid #FFF;
  775. background: #FFF;
  776. backdrop-filter: blur(8rpx);
  777. .operation-item{
  778. display: flex;
  779. flex-direction: column;
  780. align-items: center;
  781. justify-content: center;
  782. color: #333333;
  783. text-align: center;
  784. font-family: "Source Han Sans CN VF";
  785. font-size: 24rpx;
  786. font-weight: 400;
  787. }
  788. .operation-icon{
  789. width: 58rpx;
  790. height: 58rpx;
  791. }
  792. }
  793. .device-detail {
  794. display: flex;
  795. width: 100%;
  796. height: calc(100vh - 112rpx);
  797. padding-top: 112rpx;
  798. flex-direction: column;
  799. align-items: center;
  800. overflow-y: scroll;
  801. // 孢子分析
  802. .spore-analysis {
  803. width: 100%;
  804. .analysis-card {
  805. width: 100%;
  806. padding: 32rpx;
  807. box-sizing: border-box;
  808. background: #fff;
  809. border-radius: 16rpx;
  810. margin-bottom: 24rpx;
  811. &:last-child {
  812. margin-bottom: 0;
  813. }
  814. }
  815. .card-title {
  816. font-size: 32rpx;
  817. color: #042118;
  818. font-family: 'Source Han Sans CN VF';
  819. font-weight: 700;
  820. margin-bottom: 24rpx;
  821. }
  822. .pest-rank {
  823. &__item {
  824. display: flex;
  825. align-items: center;
  826. padding: 14rpx 0;
  827. }
  828. &__name {
  829. width: 160rpx;
  830. flex-shrink: 0;
  831. font-size: 26rpx;
  832. color: #042118;
  833. font-family: 'Source Han Sans CN VF';
  834. overflow: hidden;
  835. text-overflow: ellipsis;
  836. white-space: nowrap;
  837. }
  838. &__track {
  839. flex: 1;
  840. height: 12rpx;
  841. border-radius: 6rpx;
  842. background: #F0F2F5;
  843. overflow: hidden;
  844. margin: 0 24rpx;
  845. }
  846. &__fill {
  847. height: 100%;
  848. border-radius: 6rpx;
  849. }
  850. &__count {
  851. width: 80rpx;
  852. flex-shrink: 0;
  853. text-align: right;
  854. font-size: 26rpx;
  855. color: #042118;
  856. font-family: 'Source Han Sans CN VF';
  857. }
  858. }
  859. .chart-wrap--spore {
  860. width: 100%;
  861. height: 420rpx;
  862. }
  863. }
  864. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  865. .device-detail__header {
  866. width: 100%;
  867. font-size: 28rpx;
  868. color: #999;
  869. color: #042118;
  870. font-family: 'Source Han Sans CN VF';
  871. font-weight: 700;
  872. position: relative;
  873. text-align: center;
  874. .arrow-left {
  875. position: absolute;
  876. left: 32rpx;
  877. margin-right: 12rpx;
  878. }
  879. }
  880. .device-detail__body {
  881. width: calc(100% - 64rpx);
  882. margin: 0 auto;
  883. border-radius: 16rpx;
  884. overflow-x: hidden;
  885. overflow-y: auto;
  886. // 隐藏滚动条
  887. -ms-overflow-style: none;
  888. scrollbar-width: none;
  889. }
  890. .tab-content{
  891. width: 100%;
  892. padding-bottom: 32rpx;
  893. }
  894. .tabs {
  895. background: #ffffff;
  896. margin: 24rpx 0;
  897. border-radius: 16rpx;
  898. padding: 16rpx 0;
  899. padding-top: 0;
  900. .tab-container{
  901. display: flex;
  902. width: 100%;
  903. height: 88rpx;
  904. line-height: 88rpx;
  905. text-align: center;
  906. font-size: 28rpx;
  907. font-weight: 700;
  908. color: #042118;
  909. font-family: 'Source Han Sans CN VF';
  910. }
  911. .select-timer-container{
  912. display:flex;
  913. align-items: center;
  914. padding-left: 32rpx;
  915. .select-year{
  916. width: 110rpx;
  917. text-align: center;
  918. height: 64rpx;
  919. border-radius: 32rpx;
  920. font-family: 'Source Han Sans CN VF';
  921. line-height: 64rpx;
  922. background: #F1F4F8;
  923. padding: 0 32rpx;
  924. .select-year-item{
  925. color: #656565;
  926. font-size: 24rpx;
  927. display: flex;
  928. align-items: center;
  929. justify-content: space-around;
  930. }
  931. }
  932. }
  933. .tabs-timer-container{
  934. display: flex;
  935. align-items: center;
  936. width: calc(100% - 256rpx);
  937. height: 64rpx;
  938. line-height: 64rpx;
  939. text-align: center;
  940. font-size: 24rpx;
  941. font-weight: 500;
  942. font-family: 'Source Han Sans CN VF';
  943. border-radius: 32rpx;
  944. background: #F1F4F8;
  945. padding: 0 32rpx;
  946. color: #656565;
  947. margin: 16rpx;
  948. position: relative;
  949. .tabs-timer-item{
  950. width: 42%;
  951. color: #656565;
  952. text-align: center;
  953. font-family: "Source Han Sans CN VF";
  954. font-size: 24rpx;
  955. font-weight: 400;
  956. }
  957. .calendar-icon{
  958. margin-left: 24rpx;
  959. }
  960. }
  961. .tab-item {
  962. flex: 1;
  963. color: #999999;
  964. text-align: center;
  965. font-family: "Source Han Sans CN VF";
  966. font-size: 28rpx;
  967. font-weight: 400;
  968. }
  969. .active{
  970. position: relative;
  971. color: #303133;
  972. text-align: center;
  973. font-family: "Source Han Sans CN VF";
  974. font-size: 28rpx;
  975. font-weight: 700;
  976. &::after {
  977. content: '';
  978. position: absolute;
  979. bottom: 0;
  980. left: 50%;
  981. -webkit-transform: translateX(-50%);
  982. transform: translateX(-50%);
  983. width: 36rpx;
  984. height: 36rpx;
  985. border: 6rpx solid #0bbc58;
  986. border-radius: 50%;
  987. border-color: transparent;
  988. border-bottom-color: #0bbc58;
  989. }
  990. }
  991. }
  992. .tabs-fold{
  993. display: flex;
  994. align-items: center;
  995. text-align: center;
  996. font-size: 28rpx;
  997. font-weight: 700;
  998. color: #042118;
  999. font-family: 'Source Han Sans CN VF';
  1000. // 滚动条
  1001. overflow-x: auto;
  1002. white-space: nowrap;
  1003. padding-bottom: 24rpx;
  1004. // 隐藏滚动条
  1005. -ms-overflow-style: none;
  1006. scrollbar-width: none;
  1007. .tabs-fold-item{
  1008. display: flex;
  1009. align-items: center;
  1010. justify-content: center;
  1011. flex-direction: column;
  1012. flex-shrink: 0; // 不压缩子项,超出容器宽度才能横向滚动
  1013. background: #FFFFFF;
  1014. border-radius: 24rpx;
  1015. border: 4rpx solid transparent;
  1016. box-sizing: border-box;
  1017. width: 180rpx;
  1018. padding: 16rpx 0;
  1019. &.active {
  1020. border-color: #0BBC58;
  1021. }
  1022. text-align: center;
  1023. font-size: 24rpx;
  1024. font-weight: 400;
  1025. color: #656565;
  1026. font-family: 'Source Han Sans CN VF';
  1027. margin: 0 14rpx;
  1028. border: 1rpx solid #E5E5E5;
  1029. .tabs-fold-icon{
  1030. width: 48rpx;
  1031. height: 48rpx;
  1032. margin-bottom: 12rpx;
  1033. }
  1034. }
  1035. .tabs-fold-item.active{
  1036. border-color: #0bbc58;
  1037. }
  1038. }
  1039. }
  1040. </style>