第一版

This commit is contained in:
qld
2026-11-26 14:22:27 +08:00
parent 2eb325f144
commit 94d08e4a5a
317 changed files with 3943 additions and 586 deletions
+9
View File
@@ -0,0 +1,9 @@
{
"version" : "1.0",
"configurations" : [
{
"playground" : "standard",
"type" : "uni-app:app-android"
}
]
}
BIN
View File
Binary file not shown.
+134 -4
View File
@@ -1,8 +1,16 @@
<template>
<view class="agreement">
<view class="agreement" :class="{ 'agreement--local': isLocal }">
<view v-if="loading" class="agreement-status">协议加载中...</view>
<view v-else-if="error" class="agreement-status"> 协议加载失败,请稍后重试 </view>
<view v-else>
<view
v-show="isLocal && !loading && !error"
id="agreement-local"
class="agreement-local"
:class="{ 'is-modal': showInModal }"
:prop="localHtml"
:change:prop="agreementFrame.render"
/>
<view v-if="!isLocal && !loading && !error">
<view
v-if="showHeader"
class="agreement-header"
@@ -23,7 +31,7 @@
</template>
<script setup>
import { defineProps, ref, toRef, watch } from 'vue'
import { computed, defineProps, ref, toRef, watch } from 'vue'
const { protocolProject, protocolPrefix } = uni.$baseConfig
@@ -32,6 +40,11 @@ const props = defineProps({
type: String,
required: true
},
/** remote:线上协议接口;local:渲染 static/agreement 下的同名 html */
mode: {
type: String,
default: 'remote'
},
showHeader: {
type: Boolean,
default: true
@@ -44,9 +57,12 @@ const props = defineProps({
})
const asProtocol = ref(null)
const argumentTypeRef = toRef(props, 'argumentType')
const modeRef = toRef(props, 'mode')
const protocol = ref({})
const localHtml = ref('')
const loading = ref(false)
const error = ref(null)
const isLocal = computed(() => modeRef.value === 'local')
const ALLOWED_TAGS = new Set([
'h1',
@@ -101,6 +117,69 @@ const requestProtocol = (url) =>
})
})
const readLocalHtml = (url) =>
new Promise((resolve, reject) => {
// #ifdef APP-PLUS
const relative = url.replace(/^\//, '')
let path = relative
if (typeof plus !== 'undefined' && plus.io?.convertLocalFileSystemURL) {
path = plus.io.convertLocalFileSystemURL(`_www/${relative}`)
}
plus.io.resolveLocalFileSystemURL(
path,
(entry) => {
entry.file((file) => {
const reader = new plus.io.FileReader()
reader.onloadend = (event) => {
const text = event.target && event.target.result
resolve(typeof text === 'string' ? text : '')
}
reader.onerror = () => reject(new Error('协议文件读取失败'))
reader.readAsText(file, 'utf-8')
}, () => reject(new Error('协议文件读取失败')))
},
() => reject(new Error('协议文件不存在'))
)
return
// #endif
uni.request({
url,
method: 'GET',
success: ({ statusCode, data }) => {
if (statusCode >= 200 && statusCode < 300) {
resolve(typeof data === 'string' ? data : '')
return
}
reject(new Error(`协议加载失败(${statusCode})`))
},
fail: reject
})
})
const loadLocalProtocol = async () => {
if (!argumentTypeRef.value) {
localHtml.value = ''
error.value = null
return
}
loading.value = true
error.value = null
localHtml.value = ''
try {
const html = await readLocalHtml(`/static/agreement/${argumentTypeRef.value}.html`)
if (!html) throw new Error('协议文件为空')
localHtml.value = html
} catch (err) {
console.error('加载本地协议失败', err)
localHtml.value = ''
error.value = err
} finally {
loading.value = false
}
}
const loadProtocol = async () => {
if (!argumentTypeRef.value) {
protocol.value = {}
@@ -128,7 +207,39 @@ const loadProtocol = async () => {
}
}
watch(argumentTypeRef, loadProtocol, { immediate: true })
const load = () => {
if (isLocal.value) {
loadLocalProtocol()
return
}
localHtml.value = ''
loadProtocol()
}
watch([argumentTypeRef, modeRef], load, { immediate: true })
</script>
<script module="agreementFrame" lang="renderjs">
export default {
methods: {
render(html) {
const root = document.getElementById('agreement-local')
if (!root) return
let frame = root.querySelector('iframe')
if (!html) {
if (frame) frame.remove()
return
}
if (!frame) {
frame = document.createElement('iframe')
frame.setAttribute('sandbox', 'allow-same-origin')
frame.setAttribute('style', 'width:100%;height:100%;border:0;background:#fff;')
root.appendChild(frame)
}
frame.srcdoc = html
}
}
}
</script>
<style scoped lang="scss">
@@ -139,6 +250,25 @@ watch(argumentTypeRef, loadProtocol, { immediate: true })
text-align: left;
}
.agreement--local {
display: flex;
flex: 1;
flex-direction: column;
min-height: 0;
height: 100%;
}
.agreement-local {
flex: 1;
width: 100%;
min-height: 0;
}
.agreement-local.is-modal {
flex: none;
height: 60vh;
}
.agreement-status {
padding: 80rpx 24rpx;
color: #999;
+13 -5
View File
@@ -10,6 +10,7 @@ export function useCompass() {
const tiltX = ref(0)
const tiltY = ref(0)
const ready = ref(false)
const tiltReady = ref(false)
const onCompassChange = (res: { direction?: number }) => {
const next = Number(res?.direction)
@@ -19,9 +20,16 @@ export function useCompass() {
}
const onAccelChange = (res: { x?: number; y?: number; z?: number }) => {
const { horizontal, vertical } = tiltFromAccel(res?.x || 0, res?.y || 0, res?.z || 0)
tiltX.value = horizontal
tiltY.value = vertical
const x = Number(res?.x)
const y = Number(res?.y)
const z = Number(res?.z)
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z)) return
const { horizontal, vertical } = tiltFromAccel(x, y, z)
// 轻微平滑,保留 0.01° 的变化,又压掉传感器抖动
const blend = tiltReady.value ? 0.45 : 1
tiltX.value += (horizontal - tiltX.value) * blend
tiltY.value += (vertical - tiltY.value) * blend
tiltReady.value = true
}
function start() {
@@ -33,7 +41,7 @@ export function useCompass() {
})
uni.onAccelerometerChange(onAccelChange)
uni.startAccelerometer({
interval: 'ui',
interval: 'game',
fail: () => {},
})
}
@@ -49,5 +57,5 @@ export function useCompass() {
onHide(() => stop())
onUnload(() => stop())
return { heading, tiltX, tiltY, ready, start, stop }
return { heading, tiltX, tiltY, ready, tiltReady, start, stop }
}

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 65 KiB

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Before

Width:  |  Height:  |  Size: 109 KiB

After

Width:  |  Height:  |  Size: 109 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Before

Width:  |  Height:  |  Size: 110 KiB

After

Width:  |  Height:  |  Size: 110 KiB

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Some files were not shown because too many files have changed in this diff Show More