提交 d5ec601b 编写于 作者: dcloud_wdl's avatar dcloud_wdl

[转正] 4.43-alpha to release

...@@ -6,7 +6,10 @@ ...@@ -6,7 +6,10 @@
<!-- 录音权限,用于演示获取录音权限API:uni.getAppAuthorizeSetting 返回的microphoneAuthorized属性值 --> <!-- 录音权限,用于演示获取录音权限API:uni.getAppAuthorizeSetting 返回的microphoneAuthorized属性值 -->
<uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application> <!-- Android8以上支持圆形应用图标icon_round -->
<application
android:roundIcon="@drawable/icon_round"
>
<!-- 注册 url schemes --> <!-- 注册 url schemes -->
<activity android:name="io.dcloud.uniapp.UniLaunchProxyActivity" android:exported="true"> <activity android:name="io.dcloud.uniapp.UniLaunchProxyActivity" android:exported="true">
......
...@@ -45,9 +45,9 @@ ...@@ -45,9 +45,9 @@
// ) // )
// observer1.observe({ // observer1.observe({
// entryTypes: ['render', 'navigation'], // entryTypes: ['render', 'navigation'],
// } as PerformanceObserverOptions) // } as PerformanceObserverOptions)
// 统计上报 - 应用启动 // 统计上报 - 应用启动
// #ifdef APP-ANDROID || APP-IOS || WEB // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
uni.report({ uni.report({
name: 'uni-app-launch', name: 'uni-app-launch',
options: res, options: res,
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
setLifeCycleNum(state.lifeCycleNum + 100) setLifeCycleNum(state.lifeCycleNum + 100)
console.log('App Show') console.log('App Show')
// #ifdef APP-ANDROID || APP-IOS || WEB // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
// 统计上报 - 应用显示 // 统计上报 - 应用显示
uni.report({ uni.report({
name: 'uni-app-show', name: 'uni-app-show',
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
setLifeCycleNum(state.lifeCycleNum - 100) setLifeCycleNum(state.lifeCycleNum - 100)
console.log('App Hide') console.log('App Hide')
// #ifdef APP-ANDROID || APP-IOS || WEB // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
// 统计上报 - 应用进入后台 // 统计上报 - 应用进入后台
uni.report({ uni.report({
name: 'uni-app-hide', name: 'uni-app-hide',
...@@ -139,9 +139,9 @@ ...@@ -139,9 +139,9 @@
console.log('App Exit') console.log('App Exit')
}, },
// #endif // #endif
onError(err : any) { onError(err : any) {
// console.log('App onError', err) // console.log('App onError', err)
// #ifdef APP-ANDROID || APP-IOS || WEB // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
// 统计上报 - 应用发生错误 // 统计上报 - 应用发生错误
uni.report({ uni.report({
name: 'uni-app-error', name: 'uni-app-error',
...@@ -204,5 +204,10 @@ ...@@ -204,5 +204,10 @@
.uni-top-window uni-tabbar .uni-tabbar { .uni-top-window uni-tabbar .uni-tabbar {
background-color: #fff !important; background-color: #fff !important;
} }
/* #endif */
/* #ifdef MP-WEIXIN */
page {
background-color: #efeff4;
}
/* #endif */ /* #endif */
</style> </style>
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
<string>alipay</string> <string>alipay</string>
<string>safepay</string> <string>safepay</string>
<string>weixin</string> <string>weixin</string>
<string>qqmap</string>
<string>iosamap</string>
<string>baidumap</string>
</array> </array>
</dict> </dict>
</plist> </plist>
...@@ -78,6 +78,13 @@ ...@@ -78,6 +78,13 @@
.uni-list-cell-db, .uni-list-cell-db,
.uni-list-cell-right { .uni-list-cell-right {
flex: 1; flex: 1;
}
.uni-list-cell-db-text {
width: 100%;
/* #ifdef WEB || MP */
word-break: break-all;
/* #endif */
} }
.uni-label { .uni-label {
...@@ -95,7 +102,7 @@ ...@@ -95,7 +102,7 @@
} }
.uni-flex { .uni-flex {
/* #ifdef WEB */ /* #ifdef WEB || MP */
display: flex; display: flex;
/* #endif */ /* #endif */
flex-direction: row; flex-direction: row;
......
...@@ -84,10 +84,10 @@ ...@@ -84,10 +84,10 @@
<view class="input-wrapper"> <view class="input-wrapper">
<input class="uni-input" :type="inputType" :value="inputClearValue" :placeholder="title" maxlength="-1" @input="input" @blur="blur" <input class="uni-input" :type="inputType" :value="inputClearValue" :placeholder="title" maxlength="-1" @input="input" @blur="blur"
@focus="focus" /> @focus="focus" />
<!-- #ifdef WEB --> <!-- #ifdef WEB || MP -->
<image class="input-wrapper_image" src="/static/icons/clear.png" v-if="showClearIcon" @touchstart="clearIcon" @mousedown="clearIcon"> <image class="input-wrapper_image" src="/static/icons/clear.png" v-if="showClearIcon" @touchstart="clearIcon" @mousedown="clearIcon">
<!-- #endif --> <!-- #endif -->
<!-- #ifndef WEB --> <!-- #ifndef WEB || MP -->
<image class="input-wrapper_image" src="/static/icons/clear.png" v-if="showClearIcon" @touchstart="clearIcon"> <image class="input-wrapper_image" src="/static/icons/clear.png" v-if="showClearIcon" @touchstart="clearIcon">
<!-- #endif --> <!-- #endif -->
</image> </image>
......
<template> <template>
<view class="uni-navbar"> <view class="uni-navbar">
<view v-if="statusBar" class="status-bar"></view> <!-- #ifdef APP || WEB -->
<view v-if="statusBar" class="status-bar"></view>
<!-- #endif -->
<!-- #ifdef MP -->
<view v-if="statusBar" class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
<!-- #endif -->
<view class="uni-navbar-inner"> <view class="uni-navbar-inner">
<view class="left-content" @click="back"> <view class="left-content" @click="back">
<text :style="{ color: textColor }" class="uni-icons">{{ <text :style="{ color: textColor }" class="uni-icons">{{
...@@ -66,7 +71,11 @@ ...@@ -66,7 +71,11 @@
uni.setNavigationBarColor({ uni.setNavigationBarColor({
frontColor: "#000000", frontColor: "#000000",
backgroundColor: "#ffffff", backgroundColor: "#ffffff",
}); });
// #ifdef MP-WEIXIN
// TODO 部分小程序平台不支持getWindowInfo
this.statusBarHeight = uni.getWindowInfo().statusBarHeight
// #endif
}, },
methods: { methods: {
back() { back() {
......
// 仅测试 console.log 时机问题 // 仅测试 console.log 时机问题
import './test-main-console.uts' import './test-main-console.uts'
// #ifdef APP-ANDROID || APP-IOS || WEB // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
import { uniStat } from '@/uni_modules/uni-stat/plugin.uts' import { uniStat } from '@/uni_modules/uni-stat/plugin.uts'
// #endif // #endif
import App from './App.uvue' import App from './App.uvue'
...@@ -8,18 +8,18 @@ import App from './App.uvue' ...@@ -8,18 +8,18 @@ import App from './App.uvue'
import { createSSRApp } from 'vue' import { createSSRApp } from 'vue'
// 统计配置 // 统计配置
const uniStatCollectItems = { const uniStatcollectItems = {
uniStatPageLog: true uniStatPageLog: true
} }
const uniStatOptions = { const uniStatOptions = {
debug: false, debug: false,
collectItems: uniStatCollectItems, collectItems: uniStatcollectItems,
} }
export function createApp() { export function createApp() {
const app = createSSRApp(App) const app = createSSRApp(App)
// #ifdef APP-ANDROID || APP-IOS || WEB // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
app.use(uniStat, uniStatOptions) app.use(uniStat, uniStatOptions)
// #endif // #endif
// app.mixin({ // app.mixin({
......
...@@ -2,31 +2,35 @@ ...@@ -2,31 +2,35 @@
"name": "Hello uni-app x", "name": "Hello uni-app x",
"appid": "__UNI__HelloUniAppX", "appid": "__UNI__HelloUniAppX",
"description": "", "description": "",
"versionName": "1.6.10", "versionName": "1.7.2",
"versionCode": 10610, "versionCode": 10702,
"uni-app-x": {}, "uni-app-x": {},
/* 快应用特有相关 */ "uniStatistics": {
"quickapp": {}, "enable": false
/* 小程序特有相关 */ },
"vueVersion": "3",
/* 微信小程序平台配置 */
"mp-weixin": { "mp-weixin": {
"appid": "", "appid": "",
"setting": { "setting": {
"urlCheck": false "urlCheck": false
}, },
"usingComponents": true "usingComponents": true,
}, "resizable": true,
"mp-alipay": { "frameset": true,
"usingComponents": true "libVersion": "3.7.1",
}, "requiredPrivateInfos": [
"mp-baidu": { "getLocation",
"usingComponents": true "onLocationChange",
}, "startLocationUpdateBackground"
"mp-toutiao": { ],
"usingComponents": true "permission": {
}, "scope.userLocation": {
"uniStatistics": { "desc": "你的位置信息将用于小程序位置接口的效果展示"
"enable": false }
}
}, },
/* app平台配置 */
"app": { "app": {
"distribute": { "distribute": {
/* android打包配置 */ /* android打包配置 */
...@@ -36,8 +40,8 @@ ...@@ -36,8 +40,8 @@
"wxpay":{ "wxpay":{
"android": {}, "android": {},
"ios": { "ios": {
"appid": "wxd1b990d3136e369c", "appid": "",
"universalLink": "https://hellouniappx.dcloud.net.cn/ulink/" "universalLink": ""
} }
} }
}, },
...@@ -60,8 +64,8 @@ ...@@ -60,8 +64,8 @@
} }
} }
}, },
"vueVersion": "3", /* web平台配置 */
"h5": { "web": {
"router": { "router": {
"base": "/web/" "base": "/web/"
}, },
......
此差异已折叠。
const PAGE_PATH = '/pages/API/animation-frame/animation-frame' const PAGE_PATH = '/pages/API/animation-frame/animation-frame'
describe('API-cancelAnimationFrame', () => { describe('API-cancelAnimationFrame', () => {
if (process.env.uniTestPlatformInfo.startsWith('mp')) {
it('other platform', () => {
expect(1).toBe(1)
})
return
}
let page let page
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
......
...@@ -163,6 +163,9 @@ ...@@ -163,6 +163,9 @@
cropResize: false cropResize: false
} }
}, },
onHide() {
console.log("Page Hide");
},
onUnload() { onUnload() {
this.imageList = []; this.imageList = [];
this.sourceTypeIndex = 2 this.sourceTypeIndex = 2
......
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isIos = platformInfo.startsWith('ios')
describe('dialog page', () => { describe('dialog page', () => {
if (process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') { if (process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
it('skip app-webview', () => { it('skip app-webview', () => {
expect(1).toBe(1) expect(1).toBe(1)
}) })
return return
} }
if (isMP) {
it('skip mp', () => {
expect(1).toBe(1)
})
return
}
let page; let page;
let originLifeCycleNum;
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch('/pages/API/choose-location/choose-location') page = await program.reLaunch('/pages/API/choose-location/choose-location')
await page.waitFor('view'); await page.waitFor('view');
});
originLifeCycleNum = await page.callMethod('getLifeCycleNum')
it('dialogPage should empty', async () => {
await page.callMethod('chooseLocation') await page.callMethod('chooseLocation')
await page.waitFor(1000) await page.waitFor(1000)
});
it('dialogPage should empty', async () => {
const dialogPagesNum = await page.data('dialogPagesNum') const dialogPagesNum = await page.data('dialogPagesNum')
expect(dialogPagesNum).toBe(0) expect(dialogPagesNum).toBe(0)
}) })
it('should trigger parent hide', async () => {
const lifecycleNum = await page.callMethod('getLifeCycleNum')
expect(lifecycleNum).toBe(originLifeCycleNum - 1)
})
if (isIos) {
// 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
let version = process.env.uniTestPlatformInfo
let split = version.split(" ")
version = parseInt(split[split.length - 1])
if (version > 15) {
it('call chooseLocation in uts plugin', async () => {
page = await program.reLaunch('/pages/API/choose-location/choose-location')
await page.waitFor('view');
await page.callMethod('chooseLocationByPlugin')
await page.waitFor(1000)
const lifecycleNum = await page.callMethod('getLifeCycleNum')
expect(lifecycleNum).toBe(originLifeCycleNum - 1)
})
}
}
afterAll(async () => {
await page.callMethod('setLifeCycleNum', originLifeCycleNum)
});
}) })
...@@ -18,14 +18,24 @@ ...@@ -18,14 +18,24 @@
<text class="tips">注意:\n1. Web和App需要正确配置地图服务商的Key并且保证Key的权限和余额足够,才能正常选择位置\n2. 若没有关联uniCloud空间,则只能全屏地图选点,不能根据POI选择位置\n3. payload参数会原样透传给uni-map-co,可用于用户鉴权</text> <text class="tips">注意:\n1. Web和App需要正确配置地图服务商的Key并且保证Key的权限和余额足够,才能正常选择位置\n2. 若没有关联uniCloud空间,则只能全屏地图选点,不能根据POI选择位置\n3. payload参数会原样透传给uni-map-co,可用于用户鉴权</text>
<boolean-data :defaultValue="false" title="是否指定位置为天安门" @change="changeLocationBoolean"></boolean-data> <boolean-data :defaultValue="false" title="是否指定位置为天安门" @change="changeLocationBoolean"></boolean-data>
<boolean-data :defaultValue="false" title="是否携带keyword参数" @change="changeKeywordBoolean"></boolean-data> <boolean-data :defaultValue="false" title="是否携带keyword参数" @change="changeKeywordBoolean"></boolean-data>
<!-- #ifndef MP -->
<boolean-data :defaultValue="false" title="是否携带payload参数" @change="changePayloadBoolean"></boolean-data> <boolean-data :defaultValue="false" title="是否携带payload参数" @change="changePayloadBoolean"></boolean-data>
<!-- #endif -->
<button class="btn" type="primary" @tap="chooseLocation">选择位置</button> <button class="btn" type="primary" @tap="chooseLocation">选择位置</button>
<button class="btn" @tap="clear">清空</button> <button class="btn" @tap="clear">清空</button>
<!-- #ifdef APP-IOS -->
<button class="btn" type="primary" @tap="chooseLocationByPlugin">通过 uts 插件调用 chooseLocation</button>
<!-- #endif -->
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script lang="uts"> <script lang="uts">
import {
state,
setLifeCycleNum
} from '@/store/index.uts'
type Location = { type Location = {
latitude: string[] latitude: string[]
longitude: string[] longitude: string[]
...@@ -47,6 +57,16 @@ ...@@ -47,6 +57,16 @@
hoverPayload: false hoverPayload: false
} }
}, },
onShow() {
console.log("Page Show");
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
onHide() {
console.log("Page Hide");
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
methods: { methods: {
chooseLocation: function () { chooseLocation: function () {
let chooseLocationOptions = { let chooseLocationOptions = {
...@@ -65,11 +85,13 @@ ...@@ -65,11 +85,13 @@
if (this.hoverKeyword) { if (this.hoverKeyword) {
chooseLocationOptions.keyword = '公园' chooseLocationOptions.keyword = '公园'
} }
// #ifndef MP
if (this.hoverPayload) { if (this.hoverPayload) {
chooseLocationOptions.payload = { chooseLocationOptions.payload = {
token: 'xxx' token: 'xxx'
} }
} }
// #endif
uni.chooseLocation(chooseLocationOptions) uni.chooseLocation(chooseLocationOptions)
// 自动化测试 // 自动化测试
setTimeout(() => { setTimeout(() => {
...@@ -102,13 +124,28 @@ ...@@ -102,13 +124,28 @@
changePayloadBoolean(checked : boolean) { changePayloadBoolean(checked : boolean) {
this.hoverPayload = checked this.hoverPayload = checked
}, },
// #ifdef APP-IOS
chooseLocationByPlugin(){
uni.chooseLocationPlugin()
},
// #endif
// 自动化测试 // 自动化测试
test() { test() {
const pages = getCurrentPages() const pages = getCurrentPages()
const page = pages[pages.length - 1] const page = pages[pages.length - 1]
// #ifdef APP || WEB
const dialogPages = page.getDialogPages() const dialogPages = page.getDialogPages()
this.dialogPagesNum = dialogPages.length this.dialogPagesNum = dialogPages.length
} // #endif
},
// 自动化测试
setLifeCycleNum(value : number) {
setLifeCycleNum(value)
},
// 自动化测试
getLifeCycleNum() : number {
return state.lifeCycleNum
},
} }
} }
</script> </script>
......
...@@ -58,6 +58,9 @@ ...@@ -58,6 +58,9 @@
albumMode: "custom" albumMode: "custom"
} }
}, },
onHide() {
console.log("Page Hide");
},
methods: { methods: {
chooseVideo() { chooseVideo() {
uni.chooseVideo({ uni.chooseVideo({
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ // uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('API-compressImage', () => { describe('API-compressImage', () => {
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { if (
process.env.uniTestPlatformInfo.startsWith('web') ||
process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') ||
process.env.uniTestPlatformInfo.startsWith('mp')
) {
it('pass', async () => { it('pass', async () => {
expect(1).toBe(1); expect(1).toBe(1);
}); });
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ // uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('API-compressVideo', () => { describe('API-compressVideo', () => {
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { if (
process.env.uniTestPlatformInfo.startsWith('web') ||
process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') ||
process.env.uniTestPlatformInfo.startsWith('mp')
) {
it('pass', async () => { it('pass', async () => {
expect(1).toBe(1); expect(1).toBe(1);
}); });
......
<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex:1"> <scroll-view style="flex:1">
<!-- #endif --> <!-- #endif -->
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<view> <view>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<video class="video" :src="beforeCompressPath" :controls="true"></video> <video class="video" :src="beforeCompressPath" :controls="true"></video>
<view class="uni-title"> <view class="uni-title">
<text class="uni-subtitle-text">压缩前视频信息</text> <text class="uni-subtitle-text">压缩前视频信息</text>
</view> </view>
<text>{{beforeCompressVideoInfo}}</text> <text>{{beforeCompressVideoInfo}}</text>
<video class="video" :src="afterCompressPath" :controls="true"></video> <video class="video" :src="afterCompressPath" :controls="true"></video>
<view class="uni-title"> <view class="uni-title">
<text class="uni-subtitle-text">压缩后视频信息</text> <text class="uni-subtitle-text">压缩后视频信息</text>
</view> </view>
<text>{{afterCompressVideoInfo}}</text> <text>{{afterCompressVideoInfo}}</text>
<view class="uni-btn-v"> <view class="uni-btn-v">
<button type="primary" @click="chooseVideo">从相册中选取待压缩的视频</button> <button type="primary" @click="chooseVideo">从相册中选取待压缩的视频</button>
</view> </view>
<view class="uni-btn-v"> <view class="uni-btn-v">
<button type="primary" @click="compressVideo">压缩视频</button> <button type="primary" @click="compressVideo">压缩视频</button>
</view> </view>
<enum-data title="压缩质量" :items="qualityItemTypes" @change="onQualityChange"></enum-data> <enum-data title="压缩质量" :items="qualityItemTypes" @change="onQualityChange"></enum-data>
<view class="uni-common-mt"> <view class="uni-common-mt">
<text class="uni-title uni-title-text">相对于原视频的分辨率比例,取值范围(0, 1]</text> <text class="uni-title uni-title-text">相对于原视频的分辨率比例,取值范围(0, 1]</text>
<slider :min="0.1" :max="1" :step="0.1" :show-value="true" @change="onResolutionChange"></slider> <slider :min="0.1" :max="1" :step="0.1" :show-value="true" @change="onResolutionChange"></slider>
</view> </view>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
</template> </template>
<script> <script>
import { ItemType } from '@/components/enum-data/enum-data-types'; import { ItemType } from '@/components/enum-data/enum-data-types';
export default { export default {
data() { data() {
return { return {
title: "compressVideo", title: "compressVideo",
beforeCompressVideoInfo: "", beforeCompressVideoInfo: "",
afterCompressVideoInfo: "", afterCompressVideoInfo: "",
beforeCompressPath: "", beforeCompressPath: "",
afterCompressPath: "", afterCompressPath: "",
quality: null as string | null, quality: null as string | null,
bitrate: null as number | null, bitrate: null as number | null,
fps: null as number | null, fps: null as number | null,
resolution: null as number | null, resolution: null as number | null,
qualityItemTypes: [{ "value": 0, "name": "low(低)" }, { "value": 1, "name": "medium(中)" }, { "value": 2, "name": "high(高)" }] as ItemType[], qualityItemTypes: [{ "value": 0, "name": "low(低)" }, { "value": 1, "name": "medium(中)" }, { "value": 2, "name": "high(高)" }] as ItemType[],
qualityItems: ["low", "medium", "high"], qualityItems: ["low", "medium", "high"],
// 自动化测试 // 自动化测试
videoInfoForTest: null, videoInfoForTest: null,
videoSrcForTest: '/static/test-video/10second-demo.mp4' videoSrcForTest: '/static/test-video/10second-demo.mp4'
} }
}, },
methods: { methods: {
compressVideo() { compressVideo() {
if (this.beforeCompressPath == "") { if (this.beforeCompressPath == "") {
uni.showToast({ uni.showToast({
title: "请先选择视频", title: "请先选择视频",
icon: "error" icon: "error"
}); });
return; return;
} }
uni.showLoading({ uni.showLoading({
title: "视频压缩中" title: "视频压缩中"
}); });
uni.compressVideo({ uni.compressVideo({
src: this.beforeCompressPath, src: this.beforeCompressPath,
quality: this.quality, quality: this.quality,
resolution: this.resolution, resolution: this.resolution,
success: (res) => { success: (res) => {
console.log("compressVideo success", JSON.stringify(res)); console.log("compressVideo success", JSON.stringify(res));
this.afterCompressPath = res.tempFilePath; this.afterCompressPath = res.tempFilePath;
uni.showToast({ uni.showToast({
title: "压缩成功", title: "压缩成功",
icon: null icon: null
}); });
uni.getVideoInfo({ uni.getVideoInfo({
src: res.tempFilePath, src: res.tempFilePath,
success: (_res) => { success: (_res) => {
this.afterCompressVideoInfo = `视频画面方向: ${_res.orientation}\n视频格式: ${_res.type}\n视频长度: ${_res.duration}s\n视频大小: ${_res.size}KB\n视频宽度: ${_res.width}\n视频高度: ${_res.height}\n视频帧率: ${_res.fps}fps\n视频码率: ${_res.bitrate}kbps`; this.afterCompressVideoInfo = `视频画面方向: ${_res.orientation}\n视频格式: ${_res.type}\n视频长度: ${_res.duration}s\n视频大小: ${_res.size}KB\n视频宽度: ${_res.width}\n视频高度: ${_res.height}\n视频帧率: ${_res.fps}fps\n视频码率: ${_res.bitrate}kbps`;
} }
}); });
}, },
fail: (err) => { fail: (err) => {
uni.showModal({ uni.showModal({
title: "压缩视频失败", title: "压缩视频失败",
content: JSON.stringify(err), content: JSON.stringify(err),
showCancel: false showCancel: false
}); });
}, },
complete: (_) => { complete: (_) => {
uni.hideLoading(); uni.hideLoading();
} }
}); });
}, },
chooseVideo() { chooseVideo() {
uni.chooseVideo({ uni.chooseVideo({
sourceType: ["album"], sourceType: ["album"],
compressed: false, compressed: false,
success: (res) => { success: (res) => {
this.beforeCompressPath = res.tempFilePath; this.beforeCompressPath = res.tempFilePath;
uni.getVideoInfo({ uni.getVideoInfo({
src: res.tempFilePath, src: res.tempFilePath,
success: (_res) => { success: (_res) => {
this.beforeCompressVideoInfo = `视频画面方向: ${_res.orientation}\n视频格式: ${_res.type}\n视频长度: ${_res.duration}s\n视频大小: ${_res.size}KB\n视频宽度: ${_res.width}\n视频高度: ${_res.height}\n视频帧率: ${_res.fps}fps\n视频码率: ${_res.bitrate}kbps`; this.beforeCompressVideoInfo = `视频画面方向: ${_res.orientation}\n视频格式: ${_res.type}\n视频长度: ${_res.duration}s\n视频大小: ${_res.size}KB\n视频宽度: ${_res.width}\n视频高度: ${_res.height}\n视频帧率: ${_res.fps}fps\n视频码率: ${_res.bitrate}kbps`;
} }
}); });
} }
}); });
}, },
onQualityChange(value : number) { onQualityChange(value : number) {
this.quality = this.qualityItems[value]; this.quality = this.qualityItems[value];
}, },
onResolutionChange(event : UniSliderChangeEvent) { onResolutionChange(event : UniSliderChangeEvent) {
this.resolution = event.detail.value; this.resolution = event.detail.value;
}, },
testCompressVideo() { testCompressVideo() {
let beforeCompressSize : number, afterComoressSize : number; let beforeCompressSize : number, afterComoressSize : number;
uni.compressVideo({ uni.compressVideo({
src: this.videoSrcForTest, src: this.videoSrcForTest,
quality: 'medium', quality: 'medium',
success: (res) => { success: (res) => {
uni.getVideoInfo({ uni.getVideoInfo({
src: this.videoSrcForTest, src: this.videoSrcForTest,
success: (_res) => { success: (_res) => {
beforeCompressSize = Math.trunc(_res.size); beforeCompressSize = Math.trunc(_res.size);
uni.getVideoInfo({ uni.getVideoInfo({
src: res.tempFilePath, src: res.tempFilePath,
success: (__res) => { success: (__res) => {
afterComoressSize = Math.trunc(__res.size); afterComoressSize = Math.trunc(__res.size);
this.videoInfoForTest = { this.videoInfoForTest = {
"width": __res.width, "width": __res.width,
"height": __res.height, "height": __res.height,
"isSizeReduce": afterComoressSize < beforeCompressSize "isSizeReduce": afterComoressSize < beforeCompressSize
}; };
} }
}); });
} }
}); });
}, },
fail: (_) => { fail: (_) => {
this.videoInfoForTest = null; this.videoInfoForTest = null;
} }
}); });
} }
} }
} }
</script> </script>
<style> <style>
.video { .video {
align-self: center; align-self: center;
} }
.image-container { .image-container {
flex-direction: row; flex-direction: row;
} }
</style> </style>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<text class="uni-text-box uni-common-mt">当前音频播放位置(保留小数点后 6 位):{{currentTime}} s</text> <text class="uni-text-box uni-common-mt">当前音频播放位置(保留小数点后 6 位):{{currentTime}} s</text>
<text class="uni-text-box">音频的长度(单位:s):{{duration}} s</text> <text class="uni-text-box">音频的长度(单位:s):{{duration}} s</text>
<text class="uni-text-box">当前是否停止状态:{{isPaused}}</text> <text class="uni-text-box">当前是否停止状态:{{isPaused}}</text>
<text class="uni-text-box">音频缓冲的时间点:{{buffered}}</text> <text class="uni-text-box">音频缓冲的时间点:{{buffered}} s</text>
<text class="uni-text-box">当前音量:{{volume}}</text> <text class="uni-text-box">当前音量:{{volume}}</text>
<!-- 设置音量无效 --> <!-- 设置音量无效 -->
<button plain :disabled="volume == 1" @click="increaseVolume">增加音量</button> <button plain :disabled="volume == 1" @click="increaseVolume">增加音量</button>
...@@ -116,7 +116,16 @@ ...@@ -116,7 +116,16 @@
this.onTimeUpdateCb = (res : any) => { this.onTimeUpdateCb = (res : any) => {
if (this._isChanging) { return; } if (this._isChanging) { return; }
this.currentTime = this._audioContext!.currentTime; this.currentTime = this._audioContext!.currentTime;
this.buffered = this._audioContext!.buffered;
console.log('onTimeUpdateCb', this.currentTime) console.log('onTimeUpdateCb', this.currentTime)
// #ifdef MP
// 微信小程序安卓端过早的时机获取的buffered、duration为0,改为在此处获取
if(this._audioContext!.duration === 0) {
this.buffered = this._audioContext!.buffered;
this.duration = this._audioContext!.duration
}
// #endif
if (this.currentTime > this.buffered) { if (this.currentTime > this.buffered) {
console.log('缓冲不足'); console.log('缓冲不足');
} }
...@@ -145,6 +154,10 @@ ...@@ -145,6 +154,10 @@
this._audioContext!.onCanplay(() => { this._audioContext!.onCanplay(() => {
console.log('音频进入可以播放状态事件'); console.log('音频进入可以播放状态事件');
this.isCanplay = true; this.isCanplay = true;
// #ifdef MP
// 微信小程序安卓端过早的时机获取的volume为undefine,改为在此处获取
this.volume = this._audioContext!.volume;
// #endif
// 当音频可以播放时,获取缓冲信息 // 当音频可以播放时,获取缓冲信息
this.buffered = this._audioContext!.buffered; this.buffered = this._audioContext!.buffered;
this.duration = this._audioContext!.duration this.duration = this._audioContext!.duration
...@@ -250,21 +263,21 @@ ...@@ -250,21 +263,21 @@
}); });
}, },
pause() { pause() {
this._audioContext!.pause();
this._audioContext!.onPause(() => { this._audioContext!.onPause(() => {
console.log('音频暂停事件'); console.log('音频暂停事件');
this.isPaused = true; this.isPaused = true;
}); });
this._audioContext!.pause();
this.isPlaying = false; this.isPlaying = false;
}, },
stop() { stop() {
console.log('stop'); console.log('stop');
this._audioContext!.stop();
this._audioContext!.onStop(() => { this._audioContext!.onStop(() => {
// 第一次点停止时,不触发 // 第一次点停止时,不触发
this.isPaused = true; this.isPaused = true;
console.log('音频停止事件'); console.log('音频停止事件');
}); });
this._audioContext!.stop();
this.isPlaying = false; this.isPlaying = false;
console.log('stop', this.isPaused); console.log('stop', this.isPaused);
}, },
......
<template> <template>
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex: 1;"> <scroll-view style="flex: 1;">
<!-- #endif --> <!-- #endif -->
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view class="formats" v-for="(item,index) in supportFormats" :key="index"> <view class="formats" v-for="(item,index) in supportFormats" :key="index">
<text class="uni-subtitle-text">{{item.format}}</text> <text class="uni-subtitle-text">{{item.format}}</text>
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'" <image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
@click="play(item.src,index)"></image> @click="play(item.src,index)"></image>
</view> </view>
<view class="formats" v-for="(item,index) in notSupportFormats" :key="index"> <view class="formats" v-for="(item,index) in notSupportFormats" :key="index">
<text class="uni-subtitle-text">{{item.format}}(Android/web 不支持)</text> <text class="uni-subtitle-text">{{ item.format + (item.support) }}</text>
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'" <image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
@click="play(item.src,index)"></image> @click="play(item.src,index)"></image>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
</template> </template>
<script> <script>
type AudioFormat = { type AudioFormat = {
format : string format : string
src : string support: string | null
} src : string
export default { }
data() { export default {
return { data() {
title: 'audio-format', return {
playIndex: 0, title: 'audio-format',
isPlaying: false, playIndex: 0,
_audioContext: null as InnerAudioContext | null, isPlaying: false,
supportFormats: [ _audioContext: null as InnerAudioContext | null,
{ supportFormats: [
format: 'mp3', {
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp3' format: 'mp3',
}, src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp3'
{ },
format: 'mp4', {
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp4' format: 'mp4',
}, src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp4'
{ },
format: 'm4a', {
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.m4a' format: 'm4a',
}, src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.m4a'
{ },
format: 'aac', {
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.aac' format: 'aac',
}, src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.aac'
{ },
format: 'flac', {
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.flac' format: 'flac',
}, src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.flac'
},
{ {
format: 'ogg', format: 'wav',
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.ogg' src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.wav'
}, },
{ ] as Array<AudioFormat>,
format: 'wav', notSupportFormats: [
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.wav' {
}, format: 'ogg',
] as Array<AudioFormat>, support: '(iOS 不支持)',
notSupportFormats: [ src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.ogg'
{ },
format: 'wma', {
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.wma' format: 'wma',
}, support: '(iOS/Android/web 不支持)',
{ src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.wma'
format: 'aiff', },
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.aiff' {
}, format: 'aiff',
{ support: '(Android/web 不支持)',
format: 'caf', src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.aiff'
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.caf' },
}, {
{ format: 'caf',
format: '错误格式', support: '(Android/web 不支持)',
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.wmaa' src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.caf'
}, },
] as Array<AudioFormat> {
} format: '错误格式',
}, support: '(iOS/Android/web 不支持)',
onReady() { src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.wmaa'
this._audioContext = uni.createInnerAudioContext(); },
this._audioContext!.onPlay(() => { ] as Array<AudioFormat>
console.log('开始播放'); }
}); },
this._audioContext!.onPause(()=>{ onReady() {
console.log('播放暂停'); this._audioContext = uni.createInnerAudioContext();
}) this._audioContext!.onPlay(() => {
this._audioContext!.onEnded(() => { console.log('开始播放');
console.log('播放结束'); });
this.isPlaying = false; this._audioContext!.onPause(() => {
}); console.log('播放暂停');
this._audioContext!.onError((err) => { })
this.isPlaying = false; this._audioContext!.onEnded(() => {
console.log('err', err); console.log('播放结束');
}); this.isPlaying = false;
}, });
onUnload() { this._audioContext!.onError((err) => {
if (this._audioContext != null) { this.isPlaying = false;
this.pause(); console.log('err', err);
this._audioContext!.destroy() });
} },
}, onUnload() {
methods: { if (this._audioContext != null) {
pause() { this.pause();
this._audioContext!.pause(); this._audioContext!.destroy()
this.isPlaying = false; }
}, },
play(audioUrl : string, index : number) { methods: {
// console.log(index,audioUrl); pause() {
if (this.isPlaying && this.playIndex == index) { this._audioContext!.pause();
this.pause(); this.isPlaying = false;
return; },
} play(audioUrl : string, index : number) {
this.playIndex = index // console.log(index,audioUrl);
this._audioContext!.src = audioUrl; if (this.isPlaying && this.playIndex == index) {
this._audioContext!.play(); this.pause();
this.isPlaying = true; return;
}, }
}, this.playIndex = index
} this._audioContext!.src = audioUrl;
</script> this._audioContext!.play();
this.isPlaying = true;
<style> },
.formats { },
align-items: center; }
} </script>
.icon-play { <style>
width: 60px; .formats {
height: 60px; align-items: center;
margin: 10px; }
}
.icon-play {
width: 60px;
height: 60px;
margin: 10px;
}
</style> </style>
<template> <template>
<!-- #ifdef APP --> <page-head :title="title"></page-head>
<scroll-view style="flex: 1;"> <view class="uni-padding-wrap uni-common-mt">
<!-- #endif -->
<view class="uni-title"> <view class="uni-title">
<text class="uni-title-text">音频路径示例</text> <text class="uni-title-text">音频路径示例</text>
</view> </view>
...@@ -10,9 +9,7 @@ ...@@ -10,9 +9,7 @@
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'" <image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
@click="play(item.src,index)"></image> @click="play(item.src,index)"></image>
</view> </view>
<!-- #ifdef APP --> </view>
</scroll-view>
<!-- #endif -->
</template> </template>
<script> <script>
...@@ -23,14 +20,11 @@ ...@@ -23,14 +20,11 @@
export default { export default {
data() { data() {
return { return {
title: 'audio-path',
playIndex: 0, playIndex: 0,
isPlaying: false, isPlaying: false,
// #ifdef APP
nativePath: uni.env.CACHE_PATH + 'uni-audio/test/test.mp3' as string, nativePath: uni.env.CACHE_PATH + 'uni-audio/test/test.mp3' as string,
// #endif
// #ifdef APP-ANDROID
sdcardPath: 'sdcard/uni-audio/test.mp3', sdcardPath: 'sdcard/uni-audio/test.mp3',
// #endif
_audioContext: null as InnerAudioContext | null, _audioContext: null as InnerAudioContext | null,
supportPaths: [ supportPaths: [
{ {
...@@ -41,12 +35,10 @@ ...@@ -41,12 +35,10 @@
description: '本地路径:../static/', description: '本地路径:../static/',
src: '../../../static/test-audio/ForElise.mp3' src: '../../../static/test-audio/ForElise.mp3'
}, },
// #ifdef APP
{ {
description: '本地路径:env方式', description: '本地路径:env方式',
src: 'env' src: 'env'
}, },
// #endif
{ {
description: '网络路径', description: '网络路径',
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp3' src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp3'
...@@ -76,24 +68,36 @@ ...@@ -76,24 +68,36 @@
console.log('err', err); console.log('err', err);
}); });
// #ifdef APP
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
try { fileManager.mkdir({
fileManager.rmdirSync(uni.env.CACHE_PATH + 'uni-audio/test', true) dirPath: uni.env.CACHE_PATH + 'uni-audio/test',
} catch (e) { recursive: true,
} success: (res) => {
fileManager.copyFile({
try { srcPath: '/static/test-audio/ForElise.mp3',
fileManager.mkdirSync(uni.env.CACHE_PATH + 'uni-audio/test', true) destPath: this.nativePath,
} catch (e) { success: () => {
} console.log("copy成功: ", res)
try { }
fileManager.copyFileSync( })
'/static/test-audio/ForElise.mp3', },
this.nativePath) fail: (err) => {
} catch (e) { console.log("创建路径失败: ", err.errMsg)
} if (err.errMsg.includes("file already exists")) {
// #endif console.log("已经包含该路径")
fileManager.copyFile({
srcPath: '/static/test-audio/ForElise.mp3',
destPath: this.nativePath,
success: (res) => {
console.log("copy成功: ", res)
},
fail: (err) => {
console.log("copy失败: ", err)
}
})
}
}
})
}, },
onUnload() { onUnload() {
...@@ -113,11 +117,9 @@ ...@@ -113,11 +117,9 @@
this.pause(); this.pause();
return; return;
} }
// #ifdef APP
if (audioUrl == 'env') { if (audioUrl == 'env') {
audioUrl = this.nativePath audioUrl = this.nativePath
} }
// #endif
this.playIndex = index this.playIndex = index
this._audioContext!.src = audioUrl; this._audioContext!.src = audioUrl;
...@@ -138,4 +140,4 @@ ...@@ -138,4 +140,4 @@
height: 60px; height: 60px;
margin: 10px; margin: 10px;
} }
</style> </style>
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
onReady() { onReady() {
this.loadAd() this.loadAd()
}, },
onHide() {
console.log("Page Hide");
},
methods: { methods: {
loadAd() { loadAd() {
if (this.btnDisable) if (this.btnDisable)
......
const PAGE_PATH = '/pages/API/create-selector-query/create-selector-query-onScroll'
describe('create-selector-query-onScroll', () => {
// 先屏蔽 web 平台
if (
process.env.uniTestPlatformInfo.startsWith('web') ||
process.env.uniTestPlatformInfo.startsWith('mp')
) {
it('other platform', () => {
expect(1).toBe(1)
})
return
}
if (process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
it('跳过横屏模式', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500);
})
it('test-createSelectorQuery-onScroll', async () => {
let x = 100
let y = 250
// 滑动事件
await program.swipe({
startPoint: {x: x, y: y},
endPoint: {x: x,y: y-100},
duration: 300
})
await page.waitFor(600);
const ret = await page.data('ret')
expect(ret).toBe(true)
})
})
<template>
<scroll-view @scroll="onScroll" style="flex: 1;">
<view v-for="i in 60" class="content-item">
<text class="text">item-{{i}}</text>
</view>
</scroll-view>
</template>
<script>
export default {
data() {
return {
count: 0,
ret: true
}
},
onLoad() {
},
methods: {
onScroll() {
this.count++
console.log("scroll: ", this.count)
uni.createSelectorQuery()
.in(this)
.selectAll('content-item')
.boundingClientRect()
.exec((result) => {
this.count--
})
console.log("scroll: ", this.count)
if (this.count > 0) {
this.ret = false
}
}
}
}
</script>
<style>
</style>
...@@ -4,7 +4,9 @@ const RECT_LEFT = 15; ...@@ -4,7 +4,9 @@ const RECT_LEFT = 15;
const RECT_WIDTH = 150; const RECT_WIDTH = 150;
const RECT_HEIGHT = 100; const RECT_HEIGHT = 100;
describe('nodes-info', () => { describe('nodes-info', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
let page let page
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
...@@ -53,19 +55,16 @@ describe('nodes-info', () => { ...@@ -53,19 +55,16 @@ describe('nodes-info', () => {
expect(nodeInfo2.top > 220).toBe(true) expect(nodeInfo2.top > 220).toBe(true)
expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH) expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH)
expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT) expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT)
})
it('get-node-info-child', async () => {
const child = await page.$('.node-child')
const childData = await child.data()
console.log('get-node-info-child.childData.top', childData.top);
expect(childData.top > 100).toBe(true)
}) })
if(!isMP) {
it('multi-child', async () => { // 小程序端启用了虚拟host,无法获取到子组件
const pageData = await page.data() it('get-node-info-child', async () => {
expect(pageData.selectCount).toBe(1) const child = await page.$('.node-child')
expect(pageData.selectAllCount).toBe(2) const childData = await child.data()
}) console.log('get-node-info-child.childData.top', childData.top);
expect(childData.top > 100).toBe(true)
})
}
it('multi-child', async () => { it('multi-child', async () => {
const pageData = await page.data() const pageData = await page.data()
...@@ -82,7 +81,10 @@ describe('nodes-info', () => { ...@@ -82,7 +81,10 @@ describe('nodes-info', () => {
// #endif // #endif
it('test filelds', async () => { it('test filelds', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { if (
process.env.uniTestPlatformInfo.startsWith('web') ||
process.env.uniTestPlatformInfo.startsWith('mp')
) {
expect(true).toBe(true) expect(true).toBe(true)
} else { } else {
const pageData = await page.data() const pageData = await page.data()
...@@ -91,7 +93,10 @@ describe('nodes-info', () => { ...@@ -91,7 +93,10 @@ describe('nodes-info', () => {
}) })
it('test node', async () => { it('test node', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { if (
process.env.uniTestPlatformInfo.startsWith('web') ||
process.env.uniTestPlatformInfo.startsWith('mp')
) {
expect(true).toBe(true) expect(true).toBe(true)
} else { } else {
const pageData = await page.data() const pageData = await page.data()
......
<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view class="page-scroll-view"> <scroll-view class="page-scroll-view">
<!-- #endif --> <!-- #endif -->
<view class="page" id="page"> <view class="page" id="page">
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<button class="btn btn-get-node-info" @click="getNodeInfo">getNodeInfo</button> <button class="btn btn-get-node-info" @click="getNodeInfo">getNodeInfo</button>
<button class="btn btn-get-all-node-info" @click="getAllNodeInfo">getAllNodeInfo</button> <button class="btn btn-get-all-node-info" @click="getAllNodeInfo">getAllNodeInfo</button>
<view id="rect-1-2" class="rect-1-2"> <view id="rect-1-2" class="rect-1-2">
<view class="rect rect1"></view> <view class="rect rect1"></view>
<view class="rect rect2"></view> <view class="rect rect2"></view>
</view> </view>
<view class="rect-info-1-2"> <view class="rect-info-1-2">
<view class="rect-info" v-for="(nodeInfo, index) in nodeInfoList" :key="index"> <view class="rect-info" v-for="(nodeInfo, index) in nodeInfoList" :key="index">
<view class="node-info-item"> <view class="node-info-item">
<text class="node-info-item-k">left: </text> <text class="node-info-item-k">left: </text>
<text class="node-info-item-v">{{nodeInfo.left}}</text> <text class="node-info-item-v">{{nodeInfo.left}}</text>
</view> </view>
<view class="node-info-item"> <view class="node-info-item">
<text class="node-info-item-k">top: </text> <text class="node-info-item-k">top: </text>
<text class="node-info-item-v">{{nodeInfo.top}}</text> <text class="node-info-item-v">{{nodeInfo.top}}</text>
</view> </view>
<view class="node-info-item"> <view class="node-info-item">
<text class="node-info-item-k">right: </text> <text class="node-info-item-k">right: </text>
<text class="node-info-item-v">{{nodeInfo.right}}</text> <text class="node-info-item-v">{{nodeInfo.right}}</text>
</view> </view>
<view class="node-info-item"> <view class="node-info-item">
<text class="node-info-item-k">bottom: </text> <text class="node-info-item-k">bottom: </text>
<text class="node-info-item-v">{{nodeInfo.bottom}}</text> <text class="node-info-item-v">{{nodeInfo.bottom}}</text>
</view> </view>
<view class="node-info-item"> <view class="node-info-item">
<text class="node-info-item-k">width: </text> <text class="node-info-item-k">width: </text>
<text class="node-info-item-v">{{nodeInfo.width}}</text> <text class="node-info-item-v">{{nodeInfo.width}}</text>
</view> </view>
<view class="node-info-item"> <view class="node-info-item">
<text class="node-info-item-k">height: </text> <text class="node-info-item-k">height: </text>
<text class="node-info-item-v">{{nodeInfo.height}}</text> <text class="node-info-item-v">{{nodeInfo.height}}</text>
</view> </view>
</view> </view>
</view> </view>
<node-child class="node-child"></node-child> <node-child class="node-child"></node-child>
<text>子组件多根节点</text> <text>子组件多根节点</text>
<multi-child ref="multi-child" id="multi-child"></multi-child> <multi-child ref="multi-child" id="multi-child"></multi-child>
<text>子组件多根节点(仅测试,用于验证查询是否超出范围)</text> <text>子组件多根节点(仅测试,用于验证查询是否超出范围)</text>
<multi-child id="multi-child-2"></multi-child> <multi-child id="multi-child-2"></multi-child>
<view> <view>
<text>测试.fields</text> <text>测试.fields</text>
<text>{{fieldsResultContainNode}}</text> <text>{{fieldsResultContainNode}}</text>
</view> </view>
<view> <view>
<text>测试.node</text> <text>测试.node</text>
<text>{{nodeResultContainNode}}</text> <text>{{nodeResultContainNode}}</text>
</view> </view>
<canvas id="canvas1"></canvas> <canvas id="canvas1"></canvas>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
</template> </template>
<script> <script>
import nodeChild from './nodes-info-child.uvue' import nodeChild from './nodes-info-child.uvue'
import multiChild from './selector-query-child-multi.uvue' import multiChild from './selector-query-child-multi.uvue'
type NodeInfoType = { type NodeInfoType = {
left : number | null, left : number | null,
top : number | null, top : number | null,
right : number | null, right : number | null,
bottom : number | null, bottom : number | null,
width : number | null, width : number | null,
height : number | null, height : number | null,
} }
export default { export default {
components: { components: {
nodeChild, nodeChild,
multiChild multiChild
},
data() {
return {
title: 'createSelectorQuery',
nodeInfoList: [] as NodeInfoType[],
// 仅用于自动化测试
rootNodeInfo: null as NodeInfoType | null,
//供自动化测试使用
// resizeRectValid: false
// TODO
selectCount: 0,
selectAllCount: 0,
fieldsResultContainNode: false,
nodeResultContainNode: false
}
}, },
data() { onLoad() {
return { uni.$on('childReady', this.onChildReady)
title: 'createSelectorQuery',
nodeInfoList: [] as NodeInfoType[],
// 仅用于自动化测试
rootNodeInfo: null as NodeInfoType | null,
//供自动化测试使用
// resizeRectValid: false
// TODO
selectCount: 0,
selectAllCount: 0,
fieldsResultContainNode: false,
nodeResultContainNode: false
}
}, },
onUnload() {
uni.$off('childReady', this.onChildReady)
},
onReady() { onReady() {
const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance)
this.selectCount = instance2.$data['selectCount'] as number
this.selectAllCount = instance2.$data['selectAllCount'] as number
this.testFields() this.testFields()
this.testNode() this.testNode()
}, },
onResize() { onResize() {
//供自动化测试使用 //供自动化测试使用
/* var rect12Element = uni.getElementById("rect-1-2") /* var rect12Element = uni.getElementById("rect-1-2")
if(rect12Element != null) { if(rect12Element != null) {
var domRect = rect12Element.getBoundingClientRect() var domRect = rect12Element.getBoundingClientRect()
if(domRect.width > 100) { if(domRect.width > 100) {
this.resizeRectValid = true this.resizeRectValid = true
} }
} */ } */
}, },
methods: { methods: {
// 仅用于自动化测试 // 仅用于自动化测试
getRootNodeInfo(selector : string) { onChildReady() {
uni.createSelectorQuery().select(selector).boundingClientRect().exec((ret) => { const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance);
if (ret.length == 1) { this.selectCount = instance2.$data['selectCount'] as number;
const nodeInfo = ret[0] as NodeInfo; this.selectAllCount = instance2.$data['selectAllCount'] as number;
const nodeType = { },
left: nodeInfo.left, // 仅用于自动化测试
top: nodeInfo.top, getRootNodeInfo(selector : string) {
right: nodeInfo.right, uni.createSelectorQuery().select(selector).boundingClientRect().exec((ret) => {
bottom: nodeInfo.bottom, if (ret.length == 1) {
width: nodeInfo.width, const nodeInfo = ret[0] as NodeInfo;
height: nodeInfo.height, const nodeType = {
} as NodeInfoType; left: nodeInfo.left,
this.rootNodeInfo = nodeType top: nodeInfo.top,
} right: nodeInfo.right,
}) bottom: nodeInfo.bottom,
}, width: nodeInfo.width,
getNodeInfo() { height: nodeInfo.height,
uni.createSelectorQuery().select('.rect1').boundingClientRect().exec((ret) => { } as NodeInfoType;
this.nodeInfoList.length = 0 this.rootNodeInfo = nodeType
const i = ret[0] as NodeInfo }
this.nodeInfoList.push({ })
left: i.left, },
top: i.top, getNodeInfo() {
right: i.right, uni.createSelectorQuery().select('.rect1').boundingClientRect().exec((ret) => {
bottom: i.bottom, this.nodeInfoList.length = 0
width: i.width, const i = ret[0] as NodeInfo
height: i.height, this.nodeInfoList.push({
} as NodeInfoType) left: i.left,
}) top: i.top,
}, right: i.right,
getAllNodeInfo() { bottom: i.bottom,
uni.createSelectorQuery().selectAll('.rect').boundingClientRect().exec((ret) => { width: i.width,
this.nodeInfoList.length = 0 height: i.height,
const array = ret[0] as NodeInfo[] } as NodeInfoType)
array.forEach((i) => { })
this.nodeInfoList.push({ },
left: i.left, getAllNodeInfo() {
top: i.top, uni.createSelectorQuery().selectAll('.rect').boundingClientRect().exec((ret) => {
right: i.right, this.nodeInfoList.length = 0
bottom: i.bottom, const array = ret[0] as NodeInfo[]
width: i.width, array.forEach((i) => {
height: i.height, this.nodeInfoList.push({
} as NodeInfoType) left: i.left,
}) top: i.top,
}) right: i.right,
}, bottom: i.bottom,
// test .fields width: i.width,
testFields() { height: i.height,
uni.createSelectorQuery().select('.rect1').fields({ } as NodeInfoType)
node: true })
} as NodeField, (ret) => { })
const isElement = (ret as NodeInfo).node instanceof UniElement },
if (isElement) { // test .fields
this.fieldsResultContainNode = true testFields() {
} else { uni.createSelectorQuery().select('.rect1').fields({
this.fieldsResultContainNode = false node: true
} } as NodeField, (ret) => {
}).exec() const isElement = (ret as NodeInfo).node instanceof UniElement
}, if (isElement) {
// test .node this.fieldsResultContainNode = true
testNode() { } else {
uni.createSelectorQuery().select('#canvas1').node((ret) => { this.fieldsResultContainNode = false
const isElement = (ret as NodeInfo).node instanceof UniElement }
const isCanvasElement = ((ret as NodeInfo).node as UniCanvasElement).tagName == 'CANVAS' }).exec()
if (isElement && isCanvasElement) { },
this.nodeResultContainNode = true // test .node
} else { testNode() {
this.nodeResultContainNode = false uni.createSelectorQuery().select('#canvas1').node((ret) => {
} const isElement = (ret as NodeInfo).node instanceof UniElement
}).exec() const isCanvasElement = ((ret as NodeInfo).node as UniCanvasElement).tagName == 'CANVAS'
}, if (isElement && isCanvasElement) {
} this.nodeResultContainNode = true
} } else {
</script> this.nodeResultContainNode = false
}
<style> }).exec()
.page { },
padding: 15px; }
} }
</script>
.btn {
margin-top: 15px; <style>
} .page {
padding: 15px;
.rect-1-2 { }
flex-direction: row;
margin-top: 15px; .btn {
} margin-top: 15px;
}
.rect {
width: 150px; .rect-1-2 {
height: 100px; flex-direction: row;
} margin-top: 15px;
}
.rect1 {
background-color: dodgerblue; .rect {
} width: 150px;
height: 100px;
.rect2 { }
margin-left: auto;
background-color: seagreen; .rect1 {
} background-color: dodgerblue;
}
.rect-info-1-2 {
flex-direction: row; .rect2 {
margin-top: 15px; margin-left: auto;
} background-color: seagreen;
}
.rect-info {
flex: 1; .rect-info-1-2 {
flex-direction: column; flex-direction: row;
} margin-top: 15px;
}
.node-info-item {
flex-direction: row; .rect-info {
} flex: 1;
flex-direction: column;
.node-info-item-k { }
width: 72px;
line-height: 2; .node-info-item {
} flex-direction: row;
}
.node-info-item-v {
font-weight: bold; .node-info-item-k {
line-height: 2; width: 72px;
} line-height: 2;
}
.node-info-item-v {
font-weight: bold;
line-height: 2;
}
</style> </style>
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
viewCount: 0, viewCount: 0,
selectCount: 0, selectCount: 0,
selectAllCount: 0, selectAllCount: 0,
show: false show: false,
testCounter: 0
} }
}, },
mounted() { mounted() {
...@@ -29,14 +30,25 @@ ...@@ -29,14 +30,25 @@
this.text1 = JSON.stringify(ret, null, 2) this.text1 = JSON.stringify(ret, null, 2)
if (ret.length == 1) { if (ret.length == 1) {
this.selectCount = ret.length this.selectCount = ret.length
} }
this.testCounter++
this._dispatchEvent()
}) })
uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => { uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => {
this.text2 = JSON.stringify(ret, null, 2) this.text2 = JSON.stringify(ret, null, 2)
if (ret.length == 1) { if (ret.length == 1) {
this.selectAllCount = (ret[0] as NodeInfo[]).length this.selectAllCount = (ret[0] as NodeInfo[]).length
} }
this.testCounter++
this._dispatchEvent()
}) })
},
methods: {
_dispatchEvent() {
if (this.testCounter == 2) {
uni.$emit('childReady')
}
}
} }
} }
</script> </script>
......
<template> <template>
<view id="dialog1" class="dialog-container"> <view id="dialog1" class="dialog-container">
<view class="dialog-content"> <view class="dialog-content">
<text>title: {{title}}</text> <text>title: {{ title }}</text>
<text class="mt-10">onBackPress return true</text> <text class="mt-10">onBackPress return true</text>
<button class="mt-10" id="dialog1-go-next-page" @click="goNextPage">go next page</button> <button class="mt-10" id="dialog1-go-next-page" @click="goNextPage">
<button class="mt-10" id="dialog1-open-dialog2" @click="openDialog2">openDialog2</button> go next page
<button class="mt-10" id="dialog1-close-dialog" @click="closeDialog">closeDialog</button> </button>
<button class="mt-10" id="dialog1-close-this-dialog" @click="closeThisDialog">closeThisDialog</button> <button class="mt-10" id="dialog1-open-dialog2" @click="openDialog2">
openDialog2
</button>
<button class="mt-10" id="dialog1-close-dialog" @click="closeDialog">
closeDialog
</button>
<button class="mt-10" id="dialog1-close-this-dialog" @click="closeThisDialog">
closeThisDialog
</button>
<button class="mt-10" @click="checkGetParentPage">
check getParentPage
</button>
<button class="mt-10" @click="checkGetElementById">
check getElementById
</button>
<button class="mt-10" @click="toggleBackgroundColor">
toggleBackgroundColor
</button>
<button class="mt-10" id="dialog1-back" @click="back">back</button> <button class="mt-10" id="dialog1-back" @click="back">back</button>
<input class="uni-common-mt" style="border-width: 1px;border-style: solid;" :focus="true" value="DialogPage中焦点测试"/> <input class="uni-common-mt" style="border-width: 1px; border-style: solid" :focus="true"
value="DialogPage中焦点测试" />
</view> </view>
</view> </view>
</template> </template>
...@@ -23,6 +41,7 @@ ...@@ -23,6 +41,7 @@
data() { data() {
return { return {
title: 'dialog 1', title: 'dialog 1',
backgroundColorContent: 'transparent'
} }
}, },
onLoad(options : OnLoadOptions) { onLoad(options : OnLoadOptions) {
...@@ -137,6 +156,39 @@ ...@@ -137,6 +156,39 @@
} }
}) })
}, },
checkGetParentPage() : boolean {
const parentPage = this.$page.getParentPage()
console.log('checkGetParentPage', parentPage)
const res = parentPage != null
uni.showToast(res ? {
title: 'check success'
} : {
title: 'check fail',
icon: 'error'
})
return res
},
checkGetElementById() : boolean {
const page = this.$page
const element = page.getElementById('dialog1-go-next-page')
let res = element != null
// #ifndef APP-ANDROID
if (res) {
const elPage = element!.getPage()
console.log('elPage', elPage)
res = elPage === page
}
// #endif
console.log('check getElementById', res)
uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
return res
},
toggleBackgroundColor() {
this.backgroundColorContent = this.backgroundColorContent == 'transparent' ? 'rgb(0, 122, 255)' : 'transparent'
this.$page.setPageStyle({
backgroundColorContent: this.backgroundColorContent
})
},
back() { back() {
uni.navigateBack() uni.navigateBack()
} }
...@@ -164,4 +216,4 @@ ...@@ -164,4 +216,4 @@
.mt-10 { .mt-10 {
margin-top: 10px; margin-top: 10px;
} }
</style> </style>
<template>
<view id="dialog3" class="dialog-container">
<scroll-view class="dialog-content">
<text>title: {{ title }}</text>
<template v-for="(item, index) in PageStyleArray">
<view class="page-style-item" v-if="currentPageStyle[item.key] != null" :key="index">
<view class="item-text">
<text class="item-text-key">{{ item.key }}:</text>
<text class="item-text-value">{{
currentPageStyle[item.key]
}}</text>
</view>
<view class="mt-10" v-if="item.type == 'boolean'">
<switch :checked="currentPageStyle.getBoolean(item.key)"
@change="switchChange(item.key, $event as UniSwitchChangeEvent)">
</switch>
</view>
<view class="mt-10" v-else-if="item.type == 'number'">
<slider :value="currentPageStyle.getNumber(item.key)" :show-value="true"
@change="sliderChange(item.key, $event as UniSliderChangeEvent)" />
</view>
<view class="mt-10" v-else-if="item.type == 'string'">
<radio-group class="radio-set-value" @change="radioChange(item.key, $event as RadioGroupChangeEvent)">
<radio class="ml-10" v-for="(item2, index2) in item.value" :key="index2" :value="item2"
:checked="currentPageStyle[item.key] == item2">{{ item2 }}
</radio>
</radio-group>
</view>
</view>
</template>
<text class="mt-10 choose-close-animation-type-title">choose close dialogPage animationType</text>
<radio-group class="choose-close-animation-type-radio-group" @change="handleChooseAnimationType">
<radio class="ml-10 mt-10" v-for="item in closeAnimationTypeList" :key="item" :value="item"
:checked="closeAnimationType == item">{{ item }}
</radio>
</radio-group>
<button class="mt-10" @click="closeThisDialog">
closeThisDialog
</button>
</scroll-view>
</view>
</template>
<script>
import { PageStyleItem, PageStyleArray } from './page-style.uts';
type CloseAnimationType =
'auto' |
'none' |
'slide-out-right' |
'slide-out-left' |
'slide-out-top' |
'slide-out-bottom' |
'fade-out' |
'zoom-in' |
'zoom-fade-in'
export default {
data() {
return {
title: 'dialog 3',
PageStyleArray: PageStyleArray as PageStyleItem[],
currentPageStyle: {} as UTSJSONObject,
closeAnimationType: 'auto' as CloseAnimationType,
closeAnimationTypeList: [
'auto',
'none',
'slide-out-right',
'slide-out-left',
'slide-out-top',
'slide-out-bottom',
'fade-out',
'zoom-in',
'zoom-fade-in'
]
}
},
onLoad(_ : OnLoadOptions) {
this.getPageStyle()
},
methods: {
getPageStyle() {
this.currentPageStyle = this.$page.getPageStyle()
},
radioChange(key : string, e : RadioGroupChangeEvent) {
this.setStyleValue(key, e.detail.value);
},
sliderChange(key : string, e : UniSliderChangeEvent) {
this.setStyleValue(key, e.detail.value);
},
switchChange(key : string, e : UniSwitchChangeEvent) {
this.setStyleValue(key, e.detail.value);
},
setStyleValue(key : string, value : any) {
const style = {}
style[key] = value
this.setPageStyle(style)
this.getPageStyle()
},
setPageStyle(style : UTSJSONObject) {
this.$page.setPageStyle(style);
},
handleChooseAnimationType(e : RadioGroupChangeEvent){
this.closeAnimationType = e.detail.value as CloseAnimationType
},
closeThisDialog() {
uni.closeDialogPage({
dialogPage: this.$page,
animationType: this.closeAnimationType,
success(res) {
console.log('closeDialog success', res)
},
fail(err) {
console.log('closeDialog fail', err)
},
complete(res) {
console.log('closeDialog complete', res)
}
})
}
}
}
</script>
<style>
.dialog-container {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
display: flex;
justify-content: center;
align-items: center;
}
.dialog-content {
width: 90%;
height: 500px;
padding: 10px 6px;
background-color: #fff;
border-radius: 6px;
}
.mt-10 {
margin-top: 10px;
}
.ml-10 {
margin-left: 10px;
}
.page-style-item {
padding: 6px 0;
margin-top: 10px;
background-color: #ffffff;
border-radius: 5px;
}
.item-text {
flex-direction: row;
}
.item-text-key {
font-weight: bold;
}
.item-text-value {
margin-left: 5px;
}
.radio-set-value {
flex-direction: row;
}
.choose-close-animation-type-title{
font-weight: bold;
}
.choose-close-animation-type-radio-group{
flex-direction: row;
flex-wrap: wrap;
}
</style
<template>
<view class="dialog-container">
<view class="dialog-content">
<text>title: {{ title }}</text>
<button class="mt-10" @click="closeDialog">
closeDialog
</button>
<button class="mt-10" @click="closeThisDialog">
closeThisDialog
</button>
<button class="mt-10" @click="openDialog3">
open dialog 3
</button>
</view>
</view>
</template>
<script>
import {
state,
setLifeCycleNum
} from '@/store/index.uts'
export default {
data() {
return {
title: 'dialog 4'
}
},
onShow() {
console.log('dialog 4 onShow')
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
onUnload() {
console.log('dialog 4 onUnload')
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 5)
},
methods: {
closeDialog() {
uni.closeDialogPage({
success(res) {
console.log('closeDialog success', res)
},
fail(err) {
console.log('closeDialog fail', err)
},
complete(res) {
console.log('closeDialog complete', res)
}
})
},
closeThisDialog() {
uni.closeDialogPage({
dialogPage: this.$page,
success(res) {
console.log('closeThisDialog success', res)
},
fail(err) {
console.log('closeThisDialog fail', err)
},
complete(res) {
console.log('closeThisDialog complete', res)
}
})
},
openDialog3(){
uni.openDialogPage({url: '/pages/API/dialog-page/dialog-3'})
}
}
}
</script>
<style>
.dialog-container {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
display: flex;
justify-content: center;
align-items: center;
}
.dialog-content {
width: 80%;
padding: 10px;
background-color: #fff;
border-radius: 6px;
}
.mt-10 {
margin-top: 10px;
}
</style>
export type PageStyleItem = {
key : string
type : string
value : Array<any>
}
export const PageStyleArray = [
{
key: "navigationBarBackgroundColor",
type: "string",
value: ["#007AFF", "#FFFFFF", "#000000"]
},
{
key: "navigationBarTextStyle",
type: "string",
value: ["white", "black"]
},
{
key: "navigationBarTitleText",
type: "string",
value: ["dialogPage", "title2", "title3"]
},
{
key: "navigationStyle",
type: "string",
value: ["default", "custom"]
},
{
key: "backgroundColor",
type: "string",
value: ["#FFFFFF", "#000000"]
},
{
key: "backgroundColorContent",
type: "string",
value: ["#FFFFFF", "transparent", "#000000"]
},
{
key: "backgroundTextStyle",
type: "string",
value: ["dark", "light"]
},
{
key: "enablePullDownRefresh",
type: "boolean",
value: [true, false]
},
{
key: "onReachBottomDistance",
type: "number",
value: [50, 100]
},
{
key: "pageOrientation",
type: "string",
value: ["auto", "portrait", "landscape"]
},
{
key: "backgroundColorTop",
type: "string",
value: ["#FFFFFF", "#000000"]
},
{
key: "backgroundColorBottom",
type: "string",
value: ["#FFFFFF", "#000000"]
},
{
key: "navigationBarAutoBackButton",
type: "boolean",
value: [true, false]
},
{
key: "hideStatusBar",
type: "boolean",
value: [true, false]
},
{
key: "hideBottomNavigationIndicator",
type: "boolean",
value: [true, false]
}] as PageStyleItem[]
<template>
<view class="content">
<button @tap="doOpendDialogpage()">open dialogpage</button>
</view>
</template>
<script>
import { testOpenDialogPage, testCloseDialogPage } from '@/uni_modules/uts-dialogpage';
export default {
data() {
return {}
},
onLoad() {
},
methods: {
doOpendDialogpage() {
testOpenDialogPage("/pages/API/dialog-page/dialog-page")
}
}
}
</script>
<style>
.content {
flex: 1;
}
</style>
...@@ -3,36 +3,50 @@ const PAGE_PATH = '/pages/API/download-file/download-file' ...@@ -3,36 +3,50 @@ const PAGE_PATH = '/pages/API/download-file/download-file'
describe('ExtApi-DownloadFile', () => { describe('ExtApi-DownloadFile', () => {
let page; let page;
let res; let res;
let timeout = 3000
let waitForStartTime
async function waitCallbackTriggredOrTimeout(){
waitForStartTime = Date.now()
await page.waitFor(async () => {
const callbackTriggred = await page.data('jest_callback_triggred')
return callbackTriggred || (Date.now() - waitForStartTime > timeout)
})
}
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600); await page.waitFor('view');
await page.callMethod('jest_downloadFile'); await page.callMethod('jest_downloadFile');
await page.waitFor(2000); await waitCallbackTriggredOrTimeout()
res = await page.data('jest_result'); res = await page.data('jest_result');
}); });
beforeEach(async () => { beforeEach(async () => {
await page.setData({ await page.setData({
jest_result: false jest_result: false,
jest_callback_triggred: false
}) })
}); });
it('Check ', async () => { it('Check ', async () => {
expect(res).toBe(true); expect(res).toBe(true);
}); });
it('Check Special characters Url download file', async () => { it('Check Special characters Url download file', async () => {
res = await page.callMethod('jest_special_characters_download') res = await page.callMethod('jest_special_characters_download')
await page.waitFor(2000); await waitCallbackTriggredOrTimeout()
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
}); });
if (!process.env.uniTestPlatformInfo.startsWith('web')) { if (
!process.env.uniTestPlatformInfo.startsWith('web') &&
!process.env.uniTestPlatformInfo.startsWith('mp')
) {
it('Check uni.env', async () => { it('Check uni.env', async () => {
await page.callMethod('jest_downloadFile_with_uni_env'); await page.callMethod('jest_downloadFile_with_uni_env');
await page.waitFor(2000); await waitCallbackTriggredOrTimeout()
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true); expect(res).toBe(true);
}); });
...@@ -41,10 +55,10 @@ describe('ExtApi-DownloadFile', () => { ...@@ -41,10 +55,10 @@ describe('ExtApi-DownloadFile', () => {
let version = process.env.uniTestPlatformInfo let version = process.env.uniTestPlatformInfo
let split = version.split(" ") let split = version.split(" ")
version = parseInt(split[split.length - 1]) version = parseInt(split[split.length - 1])
if(!process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || version > 15) { if (!process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || version > 15) {
it('Check Download File In UTS Module', async () => { it('Check Download File In UTS Module', async () => {
res = await page.callMethod('jest_uts_module_invoked') res = await page.callMethod('jest_uts_module_invoked')
await page.waitFor(2000); await waitCallbackTriggredOrTimeout()
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
}) })
...@@ -67,13 +81,13 @@ describe('ExtApi-DownloadFile', () => { ...@@ -67,13 +81,13 @@ describe('ExtApi-DownloadFile', () => {
it('Check Set Cookie', async () => { it('Check Set Cookie', async () => {
res = await page.callMethod('jest_set_cookie') res = await page.callMethod('jest_set_cookie')
await page.waitFor(2000); await waitCallbackTriggredOrTimeout()
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
}); });
it('Check Delete Cookie', async () => { it('Check Delete Cookie', async () => {
res = await page.callMethod('jest_delete_cookie') res = await page.callMethod('jest_delete_cookie')
await page.waitFor(2000); await waitCallbackTriggredOrTimeout()
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
}); });
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册