Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mall-webview
Project
Project
Details
Activity
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
frontend
mall-webview
Commits
be7d6ee8
Commit
be7d6ee8
authored
Mar 29, 2021
by
wykolor
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/2021_03_12_bonus' of dev.jiuaoedu.com:wykolor/GeekBonusH5…
Merge branch 'feature/2021_03_12_bonus' of dev.jiuaoedu.com:wykolor/GeekBonusH5 into feature/2021_03_12_bonus
parents
92013d43
d5254d3c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
use-native-bridge.ts
src/util/use-native-bridge.ts
+19
-3
index.vue
src/views/test/index.vue
+8
-3
No files found.
src/util/use-native-bridge.ts
View file @
be7d6ee8
...
@@ -39,16 +39,32 @@ const sendNativeMessage = (data: { type: string; data: any }) => {
...
@@ -39,16 +39,32 @@ const sendNativeMessage = (data: { type: string; data: any }) => {
window
.
ReactNativeWebView
.
postMessage
(
JSON
.
stringify
(
data
));
window
.
ReactNativeWebView
.
postMessage
(
JSON
.
stringify
(
data
));
};
};
type
ListenerType
=
(
this
:
ComponentInternalInstance
|
null
,
...
arg
:
any
[])
=>
any
;
function
useNativeBridge
(
function
useNativeBridge
(
eventType
:
string
,
eventType
:
string
,
listener
:
(
this
:
ComponentInternalInstance
|
null
,
...
arg
:
any
[])
=>
any
listener
:
ListenerType
):
[
typeof
sendNativeMessage
,
typeof
eventBus
];
function
useNativeBridge
(
eventMap
:
{
[
key
:
string
]:
ListenerType
;
}):
[
typeof
sendNativeMessage
,
typeof
eventBus
];
function
useNativeBridge
(
eventTypeOrEventMap
:
string
|
{
[
key
:
string
]:
ListenerType
},
listener
?:
ListenerType
):
[
typeof
sendNativeMessage
,
typeof
eventBus
]
{
):
[
typeof
sendNativeMessage
,
typeof
eventBus
]
{
const
_listener
=
function
(
this
:
ComponentInternalInstance
|
null
,
arg
?:
NativeInvokeFuncParams
)
{
const
_listener
=
function
(
this
:
ComponentInternalInstance
|
null
,
arg
?:
NativeInvokeFuncParams
)
{
console
.
log
(
arg
,
1111111
);
console
.
log
(
arg
,
1111111
);
if
(
!
arg
)
return
;
if
(
!
arg
)
return
;
if
(
eventType
===
arg
.
method
)
{
const
{
method
,
data
}
=
arg
;
listener
.
apply
(
this
,
[
arg
.
data
]);
if
(
typeof
eventTypeOrEventMap
===
"string"
)
{
if
(
eventTypeOrEventMap
===
method
&&
listener
)
{
listener
.
apply
(
this
,
[
data
]);
}
}
else
if
(
typeof
eventTypeOrEventMap
[
method
]
===
"function"
)
{
eventTypeOrEventMap
[
method
].
apply
(
this
,
[
data
]);
}
}
};
};
...
...
src/views/test/index.vue
View file @
be7d6ee8
...
@@ -9,13 +9,18 @@ import { ref } from "vue";
...
@@ -9,13 +9,18 @@ import { ref } from "vue";
import
{
useNativeBridge
}
from
"@/util/use-native-bridge"
;
import
{
useNativeBridge
}
from
"@/util/use-native-bridge"
;
import
{
Toast
}
from
"vant"
;
import
{
Toast
}
from
"vant"
;
const
[
sendNativeMessage
,
eventBus
]
=
useNativeBridge
(
"title"
,
function
(
arg
)
{
const
[
sendNativeMessage
,
eventBus
]
=
useNativeBridge
({
Toast
(
'hahahahah'
)
onBindWechatChange
(
arg
)
{
console
.
log
(
this
,
arg
);
}
});
useNativeBridge
(
"onBindWechatChange"
,
function
(
arg
)
{
console
.
log
(
this
,
arg
,
"bb"
);
});
});
const
count
=
ref
(
1000
);
const
count
=
ref
(
1000
);
const
emitTest
=
()
=>
{
const
emitTest
=
()
=>
{
eventBus
.
emit
(
"GEEK_NATVIE_NAME"
,
{
eventBus
.
emit
(
"GEEK_NATVIE_NAME"
,
{
method
:
"
b
indWechatChange"
,
method
:
"
onB
indWechatChange"
,
data
:
{
data
:
{
hhh
:
13213
hhh
:
13213
}
}
...
...
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