refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,47 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isIos = platformInfo.startsWith('ios')
|
||||
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
|
||||
|
||||
describe('API-theme-change', () => {
|
||||
let page;
|
||||
let originalTheme;
|
||||
let deviceShotOptions = {};
|
||||
if (!(isAndroid || isIos) || isAppWebView) {
|
||||
it('dummyTest', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch('/pages/API/theme-change/theme-change')
|
||||
await page.waitFor('view');
|
||||
originalTheme = await page.data('data.originalTheme')
|
||||
|
||||
const windowInfo = await program.callUniMethod('getWindowInfo');
|
||||
deviceShotOptions = {
|
||||
deviceShot: true,
|
||||
area: {
|
||||
x: 0,
|
||||
y: windowInfo.safeAreaInsets.top + 44,
|
||||
width: windowInfo.safeArea.width - 8,
|
||||
// 规避底部手势导航栏的影响
|
||||
height: windowInfo.safeArea.height - 40
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it("check-set-app-theme", async () => {
|
||||
await page.callMethod('setAppTheme', "dark")
|
||||
await page.waitFor(300)
|
||||
expect(await page.data('data.appTheme')).toBe("dark")
|
||||
const image = await program.screenshot(deviceShotOptions);
|
||||
expect(image).toSaveImageSnapshot();
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await page.callMethod('setAppTheme', originalTheme)
|
||||
await page.waitFor(600)
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
<template>
|
||||
<view class="uni-padding-wrap">
|
||||
<!-- #ifdef APP -->
|
||||
<view class="uni-common-mt item-box">
|
||||
<text>osTheme:</text>
|
||||
<text id="theme">{{ data.osTheme }}</text>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<view class="uni-common-mt item-box">
|
||||
<text>应用当前主题:</text>
|
||||
<text id="theme">{{ data.appTheme }}</text>
|
||||
</view>
|
||||
|
||||
<!-- #ifdef APP -->
|
||||
<view>
|
||||
<view class="uni-title uni-common-mt">
|
||||
<text class="uni-title-text"> 修改appTheme主题(此处仅为演示API,本应用并未完整适配暗黑模式) </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 data.items" :key="item"
|
||||
:class="index < data.items.length - 1 ? 'uni-list-cell-line' : ''" :value="item" :checked="index === data.current">
|
||||
{{ item }}
|
||||
</radio>
|
||||
</radio-group>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type Data = {
|
||||
osThemeChangeId: number;
|
||||
appThemeChangeId: number;
|
||||
osTheme: string;
|
||||
appTheme: string;
|
||||
originalTheme: string;
|
||||
current: number;
|
||||
items: string[];
|
||||
}
|
||||
|
||||
const data = reactive({
|
||||
osThemeChangeId: 0,
|
||||
appThemeChangeId: 0,
|
||||
osTheme: 'light',
|
||||
appTheme: 'light',
|
||||
originalTheme: 'light',
|
||||
current: 0,
|
||||
items: [
|
||||
'light',
|
||||
'dark',
|
||||
'auto'
|
||||
]
|
||||
} as Data)
|
||||
|
||||
function bindOsThemeChange() : number {
|
||||
return uni.onOsThemeChange((res : OsThemeChangeResult) => {
|
||||
data.osTheme = res.osTheme
|
||||
})
|
||||
}
|
||||
|
||||
function bindAppThemeChange() : number {
|
||||
// #ifdef APP
|
||||
return uni.onAppThemeChange((res : AppThemeChangeResult) => {
|
||||
data.appTheme = res.appTheme
|
||||
})
|
||||
// #endif
|
||||
// #ifdef WEB || MP
|
||||
return uni.onHostThemeChange((res : OnHostThemeChangeCallbackResult) => {
|
||||
data.appTheme = res.hostTheme
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
|
||||
function setAppTheme(value : string) {
|
||||
uni.setAppTheme({
|
||||
theme: value as 'light' | 'dark' | 'auto',
|
||||
success: function () {
|
||||
console.log('设置appTheme为', value, '成功')
|
||||
},
|
||||
fail: function (e : IAppThemeFail) {
|
||||
console.log('设置appTheme为', value, '失败,原因:', e.errMsg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function radioChange(e : UniRadioGroupChangeEvent) {
|
||||
const theme = e.detail.value
|
||||
setAppTheme(theme)
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '当前选中:' + theme,
|
||||
})
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
uni.getSystemInfo({
|
||||
success: (res : GetSystemInfoResult) => {
|
||||
// #ifdef APP
|
||||
data.osTheme = res.osTheme!
|
||||
data.originalTheme = res.appTheme!
|
||||
data.appTheme = res.appTheme == 'auto' ? res.osTheme! : res.appTheme!
|
||||
data.current = data.items.indexOf(res.appTheme!)
|
||||
// #endif
|
||||
// #ifdef WEB || MP
|
||||
data.appTheme = res.hostTheme!
|
||||
// #endif
|
||||
}
|
||||
})
|
||||
// #ifdef APP
|
||||
data.osThemeChangeId = bindOsThemeChange()
|
||||
// #endif
|
||||
data.appThemeChangeId = bindAppThemeChange()
|
||||
})
|
||||
|
||||
onUnload(() => {
|
||||
// #ifdef APP
|
||||
uni.offAppThemeChange(data.appThemeChangeId)
|
||||
uni.offOsThemeChange(data.osThemeChangeId)
|
||||
// #endif
|
||||
// #ifdef WEB || MP
|
||||
uni.offHostThemeChange(data.appThemeChangeId)
|
||||
// #endif
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
setAppTheme,
|
||||
radioChange
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.item-box {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.uni-list-cell {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户