tabbarPanel.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view>
  3. <HomePage v-if="selectIndex === 'homePage'" tarbar-type="index" />
  4. <PersonCenter v-else-if="selectIndex === 'personCenter'" />
  5. <WorkBranch v-else-if="selectIndex === 'workbranch'" />
  6. <view class="tab_bar" :style="[isPad?'height: 100px;':'height: 3.5rem;']">
  7. <view class="tabbarBox">
  8. <view v-for="(item,index) in tabBarList" :key="index" class="handleBox"
  9. @click="goPages(item.pageIndex)">
  10. <view class="menuBox">
  11. <view class="menuIcon" :style="[isPad?'margin-top: 8px;':'']">
  12. <image v-if="item.pageIndex!=selectIndex" class="img" :src="item.iconPath" />
  13. <image v-else class="img" :src="item.selectIconPath" />
  14. </view>
  15. <view class="menuName" :style="[isPad?'margin-top: 8px;':'']">
  16. <text class="Text"
  17. :style="{ color: item.pageIndex!=selectIndex? 'gray': 'black' }">{{ item.tabbarName }}</text>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import HomePage from './homePage.vue'
  27. import PersonCenter from './personCenter.vue'
  28. import WorkBranch from './workbranch.vue'
  29. import {
  30. getFileStorage
  31. } from '@/unit/fileStorage.js'
  32. import Bluetooth from '@/unit/print/bluetooth.js'
  33. import {
  34. hideBoard
  35. } from '@/unit/default'
  36. const bluetooth = new Bluetooth()
  37. export default {
  38. components: {
  39. HomePage,
  40. PersonCenter,
  41. WorkBranch
  42. },
  43. data() {
  44. return {
  45. selectIndex: 'homePage',
  46. tabBarList: [{
  47. 'flag': 'icon',
  48. 'pageIndex': 'homePage',
  49. 'iconPath': '/static/menu_imgs/home-default.png',
  50. 'selectIconPath': '/static/menu_imgs/home.png',
  51. 'tabbarName': '首页'
  52. },
  53. {
  54. 'flag': 'icon',
  55. 'pageIndex': 'workbranch',
  56. 'iconPath': '/static/menu_imgs/workbranch-default.png',
  57. 'selectIconPath': '/static/menu_imgs/workbranch.png',
  58. 'tabbarName': '工作台'
  59. },
  60. {
  61. 'flag': 'icon',
  62. 'pageIndex': 'personCenter',
  63. 'iconPath': '/static/menu_imgs/person-default.png',
  64. 'selectIconPath': '/static/menu_imgs/person.png',
  65. 'tabbarName': '个人中心'
  66. }
  67. ]
  68. }
  69. },
  70. onShow() {
  71. },
  72. async beforeCreate() {
  73. // #ifdef APP-PLUS
  74. await bluetooth.openBluetoothAdapter()
  75. // #endif
  76. },
  77. // uniapp子组件不支持应用生命周期,所以只能用vue生命周期
  78. mounted() {
  79. const _this = this
  80. // 隐藏原生tarbar (这里因为用自定义tarbar跳转时闪白屏,所以这里用一种特殊的方式)
  81. uni.hideTabBar()
  82. // 蓝牙自连
  83. // #ifdef APP-PLUS
  84. getFileStorage('bluetoothConfig.txt')
  85. .then(async data => {
  86. if (data != null) {
  87. const blueConfig = JSON.parse(data)
  88. const isConfigNull = Object.keys(blueConfig).every(ret => ![null, ''].includes(blueConfig[
  89. ret]))
  90. if (isConfigNull) {
  91. bluetooth.serviceName = blueConfig.serviceName
  92. bluetooth.deviceId = blueConfig.deviceId
  93. bluetooth.serviceId = blueConfig.serviceId
  94. bluetooth.writeId = blueConfig.writeId
  95. bluetooth.notifyId = blueConfig.notifyId
  96. bluetooth.isOpenBle = blueConfig.isOpenBle
  97. uni.setStorageSync('bluetoothConfig', JSON.stringify(bluetooth))
  98. try {
  99. await _this.createBLEConnection()
  100. setTimeout(async () => {
  101. await _this.getBLEDeviceCharacteristics()
  102. }, 4500)
  103. } catch (e) {
  104. // TODO handle the exception
  105. }
  106. }
  107. }
  108. })
  109. .catch((e) => {
  110. uni.showToast({
  111. title: '获取蓝牙配置文件失败, 请检查本地文件是否丢失',
  112. duration: 2000,
  113. icon: 'none'
  114. })
  115. })
  116. // #endif
  117. },
  118. methods: {
  119. // 进入tabble页
  120. goPages(pageIndex) {
  121. this.selectIndex = pageIndex
  122. },
  123. createBLEConnection() {
  124. plus.bluetooth.createBLEConnection({
  125. deviceId: bluetooth.deviceId,
  126. success: (res) => {
  127. // console.log("res:createBLEConnection " + JSON.stringify(res));
  128. // resolve(res)
  129. },
  130. fail: err => {
  131. uni.hideLoading()
  132. if (err?.code === -1) {
  133. // {"code":-1,"message":"already connect"}
  134. uni.showToast({
  135. title: `此设备已连接,请勿重复操作` + JSON.stringify(err),
  136. duration: 2000,
  137. icon: 'none'
  138. })
  139. } else {
  140. uni.showToast({
  141. title: `连接蓝牙设备失败` + JSON.stringify(err),
  142. duration: 2000,
  143. icon: 'none'
  144. })
  145. }
  146. }
  147. })
  148. },
  149. getBLEDeviceCharacteristics() {
  150. plus.bluetooth.getBLEDeviceCharacteristics({
  151. deviceId: bluetooth.deviceId,
  152. serviceId: bluetooth.serviceId,
  153. success: res => {
  154. // 解决安卓低功耗蓝牙写入code 10007问题
  155. uni.setBLEMTU({
  156. deviceId: bluetooth.deviceId,
  157. mtu: 180,
  158. success(res) {
  159. console.log('设置最大值成功')
  160. }
  161. })
  162. // const result = {
  163. // 'notifyId': bluetooth.notifyId,
  164. // 'writeId': bluetooth.writeId
  165. // }
  166. const notifyifIsItEmpty = ['', null, undefined, NaN].includes(bluetooth.notifyId)
  167. const writeIdIsItEmpty = ['', null, undefined, NaN].includes(bluetooth.writeId)
  168. if (notifyifIsItEmpty || writeIdIsItEmpty) {
  169. uni.showToast({
  170. title: `此服务不可用,请选择其它服务`,
  171. duration: 2000,
  172. icon: 'none'
  173. })
  174. } else {
  175. // this.showToast(`获取服务中所有特征值OK,${JSON.stringify(result)}`);
  176. // uni.showToast({
  177. // title: `蓝牙打印自动重连成功`,
  178. // duration: 2000,
  179. // icon: "none"
  180. // });
  181. }
  182. },
  183. fail: err => {
  184. uni.showToast({
  185. title: `getBLEDeviceCharacteristics` + JSON.stringify(err),
  186. duration: 2000,
  187. icon: 'none'
  188. })
  189. }
  190. })
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="scss">
  196. .tab_bar {
  197. width: 100vw;
  198. position: fixed;
  199. bottom: 0rpx;
  200. box-shadow: 0px 10px 15px 3px gray;
  201. border-radius: 15px 15px 0 0;
  202. background: #ffffff;
  203. z-index: 99999;
  204. .tabbarBox {
  205. display: flex;
  206. justify-content: space-evenly;
  207. .handleBox {
  208. width: 20vw;
  209. height: 100%;
  210. .menuBox {
  211. padding: 0rpx 20rpx;
  212. width: 120rpx;
  213. height: 100%;
  214. text-align: center;
  215. .menuIcon {
  216. height: 30px;
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. .img {
  221. width: 40rpx;
  222. height: 40rpx;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. .Text {
  230. font-size: 25rpx;
  231. }
  232. </style>