refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范

这个提交包含在:
wikiboss
2026-09-20 17:05:22 +08:00
父节点 de3cf8b870
当前提交 9fa1d1fbd0
共有 1679 个文件被更改,包括 204798 次插入 和 16817 次删除

查看文件

@@ -0,0 +1,134 @@
<template>
<native-view @init="onInit"></native-view>
</template>
<script setup>
import {
CalendarPicker
} from '@/uni_modules/CalendarPicker'
const props = defineProps < {
/**
* 设置选中项的日期。选中的日期未设置或日期格式不符合规范则为默认值。
* 默认值:当前系统日期。
*/
selected ? : Date
/**
* 描述日期选中态底板样式。
* 默认值:底板样式为圆形。
* 说明:hintRadius为0,底板样式为直角矩形。hintRadius为0 ~ 16,底板样式为圆角矩形。hintRadius>=16,底板样式为圆形
*/
hintRadius ? : number
/**
* 设置选择器与入口组件的对齐方式。
* 默认end
* start: 左对齐
* center: 居中对齐
* end: 右对齐
*/
alignType ? : 'start' | 'center' | 'end'
/**
* 按照对齐类型对齐后,选择器相对入口组件的水平方向偏移量
* 默认:0
*/
offsetX ? : number | string
/**
* 按照对齐类型对齐后,选择器相对入口组件的竖直方向偏移量
* 默认:0
*/
offsetY ? : number | string
/**
* 文本颜色
*/
color ? : string
/**
* 文本尺寸
*/
fontSize ? : number
/**
* 字体粗细
* Lighter: 100
* Normal: 400
* Regular: 400
* Medium: 500
* Bold: 700
* Bolder: 900
*/
fontWeight ? : 100 | 400 | 500 | 700 | 900
/**
* 字体样式
* normal: 标准的字体样式
* italic: 斜体的字体样式
*/
fontStyle ? : 'normal' | 'italic'
} >
()
const emit = defineEmits < {
change: [date: Date]
} > ()
const picker: CalendarPicker = new CalendarPicker()
picker.onChange((value: Date) => {
emit('change', value)
})
watchEffect(() => {
const selected = props.selected
if (selected != null) {
picker.setSelected(selected)
}
})
watchEffect(() => {
const alignType = props.alignType
if (alignType != null) {
picker.setAlignType(alignType)
}
})
watchEffect(() => {
const offsetX = props.offsetX
if (offsetX != null) {
picker.setOffsetX(offsetX)
}
})
watchEffect(() => {
const offsetY = props.offsetY
if (offsetY != null) {
picker.setOffsetY(offsetY)
}
})
watchEffect(() => {
const hintRadius = props.hintRadius
if (hintRadius != null) {
picker.setHintRadius(hintRadius)
}
})
watchEffect(() => {
const color = props.color
if (color != null) {
picker.setColor(color)
}
})
watchEffect(() => {
const fontSize = props.fontSize
if (fontSize != null) {
picker.setFontSize(fontSize)
}
})
watchEffect(() => {
const fontStyle = props.fontStyle
if (fontStyle != null) {
picker.setFontStyle(fontStyle)
}
})
watchEffect(() => {
const fontWeight = props.fontWeight
if (fontWeight != null) {
picker.setFontWeight(fontWeight)
}
})
function onInit(event: UniNativeViewInitEvent) {
picker.init(event.detail.element)
}
</script>

查看文件

