12
chenhaozhe
2025-07-08 ca1eab1cf8a8050e5668eb7e78faea2a821c5cb2
12
6个文件已添加
3个文件已修改
555 ■■■■■ 已修改文件
components/blueToothConnector/blueToothConnector.vue 230 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages.json 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/index.vue 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/qitachuku/qitachuku.vue 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/qitaruku/qitaruku.vue 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/wuliaosaoma/detail.vue 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/wuliaosaoma/wuliaosaoma.vue 169 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
static/svgs/folder_bg.svg 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/common.js 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
components/blueToothConnector/blueToothConnector.vue
New file
@@ -0,0 +1,230 @@
<template>
    <view>
        <!-- 蓝牙连接状态 MAC地址 -->
        <view class="connection-status">
            <view>连接状态:</view>
        </view>
        <!-- 操作区 -->
        <view class="buttons">
            <button class="btn-c" @click="searchLabelPrinter()">搜索打印机</button>
            <button class="btn-d" @click="closeBluetooth()">断开连接</button>
        </view>
        <!-- 设备列表 -->
        <view v-for="(device, index) in discoveredDevices" :key="device.address">
            <uni-card :title="device.name" :extra="connectedDeviceId === device.address?'已连接':'未连接'"
                style="margin: 10px;">
                <view class="operation-zone">
                    <button class="op1" size="mini" plain @click="connectBT(device)">连接设备</button>
                </view>
            </uni-card>
        </view>
    </view>
</template>
<script>
    import bluetoothTool from '@/plugins/BluetoothTool.js'
    import permission from '@/plugins/permission.js'
    import {
        InputImage
    } from '@psdk/frame-imageb';
    import {
        ConnectedDevice,
        Lifecycle,
        Raw,
        FakeConnectedDevice,
        WriteOptions,
    } from '@psdk/frame-father';
    export default {
        name: "blueToothConnector",
        data() {
            return {
                discoveredDevices: [], // 查询到的设备
                connectedDeviceId: ""
            };
        },
        methods: {
            async checkPermission() { // 授权
                try {
                    let checkResult = await permission.androidPermissionCheck("bluetooth");
                    console.log("检测信息:", checkResult);
                    if (checkResult.code == 1) {
                        let result = checkResult.data;
                        if (result == 1) {
                            console.log("授权成功!");
                        }
                        if (result == 0) {
                            console.log("授权已拒绝!");
                        }
                        if (result == -1) {
                            console.log("您已永久拒绝权限,请在应用设置中手动打开!");
                        }
                    }
                } catch (err) {
                    console.log("授权失败:", err);
                }
            },
            async searchLabelPrinter() {
                // 查找打印机
                var that = this
                // 使用openBluetoothAdapter 接口,免去主动申请权限的麻烦
                uni.openBluetoothAdapter({
                    success: async (res) => {
                        await this.checkPermission();
                        console.log('start discovery devices');
                        this.discoveredDevices = [];
                        console.log(res)
                        bluetoothTool.discoveryNewDevice();
                    },
                    fail: async (e) => {
                        console.error(e)
                        switch (e.code) {
                            case "10009":
                                this.showToast("此设备不支持设备搜索功能!");
                                break;
                            default:
                                console.error(e);
                        }
                    }
                })
            },
            onDevice(device) {
                console.log("监听寻找到新设备的事件---------------")
                console.log(device)
                if (typeof device === 'undefined') return;
                if (typeof device.name === 'undefined') return;
                console.log(device.name);
                if (device.name === '') return;
                if (device.name === null) return;
                if (device.name.toUpperCase().endsWith('_BLE') ||
                    device.name.toUpperCase().endsWith('-LE') ||
                    device.name.toUpperCase().endsWith('-BLE')) return;
                const isDuplicate = this.discoveredDevices.find(item => item.address === device.address);
                if (isDuplicate) return;
                this.discoveredDevices.push(device);
            },
            connectBT(device) {
                const vm = this;
                uni.showLoading({
                    title: '连接中'
                });
                bluetoothTool.connDevice(device.address, (result) => {
                    console.log(result)
                    uni.hideLoading()
                    if (result) {
                        //     // console.log(result);
                        bluetoothTool.cancelDiscovery();
                        // console.log(vm.$printer)
                        vm.$printer.init(new FakeConnectedDevice());
                        vm.connectedDeviceId = device.address;
                        uni.showToast({
                            icon: 'none',
                            title: '连接成功'
                        })
                    } else {
                        uni.showToast({
                            icon: 'none',
                            title: '连接失败'
                        })
                    }
                });
            },
            stopSearchBT() {
                console.log("停止搜寻附近的蓝牙外围设备---------------")
                bluetoothTool.cancelDiscovery();
            },
            closeBluetooth() {
                console.log("停止蓝牙连接")
                const vm = this;
                if (vm.connectedDeviceId != '') {
                    bluetoothTool.closeBtSocket();
                    vm.connectedDeviceId = "";
                }
            },
        },
        async mounted() {
            //#ifdef APP-PLUS
            // 蓝牙
            bluetoothTool.init({
                listenBTStatusCallback: (state) => {
                    if (state == 'STATE_ON') {
                        console.log(state);
                    }
                },
                discoveryDeviceCallback: this.onDevice,
                discoveryFinishedCallback: function() {
                    console.log("搜索完成");
                },
                readDataCallback: function(dataByteArr) {
                    /* if(that.receiveDataArr.length >= 200) {
                        that.receiveDataArr = [];
                    }
                    that.receiveDataArr.push.apply(that.receiveDataArr, dataByteArr); */
                    console.log("读取完成" + dataByteArr);
                },
                connExceptionCallback: function(e) {
                    console.log(e);
                }
            });
            // 查看连接设备
            let pariedDevices = bluetoothTool.getPairedDevices()
            console("已配对设备", pariedDevices)
            //#endif
        },
    }
