提交 a912f940 编写于 作者: 杜庆泉's avatar 杜庆泉

Merge branch 'dev' of gitcode.net:dcloud/hello-uts into dev

<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view>
<button @click="testUtsSync">点击测试uts同步方法</button>
<view>测试return:
<view
>测试return:
{{ format(testUtsSyncResult) }}
</view>
<button @click="testUtsSyncWithCallback">
点击测试uts带callback的同步方法
</button>
<view>测试return:{{ format(testUtsSyncWithCallbackResult.return) }}</view>
<view>测试success:{{ format(testUtsSyncWithCallbackResult.success) }}</view>
<view>测试complete:{{ format(testUtsSyncWithCallbackResult.complete) }}</view>
<view
>测试return:{{ format(testUtsSyncWithCallbackResult.return) }}</view
>
<view
>测试success:{{ format(testUtsSyncWithCallbackResult.success) }}</view
>
<view
>测试complete:{{
format(testUtsSyncWithCallbackResult.complete)
}}</view
>
<!-- <button @click="testUtsAsync">点击测试uts异步方法</button>
<view>测试return:{{ format(testUtsAsyncResult.return) }}</view>
<view>测试success:{{ format(testUtsAsyncResult.success) }}</view>
<view>测试complete:{{ format(testUtsAsyncResult.complete) }}</view> -->
<button @click="testUtsClassConstructor">点击测试uts class构造函数</button>
<view>测试callback:{{ format(testUtsClassConstructorResult.callback) }}</view>
<button @click="testUtsClassConstructor">
点击测试uts class构造函数
</button>
<view
>测试callback:{{
format(testUtsClassConstructorResult.callback)
}}</view
>
<button @click="testUtsClassStaticProp">点击测试uts class静态属性</button>
<view>测试value:{{ format(testUtsClassStaticPropResult) }}</view>
<button @click="testUtsClassStaticSyncWithCallback">
点击测试uts class静态方法
</button>
<view>测试return:{{ format(testUtsClassStaticSyncWithCallbackResult.return) }}</view>
<view>测试success:{{ format(testUtsClassStaticSyncWithCallbackResult.success) }}</view>
<view>测试complete:{{ format(testUtsClassStaticSyncWithCallbackResult.complete) }}</view>
<view
>测试return:{{
format(testUtsClassStaticSyncWithCallbackResult.return)
}}</view
>
<view
>测试success:{{
format(testUtsClassStaticSyncWithCallbackResult.success)
}}</view
>
<view
>测试complete:{{
format(testUtsClassStaticSyncWithCallbackResult.complete)
}}</view
>
<!-- <button @click="testUtsClassStaticAsync">点击测试uts class静态异步方法</button>
<view>测试return:{{ format(testUtsClassStaticAsyncResult.return) }}</view>
<view>测试success:{{ format(testUtsClassStaticAsyncResult.success) }}</view>
......@@ -33,9 +63,21 @@
<button @click="testUtsClassSyncWithCallback">
点击测试uts class实例方法
</button>
<view>测试return:{{ format(testUtsClassSyncWithCallbackResult.return) }}</view>
<view>测试success:{{ format(testUtsClassSyncWithCallbackResult.success) }}</view>
<view>测试complete:{{ format(testUtsClassSyncWithCallbackResult.complete) }}</view>
<view
>测试return:{{
format(testUtsClassSyncWithCallbackResult.return)
}}</view
>
<view
>测试success:{{
format(testUtsClassSyncWithCallbackResult.success)
}}</view
>
<view
>测试complete:{{
format(testUtsClassSyncWithCallbackResult.complete)
}}</view
>
<!-- <button @click="testUtsClassAsync">点击测试uts class实例异步方法</button>
<view>测试return:{{ format(testUtsClassAsyncResult.return) }}</view>
<view>测试success:{{ format(testUtsClassAsyncResult.success) }}</view>
......@@ -44,13 +86,20 @@
<view>测试prop:{{ format(testUtsClassInstanceResult.prop) }}</view>
<view>测试return:{{ format(testUtsClassInstanceResult.return) }}</view>
<view>测试success:{{ format(testUtsClassInstanceResult.success) }}</view>
<view>测试complete:{{ format(testUtsClassInstanceResult.complete) }}</view>
<view>测试callback:{{ format(testUtsClassInstanceResult.callback) }}</view>
<view
>测试complete:{{ format(testUtsClassInstanceResult.complete) }}</view
>
<view
>测试callback:{{ format(testUtsClassInstanceResult.callback) }}</view
>
<button @click="testAll">点击测试所有</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script lang="ts">
import {
import {
MAX,
testSync,
testSyncWithCallback,
......@@ -59,26 +108,26 @@
request,
AsyncOptions,
TestOptions,
SyncOptions
} from "../../uni_modules/uts-syntaxcase";
SyncOptions,
} from '../../uni_modules/uts-syntaxcase'
const TRUE = 'true'
const FALSE = 'false'
const NULL = 'null'
const TRUE = 'true'
const FALSE = 'false'
const NULL = 'null'
let test: Test | null = null
let id = 0
let test: Test | null = null
let id = 0
type TestResult = {
return ?: string,
success ?: string,
fail ?: string,
complete ?: string,
callback?: string,
prop?: string,
}
type TestResult = {
return?: string
success?: string
fail?: string
complete?: string
callback?: string
prop?: string
}
export default {
export default {
data() {
return {
// 'null' | 'true' | 'false'
......@@ -96,7 +145,7 @@
complete: 'null',
} as TestResult,
testUtsClassConstructorResult: {
callback: 'null'
callback: 'null',
} as TestResult,
testUtsClassStaticPropResult: 'null',
testUtsClassStaticSyncWithCallbackResult: {
......@@ -130,64 +179,64 @@
success: 'null',
fail: 'null',
complete: 'null',
callback: 'null'
} as TestResult
callback: 'null',
} as TestResult,
}
},
methods: {
format(v: string | null) : string {
return v === "null" || v == null ? "--" : v === 'true' ? "通过" : "未通过";
format(v: string | null): string {
return v === 'null' || v == null ? '--' : v === 'true' ? '通过' : '未通过'
},
testAll() {
this.testUtsSync();
this.testUtsSyncWithCallback();
this.testUtsSync()
this.testUtsSyncWithCallback()
// this.testUtsAsync();
this.testUtsClassConstructor();
this.testUtsClassStaticProp();
this.testUtsClassStaticSyncWithCallback();
this.testUtsClassConstructor()
this.testUtsClassStaticProp()
this.testUtsClassStaticSyncWithCallback()
// this.testUtsClassStaticAsync();
this.testUtsClassProp();
this.testUtsClassSyncWithCallback();
this.testUtsClassProp()
this.testUtsClassSyncWithCallback()
// this.testUtsClassAsync();
this.testUtsClassInstance();
this.testUtsClassInstance()
},
testUtsSync() {
this.testUtsSyncResult = FALSE;
this.testUtsSyncResult = FALSE
try {
console.log('testSync("dcloud").msg', testSync("dcloud").msg)
if (testSync("dcloud").msg == "hello dcloud") {
this.testUtsSyncResult = TRUE;
console.log('testSync("dcloud").msg', testSync('dcloud').msg)
if (testSync('dcloud').msg == 'hello dcloud') {
this.testUtsSyncResult = TRUE
}
} catch (e) {
console.error("testUtsSync", e);
console.error('testUtsSync', e)
}
},
testUtsSyncWithCallback() {
try {
this.testUtsSyncWithCallbackResult.return = FALSE;
this.testUtsSyncWithCallbackResult.success = FALSE;
this.testUtsSyncWithCallbackResult.return = FALSE
this.testUtsSyncWithCallbackResult.success = FALSE
// testUtsSyncWithCallbackResult.fail = FALSE;
this.testUtsSyncWithCallbackResult.complete = FALSE;
this.testUtsSyncWithCallbackResult.complete = FALSE
if (
testSyncWithCallback({
type: "success",
type: 'success',
success: (res) => {
console.log("testSyncWithCallback.success.callback", res);
this.testUtsSyncWithCallbackResult.success = TRUE;
console.log('testSyncWithCallback.success.callback', res)
this.testUtsSyncWithCallbackResult.success = TRUE
},
fail: (res) => {
console.log("testSyncWithCallback.fail.callback", res);
console.log('testSyncWithCallback.fail.callback', res)
// testUtsSyncWithCallbackResult.fail = TRUE;
},
complete: (res) => {
console.log("testSyncWithCallback.complete.callback", res);
this.testUtsSyncWithCallbackResult.complete = TRUE;
console.log('testSyncWithCallback.complete.callback', res)
this.testUtsSyncWithCallbackResult.complete = TRUE
},
} as AsyncOptions).name === "testSyncWithCallback"
} as AsyncOptions).name === 'testSyncWithCallback'
) {
this.testUtsSyncWithCallbackResult.return = TRUE;
this.testUtsSyncWithCallbackResult.return = TRUE
}
} catch (e) { }
} catch (e) {}
},
// TODO uvue 暂不支持 async await
// async testUtsAsync() {
......@@ -223,7 +272,7 @@
callback: (res) => {
console.log(res)
this.testUtsClassConstructorResult.callback = TRUE
}
},
} as TestOptions)
},
testUtsClassStaticProp() {
......@@ -234,30 +283,30 @@
},
testUtsClassStaticSyncWithCallback() {
try {
this.testUtsClassStaticSyncWithCallbackResult.return = FALSE;
this.testUtsClassStaticSyncWithCallbackResult.success = FALSE;
this.testUtsClassStaticSyncWithCallbackResult.return = FALSE
this.testUtsClassStaticSyncWithCallbackResult.success = FALSE
// testUtsClassStaticSyncWithCallbackResult.fail = FALSE;
this.testUtsClassStaticSyncWithCallbackResult.complete = FALSE;
this.testUtsClassStaticSyncWithCallbackResult.complete = FALSE
if (
Test.testClassStaticSyncWithCallback({
type: "success",
type: 'success',
success: (res) => {
console.log("testStaticSyncWithCallback.success.callback", res);
this.testUtsClassStaticSyncWithCallbackResult.success = TRUE;
console.log('testStaticSyncWithCallback.success.callback', res)
this.testUtsClassStaticSyncWithCallbackResult.success = TRUE
},
fail: (res) => {
console.log("testStaticSyncWithCallback.fail.callback", res);
console.log('testStaticSyncWithCallback.fail.callback', res)
// testUtsClassStaticSyncWithCallbackResult.fail = TRUE;
},
complete: (res) => {
console.log("testStaticSyncWithCallback.complete.callback", res);
this.testUtsClassStaticSyncWithCallbackResult.complete = TRUE;
console.log('testStaticSyncWithCallback.complete.callback', res)
this.testUtsClassStaticSyncWithCallbackResult.complete = TRUE
},
} as AsyncOptions).name === "testSyncWithCallback"
} as AsyncOptions).name === 'testSyncWithCallback'
) {
this.testUtsClassStaticSyncWithCallbackResult.return = TRUE;
this.testUtsClassStaticSyncWithCallbackResult.return = TRUE
}
} catch (e) { }
} catch (e) {}
},
// async testUtsClassStaticAsync() {
......@@ -299,30 +348,30 @@
this.testUtsClassConstructor()
}
try {
this.testUtsClassSyncWithCallbackResult.return = FALSE;
this.testUtsClassSyncWithCallbackResult.success = FALSE;
this.testUtsClassSyncWithCallbackResult.return = FALSE
this.testUtsClassSyncWithCallbackResult.success = FALSE
// testUtsClassSyncWithCallbackResult.fail = FALSE;
this.testUtsClassSyncWithCallbackResult.complete = FALSE;
this.testUtsClassSyncWithCallbackResult.complete = FALSE
if (
test!.testClassSyncWithCallback({
type: "success",
type: 'success',
success: (res) => {
console.log("testSyncWithCallback.success.callback", res);
this.testUtsClassSyncWithCallbackResult.success = TRUE;
console.log('testSyncWithCallback.success.callback', res)
this.testUtsClassSyncWithCallbackResult.success = TRUE
},
fail: (res) => {
console.log("testSyncWithCallback.fail.callback", res);
console.log('testSyncWithCallback.fail.callback', res)
// testUtsClassSyncWithCallbackResult.fail = TRUE;
},
complete: (res) => {
console.log("testSyncWithCallback.complete.callback", res);
this.testUtsClassSyncWithCallbackResult.complete = TRUE;
console.log('testSyncWithCallback.complete.callback', res)
this.testUtsClassSyncWithCallbackResult.complete = TRUE
},
} as AsyncOptions).name === "testSyncWithCallback"
} as AsyncOptions).name === 'testSyncWithCallback'
) {
this.testUtsClassSyncWithCallbackResult.return = TRUE;
this.testUtsClassSyncWithCallbackResult.return = TRUE
}
} catch (e) { }
} catch (e) {}
},
// async testUtsClassAsync() {
// if (test != null) {
......@@ -356,41 +405,41 @@
// }
// },
testUtsClassInstance() {
this.testUtsClassInstanceResult.prop = FALSE;
this.testUtsClassInstanceResult.return = FALSE;
this.testUtsClassInstanceResult.success = FALSE;
this.testUtsClassInstanceResult.prop = FALSE
this.testUtsClassInstanceResult.return = FALSE
this.testUtsClassInstanceResult.success = FALSE
// testUtsClassAsyncResult.fail = FALSE;
this.testUtsClassInstanceResult.complete = FALSE;
this.testUtsClassInstanceResult.callback = FALSE;
this.testUtsClassInstanceResult.complete = FALSE
this.testUtsClassInstanceResult.callback = FALSE
const url = 'https://dcloud.io/'
const task = request(url)
if (task != null) {
if (task.url === url && task.abort().url === url) {
this.testUtsClassInstanceResult.prop = TRUE;
this.testUtsClassInstanceResult.prop = TRUE
}
task.onCallback((res) => {
if (res === 'onCallback') {
this.testUtsClassInstanceResult.callback = TRUE;
this.testUtsClassInstanceResult.callback = TRUE
}
})
const res = task.sync({
success: (res) => {
console.log("task.sync.success.callback", res);
this.testUtsClassInstanceResult.success = TRUE;
console.log('task.sync.success.callback', res)
this.testUtsClassInstanceResult.success = TRUE
},
fail: (res) => {
console.log("task.sync.fail.callback", res);
console.log('task.sync.fail.callback', res)
},
complete: (res) => {
console.log("task.sync.complete.callback", res);
this.testUtsClassInstanceResult.complete = TRUE;
console.log('task.sync.complete.callback', res)
this.testUtsClassInstanceResult.complete = TRUE
},
} as SyncOptions)
if (res === 'sync') {
this.testUtsClassInstanceResult.return = TRUE;
}
}
}
this.testUtsClassInstanceResult.return = TRUE
}
}
},
},
}
</script>
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
逐一点击执行,观察测试反馈
</view>
<view class="uni-hello-text"> 逐一点击执行,观察测试反馈 </view>
</view>
<button @click="getAppContextClick">getAppContext</button>
......@@ -25,24 +26,27 @@
</view>
<view class="uni-padding-wrap uni-common-mt">
<view class="text-box" scroll-y="true">
<text>{{text}}</text>
<text>{{ text }}</text>
</view>
</view>
<button @click="gotoSystemPermissionActivityClick">手动申请权限测试</button>
<button @click="gotoSystemPermissionActivityClick">
手动申请权限测试
</button>
<button @tap="testGoOtherActivity">跳转拍照界面</button>
<button @tap="testUnRegLifecycle">取消注册周期函数</button>
<image :src="selectImage" v-if="selectImage"></image>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
获取设备信息,观察是否符合预期
</view>
<view class="uni-hello-text"> 获取设备信息,观察是否符合预期 </view>
</view>
<button @tap="getDeviceInfoClick">获取设备基础信息</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
import {
import {
getAppContextTest,
getUniActivityTest,
getAppTempPathTest,
......@@ -56,75 +60,75 @@
initAppLifecycle,
gotoCameraTake,
getDeviceInfoTest,
privacyStateTest
} from '@/uni_modules/uts-platform-api'
privacyStateTest,
} from '@/uni_modules/uts-platform-api'
/**
/**
* 测试在页面生命周期之外,使用api
*/
export default {
export default {
data() {
return {
text: '',
selectImage:''
selectImage: '',
}
},
onLoad:function(){
let that = this;
initAppLifecycle(function(eventLog){
onLoad: function () {
let that = this
initAppLifecycle(function (eventLog) {
// 展示捕捉到的声明周期日志
let nextLine = that.text + eventLog;
that.text = nextLine;
let nextLineFlag = that.text + '\n';
let nextLine = that.text + eventLog
that.text = nextLine
let nextLineFlag = that.text + '\n'
that.text = nextLineFlag
});
})
},
methods: {
privacyStateClick(){
privacyStateTest(function(ret,desc){
privacyStateClick() {
privacyStateTest(function (ret, desc) {
if (ret) {
uni.showToast({
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'none',
title: '失败:' + desc
title: '失败:' + desc,
})
}
})
},
getDeviceInfoClick(){
getDeviceInfoClick() {
this.text = getDeviceInfoTest()
},
testGoOtherActivity(){
var that = this;
let ret = gotoCameraTake(function(file){
testGoOtherActivity() {
var that = this
let ret = gotoCameraTake(function (file) {
// 展示捕捉到的声明周期日志
console.log(file);
that.selectImage = "file://" + file;
});
console.log(file)
that.selectImage = 'file://' + file
})
if(!ret){
if (!ret) {
uni.showToast({
icon:'none',
title:'测试失败'
icon: 'none',
title: '测试失败',
})
}
},
testUnRegLifecycle(){
testUnRegLifecycle() {
// 取消注册生命周期
unRegLifecycle();
unRegLifecycle()
},
getAppContextClick() {
if (getAppContextTest()) {
uni.showToast({
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败'
title: '测试失败',
})
}
},
......@@ -132,49 +136,49 @@
getUniActivityClick() {
if (getUniActivityTest()) {
uni.showToast({
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败'
title: '测试失败',
})
}
},
pathTestClick() {
if (convert2AbsFullPathTest()) {
uni.showToast({
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败'
title: '测试失败',
})
}
},
getAppTempPathClick() {
if (getAppTempPathTest()) {
uni.showToast({
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败'
title: '测试失败',
})
}
},
dispatchAsyncClick() {
dispatchAsyncTest(function(ret,desc){
dispatchAsyncTest(function (ret, desc) {
if (ret) {
uni.showToast({
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'none',
title: '失败:' + desc
title: '失败:' + desc,
})
}
})
......@@ -182,12 +186,12 @@
typeofClick() {
if (typeofClickTest()) {
uni.showToast({
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'error',
title: '测试失败'
title: '测试失败',
})
}
},
......@@ -196,43 +200,41 @@
gotoSystemPermissionActivityTest()
},
arrayPermissionFlowClick() {
arrayPermissionFlowTest(function(ret,desc){
arrayPermissionFlowTest(function (ret, desc) {
if (ret) {
uni.showToast({
icon: 'none',
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'none',
title: '失败:' + desc
title: '失败:' + desc,
})
}
})
},
singlePermissionFlowClick() {
singlePermissionFlowTest(function(ret,desc){
singlePermissionFlowTest(function (ret, desc) {
if (ret) {
uni.showToast({
icon: 'none',
title: '测试通过'
title: '测试通过',
})
} else {
uni.showToast({
icon: 'none',
title: '失败:' + desc
title: '失败:' + desc,
})
}
})
}
}
}
},
},
}
</script>
<style>
.testButton{
width:100%
}
.testButton {
width: 100%;
}
</style>
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="content">
<page-head :title="title"></page-head>
<view v-for="(item,index) in resultArray" :key="index" class="result">
<view>{{names[index]}}测试结果:</view>
<view>
测试api:{{item.passed.join(', ')}}
</view>
<view>总共:{{item.total}}</view>
<view>通过:{{item.passed.length}}</view>
<view>失败:{{item.failed.length}}</view>
<view v-for="(fail,i) in item.failed" :key="i">
<text class="failed">{{fail}}</text>
<view v-for="(item, index) in resultArray" :key="index" class="result">
<view>{{ names[index] }}测试结果:</view>
<view> 测试api:{{ item.passed.join(', ') }} </view>
<view>总共:{{ item.total }}</view>
<view>通过:{{ item.passed.length }}</view>
<view>失败:{{ item.failed.length }}</view>
<view v-for="(fail, i) in item.failed" :key="i">
<text class="failed">{{ fail }}</text>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script lang="ts">
import {
runTests,
Result
} from '../../uni_modules/uts-tests'
import { runTests, Result } from '../../uni_modules/uts-tests'
export default {
export default {
data() {
return {
title: 'UTS基础语法',
resultArray: [] as Result[],
result: {} as UTSJSONObject,
names: [] as string[]
names: [] as string[],
}
},
onReady() {
......@@ -41,26 +42,26 @@
this.names.push(name)
this.resultArray.push(res as Result)
})
}
}
}
},
},
}
</script>
<style>
@import '@/common/uni-uvue.css';
.content {
@import '@/common/uni-uvue.css';
.content {
min-height: 100%;
padding: 32rpx;
}
}
.passed {
.passed {
color: green;
}
}
.failed {
.failed {
color: red;
}
}
.result {
.result {
margin-bottom: 20rpx;
}
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册