@@ -0,0 +1,83 @@
{
"id": "CalendarPicker",
"displayName": "CalendarPicker",
"version": "1.0.0",
"description": "CalendarPicker",
"keywords": [
"CalendarPicker"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"type": "component-vue",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-vue": "u",
"app-nvue": "u",
"app-uvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1 @@
# test-native-view

查看文件

@@ -0,0 +1,13 @@
@Builder
export function buildCalendarPicker(params: ESObject) {
CalendarPicker({ hintRadius: params.hintRadius, selected: params.selected })
.edgeAlign(params.alignType, { dx: params.offsetX, dy: params.offsetY })
.textStyle({
color: params.color,
font: { size: params.fontSize, weight: params.fontWeight, style: params.fontStyle }
})
.onChange((value) => {
params.onChange(value)
})
.attributeModifier(params.attributeUpdater)
}

查看文件

@@ -0,0 +1,108 @@
import { BuilderNode } from "@kit.ArkUI"
import { buildCalendarPicker } from "./builder.ets"
interface CalendarPickerOptions {
selected ?: Date
hintRadius ?: number
alignType ?: CalendarAlign
offsetX ?: number | string
offsetY ?: number | string
color ?: string
fontSize ?: number
fontWeight ?: 100 | 400 | 500 | 700 | 900
fontStyle ?: FontStyle
onChange ?: (value : Date) => void
}
export class CalendarPicker {
private onChanges : Array<(value : Date) => void> = []
private params : CalendarPickerOptions = {
onChange: (value : Date) => {
this.onChanges.forEach((onChange) => {
onChange(value)
})
}
}
private builder : BuilderNode<[CalendarPickerOptions]> | null = null
init(element : UniNativeViewElement) {
this.builder =
element.bindHarmonyWrappedBuilder(wrapBuilder<[CalendarPickerOptions]>(buildCalendarPicker), this.params)
}
onChange(callback : (value : Date) => void) : CalendarPicker {
this.onChanges.push(callback)
return this
}
setSelected(date : Date) : CalendarPicker {
this.params.selected = date
this.builder?.update(this.params)
return this
}
setAlignType(alignType : 'start' | 'center' | 'end') : CalendarPicker {
switch (alignType) {
case 'start':
this.params.alignType = CalendarAlign.START
break
case 'center':
this.params.alignType = CalendarAlign.CENTER
break
case 'end':
this.params.alignType = CalendarAlign.END
break
}
this.builder?.update(this.params)
return this
}
setOffsetX(offsetX : number | string) : CalendarPicker {
this.params.offsetX = offsetX
this.builder?.update(this.params)
return this
}
setOffsetY(offsetY : number | string) : CalendarPicker {
this.params.offsetY = offsetY
this.builder?.update(this.params)
return this
}
setHintRadius(hintRadius : number) : CalendarPicker {
this.params.hintRadius = hintRadius
this.builder?.update(this.params)
return this
}
setColor(color : string) : CalendarPicker {
this.params.color = color
this.builder?.update(this.params)
return this
}
setFontSize(fontSize : number) : CalendarPicker {
this.params.fontSize = fontSize
this.builder?.update(this.params)
return this
}
setFontWeight(fontWeight : 100 | 400 | 500 | 700 | 900) : CalendarPicker {
this.params.fontWeight = fontWeight
this.builder?.update(this.params)
return this
}
setFontStyle(fontStyle : 'normal' | 'italic') : CalendarPicker {
switch (fontStyle) {
case 'normal':
this.params.fontStyle = FontStyle.Normal
break
case 'italic':
this.params.fontStyle = FontStyle.Italic
break
}
this.builder?.update(this.params)
return this
}
}

查看文件

@@ -0,0 +1,56 @@
<template>
<!--建议只存在一个根节点,如果native-view存在兄弟节点则需要将其包裹处理-->
<view>
<native-view style="height: 100px;" @init="onviewinit" @customClick="ontap"></native-view>
<button style="width: 50%;margin: 10px 0px;align-self: center;">测试按钮</button>
</view>
</template>
<script setup lang="uts">
import { NativeButton } from "@/uni_modules/native-button";
let button : NativeButton | null = null
//声明属性
const props = defineProps<{ text : string }>()
//声明事件
const emit = defineEmits<{
(e : "load") : void
(e : "buttonTap", event : UniNativeViewEvent) : void
}>()
//声明方法
function updateText(value : string) {
button?.updateText(value)
}
//监听属性变化
watchEffect(() => {
const text = props.text
updateText(text)
})
/**
* native-view组件初始化时触发
* 用于绑定App平台原生View
*/
function onviewinit(e : UniNativeViewInitEvent) {
//获取UniNativeViewElement 传递给NativeButton对象
button = new NativeButton(e.detail.element);
updateText(props.text)
emit("load")
}
/**
* 将native-view组件的ontap事件转换为buttonTap事件
*/
function ontap(e : UniNativeViewEvent) {
emit("buttonTap", e)
}
/**
* App平台需要主动释放资源
*/
onUnmounted(() => {
button?.destroy()
})
</script>

查看文件

@@ -0,0 +1,82 @@
{
"id": "native-button",
"displayName": "native-button",
"version": "0.0.1",
"description": "vue开发button原生组件",
"repository": "",
"engines": {
"HBuilderX": "^4.25"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-android": {
"minVersion": "21"
},
"app-ios": {
"minVersion": "9"
}
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "y",
"字节跳动": "u",
"QQ": "y",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1,3 @@
## native-button
通过 object 封装原生平台Button按钮

查看文件

@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}

查看文件

@@ -0,0 +1,106 @@
import Button from "android.widget.Button"
import { INativeButtonContext, CreateNativeButtonContext } from "../interface.uts"
export class NativeButton {
$element : UniNativeViewElement;
constructor(element : UniNativeViewElement) {
//接收传递过来的UniNativeViewElement
this.$element = element;
this.bindView();
}
button : Button | null = null;
bindView() {
//通过UniElement.getAndroidActivity()获取android平台activity 用于创建view的上下文
this.button = new Button(this.$element.getAndroidActivity()!); //构建原生view
//限制原生Button 文案描述不自动大写
this.button?.setAllCaps(false)
//监听原生Button点击事件
this.button?.setOnClickListener(_ => {
const detail = {
value: "CustomValue"
}
//构建自定义UniNativeViewEvent返回对象
const event = new UniNativeViewEvent("customClick", detail)
//触发原生Button的点击事件
this.$element.dispatchEvent(event)
})
//UniNativeViewEvent 绑定 安卓原生view
this.$element.bindAndroidView(this.button!);
}
updateText(text : string) {
//更新原生Button 文案描述
this.button?.setText(text)
}
destroy() {
//数据回收
}
}
class NativeButtonContext implements INativeButtonContext {
private element : UniElement | null = null
constructor(element : UniElement) {
this.element = element
}
updateText(text : string) {
let button = this.element?.getAndroidView()
if(null != button){
(button as Button).setText(text)
}
}
}
/**
* 递归查询
*/
function iterateElement(homeElement : UniElement) : UniElement | null {
if ("NATIVE-VIEW" == homeElement.nodeName) {
return homeElement
}
for (perChildEle of homeElement.children) {
let findEle = iterateElement(perChildEle)
if (findEle != null) {
return findEle
}
}
return null
}
export function createNativeButtonContext(id : string, ins : ComponentPublicInstance | null = null) : INativeButtonContext | null {
if (ins == null) {
const pages = getCurrentPages()
if (pages.length > 0) {
const page = pages[pages.length - 1]
const rootViewElement = page.getElementById(id)
if (rootViewElement != null) {
/**
* 找到了root节点,递归检索目标 native-view
*/
const nativeViewElement = iterateElement(rootViewElement)
if (nativeViewElement != null) {
return new NativeButtonContext(nativeViewElement)
}
}
}
} else {
/**
* 尝试迭代遍历
*/
if (ins.$el != null) {
const nativeViewElement = iterateElement(ins.$el as UniElement)
if (nativeViewElement != null) {
return new NativeButtonContext(nativeViewElement)
}
}
}
return null
}

查看文件

@@ -0,0 +1,12 @@
@Builder
export function buildButton(params: ESObject) {
Button(params.text, { type: ButtonType.Normal, stateEffect: true })
.borderRadius(8)
.backgroundColor(0x317aff)
.width('100%')
.height('100%')
.onClick(() => {
params.onClick()
})
.attributeModifier(params.attributeUpdater)
}

查看文件

@@ -0,0 +1,105 @@
import { BuilderNode } from "@kit.ArkUI"
// 导入混编实现的声明式UI构建函数
import { buildButton } from "./builder.ets"
import { INativeButtonContext } from "../interface.uts"
// 定义 buildButton 的参数类型
interface NativeButtonOptions {
text : string
onClick : () => void
}
export class NativeButton {
private $element : UniNativeViewElement;
private builder : BuilderNode<[NativeButtonOptions]> | null = null
// 初始化 buildButton 默认参数
private params : NativeButtonOptions = {
text: '',
onClick: () => {
const detail = {
value: "CustomValue"
}
this.$element.dispatchEvent(new UniNativeViewEvent("customClick", detail))
}
}
constructor(element : UniNativeViewElement) {
// 绑定 wrapBuilder 函数
this.builder = element.bindHarmonyWrappedBuilder(wrapBuilder<[NativeButtonOptions]>(buildButton), this.params)
this.$element = element
// 绑定当前实例为自定义的controller,方便其他地方通过 element 获取使用
this.$element.bindHarmonyController(this)
}
updateText(text : string) {
this.params.text = text
// 调用 builder update 函数来更新 UI
this.builder?.update(this.params)
}
destroy() {
//数据回收
}
}
class NativeButtonContext implements INativeButtonContext {
private controller : NativeButton
constructor(element : UniNativeViewElement) {
// 获取自定义的 controller
this.controller = element.getHarmonyController<NativeButton>()!
}
updateText(text : string) {
// 调用 controller 来更新文字
this.controller?.updateText(text)
}
}
/**
* 递归查询
*/
function iterateElement(homeElement : UniElement) : UniNativeViewElement | null {
if ("NATIVE-VIEW" == homeElement.nodeName) {
return homeElement as UniNativeViewElement
}
for (const perChildEle of homeElement.children) {
let findEle = iterateElement(perChildEle)
if (findEle != null) {
return findEle
}
}
return null
}
export function createNativeButtonContext(id : string, ins : ComponentPublicInstance | null = null) : INativeButtonContext | null {
if (ins == null) {
const pages = getCurrentPages()
if (pages.length > 0) {
const page = pages[pages.length - 1]
const rootViewElement = page.getElementById(id)
if (rootViewElement != null) {
/**
* 找到了root节点,递归检索目标 native-view
*/
const nativeViewElement = iterateElement(rootViewElement)
if (nativeViewElement != null) {
return new NativeButtonContext(nativeViewElement)
}
}
}
} else {
/**
* 尝试迭代遍历
*/
if (ins.$el != null) {
const nativeViewElement = iterateElement(ins.$el as UniElement)
if (nativeViewElement != null) {
return new NativeButtonContext(nativeViewElement)
}
}
}
return null
}

查看文件

@@ -0,0 +1,3 @@
{
"deploymentTarget": "12"
}

查看文件

@@ -0,0 +1,103 @@
import { UIButton, UIControl } from "UIKit"
import { INativeButtonContext, CreateNativeButtonContext } from "../interface.uts"
import { CGFloat } from 'CoreFoundation';
export class NativeButton {
element : UniNativeViewElement;
button : UIButton | null = null;
constructor(element : UniNativeViewElement) {
// 接收组件传递过来的UniNativeViewElement
this.element = element;
super.init()
this.bindView();
}
// element 绑定原生view
bindView() {
// 初始化原生 UIButton
this.button = new UIButton(type=UIButton.ButtonType.system)
// 构建方法选择器
const method = Selector("buttonClickAction")
// button 绑定点击回调方法
button?.addTarget(this, action = method, for = UIControl.Event.touchUpInside)
// UniNativeViewElement 绑定原生 view
this.element.bindIOSView(this.button!);
}
updateText(text : string) {
// 更新 button 显示文字
this.button?.setTitle(text, for = UIControl.State.normal)
}
/**
* 按钮点击回调方法
* 在 swift 中,所有target-action (例如按钮的点击事件,NotificationCenter 的通知事件等)对应的 action 函数前面都要使用 @objc 进行标记。
*/
@objc buttonClickAction() {
//构建自定义 UniNativeViewEvent 对象
const detail = {
value: "CustomValue"
}
let event = new UniNativeViewEvent("customClick", detail)
//触发自定义事件
this.element.dispatchEvent(event)
}
destroy() {
// 释放 UTS 实例对象,避免内存泄露
UTSiOS.destroyInstance(this)
}
}
function getNativeViewElemet(element: UniElement | null): UniNativeViewElement | null {
if (element == null) {
return null;
}
if (element instanceof UniNativeViewElement) {
return element as UniNativeViewElement
}
for (item in element!.children) {
let tmp = getNativeViewElemet(item)
if (tmp != null) {
return tmp
}
}
return null
}
export const createNativeButtonContext: CreateNativeButtonContext = function (id : string, component ?: ComponentPublicInstance | null) : INativeButtonContext | null {
let element : UniNativeViewElement | null = null;
let e: UniElement | null = null;
if (component == null) {
e = uni.getElementById(id)
} else {
e = component?.$el as UniElement | null;
}
if (e instanceof UniNativeViewElement) {
element = e as UniNativeViewElement | null
}else {
element = getNativeViewElemet(e)
}
if (element == null) return null;
return new NativeButtonContextImpl(element!);
}
class NativeButtonContextImpl implements INativeButtonContext {
btn: UIButton | null = null
constructor(element : UniNativeViewElement) {
let view = element.getIOSView()
if (view != null) {
this.btn = view as UIButton
}
}
updateText(title: string) : void {
this.btn?.setTitle(title, for = UIControl.State.normal)
}
}

查看文件

@@ -0,0 +1,14 @@
/**
* 原生组件的上下文对象
*/
export interface INativeButtonContext {
/**
* 更新文本示例
*/
updateText(text : string) : void
}
export type CreateNativeButtonContext = (
id : string,
component ?: ComponentPublicInstance | null
) => INativeButtonContext | null;

查看文件

@@ -0,0 +1,71 @@
<template>
<view class="def-picker">
<native-view style="width: 100%; height: 100%;" @init="onviewinit" @timechanged="ontimechanged"></native-view>
</view>
</template>
<script lang="uts" setup>
import { NativeTimePicker } from "@/uni_modules/native-time-picker";
// 定义 props
const props = defineProps({
"hour": {
type: Number,
default: 0
},
"minute": {
type: Number,
default: 0
}
});
// 定义 emits
const emit = defineEmits(['load', 'changed']);
// 响应式状态
const picker = ref<NativeTimePicker | null>(null);
const hourValue = ref(props.hour);
const minuteValue = ref(props.minute);
// 监听 hour prop 的变化
watch(():number => props.hour, (newValue: number) => {
if (newValue < 23 && newValue >= 0) {
hourValue.value = newValue;
picker.value?.setHour(hourValue.value);
}
}, {
immediate: true
});
// 监听 minute prop 的变化
watch(():number => props.minute, (newValue: number) => {
if (newValue < 59 && newValue >= 0) {
minuteValue.value = newValue;
picker.value?.setMinute(minuteValue.value);
}
}, {
immediate: true
});
// 方法
function onviewinit(e: UniNativeViewInitEvent) {
picker.value = new NativeTimePicker(e.detail.element, hourValue.value, minuteValue.value);
emit("load");
}
function ontimechanged(e: UniNativeViewEvent) {
emit("changed", e);
}
</script>
<style>
.def-picker {
min-width: 300px;
min-height: 380px;
max-width: 400px;
max-height: 400px;
}
</style>

查看文件

@@ -0,0 +1,80 @@
{
"id": "native-time-picker",
"displayName": "native-time-picker",
"version": "1.0.0",
"description": "native-time-picker",
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"type": "component-vue",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-vue": "u",
"app-nvue": "u",
"app-uvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1 @@
# native-time-picker

查看文件

@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}

查看文件

@@ -0,0 +1,31 @@
import TimePicker from "android.widget.TimePicker"
export class NativeTimePicker {
$element : UniNativeViewElement;
constructor(element : UniNativeViewElement, hour: number, minute: number) {
this.$element = element;
this.bindView(hour, minute);
}
picker : TimePicker | null = null;
bindView(hour: number, minute: number) {
this.picker = new TimePicker(this.$element.getAndroidActivity()!); //构建原生view
this.$element.bindAndroidView(this.picker!);
this.setHour(hour)
this.setMinute(minute)
this.picker?.setOnTimeChangedListener((_, hourOfDay, minute) => {
const detail = {"hour": hourOfDay, "minute": minute}
const event = new UniNativeViewEvent("timechanged", detail)
this.$element.dispatchEvent(event)
})
}
setHour(hour: number) {
this.picker?.setHour(hour.toInt())
}
setMinute(minute: number) {
this.picker?.setMinute(minute.toInt())
}
}

查看文件

@@ -0,0 +1,3 @@
{
"deploymentTarget": "12"
}

查看文件

@@ -0,0 +1,89 @@
import { UIDatePicker, UIControl, UIDatePickerStyle, UIUserInterfaceStyle } from "UIKit"
import { DateFormatter } from "Foundation"
export class NativeTimePicker {
element : UniNativeViewElement
timePicker : UIDatePicker
h : number
m : number
constructor(element : UniNativeViewElement, hour : number, minute : number) {
this.element = element
this.timePicker = new UIDatePicker()
this.h = hour
this.m = minute
super.init()
// 在 swift target-action 对应的方法需要以OC的方式来调用,那么OC语言中用Selector来表示一个方法的名称(又称方法选择器),创建一个Selector可以使用 Selector("functionName") 的方式。
const method = Selector("timeChange")
// 监听时间变化回调
this.timePicker.addTarget(this, action = method, for = UIControl.Event.valueChanged)
// 设置为时间选择模式
this.timePicker.datePickerMode = UIDatePicker.Mode.time
// 设置外观样式为 wheels
if (UTSiOS.available("iOS 13.4, *")) {
this.timePicker.preferredDatePickerStyle = UIDatePickerStyle.wheels
}
if (UTSiOS.available("iOS 13.0, *")) {
this.timePicker.overrideUserInterfaceStyle = UIUserInterfaceStyle.light
}
this.updateTime()
this.bindView(hour, minute)
}
// element 绑定原生view
bindView(hour : number, minute : number) {
this.element.bindIOSView(this.timePicker);
}
// 设置时
setHour(hour : number) {
this.h = hour
this.updateTime()
}
// 设置分
setMinute(minute : number) {
this.m = minute
this.updateTime()
}
// 更新显示
updateTime() {
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm"
let date = formatter.date(from = `${this.h}:${this.m}`)
if (date != null) {
this.timePicker.date = date!
}
}
/**
* 按钮点击回调方法
* 在 swift 中,所有target-action (例如按钮的点击事件,NotificationCenter 的通知事件等)对应的 action 函数前面都要使用 @objc 进行标记。
*/
@objc timeChange() {
// 发送事件
console.log("timeChange")
let formatter = DateFormatter()
formatter.dateFormat = "HH"
let hourString = formatter.string(from = this.timePicker.date)
formatter.dateFormat = "mm"
let minuteString = formatter.string(from = this.timePicker.date)
const detail = { "hour": hourString, "minute": minuteString }
const event = new UniNativeViewEvent("timechanged", detail)
this.element.dispatchEvent(event)
}
destroy() {
UTSiOS.destroyInstance(this)
}
}

查看文件

@@ -0,0 +1,23 @@
<template>
<view>
<view>
<text class="uni-subtitle-text">uni_modules的组件模板相对路径静态引入插件内static目录图片</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" mode="widthFix" src="../../static/test-image-path.png" />
</view>
</view>
<view>
<text class="uni-subtitle-text">uni_modules的组件模板绝对路径静态引入插件内static目录图片</text>
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" mode="widthFix" src="/uni_modules/test-image-path/static/test-image-path.png" />
</view>
</view>
</view>
</template>
<style>
.image {
margin: 20px auto;
width: 100px;
}
</style>

查看文件

@@ -0,0 +1,83 @@
{
"id": "test-image-path",
"displayName": "test-image-path",
"version": "1.0.0",
"description": "test-image-path",
"keywords": [
"test-image-path"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"type": "component-vue",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-vue": "u",
"app-nvue": "u",
"app-uvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1 @@
# test-image-path

二进制文件未显示。

之后

宽度:  |  高度:  |  大小: 4.2 KiB

查看文件

@@ -0,0 +1,82 @@
{
"id": "test-invoke-network-api",
"displayName": "test-invoke-network-api",
"version": "1.0.0",
"description": "测试UTS插件中访问网络相关接口",
"keywords": [
"test-invoke-network-api"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1,6 @@
# test-invoke-network-api
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)

查看文件

@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}

查看文件

@@ -0,0 +1,64 @@
import { CommonOptions } from '../interface.uts'
export function testInovkeRequest(options : CommonOptions) : void {
uni.request<any>({
url: "https://request.dcloud.net.cn/api/http/method/post",
method: "POST",
header: {
"Cookie": "token11222"
} as UTSJSONObject,
timeout: 6000,
sslVerify: false,
withCredentials: false,
data: {
"platform": {
"abc": "xyq"
},
},
firstIpv4: false,
success: (res : RequestSuccess<any>) => {
options.success?.(res)
},
fail(e : RequestFail) {
options.fail?.(e)
},
} as RequestOptions<any>)
}
export function testInovkeUploadFile(options : CommonOptions) : void {
const imageSrc = "/static/test-image/logo.png";
uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload',
files: [
{
name: "file1",
uri: imageSrc
} as UploadFileOptionFiles,
{
name: "file2",
uri: imageSrc
} as UploadFileOptionFiles
],
success: (res : UploadFileSuccess) => {
options.success?.(res)
},
fail: (err : UploadFileFail) => {
options.fail?.(err)
},
} as UploadFileOptions)
}
export function testInovkeDownloadFile(options : CommonOptions) : void {
uni.downloadFile({
url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
filePath: `${uni.env.CACHE_PATH}/halo/world/`,
success(res : DownloadFileSuccess) {
options.success?.(res)
},
fail(e : DownloadFileFail) {
options.fail?.(e)
}
} as DownloadFileOptions);
}

查看文件

@@ -0,0 +1,67 @@
import { CommonOptions } from '../interface.uts'
export function testInovkeRequest(options : CommonOptions) : void {
uni.request({
url: "https://request.dcloud.net.cn/api/http/method/post",
method: "POST",
header: {
"Cookie": "token11222"
} as UTSJSONObject,
timeout: 6000,
sslVerify: false,
withCredentials: false,
dataType: 'json',
responseType: 'text',
data: {
"platform": {
"abc": "xyq"
},
},
firstIpv4: false,
success: (res) => {
options.success?.(res)
},
fail(e) {
options.fail?.(e)
},
complete: () => {},
})
}
export function testInovkeUploadFile(options : CommonOptions) : void {
const imageSrc = "/static/test-image/logo.png";
uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload',
files: [
{
name: "file1",
uri: imageSrc
},
{
name: "file2",
uri: imageSrc
}
],
success: (res) => {
options.success?.(res)
},
fail: (err) => {
options.fail?.(err)
},
} as UploadFileOptions)
}
export function testInovkeDownloadFile(options : CommonOptions) : void {
uni.downloadFile({
url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
filePath: `${uni.env.CACHE_PATH}/halo/world/`,
success(res) {
options.success?.(res)
},
fail(e) {
options.fail?.(e)
}
} as DownloadFileOptions);
}

