Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
web-lib
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑磊
web-lib
Commits
266fc754
Commit
266fc754
authored
Apr 10, 2024
by
郑磊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新与app交互的代码
parent
741b3fe6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
206 additions
and
0 deletions
+206
-0
extends.d.ts
src/app/extends.d.ts
+7
-0
index.ts
src/app/index.ts
+2
-0
native-api.ts
src/app/native-api.ts
+192
-0
status.ts
src/app/status.ts
+5
-0
No files found.
src/app/extends.d.ts
0 → 100644
View file @
266fc754
interface
IosWebkitInterface
{}
declare
global
{
interface
Window
{
webkit
:
IosWebkitInterface
}
}
src/app/index.ts
0 → 100644
View file @
266fc754
export
*
from
'./status'
export
*
from
'./native-api'
src/app/native-api.ts
0 → 100644
View file @
266fc754
interface
IosWebkitInterface
{
messageHandlers
:
{
[
name
:
string
]:
{
postMessage
(
data
?:
any
):
void
}
}
}
declare
global
{
interface
Window
{
webkit
:
IosWebkitInterface
liveapp
:
{
[
name
:
string
]:
(
data
?:
string
)
=>
void
}
}
}
function
callIosApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
function
callIosApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
function
callIosApi
<
T
>
(
name
:
string
,
...
args
:
any
[]):
boolean
{
if
(
typeof
window
.
webkit
?.
messageHandlers
[
name
]?.
postMessage
===
'function'
)
{
return
false
}
let
params
:
any
=
undefined
let
ack
:
Function
|
undefined
=
undefined
if
(
typeof
args
[
0
]
===
'function'
)
{
ack
=
args
[
0
]
}
else
if
(
typeof
args
[
1
]
===
'function'
)
{
params
=
args
[
0
]
ack
=
args
[
1
]
}
if
(
typeof
ack
===
'function'
)
{
// @ts-ignore
window
[
name
]
=
ack
}
window
.
webkit
.
messageHandlers
[
name
].
postMessage
(
params
??
true
)
return
true
}
function
callAndroidApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
function
callAndroidApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
function
callAndroidApi
(
name
:
string
,
...
args
:
any
[]):
boolean
{
if
(
typeof
window
.
liveapp
[
name
]
!==
'function'
)
{
return
false
}
let
params
:
any
=
undefined
let
ack
:
Function
|
undefined
=
undefined
if
(
typeof
args
[
0
]
===
'function'
)
{
ack
=
args
[
0
]
}
else
if
(
typeof
args
[
1
]
===
'function'
)
{
params
=
args
[
0
]
ack
=
args
[
1
]
}
if
(
typeof
ack
===
'function'
)
{
// @ts-ignore
window
[
name
]
=
ack
}
const
invokeArgs
:
Parameters
<
(
typeof
window
.
liveapp
)[
string
]
>
=
[]
if
(
typeof
params
!==
'undefined'
&&
params
!==
null
)
{
invokeArgs
.
push
(
JSON
.
stringify
(
params
))
}
window
.
liveapp
[
name
].
apply
(
null
,
invokeArgs
)
return
true
}
const
isiOS
=
!!
navigator
.
userAgent
.
match
(
/
\(
i
[^
;
]
+;
(
U;
)?
CPU.+Mac OS X/
)
//ios终端
/**
* 调用原生提供的api
* @param name
* @param params
*/
export
function
callNativeApi
<
T
>
(
name
:
string
,
data
:
any
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
export
function
callNativeApi
<
T
>
(
name
:
string
,
ack
?:
(
data
:
T
)
=>
void
):
boolean
export
function
callNativeApi
(
name
:
string
,
...
args
:
any
[]):
boolean
{
return
isiOS
?
callIosApi
(
name
,
...
args
)
:
callAndroidApi
(
name
,
...
args
)
}
export
namespace
NativeApi
{
interface
ActionAsPhpData
{
app_open
:
string
url
:
string
ios_url
:
string
android_url
:
string
}
/**
* 跳转到
* @param data 跳转参数
*/
export
function
actionAsPhp
(
data
:
ActionAsPhpData
):
void
{
callNativeApi
(
'actionAsPhp'
,
data
)
}
/**
* 关闭当前页面
*/
export
function
closeWeb
()
{
callNativeApi
(
'closeWeb'
)
}
/**
* 获取状态栏高度
* @returns
*/
export
function
getStatusBarHeight
():
Promise
<
number
>
{
return
new
Promise
<
number
>
((
resolve
)
=>
callNativeApi
(
'getStatusBarHeight'
,
resolve
))
}
/**
* 获取底部安全区高度
* @returns
*/
export
function
getBottomSafeHeight
():
Promise
<
number
>
{
return
new
Promise
<
number
>
((
resolve
)
=>
callNativeApi
(
'getBottomSafeHeight'
,
resolve
))
}
/**
* 绑定支付宝
*/
export
function
openBindZfb
()
{
callNativeApi
(
'openBindZfb'
)
}
/**
* 打开银行列表
*/
export
function
openBankList
()
{
callNativeApi
(
'openBankList'
)
}
interface
ShareTipData
{
url
:
string
img
:
string
title
:
string
desc
:
string
}
/**
* 分享
* @param data
*/
export
function
openShareTip
(
data
:
ShareTipData
)
{
callNativeApi
(
'openShareTip'
,
data
)
}
/**
* 打开个人中心
* @param userId
*/
export
function
toPerson
(
userId
:
number
|
string
)
{
callNativeApi
(
'toPerson'
,
{
userid
:
String
(
userId
)
})
}
/**
* 验证⽤户身份
* @param action 1-进入手机认证 2-进入实名认证
*/
export
function
verify
(
action
:
'1'
|
'2'
)
{
callNativeApi
(
'verify'
,
{
action
})
}
/**
* 进入直播间
* @param userId
* @param avatar
*/
export
function
toLiveroom
(
userId
:
number
|
string
,
avatar
?:
string
)
{
callNativeApi
(
'toLiveroom'
,
{
userid
:
String
(
userId
),
avatar
})
}
/**
* 清除浏览器缓存
*/
export
function
removeHistory
()
{
callNativeApi
(
'removeHistory'
)
}
/**
* 去开播
*/
export
function
openLive
()
{
callNativeApi
(
'openLive'
)
}
}
src/app.ts
→
src/app
/status
.ts
View file @
266fc754
...
...
@@ -24,6 +24,10 @@ export interface AppStatus {
* 加密后的用户id
*/
userid
:
string
/**
* 是否能使用内购
*/
canUseIAP
:
boolean
}
/**
...
...
@@ -42,5 +46,6 @@ export function getAppStatus(): AppStatus | undefined {
isOnLiveRoom
:
parseInt
(
Cookies
.
get
(
'isOnLiveRoom'
)
??
'0'
),
roomIdentifier
:
parseInt
(
Cookies
.
get
(
'roomIdentifier'
)
||
'0'
),
userid
:
Cookies
.
get
(
'userid'
)
??
''
,
canUseIAP
:
Cookies
.
get
(
'canUseIAP'
)
===
'true'
,
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment