schangxiang@126.com
2025-03-10 8706d6948d9a922d8e5adce27f49790ad4ac1d71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * 扫码后获取指定的物料的属性
 * @param {Object} str 扫描得到的字符串
 * @param {Object} attr 需要获取到的属性值
 */
export function getAttrValue(targetStr,attr) {
    let endStr = '';
    // let targetStr = str.replace(/\s/g,'') 
    //字符串拆分数组
    const targetArr = targetStr.split(',')
    //循环数组
    for(let i=0;i<targetArr.length;i++) {
        let itemK = targetArr[i].replace(/\s/g,'') //物料含空格bug - E18VS300C002-00 n
        if(itemK.startsWith(attr)) {
            let arr = targetArr[i].split(':')
            endStr = arr[1].trim() //去掉前后空格
            break;
        }
    }
    return endStr
}
 
/**
 * @param {Object} str  扫描到的字符串
 * @param {Object} attr 获取的属性
 */
export function getNewAttrValue(str,attr) {
    const arr = [];
    //替换空字符
    let targetStr = str.replace(/\s/g,'')
    //获取物料编号
    const startIndex = targetStr.indexOf('PARTSNUMBER:')
    //物料名称
    const middleIndex = targetStr.indexOf('MATERIALNAME:')
    //批次
    const endIndex = targetStr.indexOf('LOTNO:')
    //城市
    const lastIndex = targetStr.indexOf('City:WH')
    
    arr.push(targetStr.slice(startIndex+1,middleIndex),targetStr.slice(middleIndex+1,endIndex),targetStr.slice(endIndex+1,lastIndex))
    console.log(arr)
    if(attr = 'PARTSNUMBER') {
        return arr[0] || ''
    }else if(arrt = 'MATERIALNAME') {
        return arr[1] || ''
    }else if(attr = 'LOTNO') {
        return arr[2] || ''
    }else {
        return ''
    }
}