查看文件

@@ -0,0 +1,3 @@
{
"deploymentTarget": "9"
}

查看文件

@@ -0,0 +1,64 @@
import { CommonOptions } from '../interface.uts'
export function testInovkeRequest(options : CommonOptions) : void {
uni.request<any>({
url: "https://request.dcloud.net.cn/api/http/method/post",
method: "POST",
header: {
"Cookie": "token11222"
} as UTSJSONObject,
timeout: 6000,
sslVerify: false,
withCredentials: false,
data: {
"platform": {
"abc": "xyq"
},
},
firstIpv4: false,
success: (res : RequestSuccess<any>) => {
options.success?.(res)
},
fail(e : RequestFail) {
options.fail?.(e)
},
} as RequestOptions<any>)
}
export function testInovkeUploadFile(options : CommonOptions) : void {
const imageSrc = "/static/test-image/logo.png";
uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload',
files: [
{
name: "file1",
uri: imageSrc
} as UploadFileOptionFiles,
{
name: "file2",
uri: imageSrc
} as UploadFileOptionFiles
],
success: (res : UploadFileSuccess) => {
options.success?.(res)
},
fail: (err : UploadFileFail) => {
options.fail?.(err)
},
} as UploadFileOptions)
}
export function testInovkeDownloadFile(options : CommonOptions) : void {
uni.downloadFile({
url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
filePath: `${uni.env.CACHE_PATH}/halo/world/`,
success(res : DownloadFileSuccess) {
options.success?.(res)
},
fail(e : DownloadFileFail) {
options.fail?.(e)
}
} as DownloadFileOptions);
}

查看文件

@@ -0,0 +1,17 @@
export type CommonOptions = {
success ?: (res: any) => void
fail ?: (res : any) => void
}
export type testInovkeRequest = (options : CommonOptions) => void
export type testInovkeUploadFile = (options : CommonOptions) => void
export type testInovkeDownloadFile = (options : CommonOptions) => void

查看文件

@@ -0,0 +1,46 @@
<template>
<!-- #ifdef APP -->
<native-view @init="onviewinit"></native-view>
<!-- #endif -->
<!-- #ifndef APP -->
<view></view>
<!-- #endif -->
</template>
<script setup lang="uts">
// #ifdef APP
import { TestNativeView } from "@/uni_modules/test-native-view";
let view : TestNativeView | null = null
// Style样式监听
const style = useComputedStyle({
properties: ['background-color'],
filterProperties: true
} as UseComputedStyleOptions)
const backgroundColor = computed<string>(() => {
return style.get('background-color')?.toString() ?? '#FFFFFF'
})
/**
* 监听background-color变化
*/
watch([backgroundColor], () => {
view?.updateBackground(backgroundColor.value)
})
/**
* native-view组件初始化时触发
* 用于绑定App平台原生View
*/
function onviewinit(e : UniNativeViewInitEvent) {
view = new TestNativeView(e.detail.element)
view?.updateBackground(backgroundColor.value)
}
/**
* App平台主动释放资源
*/
onUnmounted(() => {
view?.destroy()
})
// #endif
</script>

查看文件

@@ -0,0 +1,82 @@
{
"id": "test-native-view",
"displayName": "test-native-view",
"version": "0.0.1",
"description": "测试native-view组件",
"repository": "",
"engines": {
"HBuilderX": "^4.25"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-android": {
"minVersion": "21"
},
"app-ios": {
"minVersion": "9"
}
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "y",
"字节跳动": "u",
"QQ": "y",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}

查看文件

@@ -0,0 +1,37 @@
import View from "android.view.View"
import Color from "android.graphics.Color"
export class TestNativeView {
$element : UniNativeViewElement
view : View | null = null
constructor(element : UniNativeViewElement) {
this.$element = element
this.bindView()
}
bindView() {
// 构建原生view
this.view = new View(this.$element.getAndroidActivity()!)
this.view.setBackgroundColor(Color.WHITE)
// 绑定原生view
this.$element.bindAndroidView(this.view!)
}
destroy() {
this.view = null
}
/**
* 更新背景颜色
* 仅支持#RRGGBB格式颜色字符串
*/
updateBackground(color: string) {
try{
this.view?.setBackgroundColor(UTSAndroid.colorWithString(color))
}catch(e){
//Nothing to do
}
}
}

查看文件

@@ -0,0 +1,8 @@
@Builder
export function buildView(params: ESObject) {
Stack({alignContent: Alignment.Center})
.width('100%')
.height('100%')
.backgroundColor(params.backgroundColor)
.attributeModifier(params.attributeUpdater)
}

查看文件

@@ -0,0 +1,61 @@
import { BuilderNode } from "@kit.ArkUI"
// 导入混编实现的声明式UI构建函数
import { buildView } from "./builder.ets"
/**
* 颜色转换,仅支持#开头的格式
* uni-app x 蒸汽模式8位时格式为 #RRGGBBAA
* 鸿蒙平台需要的是 #AARRGGBB
*/
class ColorUtils {
static fromUniColor(color: string): string | null {
if(color.startsWith("#")){
const len = color.length
if(len >= 9){
let rgb = color.substring(1, 7)
let a = color.substring(7, 9)
return `#${a}${rgb}`
}
return color;
}
return null
}
}
// Harmony 侧直接传递颜色字符串,避免依赖当前 SDK 未导出的颜色类型。
type NativeViewOptions = {
backgroundColor: string
}
export class TestNativeView {
private $element : UniNativeViewElement;
private builder : BuilderNode<[NativeViewOptions]> | null = null
// 初始化 buildButton 默认参数
private params : NativeViewOptions = {
backgroundColor: '#FFFFFF'
}
constructor(element : UniNativeViewElement) {
// 绑定 wrapBuilder 函数
this.builder = element.bindHarmonyWrappedBuilder(wrapBuilder<[NativeViewOptions]>(buildView), this.params)
this.$element = element
// 绑定当前实例为自定义的controller,方便其他地方通过 element 获取使用
this.$element.bindHarmonyController(this)
}
/**
* 更新背景颜色
* 仅支持#RRGGBB格式颜色字符串
*/
updateBackground(color : string) {
this.params.backgroundColor = UTSHarmony.colorWithString(color)
this.builder?.update(this.params)
}
/**
* 用于拉齐差异,鸿蒙平台无需实现
*/
destroy() {
}
}

查看文件

@@ -0,0 +1,3 @@
{
"deploymentTarget": "12"
}

查看文件

@@ -0,0 +1,35 @@
import { UIView, UIColor } from "UIKit"
import { CGFloat } from 'CoreFoundation';
export class TestNativeView {
$element : UniNativeViewElement;
view : UIView | null = null;
constructor(element : UniNativeViewElement) {
this.$element = element;
super.init()
this.bindView();
}
bindView() {
// 构建原生view
this.view = new UIView()
this.view!.backgroundColor = UIColor.white
// 绑定原生view
this.$element.bindIOSView(this.view!)
}
destroy() {
// 释放 UTS 实例对象,避免内存泄露
UTSiOS.destroyInstance(this)
}
/**
* 更新背景颜色
* 仅支持#RRGGBB格式颜色字符串
*/
updateBackground(color : string) {
this.view!.backgroundColor = UTSiOS.colorWithString(color)
}
}

查看文件

@@ -0,0 +1,6 @@
## 1.0.2(2026-05-18)
- 修复类名拼写错误
## 1.0.1(2026-04-30)
- 更新文档
## 1.0.0(2026-04-30)
- 支持 uni-badge-view 组件

查看文件

@@ -0,0 +1,267 @@
<template>
<!-- 如果不显示badge,则不包裹,直接显示子内容。保证常态下的高性能。但如果设置了alwaysWrapWithContent且有slot内容,则仍然保持包裹层 -->
<slot v-if="text == '0' && alwaysWrapWithContent== false"></slot>
<!-- 如果有多个子slot,且不设badge,去掉包裹层直接露出slot,会导致flex方向错乱。此时应设置alwaysWrapWithContent为true,总是保留包裹层 -->
<!-- 微信小程序不支持外部绑定事件 -->
<template v-else>
<view v-if="hasDefaultSlot" style="overflow: visible;" class="badge-wrap" v-bind="$attrs">
<!-- 目标内容插槽 -->
<slot></slot>
<!-- badge 文字模式 -->
<text v-if="text != '' && text != '0' " :class="['text', 'position', badgeClass]" :style="badgeStyle">
{{ text }}
</text>
<!-- badge 红点模式 -->
<view v-else-if="text != '0'" :class="['dot', 'position', badgeClass]" :style="badgeStyle"></view>
</view>
<!-- 不包裹,直接显示badge 文字模式 -->
<text v-else-if="text != ''" :class="['text', badgeClass]" :style="badgeStyle">
{{ text }}
</text>
<!-- 不包裹,直接显示badge 红点模式 -->
<view v-else :class="['dot', badgeClass]" :style="badgeStyle"></view>
</template>
</template>
<script setup lang="uts">
/**
* Badge 数字角标
* @description 数字角标(徽章)组件
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.08"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
// 禁用自动属性继承,手动控制属性绑定位置
defineOptions({
inheritAttrs: false,
externalClasses: ['badge-class']
})
// 定义组件属性接口
type Props = {
/**
* @description badge 的内容。为 "0" 时不显示 badge;为空字符串时显示圆点;有文字则显示文字
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
* }
*/
text? : string,
/**
* @description badge 的内联样式,用于覆盖内置 style
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
* }
*/
badgeStyle? : string,
/**
* @description badge 的样式类,用于覆盖内置 class
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
* }
*/
badgeClass? : string.ClassString,
/**
* @description 当有 slot 内容时,即使 text 为 "0" 也保留包裹层(badge-wrap),避免多个子 slot 时 flex 方向错乱
* @default false
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
* }
*/
alwaysWrapWithContent? : boolean
}
// 使用 withDefaults 设置默认值
const props = withDefaults(defineProps<Props>(), {
text: '',
badgeStyle: '',
badgeClass: '',
alwaysWrapWithContent: false
})
// 1. 获取插槽对象
const slots = useSlots();
// 2. 定义计算属性来判断默认插槽是否有内容
// TODO 这种判断方式的性能有待商榷,这利用了模板的隐式转换
const hasDefaultSlot = computed(() => {
// console.log('slot: ',slots['default']);
return slots['default'] != null;
});
</script>
<style>
.text {
/* background-color: rgba(225, 80, 80, 0.9); */ /* 有透明度*/
background-color: rgb(225, 80, 80); /* 无透明度*/
min-width: 14px;
height: 14px;
line-height: 14px;
border-radius: 7px;
/* padding-left: 4px; *//* 保证圆角不裁剪文字 */
/* padding-right: 4px; *//* 保证圆角不裁剪文字 */
font-size: 10px;
color: white;
text-align: center;
white-space: nowrap;
}
.dot {
background-color: rgb(225, 80, 80);
width: 8px;
height: 8px;
border-radius: 4px;
}
/* 有包裹内容,才定位在右上角。所以这个样式是一个单独的class,在slot有内容时才生效 */
.position {
position: absolute;
top: 0px; /* 定位在顶部*/
right: 0px; /* 定位在右边*/
transform: translate(50%, -50%); /* 中心向右上角偏移,保证中心在元素右上角顶点*/
}
.badge-wrap{
/* #ifdef WEB */
/* width: fit-content; */
/* #endif */
align-self: flex-start; /* 默认这样,不然width会变100%。但需要居中时得覆盖重设*/
}
</style>

查看文件

@@ -0,0 +1,74 @@
{
"id": "uni-badge-view",
"displayName": "uni-badge-view 数字角标",
"version": "1.0.2",
"description": "数字角标(徽章)组件,在元素周围展示消息提醒,一般用于列表、九宫格、按钮等地方。",
"isExt": true,
"extUrl": "https://ext.dcloud.net.cn/plugin?id=27844",
"keywords": [
"badge",
"uni-ui",
"uniui",
"数字角标",
"徽章"
],
"repository": "https://gitcode.com/dcloud/uni-ui-x",
"engines": {
"HBuilderX": "^5.08",
"uni-app-x": "^5.08",
"uni-app": ""
},
"directories": {
"example": "../../temps/example_temps"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"type": "component-vue",
"darkmode": "√",
"i18n": "√",
"widescreen": "√",
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"client": {
"uni-app-x": {
"web": {
"safari": "√",
"chrome": "√"
},
"app": {
"android": "√",
"ios": "√",
"harmony": "√"
},
"mp": {
"weixin": "√"
}
}
},
"cloud": {
"tcb": "x",
"aliyun": "x",
"alipay": "x"
}
}
}
}