</script>
<style lang="scss" scoped>
    .buttons {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-top: 20rpx;
        button {
            border-radius: 50rpx;
            width: 220rpx;
            height: 66rpx;
            line-height: 66rpx;
            font-size: 28rpx;
        }
        .btn-a {
            background-color: #acacac;
            color: #fff;
        }
        .btn-b {
            background-color: #41a863;
            color: #fff;
        }
        .btn-c {
            background-color: #3a78ff;
            color: #fff;
        }
        .btn-d {
            background-color: #da0000;
            color: #fff;
        }
    }
    .operation-zone {
        display: flex;
        justify-content: space-around;
        margin-top: 10rpx;
        .op1 {
            border: 1px solid #41a863;
            color: #41a863;
        }
        .op4 {
            border: 1px solid #da0000;
            color: #da0000;
        }
    }
</style>
pages.json
@@ -299,6 +299,34 @@
            {
                "navigationBarTitleText" : "条码拆码"
            }
        },
        {
            "path" : "pages/wuliaosaoma/wuliaosaoma",
            "style" :
            {
                "navigationBarTitleText" : "物料清单"
            }
        },
        {
            "path" : "pages/wuliaosaoma/detail",
            "style" :
            {
                "navigationBarTitleText" : "条码档案"
            }
        },
        {
            "path" : "pages/qitachuku/qitachuku",
            "style" :
            {
                "navigationBarTitleText" : "其他出库单"
            }
        },
        {
            "path" : "pages/qitaruku/qitaruku",
            "style" :
            {
                "navigationBarTitleText" : "其他入库单"
            }
        }
    ],
    "tabBar": {
pages/index/index.vue
@@ -125,6 +125,24 @@
                        text: '条码拆码',
                        url: '/pages/tiaomachaima/tiaomachaima',
                        id: 20,
                    },
                    {
                        img: '../../static/icon/icon16.png',
                        text: '物料扫码',
                        url: '/pages/wuliaosaoma/wuliaosaoma',
                        id: 21,
                    },
                    {
                        img: '../../static/icon/icon16.png',
                        text: '其他入库',
                        url: '/pages/qitaruku/qitaruku',
                        id: 21,
                    },
                    {
                        img: '../../static/icon/icon16.png',
                        text: '其他出库',
                        url: '/pages/qitachuku/qitachuku',
                        id: 22,
                    }
                ]
            }
pages/qitachuku/qitachuku.vue
New file
@@ -0,0 +1,19 @@
<template>
    <view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
            };
        }
    }
</script>
<style lang="scss">
</style>
pages/qitaruku/qitaruku.vue
New file
@@ -0,0 +1,24 @@
<template>
    <view>
        <blueToothConnectorVue></blueToothConnectorVue>
    </view>
</template>
<script>
    import blueToothConnectorVue from '../../components/blueToothConnector/blueToothConnector.vue';
    export default {
        data() {
            return {
            };
        },
        components: {blueToothConnectorVue},
        methods: {
        }
    }
</script>
<style lang="scss">
</style>
pages/wuliaosaoma/detail.vue
New file
@@ -0,0 +1,25 @@
<template>
    <view></view>
</template>
<script>
    export default{
        data(){
            return {
            }
        }
    }
</script>
<style lang="scss">
    * {
        box-sizing: border-box;
    }
    page{
        >view {
        }
    }
</style>
pages/wuliaosaoma/wuliaosaoma.vue
New file
@@ -0,0 +1,169 @@
<template>
    <view class="container">
        <view class="header">
            <view class="item">
                <view class="left">源单号:</view>
                <view class="right">
                    <input name="HBillNo" v-model="HBillNo" placeholder="请扫描收料通知单" disabled />
                </view>
                <view>
                    <uni-icons type="scan"
                        style="background-color: #3A78FF;padding: 6rpx;color: #fff;border-radius: 100%;font-weight: 500;"
                        size="20" @click="toScanCode"></uni-icons>
                </view>
            </view>
            <!--             <view class="item">
                <view class="left">源单号:</view>
                <view class="right">
                    <input type="number" name="HBillNo" placeholder="请扫描收料通知单" />
                </view>
            </view> -->
        </view>
        <view class="content">
            <view class="over" v-if="HMaterList.length == 0">暂无数据</view>
            <view v-else class="mater-list-wrapper">
                {{ HMaterList }}
            </view>
        </view>
    </view>
