Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
5fbfda0d
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5992
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
5fbfda0d
编写于
5月 23, 2024
作者:
shutao-dc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
补充theme-change示例
上级
dcaa9890
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
139 addition
and
93 deletion
+139
-93
pages.json
pages.json
+7
-7
pages/API/theme-change/theme-change.test.js
pages/API/theme-change/theme-change.test.js
+27
-0
pages/API/theme-change/theme-change.uvue
pages/API/theme-change/theme-change.uvue
+95
-76
pages/tabBar/API.uvue
pages/tabBar/API.uvue
+10
-10
未找到文件。
pages.json
浏览文件 @
5fbfda0d
...
...
@@ -1309,6 +1309,13 @@
"navigationBarTitleText"
:
"日历"
}
},
{
"path"
:
"pages/API/theme-change/theme-change"
,
"style"
:
{
"navigationBarTitleText"
:
"主题切换"
,
"enablePullDownRefresh"
:
false
}
},
//
#endif
{
"path"
:
"pages/template/schema/schema"
,
...
...
@@ -1380,13 +1387,6 @@
"enablePullDownRefresh"
:
false
}
},
//
{
//
"path"
:
"pages/API/theme-change/theme-change"
,
//
"style"
:
{
//
"navigationBarTitleText"
:
"主题切换"
,
//
"enablePullDownRefresh"
:
false
//
}
//
},
{
"path"
:
"uni_modules/uni-pay-x/pages/success/success"
,
"style"
:
{
...
...
pages/API/theme-change/theme-change.test.js
0 → 100644
浏览文件 @
5fbfda0d
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe
(
'
API-theme-change
'
,
()
=>
{
let
page
;
const
isApp
=
process
.
env
.
UNI_OS_NAME
===
"
android
"
||
process
.
env
.
UNI_OS_NAME
===
"
ios
"
;
if
(
!
isApp
)
{
it
(
'
dummyTest
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/API/theme-change/theme-change
'
)
await
page
.
waitFor
(
600
);
});
it
(
"
check-set-app-theme
"
,
async
()
=>
{
await
page
.
callMethod
(
'
setAppTheme
'
,
"
dark
"
)
await
page
.
waitFor
(
300
)
expect
(
await
page
.
data
(
'
appTheme
'
)).
toBe
(
"
dark
"
)
})
});
pages/API/theme-change/theme-change.uvue
浏览文件 @
5fbfda0d
<template>
<view class="uni-padding-wrap">
<view class="uni-common-mt item-box">
<text>theme:</text>
<text id="theme">{{ dataInfo.theme }}</text>
</view>
<view class="uni-common-mt item-box">
<text>fn1 trigger num:</text>
<text id="fn1-trigger-num">{{ dataInfo.fn1TriggerNum }}</text>
<template>
<view class="uni-padding-wrap">
<view class="uni-common-mt item-box">
<text>osTheme:</text>
<text id="theme">{{ osTheme }}</text>
</view>
<view class="uni-common-mt item-box">
<text>
fn2 trigger num
:</text>
<text id="
fn2-trigger-num">{{ dataInfo.fn2TriggerNum
}}</text>
<text>
appTheme
:</text>
<text id="
theme">{{ appTheme
}}</text>
</view>
<button class="uni-common-mt" id="bind-fn1" @click="bindFn1">
bind fn1
</button>
<button class="uni-common-mt" id="remove-fn1" @click="removeFn1">
remove fn1
</button>
<button class="uni-common-mt" id="bind-fn2" @click="bindFn2">
bind fn2
</button>
<button class="uni-common-mt" id="remove-fn2" @click="removeFn2">
remove fn2
</button>
</view>
</template>
<script setup lang="uts">
type DataInfo = {
fn1TriggerNum: number
fn2TriggerNum: number
theme: string
}
const dataInfo = reactive<DataInfo>({
fn1TriggerNum: 0,
fn2TriggerNum: 0,
theme: ''
})
const fn1 = (options : OnThemeChangeOptions) => {
dataInfo.fn1TriggerNum++
console.log('fn1 triggered options: ', options)
dataInfo.theme = options.theme
}
const fn2 = (options : OnThemeChangeOptions) => {
dataInfo.fn2TriggerNum++
console.log('fn2 triggered options: ', options)
dataInfo.theme = options.theme
}
const bindFn1 = () => {
uni.onOSThemeChange(fn1)
}
const removeFn1 = () => {
uni.offOSThemeChange(fn1)
}
const bindFn2 = () => {
uni.onOSThemeChange(fn2)
}
const removeFn2 = () => {
uni.offOSThemeChange(fn2)
}
onReady(() => {
bindFn1()
bindFn2()
})
</script>
<style>
.item-box {
display: flex;
flex-direction: row;
justify-content: space-between;
}
<view>
<view class="uni-title uni-common-mt">
<text class="uni-title-text"> 修改appTheme主题 </text>
</view>
</view>
<view class="uni-list uni-common-pl">
<radio-group @change="radioChange" class="radio-group">
<radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item"
:class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item"
:checked="index === current">
{{ item }}
</radio>
</radio-group>
</view>
</view>
</template>
<script>
export default {
data() {
return {
osThemeChangeId: 0,
appThemeChangeId: 0,
osTheme: "light" as string,
appTheme: "light" as string,
current: 0,
items: [
"light",
"dark",
"auto"
] as string[]
}
},
methods: {
bindOsThemeChange(): number {
return uni.onOsThemeChange(function(res: OsThemeChangeResult) {
this.osTheme = res.osTheme
})
},
bindAppThemeChange(): number {
return uni.onAppThemeChange(function(res: AppThemeChangeResult) {
this.appTheme = res.appTheme
})
},
radioChange(e : UniRadioGroupChangeEvent) {
const theme = e.detail.value
setAppTheme(theme)
uni.showToast({
icon: 'none',
title: '当前选中:'+theme,
})
},
setAppTheme(value: string) {
uni.setAppTheme({
theme: value,
success: function() {
console.log("设置appTheme为", value, "成功")
},
fail: function(e: IAppThemeFail) {
console.log("设置appTheme为", value, "失败,原因:", e.errMsg)
}
})
}
},
onReady() {
uni.getSystemInfo({
success: (res:GetSystemInfoResult) => {
this.osTheme = res.osTheme!
this.appTheme = res.appTheme!
this.current = this.items.indexOf(this.appTheme)
}
})
this.osThemeChangeId = bindOsThemeChange()
this.appThemeChangeId = bindAppThemeChange()
}
}
</script>
<style>
.item-box {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.uni-list-cell {
justify-content: flex-start;
}
</style>
pages/tabBar/API.uvue
浏览文件 @
5fbfda0d
...
...
@@ -500,6 +500,16 @@
url: 'facial-recognition-verify',
}
] as Page[],
},
{
id: 'theme-change',
name: '主题切换',
pages: [
{
name: '主题切换',
url: 'theme-change',
}
] as Page[]
},
// #endif
{
...
...
@@ -546,16 +556,6 @@
}
] as Page[]
},
// {
// id: 'theme-change',
// name: '主题切换',
// pages: [
// {
// name: '主题切换',
// url: 'theme-change',
// }
// ] as Page[]
// },
// #endif
/*
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录