refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,92 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
|
||||
|
||||
describe('ExtApi-GetSystemInfo', () => {
|
||||
if ( isMP) {
|
||||
it('skip', async () => {
|
||||
expect(1).toBe(1);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const PAGE_PATH = '/pages/API/get-system-info/get-system-info'
|
||||
let page;
|
||||
let res;
|
||||
const stringProperties = [
|
||||
'appId', 'appLanguage', 'appName', 'appVersion', 'appVersionCode',
|
||||
'brand', 'deviceId', 'deviceBrand', 'deviceModel', 'deviceType', 'language',
|
||||
'model', 'osName', 'osVersion', 'osLanguage', 'platform', 'system', 'ua', 'uniCompilerVersion',
|
||||
'uniPlatform', 'uniRuntimeVersion', 'romName', 'romVersion',
|
||||
]
|
||||
const numberProperties = [
|
||||
'osAndroidAPILevel', 'devicePixelRatio', 'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
|
||||
'windowWidth',
|
||||
'windowHeight', 'windowTop', 'windowBottom', 'screenTop',
|
||||
'uniCompilerVersionCode', 'uniRuntimeVersionCode'
|
||||
]
|
||||
const booleanProperties = [
|
||||
]
|
||||
const requiredProperties = [
|
||||
'uniCompilerVersion',
|
||||
'uniCompilerVersionCode',
|
||||
'uniRuntimeVersion',
|
||||
'uniRuntimeVersionCode'
|
||||
]
|
||||
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor(600);
|
||||
res = await page.callMethod('jest_getSystemInfo')
|
||||
});
|
||||
it('Check GetSystemInfoSync', async () => {
|
||||
for (const key in res) {
|
||||
const value = res[key];
|
||||
if (stringProperties.indexOf(key) != -1) {
|
||||
expect(value).not.toBeNull();
|
||||
expect(value).not.toBe("");
|
||||
}
|
||||
if (numberProperties.indexOf(key) != -1) {
|
||||
expect(value).not.toBeNull();
|
||||
expect(value).toBeGreaterThanOrEqual(0);
|
||||
}
|
||||
if (booleanProperties.indexOf(key) != -1) {
|
||||
expect(value).not.toBeNull();
|
||||
expect(typeof value).toBe('boolean');
|
||||
}
|
||||
if (key == 'deviceOrientation') {
|
||||
expect(['portrait', 'landscape']).toContain(value);
|
||||
}
|
||||
if (key == "osTheme") {
|
||||
expect(['light', 'dark']).toContain(value);
|
||||
}
|
||||
if (key == "appTheme") {
|
||||
expect(['light', 'dark', 'auto']).toContain(value);
|
||||
}
|
||||
}
|
||||
if (isAndroid) {
|
||||
if (res.safeAreaInsets.bottom > 0) {
|
||||
expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.screenHeight);
|
||||
} else {
|
||||
expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.safeArea.bottom);
|
||||
}
|
||||
}
|
||||
});
|
||||
it('Check GetSystemInfoSync required properties', async () => {
|
||||
for (let i = 0; i < requiredProperties.length; i++) {
|
||||
const key = requiredProperties[i]
|
||||
expect(`${key} not null: ${res[key] != null}`).toBe(`${key} not null: true`)
|
||||
}
|
||||
})
|
||||
|
||||
it('Check screenHeight at different stages', async ()=> {
|
||||
if(res["deviceOrientation"] == "landscape"){
|
||||
expect(1).toBe(1)
|
||||
}else{
|
||||
await page.callMethod('jest_getScreenHeight_at_different_stages')
|
||||
const res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true)
|
||||
}
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,136 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view>
|
||||
<page-head :title="data.title"></page-head>
|
||||
<view class="uni-common-mt">
|
||||
<view class="uni-list">
|
||||
<view class="uni-list-cell" v-for="(item, _) in data.items" style="align-items: center">
|
||||
<view class="uni-pd">
|
||||
<view class="uni-label" style="width: 180px">{{
|
||||
item.label
|
||||
}}</view>
|
||||
</view>
|
||||
<view class="uni-list-cell-db">
|
||||
<text class="uni-list-cell-db-text">{{ item.value == '' ? '未获取' : item.value }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="uni-padding-wrap">
|
||||
<view class="uni-btn-v">
|
||||
<button type="primary" @tap="getSystemInfoSync">
|
||||
同步获取设备系统信息
|
||||
</button>
|
||||
<button type="primary" @tap="getSystemInfo" style="margin-top: 20px;">
|
||||
异步获取设备系统信息
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
<script setup lang="uts">
|
||||
type Item = {
|
||||
label : string,
|
||||
value : string,
|
||||
}
|
||||
|
||||
type DataType = {
|
||||
title: string;
|
||||
items: Item[];
|
||||
screenHeightAtReady: number;
|
||||
jest_result: boolean;
|
||||
}
|
||||
|
||||
let globalScreenHeight = 0
|
||||
try {
|
||||
globalScreenHeight = uni.getWindowInfo().screenHeight
|
||||
} catch (e) {
|
||||
// 兼容本地测试
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
const data = reactive({
|
||||
title: 'getSystemInfo',
|
||||
items: [] as Item[],
|
||||
screenHeightAtReady: 0,
|
||||
jest_result: false,
|
||||
} as DataType)
|
||||
|
||||
onReady(() => {
|
||||
data.screenHeightAtReady = uni.getSystemInfoSync().screenHeight
|
||||
console.log(`全局获取屏幕高度: ${globalScreenHeight} onReady内获取屏幕高度: ${data.screenHeightAtReady}`);
|
||||
})
|
||||
|
||||
const getSystemInfo = () => {
|
||||
uni.getSystemInfo({
|
||||
success: (res) => {
|
||||
data.items = [] as Item[];
|
||||
const res_str = JSON.stringify(res);
|
||||
const res_obj = JSON.parseObject(res_str);
|
||||
const res_map = res_obj!.toMap();
|
||||
let keys = [] as string[]
|
||||
res_map.forEach((_, key) => {
|
||||
keys.push(key);
|
||||
});
|
||||
keys.sort().forEach(key => {
|
||||
const value = res[key];
|
||||
if (value != null) {
|
||||
const item = {
|
||||
label: key,
|
||||
value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
|
||||
} as Item;
|
||||
data.items.push(item);
|
||||
}
|
||||
});
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const getSystemInfoSync = () => {
|
||||
data.items = [] as Item[];
|
||||
const res = uni.getSystemInfoSync()
|
||||
const res_str = JSON.stringify(res);
|
||||
const res_obj = JSON.parseObject(res_str);
|
||||
const res_map = res_obj!.toMap();
|
||||
let keys = [] as string[]
|
||||
res_map.forEach((_, key) => {
|
||||
keys.push(key);
|
||||
});
|
||||
keys.sort().forEach(key => {
|
||||
const value = res[key];
|
||||
if (value != null) {
|
||||
const item = {
|
||||
label: key,
|
||||
value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
|
||||
} as Item;
|
||||
data.items.push(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//自动化测试例专用
|
||||
const jest_getSystemInfo = () : GetSystemInfoResult => {
|
||||
return uni.getSystemInfoSync();
|
||||
}
|
||||
|
||||
const jest_getScreenHeight_at_different_stages = () => {
|
||||
data.jest_result = (globalScreenHeight == data.screenHeightAtReady)
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
jest_getSystemInfo,
|
||||
jest_getScreenHeight_at_different_stages
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.uni-pd {
|
||||
padding-left: 15px;
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户