detail.vue 11 KB

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