Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
X
XiTianSenMall
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
leiqingsong
XiTianSenMall
Commits
425b6dfb
Commit
425b6dfb
authored
Mar 13, 2021
by
leiqingsong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
安卓调用
parent
660c1c73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
6 deletions
+20
-6
bridgeToAppFun.js
H5/src/utils/bridgeToAppFun.js
+20
-6
No files found.
H5/src/utils/bridgeToAppFun.js
View file @
425b6dfb
// H5 去调用App的方法
import
jsBridge
from
"./bridge"
;
import
{
getUserInfo
}
from
"@/api/user"
;
function
saveUser
(
data
)
{
localStorage
.
setItem
(
"token"
,
data
);
if
(
data
)
{
getUserInfo
().
then
(
res
=>
{
if
(
res
.
code
===
0
)
{
localStorage
.
setItem
(
"user"
,
JSON
.
stringify
(
res
.
data
));
}
})
}
else
{
console
.
log
(
"调用失败"
);
}
}
// 获取Token
export
function
getAuthToken
()
{
getUserInfo
().
then
()
// return new Promise((resolve, reject) => {
// console.log("调用1");
const
userAgent
=
navigator
.
userAgent
;
if
(
userAgent
.
indexOf
(
'Android'
)
>
-
1
||
userAgent
.
indexOf
(
'Adr'
)
>
-
1
)
{
// android
const
token
=
window
.
android
.
getAuthToken
();
saveUser
(
token
);
}
else
if
(
userAgent
.
match
(
/
\(
i
[^
;
]
+;
(
U;
)?
CPU.+Mac OS X/
))
{
// ios
jsBridge
.
callhandler
(
"getAuthToken"
,
null
,
data
=>
{
console
.
log
(
"调用2"
);
localStorage
.
setItem
(
"token"
,
data
);
...
...
@@ -16,13 +32,11 @@ export function getAuthToken() {
localStorage
.
setItem
(
"user"
,
JSON
.
stringify
(
res
.
data
));
}
})
// resolve(data);
}
else
{
// reject("调用失败,未返回data");
console
.
log
(
"调用失败"
);
}
});
// });
}
}
// 退出
...
...
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