zengh
2022-09-14 8ea19a6bb34daab1410f6186992a4c1e90299c92
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// #ifndef APP-NVUE
// 计算版本
export function compareVersion(v1, v2) {
    v1 = v1.split('.')
    v2 = v2.split('.')
    const len = Math.max(v1.length, v2.length)
    while (v1.length < len) {
        v1.push('0')
    }
    while (v2.length < len) {
        v2.push('0')
    }
    for (let i = 0; i < len; i++) {
        const num1 = parseInt(v1[i], 10)
        const num2 = parseInt(v2[i], 10)
 
        if (num1 > num2) {
            return 1
        } else if (num1 < num2) {
            return -1
        }
    }
    return 0
}
 
export function wrapTouch(event) {
  for (let i = 0; i < event.touches.length; ++i) {
    const touch = event.touches[i];
    touch.offsetX = touch.x;
    touch.offsetY = touch.y;
  }
  return event;
}
export const devicePixelRatio = uni.getSystemInfoSync().pixelRatio
// #endif
// #ifdef APP-NVUE
export function base64ToPath(base64) {
    return new Promise((resolve, reject) => {
        const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64) || [];
        const bitmap = new plus.nativeObj.Bitmap('bitmap' + Date.now())
        bitmap.loadBase64Data(base64, () => {
            if (!format) {
                reject(new Error('ERROR_BASE64SRC_PARSE'))
            }
            const time = new Date().getTime();
            const filePath = `_doc/uniapp_temp/${time}.${format}`
            
            bitmap.save(filePath, {}, 
                () => {
                    bitmap.clear()
                    resolve(filePath)
                }, 
                (error) => {
                    bitmap.clear()
                    console.error(`${JSON.stringify(error)}`)
                    reject(error)
                })
        }, (error) => {
            bitmap.clear()
            console.error(`${JSON.stringify(error)}`)
            reject(error)
        })
    })
}
// #endif