Commit e83ebbf2 by huangzhi

feat: web 二维码解析

parent 8b8a24fe
......@@ -9,11 +9,13 @@
<script>
import { hostPrefix } from '@/config.js'
import { ffrom } from '@/utils/enums'
export default {
name: 'WebPage',
data() {
return {
cccc: '',
loadUrl: '',
options: {},
}
......@@ -29,6 +31,8 @@ export default {
})
}
this.cccc = options.scene
// 有scene,说明是扫描二维码进入
if (options.scene) {
uni.showLoading({
......@@ -42,48 +46,46 @@ export default {
uni.$off('loginSuccess', this.handleLoginSuccess)
},
mounted() {
this.init()
// this.options.scene 无值,说明是非扫描二维码,此时自己拼装路径
if (!this.options.scene) {
this.initWeviewUrl()
}
},
methods: {
// 初始化
init() {
// 判断即将进入的页面是否需要登录
if (this.options.login && !this.$store.getters.isLogin) {
uni.navigateTo({
url: '/pages/login/login?required=1',
})
} else {
// 配置 webview 的 url 地址
let url = decodeURIComponent(this.options.loadUrl || this.options.load_url)
// 设置页面地址额外的通用参数
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,
openId: this.$store.state.user.openId,
isFromMin: 'weapp',
miniType: 'confide',
miniType: 'groupActivity',
ffrom,
timestamp: +new Date(),
}
// 更新 url 中的参数
Object.keys(query).forEach(prop => {
url = this.changeURLArg(url, prop, query[prop])
})
this.loadUrl = url
return url
},
// 初始化页面地址
initWeviewUrl() {
// 判断即将进入的页面是否需要登录
if (this.options.login && !this.$store.getters.isLogin) {
uni.navigateTo({
url: '/pages/login/login?required=1',
})
} else {
this.loadUrl = this.setCommonUrlParams(this.options.loadUrl || this.options.load_url)
console.log(this.loadUrl)
}
},
// 二维码识别进入小程序携带参数 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
try {
const res = await this.$request
......@@ -91,15 +93,11 @@ export default {
.finally(() => (this.loading = false))
if (res) {
this.options.doctorId = res.doctorId
// todo
this.options.courseId = res.courseId || res.doctorId
// https://testnewm.ydl.com/h5-course/detail/7529
const url = `${hostPrefix}/h5-course/detail/${res.doctorId}`
const uid = this.$store.state.user.uid || ''
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}`
const url = `${hostPrefix}/h5-course/detail/${res.courseId || res.doctorId}`
this.loadUrl = this.setCommonUrlParams(`${url}`)
console.log(res, '二维码参数解析')
uni.hideLoading()
......
......@@ -63,3 +63,5 @@ export const goodDirection = {
{ id: 9, name: '个人成长' },
],
}
export const ffrom = 'AppletWechatCourseFuLi'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment