diff --git a/pages/calibrator/calibrator.js b/pages/calibrator/calibrator.js new file mode 100644 index 0000000..ee6483c --- /dev/null +++ b/pages/calibrator/calibrator.js @@ -0,0 +1,71 @@ +// pages/calibrator/calibrator.js +Component({ + /** + * 组件的属性列表 + */ + properties: {}, + + /** + * 组件的初始数据 + */ + data: { + pendingStart: 0, + success: false, + lineStyle: "", + }, + + /** + * 组件的方法列表 + */ + methods: {}, + lifetimes: { + attached() { + const windowInfo = wx.getWindowInfo(); + const vh = windowInfo.windowHeight; + wx.startDeviceMotionListening({ interval: "ui" }); + this.deviceCb = ({ beta, gamma }) => { + if (this.data.success) return; + const isGammaPass = + (gamma > -45 && gamma < 45) || gamma < -135 || gamma > 135; + let top = + (((Math.abs(gamma) > 90 ? 180 - Math.abs(beta) : Math.abs(beta)) / + 90) * + vh) / + 2; + if (!isGammaPass) { + if (top < vh / 2) top = vh / 2 - 100; + else top = vh / 2 + 100; + } + const success = top > vh / 2 - 50 && top < vh / 2 + 50; + if (!success) { + this.setData({ + lineStyle: `top: ${top}px;`, + pendingStart: 0, + }); + } else if (!this.data.pendingStart) { + this.setData({ + lineStyle: `top: ${top}px;`, + pendingStart: Date.now(), + }); + } else if (Date.now() - this.data.pendingStart > 750) { + this.setData({ + lineStyle: `top: ${top}px;`, + success: true, + }); + setTimeout(() => { + this.triggerEvent("success"); + }, 500); + } else { + this.setData({ + lineStyle: `top: ${top}px;`, + }); + } + }; + wx.onDeviceMotionChange(this.deviceCb); + }, + detached() { + wx.offDeviceMotionChange(this.deviceCb); + wx.stopDeviceMotionListening(); + }, + }, +}); diff --git a/pages/calibrator/calibrator.json b/pages/calibrator/calibrator.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/pages/calibrator/calibrator.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/calibrator/calibrator.wxml b/pages/calibrator/calibrator.wxml new file mode 100644 index 0000000..9bdc21e --- /dev/null +++ b/pages/calibrator/calibrator.wxml @@ -0,0 +1,14 @@ + + 请竖举手机 + 将摄像头对准周围环境,并保持手机对准水平状态 + + + + + + 请校准手机至中间高亮区域 + + + + + \ No newline at end of file diff --git a/pages/calibrator/calibrator.wxss b/pages/calibrator/calibrator.wxss new file mode 100644 index 0000000..652f49f --- /dev/null +++ b/pages/calibrator/calibrator.wxss @@ -0,0 +1,127 @@ +.calibrator { + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + z-index: 10; + background: rgba(0, 0, 0, 0.8); +} +.rect { + display: flex; + align-items: center; + justify-content: center; + position: absolute; + left: 0; + top: calc(50vh - 40px); + width: 100vw; + height: 80px; + background: rgba(238, 233, 222, 0.3); + backdrop-filter: blur(3px); +} +.rect .l1 { + position: absolute; + bottom: 25px; + left: 14px; + width: calc(50vw - 30px); + border-top: 2px dashed rgba(215, 207, 198, 0.4); +} +.rect .l2 { + position: absolute; + bottom: 25px; + right: 14px; + width: calc(50vw - 30px); + border-top: 2px dashed rgba(215, 207, 198, 0.4); +} +.rect .p { + position: absolute; + left: 0; + right: 0; + bottom: 16px; + margin: auto; + width: 24px; + height: 40px; +} +.title { + position: absolute; + left: 0; + right: 0; + top: calc(50vh - 40px - 192px - 34px); + margin: auto; + color: var(--T-G1, #eee9de); + text-align: center; + /* 标题-Title1/B */ + font-family: "PingFang SC"; + font-size: 24px; + font-style: normal; + font-weight: 500; + line-height: normal; + z-index: 2; +} +.opacity6 { + opacity: 0.6; +} +.meta { + position: absolute; + left: 0; + right: 0; + top: calc(50vh - 40px - 137px - 41px); + width: 288px; + margin: auto; + padding: 12px; + border-radius: 16px; + background: rgba(0, 0, 0, 0.7); + backdrop-filter: blur(6px); + color: var(--T-9, #fff); + text-align: center; + font-family: "PingFang SC"; + font-size: 12px; + font-style: normal; + font-weight: 400; + line-height: normal; + z-index: 2; +} +.line { + position: absolute; + width: 100vh; + height: 80px; + top: 50vh; + left: 0; + transform-origin: center; + transform: translateY(-40px); + z-index: 1; +} +.line .l { + position: absolute; + left: 16px; + right: 16px; + width: calc(100vw - 32px); + background: #ffdb00; + height: 4px; + border-radius: 100px; + bottom: 23px; + z-index: 1; +} +.line .p { + position: absolute; + width: 30px; + height: 56px; + left: calc(50vw - 15px); + bottom: 11px; + z-index: 2; +} +.meta1 { + position: absolute; + left: 0; + right: 0; + top: calc(50vh + 40px + 18px); + color: var(--T-G2, #d1c8b9); + text-align: center; + /* Font/正文B2M-14 */ + font-family: "PingFang SC"; + font-size: 14px; + font-style: normal; + font-weight: 500; + line-height: normal; + z-index: 2; +} diff --git a/pages/calibrator/p.png b/pages/calibrator/p.png new file mode 100644 index 0000000..a47a4e1 Binary files /dev/null and b/pages/calibrator/p.png differ diff --git a/pages/calibrator/p1.png b/pages/calibrator/p1.png new file mode 100644 index 0000000..be76701 Binary files /dev/null and b/pages/calibrator/p1.png differ diff --git a/pages/calibrator/success.png b/pages/calibrator/success.png new file mode 100644 index 0000000..baf95b2 Binary files /dev/null and b/pages/calibrator/success.png differ diff --git a/pages/index/index-helper.js b/pages/index/index-helper.js index a58aba3..442c335 100644 --- a/pages/index/index-helper.js +++ b/pages/index/index-helper.js @@ -15,7 +15,7 @@ export const STATES = { noCamera: "noCamera", tomap: "tomap", arriveEnd: "arriveEnd", - bluetoothRequired: "bluetoothRequired", + bluetoothRequired: "bluetoothRequired",calibrating: "calibrating", }; export const promptIcons = { info: "info", diff --git a/pages/index/index.js b/pages/index/index.js index f55a156..45498aa 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -175,6 +175,9 @@ Page({ registerGLTFLoader(THREE); }); }, + startCalibrator() { + this.setData({ state: STATES.calibrating }); + }, requestLocation() { if (!(this.data.inited && this.data.floorOrder !== null)) return; if (!this.sdkInited) { @@ -554,7 +557,7 @@ Page({ if (btn === "3") return this.exit(); } if (state === STATES.fail8s) { - if (btn === "1") return this.requestLocation(); + if (btn === "1") return this.startCalibrator(); if (btn === "2") return this.setState(STATES.selectFloor); if (btn === "3") return this.exit(); } @@ -576,7 +579,7 @@ Page({ floorId: nextFloor.floorId, floorName: nextFloor.name, }); - return this.requestLocation(); + return this.startCalibrator(); } if (state === STATES.requestEnd || state === STATES.arriveEnd) { if (btn === "1") return this.exit(); @@ -642,7 +645,7 @@ Page({ }, handleRelocate() { this.SDK.finishARNavigation(); - this.requestLocation(); + this.startCalibrator(); }, handleNavExit() { this.setState(STATES.requestEnd); diff --git a/pages/index/index.json b/pages/index/index.json index 38b5100..ccb65f4 100644 --- a/pages/index/index.json +++ b/pages/index/index.json @@ -4,6 +4,7 @@ "map2d": "../map2d/map2d", "tabs": "../tabs/tabs", "destination": "../destination/destination", - "nav": "../nav/nav" + "nav": "../nav/nav", + "calibrator": "../calibrator/calibrator" } -} \ No newline at end of file +} diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 73db0ab..73ef78e 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -26,7 +26,7 @@ {{item.name}} - + @@ -67,6 +67,7 @@ 返回 +