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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
export function calcAdapt() {
const maxScale = 2.16
const minScale = 1.78
const dot = 2
const { scale } = getSystemInfo()
return {
calcCoord: function ({ minTop, maxTop }, currentScale = scale) {
if (!currentScale) return {
top: maxTop
}
const s = +((currentScale - minScale) / (maxScale - minScale)).toFixed(dot)
const top = (maxTop - minTop) * s + minTop
return {
top
}
},
calc: function ({
minWidth, minHeight, maxWidth, maxHeight
}, currentScale = scale) {
if (!currentScale) return
// 1.78
// 2.16
let width, height;
// (minWidth / maxWidth)
// 比例因子
const s = +((currentScale - minScale) / (maxScale - minScale)).toFixed(dot)
width = (maxWidth - minWidth) * s + minWidth
height = (maxHeight - minHeight) * s + minHeight
return {
width,
height,
}
}
}
}
export const isBigScreen = () => {
let { scale } = getSystemInfo();
if (scale > 2) return true
return false
}
export const isSmallScreen = () => {
let { scale } = getSystemInfo();
if (scale < 1) return true
return false
}
export const getSystemInfo = () => {
let width = 0;
let height = 0;
if (!isMobile()) {
width = 375;
height = document.body.clientHeight > 667 ? document.body.clientHeight : 667;
} else {
width = document.body.clientWidth;
height = document.body.clientHeight;
}
if (height === 0) {
height = window.innerHeight;
if (!isMobile()) {
height = window.innerHeight > 667 ? window.innerHeight : 667;
}
}
let scale = height / width;
scale = parseFloat(scale.toFixed(2))
return {
windowWidth: width,
windowHeight: height,
screenWidth: width,
screenHeight: height,
scale: scale
}
}
export const authCamera = (lying) => {
const that = this;
return new Promise((resolve, reject) => {
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
}
if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function (constraints) {
// 首先获取现存的getUserMedia(如果存在)
let getUserMedia =
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.getUserMedia;
if (!getUserMedia) {
return Promise.reject(
new Error("getUserMedia is not implemented in this browser")
);
}
return new Promise(function (resolve, reject) {
getUserMedia.call(navigator, constraints, resolve, reject);
});
};
}
const constraints = {
audio: false,
video: {
transform: "scaleX(-1)"
}
};
navigator.mediaDevices
.getUserMedia(constraints)
.then(function (stream) {
resolve({ camera: 1, lying })
})
.catch(err => {
console.log("没有开启摄像头权限或浏览器版本不兼容");
console.log('获取用户授权信息失败')
resolve({ camera: 0, lying })
});
})
}
export const isMobile = () => {
let flag = navigator.userAgent.match(
/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
);
return flag;
}