Commit e83ebbf2 by huangzhi

feat: web 二维码解析

parent 8b8a24fe
...@@ -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)
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)
const query = { const query = {
uid: this.$store.state.user.uid || '', uid: this.$store.state.user.uid || '',
accessToken: this.$store.state.user.accessToken || '', accessToken: this.$store.state.user.accessToken || '',
appId: uni.getAccountInfoSync().miniProgram.appId, appId: uni.getAccountInfoSync().miniProgram.appId,
openId: this.$store.state.user.openId,
isFromMin: 'weapp', isFromMin: 'weapp',
miniType: 'confide', miniType: 'groupActivity',
ffrom,
timestamp: +new Date(), timestamp: +new Date(),
} }
// 更新 url 中的参数 // 更新 url 中的参数
Object.keys(query).forEach(prop => { Object.keys(query).forEach(prop => {
url = this.changeURLArg(url, prop, query[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) 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()
......
...@@ -63,3 +63,5 @@ export const goodDirection = { ...@@ -63,3 +63,5 @@ export const goodDirection = {
{ id: 9, name: '个人成长' }, { 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