查看文件

@@ -0,0 +1,34 @@
badge角标,可以用于显示红点、被红圈或其他颜色圈包裹的数字、文字。提醒用户此时有需要注意的新信息。
### 文件路径
项目下有一个 /pages/uni-ui/badge/badge.uvue 页面,里面演示了badge组件的各种用法。
### 设计
#### badge组件有多种用法:
1. 独立显示
如果没有slot内容,视为要显示独立的红点和数字,此时不是角标,就是普通的红点和圆背景数字。
在按钮或列表项的右侧,独立显示数字。也可以显示红点,但这种场景数字更多一些。
2. 作为一个容器组件,包含一个slot,在包裹内容的右上角显示一个角标view。
badge组件包裹一个目标view时,badge组件内部的角标view的中心点位于目标view的右上角顶点。
此时角标view是通过transform位移到右上角的,实际内容已经超出了容器本身。
所以需要注意容器的父级的设置,留出超出容器的尺寸(即top和right边距需要留出角标view的高度和宽度的一半),避免被父级裁剪。
#### badge的text属性的用法:
在badge作为容器组件时,text属性的不同设置,可以代表不同的效果。具体见属性章节。
#### 样式自定义
badge组件的badge-class和badge-style属性,直接作用在角标view上,可以修改角标view的样式。
角标view本质是一个text组件,可以覆盖前景、背景、位置等各种样式。
#### badge组件有如下属性:
- text
类型为 string|null
* 值为"0"时,不显示角标;所以永远不会显示一个为0的角标。此时直接显示slot子内容,不包裹外层,减少层级,提高性能;
* 值为null或""时,代表一个长宽为8px的红色圆点;
* 否则显示为该文字内容的圆角红底圈套文字。
- badge-class
直接作用于角标view的class
- badge-style
直接作用于角标view的style

查看文件

