|
@@ -30,16 +30,20 @@ export const useScheduler = (cb: () => void, delay: number) => {
|
|
|
onPlaying: () => {}
|
|
|
}
|
|
|
|
|
|
- let timeId: number | null = null
|
|
|
+ let timeId = ref<number>()
|
|
|
|
|
|
const playing = () => {}
|
|
|
|
|
|
- const clearScheduler = () => clearInterval(timeId as number)
|
|
|
+ const clearScheduler = () => {
|
|
|
+ console.log('暂停计时器:', timeId.value);
|
|
|
+
|
|
|
+ clearInterval(timeId.value as number)
|
|
|
+ }
|
|
|
|
|
|
onUnmounted(clearScheduler)
|
|
|
|
|
|
stx.start = () => {
|
|
|
- timeId = setInterval(() => {
|
|
|
+ timeId.value = setInterval(() => {
|
|
|
cb()
|
|
|
playing()
|
|
|
}, delay)
|
|
@@ -206,17 +210,6 @@ export const usePlatform = (): DEVICE.Platform => {
|
|
|
* node.width = node.width * rate * 2 + 'rpx
|
|
|
*/
|
|
|
export const useAdaptationIpadAndPhone = () => {
|
|
|
- // const { windowWidth, windowHeight } = uni.getWindowInfo()
|
|
|
- // console.log(document.documentElement.clientWidth, document.documentElement.clientHeight);
|
|
|
-
|
|
|
- // const { screenWidth, screenHeight, windowWidth, windowHeight } = uni.getSystemInfoSync()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // console.log(window.screen.width, window.screen.height);
|
|
|
-
|
|
|
- console.log('useAdaptationIpadAndPhone');
|
|
|
-
|
|
|
let a = window.innerWidth / window.innerHeight > 0.5 ? 667 / ( window.innerHeight ) : 1
|
|
|
|
|
|
const resizeHanlde = () => {
|
|
@@ -224,9 +217,8 @@ export const useAdaptationIpadAndPhone = () => {
|
|
|
var screenWidth = window.innerWidth;
|
|
|
var screenHeight = window.innerHeight;
|
|
|
|
|
|
- const rate = screenWidth / screenHeight
|
|
|
-
|
|
|
- console.log(screenWidth, screenHeight );
|
|
|
+ const rate = screenWidth / screenHeight
|
|
|
+
|
|
|
if ( rate > 0.5 ) { // 大于0.6 说明是平板
|
|
|
a = 667 / ( screenHeight )
|
|
|
} else {
|
|
@@ -235,13 +227,9 @@ export const useAdaptationIpadAndPhone = () => {
|
|
|
}
|
|
|
|
|
|
// 监听窗口尺寸变化事件
|
|
|
-window.addEventListener('resize', resizeHanlde);
|
|
|
-
|
|
|
-console.log('a', a);
|
|
|
-
|
|
|
-return a
|
|
|
-
|
|
|
+ window.addEventListener('resize', resizeHanlde);
|
|
|
|
|
|
+ return a
|
|
|
}
|
|
|
|
|
|
export const useQueryParmas = async () => {
|
|
@@ -307,7 +295,6 @@ export const useMagnifier = async (
|
|
|
{ ansUrl: string, quesUrl: string, instance: ComponentInternalInstance, rate: number}
|
|
|
) => {
|
|
|
|
|
|
- return
|
|
|
const adaptatio = useAdaptationIpadAndPhone()
|
|
|
|
|
|
let ctx: UniApp.CanvasContext = uni.createCanvasContext(canvasId)
|
|
@@ -317,140 +304,148 @@ export const useMagnifier = async (
|
|
|
// 初始化放大镜的参数
|
|
|
const magnifierSize = 150 * deviceWidthRate ; // 放大镜尺寸
|
|
|
const magnification = 1.5 ; // 放大倍数
|
|
|
- const lineWidth = 4 * deviceWidthRate// 放大镜边框宽度
|
|
|
+ const lineWidth = 6 * deviceWidthRate// 放大镜边框宽度
|
|
|
+
|
|
|
+ let _moveMagnifier = (event: TouchEvent) => {}
|
|
|
|
|
|
+ const createImgStr = async () => {
|
|
|
ctx.drawImage(quesUrl, 0, 0, 224 * deviceWidthRate, 386 * deviceWidthRate)
|
|
|
- ctx.save()
|
|
|
+ // ctx.save()
|
|
|
ctx.drawImage(ansUrl, 225 * deviceWidthRate , 0, 75 * deviceWidthRate, 386 * deviceWidthRate)
|
|
|
ctx.save()
|
|
|
ctx.draw()
|
|
|
ctx.restore();
|
|
|
-
|
|
|
- // console.log(' canvas.getBoundingClientRect().width:', canvas.getBoundingClientRect().width);
|
|
|
-
|
|
|
- // ctx.fillRect(0, 0, canvas.getBoundingClientRect().width / adaptatio , canvas.getBoundingClientRect().height / adaptatio )
|
|
|
- // ctx.setFillStyle('rgb(0, 0, 0)')
|
|
|
- // ctx.draw()
|
|
|
- // return
|
|
|
// 创建 Image 对象并加载图片
|
|
|
await new Promise( resolve => {
|
|
|
- useSchedulerOnce(() => {
|
|
|
- resolve(true)
|
|
|
- }, 100)
|
|
|
+ useSchedulerOnce(() => {
|
|
|
+ resolve(true)
|
|
|
+ }, 100)
|
|
|
})
|
|
|
-
|
|
|
- const imageStr = await new Promise((resolve) => {
|
|
|
-
|
|
|
- uni.canvasToTempFilePath({
|
|
|
- canvasId: canvasId,
|
|
|
- fileType: 'png',
|
|
|
- quality: 1,
|
|
|
- destWidth: 300 * deviceWidthRate,
|
|
|
- destHeight: 386 * deviceWidthRate,
|
|
|
- success: (res) => resolve( res.tempFilePath),
|
|
|
- fail: (error) => {
|
|
|
- console.error('canvasToTempFilePath failed: ', error);
|
|
|
- }
|
|
|
- }, instance);
|
|
|
+
|
|
|
+ return await new Promise((resolve) => {
|
|
|
+ uni.canvasToTempFilePath({
|
|
|
+ canvasId: canvasId,
|
|
|
+ fileType: 'png',
|
|
|
+ quality: 1,
|
|
|
+ destWidth: 300 * deviceWidthRate,
|
|
|
+ destHeight: 386 * deviceWidthRate,
|
|
|
+ success: (res) => resolve( res.tempFilePath),
|
|
|
+ fail: (error) => {
|
|
|
+ console.error('canvasToTempFilePath failed: ', error);
|
|
|
+ }
|
|
|
+ }, instance);
|
|
|
}) as string
|
|
|
+ }
|
|
|
+
|
|
|
+ const draw = async () => {
|
|
|
+
|
|
|
+ const imgStr = await createImgStr()
|
|
|
|
|
|
function initMagnifier () {
|
|
|
- // 计算放大镜区域的位置和尺寸
|
|
|
- const startX = 0;
|
|
|
- const startY = 0;
|
|
|
- const width = magnifierSize;
|
|
|
- const height = magnifierSize;
|
|
|
-
|
|
|
- // 绘制放大镜效果
|
|
|
- ctx.save();
|
|
|
- ctx.beginPath();
|
|
|
- ctx.arc(
|
|
|
- magnifierSize / 2,
|
|
|
- magnifierSize / 2,
|
|
|
- magnifierSize / 2,
|
|
|
- 0,
|
|
|
- 2 * Math.PI
|
|
|
- );
|
|
|
- ctx.strokeStyle = 'yellow'; // 设置边框颜色为黄色
|
|
|
- ctx.lineWidth = lineWidth; // 设置边框宽度
|
|
|
- ctx.stroke(); // 绘制边框
|
|
|
- ctx.closePath();
|
|
|
- ctx.clip();
|
|
|
- ctx.drawImage(
|
|
|
- imageStr,
|
|
|
- startX,
|
|
|
- startY,
|
|
|
- width,
|
|
|
- height,
|
|
|
- 0 - magnifierSize / 2,
|
|
|
- 0 - magnifierSize / 2,
|
|
|
- magnifierSize * magnification,
|
|
|
- magnifierSize * magnification
|
|
|
- );
|
|
|
- ctx.draw()
|
|
|
- ctx.restore();
|
|
|
+ // 计算放大镜区域的位置和尺寸
|
|
|
+ const startX = 0;
|
|
|
+ const startY = 0;
|
|
|
+ const width = magnifierSize;
|
|
|
+ const height = magnifierSize;
|
|
|
+
|
|
|
+ // 绘制阴影
|
|
|
+ ctx.shadowColor = 'black';
|
|
|
+ ctx.shadowBlur = 20;
|
|
|
+ ctx.shadowOffsetX = 0;
|
|
|
+ ctx.shadowOffsetY = 0;
|
|
|
+
|
|
|
+
|
|
|
+ // 绘制放大镜效果
|
|
|
+ ctx.save();
|
|
|
+ ctx.beginPath();
|
|
|
+ ctx.arc(
|
|
|
+ magnifierSize / 2,
|
|
|
+ magnifierSize / 2,
|
|
|
+ magnifierSize / 2,
|
|
|
+ 0,
|
|
|
+ 2 * Math.PI
|
|
|
+ );
|
|
|
+ ctx.strokeStyle = 'yellow'; // 设置边框颜色为黄色
|
|
|
+ ctx.lineWidth = lineWidth; // 设置边框宽度
|
|
|
+ ctx.stroke(); // 绘制边框
|
|
|
+ ctx.closePath();
|
|
|
+ ctx.clip();
|
|
|
+ ctx.drawImage(
|
|
|
+ imgStr,
|
|
|
+ startX,
|
|
|
+ startY,
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ 0 - magnifierSize / 2,
|
|
|
+ 0 - magnifierSize / 2,
|
|
|
+ magnifierSize * magnification,
|
|
|
+ magnifierSize * magnification
|
|
|
+ );
|
|
|
+ ctx.draw()
|
|
|
+ ctx.restore();
|
|
|
}
|
|
|
-
|
|
|
- function moveMagnifier (event: TouchEvent) {
|
|
|
-
|
|
|
- event.preventDefault();
|
|
|
- event.stopPropagation();
|
|
|
- // * adaptatio * deviceWidthRate
|
|
|
- const mouseX = (event.touches[0].pageX - canvas.getBoundingClientRect().left) / adaptatio
|
|
|
- const mouseY = (event.touches[0].pageY - canvas.getBoundingClientRect().top) / adaptatio
|
|
|
-
|
|
|
- // 清空 Canvas
|
|
|
- ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
|
|
|
-
|
|
|
- // 计算放大镜区域的位置和尺寸
|
|
|
- const startX = (mouseX - magnifierSize / 2)
|
|
|
- const startY = (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.stroke()
|
|
|
- ctx.closePath();
|
|
|
- ctx.clip();
|
|
|
- ctx.drawImage(
|
|
|
- imageStr,
|
|
|
- startX,
|
|
|
- startY,
|
|
|
- width,
|
|
|
- height,
|
|
|
- mouseX - (magnifierSize * magnification) / 2,
|
|
|
- mouseY - (magnifierSize * magnification) / 2,
|
|
|
- magnifierSize * magnification,
|
|
|
- magnifierSize * magnification
|
|
|
- );
|
|
|
- ctx.draw()
|
|
|
- ctx.restore();
|
|
|
- }
|
|
|
+ function moveMagnifier (event: TouchEvent) {
|
|
|
+
|
|
|
+ event.preventDefault();
|
|
|
+ event.stopPropagation();
|
|
|
+ const mouseX = (event.touches[0].pageX - canvas.getBoundingClientRect().left) / adaptatio
|
|
|
+ const mouseY = (event.touches[0].pageY - canvas.getBoundingClientRect().top) / adaptatio
|
|
|
|
|
|
- const draw = async () => {
|
|
|
- initMagnifier();
|
|
|
- // 监听鼠标移动事件,实现放大镜效果
|
|
|
- canvas.addEventListener("touchmove", moveMagnifier);
|
|
|
+ // 清空 Canvas
|
|
|
+ ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
|
|
|
+
|
|
|
+ // 计算放大镜区域的位置和尺寸
|
|
|
+ const startX = (mouseX - magnifierSize / 2)
|
|
|
+ const startY = (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.stroke()
|
|
|
+ ctx.closePath();
|
|
|
+ ctx.clip();
|
|
|
+ ctx.drawImage(
|
|
|
+ imgStr,
|
|
|
+ startX,
|
|
|
+ startY,
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ mouseX - (magnifierSize * magnification) / 2,
|
|
|
+ mouseY - (magnifierSize * magnification) / 2,
|
|
|
+ magnifierSize * magnification,
|
|
|
+ magnifierSize * magnification
|
|
|
+ );
|
|
|
+ ctx.draw()
|
|
|
+ ctx.restore();
|
|
|
}
|
|
|
|
|
|
- const clear = () => {
|
|
|
- ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
|
|
|
- ctx.draw()
|
|
|
- canvas.removeEventListener('touchmove', moveMagnifier)
|
|
|
- }
|
|
|
+ _moveMagnifier = moveMagnifier
|
|
|
|
|
|
- onUnmounted(() => {
|
|
|
- canvas.removeEventListener('touchmove', moveMagnifier)
|
|
|
- })
|
|
|
-
|
|
|
- return {
|
|
|
- draw, clear
|
|
|
- }
|
|
|
+ initMagnifier();
|
|
|
+
|
|
|
+ // 监听鼠标移动事件,实现放大镜效果
|
|
|
+ canvas.addEventListener("touchmove",moveMagnifier);
|
|
|
+ }
|
|
|
+
|
|
|
+ const clear = () => {
|
|
|
+ ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
|
|
|
+ ctx.draw()
|
|
|
+ canvas.removeEventListener('touchmove', _moveMagnifier)
|
|
|
+ }
|
|
|
+
|
|
|
+ onUnmounted(() => {
|
|
|
+ canvas.removeEventListener('touchmove', _moveMagnifier)
|
|
|
+ })
|
|
|
+
|
|
|
+ return {
|
|
|
+ draw, clear
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
|
|
@@ -475,8 +470,7 @@ export const useGyro = async () => {
|
|
|
|
|
|
}
|
|
|
if (window.DeviceOrientationEvent) {
|
|
|
- console.log();
|
|
|
-
|
|
|
+ console.log('设备支持陀螺仪功能');
|
|
|
// 支持陀螺仪功能
|
|
|
window.addEventListener('deviceorientation', handleOrientation);
|
|
|
} else {
|