4***@qq.com
4***@qq.com
  • 发布:2024-08-16 11:40
  • 更新:2024-08-16 11:47
  • 阅读:351

怎么在app里支持 TextEncoder方法

分类:uni-app

TextEncoder API 是web api。运行h5 没啥 问题 但是跑到app里会报错 怎么解决啊?

2024-08-16 11:40 负责人:无 分享
已邀请:
jgj_app

jgj_app

render.js

  • 4***@qq.com (作者)

    试了下 有点尴尬。又报错 Big integer literals are not available in the configured target environment ("es2015")

    我需要用protobuf-ts 包装 数据

    2024-08-16 12:30

  • jgj_app

    回复 4***@qq.com: 代码怎么写的

    2024-08-16 13:07

  • 4***@qq.com (作者)

    回复 jgj_app:


    <template>

    <button @click="toHome">qweq</button>

    <button @click="toBluetooth">Bluetooth</button>

    <button @click="welcome.toSendBluetooth">蓝牙发送</button>

    </template>


    <script setup lang="ts">

    import BleService from '../../services/ble';

    import {CommandId} from "../../proto/command_id_enum";

    import {onMounted} from 'vue';


    const toSendBluetooth = async (id, data) => {

    const body = {

    value: {

    oneofKind: 'intVal',

    intVal: 90, // 模拟baohedu 90

    }

    }

    console.log(1222)

    const res3 = await BleService.sendSetRequest(id, body);


    console.log('sendData:', res3);

    uni.showModal({

    title: '提示',

    content: '发送成功',

    showCancel: false,

    success: (res) => {

    }

    });

    }


    const toHome = () => {

    uni.navigateTo({

    url: '/pages/home/index'

    })

    }


    const toBluetooth = () => {

    uni.navigateTo({

    url: '/pages/bluetooth/index'

    })

    }

    onMounted(() => {

    startReadBluetooth();

    });

    const stringToAnyArray = (str: string): any[] => {

    const bytes = [];

    for (let i = 0; i < str.length; i++) {

    // 将字符编码为 UTF-8 字节

    let code = str.charCodeAt(i);

    if (code <= 0x7F) {

    bytes.push(code);

    } else if (code <= 0x7FF) {

    bytes.push(0xC0 | (code >> 6));

    bytes.push(0x80 | (code & 0x3F));

    } else if (code <= 0xFFFF) {

    bytes.push(0xE0 | (code >> 12));

    bytes.push(0x80 | ((code >> 6) & 0x3F));

    bytes.push(0x80 | (code & 0x3F));

    } else {

    bytes.push(0xF0 | (code >> 18));

    bytes.push(0x80 | ((code >> 12) & 0x3F));

    bytes.push(0x80 | ((code >> 6) & 0x3F));

    bytes.push(0x80 | (code & 0x3F));

    }

    }

    return bytes;

    };

    const startReadBluetooth = () => {

    setInterval(() => {

    if (!BleService.isrReading && BleService.getDeviceId()!='') {

    BleService.readBLECharacteristicValue();

    }

    }, 1000);

    }


    defineExpose({

    toSendBluetooth

    })

    </script>


    <script module="welcome" lang="renderjs">


    export default {  
    methods: {
    toSendBluetooth(ev, ownerInstance) {
    console.log(11)
    this.$ownerInstance.callMethod('toSendBluetooth')
    }

    }
    }

    </script>


    尝试了这种写法 好像调用不到 外部方法

    2024-08-16 13:10

  • 4***@qq.com (作者)

    无语了 就算不用 BIgInt renderjs 也没法 import 一个script

    BleService 是一个单例 ts文件

    renderjs。也没法import 引用

    太难玩 uniapp

    2024-08-16 13:12

  • 4***@qq.com (作者)

    情况就是 我有一个外部的蓝牙 ts ,这个ts引用了 @protobuf-ts的库 (这个库用了 TextEncoder、big Int 这些东西)然后uniapp app 就不行了

    2024-08-16 13:14

要回复问题请先登录注册