@@ -0,0 +1,96 @@
{
"id": "uni-chooseLocation-plugin",
"displayName": "uni-chooseLocation-plugin",
"version": "1.0.0",
"description": "uni-chooseLocation-plugin",
"keywords": [
"uni-chooseLocation-plugin"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [
"uni-chooseLocation"
],
"uni-ext-api": {
"uni": {
"chooseLocationPlugin": {
"name": "chooseLocationPlugin",
"app": {
"js": false,
"kotlin": false,
"swift": true,
"arkts": false
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1,6 @@
# uni-actionSheet
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)

查看文件

@@ -0,0 +1,16 @@
export const chooseLocationPlugin = () => {
uni.chooseLocation({
latitude: 39.951372,
longitude: 116.39747,
keyword: '公园',
success(res){
console.log('chooseLocation in plugin complete success', res);
},
fail(err){
console.log('chooseLocation in plugin complete fail', err);
},
complete(res){
console.log('chooseLocation in plugin complete res', res);
}
})
};

查看文件

@@ -0,0 +1,4 @@
## 1.0.1(2026-05-14)
- 支持 content-wrap-class 定义内层容器样式
## 1.0.0(2026-05-07)
- 支持 uni-collapse 组件

查看文件

@@ -0,0 +1,3 @@
export const UNI_COLLAPSE_REGISTER_CHILD = 'uni-collapse-register-child'
export const UNI_COLLAPSE_UNREGISTER_CHILD = 'uni-collapse-unregister-child'
export const UNI_COLLAPSE_CHILD_TOGGLE = 'uni-collapse-child-toggle'

查看文件

@@ -0,0 +1,6 @@
export type ItemChildType = {
openCollapse?: (show: boolean) => void;
openOrClose: (show: boolean) => void;
is_open: Ref<boolean>;
elId: string;
};

查看文件

@@ -0,0 +1,691 @@
<template>
<view>
<view class="uni-collapse-item__title" :class="props.titleWrapClass" @click="openCollapse(!is_open)">
<view class="uni-collapse-item__title-main">
<slot name="title" :open="is_open" :disabled="props.disabled">
<text class="uni-collapse-item__title-text"
:class="[{'open--active': is_open, 'is-disabled': props.disabled}, props.titleClass, is_open ? props.titleOpenClass : '', props.disabled ? props.titleDisabledClass : '']">{{ props.title }}</text>
</slot>
</view>
<view class="down_arrow"
:class="[arrowPlatformClass, arrowStateClass, arrowDisabledClass, props.arrowClass, is_open ? props.arrowOpenClass : '', props.disabled ? props.arrowDisabledClass : '']"></view>
</view>
<view ref="contentWrapRef" class="uni-collapse-item__content"
:class="[transition_enabled ? 'content-transition--active' : '', box_is_open ? 'content-state-open' : 'content-state-close', contentWrapClass]">
<view ref="contentRef" class="uni-collapse-item__content-box"
:class="[transition_enabled ? 'content-transition--active' : '', box_is_open ? 'content-box-open' : 'content-box-close']">
<slot></slot>
</view>
</view>
</view>
</template>
<script lang="uts" setup>
/**
* 折叠面板子项
* @description 折叠面板子项组件
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
import type { ItemChildType } from '../type.uts'
import {
UNI_COLLAPSE_REGISTER_CHILD,
UNI_COLLAPSE_UNREGISTER_CHILD,
UNI_COLLAPSE_CHILD_TOGGLE
} from '../common.uts'
defineOptions({
name: 'UniCollapseItem',
styleIsolation: 'app',
externalClasses: ['title-wrap-class', 'title-class', 'title-open-class', 'title-disabled-class', 'content-wrap-class', 'arrow-class', 'arrow-open-class', 'arrow-disabled-class']
})
type Props = {
/**
* @description 折叠项标题文字
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
title? : string,
/**
* @description 是否默认展开
* @default false
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
open? : boolean,
/**
* @description 是否禁用,禁用后点击标题不会展开或收起
* @default false
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
disabled? : boolean,
/**
* @description 标题行(整行容器)的样式类
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
titleWrapClass? : string.ClassString,
/**
* @description 标题文字的基础样式类
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
titleClass? : string.ClassString,
/**
* @description 展开状态下叠加到标题文字的样式类
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
titleOpenClass? : string.ClassString,
/**
* @description 禁用状态下叠加到标题文字的样式类
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
titleDisabledClass? : string.ClassString,
/**
* @description 内容外层容器的样式类
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
contentWrapClass? : string.ClassString,
/**
* @description 箭头图标的基础样式类
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
arrowClass? : string.ClassString,
/**
* @description 展开状态下叠加到箭头图标的样式类
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
arrowOpenClass? : string.ClassString,
/**
* @description 禁用状态下叠加到箭头图标的样式类
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
arrowDisabledClass? : string.ClassString
}
const props = withDefaults(defineProps<Props>(), {
title: '',
open: false,
disabled: false,
titleWrapClass: '',
titleClass: '',
titleOpenClass: '',
titleDisabledClass: '',
contentWrapClass: '',
arrowClass: '',
arrowOpenClass: '',
arrowDisabledClass: ''
})
const emit = defineEmits<{
change: [open: boolean]
}>()
defineSlots<{
default(props : {}) : any,
title(props : { open : boolean, disabled : boolean }) : any
}>()
let is_open = ref<boolean>(props.open)
let box_is_open = ref<boolean>(props.open)
let transition_enabled = ref<boolean>(false)
let contentWrapRef = ref<UniViewElement | null>(null)
let contentRef = ref<UniViewElement | null>(null)
const elId = ref(`uni_collapse_item_${Math.ceil(Math.random() * 10e5).toString(36)}`)
const contentTransitionDelay = 16
let enableTransitionTimer = 0
let isAndroidArrowRenderFix = false
// #ifdef APP-ANDROID
// Android arrow fix:
// keep transform rotation, but avoid animating border colors for border-drawn arrows.
// Keep split border-* properties here. Do not use border shorthand with var().
isAndroidArrowRenderFix = true
// #endif
const registerChild = inject<((child : ItemChildType) => void) | null>(UNI_COLLAPSE_REGISTER_CHILD, null)
const unregisterChild = inject<((elId : string) => void) | null>(UNI_COLLAPSE_UNREGISTER_CHILD, null)
const collapseToggle = inject<((elId : string) => void) | null>(UNI_COLLAPSE_CHILD_TOGGLE, null)
const arrowPlatformClass = computed(() : string => {
return isAndroidArrowRenderFix ? 'down_arrow--android-fix' : ''
})
const arrowStateClass = computed(() : string => {
if (!is_open.value) {
return ''
}
return isAndroidArrowRenderFix ? 'down_arrow--android-active' : 'down_arrow--active'
})
const arrowDisabledClass = computed(() : string => {
return props.disabled ? 'down_arrow--disabled' : ''
})
function clearEnableTransitionTimer() {
if (enableTransitionTimer != 0) {
clearTimeout(enableTransitionTimer)
enableTransitionTimer = 0
}
}
function openOrClose(open : boolean) {
box_is_open.value = open
}
function applyOpenState(open : boolean, syncSiblings : boolean, triggerEmit : boolean) {
if (is_open.value == open && box_is_open.value == open) {
return
}
if (open && syncSiblings && collapseToggle != null) {
collapseToggle(elId.value)
}
is_open.value = open
openOrClose(open)
if (triggerEmit) {
emit('change', open)
}
}
function openCollapse(open : boolean) {
if (props.disabled) {
return
}
applyOpenState(open, true, true)
}
onMounted(() => {
if (registerChild != null) {
const child : ItemChildType = {
is_open,
elId: elId.value,
openOrClose
}
registerChild(child)
}
if (is_open.value && collapseToggle != null) {
collapseToggle(elId.value)
}
nextTick(() => {
enableTransitionTimer = setTimeout(() => {
enableTransitionTimer = 0
transition_enabled.value = true
}, contentTransitionDelay)
})
})
onUnmounted(() => {
clearEnableTransitionTimer()
if (unregisterChild != null) {
unregisterChild(elId.value)
}
})
watch(() : boolean => props.open, (value : boolean) => {
applyOpenState(value, false, false)
})
defineExpose({
is_open,
openOrClose,
openCollapse
})
</script>
<style>
.uni-collapse-item__title {
flex-direction: row;
align-items: center;
padding: 12px 18px;
background-color: #ffffff;
}
.uni-collapse-item__title-main {
flex: 1;
flex-direction: row;
align-items: center;
}
.uni-collapse-item__title-text {
flex: 1;
font-size: 14px;
font-weight: 400;
color: #333333;
}
.open--active {
opacity: 0.78;
}
.is-disabled {
opacity: 0.45;
}
.down_arrow {
width: 8px;
height: 8px;
margin-left: 12px;
margin-top: -3px;
transform: rotate(45deg);
border-right-width: 1px;
border-right-style: solid;
border-right-color: #999999;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999999;
transition-property: transform, border-right-color, border-bottom-color;
transition-duration: 150ms;
}
.down_arrow--active {
margin-top: 0px;
transform: rotate(-135deg);
}
.down_arrow--android-fix {
transition-property: transform;
}
.down_arrow--android-active {
margin-top: 0px;
transform: rotate(-135deg);
}
.down_arrow--disabled {
opacity: 0.45;
}
.uni-collapse-item__content {
overflow: hidden;
width: 100%;
max-height: 0px;
background-color: #ffffff;
}
.uni-collapse-item__content-box {
width: 100%;
opacity: 0;
transform: translateY(-8px);
}
.content-state-open {
max-height: 2000px;
}
.content-state-close {
max-height: 0px;
}
.content-box-open {
opacity: 1;
transform: translateY(0px);
}
.content-box-close {
opacity: 0;
transform: translateY(-8px);
}
.content-transition--active {
transition-duration: 180ms;
transition-timing-function: ease;
}
/* 不要恢复旧的“运行时测量高度 + 内联 style.height”方案。
该方案在 HarmonyOS 上会出现默认展开时外层容器仍为 0 高度,导致内容不显示。 */
.uni-collapse-item__content {
transition-property: max-height;
}
.uni-collapse-item__content-box {
transition-property: opacity, transform;
}
</style>

查看文件

@@ -0,0 +1,121 @@
<template>
<view>
<slot></slot>
</view>
</template>
<script lang="uts" setup>
/**
* 折叠面板
* @description 折叠面板组件
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
import type { ItemChildType } from '../type.uts'
import {
UNI_COLLAPSE_REGISTER_CHILD,
UNI_COLLAPSE_UNREGISTER_CHILD,
UNI_COLLAPSE_CHILD_TOGGLE
} from '../common.uts'
defineOptions({
name: 'UniCollapse'
})
type Props = {
/**
* @description 是否开启手风琴模式,开启后同一时间仅允许一个子项展开
* @default true
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
accordion? : boolean
}
const props = withDefaults(defineProps<Props>(), {
accordion: true
})
let childNodes = [] as ItemChildType[]
function registerChild(child : ItemChildType) {
const existIndex = childNodes.findIndex((item : ItemChildType) : boolean => item.elId == child.elId)
if (existIndex == -1) {
childNodes.push(child)
}
}
function unregisterChild(elId : string) {
childNodes = childNodes.filter((item : ItemChildType) : boolean => item.elId != elId)
}
function toggle(elId : string) {
if (props.accordion && childNodes.length > 0) {
childNodes.forEach((item : ItemChildType) => {
const isOpen = item.is_open.value as boolean
if (isOpen && item.elId != elId) {
item.is_open.value = false
item.openOrClose(false)
}
})
}
}
provide(UNI_COLLAPSE_REGISTER_CHILD, registerChild)
provide(UNI_COLLAPSE_UNREGISTER_CHILD, unregisterChild)
provide(UNI_COLLAPSE_CHILD_TOGGLE, toggle)
</script>

查看文件

@@ -0,0 +1,74 @@
{
"id": "uni-collapse-x",
"displayName": "uni-collapse 折叠面板",
"version": "1.0.1",
"description": "Collapse 折叠面板组件,可自定义折叠面板的展开和收起。",
"isExt": true,
"extUrl": "https://ext.dcloud.net.cn/plugin?id=27899",
"keywords": [
"uni-ui",
"uniui",
"collapse",
"折叠面板",
"uni-app-x"
],
"engines": {
"HBuilderX": "",
"uni-app": "",
"uni-app-x": "^5.07"
},
"repository": "https://gitcode.com/dcloud/uni-ui-x",
"directories": {
"example": "../../temps/example_temps"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"type": "component-vue",
"darkmode": "x",
"i18n": "x",
"widescreen": "x",
"npmurl": ""
},
"uni_modules": {
"encrypt": [],
"dependencies": [],
"platforms": {
"cloud": {
"tcb": "x",
"aliyun": "x",
"alipay": "x"
},
"client": {
"uni-app-x": {
"web": {
"safari": "√",
"chrome": "√"
},
"app": {
"android": "√",
"ios": "√",
"harmony": "√"
},
"mp": {
"weixin": "√"
}
}
}
}
}
}

查看文件

@@ -0,0 +1,96 @@
折叠面板组件,包含:
- `uni-collapse`:父容器
- `uni-collapse-item`:子面板
一个折叠面板组件可以包含若干uni-collapse-item。每个uni-collapse-item包括顶部标题栏和通过slot传入的内容区。
### 基本用法
```html
<uni-collapse :accordion="true">
<uni-collapse-item title="标题 1" :open="true">
<view><text>内容 1</text></view>
</uni-collapse-item>
<uni-collapse-item title="标题 2">
<view><text>内容 2</text></view>
</uni-collapse-item>
</uni-collapse>
```
uni-collapse-item的标题栏的自定义:
- 标题栏容器可通过 `title-wrap-class` 自定义背景等容器样式。
- 标题栏支持title属性,可通过title-class自定义文字样式。
- 标题展开态可通过 `title-open-class` 自定义激活文字样式。组件默认使用透明度区分状态,便于外部继续覆盖文字颜色。
- 标题禁用态可通过 `title-disabled-class` 自定义禁用文字样式。若同时存在展开态和禁用态,以禁用态为最终状态。
- 内容外层容器可通过 `content-wrap-class` 自定义背景等容器样式。
- 标题栏右边默认带有箭头,可通过arrow-class自定义箭头样式。该箭头为一个view包括2个直角边的边框,然后旋转而成。
- 箭头展开态和禁用态可分别通过 `arrow-open-class`、`arrow-disabled-class` 覆盖。组件默认也使用透明度区分状态,便于外部继续覆盖箭头颜色。
- 如果完全不想要默认包含的title和arrow,也可以传入一个名为title的具名插槽来替换。
### 具名插槽标题
```html
<uni-collapse-item>
<template #title="{ open, disabled }">
<view class="custom-title">
<view class="custom-title-icon"></view>
<text class="custom-title-text">{{ open ? '已展开' : '未展开' }}</text>
</view>
</template>
<view><text>自定义标题内容</text></view>
</uni-collapse-item>
```
### externalClass
```html
<uni-collapse-item
title="自定义样式"
title-wrap-class="my-title-wrap-class"
title-class="my-title-class"
title-open-class="my-title-open-class"
content-wrap-class="my-content-wrap-class"
arrow-class="my-arrow-class"
arrow-open-class="my-arrow-open-class"
>
<view><text>内容区域</text></view>
</uni-collapse-item>
```
### Slots
#### uni-collapse-item
| 插槽名 | 说明 | 插槽参数 |
| --- | --- | --- |
| default | 面板内容 | - |
| title | 自定义标题区域 | `open: boolean`、`disabled: boolean` |
### Events
#### uni-collapse-item
| 事件名 | 说明 | 回调参数 |
| --- | --- | --- |
| change | 面板展开状态变化时触发 | `open: boolean` |
### Expose
#### uni-collapse-item
| 方法名 | 说明 |
| --- | --- |
| openCollapse(open: boolean) | 执行展开/收起,会遵循 `disabled` 和手风琴逻辑 |
| openOrClose(open: boolean) | 直接切换内容显示状态 |
### 暗黑模式适配
建议通过组件 `class` 和 externalClass 组合传入暗色样式:
- 用组件 `class` 统一控制根节点和内容区等外层视觉。
- 用 `title-wrap-class`、`title-class`、`title-open-class`、`content-wrap-class`、`arrow-class`、`arrow-open-class` 等 externalClass 覆盖标题区、内容外层和箭头样式。
- 默认展开态和禁用态主要通过透明度表达,减少颜色覆盖时的交叉冲突。
### 注意
- 本组件在Android上需HBuilderX 5.09+。在低版本上箭头变颜色+旋转时,在Android上会消失

查看文件

@@ -0,0 +1,6 @@
## 0.0.3(2022-11-11)
- 修复 config 方法获取根节点为数组格式配置时错误的转化为了对象的Bug
## 0.0.2(2021-04-16)
- 修改插件package信息
## 0.0.1(2021-03-15)
- 初始化项目

查看文件

@@ -0,0 +1,81 @@
{
"id": "uni-config-center",
"displayName": "uni-config-center",
"version": "0.0.3",
"description": "uniCloud 配置中心",
"keywords": [
"配置",
"配置中心"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "",
"type": "unicloud-template-function"
},
"directories": {
"example": "../../../scripts/dist"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "u",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1,93 @@
# 为什么使用uni-config-center
实际开发中很多插件需要配置文件才可以正常运行,如果每个插件都单独进行配置的话就会产生下面这样的目录结构
```bash
cloudfunctions
└─────common 公共模块
├─plugin-a // 插件A对应的目录
│ ├─index.js
│ ├─config.json // plugin-a对应的配置文件
│ └─other-file.cert // plugin-a依赖的其他文件
└─plugin-b // plugin-b对应的目录
├─index.js
└─config.json // plugin-b对应的配置文件
```
假设插件作者要发布一个项目模板,里面使用了很多需要配置的插件,无论是作者发布还是用户使用都是一个大麻烦。
uni-config-center就是用了统一管理这些配置文件的,使用uni-config-center后的目录结构如下
```bash
cloudfunctions
└─────common 公共模块
├─plugin-a // 插件A对应的目录
│ └─index.js
├─plugin-b // plugin-b对应的目录
│ └─index.js
└─uni-config-center
├─index.js // config-center入口文件
├─plugin-a
│ ├─config.json // plugin-a对应的配置文件
│ └─other-file.cert // plugin-a依赖的其他文件
└─plugin-b
└─config.json // plugin-b对应的配置文件
```
使用uni-config-center后的优势
- 配置文件统一管理,分离插件主体和配置信息,更新插件更方便
- 支持对config.json设置schema,插件使用者在HBuilderX内编写config.json文件时会有更好的提示(后续HBuilderX会提供支持)
# 用法
在要使用uni-config-center的公共模块或云函数内引入uni-config-center依赖,请参考:[使用公共模块](https://uniapp.dcloud.net.cn/uniCloud/cf-common)
```js
const createConfig = require('uni-config-center')
const uniIdConfig = createConfig({
pluginId: 'uni-id', // 插件id
defaultConfig: { // 默认配置
tokenExpiresIn: 7200,
tokenExpiresThreshold: 600,
},
customMerge: function(defaultConfig, userConfig) { // 自定义默认配置和用户配置的合并规则,不设置的情况侠会对默认配置和用户配置进行深度合并
// defaudltConfig 默认配置
// userConfig 用户配置
return Object.assign(defaultConfig, userConfig)
}
})
// 以如下配置为例
// {
// "tokenExpiresIn": 7200,
// "passwordErrorLimit": 6,
// "bindTokenToDevice": false,
// "passwordErrorRetryTime": 3600,
// "app-plus": {
// "tokenExpiresIn": 2592000
// },
// "service": {
// "sms": {
// "codeExpiresIn": 300
// }
// }
// }
// 获取配置
uniIdConfig.config() // 获取全部配置,注意:uni-config-center内不存在对应插件目录时会返回空对象
uniIdConfig.config('tokenExpiresIn') // 指定键值获取配置,返回:7200
uniIdConfig.config('service.sms.codeExpiresIn') // 指定键值获取配置,返回:300
uniIdConfig.config('tokenExpiresThreshold', 600) // 指定键值获取配置,如果不存在则取传入的默认值,返回:600
// 获取文件绝对路径
uniIdConfig.resolve('custom-token.js') // 获取uni-config-center/uni-id/custom-token.js文件的路径
// 引用文件(require)
uniIDConfig.requireFile('custom-token.js') // 使用require方式引用uni-config-center/uni-id/custom-token.js文件。文件不存在时返回undefined,文件内有其他错误导致require失败时会抛出错误。
// 判断是否包含某文件
uniIDConfig.hasFile('custom-token.js') // 配置目录是否包含某文件,true: 文件存在,false: 文件不存在
```

查看文件

@@ -0,0 +1,13 @@
{
"name": "uni-config-center",
"version": "0.0.3",
"description": "配置中心",
"main": "index.js",
"keywords": [],
"author": "DCloud",
"license": "Apache-2.0",
"origin-plugin-dev-name": "hello-uniapp-x",
"origin-plugin-version": "1.0.44",
"plugin-dev-name": "hello-uniapp-x",
"plugin-version": "1.0.44"
}

查看文件

@@ -0,0 +1,25 @@
{
"mode": "svg",
"level": 2,
"width": 150,
"height": 50,
"background": "#FFFAE8",
"size": 4,
"noise": 4,
"color": false,
"fontSize": 40,
"ignoreChars": "",
"mathExpr": false,
"mathMin": 1,
"mathMax": 9,
"mathOperator": "",
"expiresDate": 180,
"scene": {
"login": {
"mathExpr": true
},
"register": {
"expiresDate": 60
}
}
}

查看文件

@@ -0,0 +1,25 @@
## 配置参数说明
由于json不可以写注释,故在此写说明
```js
{
"mode": "svg", // 可选 svg bmp 默认使用svg格式验证码,nvue(uniapp X)只支持bmp格式验证码
"background": "#FFFAE8", //验证码背景色,设置空字符`''`不使用背景颜色
"size": 4, //验证码长度,最多 6 个字符
// "expiresDate": 180 //验证码过期时间(s)
// "noise": 6, //验证码干扰线条数
// 以下是svg专属配置 -----------------------------------------------------------
"width": 150, //图片宽度
"height": 50, //图片高度
// "color": false, //字体是否使用随机颜色,当设置`background`后恒为`true`
// "fontSize": 40, //字体大小
// "ignoreChars": '', //忽略那些字符
// "mathExpr": false, //是否使用数学表达式
// "mathMin": 1, //表达式所使用的最小数字
// "mathMax": 9, //表达式所使用的最大数字
// "mathOperator": '' //表达式所使用的运算符,支持 `+`、`-`。不传随机使用
// 以下是bmp专属配置 -----------------------------------------------------------
"level": 2, // 干扰等级 1 低 2 中 3 高 4 极高 推荐使用2或3即可
}
```

查看文件

@@ -0,0 +1,77 @@
{
"passwordSecret": "passwordSecret-demo",
"tokenSecret": "tokenSecret-demo",
"tokenExpiresIn": 7200,
"tokenExpiresThreshold": 3600,
"passwordErrorLimit": 6,
"bindTokenToDevice": false,
"passwordErrorRetryTime": 3600,
"autoSetInviteCode": false,
"forceInviteCode": false,
"app": {
"tokenExpiresIn": 2592000,
"tokenExpiresThreshold": 864000,
"oauth": {
"weixin": {
"appid": "填写来源微信开放平台https://open.weixin.qq.com/创建的应用的appid",
"appsecret": "填写来源微信开放平台https://open.weixin.qq.com/创建的应用的appsecret"
},
"apple": {
"bundleId": "苹果开发者后台获取的bundleId"
}
}
},
"web": {
"tokenExpiresIn": 7200,
"tokenExpiresThreshold": 3600,
"oauth": {
"weixin-h5": {
"appid": "微信公众号登录所用的appid、appsecret需要在对应的小程序管理控制台获取",
"appsecret": "微信公众号后台获取的appsecret"
},
"weixin-web": {
"appid": "微信PC页面扫码登录配置appid",
"appsecret": "微信PC页面扫码登录配置appsecret"
}
}
},
"mp-weixin": {
"tokenExpiresIn": 259200,
"tokenExpiresThreshold": 86400,
"oauth": {
"weixin": {
"appid": "微信小程序登录所用的appid、appsecret需要在对应的小程序管理控制台获取",
"appsecret": "微信小程序后台获取的appsecret"
}
}
},
"mp-alipay": {
"tokenExpiresIn": 259200,
"tokenExpiresThreshold": 86400,
"oauth": {
"alipay": {
"appid": "支付宝小程序登录用到的appid、privateKey请参考支付宝小程序的文档进行设置或者获取,https://opendocs.alipay.com/open/291/105971#LDsXr",
"privateKey": "支付宝小程序登录用到的appid、privateKey请参考支付宝小程序的文档进行设置或者获取,https://opendocs.alipay.com/open/291/105971#LDsXr"
}
}
},
"service": {
"sms": {
"name": "应用名称,对应短信模版的name",
"codeExpiresIn": 300,
"smsKey": "短信密钥key,开通短信服务处可以看到",
"smsSecret": "短信密钥secret,开通短信服务处可以看到",
"scene": {
"bind-mobile-by-sms": {
"templateId": "绑定手机号使用的短信验证码模板",
"codeExpiresIn": 240
}
}
},
"univerify": {
"appid": "当前应用的appid,使用云函数URL化,此项必须配置",
"apiKey": "apiKey 和 apiSecret 在开发者中心获取,开发者中心:https://dev.dcloud.net.cn/uniLogin/index?type=0,文档:https://ask.dcloud.net.cn/article/37965",
"apiSecret": ""
}
}
}

查看文件

@@ -0,0 +1,7 @@
module.exports = {
"default": "qqmap", // 默认使用的平台
"key": {
"qqmap": "XVXBZ-NDMC4-JOGUS-XGIEE-QVHDZ-AMFV2", // 腾讯地图key
"amap": "", // 高德地图key
}
}

查看文件

@@ -0,0 +1,12 @@
{
"schedule": {
"__UNI__xxxxxx": {
"enable": true,
"h5-weixin": {
"enable": false,
"tasks": ["ticket"]
}
}
},
"ipWhitelist": ["0.0.0.0"]
}

查看文件

@@ -0,0 +1,3 @@
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----

查看文件

@@ -0,0 +1,3 @@
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----

查看文件

@@ -0,0 +1,3 @@
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----

查看文件

@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----

查看文件

@@ -0,0 +1,124 @@
const fs = require('fs');
const path = require('path')
module.exports = {
// 统一 - 支付回调地址,格式为 "服务空间ID":"URL化地址"
"notifyUrl": {
// 测试环境服务空间-支付回调地址
"mp-b267e273-19a7-7788-99c7-f6f27f9c5b77": "https://fc-mp-b267e273-19a7-7788-99c7-f6f27f9c5b77.next.bspapp.com/uni-pay-co",
// 线上环境服务空间-支付回调地址(如果只有一个服务空间,则只需要配置线上环境服务空间即可)
"mp-499e2a37-0c66-418a-82aa-3e5820ecb057": "https://fc-mp-499e2a37-0c66-418a-82aa-3e5820ecb057.next.bspapp.com/uni-pay-co",
},
"notifyKey": "", // 跨云函数通信时的加密密钥,建议手动改下,不要使用默认的密钥,长度保持在64位以上即可
// 微信支付相关
"wxpay": {
"enable": true, // 是否启用微信支付
// 微信 - 小程序支付
"mp": {
"appId": "", // 小程序的appid
"secret": "", // 小程序的secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/apiclient_cert.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
},
// 微信 - APP支付
"app": {
"appId": "", // app开放平台下的应用的appid
"secret": "", // app开放平台下的应用的secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/apiclient_cert.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
},
// 微信 - 扫码支付
"native": {
"appId": "", // 可以是小程序或公众号或app开放平台下的应用的任意一个appid
"secret": "", // secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/apiclient_cert.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
},
// 微信 - 公众号支付
"jsapi": {
"appId": "", // 公众号的appid
"secret": "", // 公众号的secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/apiclient_cert.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
},
// 微信 - 手机外部浏览器H5支付
"mweb": {
"appId": "", // 可以是小程序或公众号或app开放平台下的应用的任意一个appid
"secret": "", // secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/apiclient_cert.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
// 场景信息,必填
"sceneInfo": {
"h5_info": {
"type": "Wap", // 此值固定Wap
"wap_url": "", // 你的H5首页地址,必须和你发起支付的页面的域名一致。
"wap_name": "", // 你的H5网站名称
}
}
},
},
// 支付宝相关(加签方式选证书模式,加密算法选RSA2)
"alipay": {
"enable": true, // 是否启用支付宝支付
// 支付宝 - 小程序支付配置
"mp": {
"appId": "", // 支付宝小程序appid
"privateKey": "", // 支付宝商户私钥
"appCertPath": path.join(__dirname, 'alipay/appCertPublicKey.crt'), // 支付宝商户公钥路径
"alipayPublicCertPath": path.join(__dirname, 'alipay/alipayCertPublicKey_RSA2.crt'), // 支付宝公钥路径
"alipayRootCertPath": path.join(__dirname, 'alipay/alipayRootCert.crt'), // 支付宝根证书路径
},
// 支付宝 - APP支付配置
"app": {
"appId": "", // 支付宝开放平台下应用的appid
"privateKey": "", // 支付宝商户私钥
"appCertPath": path.join(__dirname, 'alipay/appCertPublicKey.crt'), // 支付宝商户公钥路径
"alipayPublicCertPath": path.join(__dirname, 'alipay/alipayCertPublicKey_RSA2.crt'), // 支付宝公钥路径
"alipayRootCertPath": path.join(__dirname, 'alipay/alipayRootCert.crt'), // 支付宝根证书路径
},
// 支付宝 - H5支付配置(包含:网站二维码、手机H5,需申请支付宝当面付接口权限)
"native": {
"appId": "", // 支付宝开放平台下应用的appid
"privateKey": "", // 支付宝商户私钥
"appCertPath": path.join(__dirname, 'alipay/appCertPublicKey.crt'), // 支付宝商户公钥路径
"alipayPublicCertPath": path.join(__dirname, 'alipay/alipayCertPublicKey_RSA2.crt'), // 支付宝公钥路径
"alipayRootCertPath": path.join(__dirname, 'alipay/alipayRootCert.crt'), // 支付宝根证书路径
}
},
// 苹果虚拟支付相关
"appleiap": {
// 苹果虚拟支付支付,参数获取地址:https://appstoreconnect.apple.com/access/integrations/api/subs
"app": {
"appId": "", // 密钥ID
"issuerId": "", // Issuer ID
"bundleId": "", // 正式包名(如果dev包名和正式包名一致,则只填bundleId即可)
"devBundleId": "", // dev包名(如果dev包名和正式包名一致,则devBundleId可不填)
"appCertPath": path.join(__dirname, 'appleiap/apiclient_cert.p8'), // 证书路径
"sandbox": true, // 是否是沙箱环境
},
}
}

查看文件

@@ -0,0 +1,3 @@
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----

查看文件

@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----

查看文件

@@ -0,0 +1,137 @@
# uni-pay配置说明
## 目录结构
```
.
├── alipay──────────────────────────────# 支付宝证书目录
│ └── alipayCertPublicKey_RSA2.crt────────────────# 支付宝商户公钥证书
│ └── alipayRootCert.crt──────────────────────────# 支付宝根证书
│ └── appCertPublicKey.crt────────────────────────# 支付宝公钥证书
├── wxpay───────────────────────────────# 微信支付证书目录
│ └── apiclient_cert.pem─────────────────────────# 微信商户公钥证书
│ └── apiclient_key.pem──────────────────────────# 微信商户私钥证书
│ └── apiclient_cert.p12──────────────────────────────────# 微信商户p12格式的证书
├── config.js──────────────────────────# 支付配置文件
```
**注意:即使你不需要证书,也不要删除默认的空白证书(否则会报fs.readFileSync(__dirname+'/wxpay/apiclient_cert.p12') 找不到文件的错误。)**
## config.js 介绍
```js
const fs = require('fs');
const path = require('path')
module.exports = {
// 统一 - 支付回调地址,格式为 "服务空间ID":"URL化地址"
"notifyUrl": {
// 本地开发环境-支付回调地址
"b267e273-19a7-4288-99c7-f6f27f9c5b77": "https://b267e273-19a7-4288-99c7-f6f27f9c5b77.bspapp.com/uni-pay-co",
// 线上正式环境-支付回调地址
"499e2a37-0c77-418a-82aa-3e5820ecb057": "https://499e2a37-0c77-418a-82aa-3e5820ecb057.bspapp.com/uni-pay-co",
},
"notifyKey":"5FB2CD73C7B53918728417C50762E6D45FB2CD73C7B53918728417C50762E6D4", // 跨云函数通信时的加密密钥,建议手动改下,不要使用默认的密钥,长度保持在64位以上即可
// 微信支付相关
"wxpay": {
"enable": true, // 是否启用微信支付
// 微信 - 小程序支付
"mp": {
"appId": "", // 小程序的appid
"secret": "", // 小程序的secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/wxpay.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
},
// 微信 - APP支付
"app": {
"appId": "", // app开放平台下的应用的appid
"secret": "", // app开放平台下的应用的secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/wxpay.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
},
// 微信 - 扫码支付
"native": {
"appId": "", // 可以是小程序或公众号或app开放平台下的应用的任意一个appid
"secret": "", // secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/wxpay.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
},
// 微信 - 公众号支付
"jsapi": {
"appId": "", // 公众号的appid
"secret": "", // 公众号的secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/wxpay.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
},
// 微信 - 手机外部浏览器H5支付
"mweb": {
"appId": "", // 可以是小程序或公众号或app开放平台下的应用的任意一个appid
"secret": "", // secret
"mchId": "", // 商户id
"key": "", // v2的api key
"pfx": fs.readFileSync(__dirname + '/wxpay/wxpay.p12'), // v2需要用到的证书
"v3Key": "", // v3的api key
"appCertPath": path.join(__dirname, 'wxpay/apiclient_cert.pem'), // v3需要用到的证书
"appPrivateKeyPath": path.join(__dirname, 'wxpay/apiclient_key.pem'), // v3需要用到的证书
"version": 2, // 启用支付的版本 2代表v2版本 3 代表v3版本
// 场景信息,必填
"sceneInfo": {
"h5_info": {
"type": "Wap", // 此值固定Wap
"wap_url": "", // 你的H5首页地址,必须和你发起支付的页面的域名一致。
"wap_name": "", // 你的H5网站名称
}
}
},
},
// 支付宝相关(证书记得选java版本)
"alipay": {
"enable": true, // 是否启用支付宝支付
// 支付宝 - 小程序支付配置
"mp": {
"appId": "", // 支付宝小程序appid
"privateKey": "", // 支付宝商户私钥
"appCertPath": path.join(__dirname, 'alipay/appCertPublicKey.crt'), // 支付宝商户公钥路径
"alipayPublicCertPath": path.join(__dirname, 'alipay/alipayCertPublicKey_RSA2.crt'), // 支付宝公钥路径
"alipayRootCertPath": path.join(__dirname, 'alipay/alipayRootCert.crt'), // 支付宝根证书路径
},
// 支付宝 - APP支付配置
"app": {
"appId": "", // 支付宝开放平台下应用的appid
"privateKey": "", // 支付宝商户私钥
"appCertPath": path.join(__dirname, 'alipay/appCertPublicKey.crt'), // 支付宝商户公钥路径
"alipayPublicCertPath": path.join(__dirname, 'alipay/alipayCertPublicKey_RSA2.crt'), // 支付宝公钥路径
"alipayRootCertPath": path.join(__dirname, 'alipay/alipayRootCert.crt'), // 支付宝根证书路径
},
// 支付宝 - H5支付配置(包含:网站二维码、手机H5,需申请支付宝当面付接口权限)
"native": {
"appId": "", // 支付宝开放平台下应用的appid
"privateKey": "", // 支付宝商户私钥
"appCertPath": path.join(__dirname, 'alipay/appCertPublicKey.crt'), // 支付宝商户公钥路径
"alipayPublicCertPath": path.join(__dirname, 'alipay/alipayCertPublicKey_RSA2.crt'), // 支付宝公钥路径
"alipayRootCertPath": path.join(__dirname, 'alipay/alipayRootCert.crt'), // 支付宝根证书路径
}
}
}
```

查看文件

@@ -0,0 +1,4 @@
{
"smsKey": "your smsKey",
"smsSecret": "your smsSecret"
}

查看文件

@@ -0,0 +1,102 @@
{
"debug": false,
"redis": false,
"cachetime": 604800,
"sessionExpireTime": 1800,
"realtimeStat": true,
"cronMin": false,
"cronMinTips": "如果设置cronMin: true(开启分钟级统计)则你必须再修改 cloudfunctions/uni-stat-cron/package.json 文件内的 triggers 属性的 config的值为 0 */10 * * * * * 代表每10分钟运行一次定时任务",
"cron": [
{
"type": "stat",
"time": "* * * 0"
},
{
"type": "stat",
"time": "* * 1 10"
},
{
"type": "stat",
"time": "1 * 1 20"
},
{
"type": "stat",
"time": "* 1 3 30"
},
{
"type": "active-device",
"time": "* * 0 10"
},
{
"type": "active-user",
"time": "* * 0 20"
},
{
"type": "page",
"time": "* * 3 20"
},
{
"type": "event",
"time": "* * 4 20"
},
{
"type": "error",
"time": "* * 5 20"
},
{
"type": "loyalty",
"time": "* * 6 20"
},
{
"type": "clean",
"time": "* * 5 30"
},
{
"type": "retention-device",
"time": "* * 2 20"
},
{
"type": "retention-device",
"time": "* 1 4 30"
},
{
"type": "retention-device",
"time": "1 * 2 30"
},
{
"type": "retention-user",
"time": "* * 3 40"
},
{
"type": "retention-user",
"time": "* 1 5 40"
},
{
"type": "retention-user",
"time": "1 * 6 30"
},
{
"type": "pay-result",
"time": "* * * 10",
"dimension": "hour",
"description": "每小时执行统计(会自动统计小时、天、周、月、季度、年度)",
"timely": true
}
],
"batchInsertNum": 5000,
"errorCheck": {
"needCheck": true,
"checkTime": 5
},
"cleanLog": {
"open": true,
"reserveDays": {
"sessionLog": 31,
"userSessionLog": 31,
"pageLog": 7,
"eventLog": 7,
"shareLog": 7,
"errorLog": 7
}
}
}

查看文件

@@ -0,0 +1,73 @@
{
"id": "uni-drag-cell",
"displayName": "uni-drag-cell",
"version": "1.0.0",
"description": "可拖拽排序组件",
"isExt": true,
"extUrl": "https://ext.dcloud.net.cn/plugin?id=27845",
"keywords": [
"uni-drag-cell",
"uni-app-x",
"uni-app x",
"组件"
],
"repository": "https://gitcode.com/dcloud/uni-ui-x",
"engines": {
"HBuilderX": "^5.08",
"uni-app-x": "^5.08",
"uni-app": ""
},
"directories": {
"example": "../../temps/example_temps"
},
"dcloudext": {
"type": "component-vue",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"darkmode": "x",
"i18n": "x",
"widescreen": "x",
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "x",
"aliyun": "x",
"alipay": "x"
},
"client": {
"uni-app-x": {
"web": {
"safari": "√",
"chrome": "√"
},
"app": {
"android": "√",
"ios": "√",
"harmony": "√"
},
"mp": {
"weixin": "√"
}
}
}
}
}
}

查看文件

@@ -0,0 +1,331 @@
`uni-drag-cell` 是一个基于 `uni-app x + uvue + UTS` 实现的可拖拽排序组件。
它适合这些场景:
- 标签排序
- 宫格排序
- 单列列表排序
- 带删除能力的拖拽
- 尾部追加“+”入口
- 手柄拖拽排序
- 九宫格图片选择和排序
- 支付方式排序
组件通过 v-model 绑定了一个数组,通过插槽渲染绑定数组的内容,通过拖拽调整数组项的顺序。
组件还提供了show-close属性,显示底部删除条,拖到删除条即可删除。
组件还提供了show-append属性,显示尾部的添加插槽。该插槽不参与拖拽排序,始终在最后一个。(添加数组项的逻辑需自行实现)
通过这些能力,本组件具备对数组数据排序、添加、删除的能力。
但本组件不适合超长虚拟列表。不具备拖动到顶部或底部后自动滚动列表的功能。
### 设计目标
这个组件的设计不是“拖一下就立刻改数组”,而是分成两个阶段:
1. **拖拽预览阶段**
- 拖动过程中,通过 `transform` 动态调整视觉顺序
- 其他 item 会根据碰撞结果做位移动画
- 此时外部 `v-model` 还不会被正式改写
2. **拖拽提交阶段**
- 松手后,才正式修改内部数组顺序
- 然后通过 `update:modelValue` 和 `change` 把最终结果抛给外部
这样做的好处是:
- 拖动过程更平滑
- 外部响应式更新次数更少
- 更容易支持删除条、追加入口、手柄拖拽等扩展能力
### 交互模式
组件目前支持两种进入拖拽态的方式:长按拖拽和手柄拖拽。
#### 1. 长按拖拽
默认模式。
- 长按某个 item 后进入拖拽态
- 当前长按触发时间为 `350ms`
- 进入拖拽态后,item 会跟随手指/鼠标移动,并且会scale放大1.12倍。
- 拖动过程中持续做碰撞检测,并实时预览排序结果
补充:
- 如果按下后移动距离超过组件内部阈值,会取消本次长按判定,避免页面滚动时误触发拖拽
适合:
- 标签排序
- 宫格排序
- 图片排序
#### 2. 手柄拖拽
当 `handleMode` 为 `true`,且同时提供 `handle` 插槽时,会启用手柄模式。
- 不再需要长按
- 只有拖动手柄才会开始排序
- 内容区本身可以继续点击、滚动、预览
适合:
- 设置项排序
- 表单项排序
- 内容区本身还有点击行为的列表
### 插槽
| 插槽名 | 插槽参数 | 说明 |
| --- | --- | --- |
| `default` | `{ item, index }` | 默认内容插槽,用于渲染每一个可排序项。组件不限制 item 的视觉形式,可以自由渲染标签、卡片、宫格、图片等内容。 |
| `append` | - | 列表末尾的固定入口。不参与拖拽排序,不会写入 `v-model`,不会被删除,适合放“新增按钮”“上传入口”“更多入口”等内容。 |
| `handle` | `{ item, index }` | 拖拽手柄插槽,仅在 `handleMode` 开启时生效。手柄由组件放在每个 item 的右上角,建议给内容区预留右侧空间,避免手柄遮挡正文。 |
### 事件
| 事件名 | 回调参数 | 触发时机 | 说明 |
| --- | --- | --- | --- |
| `change` | 最新数组 | 排序完成后、删除完成后 | 最终结果事件。拖动中的视觉预览不会频繁触发 `change`。 |
### 使用方式
#### 1. 基础标签排序
```vue
<uni-drag-cell v-model="tagList">
<template #default="{ item, index }">
<view class="tag-item" @click="onClickTag(item, index)">
<text>{{ item }}</text>
</view>
</template>
</uni-drag-cell>
```
适合:
- 标签拖拽
- 轻量横向流式布局
说明:
- 默认使用长按触发拖拽
- 当前长按触发时间为 `350ms`
#### 2. 宫格排序
```vue
<uni-drag-cell v-model="gridList" :column="3">
<template #default="{ item }">
<view class="grid-item">
<text>{{ item.name }}</text>
</view>
</template>
</uni-drag-cell>
```
适合:
- 应用图标
- 功能入口宫格
- 九宫格类布局
#### 3. 带删除条的拖拽
```vue
<uni-drag-cell v-model="list" :show-close="true">
<template #default="{ item }">
<view class="cell-item">
<text>{{ item }}</text>
</view>
</template>
</uni-drag-cell>
```
交互:
- 长按进入拖拽
- 拖到屏幕底部删除条
- 删除条高亮后松手即删除
#### 4. 尾部追加一个固定入口
```vue
<uni-drag-cell v-model="tagList" :show-append="true">
<template #default="{ item }">
<view class="tag-item">
<text>{{ item }}</text>
</view>
</template>
<template #append>
<view class="tag-add" @click="addTag">
<text>+</text>
</view>
</template>
</uni-drag-cell>
```
说明:
- `append` 是通用设计,不局限于图片场景
- 拖拽排序时,`append` 不参与位置计算
#### 5. 九宫格图片选择
```vue
<uni-drag-cell
v-model="imageList"
:column="3"
:show-close="true"
:show-append="imageList.length < 9">
<template #default="{ item, index }">
<view class="image-item" @click="previewImage(index)">
<image :src="item" mode="aspectFill"></image>
</view>
</template>
<template #append>
<view class="image-add" @click="chooseImages">
<text>+</text>
</view>
</template>
</uni-drag-cell>
```
设计说明:
- 图片数组本身就是 `v-model`
- `append` 用来放“添加图片”入口
- 当达到上限时,把 `showAppend` 设为 `false`
#### 6. 手柄拖拽排序
```vue
<uni-drag-cell v-model="list" :column="1" :handle-mode="true">
<template #default="{ item }">
<view class="cell-item">
<text>{{ item }}</text>
</view>
</template>
<template #handle>
<view class="cell-handle">
<text>≡</text>
</view>
</template>
</uni-drag-cell>
```
说明:
- 手柄模式下,不需要长按
- 当前实现中,手柄模式不会再把整个 item 放大
- 这样可以避免单列场景下被父容器裁剪
### 组件内部设计说明
#### 1. 排序预览不是直接改数组
拖动过程中,组件内部维护的是“预览顺序”。
实现方式:
- 记录每个 item 的稳定 id
- 根据碰撞结果生成一份预览顺序
- 通过 `transform` 让其他项移动到目标位置
- 松手后再正式更新数组和 id 顺序
这样可以避免:
- 拖动中频繁改外部数组
- 频繁触发父组件重渲染
- item 身份丢失导致动画错乱
#### 2. 删除判定基于拖动内容区域
删除命中不是简单按手指坐标判断,而是优先按“拖动内容的真实边界”和“删除条边界”是否接触来判断。
这样做是为了避免:
- item 外层有 padding 时提前触发删除
- 不同高度 item 在删除区表现不一致
- web 与 app 坐标系不一致时出现明显偏移
#### 3. 追加项与删除条互不干扰
`append` 项的设计目标是“固定入口”,因此:
- 不参与碰撞排序
- 不参与删除
- 不写入绑定数组
#### 4. 手柄模式与长按模式共用同一套拖拽链路
也就是说:
- 排序逻辑相同
- 删除逻辑相同
- 只是“进入拖拽态”的入口不同
这样可以减少两套逻辑分叉导致的维护成本。
### 性能注意
拖拽时耗费性能的点主要有两个:
#### 1. 拖动中的碰撞检测
每次 move 都会更新:
- 当前拖动偏移
- 删除条命中状态
- 目标悬停位置
这是拖拽组件的必要开销,当前实现已经把重测布局的频率控制在较低水平,只在必要时重新测量。
#### 2. 删除条命中时的实时矩形读取
当启用 `showClose` 时,拖动中会优先读取当前拖动内容的实时矩形,以保证删除命中准确。
这部分是“精度优先”的设计,开销可接受,但不建议把它用于超大数量、超复杂 item 的高频拖拽场景。
### 使用注意事项
#### 1. 建议 item 尺寸稳定
尤其是宫格模式下,建议每个 item 的宽高尽量稳定。
否则可能带来:
- 拖动命中感不一致
- 排序预览观感不稳定
#### 2. 手柄模式下给内容区预留右侧空间
因为手柄是覆盖在 item 右上角的。
建议:
- 内容区右侧留白
- 或者把手柄区域设计成视觉上独立的一块
#### 3. `append` 只是入口,不是数据项
这点非常重要。
不要指望:
- `append` 参与排序
- `append` 进入 `v-model`
- `append` 被删除
如果你需要“真正的数据项”,请直接写进 `modelValue`。
#### 4. 外部不要在拖拽过程中频繁整体替换列表
建议:
- 由组件在松手后统一回传结果
- 父组件收到结果后再更新自己的数据源
不建议:
- 拖动过程中再由父组件持续重建整个数组
#### 5. 不建议用于超大列表或虚拟列表场景
这个组件当前更适合:
- 小中型标签列表
- 宫格
- 表单排序
- 九宫格图片选择
如果是超长列表、虚拟滚动列表,应该使用专门为大数据量设计的方案。
### 平台说明
#### Web
- 支持 pointer / touch 交互
#### Android
- 支持触摸拖拽

查看文件

@@ -0,0 +1,140 @@
<template>
<view style="align-items: center; justify-content: center;" class="fab" @click="handleClick">
<view flatten class="plus" :class="plusClass" style="position: absolute;"></view>
<view flatten class="plus" :class="plusClass" style="position: absolute;transform: rotate(90deg);"></view>
</view>
</template>
<script lang="uts" setup>
/**
* 悬浮加号按钮
* @description 悬浮加号按钮组件
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
defineOptions({
externalClasses: ['plus-class']
})
const props = defineProps({
/**
* @description 加号图标的自定义样式类,用于调整加号颜色、尺寸等样式
* @default ""
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
plusClass: { type: String, default: "" }
})
const emit = defineEmits<{
/**
* @description 点击事件,参数为事件对象,类型为 UniPointerEvent
* @uniPlatform {
* "app": {
* "android": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.21"
* },
* "ios": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.11"
* },
* "harmony": {
* "uniVer": "x",
* "unixVer": "5.07",
* "unixVaporVer": "5.07"
* }
* },
* "mp": {
* "weixin": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "5.07"
* }
* }
*/
click: [event: UniPointerEvent]
}>()
const handleClick = (event: UniPointerEvent) => {
emit('click', event)
}
</script>
<style>
.fab {
position: relative;
width: 44px;
height: 44px;
background-color: #007AFF;
border-radius: 50%;
box-shadow: 0 1px 5px 2px rgba(0, 0, 0, .3);
/* #ifdef WEB */
cursor: pointer;
/* #endif */
}
.plus {
background-color: white;
border-radius: 2px; /* 给加号边缘一点圆角 */
width: 40%;
height: 2px;
}
</style>

查看文件

@@ -0,0 +1,73 @@
{
"id": "uni-fab-button",
"displayName": "uni-fab-button",
"version": "1.0.0",
"description": "uni-fab-button",
"isExt": true,
"extUrl": "https://ext.dcloud.net.cn/plugin?id=27846",
"keywords": [
"uni-fab-button",
"uni-app-x",
"ui",
"组件"
],
"repository": "https://gitcode.com/dcloud/uni-ui-x",
"engines": {
"HBuilderX": "^5.07",
"uni-app-x": "^5.07",
"uni-app": ""
},
"directories": {
"example": "../../temps/example_temps"
},
"dcloudext": {
"type": "component-vue",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"darkmode": "x",
"i18n": "x",
"widescreen": "x",
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "x",
"aliyun": "x",
"alipay": "x"
},
"client": {
"uni-app-x": {
"web": {
"safari": "√",
"chrome": "√"
},
"app": {
"android": "√",
"ios": "√",
"harmony": "√"
},
"mp": {
"weixin": "√"
}
}
}
}
}
}

