Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
97a83a8f
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
97a83a8f
编写于
6月 24, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): automator uni api
上级
c36637fb
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
123 addition
and
19 deletion
+123
-19
packages/uni-app-uts/lib/automator/apis/App.uts
packages/uni-app-uts/lib/automator/apis/App.uts
+120
-16
packages/uni-automator/dist/environment.js
packages/uni-automator/dist/environment.js
+1
-1
packages/uni-automator/dist/index.js
packages/uni-automator/dist/index.js
+2
-2
未找到文件。
packages/uni-app-uts/lib/automator/apis/App.uts
浏览文件 @
97a83a8f
...
...
@@ -6,6 +6,7 @@ import {
} from 'io.dcloud.uniapp.runtime'
import { getCurrentPages } from 'io.dcloud.uts.framework'
import { parsePage } from './util.uts'
import { ShowToastOptions, ShowLoadingOptions, ShowModalOptions } from "io.dcloud.uts.extapi";
export type GetPageStackParams = {
callback: (res: any) => void
...
...
@@ -45,10 +46,6 @@ export const callUniMethod = (params: CallUniMethodParams): void => {
const callback = params.callback
let animationType: string = 'pop-in'
let animationDuration: number = 300
let arg = {} as JSONObject
if (args.size > 0) {
arg = args[0] as JSONObject
}
const success = (result: any) => {
const timeout = method == 'pageScrollTo' ? 350 : 0
setTimeout(() => {
...
...
@@ -60,14 +57,14 @@ export const callUniMethod = (params: CallUniMethodParams): void => {
}
switch (method) {
case 'navigateTo':
if (
arg
['animationType'] !== null) {
animationType =
arg
['animationType'] as string
if (
(args[0] as JSONObject)
['animationType'] !== null) {
animationType =
(args[0] as JSONObject)
['animationType'] as string
}
if (
arg
['animationDuration'] !== null) {
animationDuration =
arg
['animationDuration'] as number
if (
(args[0] as JSONObject)
['animationDuration'] !== null) {
animationDuration =
(args[0] as JSONObject)
['animationDuration'] as number
}
uni.navigateTo({
url:
arg
['url'] as string,
url:
(args[0] as JSONObject)
['url'] as string,
animationType,
animationDuration,
success,
...
...
@@ -77,7 +74,7 @@ export const callUniMethod = (params: CallUniMethodParams): void => {
case 'redirectTo':
uni.redirectTo({
url:
arg
['url'] as string,
url:
(args[0] as JSONObject)
['url'] as string,
success,
fail
})
...
...
@@ -85,7 +82,7 @@ export const callUniMethod = (params: CallUniMethodParams): void => {
case 'reLaunch':
uni.reLaunch({
url:
arg
['url'] as string,
url:
(args[0] as JSONObject)
['url'] as string,
success,
fail
})
...
...
@@ -93,11 +90,11 @@ export const callUniMethod = (params: CallUniMethodParams): void => {
case 'navigateBack':
animationType = 'pop-out'
if (
arg
['animationType'] !== null) {
animationType =
arg
['animationType'] as string
if (
(args[0] as JSONObject)
['animationType'] !== null) {
animationType =
(args[0] as JSONObject)
['animationType'] as string
}
if (
arg
['animationDuration'] !== null) {
animationDuration =
arg
['animationDuration'] as number
if (
(args[0] as JSONObject)
['animationDuration'] !== null) {
animationDuration =
(args[0] as JSONObject)
['animationDuration'] as number
}
uni.navigateBack({
animationType,
...
...
@@ -106,8 +103,115 @@ export const callUniMethod = (params: CallUniMethodParams): void => {
fail
})
break
case 'switchTab':
uni.switchTab({
url: (args[0] as JSONObject)['url'] as string,
success,
fail
})
break
case 'setStorage':
uni.setStorage({
key: (args[0] as JSONObject)['key'] as string,
data: (args[0] as JSONObject)['data'] as any,
success,
fail
})
break
case 'getStorage':
uni.getStorage({
key: (args[0] as JSONObject)['key'] as string,
success(result: any) {
callback({ result })
},
fail
})
break
case 'setStorageSync':
uni.setStorageSync(args[0] as string, args[1] as any)
callback({ result: { errMsg: 'uni.setStorageSync success' } })
break
case 'getStorageSync':
const result = uni.getStorageSync((args[0] as string))
callback({ result })
break
case 'showToast':
const icon = (args[0] as JSONObject)['icon'] != null ? (args[0] as JSONObject)['icon'] as string : 'success'
const image = (args[0] as JSONObject)['image'] != null && (args[0] as JSONObject)['image'] !== '' ? (args[0] as JSONObject)['image'] as string : null
const toastMask = (args[0] as JSONObject)['mask'] != null ? (args[0] as JSONObject)['mask'] as boolean : false
const duration: number = (args[0] as JSONObject)['duration'] != null ? (args[0] as JSONObject)['duration'] as number : 1500
const position = (args[0] as JSONObject)['position'] != null ? (args[0] as JSONObject)['position'] as string : null
uni.showToast({
title: (args[0] as JSONObject)['title'] as string,
icon,
image,
mask: toastMask,
duration,
position,
success,
fail
} as ShowToastOptions)
break
case 'hideToast':
uni.hideToast()
break
case 'showLoading':
const loadingMask = (args[0] as JSONObject)['mask'] != null ? (args[0] as JSONObject)['mask'] as boolean : false
uni.showLoading({
title: (args[0] as JSONObject)['title'] as string,
mask: loadingMask,
success,
fail
} as ShowLoadingOptions)
break
case 'hideLoading':
uni.hideLoading()
break
case 'showModal':
const showModalTitle = (args[0] as JSONObject)['title'] != null ? (args[0] as JSONObject)['title'] as string : null
const content = (args[0] as JSONObject)['content'] != null ? (args[0] as JSONObject)['content'] as string : null
const showCancel = (args[0] as JSONObject)['showCancel'] != null ? (args[0] as JSONObject)['showCancel'] as boolean : true
const cancelText = (args[0] as JSONObject)['cancelText'] != null ? (args[0] as JSONObject)['cancelText'] as string : null
const cancelColor: string | null = (args[0] as JSONObject)['cancelColor'] != null ? (args[0] as JSONObject)['cancelColor'] as string : null
const confirmText = (args[0] as JSONObject)['confirmText'] != null ? (args[0] as JSONObject)['confirmText'] as string : null
const confirmColor = (args[0] as JSONObject)['confirmColor'] != null ? (args[0] as JSONObject)['confirmColor'] as string : null
const editable = (args[0] as JSONObject)['editable'] != null ? (args[0] as JSONObject)['editable'] as boolean : false
const placeholderText = (args[0] as JSONObject)['placeholderText'] != null ? (args[0] as JSONObject)['placeholderText'] as string : null
uni.showModal({
title: showModalTitle,
content,
showCancel,
cancelText,
cancelColor,
confirmText,
confirmColor,
editable,
placeholderText,
success(result: any) {
callback({ result })
},
fail(error: any) {
callback({ result: error })
}
} as ShowModalOptions)
break
// case 'showActionSheet':
// const showActionSheetTitle = (args[0] as JSONObject)['title'] != null ? (args[0] as JSONObject)['title'] as string : null
// const itemColor = (args[0] as JSONObject)['itemColor'] != null ? (args[0] as JSONObject)['itemColor'] as string : null
// uni.showActionSheet({
// title: showActionSheetTitle,
// itemList: (args[0] as JSONObject)['itemList'] as string[],
// itemColor,
// success(result: any) {
// callback({ result })
// },
// fail(error: any) {
// callback({ result: error })
// }
// } as ShowActionSheetOptions)
// break
default:
callback({
errMsg: 'uni.' + method + ' not exists'
})
callback({
result: { errMsg: 'uni.' + method + ' not exists.' }
})
break
}
}
...
...
packages/uni-automator/dist/environment.js
浏览文件 @
97a83a8f
"
use strict
"
;
function
t
(
t
){
return
t
&&
"
object
"
==
typeof
t
&&
"
default
"
in
t
?
t
:{
default
:
t
}}
const
e
=
new
(
t
(
require
(
"
./index.js
"
)).
default
);
let
n
,
r
=!
1
;
try
{
n
=
require
(
"
jest-environment-node
"
)}
catch
(
t
){
n
=
require
(
require
.
resolve
(
"
jest-environment-node
"
,{
paths
:[
process
.
cwd
()]}))}
n
&&
n
.
TestEnvironment
&&
(
r
=!
0
,
n
=
n
.
TestEnvironment
);
module
.
exports
=
class
extends
n
{
constructor
(
t
,
e
){
super
(
r
?{
projectConfig
:
t
}:
t
),
process
.
env
.
UNI_AUTOMATOR_CONFIG
?
this
.
launchOptions
=
require
(
process
.
env
.
UNI_AUTOMATOR_CONFIG
):
this
.
launchOptions
=
t
.
testEnvironmentOptions
}
async
setup
(){
await
super
.
setup
();
const
t
=
global
;
if
(
t
.
__init__
){
if
(
!
t
.
program
)
throw
Error
(
"
Program init failed
"
)}
else
t
.
__init__
=!
0
,
this
.
launchOptions
.
platform
=
this
.
launchOptions
.
platform
||
process
.
env
.
UNI_PLATFORM
,
t
.
program
=
await
e
.
launch
(
this
.
launchOptions
),
this
.
launchOptions
.
devtools
&&
this
.
launchOptions
.
devtools
.
remote
&&
await
t
.
program
.
remote
(
!
0
);
this
.
global
.
program
=
t
.
program
}
async
teardown
(){
await
super
.
teardown
()}};
"
use strict
"
;
var
t
=
require
(
"
./index.js
"
);
function
e
(
t
){
return
t
&&
"
object
"
==
typeof
t
&&
"
default
"
in
t
?
t
:{
default
:
t
}}
const
n
=
new
(
e
(
t
).
default
);
let
r
,
o
=!
1
;
try
{
r
=
require
(
"
jest-environment-node
"
)}
catch
(
t
){
r
=
require
(
require
.
resolve
(
"
jest-environment-node
"
,{
paths
:[
process
.
cwd
()]}))}
r
&&
r
.
TestEnvironment
&&
(
o
=!
0
,
r
=
r
.
TestEnvironment
);
module
.
exports
=
class
extends
r
{
constructor
(
t
,
e
){
super
(
o
?{
projectConfig
:
t
}:
t
),
process
.
env
.
UNI_AUTOMATOR_CONFIG
?
this
.
launchOptions
=
require
(
process
.
env
.
UNI_AUTOMATOR_CONFIG
):
this
.
launchOptions
=
t
.
testEnvironmentOptions
}
async
setup
(){
await
super
.
setup
();
const
e
=
global
;
if
(
e
.
__init__
){
if
(
!
e
.
program
)
throw
Error
(
"
Program init failed
"
)}
else
e
.
__init__
=!
0
,
this
.
launchOptions
.
platform
=
this
.
launchOptions
.
platform
||
process
.
env
.
UNI_PLATFORM
,
e
.
program
=
await
n
.
launch
(
this
.
launchOptions
),
this
.
launchOptions
.
devtools
&&
this
.
launchOptions
.
devtools
.
remote
&&
await
e
.
program
.
remote
(
!
0
);
this
.
global
.
program
=
e
.
program
,
this
.
global
.
uni
=
t
.
initUni
(
e
.
program
)
}
async
teardown
(){
await
super
.
teardown
()}};
packages/uni-automator/dist/index.js
浏览文件 @
97a83a8f
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录