|
@@ -34,11 +34,7 @@ export const useScheduler = (cb: () => void, delay: number) => {
|
|
|
|
|
|
const playing = () => {}
|
|
|
|
|
|
- const clearScheduler = () => {
|
|
|
- console.log('暂停计时器:', timeId.value);
|
|
|
-
|
|
|
- clearInterval(timeId.value as number)
|
|
|
- }
|
|
|
+ const clearScheduler = () => clearInterval(timeId.value as number)
|
|
|
|
|
|
onUnmounted(clearScheduler)
|
|
|
|
|
@@ -117,7 +113,7 @@ export const useNavbarInfo = () => {
|
|
|
* @param {string} id - 您要从中获取信息的元素的 ID
|
|
|
* @param cb - 回调函数
|
|
|
* @param {ComponentInternalInstance} vm - 组件实例
|
|
|
- */
|
|
|
+ */
|
|
|
export const useQueryElInfo = (
|
|
|
id: string,
|
|
|
cb: (params: UniApp.NodeInfo | UniApp.NodeInfo[] ) => void,
|
|
@@ -147,7 +143,6 @@ export const useAudioMange = (src?: string) => {
|
|
|
audioInstance.value = uni.createInnerAudioContext()
|
|
|
|
|
|
if (src) {
|
|
|
- console.log('src');
|
|
|
|
|
|
audioInstance.value.src = src
|
|
|
}
|
|
@@ -295,6 +290,11 @@ export const useMagnifier = async (
|
|
|
{ ansUrl: string, quesUrl: string, instance: ComponentInternalInstance, rate: number}
|
|
|
) => {
|
|
|
|
|
|
+ function isIOS() {
|
|
|
+ const userAgent = navigator.userAgent;
|
|
|
+ return /iPhone|iPad|iPod/i.test(userAgent);
|
|
|
+ }
|
|
|
+
|
|
|
const adaptatio = useAdaptationIpadAndPhone()
|
|
|
|
|
|
let ctx: UniApp.CanvasContext = uni.createCanvasContext(canvasId)
|
|
@@ -310,11 +310,10 @@ export const useMagnifier = async (
|
|
|
|
|
|
const createImgStr = async () => {
|
|
|
ctx.drawImage(quesUrl, 0, 0, 224 * deviceWidthRate, 386 * deviceWidthRate)
|
|
|
- // ctx.save()
|
|
|
ctx.drawImage(ansUrl, 225 * deviceWidthRate , 0, 75 * deviceWidthRate, 386 * deviceWidthRate)
|
|
|
ctx.save()
|
|
|
ctx.draw()
|
|
|
- ctx.restore();
|
|
|
+ // ctx.restore();
|
|
|
// 创建 Image 对象并加载图片
|
|
|
await new Promise( resolve => {
|
|
|
useSchedulerOnce(() => {
|
|
@@ -343,7 +342,7 @@ export const useMagnifier = async (
|
|
|
|
|
|
function initMagnifier () {
|
|
|
// 计算放大镜区域的位置和尺寸
|
|
|
- const startX = 0;
|
|
|
+ const startX = 200;
|
|
|
const startY = 0;
|
|
|
const width = magnifierSize;
|
|
|
const height = magnifierSize;
|
|
@@ -359,15 +358,15 @@ export const useMagnifier = async (
|
|
|
ctx.save();
|
|
|
ctx.beginPath();
|
|
|
ctx.arc(
|
|
|
- magnifierSize / 2,
|
|
|
- magnifierSize / 2,
|
|
|
+ startX,
|
|
|
+ startY,
|
|
|
magnifierSize / 2,
|
|
|
0,
|
|
|
2 * Math.PI
|
|
|
);
|
|
|
- ctx.strokeStyle = 'yellow'; // 设置边框颜色为黄色
|
|
|
- ctx.lineWidth = lineWidth; // 设置边框宽度
|
|
|
- ctx.stroke(); // 绘制边框
|
|
|
+ ctx.strokeStyle = 'yellow';
|
|
|
+ ctx.lineWidth = lineWidth;
|
|
|
+ ctx.stroke();
|
|
|
ctx.closePath();
|
|
|
ctx.clip();
|
|
|
ctx.drawImage(
|
|
@@ -376,8 +375,8 @@ export const useMagnifier = async (
|
|
|
startY,
|
|
|
width,
|
|
|
height,
|
|
|
- 0 - magnifierSize / 2,
|
|
|
- 0 - magnifierSize / 2,
|
|
|
+ startX - magnifierSize / 2,
|
|
|
+ startY - magnifierSize / 2,
|
|
|
magnifierSize * magnification,
|
|
|
magnifierSize * magnification
|
|
|
);
|
|
@@ -389,38 +388,66 @@ export const useMagnifier = async (
|
|
|
|
|
|
event.preventDefault();
|
|
|
event.stopPropagation();
|
|
|
- const mouseX = (event.touches[0].pageX - canvas.getBoundingClientRect().left) / adaptatio
|
|
|
- const mouseY = (event.touches[0].pageY - canvas.getBoundingClientRect().top) / adaptatio
|
|
|
-
|
|
|
+ let mouseX = Math.floor((event.touches[0].pageX - canvas.getBoundingClientRect().left) / adaptatio)
|
|
|
+ let mouseY = Math.floor((event.touches[0].pageY - canvas.getBoundingClientRect().top) / adaptatio)
|
|
|
+
|
|
|
+
|
|
|
+ // 拖拽边界处理
|
|
|
+ if (mouseX <= 0) mouseX = 0
|
|
|
+ if (mouseX >= canvas.getBoundingClientRect().right - 26 ) mouseX = canvas.getBoundingClientRect().right - 26
|
|
|
+ if (mouseY <= 0) mouseY = 0
|
|
|
+ if (mouseY >= (canvas.getBoundingClientRect().bottom - 214 )) mouseY = canvas.getBoundingClientRect().bottom - 214
|
|
|
+ // 拖拽边界处理
|
|
|
// 清空 Canvas
|
|
|
ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
|
|
|
-
|
|
|
+
|
|
|
// 计算放大镜区域的位置和尺寸
|
|
|
- const startX = (mouseX - magnifierSize / 2)
|
|
|
- const startY = (mouseY - magnifierSize / 2)
|
|
|
+ const startX = Math.floor((mouseX - magnifierSize / 2 ))
|
|
|
+ const startY = Math.floor((mouseY - magnifierSize / 2 ))
|
|
|
const width = magnifierSize;
|
|
|
const height = magnifierSize;
|
|
|
-
|
|
|
+
|
|
|
// 绘制放大镜效果
|
|
|
ctx.save();
|
|
|
ctx.beginPath();
|
|
|
ctx.arc(mouseX, mouseY, magnifierSize / 2, 0, 2 * Math.PI);
|
|
|
ctx.strokeStyle = 'yellow';
|
|
|
- ctx.lineWidth = lineWidth;
|
|
|
+ ctx.lineWidth = lineWidth;
|
|
|
ctx.stroke()
|
|
|
ctx.closePath();
|
|
|
ctx.clip();
|
|
|
+
|
|
|
+ const sxCount = mouseX - (magnifierSize * magnification) / 2
|
|
|
+ const syCount = mouseY - (magnifierSize * magnification) / 2
|
|
|
+
|
|
|
+ const sx = sxCount <= 0 ? 0 : mouseX - (magnifierSize * magnification) / 2
|
|
|
+
|
|
|
+ const sy = syCount <= 0 ? 0 : (mouseY - (magnifierSize * magnification) / 2)
|
|
|
+
|
|
|
ctx.drawImage(
|
|
|
imgStr,
|
|
|
startX,
|
|
|
startY,
|
|
|
width,
|
|
|
height,
|
|
|
- mouseX - (magnifierSize * magnification) / 2,
|
|
|
- mouseY - (magnifierSize * magnification) / 2,
|
|
|
- magnifierSize * magnification,
|
|
|
- magnifierSize * magnification
|
|
|
+ isIOS() ? sx: sxCount ,
|
|
|
+ isIOS() ? sy : syCount,
|
|
|
+ magnifierSize * magnification ,
|
|
|
+ magnifierSize * magnification
|
|
|
);
|
|
|
+
|
|
|
+ // ctx.drawImage(
|
|
|
+ // imgStr,
|
|
|
+ // startX,
|
|
|
+ // startY,
|
|
|
+ // width,
|
|
|
+ // height,
|
|
|
+ // mouseX - (magnifierSize * magnification) / 2 ,
|
|
|
+ // mouseY - (magnifierSize * magnification) / 2 ,
|
|
|
+ // magnifierSize * magnification ,
|
|
|
+ // magnifierSize * magnification
|
|
|
+ // );
|
|
|
+
|
|
|
ctx.draw()
|
|
|
ctx.restore();
|
|
|
}
|
|
@@ -451,28 +478,30 @@ export const useMagnifier = async (
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 陀螺仪
|
|
|
+ * @description 陀螺仪 根据陀螺仪判断是否是横屏状态
|
|
|
*/
|
|
|
-export const useGyro = async () => {
|
|
|
+export const useGyroH = async (cb: (dire: string) => void) => {
|
|
|
const handleOrientation = (event: DeviceOrientationEvent) => {
|
|
|
|
|
|
- var alpha = event.alpha; // 设备绕 Z 轴的旋转角度(0 到 360 度)
|
|
|
+ var alpha = event.alpha!; // 设备绕 Z 轴的旋转角度(0 到 360 度)
|
|
|
var beta = event.beta!; // 设备绕 X 轴的旋转角度(-180 到 180 度)
|
|
|
- var gamma = event.gamma; // 设备绕 Y 轴的旋转角度(-90 到 90 度)
|
|
|
-
|
|
|
- console.log('beta', beta);
|
|
|
+ var gamma = event.gamma!; // 设备绕 Y 轴的旋转角度(-90 到 90 度)
|
|
|
+ console.log(`x轴:${Math.floor(beta)} y轴:${ Math.floor(gamma)} z轴:${ Math.floor(alpha) }`);
|
|
|
|
|
|
- if ( beta > 45 && beta <= 270 ) {
|
|
|
- console.log('顺时针横屏');
|
|
|
- } else if ( beta < -45 && beta >= -270 ) {
|
|
|
- console.log('逆時針横屏');
|
|
|
+ let dire = ''
|
|
|
+ if (alpha < 10 ) {
|
|
|
+ dire = 'H'
|
|
|
+ } else {
|
|
|
+ dire = 'V'
|
|
|
}
|
|
|
+
|
|
|
+ cb && cb(dire)
|
|
|
|
|
|
}
|
|
|
+
|
|
|
if (window.DeviceOrientationEvent) {
|
|
|
- console.log('设备支持陀螺仪功能');
|
|
|
- // 支持陀螺仪功能
|
|
|
window.addEventListener('deviceorientation', handleOrientation);
|
|
|
+ // if ( uni.getSystemInfoSync().system.includes('iOS')) { }
|
|
|
} else {
|
|
|
console.log('设备不支持陀螺仪功能');
|
|
|
}
|
|
@@ -481,3 +510,5 @@ export const useGyro = async () => {
|
|
|
window.removeEventListener('deviceorientation', handleOrientation)
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+
|