device.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <view class="content">
  3. <button @click="godoBle">添加设备</button>
  4. <button @click="test1">test1</button>
  5. </view>
  6. </template>
  7. <script>
  8. import {common} from '../../proto/bundle.js';
  9. export default {
  10. data() {
  11. return {
  12. }
  13. },
  14. onLoad() {
  15. },
  16. methods: {
  17. test1(){
  18. let errinfo = common.ErrorInfo.create({
  19. errorCode: 0,
  20. errorMessage:Buffer.from('成功')
  21. })
  22. //把ErrorInfo对象 编码成Uint8Array (browser) or Buffer (node)
  23. let errBuffer = common.ErrorInfo.encode(errinfo).finish()
  24. //把Uint8Array (browser) 或者 Buffer (node) 解码成ErrorInfo对象
  25. let message = common.ErrorInfo.decode(errBuffer)
  26. //转化为一个对象
  27. let obj = common.ErrorInfo.toObject(message, {
  28. enums: String, // enums as string names
  29. longs: String, // longs as strings (requires long.js)
  30. //bytes: String,
  31. })
  32. console.log(obj);
  33. let buf = Buffer.from(obj.errorMessage)
  34. console.log(`errorMessage = ${buf.toString()}`);
  35. // let buf = Buffer.from(obj.errorMessage)
  36. // console.log(buf);
  37. // console.log(buf.toString());
  38. },
  39. godoBle() { //添加设备
  40. // #ifdef MP-WEIXIN||APP-PLUS
  41. uni.navigateTo({
  42. url: '../ble/ScanBleDevice'
  43. })
  44. // #endif
  45. // #ifdef H5
  46. uni.navigateTo({
  47. url: '../ble/ConnectBleDevice'
  48. })
  49. // uni.showToast({
  50. // title:'H5页面不支持扫描设备',
  51. // icon:'none'
  52. // })
  53. // #endif
  54. }
  55. }
  56. }
  57. </script>
  58. <style>
  59. .content {
  60. display: flex;
  61. flex-direction: column;
  62. align-items: center;
  63. justify-content: center;
  64. margin: 20rpx;
  65. }
  66. </style>