前端 uni-app 重写: 9页面 H5

This commit is contained in:
zhiqui
2026-11-15 15:09:37 +08:00
parent 513b53672e
commit ea7c2529e9
24104 changed files with 3667749 additions and 0 deletions
@@ -0,0 +1,4 @@
// vapor 临时处理
class UniViewElementImpl extends UniElement { }
export class UniLoadingElement extends UniViewElementImpl { }
@@ -0,0 +1,131 @@
<template>
<uni-loading-element class="default __uni_loading_container__" ref="LoadingRef" style="display: flex;">
<view class="__uni-loading__ __loading-4-3__" :class="{ '__uni-loading__paused': props.paused }" :style="loadingStyle"></view>
</uni-loading-element>
</template>
<script setup lang="uts">
import { UniLoadingElement } from './element';
const props = withDefaults(defineProps<{
/**
* 是否暂停动画
* @uniPlatform {
"app": {
"ios": {
"unixVaporVer": "5.11"
},
"harmony": {
"unixVaporVer": "5.0"
}
}
}
*/
paused?: boolean,
/**
* 是否加粗线条
* @uniPlatform {
"app": {
"ios": {
"unixVaporVer": "5.11"
},
"harmony": {
"unixVaporVer": "5.0"
}
}
}
*/
bold ?: boolean,
/**
* iOS是否采用系统雪花状样式
* @uniPlatform {
"app": {
"ios": {
"unixVaporVer": "5.11"
}
}
}
*/
iosSpinner ?: boolean
}>(), {
paused: false,
bold: false,
iosSpinner: false
})
defineOptions({
name: 'loading',
styleIsolation: 'app-and-page',
// @ts-ignore
rootElement: {
name: 'uni-loading-element',
class: UniLoadingElement
}
});
// 当没有设置显式颜色时,遵循系统主题
const LoadingRef = ref<HTMLElement | null>(null)
const loadingStyle = reactive({})
</script>
<style>
.default {
width: 16px;
height: 16px;
}
.defaultNativeView {
width: 100%;
height: 100%;
}
.__uni_loading_container__ {
justify-content: center;
align-items: center;
flex-shrink: 0;
}
.__uni-loading__ {
width: 100%;
height: 100%;
box-sizing: border-box;
border-radius: 100%;
border-width: 1px;
border-style: solid;
border-color: transparent;
transform: translateZ(0);
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
animation: k-loading-spin 1.333s infinite;
animation-timing-function: linear;
}
.__uni-loading__paused {
animation-play-state: paused;
}
.__loading-4-3__ {
border-color: inherit;
border-right-color: transparent !important;
}
@keyframes k-loading-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@media (prefers-color-scheme: dark) {
.default {
color: #fff;
}
}
</style>
@@ -0,0 +1,58 @@
import { type Ref, onMounted, onUnmounted, watchEffect, ref } from 'vue'
export type _Element = UniElement
type _ResizeObserver = UniResizeObserver
export function useLoadingStyle(targetElement : Ref<_Element | null>, bold : Ref<boolean>) {
const loadingSize = ref('16px')
const loadingBorderWidth = ref('1px')
const loadingBorderRadius = ref('8px')
let observer : _ResizeObserver | null = null
const calculateLoadingWidth = (element : _Element, bold : boolean) => {
const { width, height } = element.getBoundingClientRect()
const coefficient = bold ? 2 : 1
const minSide = Math.min(width, height)
// (最小边 / 16) * 系数
const calculatedWidth = (minSide / 16) * coefficient
loadingSize.value = `${minSide}px`
loadingBorderWidth.value = `${calculatedWidth}px`
loadingBorderRadius.value = `${minSide / 2}px`
}
const setupObserver = (cb : (el : _Element) => void) => {
const el = targetElement.value as _Element
if (!el) return
observer!.observe(el)
}
onMounted(() => {
setupObserver((el) => {
calculateLoadingWidth(el, bold.value)
})
watchEffect(() => {
const _bold = bold.value
const el = targetElement.value
if (el !== null) {
calculateLoadingWidth(el, _bold)
}
})
})
onUnmounted(() => {
if (observer) {
observer.disconnect()
}
})
return {
width: loadingSize,
height: loadingSize,
borderWidth: loadingBorderWidth,
// borderRadius: loadingBorderRadius,
}
}