查看文件

@@ -0,0 +1,14 @@
悬浮加号按钮
本组件常用于页面中右下角悬浮的、里面有一个加号的圆形按钮。
组件的根view默认是一个圆形,蓝色背景(#007AFF),并带有阴影。使用组件时注意组件的父容器要留出阴影的空间,避免被裁剪。
组件的二级view是2个view交叉组成的加号。其中垂直的view是通过transform变换方向实现的。
组件的属性为 plus-class,它是一个externalClass,用于外部修改组件内部的、组成加号的2个view的样式。
组件中加号的默认样式为背景白色、粗细为2px、尺寸为40%。
### 注意
- 鸿蒙平台按下fab-button不缩写的问题,需升级到HBuilderX 5.09+解决

查看文件

@@ -0,0 +1,16 @@
## 1.3.2(2024-10-14)
- 新增 支持 HarmonyOS Next 调用
## 1.3.1(2023-09-15)
app端适配使用UniError
## 1.3.0(2023-05-30)
新增 同步获取电量api
## 1.2.0(2022-10-17)
实现百度小程序/支付宝小程序/QQ小程序获取电量
## 1.1.0(2022-10-17)
实现ios平台获取电量
## 1.0.0(2022-09-01)
实现android/web/微信小程序平台获取电量

查看文件

@@ -0,0 +1,94 @@
{
"id": "uni-getbatteryinfo",
"displayName": "uni-getbatteryinfo",
"version": "1.3.2",
"description": "使用uts开发,实现在多个平台获取电池电量功能",
"keywords": [
"battery"
],
"repository": "",
"engines": {
"HBuilderX": "^3.9.0"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"uni-ext-api": {
"uni": {
"getBatteryInfo": "getBatteryInfo",
"getBatteryInfoSync": {
"web": false
}
}
},
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y",
"alipay": "n"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-android": {
"minVersion": "21"
},
"app-ios": {
"minVersion": "9"
}
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "y",
"字节跳动": "u",
"QQ": "y",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

查看文件

@@ -0,0 +1,38 @@
# uni-getbatteryinfo
## 使用文档
```ts
// 获取电量信息
uni.getBatteryInfo({
success(res) {
console.log(res);
uni.showToast({
title: "当前电量:" + res.level + '%',
icon: 'none'
});
}
})
```
### 参数
Object object
|属性|类型|必填|说明|
|----|---|----|----|
|success|function|否|接口调用成功的回调函数|
|fail|function|否|接口调用失败的回调函数|
|complete|function|否|接口调用结束的回调函数(调用成功、失败都会执行)|
object.success 回调函数
|属性|类型|说明|
|----|---|----|
|level|number|设备电量,范围 1 - 100|
|isCharging|boolean|是否正在充电中|

查看文件

@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}

查看文件

@@ -0,0 +1,76 @@
import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess, GetBatteryInfoResult, GetBatteryInfoSync } from '../interface.uts'
import IntentFilter from 'android.content.IntentFilter';
import Intent from 'android.content.Intent';
import { GetBatteryInfoFailImpl } from '../unierror';
/**
* 异步获取电量
*/
export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
let batteryStatus = context.registerReceiver(null, ifilter);
let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
const res : GetBatteryInfoSuccess = {
errMsg: 'getBatteryInfo:ok',
level,
isCharging: isCharging
}
options.success?.(res)
options.complete?.(res)
} else {
let res = new GetBatteryInfoFailImpl(1001);
options.fail?.(res)
options.complete?.(res)
}
}
/**
* 同步获取电量
*/
export const getBatteryInfoSync : GetBatteryInfoSync = function () : GetBatteryInfoResult {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
Context.BATTERY_SERVICE
) as BatteryManager;
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
let batteryStatus = context.registerReceiver(null, ifilter);
let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
const res : GetBatteryInfoResult = {
level: level,
isCharging: isCharging
};
return res;
}
else {
/**
* 无有效上下文
*/
const res : GetBatteryInfoResult = {
level: -1,
isCharging: false
};
return res;
}
}

