deviceDetail.vue 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  1. <template>
  2. <!-- 设备详情 -->
  3. <view class="content">
  4. <view class="name_box">
  5. <view class="name_content">{{ devInfo.devName }}</view>
  6. </view>
  7. <view class="radar-box">
  8. <view
  9. :style="{
  10. width: `${length / 200}px`,
  11. height: `${width / 200}px`,
  12. position: 'relative',
  13. }"
  14. :class="[
  15. width < 25500 && length < 25000 ? 'tranStyle' : 'center',
  16. ]"
  17. >
  18. <view
  19. v-for="(item, index) in modules"
  20. :key="index"
  21. class="moduleContent"
  22. >
  23. <view
  24. :class="item.type"
  25. :style="{
  26. width: `${item.width / 2}px`,
  27. height: `${item.length / 2}px`,
  28. top: `${item.top / 2}px`,
  29. left: `${item.left / 2}px`,
  30. transform: `rotate(${item.rotate}deg)`,
  31. 'transform-origin': 'center center',
  32. }"
  33. >
  34. <image
  35. class="module-img"
  36. :src="`../../static/furnitures/${item.type}.png`"
  37. mode=""
  38. />
  39. </view>
  40. </view>
  41. <template>
  42. <view v-for="item in targetPoints" :key="item.id">
  43. <image
  44. class="action-icon-M"
  45. :style="{
  46. position: 'absolute',
  47. transform: `translate3d(${
  48. item.displayX / 2
  49. }px, ${
  50. -item.displayY / 2
  51. }px, 0) translate(-50%, -50%)`,
  52. zIndex: 9999,
  53. transition: 'transform 1s linear',
  54. willChange: 'transform',
  55. }"
  56. :src="`../../static/${lnbAction}.png`"
  57. mode=""
  58. />
  59. </view>
  60. </template>
  61. </view>
  62. <!-- <image
  63. class="redar-pic"
  64. src="../../static/rander.png"
  65. mode=""
  66. :style="{
  67. transform:
  68. 'translate(' +
  69. -xOffset / 100 +
  70. 'rpx,' +
  71. -yOffset / 100 +
  72. 'rpx)',
  73. }"
  74. /> -->
  75. </view>
  76. <view class="switchBox">
  77. <text class="name">呼吸灯</text>
  78. <switch
  79. :checked="statusLight == 1"
  80. @change="handleLightChange"
  81. :active-value="1"
  82. :inactive-value="0"
  83. size="24px"
  84. active-color="#07c160"
  85. inactive-color="#eeeff1"
  86. style="transform: scale(0.8)"
  87. />
  88. </view>
  89. <view class="notice-info">
  90. <view class="notice_title" @click="discrepancy">
  91. <text style="color: #95a4b3; font-size: 28rpx">{{
  92. todayDate
  93. }}</text>
  94. <image src="../../static/rightArrow.png"></image>
  95. </view>
  96. <!-- <view
  97. @click="getFrenEcharts()"
  98. class="title"
  99. v-if="
  100. devInfo.installPosition == 'Bedroom' ||
  101. (breathRate !== 0 && breathRate !== '')
  102. "
  103. >
  104. <view
  105. class="title-text"
  106. style="color: #111111; font-size: 30rpx"
  107. >当前呼吸率</view
  108. >
  109. <view
  110. style="
  111. display: flex;
  112. justify-content: center;
  113. align-items: center;
  114. "
  115. >
  116. <view
  117. class="title-btn"
  118. style="color: #111111; font-size: 30rpx"
  119. v-if="breathRate !== ''"
  120. >
  121. {{ breathRate }}次/分钟</view
  122. >
  123. <view
  124. v-else
  125. class="title-btn"
  126. style="color: #111111; font-size: 30rpx"
  127. >
  128. 暂无
  129. </view>
  130. <image
  131. src="../../static/rightArrow.png"
  132. style="margin-left: auto; width: 30rpx; height: 30rpx"
  133. ></image>
  134. </view>
  135. </view> -->
  136. <view class="title" v-if="devInfo.installPosition == 'Toilet'">
  137. <view class="title-text" style="color: #22dea7"
  138. >今日卫生间使用频次</view
  139. >
  140. <view class="title-btn" style="color: #22dea7"
  141. >{{
  142. freQuenceList.length == "" ? "0" : freQuenceList.length
  143. }}次</view
  144. >
  145. </view>
  146. <view class="title" v-if="devInfo.installPosition != 'Toilet'">
  147. <view class="title-text" style="color: #22dea7"
  148. >今日进出频次</view
  149. >
  150. <view class="title-btn" style="color: #22dea7"
  151. >{{
  152. freQuenceList.length == "" ? "0" : freQuenceList.length
  153. }}次</view
  154. >
  155. </view>
  156. <view
  157. class="stayDetail"
  158. v-if="freQuenceList.length > 0 && freQuenceList.length == 1"
  159. >
  160. <view v-for="item in freQuenceList" :key="item.id">
  161. <view class="stayDetail-item">
  162. <view class="stayDetail-text"
  163. >{{
  164. item.info.start_time.slice(11, 16)
  165. }}目标进入</view
  166. >
  167. <view class="stayDetail-btn"
  168. >{{
  169. item.info.end_time.slice(11, 16)
  170. }}目标离开</view
  171. >
  172. </view>
  173. </view>
  174. </view>
  175. <view
  176. class="stayDetail"
  177. v-if="freQuenceList.length > 0 && freQuenceList.length > 1"
  178. >
  179. <swiper
  180. class="auto-scroll-swiper"
  181. :indicator-dots="false"
  182. :autoplay="false"
  183. :interval="3000"
  184. :circular="true"
  185. :display-multiple-items="1"
  186. :vertical="false"
  187. :current="currentIndex"
  188. @change="onSwiperChange"
  189. >
  190. <swiper-item
  191. v-for="item in freQuenceList"
  192. :key="item.id"
  193. class="stayDetail-item"
  194. >
  195. <view class="stayDetail-text"
  196. >{{
  197. item.info.start_time.slice(11, 16)
  198. }}目标进入</view
  199. >
  200. <view class="stayDetail-btn"
  201. >{{
  202. item.info.end_time.slice(11, 16)
  203. }}目标离开</view
  204. >
  205. </swiper-item>
  206. </swiper>
  207. </view>
  208. <!-- <view class="title" v-if="devInfo.installPosition == 'Toilet'">
  209. <view class="title-text" style="color: #ff976a"
  210. >昨日卫生间使用频次</view
  211. >
  212. <view class="title-btn" style="color: #ff976a"
  213. >{{
  214. freQuenceList.length == "" ? "0" : freQuenceList.length
  215. }}次</view
  216. >
  217. </view>
  218. <view class="title" v-else>
  219. <view class="title-text" style="color: #ff976a"
  220. >昨日进出频次</view
  221. >
  222. <view class="title-btn" style="color: #ff976a"
  223. >{{
  224. freQuenceList.length == "" ? "0" : freQuenceList.length
  225. }}次</view
  226. >
  227. </view> -->
  228. </view>
  229. <view class="box" v-if="!breathShow">
  230. <view class="handle-btn">
  231. <view class="btn1" @click="shareDevice">分享</view>
  232. <view class="btn1" @click="gotoSetting">设置</view>
  233. <view class="btn2" @click="healthAlarm">守护计划</view>
  234. </view>
  235. </view>
  236. <view class="box" v-else>
  237. <view class="handle-btn">
  238. <view class="closeBreath" @click="breathShow = false"
  239. >关闭呼吸率曲线图</view
  240. >
  241. <view class="btn2" @click="saveBreath"> 保存呼吸率曲线图 </view>
  242. </view>
  243. </view>
  244. <!-- 遮罩层 -->
  245. <view class="mask" v-if="shareModel" @click="shareModel = false"></view>
  246. <!-- 弹窗内容 -->
  247. <view class="share-modal" v-if="shareModel">
  248. <view class="modal-header">
  249. <text class="cancel-btn" @click="shareModel = false">取消</text>
  250. <text class="modal-title">分享</text>
  251. <text class="confirm-btn" @click="onShareConfirm()">确认</text>
  252. </view>
  253. <view class="modal-body">
  254. <view class="info-row">
  255. <view class="label">设备序列号:</view>
  256. <view class="value">{{ devInfo.clientId }}</view>
  257. </view>
  258. <view class="info-row">
  259. <view class="label">设备名称:</view>
  260. <view class="value">{{ devInfo.devName }}</view>
  261. </view>
  262. <view class="input-row phoneInfo">
  263. <view>被分享人</view>
  264. <input
  265. class="input"
  266. placeholder="请输入手机号"
  267. type="number"
  268. v-model="sharedPhone"
  269. />
  270. </view>
  271. <view class="funChoice">
  272. <view class="funItem" @click="smChange()">
  273. <label class="simple-radio">
  274. <radio
  275. :value="messageFlag"
  276. color="#7c5345"
  277. :checked="messageFlag == true"
  278. class="hide-original"
  279. />
  280. <text>短信权限</text>
  281. </label>
  282. </view>
  283. <view class="funItem">
  284. <label class="simple-radio" @click="snChange()">
  285. <radio
  286. :value="serviceNumberFlag"
  287. color="#7c5345"
  288. :checked="serviceNumberFlag == true"
  289. class="hide-original"
  290. />
  291. <text>服务号通知</text>
  292. </label>
  293. </view>
  294. <view class="funItem">
  295. <label class="simple-radio" @click="vfChange()">
  296. <radio
  297. :value="voipFlag"
  298. color="#7c5345"
  299. :checked="voipFlag == true"
  300. class="hide-original"
  301. />
  302. <text>语音通话</text>
  303. </label>
  304. </view>
  305. </view>
  306. </view>
  307. </view>
  308. <view class="modal-mask" v-if="choiceVisible" @click="closeChoice">
  309. <view class="modal-container">
  310. <view class="modal-header">
  311. <text class="title">请选择分享方式</text>
  312. </view>
  313. <view class="modal-buttons">
  314. <!-- 手机号分析按钮 -->
  315. <button class="btn phone-btn" @click="handlePhoneAnalysis">
  316. <text>手机号分享</text>
  317. </button>
  318. <!-- 链接分享按钮 -->
  319. <button class="btn link-btn" @click="handleLinkShare">
  320. <text>链接分享</text>
  321. </button>
  322. </view>
  323. </view>
  324. </view>
  325. <!-- ECharts图标模块 -->
  326. <view v-if="breathShow" class="echartsClass">
  327. <image
  328. src="../../static/closePng.png"
  329. class="closePng"
  330. @click="breathShow = false"
  331. ></image>
  332. <l-echart
  333. id="chart-canvas"
  334. canvas-id="chart-canvas"
  335. ref="chartRef"
  336. @finished="initChart"
  337. v-if="breathShow"
  338. @click="breathShow = false"
  339. ></l-echart>
  340. </view>
  341. <alarModel v-if="showModle" ref="alarmModel" />
  342. </view>
  343. </template>
  344. <script>
  345. // import * as echarts from "../../uni_modules/lime-echart/static/echarts.min";
  346. import MqttService from "../../utils/globalMqtt.js";
  347. export default {
  348. data() {
  349. return {
  350. clientId: "",
  351. width: 0, //检测区域宽度
  352. length: 0, //检测区域长度
  353. xOffset: 0,
  354. yOffset: 0,
  355. devInfo: "",
  356. actionName: "",
  357. startDate: "",
  358. endDate: "",
  359. softWare: "",
  360. statusLight: 0,
  361. currentDate: new Date().getTime(),
  362. lnbAction: "action8",
  363. wsj: false,
  364. todayWcTimes: "",
  365. stayDetail: "",
  366. todayDate: "",
  367. dev_id: "",
  368. nowTime: "",
  369. devName: "",
  370. devType: "",
  371. localPhone: uni.getStorageSync("phone"),
  372. startArr: [],
  373. freQuenceList: [],
  374. // mqtt相关
  375. currentIndex: 0,
  376. modules: [],
  377. autoPlayinterval: "",
  378. choiceVisible: "",
  379. // 手机号分享授权模块
  380. shareModel: false,
  381. alarmModel: false,
  382. sharedPhone: "",
  383. messageFlag: true,
  384. serviceNumberFlag: true,
  385. voipFlag: true,
  386. // mqtt模块
  387. targetPoints: {},
  388. inactivityTimer: null,
  389. left: 0,
  390. top: 0,
  391. clientIdProp: null,
  392. breathRate: "",
  393. breathShow: false,
  394. breathRpmList: [],
  395. option: {
  396. title: [
  397. {
  398. text: "呼吸率曲线",
  399. left: "center",
  400. top: 20,
  401. textStyle: { fontSize: 14 },
  402. },
  403. {
  404. text: "BPM: 0 次/分钟",
  405. left: "center",
  406. top: 50,
  407. textStyle: { fontSize: 12, color: "#805246" },
  408. },
  409. {
  410. text: "时间 (秒)",
  411. left: "right",
  412. top: "bottom",
  413. textStyle: { fontSize: 12, color: "#888888" },
  414. },
  415. ],
  416. grid: { left: 60, right: 20, top: 80, bottom: 50 },
  417. xAxis: {
  418. type: "category",
  419. data: Array.from({ length: 60 }, (_, i) => i + 1),
  420. boundaryGap: false,
  421. splitLine: { show: false },
  422. },
  423. yAxis: {
  424. type: "value",
  425. min: 0,
  426. max: 40,
  427. name: "呼吸率(次)",
  428. nameLocation: "end",
  429. nameGap: 20,
  430. nameTextStyle: { fontSize: 12, color: "#888888" },
  431. splitLine: { show: true },
  432. },
  433. series: [
  434. {
  435. type: "line",
  436. smooth: true,
  437. symbol: "none",
  438. lineStyle: { color: "#805246", width: 2 },
  439. data: Array(60).fill(0),
  440. },
  441. ],
  442. animation: true,
  443. animationDuration: 100,
  444. },
  445. index: 0,
  446. showModle: false,
  447. };
  448. },
  449. computed: {},
  450. methods: {
  451. getdevInfo(devId) {
  452. this.$http
  453. .get(`wap/device/queryDeviceInfoById`, {
  454. devId: devId,
  455. })
  456. .then((res) => {
  457. if (res.data.data) {
  458. this.devInfo = res.data.data;
  459. this.devType = this.devInfo.devType;
  460. this.width =
  461. Math.abs(
  462. this.devInfo.yyEnd - this.devInfo.yyStart
  463. ) * 100;
  464. this.length =
  465. Math.abs(
  466. this.devInfo.xxEnd - this.devInfo.xxStart
  467. ) * 100;
  468. this.xOffset =
  469. (this.devInfo.xxStart + this.devInfo.xxEnd) * 50;
  470. this.yOffset =
  471. -(this.devInfo.yyStart + this.devInfo.yyEnd) * 50;
  472. this.statusLight = this.devInfo.statusLight;
  473. }
  474. })
  475. .catch((err) => {});
  476. },
  477. getdevRoomInfo(devId) {
  478. this.$http
  479. .get(`wap/room/readRoom`, {
  480. devId: devId,
  481. })
  482. .then((res) => {
  483. if (res.data.data) {
  484. this.modules = res.data.data.furnitures;
  485. }
  486. });
  487. },
  488. handleLightChange(e) {
  489. let newValue = e.detail.value == true ? 1 : 0;
  490. this.$http
  491. .post(`wap/device/statusLight`, {
  492. statusLight: newValue,
  493. devId: this.devInfo.devId,
  494. })
  495. .then((res) => {
  496. if (res.data.code == 200) {
  497. uni.showToast({
  498. title: "操作成功",
  499. icon: "success",
  500. });
  501. this.statusLight = newValue;
  502. } else {
  503. wx.showToast({
  504. title: res.data.message,
  505. icon: "none",
  506. });
  507. }
  508. });
  509. },
  510. // 分享功能模块
  511. shareDevice() {
  512. this.choiceVisible = true;
  513. },
  514. onShareConfirm() {
  515. if (!this.sharedPhone) {
  516. uni.showModal({
  517. content: "请填写手机号!",
  518. showCancel: false,
  519. });
  520. return;
  521. }
  522. let reg_tel =
  523. /^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8}$/;
  524. if (!reg_tel.test(this.sharedPhone)) {
  525. uni.showModal({
  526. content: "请填写正确手机号!",
  527. showCancel: false,
  528. });
  529. return;
  530. }
  531. let shareParam = {
  532. sharerUserId: uni.getStorageSync("userId"),
  533. devId: this.devInfo.devId,
  534. sharerPhone: uni.getStorageSync("phone"),
  535. sharedUserId: "",
  536. sharedPhone: this.sharedPhone,
  537. messageFlag: this.messageFlag == true ? 0 : 1,
  538. serviceNumberFlag: this.serviceNumberFlag == true ? 0 : 1,
  539. voipFlag: this.voipFlag == true ? 0 : 1,
  540. };
  541. this.$http
  542. .post("wap/share/deviceShare", shareParam, {
  543. header: {
  544. "Content-Type": "application/json;charset=UTF-8",
  545. },
  546. })
  547. .then((res) => {
  548. if (res.data.code == 200) {
  549. uni.showToast({
  550. title: "分享成功",
  551. icon: "success",
  552. duration: 1500,
  553. });
  554. } else {
  555. uni.showToast({
  556. title: res.data.message,
  557. icon: "none",
  558. duration: 1500,
  559. });
  560. }
  561. });
  562. this.shareModel = false;
  563. },
  564. closeChoice() {
  565. this.choiceVisible = false;
  566. },
  567. handlePhoneAnalysis() {
  568. this.choiceVisible = false;
  569. this.shareModel = true;
  570. },
  571. handleLinkShare() {
  572. this.choiceVisible = false;
  573. uni.navigateTo({
  574. url:
  575. "/pagesA/linkShare/linkShare?devInfo=" +
  576. JSON.stringify(this.devInfo),
  577. });
  578. },
  579. smChange() {
  580. this.messageFlag = !this.messageFlag;
  581. },
  582. snChange() {
  583. this.serviceNumberFlag = !this.serviceNumberFlag;
  584. },
  585. vfChange() {
  586. this.voipFlag = !this.voipFlag;
  587. },
  588. gotoSetting() {
  589. if (this.devInfo.online == 0) {
  590. uni.showToast({
  591. title: "离线设备不支持设置",
  592. icon: "none",
  593. });
  594. return;
  595. }
  596. uni.navigateTo({
  597. url:
  598. "/pagesA/deviceSetting/deviceSetting?devInfo=" +
  599. JSON.stringify(this.devInfo),
  600. });
  601. },
  602. getFrequency(clientId) {
  603. this.$http
  604. .post(`wap/stats/alarmEventsQuery`, {
  605. clientId: clientId,
  606. createTimeStart: this.$time(new Date()),
  607. createTimeEnd: this.$time(new Date()),
  608. eventType: 1,
  609. })
  610. .then((res) => {
  611. if (res.data.code == 200) {
  612. if (res.data.data.rows.length > 0) {
  613. this.freQuenceList = this.parseJsonToObjects(
  614. res.data.data.rows
  615. );
  616. } else {
  617. this.freQuenceList = [];
  618. }
  619. } else {
  620. wx.showToast({
  621. title: res.data.message,
  622. icon: "none",
  623. });
  624. }
  625. });
  626. },
  627. parseJsonToObjects(jsonArray) {
  628. return jsonArray.map((item) => {
  629. // 解析info字段的JSON字符串
  630. let infoData = {};
  631. try {
  632. infoData = JSON.parse(item.info);
  633. } catch (e) {
  634. console.error("Failed to parse info JSON:", e);
  635. }
  636. return {
  637. id: item.id,
  638. clientId: item.clientId,
  639. tenantId: item.tenantId,
  640. devName: item.devName,
  641. uuid: item.uuid,
  642. planUuid: item.planUuid,
  643. eventType: item.eventType,
  644. info: infoData,
  645. isHandle: item.isHandle,
  646. createTime: item.createTime,
  647. remark: item.remark,
  648. };
  649. });
  650. },
  651. // 健康闹钟方法
  652. healthAlarm() {
  653. uni.navigateTo({
  654. url:
  655. "/pagesA/healthAlarm/healthAlarm?devInfo=" +
  656. JSON.stringify(this.devInfo),
  657. });
  658. },
  659. onSwiperChange(event) {
  660. const current = event.detail.current;
  661. const totalItems = this.freQuenceList.length;
  662. if (current === totalItems - 1) {
  663. this.autoplay = false;
  664. }
  665. this.currentIndex = current;
  666. },
  667. autoSwipe() {
  668. if (this.freQuenceList && this.freQuenceList.length > 0) {
  669. setInterval(() => {
  670. let nextIndex = this.currentIndex + 1;
  671. if (nextIndex >= this.freQuenceList.length) {
  672. nextIndex = 0; // 循环到第一个项目
  673. }
  674. this.currentIndex = nextIndex;
  675. }, 3000); // 每3秒自动滚动一次
  676. }
  677. },
  678. discrepancy() {
  679. uni.navigateTo({
  680. url:
  681. "/pagesA/discrepancy/discrepancy?freQuenceList=" +
  682. JSON.stringify(this.freQuenceList),
  683. });
  684. },
  685. getCurrentDate() {
  686. const now = new Date();
  687. this.currentDate = `${now.getFullYear()}-${
  688. now.getMonth() + 1
  689. }月${now.getDate().toString().padStart(2, "0")}日`;
  690. },
  691. receptionChange(val) {
  692. this.targetPoints = val;
  693. },
  694. receptHealth(val) {
  695. this.breathRate = val;
  696. this.setEcharts(val);
  697. },
  698. // echarts图表模块
  699. getOption(list) {
  700. // 固定 X 轴 [0 ~ 60]
  701. const xData = Array.from({ length: 61 }, (_, i) => i);
  702. const recent = list.slice(-61);
  703. const data = new Array(61).fill(null);
  704. for (let i = 0; i < recent.length; i++) {
  705. data[i] = recent[i];
  706. }
  707. return {
  708. title: [
  709. { text: "呼吸率曲线", left: "center", top: 20 },
  710. {
  711. text: `BPM: ${recent[recent.length - 1] || 0} 次/分钟`,
  712. left: "center",
  713. top: 50,
  714. textStyle: { fontSize: 12, color: "#805246" },
  715. },
  716. {
  717. text: "时间 (秒)",
  718. left: "right",
  719. top: "bottom",
  720. textStyle: {
  721. fontSize: 10,
  722. color: "#888888",
  723. fontWeight: "normal",
  724. },
  725. },
  726. ],
  727. grid: { left: 60, right: 20, top: 80, bottom: 50 },
  728. xAxis: {
  729. type: "category",
  730. data: xData,
  731. boundaryGap: false,
  732. },
  733. yAxis: {
  734. type: "value",
  735. min: 0,
  736. max: 40,
  737. name: "呼吸率(次)",
  738. nameLocation: "end",
  739. nameGap: 20,
  740. nameTextStyle: {
  741. fontSize: 10,
  742. color: "#888888",
  743. fontWeight: "normal",
  744. },
  745. splitLine: { show: true },
  746. },
  747. series: [
  748. {
  749. type: "line",
  750. smooth: true,
  751. symbol: "none",
  752. data: data,
  753. showSymbol: false,
  754. lineStyle: { color: "#7a4e42", width: 2 },
  755. },
  756. ],
  757. };
  758. },
  759. getFrenEcharts() {
  760. if (this.breathRate === "" || this.breathRate === null) {
  761. uni.showToast({
  762. title: "暂无呼吸率",
  763. icon: "none",
  764. duration: 1500,
  765. });
  766. return;
  767. }
  768. this.breathShow = true;
  769. this.$nextTick(() => {
  770. this.initChart();
  771. });
  772. },
  773. initChart() {
  774. if (!this.$refs.chartRef) return;
  775. if (this.chartInstance) {
  776. this.chartInstance.dispose();
  777. this.chartInstance = null;
  778. }
  779. this.$refs.chartRef.init(echarts, (chart) => {
  780. this.chartInstance = chart;
  781. chart.setOption(this.option, true);
  782. });
  783. },
  784. setEcharts(val) {
  785. if (!Array.isArray(this.breathRpmList)) {
  786. this.breathRpmList = [];
  787. }
  788. this.breathRpmList.push(val);
  789. if (!this.chartInstance) return;
  790. const option = this.getOption(this.breathRpmList);
  791. this.chartInstance.setOption(option, { notMerge: true });
  792. },
  793. saveBreath() {
  794. const chart = this.$refs.chartRef;
  795. if (!chart) {
  796. uni.showToast({ title: "图表未渲染", icon: "none" });
  797. return;
  798. }
  799. chart.canvasToTempFilePath({
  800. success: (res) => {
  801. uni.saveImageToPhotosAlbum({
  802. filePath: res.tempFilePath,
  803. success: () => {
  804. uni.showToast({
  805. title: "保存成功",
  806. icon: "success",
  807. });
  808. },
  809. fail: (err) => {
  810. uni.showToast({
  811. title: "保存失败",
  812. icon: "none",
  813. });
  814. },
  815. });
  816. },
  817. fail: (err) => {
  818. uni.showToast({
  819. title: "导出失败",
  820. icon: "none",
  821. });
  822. },
  823. });
  824. },
  825. handleMessage(topic, message, clientId) {
  826. // 清除不活动定时器
  827. clearTimeout(this.inactivityTimer);
  828. this.inactivityTimer = setTimeout(() => {
  829. this.targetPoints = {};
  830. console.log("长时间没有点位消除");
  831. }, 1500);
  832. // 验证topic格式
  833. const match = topic.match(/^\/dev\/(.+)\/tracker_targets$/);
  834. if (!match || match[1] !== clientId) return;
  835. try {
  836. const data = JSON.parse(message.toString());
  837. if (data.health) {
  838. if (
  839. data.health.breath_rpm ||
  840. data.health.breath_rpm === 0
  841. ) {
  842. this.receptHealth(Math.floor(data.health.breath_rpm));
  843. } else {
  844. }
  845. }
  846. this.processTrackerData(data.tracker_targets);
  847. // console.log(data.tracker_targets, "MQTT消息解析成功22222");
  848. } catch (e) {
  849. console.error("MQTT消息解析失败", e);
  850. }
  851. },
  852. processTrackerData(arr) {
  853. if (Array.isArray(arr) && arr.length > 0 && Array.isArray(arr[0])) {
  854. this.targetPoints = {};
  855. const currentIds = new Set();
  856. const newTargetPoints = {};
  857. // 处理每个追踪目标
  858. arr.forEach((item) => {
  859. if (!Array.isArray(item) || item.length < 4) return;
  860. const [x, y, z, id] = item;
  861. currentIds.add(id.toString());
  862. // 处理新点或更新现有点
  863. if (!this.targetPoints[id]) {
  864. newTargetPoints[id] = this.createNewTargetPoint(
  865. x,
  866. y,
  867. z,
  868. id
  869. );
  870. } else {
  871. newTargetPoints[id] = this.updateExistingTargetPoint(
  872. this.targetPoints[id],
  873. x,
  874. y,
  875. z,
  876. 2
  877. );
  878. }
  879. });
  880. // 移除不存在的点
  881. Object.keys(this.targetPoints).forEach((id) => {
  882. if (!currentIds.has(id)) {
  883. delete this.targetPoints[id];
  884. }
  885. });
  886. // 更新目标点
  887. this.targetPoints = {
  888. ...this.targetPoints,
  889. ...newTargetPoints,
  890. };
  891. if (Array.isArray(this.targetPoints)) {
  892. this.targetPoints = this.targetPoints.filter(
  893. (item) => item !== null && item !== undefined
  894. );
  895. }
  896. }
  897. },
  898. createNewTargetPoint(x, y, z, id) {
  899. return {
  900. x,
  901. y,
  902. z,
  903. id,
  904. displayX: x - Number(this.devInfo.xxStart),
  905. displayY: y - Number(this.devInfo.yyEnd),
  906. lastX: x,
  907. lastY: y,
  908. };
  909. },
  910. updateExistingTargetPoint(existingPoint, x, y, z, THRESHOLD) {
  911. const dx = x - existingPoint.lastX;
  912. const dy = y - existingPoint.lastY;
  913. const distance = Math.sqrt(dx * dx + dy * dy);
  914. if (distance > THRESHOLD) {
  915. return {
  916. ...existingPoint,
  917. x,
  918. y,
  919. z,
  920. lastX: x,
  921. lastY: y,
  922. displayX: x - Number(this.devInfo.xxStart),
  923. displayY: y - Number(this.devInfo.yyEnd),
  924. };
  925. }
  926. return existingPoint;
  927. },
  928. },
  929. onShow() {
  930. this.showModle = true;
  931. this.todayDate = this.$time(new Date(), 2);
  932. },
  933. onLoad(options) {
  934. const devItem = JSON.parse(options.devItem);
  935. const { devId, clientId } = devItem;
  936. this.getFrequency(clientId);
  937. this.getdevInfo(devId);
  938. this.getdevRoomInfo(devId);
  939. this.autoPlayinterval = setTimeout(() => {
  940. this.autoSwipe();
  941. }, 3000);
  942. this.getCurrentDate();
  943. this.clientId = clientId;
  944. console.log(this.clientId, "clientIDetail");
  945. this.clientId = clientId;
  946. let userId = uni.getStorageSync("userId");
  947. const topic = `/dev/${this.clientId}/tracker_targets`;
  948. // 使用 MqttService.subscribe 管理订阅
  949. this.unsubscribeFn = MqttService.subscribe(
  950. "DATA",
  951. topic,
  952. (message, msgTopic) => {
  953. console.log(`接收到 ${msgTopic} 消息:`, message);
  954. // 处理消息
  955. const dataMatch = msgTopic.match(
  956. /^\/dev\/(.+)\/tracker_targets$/
  957. );
  958. const cmdMatch = msgTopic.match(/^\/mps\/wx_(.+)\/notice$/);
  959. if (dataMatch && dataMatch[1] === this.clientId) {
  960. this.handleMessage(msgTopic, message, this.clientId);
  961. } else if (cmdMatch) {
  962. this.$refs.alarmModel.hanOtherMessage(msgTopic, message);
  963. }
  964. }
  965. );
  966. if (this.unsubscribeFn) {
  967. console.log(`✅ 已成功订阅主题: ${topic}`);
  968. }
  969. },
  970. onUnload() {
  971. this.inactivityTimer = null;
  972. this.autoPlayinterval = null;
  973. if (this.unsubscribeFn) {
  974. this.unsubscribeFn();
  975. this.unsubscribeFn = null;
  976. }
  977. // 关闭 DATA 连接
  978. // MqttService.disconnectData();
  979. },
  980. onHide() {
  981. this.showModle = false;
  982. },
  983. beforeDestroy() {
  984. console.log("组件销毁时调用");
  985. },
  986. };
  987. </script>
  988. <style lang="less" scoped>
  989. .content {
  990. height: 100vh;
  991. background: linear-gradient(180deg, #faede2 0%, #f4f4f4 100%);
  992. box-sizing: border-box;
  993. padding-top: 20rpx;
  994. .name_box {
  995. display: flex;
  996. justify-content: center;
  997. align-items: center;
  998. margin: 0 auto 37rpx 0;
  999. .name_content {
  1000. display: inline-flex;
  1001. background: rgba(255, 255, 255, 0.65);
  1002. border-radius: 37rpx;
  1003. padding: 6rpx 18rpx;
  1004. }
  1005. }
  1006. .radar-box {
  1007. margin: 0 auto;
  1008. position: relative;
  1009. display: flex;
  1010. align-items: center;
  1011. justify-content: center;
  1012. width: 710rpx;
  1013. height: 710rpx;
  1014. background: #ffffff;
  1015. border-radius: 37.5rpx;
  1016. box-sizing: border-box;
  1017. .center {
  1018. position: absolute;
  1019. background-color: #fff;
  1020. border: 14rpx solid #333333;
  1021. background-image: url("https://hflnxx.oss-cn-shanghai.aliyuncs.com/IMAGE/20250919/toilet_bg.png");
  1022. background-repeat: no-repeat;
  1023. background-position: center;
  1024. transform: scale(1.3);
  1025. .moduleContent {
  1026. position: relative;
  1027. view {
  1028. position: absolute;
  1029. }
  1030. .module-img {
  1031. width: 100%;
  1032. height: 100%;
  1033. display: block;
  1034. }
  1035. }
  1036. }
  1037. .tranStyle {
  1038. position: absolute;
  1039. background-color: #fff;
  1040. border: 9rpx solid #333333;
  1041. background-image: url("https://hflnxx.oss-cn-shanghai.aliyuncs.com/IMAGE/20250919/toilet_bg.png");
  1042. background-repeat: no-repeat;
  1043. background-position: center;
  1044. transform: scale(2.3);
  1045. .moduleContent {
  1046. // overflow: hidden;
  1047. // position: relative;
  1048. view {
  1049. position: absolute;
  1050. }
  1051. .module-img {
  1052. width: 100%;
  1053. height: 100%;
  1054. display: block;
  1055. }
  1056. }
  1057. }
  1058. .action-icon-G {
  1059. position: absolute;
  1060. width: 100rpx;
  1061. height: 100rpx;
  1062. }
  1063. .action-icon-M {
  1064. // position: absolute;
  1065. width: 50rpx;
  1066. height: 50rpx;
  1067. }
  1068. .redar-pic {
  1069. position: absolute;
  1070. left: 50%;
  1071. top: 50%;
  1072. width: 40rpx;
  1073. height: 40rpx;
  1074. transform: translate(-50%, -50%); /* 先居中 */
  1075. }
  1076. }
  1077. .switchBox {
  1078. width: 710rpx;
  1079. height: 94rpx;
  1080. margin: 18rpx auto;
  1081. padding: 0 37rpx;
  1082. display: flex;
  1083. align-items: center;
  1084. background: #ffffff;
  1085. border-radius: 37rpx;
  1086. box-sizing: border-box;
  1087. .name {
  1088. color: #111111;
  1089. font-size: 32rpx;
  1090. }
  1091. }
  1092. .notice-info {
  1093. width: 710rpx;
  1094. max-height: 300rpx;
  1095. // overflow: hidden;
  1096. padding: 30rpx 37rpx 10rpx 37rpx;
  1097. background: #ffffff;
  1098. border-radius: 37rpx;
  1099. box-sizing: border-box;
  1100. margin: 0 auto;
  1101. .notice_title {
  1102. display: flex;
  1103. align-items: space-between;
  1104. image {
  1105. margin-left: auto;
  1106. width: 30rpx;
  1107. height: 30rpx;
  1108. }
  1109. }
  1110. .title {
  1111. margin-top: 10rpx;
  1112. margin-bottom: 10rpx;
  1113. font-family: PingFang SC, PingFang SC;
  1114. font-weight: 500;
  1115. font-size: 34rpx;
  1116. color: #1757dd;
  1117. display: flex;
  1118. align-items: center;
  1119. justify-content: space-between;
  1120. .title-text {
  1121. font-size: 28rpx;
  1122. font-weight: 500;
  1123. color: #1757dd;
  1124. }
  1125. .title-btn {
  1126. font-size: 28rpx;
  1127. font-weight: 500;
  1128. color: #5a5a5a;
  1129. }
  1130. }
  1131. .stayDetail {
  1132. height: 80rpx;
  1133. // overflow: hidden;
  1134. margin-top: 10rpx;
  1135. margin-bottom: 10rpx;
  1136. padding-left: 20rpx;
  1137. font-family: PingFang SC, PingFang SC;
  1138. font-weight: 500;
  1139. font-size: 34rpx;
  1140. .stayDetail-item {
  1141. display: flex;
  1142. padding-bottom: 5rpx !important;
  1143. padding-top: 10rpx !important;
  1144. box-sizing: border-box;
  1145. line-height: 60rpx;
  1146. .stayDetail-text {
  1147. width: 40%;
  1148. font-size: 28rpx;
  1149. height: 30rpx !important;
  1150. }
  1151. .stayDetail-btn {
  1152. padding-left: 30rpx;
  1153. font-size: 28rpx;
  1154. height: 30rpx !important;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. .box {
  1160. position: fixed;
  1161. bottom: 0;
  1162. left: 0;
  1163. width: 100vw;
  1164. height: 168rpx;
  1165. padding: 0 37rpx;
  1166. background: #ffffff;
  1167. box-sizing: border-box;
  1168. .handle-btn {
  1169. margin-top: 40rpx;
  1170. display: flex;
  1171. align-items: center;
  1172. justify-content: space-between;
  1173. .btn1 {
  1174. display: flex;
  1175. align-items: center;
  1176. justify-content: center;
  1177. width: 155rpx;
  1178. height: 94rpx;
  1179. background: #ffebe4;
  1180. border-radius: 28rpx;
  1181. font-weight: 500;
  1182. color: #111111;
  1183. font-size: 32rpx;
  1184. text-align: center;
  1185. }
  1186. .btn2 {
  1187. display: flex;
  1188. align-items: center;
  1189. justify-content: center;
  1190. width: 328rpx;
  1191. height: 94rpx;
  1192. background: linear-gradient(
  1193. 105.95deg,
  1194. #a27867 0%,
  1195. #74483d 100%
  1196. );
  1197. border-radius: 28rpx;
  1198. box-shadow: 0rpx 4.69rpx 18.75rpx rgba(72, 41, 29, 0.15),
  1199. 0rpx 9.38rpx 9.38rpx rgba(154, 132, 89, 0.2),
  1200. 0rpx -4.69rpx 28.13rpx 4.69rpx #a16647 inset;
  1201. font-family: MiSans;
  1202. font-weight: 500;
  1203. color: #ffffff;
  1204. font-size: 32rpx;
  1205. }
  1206. .closeBreath {
  1207. display: flex;
  1208. align-items: center;
  1209. justify-content: center;
  1210. width: 328rpx;
  1211. height: 94rpx;
  1212. background: #ffebe4;
  1213. border-radius: 28rpx;
  1214. font-weight: 500;
  1215. color: #111111;
  1216. font-size: 32rpx;
  1217. text-align: center;
  1218. }
  1219. }
  1220. }
  1221. /* 弹窗部分样式 */
  1222. .mask {
  1223. position: fixed;
  1224. left: 0;
  1225. top: 0;
  1226. right: 0;
  1227. bottom: 0;
  1228. background: rgba(0, 0, 0, 0.3);
  1229. z-index: 100;
  1230. }
  1231. .share-modal {
  1232. position: fixed;
  1233. left: 0;
  1234. right: 0;
  1235. bottom: 0;
  1236. background: #fff;
  1237. border-radius: 24rpx 24rpx 0 0;
  1238. z-index: 101;
  1239. height: 750rpx;
  1240. .modal-header {
  1241. display: flex;
  1242. justify-content: space-between;
  1243. align-items: center;
  1244. padding: 32rpx 32rpx 0 32rpx;
  1245. font-size: 30rpx;
  1246. .cancel-btn {
  1247. color: #888;
  1248. font-size: 32rpx;
  1249. }
  1250. .modal-title {
  1251. color: #111111;
  1252. font-size: 36rpx;
  1253. }
  1254. .confirm-btn {
  1255. color: #996e5f;
  1256. font-size: 32rpx;
  1257. }
  1258. }
  1259. .modal-body {
  1260. padding: 50rpx;
  1261. .info-row {
  1262. display: flex;
  1263. margin-bottom: 24rpx;
  1264. font-size: 28rpx;
  1265. padding: 0 20rpx;
  1266. .label {
  1267. color: #111111;
  1268. width: 200rpx;
  1269. font-size: 32rpx;
  1270. text-align-last: justify;
  1271. }
  1272. .value {
  1273. text-align: right;
  1274. width: 65%;
  1275. color: #111111;
  1276. font-size: 32rpx;
  1277. }
  1278. }
  1279. .input-row {
  1280. display: flex;
  1281. align-items: center;
  1282. margin-top: 32rpx;
  1283. border-radius: 40rpx;
  1284. background: #f7f7f7;
  1285. padding: 0 24rpx;
  1286. height: 80rpx;
  1287. .input {
  1288. text-align: right;
  1289. flex: 1;
  1290. border: none;
  1291. background: transparent;
  1292. font-size: 28rpx;
  1293. color: #333;
  1294. }
  1295. }
  1296. .funChoice {
  1297. .funItem {
  1298. .simple-radio {
  1299. display: flex;
  1300. align-items: center;
  1301. padding: 20rpx 0;
  1302. }
  1303. }
  1304. }
  1305. }
  1306. }
  1307. // 分享弹窗样式
  1308. .modal-mask {
  1309. position: fixed;
  1310. top: 0;
  1311. left: 0;
  1312. right: 0;
  1313. bottom: 0;
  1314. background: rgba(0, 0, 0, 0.5);
  1315. display: flex;
  1316. justify-content: center;
  1317. align-items: center;
  1318. z-index: 333;
  1319. .modal-container {
  1320. width: 80%;
  1321. background: #fff;
  1322. border-radius: 16rpx;
  1323. // overflow: hidden;
  1324. animation: fadeIn 0.3s;
  1325. .modal-header {
  1326. padding: 30rpx;
  1327. text-align: center;
  1328. border-bottom: 1rpx solid #f5f5f5;
  1329. .title {
  1330. font-size: 36rpx;
  1331. display: block;
  1332. margin-bottom: 10rpx;
  1333. }
  1334. }
  1335. .modal-buttons {
  1336. display: flex;
  1337. flex-direction: column;
  1338. padding: 20rpx;
  1339. .btn {
  1340. flex: 1;
  1341. height: 90rpx;
  1342. margin: 15rpx 0;
  1343. border-radius: 45rpx;
  1344. display: flex;
  1345. align-items: center;
  1346. justify-content: center;
  1347. font-size: 32rpx;
  1348. border: none;
  1349. background: none;
  1350. position: relative;
  1351. }
  1352. .btn-icon {
  1353. width: 40rpx;
  1354. height: 40rpx;
  1355. margin-right: 15rpx;
  1356. }
  1357. .phone-btn {
  1358. background: linear-gradient(
  1359. 105.95deg,
  1360. #ba978a 0%,
  1361. #a27867 100%
  1362. );
  1363. color: white;
  1364. }
  1365. .link-btn {
  1366. background: linear-gradient(
  1367. 105.95deg,
  1368. #a27867 0%,
  1369. #74483d 100%
  1370. );
  1371. color: white;
  1372. }
  1373. }
  1374. }
  1375. }
  1376. .echartsClass {
  1377. position: absolute;
  1378. width: 650rpx;
  1379. height: 600rpx;
  1380. top: -8%;
  1381. left: -37%;
  1382. transform: translate(50%, 50%);
  1383. background: #ffffff;
  1384. .closePng {
  1385. width: 40rpx;
  1386. height: 40rpx;
  1387. position: fixed;
  1388. top: 10rpx;
  1389. right: 10rpx;
  1390. z-index: 333;
  1391. }
  1392. }
  1393. }
  1394. </style>