App.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <div id="app"
  3. style="height:100%;">
  4. <view-box ref="viewBox">
  5. <router-view></router-view>
  6. <!--bottom slot-->
  7. <tabbar slot="bottom"
  8. v-show="showTab">
  9. <tabbar-item :link="{path:'/'}"
  10. :selected="$route.path === '/'">
  11. <img slot="icon"
  12. src="./assets/images/list1.png"
  13. v-if="($route.path === '/' || $route.path.indexOf('/detail/') !== -1)">
  14. <img slot="icon"
  15. src="./assets/images/list0.png"
  16. v-else>
  17. <span slot="label">设备列表</span>
  18. </tabbar-item>
  19. <tabbar-item v-if="lockflag == 1">
  20. <img slot="icon"
  21. @click="opendoor"
  22. src="./assets/images/sm.png">
  23. <span slot="label">扫码</span>
  24. </tabbar-item>
  25. <tabbar-item :link="{path:'/profile'}">
  26. <img slot="icon"
  27. src="./assets/images/user1.png"
  28. v-if="$route.path === '/profile'">
  29. <img slot="icon"
  30. src="./assets/images/user0.png"
  31. v-else>
  32. <span slot="label">我</span>
  33. </tabbar-item>
  34. </tabbar>
  35. </view-box>
  36. </div>
  37. </template>
  38. <script>
  39. import {
  40. Tabbar,
  41. TabbarItem,
  42. Loading,
  43. ViewBox,
  44. XHeader
  45. } from 'vux'
  46. import wx from 'weixin-jsapi'
  47. import Vue from 'vue'
  48. Vue.prototype.wx = wx
  49. import axios from 'axios'
  50. import store from 'store'
  51. import dataManager from 'SERVICES/dataManager'
  52. export default {
  53. name: 'app',
  54. components: {
  55. Tabbar,
  56. TabbarItem,
  57. Loading,
  58. ViewBox,
  59. XHeader
  60. },
  61. data () {
  62. return {
  63. // userService, // 实现 userService 挂载 data 的可追踪
  64. userData: null, // 须与 userService.data【手动】同步
  65. isLoading: false,
  66. lockflag: 0, // 是否显示扫码
  67. seriallist: ''
  68. }
  69. },
  70. created () {
  71. this.openid = store.get('ygopenid')
  72. // this.wxInitialization()
  73. // this.getChannels()
  74. },
  75. methods: {
  76. getChannels () {
  77. const params = { _currentPage: this.currentPage, _size: 100, keyword: this.keyword, openid: this.openid }
  78. this.$services.channel.get('list', { params })
  79. .then(res => {
  80. this.lockflag = 0
  81. this.seriallist = ''
  82. for (var i = 0; i < res.data.items.length; i++) {
  83. if (res.data.items[i].DataItem === 31) {
  84. this.lockflag = 1
  85. this.seriallist = this.seriallist + res.data.items[i].Serial + ','
  86. // console.log('----this.seriallist----', this.seriallist)
  87. }
  88. }
  89. }).catch(() => { })
  90. },
  91. wxInitialization () {
  92. // const params = { openid: 'wx.labsop.cn/ui/index.html#/profile' }
  93. const params = { openid: location.href.split('#')[0] }
  94. this.$services.channel.get('getwxconfig', { params })
  95. .then(res => {
  96. wx.config({
  97. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  98. appId: res.data.items.app_id, // 必填,公众号的唯一标识
  99. timestamp: res.data.items.timestamp, // 必填,生成签名的时间戳
  100. nonceStr: res.data.items.nonce_str, // 必填,生成签名的随机串
  101. signature: res.data.items.signature, // 必填,签名,见附录1
  102. jsApiList: [
  103. 'checkJsApi',
  104. 'startRecord',
  105. 'stopRecord',
  106. 'translateVoice',
  107. 'scanQRCode', // 微信扫一扫接口
  108. 'openCard'
  109. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  110. });
  111. wx.error(function (res) {
  112. alert('出错了:' + res.errMsg);// 这个地方的好处就是wx.config配置错误,会弹出窗口哪里错误,然后根据微信文档查询即可。
  113. });
  114. wx.ready(function () {
  115. wx.checkJsApi({
  116. jsApiList: ['scanQRCode'],
  117. success: function (res) {
  118. }
  119. });
  120. });
  121. })
  122. // this.$router.replace({ path: '/open' })
  123. // axios.request({
  124. // method: 'get',
  125. // url: 'http://39.98.34.197:12001/api/remote_control/rtuseedcmd?code=63000105&instruction=DO1=1'
  126. // }).then(resp => {
  127. // console.log('start --->', resp.data);
  128. // this.showInfo = true;
  129. // this.info = '开锁成功';
  130. // this.showtype = 'success';
  131. // }).catch(error => {
  132. // console.log(error);
  133. // });
  134. },
  135. opendoor () {
  136. const params = { _currentPage: this.currentPage, _size: 100, keyword: this.keyword, openid: this.openid }
  137. this.$services.channel.get('list', { params })
  138. .then(res => {
  139. var seriallist = ''
  140. for (var i = 0; i < res.data.items.length; i++) {
  141. if (res.data.items[i].DataItem === 31) {
  142. seriallist = seriallist + res.data.items[i].Serial + ','
  143. // console.log('----this.seriallist----', seriallist)
  144. }
  145. }
  146. wx.scanQRCode({
  147. needResult: 1, // 默认为0,扫描结果由微信处理,1 则直接返回扫描结果,
  148. scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  149. success: function (res) {
  150. var result = res.resultStr;
  151. axios.request({
  152. method: 'get',
  153. url: 'http://iot.labsop.cn:12001/api/remote_control/rtuseedcmd?instruction=DO1=1&code=' + result + '&ygnick=' + store.get('ygnick') + '&ygopenid=' + store.get('ygopenid') + '&seriallist=' + seriallist
  154. }).then(resp => {
  155. // console.log('start -123-->', resp.data);
  156. if (resp.data.code !== 0) {
  157. alert('操作失败')
  158. } else {
  159. alert('操作成功')
  160. }
  161. // this.showInfo = true;
  162. // this.info = '开锁成功';
  163. // this.showtype = 'success';
  164. }).catch(error => {
  165. console.log(error);
  166. });
  167. },
  168. error: function (res) {
  169. alert(res, 2);
  170. if (res.errMsg.indexOf('function_not_exist') > 0) {
  171. alert('版本过低请升级')
  172. }
  173. }
  174. });
  175. }).catch(() => { })
  176. },
  177. scrollTop () {
  178. this.$refs.viewBox.$els.viewBoxBody.scrollTop = 0
  179. },
  180. print () {
  181. console.info('[Print] ' + this.$route.path.substring(8));
  182. // if (dataManager.deviceType() === 'iOS') {
  183. // WebViewJavascriptBridge.printChannelData(this.$route.path.substring(8));
  184. // }
  185. }
  186. },
  187. computed: {
  188. leftOptions () {
  189. return {
  190. showBack: this.$route.path.indexOf('/detail/') !== -1
  191. }
  192. },
  193. getTitle () {
  194. return dataManager.getNavTitle()
  195. },
  196. showPrint () {
  197. return false
  198. },
  199. showTab () {
  200. return this.$route.path !== '/login'
  201. },
  202. title () {
  203. if (this.$route.path === '/') return '设备列表'
  204. if (this.$route.path === '/about') return '关于'
  205. if (this.$route.path === '/profile') return '我'
  206. if (this.$route.path === '/login') return '账号绑定'
  207. if (this.$route.path === '/setting') return '设置'
  208. if (this.$route.path.indexOf('/detail/') !== -1) return '详细信息'
  209. return this.$route.name
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang="less">
  215. @import "~vux/src/styles/reset.less";
  216. @font-face {
  217. font-family: "Oswald";
  218. src: url("assets/font/Oswald-Light.ttf");
  219. }
  220. body,
  221. html {
  222. height: 100%;
  223. width: 100%;
  224. overflow-x: hidden;
  225. }
  226. body {
  227. background-color: #fbf9fe;
  228. }
  229. .vux-demo-header-box {
  230. z-index: 100;
  231. position: absolute;
  232. width: 100%;
  233. left: 0;
  234. top: 0;
  235. }
  236. .weui_tab_bd {
  237. padding-top: 46px;
  238. }
  239. </style>