Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
5fbfda0d
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6005
Star
91
Fork
164
代码
文件
提交
分支
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 @@
...
@@ -1309,6 +1309,13 @@
"navigationBarTitleText"
:
"日历"
"navigationBarTitleText"
:
"日历"
}
}
},
},
{
"path"
:
"pages/API/theme-change/theme-change"
,
"style"
:
{
"navigationBarTitleText"
:
"主题切换"
,
"enablePullDownRefresh"
:
false
}
},
//
#endif
//
#endif
{
{
"path"
:
"pages/template/schema/schema"
,
"path"
:
"pages/template/schema/schema"
,
...
@@ -1380,13 +1387,6 @@
...
@@ -1380,13 +1387,6 @@
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
},
},
//
{
//
"path"
:
"pages/API/theme-change/theme-change"
,
//
"style"
:
{
//
"navigationBarTitleText"
:
"主题切换"
,
//
"enablePullDownRefresh"
:
false
//
}
//
},
{
{
"path"
:
"uni_modules/uni-pay-x/pages/success/success"
,
"path"
:
"uni_modules/uni-pay-x/pages/success/success"
,
"style"
:
{
"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>
<template>
<view class="uni-padding-wrap">
<view class="uni-padding-wrap">
<view class="uni-common-mt item-box">
<view class="uni-common-mt item-box">
<text>
theme:</text>
<text>
osTheme:</text>
<text id="theme">{{
dataInfo.theme }}</text>
<text id="theme">{{
osTheme }}</text>
</view>
</view>
<view class="uni-common-mt item-box">
<view class="uni-common-mt item-box">
<text>
fn1 trigger num
:</text>
<text>
appTheme
:</text>
<text id="
fn1-trigger-num">{{ dataInfo.fn1TriggerNum
}}</text>
<text id="
theme">{{ appTheme
}}</text>
</view>
</view>
<view class="uni-common-mt item-box">
<text>fn2 trigger num:</text>
<view>
<text id="fn2-trigger-num">{{ dataInfo.fn2TriggerNum }}</text>
<view class="uni-title uni-common-mt">
<text class="uni-title-text"> 修改appTheme主题 </text>
</view>
</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>
</view>
</template>
<view class="uni-list uni-common-pl">
<radio-group @change="radioChange" class="radio-group">
<script setup lang="uts">
<radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item"
type DataInfo = {
:class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item"
fn1TriggerNum: number
:checked="index === current">
fn2TriggerNum: number
{{ item }}
theme: string
</radio>
</radio-group>
}
</view>
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 = () => {
</view>
uni.onOSThemeChange(fn1)
</template>
}
const removeFn1 = () => {
uni.offOSThemeChange(fn1)
}
const bindFn2 = () => {
uni.onOSThemeChange(fn2)
}
const removeFn2 = () => {
uni.offOSThemeChange(fn2)
}
onReady(() => {
<script>
bindFn1()
export default {
bindFn2()
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>
</script>
<style>
<style>
.item-box {
.item-box {
display: flex;
display: flex;
flex-direction: row;
flex-direction: row;
justify-content: space-between;
justify-content: space-between;
}
}
.uni-list-cell {
justify-content: flex-start;
}
</style>
</style>
pages/tabBar/API.uvue
浏览文件 @
5fbfda0d
...
@@ -501,6 +501,16 @@
...
@@ -501,6 +501,16 @@
}
}
] as Page[],
] as Page[],
},
},
{
id: 'theme-change',
name: '主题切换',
pages: [
{
name: '主题切换',
url: 'theme-change',
}
] as Page[]
},
// #endif
// #endif
{
{
id: "payment",
id: "payment",
...
@@ -546,16 +556,6 @@
...
@@ -546,16 +556,6 @@
}
}
] as Page[]
] as Page[]
},
},
// {
// id: 'theme-change',
// name: '主题切换',
// pages: [
// {
// name: '主题切换',
// url: 'theme-change',
// }
// ] as Page[]
// },
// #endif
// #endif
/*
/*
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录