提交 9de6696c 编写于 作者: X xty

uts dialogpage uni.$emit补充object类型测试例

上级 85b35ecb
......@@ -1932,6 +1932,13 @@
"navigationBarTitleText": ""
}
},
{
"path" : "pages/API/dialog-page/uts-dialog-page",
"style" :
{
"navigationBarTitleText" : ""
}
},
// #endif
// #ifdef APP
{
......
<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>
......@@ -34,14 +34,31 @@ describe('event-bus', () => {
await page.callMethod('JsOnUts')
await page.callMethod('emitFromUts')
const l1 = (await page.data()).log.length
expect(l1).toBeGreaterThan(0)
expect(l1).toBeGreaterThan(0)
await page.callMethod('clear')
await page.callMethod('emitUtsMessageUTSObject')
const data = await page.data()
console.log(data)
expect(data.log.length).toBe(1)
expect(data.log[0].name).toMatch('金运大厦')
await page.callMethod('clear')
await page.callMethod('emitUtsMessages')
const l12 = (await page.data()).log.length
expect(l12).toBe(2)
await page.callMethod('clear')
await page.callMethod('emitUtsMessageNoArgument')
const l13 = (await page.data()).log.length
expect(l13).toBe(0)
await page.callMethod('clear')
await page.callMethod('offUts')
await page.callMethod('emitFromUts')
const l2 = (await page.data()).log.length
expect(l2).toBe(0)
expect(l2).toBe(0)
await page.callMethod('clear')
await page.callMethod('UtsOnJS')
......
......@@ -4,11 +4,15 @@
<!-- #endif -->
<view>
<button @click="JsOnUts">1. js监听uts消息</button>
<button @click="emitFromUts">2. uts中触发监听</button>
<button @click="offUts">取消uts消息监听</button>
<button @click="emitFromUts">2. uts中触发监听</button>
<button @click="emitUtsMessageUTSObject">2.1 uts中触发监听(UTSJSONObject)</button>
<button @click="emitUtsMessages">2.2 uts中触发监听(多个参数)</button>
<button @click="emitUtsMessageNoArgument">2.3 uts中触发监听(无参数)</button>
<button @click="offUts">取消uts消息监听</button>
<button @click="UtsOnJS">1. uts监听js消息</button>
<button @click="emitFormJS">2 .js中触发监听</button>
<button @click="emitFormJS">2 .js中触发监听</button>
<button @click="emitFormJSObject">2.1 js中触发监听(UTSJSONObject)</button>
<button @click="offJs">取消js消息监听</button>
<button @click="clear">清空消息</button>
......@@ -29,7 +33,10 @@
import {
onJsMessage,
offJsMessage,
emitUtsMessage,
emitUtsMessage,
emitUtsMessageUTSObject,
emitUtsMessageNoArgument,
emitUtsMessages,
getMessageChannel,
getRevJsMessage,
clearJsMessage,
......@@ -44,10 +51,15 @@
}
},
methods: {
fn(res : string, res2 : string) {
console.log("on rev: " + res)
this.log.push(res)
this.log.push(res2)
fn(res : any, res2 : any) {
if (res != null){
console.log("on rev: " + JSON.stringify(res))
this.log.push(res)
}
if (res2 != null) {
console.log("on rev: " + JSON.stringify(res2))
this.log.push(res2)
}
},
fn2(res : string) {
this.log.push(res)
......@@ -61,6 +73,25 @@
},
emitFromUts() {
emitUtsMessage("emit form uts")
},
emitUtsMessageUTSObject() {
emitUtsMessageUTSObject({
latitude: 39.951028,
longitude: 116.354662,
name: '金运大厦',
address: '西直门北大街xx号'
})
},
emitUtsMessages() {
emitUtsMessages({
latitude: 39.951028,
longitude: 116.354662,
name: '金运大厦',
address: '西直门北大街xx号'
}, "emit form uts")
},
emitUtsMessageNoArgument() {
emitUtsMessageNoArgument()
},
JsOnUtsOnce() {
uni.$once(getMessageChannel(), this.fn2)
......@@ -82,6 +113,20 @@
if (msg && msg.length){
this.log.push(msg)
}
},
emitFormJSObject() {
clearJsMessage()
uni.$emit("JsMessage", {
latitude: 39.951028,
longitude: 116.354662,
name: '金运大厦form js',
address: '西直门北大街xx号 from js'
})
let msg = getRevJsMessage()
console.log("message:"+msg)
if (msg && msg.length){
this.log.push(msg)
}
},
clear() {
clearJsMessage()
......
{
"id": "uts-dialogpage",
"displayName": "uts-dialogpage",
"version": "1.0.0",
"description": "uts-dialogpage",
"keywords": [
"uts-dialogpage"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uts-dialogpage
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
\ No newline at end of file
/**
* 引用 iOS 系统库,示例如下:
* import { UIDevice } from "UIKit";
* [可选实现,按需引入]
*/
// import {OpenDialogPageOptions,openDialogPage} from "DCloudUTSExtAPI";
/* 引入 interface.uts 文件中定义的变量 */
import { TestOpenDialogPage, TestCloseDialogPage } from '../interface.uts';
var curDialogPage : UniDialogPage | null = null
export const testOpenDialogPage : TestOpenDialogPage = function (url:string) {
// let utsJsonObj : DCloudUTSExtAPI.OpenDialogPageOptions = {
// url:"zhangsan"
// }
console.log("testOpenDialogPage")
// let option = new OpenDialogPageOptions({
// url:url
// })
let option = new OpenDialogPageOptions()
option.url = url
console.log(url)
option.animationType ="slide-in-left"
// option.parentPage = getCurrentPages()[0]
option.success = (arg : OpenDialogPageSuccess )=>{
console.log("success")
}
option.complete = (arg : OpenDialogPageComplete )=>{
console.log(arg)
}
option.fail = (arg : OpenDialogPageFail )=>{
console.log("fail")
}
curDialogPage = uni.openDialogPage(option)
}
export const testCloseDialogPage : TestCloseDialogPage = function () {
console.log("testCloseDialogPage")
if ( curDialogPage != null ){
let option = new CloseDialogPageOptions()
option.dialogPage = curDialogPage
option.success = (arg : CloseDialogPageSuccess )=>{
console.log("success")
}
option.complete = (arg : CloseDialogPageComplete )=>{
console.log(arg)
}
option.fail = (arg : CloseDialogPageFail )=>{
console.log("fail")
}
uni.closeDialogPage(option)
}
}
/**
* 更多插件开发的信息详见:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
*/
/**
* interface.uts
* uts插件接口定义文件,按规范定义接口文件可以在HBuilderX中更好的做到语法提示
*/
export type TestOpenDialogPage = (url:string)=>void
export type TestCloseDialogPage = ()=>void
\ No newline at end of file
/* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */
import { MyApiErrorCode, MyApiFail } from "./interface.uts"
/**
* 错误主题
* 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。
* [可选实现]
*/
export const UniErrorSubject = 'uts-api';
/**
* 错误信息
* @UniError
* [可选实现]
*/
export const MyAPIErrors : Map<MyApiErrorCode, string> = new Map([
/**
* 错误码及对应的错误信息
*/
[9010001, 'custom error mseeage1'],
[9010002, 'custom error mseeage2'],
]);
/**
* 错误对象实现
*/
export class MyApiFailImpl extends UniError implements MyApiFail {
/**
* 错误对象构造函数
*/
constructor(errCode : MyApiErrorCode) {
super();
this.errSubject = UniErrorSubject;
this.errCode = errCode;
this.errMsg = MyAPIErrors.get(errCode) ?? "";
}
}
......@@ -17,19 +17,30 @@ export function emitUtsMessage(arg : string) {
uni.$emit(MessageChannel, arg);
}
export function emitUtsMessageUTSObject(arg : UTSJSONObject) {
uni.$emit(MessageChannel, arg);
}
export function emitUtsMessages(arg : UTSJSONObject, arg2 : string ){
uni.$emit(MessageChannel, arg, arg2);
}
export function emitUtsMessageNoArgument(){
uni.$emit(MessageChannel);
}
var callbackId : NSNumber | null = null
export function onJsMessage (messageChannel : string ) {
revFromJS = ""
if (callbackId != null) {
uni.$off(messageChannel, callbackId!)
callbackId = null
callbackId = null
}
callbackId = uni.$on(messageChannel, function (...spreadArgs : Any) {
if (spreadArgs.length > 0) {
let arg0 = spreadArgs[0] as String | null
if ( arg0 != null ){
revFromJS = arg0!;
let arg0 = JSON.stringify(spreadArgs[0])
if ( typeof arg0 == "string" ) {
revFromJS = arg0!
}
}
})
......@@ -39,20 +50,21 @@ export function onJsMessageOnce (messageChannel : string ) {
revFromJS = ""
uni.$once(messageChannel, function (...spreadArgs : Any) {
if (spreadArgs.length > 0) {
let arg0 = spreadArgs[0] as String | null
if ( arg0 != null ){
revFromJS = arg0!;
}
let arg0 = JSON.stringify(spreadArgs[0])
if ( typeof arg0 == "string" ) {
revFromJS = arg0!
}
}
})
}
export function offJsMessage(messageChannel : string) {
if (callbackId != null) {
uni.$off(messageChannel, callbackId!)
uni.$off(messageChannel, callbackId!)
callbackId = null
}
}
export function clearJsMessage() {
revFromJS = ""
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册