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
00d4ebd8
Commit
00d4ebd8
authored
Mar 26, 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
64d7469d
ab937710
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
71 deletions
+71
-71
use-native-bridge.ts
src/util/use-native-bridge.ts
+69
-69
index.vue
src/views/test/index.vue
+2
-2
No files found.
src/util/use-native-brid
a
ge.ts
→
src/util/use-native-bridge.ts
View file @
00d4ebd8
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-explicit-any */
import
{
onBeforeUnmount
,
onMounted
,
getCurrentInstance
,
ComponentInternalInstance
}
from
"vue"
;
import
{
onBeforeUnmount
,
onMounted
,
getCurrentInstance
,
ComponentInternalInstance
}
from
"vue"
;
import
mitt
from
"./mitt"
;
import
mitt
from
"./mitt"
;
const
eventBus
=
mitt
();
const
eventBus
=
mitt
();
const
GEEK_NATVIE_NAME
=
"GEEK_NATVIE_NAME"
;
const
GEEK_NATVIE_NAME
=
"GEEK_NATVIE_NAME"
;
interface
NativeInvokeFuncParams
{
interface
NativeInvokeFuncParams
{
method
:
string
;
method
:
string
;
data
:
any
;
data
:
any
;
}
}
const
isAndroid
=
()
=>
{
const
isAndroid
=
()
=>
{
const
u
=
navigator
.
userAgent
;
const
u
=
navigator
.
userAgent
;
const
android
=
u
.
indexOf
(
"Android"
)
>
-
1
||
u
.
indexOf
(
"Adr"
)
>
-
1
;
const
android
=
u
.
indexOf
(
"Android"
)
>
-
1
||
u
.
indexOf
(
"Adr"
)
>
-
1
;
return
android
;
return
android
;
};
};
window
.
$geek_excuteJS
=
function
(
args
)
{
window
.
$geek_excuteJS
=
function
(
args
)
{
try
{
try
{
const
params
=
JSON
.
parse
(
args
);
const
params
=
JSON
.
parse
(
args
);
eventBus
.
emit
<
NativeInvokeFuncParams
>
(
GEEK_NATVIE_NAME
,
params
);
eventBus
.
emit
<
NativeInvokeFuncParams
>
(
GEEK_NATVIE_NAME
,
params
);
}
catch
(
error
)
{
}
catch
(
error
)
{
eventBus
.
emit
<
NativeInvokeFuncParams
>
(
GEEK_NATVIE_NAME
,
args
);
eventBus
.
emit
<
NativeInvokeFuncParams
>
(
GEEK_NATVIE_NAME
,
args
);
}
}
};
};
const
sendNativeMessage
=
(
data
:
{
type
:
string
;
data
:
any
})
=>
{
const
sendNativeMessage
=
(
data
:
{
type
:
string
;
data
:
any
})
=>
{
if
(
isAndroid
())
{
if
(
isAndroid
())
{
window
.
ReactNativeWebView
&&
window
.
ReactNativeWebView
&&
window
.
ReactNativeWebView
.
onMessage
&&
window
.
ReactNativeWebView
.
onMessage
&&
window
.
ReactNativeWebView
.
onMessage
(
JSON
.
stringify
(
data
));
window
.
ReactNativeWebView
.
onMessage
(
JSON
.
stringify
(
data
));
}
}
window
.
ReactNativeWebView
&&
window
.
ReactNativeWebView
&&
window
.
ReactNativeWebView
.
postMessage
&&
window
.
ReactNativeWebView
.
postMessage
&&
window
.
ReactNativeWebView
.
postMessage
(
JSON
.
stringify
(
data
));
window
.
ReactNativeWebView
.
postMessage
(
JSON
.
stringify
(
data
));
};
};
function
useNativeBrid
age
(
function
useNativeBrid
ge
(
eventType
:
string
,
eventType
:
string
,
listener
:
(
this
:
ComponentInternalInstance
|
null
,
...
arg
:
any
[])
=>
any
listener
:
(
this
:
ComponentInternalInstance
|
null
,
...
arg
:
any
[])
=>
any
):
[
typeof
sendNativeMessage
,
typeof
eventBus
]
{
):
[
typeof
sendNativeMessage
,
typeof
eventBus
]
{
const
_listener
=
function
(
this
:
ComponentInternalInstance
|
null
,
arg
?:
NativeInvokeFuncParams
)
{
const
_listener
=
function
(
this
:
ComponentInternalInstance
|
null
,
arg
?:
NativeInvokeFuncParams
)
{
if
(
!
arg
)
return
;
if
(
!
arg
)
return
;
if
(
eventType
===
arg
.
method
)
{
if
(
eventType
===
arg
.
method
)
{
listener
.
apply
(
this
,
[
arg
.
data
]);
listener
.
apply
(
this
,
[
arg
.
data
]);
}
}
};
};
let
fn
:
let
fn
:
|
((
this
:
ComponentInternalInstance
|
null
,
arg
?:
NativeInvokeFuncParams
)
=>
void
)
|
((
this
:
ComponentInternalInstance
|
null
,
arg
?:
NativeInvokeFuncParams
)
=>
void
)
|
null
=
null
;
|
null
=
null
;
onMounted
(()
=>
{
onMounted
(()
=>
{
fn
=
_listener
.
bind
(
getCurrentInstance
());
fn
=
_listener
.
bind
(
getCurrentInstance
());
eventBus
.
on
<
NativeInvokeFuncParams
>
(
GEEK_NATVIE_NAME
,
fn
);
eventBus
.
on
<
NativeInvokeFuncParams
>
(
GEEK_NATVIE_NAME
,
fn
);
});
});
onBeforeUnmount
(()
=>
{
onBeforeUnmount
(()
=>
{
if
(
fn
)
{
if
(
fn
)
{
eventBus
.
off
<
NativeInvokeFuncParams
>
(
GEEK_NATVIE_NAME
,
fn
);
eventBus
.
off
<
NativeInvokeFuncParams
>
(
GEEK_NATVIE_NAME
,
fn
);
}
}
});
});
return
[
sendNativeMessage
,
eventBus
];
return
[
sendNativeMessage
,
eventBus
];
}
}
export
{
useNativeBrid
age
};
export
{
useNativeBrid
ge
};
src/views/test/index.vue
View file @
00d4ebd8
...
@@ -5,9 +5,9 @@
...
@@ -5,9 +5,9 @@
<
script
lang=
"ts"
setup
>
<
script
lang=
"ts"
setup
>
import
{
ref
}
from
"vue"
;
import
{
ref
}
from
"vue"
;
import
{
useNativeBrid
age
}
from
"@/util/use-native-brida
ge"
;
import
{
useNativeBrid
ge
}
from
"@/util/use-native-brid
ge"
;
const
[
sendNativeMessage
,
eventBus
]
=
useNativeBrid
a
ge
(
"bindWechatChange"
,
function
(
arg
)
{
const
[
sendNativeMessage
,
eventBus
]
=
useNativeBridge
(
"bindWechatChange"
,
function
(
arg
)
{
console
.
log
(
this
,
arg
);
console
.
log
(
this
,
arg
);
});
});
const
count
=
ref
(
1000
);
const
count
=
ref
(
1000
);
...
...
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