1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <template>
- <view class="content">
- <button @click="godoBle">添加设备</button>
-
- <button v-if="false" @click="test1">test1</button>
- </view>
- </template>
- <script>
- import {common} from '../../proto/bundle.js';
-
-
- export default {
- data() {
- return {
- }
- },
- onLoad() {
- },
- methods: {
- test1(){
- let errinfo = common.ErrorInfo.create({
- errorCode: 0,
- errorMessage:Buffer.from('成功')
- })
-
- //把ErrorInfo对象 编码成Uint8Array (browser) or Buffer (node)
- let errBuffer = common.ErrorInfo.encode(errinfo).finish()
-
- //把Uint8Array (browser) 或者 Buffer (node) 解码成ErrorInfo对象
- let message = common.ErrorInfo.decode(errBuffer)
-
- //转化为一个对象
- let obj = common.ErrorInfo.toObject(message, {
- enums: String, // enums as string names
- longs: String, // longs as strings (requires long.js)
- //bytes: String,
- })
- console.log(obj);
- let buf = Buffer.from(obj.errorMessage)
- console.log(`errorMessage = ${buf.toString()}`);
- // let buf = Buffer.from(obj.errorMessage)
- // console.log(buf);
- // console.log(buf.toString());
- },
- godoBle() { //添加设备
- // #ifdef MP-WEIXIN||APP-PLUS
- uni.navigateTo({
- url: '../ble/ScanBleDevice'
- })
- // #endif
- // #ifdef H5
- uni.navigateTo({
- url: '../ble/ConnectBleDevice'
- })
- // uni.showToast({
- // title:'H5页面不支持扫描设备',
- // icon:'none'
- // })
- // #endif
- }
- }
- }
- </script>
- <style>
- .content {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- margin: 20rpx;
- }
- </style>
|