detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <view class="container">
  3. <cu-custom
  4. ref="Dustom"
  5. id="custom"
  6. bgImage="https://yostest175549.obs.cn-east-2.myhuaweicloud.com:443/202306151686796745663B52544232.png"
  7. :isBack="true"
  8. >
  9. <block slot="backText">返回</block>
  10. <block slot="content"> 设备详情 </block>
  11. </cu-custom>
  12. <My_listbox ref="List" :pullDown="false" @getlist="loadData">
  13. <view class="head">
  14. <view class="name">
  15. <view class="left">
  16. <text class="status" :style="{ backgroundColor: detail.bgColor }">{{
  17. detail.status
  18. }}</text>
  19. {{ detail.devicename }}
  20. </view>
  21. <view class="sliding-block" v-if="detail.issupportbluetooth == 1">
  22. <view
  23. class="but"
  24. :class="mode == 0 ? 'action' : ''"
  25. style="left: 0"
  26. hover-class="navigator-hover"
  27. @click="changeMode(0)"
  28. >网络</view
  29. >
  30. <view
  31. class="but"
  32. hover-class="navigator-hover"
  33. style="right: 0"
  34. :class="mode == 1 ? 'action' : ''"
  35. @click="changeMode(1)"
  36. >蓝牙</view
  37. >
  38. <view
  39. class="sliding"
  40. :style="{
  41. transform: `translateX(${mode == 0 ? 0 : '34px'})`,
  42. }"
  43. />
  44. </view>
  45. </view>
  46. <view class="row"> 设备编号:{{ detail.serialnumber || " --" }} </view>
  47. <view class="row">
  48. 最近上线时间:{{ detail.lastconnecttime || " --" }}
  49. </view>
  50. </view>
  51. <preview-image ref="轮播图" :attinfos="detail.attinfos" />
  52. <view class="ceiling" :style="{ top: tovw(CustomBar) }">
  53. <horizontal-direction ref="hd" />
  54. </view>
  55. <view class="ceiling" :style="{ top: tovw(CustomBar + tabsTop) }">
  56. <tabs :tabs="tabs" @changeTab="changeTab" />
  57. </view>
  58. <control ref="设备控制" :detail="detail" @onUpdate="getDetail" />
  59. <daily-record
  60. ref="设备日志"
  61. :isfeedback="detail.isfeedback"
  62. :w_deviceid="w_deviceid"
  63. />
  64. <preview ref="详情信息" :detail="detail" />
  65. <alerts ref="告警记录" :w_deviceid="w_deviceid" />
  66. <view style="height: 30px" />
  67. </My_listbox>
  68. </view>
  69. </template>
  70. <script>
  71. import horizontalDirection from "./modules/horizontalDirection.vue";
  72. import tabs from "./modules/tabs.vue";
  73. import preview from "./modules/preview.vue";
  74. import dailyRecord from "./modules/dailyRecord.vue";
  75. import control from "./modules/control.vue";
  76. import previewImage from "./modules/previewImage.vue";
  77. import alerts from "./modules/alerts.vue";
  78. let page = {};
  79. export default {
  80. components: {
  81. horizontalDirection,
  82. tabs,
  83. preview,
  84. dailyRecord,
  85. control,
  86. previewImage,
  87. alerts,
  88. },
  89. name: "facilityD",
  90. data() {
  91. return {
  92. CustomBar: 0,
  93. tabsTop: 0,
  94. w_deviceid: 0,
  95. detail: {},
  96. mode: 0, //0网络 1蓝牙
  97. showTab: "设备控制",
  98. tabs: [
  99. {
  100. name: "设备控制",
  101. },
  102. {
  103. name: "设备日志",
  104. },
  105. {
  106. name: "告警记录",
  107. },
  108. {
  109. name: "详情信息",
  110. },
  111. ],
  112. };
  113. },
  114. watch: {
  115. mode: function (newv) {
  116. this.$refs.设备控制.mode = newv;
  117. this.$refs.设备控制.uninitialized = true;
  118. this.$refs.设备控制.getControl(true);
  119. },
  120. },
  121. onLoad(options) {
  122. this.w_deviceid = options.id;
  123. },
  124. mounted() {
  125. this.CustomBar = -10;
  126. this.$refs.List.setHeight();
  127. },
  128. onShow() {
  129. // if (["development"].includes(process.env.NODE_ENV)) this.getDetail(true);
  130. if (this.mode == 0) this.getDetail(true);
  131. try {
  132. this.$Http.openNetwork = this.$refs.轮播图.openNetwork;
  133. this.$Http.slideshowSetData = this.$refs.轮播图.setData;
  134. } catch (error) {
  135. setTimeout(() => {
  136. this.$Http.openNetwork = this.$refs.轮播图.openNetwork;
  137. this.$Http.slideshowSetData = this.$refs.轮播图.setData;
  138. }, 100);
  139. }
  140. },
  141. methods: {
  142. getDetail(init = false) {
  143. this.$Http
  144. .basic({
  145. id: 20230615103902,
  146. content: {
  147. nocache: true,
  148. w_deviceid: this.w_deviceid,
  149. },
  150. })
  151. .then((res) => {
  152. console.log("设备详情", res);
  153. if (this.cutoff(res.msg)) return;
  154. if (!res.data.miniapppath) {
  155. res.data.miniapppath = require("../../control/pages").getPageName(
  156. res.data.prodnum
  157. );
  158. if (!res.data.miniapppath) {
  159. //未匹配到设备控制页
  160. this.showTab = "设备日志";
  161. this.tabs.shift();
  162. }
  163. }
  164. console.log("res.data.miniapppath", res.data.miniapppath);
  165. switch (res.data.status) {
  166. case "在线":
  167. res.data.bgColor = "#007aff";
  168. break;
  169. case "禁用":
  170. res.data.bgColor = "#F56C6C";
  171. break;
  172. default:
  173. res.data.bgColor = "#F9AE3D";
  174. break;
  175. }
  176. this.detail = res.data;
  177. if (init) {
  178. let prodnum = res.data.prodnum;
  179. if (res.data.miniapppath)
  180. prodnum = res.data.miniapppath.split("-")[1];
  181. this.$refs.hd
  182. .getList(this.w_deviceid, prodnum)
  183. .then((num) => (this.tabsTop = num));
  184. setTimeout(() => {
  185. this.changeTab({ name: this.showTab }, true);
  186. }, 100);
  187. }
  188. });
  189. },
  190. changeTab({ name }, init = false) {
  191. this.showTab = name;
  192. page.show = false;
  193. page = this.$refs[name];
  194. this.loadData(init);
  195. },
  196. loadData(init) {
  197. // show t =加载 f=变化
  198. if ((page.uninitialized && !page.show) || init) {
  199. console.log("首次加载", this.showTab);
  200. page.show = true;
  201. page.initialize(true);
  202. } else if (page.show) {
  203. page.initialize();
  204. } else {
  205. page.show = true;
  206. }
  207. },
  208. changeMode(mode) {
  209. const that = this;
  210. if (this.mode == mode) return;
  211. switch (mode) {
  212. case 0:
  213. uni.showModal({
  214. content: "是否关闭蓝牙\n并切换至网络控制",
  215. success: function ({ confirm }) {
  216. if (confirm) {
  217. that.mode = mode;
  218. try {
  219. if (that.$Http.Bluetooth)
  220. uni.closeBLEConnection({
  221. deviceId: that.$Http.Bluetooth.device.deviceId,
  222. });
  223. uni.closeBluetoothAdapter();
  224. delete that.$Http.Bluetooth;
  225. } catch (error) {}
  226. }
  227. },
  228. });
  229. break;
  230. case 1:
  231. try {
  232. if (that.$Http.Bluetooth.device.deviceId)
  233. uni.closeBLEConnection({
  234. deviceId: that.$Http.Bluetooth.device.deviceId,
  235. });
  236. } catch (error) {}
  237. uni.closeBluetoothAdapter({
  238. complete: (complete) => {
  239. console.log("closeBluetoothAdapterComplete", complete);
  240. uni.openBluetoothAdapter({
  241. success: (result) => {
  242. if (result.errno == 0) {
  243. uni.navigateTo({
  244. url:
  245. "/Bluetooth/index/index?services=" +
  246. JSON.stringify([
  247. that.detail.prodnum,
  248. that.detail.w_productid,
  249. ]),
  250. });
  251. this.$Http.setBluetooth = function (Bluetooth) {
  252. this.mode = mode;
  253. let curPages = getCurrentPages();
  254. if (
  255. curPages[curPages.length - 1].__route__ ==
  256. "Bluetooth/index/index"
  257. )
  258. uni.navigateBack();
  259. this.$Http.setDetailMode = function (mode1) {
  260. this.mode = mode1;
  261. delete this.$Http.setDetailMode;
  262. uni.closeBluetoothAdapter();
  263. }.bind(this);
  264. this.$Http.Bluetooth = Bluetooth;
  265. delete this.$Http.setBluetooth;
  266. }.bind(this);
  267. } else {
  268. uni.showModal({
  269. title: result.errno,
  270. content: result.Msg,
  271. showCancel: false,
  272. confirmText: "确定",
  273. });
  274. }
  275. },
  276. fail: (fail) => {
  277. console.log("蓝牙初始化fail:", fail);
  278. if (fail.errno == "103") {
  279. uni.showModal({
  280. title: "提示",
  281. content: "未获取使用蓝牙功能授权,请授权后使用",
  282. showCancel: false,
  283. confirmText: "前去授权",
  284. success() {
  285. uni.openSetting({
  286. success({ authSetting }) {
  287. if (authSetting["scope.bluetooth"])
  288. that.changeMode(mode);
  289. },
  290. });
  291. },
  292. });
  293. } else {
  294. const codes = {
  295. 0: "ok",
  296. "-1": "已连接 ",
  297. 10000: "未初始化蓝牙适配器",
  298. 10001: "当前蓝牙适配器不可用",
  299. 10002: "没有找到指定设备",
  300. 10003: "连接失败",
  301. 10004: "没有找到指定服务",
  302. 10005: "没有找到指定特征值",
  303. 10006: "当前连接已断开",
  304. 10007: "当前特征值不支持此操作",
  305. 10008: "其余所有系统上报的异常",
  306. 10009: "系统版本低于 4.3 不支持 BLE",
  307. 10010: "已连接",
  308. 10011: "配对设备需要配对码",
  309. 10012: "连接超时",
  310. 10013: "连接 deviceId 为空或者是格式不正确",
  311. };
  312. uni.showModal({
  313. content: codes[fail.errCode] || fail.errMsg,
  314. showCancel: false,
  315. confirmText: "确认",
  316. });
  317. }
  318. },
  319. });
  320. },
  321. });
  322. break;
  323. }
  324. },
  325. },
  326. };
  327. </script>
  328. <style lang="scss" scoped>
  329. .ceiling {
  330. position: sticky;
  331. z-index: 9;
  332. }
  333. .head {
  334. width: 355px;
  335. background: #ffffff;
  336. border-radius: 4px;
  337. padding: 10px 15px;
  338. box-sizing: border-box;
  339. margin: 10px auto 0;
  340. .name {
  341. display: flex;
  342. line-height: 20px;
  343. font-size: 14px;
  344. font-family: PingFang SC-Medium, PingFang SC;
  345. font-weight: bold;
  346. color: #333333;
  347. margin-bottom: 10px;
  348. .left {
  349. flex: 1;
  350. .status {
  351. display: inline-block;
  352. padding: 2px 6px;
  353. border-radius: 4px;
  354. color: #ffffff;
  355. margin-right: 5px;
  356. font-weight: normal;
  357. font-size: 14px;
  358. }
  359. }
  360. .sliding-block {
  361. position: relative;
  362. flex-shrink: 0;
  363. width: 74px;
  364. height: 20px;
  365. border-radius: 12px;
  366. overflow: hidden;
  367. box-sizing: border-box;
  368. background: #f5f6fa;
  369. .but {
  370. position: absolute;
  371. font-size: 10px;
  372. width: 40px;
  373. text-align: center;
  374. line-height: 21px;
  375. z-index: 2;
  376. color: #bbbbbb;
  377. border-radius: 12px;
  378. transition: color 0.3s ease;
  379. }
  380. .action {
  381. color: #ffffff;
  382. z-index: 3;
  383. }
  384. .sliding {
  385. position: absolute;
  386. width: 40px;
  387. height: 20px;
  388. background: #3874f6;
  389. border-radius: 12px;
  390. z-index: 1;
  391. transition: transform 0.3s ease;
  392. }
  393. }
  394. }
  395. .row {
  396. line-height: 17px;
  397. font-size: 12px;
  398. color: #666666;
  399. margin-bottom: 5px;
  400. }
  401. }
  402. </style>