detail.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. if (this.mode == mode) return;
  212. const that = this;
  213. switch (mode) {
  214. case 0:
  215. uni.showModal({
  216. content: "是否关闭蓝牙\n并切换至网络控制",
  217. success: function ({ confirm }) {
  218. if (confirm) that.mode = mode;
  219. },
  220. });
  221. break;
  222. case 1:
  223. uni.openBluetoothAdapter({
  224. success: (result) => {
  225. console.log("蓝牙初始化success:", result);
  226. if (result.errno == 0) {
  227. uni.navigateTo({
  228. url: "/Bluetooth/index/index",
  229. });
  230. this.$Http.setBluetooth = function (Bluetooth) {
  231. this.mode = mode;
  232. let curPages = getCurrentPages();
  233. if (
  234. curPages[curPages.length - 1].__route__ ==
  235. "Bluetooth/index/index"
  236. )
  237. uni.navigateBack();
  238. this.$Http.Bluetooth = Bluetooth;
  239. console.log(this.$Http.Bluetooth);
  240. delete this.$Http.setBluetooth;
  241. }.bind(this);
  242. } else {
  243. uni.showModal({
  244. title: result.errno,
  245. content: result.Msg,
  246. showCancel: false,
  247. confirmText: "确定",
  248. });
  249. }
  250. },
  251. fail: (fail) => {
  252. console.log("蓝牙初始化fail:", fail);
  253. if (fail.errno == "103") {
  254. uni.showModal({
  255. title: "提示",
  256. content: "未获取使用蓝牙功能授权,请授权后使用",
  257. showCancel: false,
  258. confirmText: "前去授权",
  259. success() {
  260. uni.openSetting({
  261. success({ authSetting }) {
  262. if (authSetting["scope.bluetooth"])
  263. that.changeMode(mode);
  264. },
  265. });
  266. },
  267. });
  268. } else {
  269. uni.showModal({
  270. title: fail.errno || "",
  271. content: fail.errno
  272. ? "请确认已开启蓝牙设备权限"
  273. : fail.errMsg,
  274. showCancel: false,
  275. confirmText: "确定",
  276. });
  277. }
  278. },
  279. });
  280. break;
  281. }
  282. },
  283. },
  284. };
  285. </script>
  286. <style lang="scss" scoped>
  287. .ceiling {
  288. position: sticky;
  289. z-index: 9;
  290. }
  291. .head {
  292. width: 355px;
  293. background: #ffffff;
  294. border-radius: 4px;
  295. padding: 10px 15px;
  296. box-sizing: border-box;
  297. margin: 10px auto 0;
  298. .name {
  299. display: flex;
  300. line-height: 20px;
  301. font-size: 14px;
  302. font-family: PingFang SC-Medium, PingFang SC;
  303. font-weight: bold;
  304. color: #333333;
  305. margin-bottom: 10px;
  306. .left {
  307. flex: 1;
  308. .status {
  309. display: inline-block;
  310. padding: 2px 6px;
  311. border-radius: 4px;
  312. color: #ffffff;
  313. margin-right: 5px;
  314. font-weight: normal;
  315. font-size: 14px;
  316. }
  317. }
  318. .sliding-block {
  319. position: relative;
  320. flex-shrink: 0;
  321. width: 74px;
  322. height: 20px;
  323. border-radius: 12px;
  324. overflow: hidden;
  325. box-sizing: border-box;
  326. background: #f5f6fa;
  327. .but {
  328. position: absolute;
  329. font-size: 10px;
  330. width: 40px;
  331. text-align: center;
  332. line-height: 21px;
  333. z-index: 2;
  334. color: #bbbbbb;
  335. border-radius: 12px;
  336. transition: color 0.3s ease;
  337. }
  338. .action {
  339. color: #ffffff;
  340. z-index: 3;
  341. }
  342. .sliding {
  343. position: absolute;
  344. width: 40px;
  345. height: 20px;
  346. background: #3874f6;
  347. border-radius: 12px;
  348. z-index: 1;
  349. transition: transform 0.3s ease;
  350. }
  351. }
  352. }
  353. .row {
  354. line-height: 17px;
  355. font-size: 12px;
  356. color: #666666;
  357. margin-bottom: 5px;
  358. }
  359. }
  360. </style>