查看文件

@@ -0,0 +1,27 @@
import batteryInfo from '@ohos.batteryInfo';
import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess, GetBatteryInfoResult, GetBatteryInfoSync } from '../interface.uts';
export const getBatteryInfoSync : GetBatteryInfoSync = function () : GetBatteryInfoResult {
return {
level: batteryInfo.batterySOC,
isCharging: batteryInfo.chargingStatus === batteryInfo.BatteryChargeState.ENABLE || batteryInfo.chargingStatus === batteryInfo.BatteryChargeState.FULL,
};
}
export const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) {
const batteryInfoResult : GetBatteryInfoSuccess = {
errMsg: "getBatteryInfo:ok",
level: batteryInfo.batterySOC,
isCharging: batteryInfo.chargingStatus === batteryInfo.BatteryChargeState.ENABLE || batteryInfo.chargingStatus === batteryInfo.BatteryChargeState.FULL,
}
try {
options.success && options.success(batteryInfoResult)
} catch (e) {
console.error(e)
}
try {
options.complete && options.complete(batteryInfoResult)
} catch (e) {
console.error(e)
}
}

查看文件

@@ -0,0 +1,3 @@
{
"deploymentTarget": "9"
}

查看文件

@@ -0,0 +1,34 @@
// 引用 iOS 原生平台 api
import { UIDevice } from "UIKit";
import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoResult, GetBatteryInfoSync } from '../interface.uts';
/**
* 导出 获取电量方法
*/
export const getBatteryInfo: GetBatteryInfo = function (options) {
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
// 返回数据
const res: GetBatteryInfoSuccess = {
errMsg: "getBatteryInfo:ok",
level: Number(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
};
options.success?.(res);
options.complete?.(res);
}
export const getBatteryInfoSync: GetBatteryInfoSync = function (): GetBatteryInfoResult {
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
// 返回数据
const res: GetBatteryInfoResult = {
level: Number(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
};
return res;
}

查看文件

@@ -0,0 +1,43 @@
declare namespace UniNamespace {
interface GetBatteryInfoSuccessCallbackResult {
/**
* 是否正在充电中
*/
isCharging: boolean;
/**
* 设备电量,范围 1 - 100
*/
level: number;
errMsg: string;
}
interface GetBatteryInfoOption {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: Function
/**
* 接口调用失败的回调函数
*/
fail?: Function
/**
* 接口调用成功的回调函数
*/
success?: (result: GetBatteryInfoSuccessCallbackResult) => void
}
}
declare interface Uni {
/**
* 获取设备电量
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
*/
getBatteryInfo(option?: UniNamespace.GetBatteryInfoOption): void;
/**
* 同步获取电池电量信息
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
*/
getBatteryInfoSync(): UniNamespace.GetBatteryInfoSuccessCallbackResult;
}

查看文件

@@ -0,0 +1,147 @@
export type GetBatteryInfoSuccess = {
errMsg: string,
/**
* 设备电量,范围1 - 100
*/
level: number,
/**
* 是否正在充电中
*/
isCharging: boolean
}
export type GetBatteryInfoOptions = {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
success?: (res: GetBatteryInfoSuccess) => void
/**
* 接口调用失败的回调函数
*/
fail?: (res: UniError) => void
/**
* 接口调用成功的回调
*/
complete?: (res: any) => void
}
export type GetBatteryInfoResult = {
/**
* 设备电量,范围1 - 100
*/
level: number,
/**
* 是否正在充电中
*/
isCharging: boolean
}
/**
* 错误码
* - 1001 getAppContext is null
*/
export type GetBatteryInfoErrorCode = 1001 | 1002;
/**
* GetBatteryInfo 的错误回调参数
*/
export interface GetBatteryInfoFail extends IUniError {
errCode: GetBatteryInfoErrorCode
};
/**
* 获取电量信息
* @param {GetBatteryInfoOptions} options
*
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.11
*
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
export type GetBatteryInfo = (options: GetBatteryInfoOptions) => void
export type GetBatteryInfoSync = () => GetBatteryInfoResult
interface Uni {
/**
* 获取电池电量信息
*
* @example
* ```typescript
* uni.getBatteryInfo({
* success(res) {
* console.log(res);
* }
* })
* ```
* @remark
* - 该接口需要同步调用
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "3.6.11",
* "unixVer": "4.11"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "3.6.11",
* "unixVer": "4.0"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*
*/
getBatteryInfo(options: GetBatteryInfoOptions): void,
/**
* 同步获取电池电量信息
*
* @example
* ```typescript
* uni.getBatteryInfo()
* ```
* @remark
* - 该接口需要同步调用
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "3.6.11",
* "unixVer": "4.11"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "3.6.11",
* "unixVer": "4.0"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*
*/
getBatteryInfoSync(): GetBatteryInfoResult
}

查看文件

@@ -0,0 +1,6 @@
export function getBatteryInfo(options) {
return my.getBatteryInfo(options)
}
export function getBatteryInfoSync(options) {
return my.getBatteryInfoSync(options)
}

查看文件

@@ -0,0 +1,6 @@
export function getBatteryInfo(options) {
return swan.getBatteryInfo(options)
}
export function getBatteryInfoSync(options) {
return swan.getBatteryInfoSync(options)
}

查看文件

@@ -0,0 +1,6 @@
export function getBatteryInfo(options) {
return qq.getBatteryInfo(options)
}
export function getBatteryInfoSync(options) {
return qq.getBatteryInfoSync(options)
}

查看文件

@@ -0,0 +1,6 @@
export function getBatteryInfo(options) {
return wx.getBatteryInfo(options)
}
export function getBatteryInfoSync(options) {
return wx.getBatteryInfoSync(options)
}

查看文件

@@ -0,0 +1,35 @@
import { GetBatteryInfoErrorCode, GetBatteryInfoFail } from "./interface.uts"
/**
* 错误主题
*/
export const UniErrorSubject = 'uni-getBatteryInfo';
/**
* 错误信息
* @UniError
*/
export const UniErrors: Map<GetBatteryInfoErrorCode, string> = new Map([
/**
* 错误码及对应的错误信息
*/
[1001, 'getBatteryInfo:fail getAppContext is null'],
[1002, 'getBatteryInfo:fail not support'],
]);
/**
* 错误对象实现
*/
export class GetBatteryInfoFailImpl extends UniError implements GetBatteryInfoFail {
override errCode: GetBatteryInfoErrorCode;
/**
* 错误对象构造函数
*/
constructor(errCode: GetBatteryInfoErrorCode) {
super();
this.errSubject = UniErrorSubject;
this.errCode = errCode;
this.errMsg = UniErrors[errCode] ?? "";
}
}

查看文件

@@ -0,0 +1,23 @@
export function getBatteryInfo(options) {
if (navigator.getBattery) {
navigator.getBattery().then(battery => {
const res = {
errCode: 0,
errSubject: "uni-getBatteryInfo",
errMsg: 'getBatteryInfo:ok',
level: battery.level * 100,
isCharging: battery.charging
}
options.success && options.success(res)
options.complete && options.complete(res)
})
} else {
const res = {
errCode: 1002,
errSubject: "uni-getBatteryInfo",
errMsg: 'getBatteryInfo:fail navigator.getBattery is unsupported'
}
options.fail && options.fail(res)
options.complete && options.complete(res)
}
}

查看文件

@@ -0,0 +1,20 @@
import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess } from '../interface.uts'
export const getBatteryInfo: GetBatteryInfo = function (options: GetBatteryInfoOptions) {
if ((navigator as any).getBattery) {
(navigator as any).getBattery().then(battery => {
const res = {
errCode: 0,
errSubject: "uni-getBatteryInfo",
errMsg: 'getBatteryInfo:ok',
level: battery.level * 100,
isCharging: battery.charging
} as GetBatteryInfoSuccess
options.success && options.success(res)
options.complete && options.complete(res)
})
} else {
const res = new UniError("uni-getBatteryInfo", 1002, "getBatteryInfo:fail navigator.getBattery is unsupported")
options.fail && options.fail(res)
options.complete && options.complete(res)
}
}

某些文件未显示,因为此 diff 中更改的文件太多 显示更多