</template>
<script>
    import {
        CommonUtils
    } from "@/utils/common.js"
    import {
        getUserInfo
    } from "@/utils/auth.js"
    import {
        string
    } from "i/lib/util";
    export default {
        data() {
            return {
                CommonUtils,
                userInfo: getUserInfo(),
                HBillNo: '',
                HMaterList: [],
                pageInfo: {
                    page: 1,
                    size: 500,
                    total: 0,
                }
            };
        },
        methods: {
            toScanCode() {
                uni.scanCode({
                    onlyFromCamera: true,
                    success: (res) => {
                        if (this.CommonUtils.isEmpty(res.result) === false) {
                            console.log('条码内容:' + res.result);
                            this.HBillNo = res.result
                            CommonUtils.doRequest(
                                "/Cg_POInStockBill/page", {
                                    sWhere: ` and 单据号='${res.result}'`,
                                    user: this.userInfo.HEmpName,
                                    page: this.pageInfo.page,
                                    size: this.pageInfo.size
                                },
                                function(res) {
                                    console.log(res)
                                    let res1 = res.data
                                    let {
                                        count,
                                        data
                                    } = res1;
                                    if (count > 0) {
                                        console.log(data)
                                        // this.HMaterList = data.reduce((acc, obj) => {
                                        //     acc.push({
                                        //         "HMaterID": obj['HMaterID'],
                                        //         "HMaterNo": obj['物料代码'],
                                        //         "HMaterName": obj['物料名称'],
                                        //         "HMaterType": obj['规格型号'],
                                        //         "HQty": obj['数量'],
                                        //         "HBarCode": "",
                                        //         "HBillNo": obj['单据号']
                                        //     })
                                        // }, [])
                                    }
                                },
                                function(err) {
                                    console.error(err)
                                }
                            )
                        }
                    }
                });
            },
        },
        onload() {
        }
    }
</script>
<style lang="scss">
    * {
        box-sizing: border-box;
    }
    input {
        padding: 8rpx 20rpx;
        font-size: 30rpx;
        line-height: 30rpx;
    }
    .container {
        display: flex;
        flex-direction: column;
        .header {
            height: auto;
            display: flex;
            flex-direction: column;
            gap: 20rpx;
            padding: 20rpx 10rpx;
            .item {
                display: flex;
                flex-direction: row;
                padding: 0 10rpx;
                gap: 20rpx;
                font-size: 30rpx;
                // height: 1.5rem;
                // justify-content: center;
                align-items: center;
                .left {
                    text-align: right;
                    width: 6rem;
                }
                .right {
                    flex: 1;
                    height: 100%;
                    padding: 6rpx 0;
                    border-radius: 22rpx;
                    border: 1px solid #e4e4e4;
                    background-color: #e4e4e4;
                    >input {
                        height: auto;
                    }
                }
            }
        }
        .content {
            flex: 1;
            .mater-list-wrapper {
                background-image: url("@/static/svgs/folder_bg.svg");
            }
        }
    }
</style>
static/svgs/folder_bg.svg
New file
@@ -0,0 +1 @@
<svg width="100%" height="100%" viewBox="0 0 750 590" preserveAspectRatio="none"  xmlns="http://www.w3.org/2000/svg"><!-- 标题区域 (固定高度 64px) --><g id="title" transform="translate(0)"><polyline fill="none" stroke="#000" points="0 64 0 0 300 0 375 64" stroke-width="3"/></g><!-- 内容区域 (自动填充剩余高度) --><g id="content" transform="translate(0 64)"><!-- 使用相对坐标重绘内容区域 --><polyline fill="none" stroke="#000" points="375 0 750 0 750 526 0 526 0 0" stroke-width="3"/></g></svg>
utils/common.js
@@ -1,4 +1,10 @@
class commonUtils {
    serverUrl
    constructor() {
        this.serverUrl = uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API';
    }
    // 防抖函数
    debounce(func, delay, immediate = false) {
        let timer = null;
@@ -82,6 +88,41 @@
        return /^\d+$/.test(str);
    }
    
    // uni-app 使用 封装请求函数
    doRequest(url, data, resFunction, errFunction, method) {
        uni.showLoading({
            title: '加载中...'
        })
        uni.request({
            method: method || "GET",
            url: this.serverUrl + url,
            data: data || "",
            success: (res) => {
                if (typeof resFunction === 'function') {
                    resFunction.call(this, res)
                } else if (typeof errFunction === 'undefined') {
                    return
                } else {
                    throw new TypeError("访问成功回调函数类型异常!")
                }
            },
            fail: (err) => {
                uni.showToast({
                    icon: "error",
                    title: "接口访问异常!",
                    duration: 2000
                })
                if (typeof errFunction === 'function') {
                    errFunction.call(this, err)
                } else if (typeof errFunction === 'undefined') {
                    return
                } else {
                    throw new TypeError("访问失败回调函数类型异常!")
                }
            }
        })
        uni.hideLoading()
    }
}
export const CommonUtils =  Object.freeze(new commonUtils());