Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl-group-course
Overview
Overview
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
黄志
ydl-group-course
Commits
e83ebbf2
Commit
e83ebbf2
authored
Mar 13, 2023
by
huangzhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: web 二维码解析
parent
8b8a24fe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
36 deletions
+36
-36
web.vue
src/pages/web/web.vue
+34
-36
enums.js
src/utils/enums.js
+2
-0
No files found.
src/pages/web/web.vue
View file @
e83ebbf2
...
@@ -9,11 +9,13 @@
...
@@ -9,11 +9,13 @@
<
script
>
<
script
>
import
{
hostPrefix
}
from
'@/config.js'
import
{
hostPrefix
}
from
'@/config.js'
import
{
ffrom
}
from
'@/utils/enums'
export
default
{
export
default
{
name
:
'WebPage'
,
name
:
'WebPage'
,
data
()
{
data
()
{
return
{
return
{
cccc
:
''
,
loadUrl
:
''
,
loadUrl
:
''
,
options
:
{},
options
:
{},
}
}
...
@@ -29,6 +31,8 @@ export default {
...
@@ -29,6 +31,8 @@ export default {
})
})
}
}
this
.
cccc
=
options
.
scene
// 有scene,说明是扫描二维码进入
// 有scene,说明是扫描二维码进入
if
(
options
.
scene
)
{
if
(
options
.
scene
)
{
uni
.
showLoading
({
uni
.
showLoading
({
...
@@ -42,48 +46,46 @@ export default {
...
@@ -42,48 +46,46 @@ export default {
uni
.
$off
(
'loginSuccess'
,
this
.
handleLoginSuccess
)
uni
.
$off
(
'loginSuccess'
,
this
.
handleLoginSuccess
)
},
},
mounted
()
{
mounted
()
{
this
.
init
()
// this.options.scene 无值,说明是非扫描二维码,此时自己拼装路径
if
(
!
this
.
options
.
scene
)
{
this
.
initWeviewUrl
()
}
},
},
methods
:
{
methods
:
{
// 初始化
// 设置页面地址额外的通用参数
init
()
{
setCommonUrlParams
(
pageUrl
)
{
let
url
=
decodeURIComponent
(
pageUrl
)
const
query
=
{
uid
:
this
.
$store
.
state
.
user
.
uid
||
''
,
accessToken
:
this
.
$store
.
state
.
user
.
accessToken
||
''
,
appId
:
uni
.
getAccountInfoSync
().
miniProgram
.
appId
,
isFromMin
:
'weapp'
,
miniType
:
'groupActivity'
,
ffrom
,
timestamp
:
+
new
Date
(),
}
// 更新 url 中的参数
Object
.
keys
(
query
).
forEach
(
prop
=>
{
url
=
this
.
changeURLArg
(
url
,
prop
,
query
[
prop
])
})
return
url
},
// 初始化页面地址
initWeviewUrl
()
{
// 判断即将进入的页面是否需要登录
// 判断即将进入的页面是否需要登录
if
(
this
.
options
.
login
&&
!
this
.
$store
.
getters
.
isLogin
)
{
if
(
this
.
options
.
login
&&
!
this
.
$store
.
getters
.
isLogin
)
{
uni
.
navigateTo
({
uni
.
navigateTo
({
url
:
'/pages/login/login?required=1'
,
url
:
'/pages/login/login?required=1'
,
})
})
}
else
{
}
else
{
// 配置 webview 的 url 地址
this
.
loadUrl
=
this
.
setCommonUrlParams
(
this
.
options
.
loadUrl
||
this
.
options
.
load_url
)
let
url
=
decodeURIComponent
(
this
.
options
.
loadUrl
||
this
.
options
.
load_url
)
const
query
=
{
uid
:
this
.
$store
.
state
.
user
.
uid
||
''
,
accessToken
:
this
.
$store
.
state
.
user
.
accessToken
||
''
,
appId
:
uni
.
getAccountInfoSync
().
miniProgram
.
appId
,
openId
:
this
.
$store
.
state
.
user
.
openId
,
isFromMin
:
'weapp'
,
miniType
:
'confide'
,
timestamp
:
+
new
Date
(),
}
// 更新 url 中的参数
Object
.
keys
(
query
).
forEach
(
prop
=>
{
url
=
this
.
changeURLArg
(
url
,
prop
,
query
[
prop
])
})
this
.
loadUrl
=
url
console
.
log
(
this
.
loadUrl
)
console
.
log
(
this
.
loadUrl
)
}
}
},
},
// 二维码识别进入小程序携带参数 scene 需要通过接口解析具体数据
// 二维码识别进入小程序携带参数 scene 需要通过接口解析具体数据
async
getParamsByScene
(
scene
)
{
async
getParamsByScene
(
scene
)
{
// 扫码进入页面时需要判断是否存有当前用户的openId,若不存在则等待接口响应
if
(
!
this
.
$store
.
state
.
user
.
openId
)
{
const
timer
=
setTimeout
(()
=>
{
this
.
getParamsByScene
(
scene
)
clearTimeout
(
timer
)
},
300
)
return
}
const
appId
=
uni
.
getAccountInfoSync
().
miniProgram
.
appId
const
appId
=
uni
.
getAccountInfoSync
().
miniProgram
.
appId
try
{
try
{
const
res
=
await
this
.
$request
const
res
=
await
this
.
$request
...
@@ -91,15 +93,11 @@ export default {
...
@@ -91,15 +93,11 @@ export default {
.
finally
(()
=>
(
this
.
loading
=
false
))
.
finally
(()
=>
(
this
.
loading
=
false
))
if
(
res
)
{
if
(
res
)
{
this
.
options
.
doctorId
=
res
.
doctorId
// todo
this
.
options
.
courseId
=
res
.
courseId
||
res
.
doctorId
// https://testnewm.ydl.com/h5-course/detail/7529
// https://testnewm.ydl.com/h5-course/detail/7529
const
url
=
`
${
hostPrefix
}
/h5-course/detail/
${
res
.
doctorId
}
`
const
url
=
`
${
hostPrefix
}
/h5-course/detail/
${
res
.
courseId
||
res
.
doctorId
}
`
const
uid
=
this
.
$store
.
state
.
user
.
uid
||
''
this
.
loadUrl
=
this
.
setCommonUrlParams
(
`
${
url
}
`
)
const
accessToken
=
this
.
$store
.
state
.
user
.
accessToken
||
''
const
appId
=
uni
.
getAccountInfoSync
().
miniProgram
.
appId
const
openId
=
this
.
$store
.
state
.
user
.
openId
const
query
=
`uid=
${
uid
}
&accessToken=
${
accessToken
}
&isFromMin=weapp&appId=
${
appId
}
&openId=
${
openId
}
`
this
.
loadUrl
=
`
${
url
}
?
${
query
}
`
console
.
log
(
res
,
'二维码参数解析'
)
console
.
log
(
res
,
'二维码参数解析'
)
uni
.
hideLoading
()
uni
.
hideLoading
()
...
...
src/utils/enums.js
View file @
e83ebbf2
...
@@ -63,3 +63,5 @@ export const goodDirection = {
...
@@ -63,3 +63,5 @@ export const goodDirection = {
{
id
:
9
,
name
:
'个人成长'
},
{
id
:
9
,
name
:
'个人成长'
},
],
],
}
}
export
const
ffrom
=
'AppletWechatCourseFuLi'
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