Commit 77d41957 by huangzhi

feat: 增加一个测试页面

parent 8f215cd6
...@@ -6,11 +6,15 @@ let h2Prefix ...@@ -6,11 +6,15 @@ let h2Prefix
let ydlH5Prefix let ydlH5Prefix
if (isDevelopment) { if (isDevelopment) {
hostPrefix = 'https://testnewm.ydl.com' // 开发
// hostPrefix = 'http://192.168.211.138' // hostPrefix = 'https://testnewm.ydl.com'
apiPrefix = 'https://testapi.ydl.com' // // hostPrefix = 'http://192.168.211.138'
// hostPrefix = 'https://newm-test.ydl.com' // 下云 // apiPrefix = 'https://testapi.ydl.com'
// apiPrefix = 'https://api-test.ydl.com' // 下云
// 下云
hostPrefix = 'https://newm-test.ydl.com' // 下云
apiPrefix = 'https://api-test.ydl.com' // 下云
h2Prefix = 'https://h2.yidianling.com' h2Prefix = 'https://h2.yidianling.com'
ydlH5Prefix = 'https://testh5.ydl.com' ydlH5Prefix = 'https://testh5.ydl.com'
} else { } else {
......
...@@ -33,6 +33,12 @@ ...@@ -33,6 +33,12 @@
} }
}, },
{ {
"path": "pages/test/test",
"style": {
"enablePullDownRefresh": false
}
},
{
"path": "pages/login/login", "path": "pages/login/login",
"style": { "style": {
"navigationStyle": "custom", "navigationStyle": "custom",
......
...@@ -119,6 +119,14 @@ export default { ...@@ -119,6 +119,14 @@ export default {
this.logoutVisible = true this.logoutVisible = true
}, },
}, },
{
icon: '/static/icon_order.png',
label: '测试二维码',
callback: () => {
this.handleSendMenuTrackData('测试二维码')
this.navigateToOrder1()
},
},
], ],
logoutVisible: false, logoutVisible: false,
} }
...@@ -158,19 +166,19 @@ export default { ...@@ -158,19 +166,19 @@ export default {
methods: { methods: {
// 菜单项的埋点 // 菜单项的埋点
handleSendMenuTrackData(content) { handleSendMenuTrackData(content) {
setTrackData({ // setTrackData({
events: [ // events: [
{ // {
event_id: 'content_click', // event_id: 'content_click',
event_custom_properties: { // event_custom_properties: {
part: 'ydl_user_my_page', // part: 'ydl_user_my_page',
position: 'other_list', // position: 'other_list',
element: 'other_column', // element: 'other_column',
content, // content,
}, // },
}, // },
], // ],
}) // })
}, },
// 登录点击事件 // 登录点击事件
handleLoginClick() { handleLoginClick() {
...@@ -224,6 +232,24 @@ export default { ...@@ -224,6 +232,24 @@ export default {
url: `/pages/web/web?title=已购订单&loadUrl=${encodeURIComponent(url)}`, url: `/pages/web/web?title=已购订单&loadUrl=${encodeURIComponent(url)}`,
}) })
}, },
// 跳转订单
navigateToOrder1() {
// const aa =
// 'orderId=90230307003008&totalAmount=0.03&balance=9779&payType=5&title=%E6%94%AF%E4%BB%98%E4%B8%AD%E9%97%B4%E9%A1%B5%E9%9D%A2'
// uni.navigateTo({
// url: `/pages/pay/pay`,
// })
if (!this.isLogin) {
this.handleLogin()
return
}
const url = `${hostPrefix}/h5-course/my/components/Buylist`
// const url = `${hostPrefix}/h5-course/detail/7747?uid&accessToken&appId=wx1106c32a36d87d49&isFromMin=weapp&miniType=groupActivity&ffrom=AppletWechatCourseFuLi&timestamp=1678689403156`
uni.navigateTo({
url: `/pages/test/test?title=已购订单&loadUrl=${encodeURIComponent(url)}`,
})
},
}, },
} }
</script> </script>
......
<template>
<!-- <web-view
v-if="!!loadUrl"
:src="loadUrl"
@onPostMessage="handlePostMessage"
@message="handleMessage"
></web-view> -->
<div>
<div>
<span>scene::</span>
<span>{{ cccc }}</span>
</div>
<view @click="handleLoginClick(cccc)">复制到剪切板</view>
<div>-------------</div>
<div>
<span>loadUrl::</span>
<!-- <span>{{ loadUrl }}</span> -->
</div>
<div class="test-url">
{{ loadUrl }}
</div>
<view @click="handleLoginClick(loadUrl)">复制到剪切板</view>
<div>-------------</div>
<div>
<span>options::</span>
<!-- <span>{{ loadUrl }}</span> -->
</div>
<div class="test-url">
{{ JSON.stringify(options) }}
</div>
<view @click="handleLoginClick(JSON.stringify(options))">复制到剪切板</view>
<div>-------------</div>
<!-- <div>
<span>loadUrl::</span>
<span>{{ loadUrl }}</span>
</div> -->
</div>
</template>
<script>
import { hostPrefix } from '@/config.js'
import { ffrom } from '@/utils/enums'
export default {
name: 'WebPage',
data() {
return {
cccc: '1',
loadUrl: '',
options: {},
}
},
onLoad(options) {
// 监听登录成功事件
uni.$on('loginSuccess', this.handleLoginSuccess)
this.options = options || {}
// 设置标题
if (this.options.title) {
uni.setNavigationBarTitle({
title: this.options.title,
})
}
this.cccc = options.scene
// 有scene,说明是扫描二维码进入
if (options.scene) {
uni.showLoading({
title: '加载中',
})
this.getParamsByScene(options.scene)
}
},
// 移除登录成功事件
onUnload() {
uni.$off('loginSuccess', this.handleLoginSuccess)
},
mounted() {
// this.options.scene 无值,说明是非扫描二维码,此时自己拼装路径
if (!this.options.scene) {
this.initWeviewUrl()
}
},
methods: {
// 初始化页面地址
handleLoginClick(data) {
uni.setClipboardData({
data: String(data),
success: function () {
uni.showToast({
title: '复制成功',
duration: 1000,
})
},
})
},
// 设置页面地址额外的通用参数
setCommonUrlParams(pageUrl, urlParmas) {
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(),
...urlParmas,
}
// 更新 url 中的参数
Object.keys(query).forEach(prop => {
url = this.changeURLArg(url, prop, query[prop])
})
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) {
const appId = uni.getAccountInfoSync().miniProgram.appId
try {
const res = await this.$request
.get(`mini/wx/business/${appId}/qrCodeParam?scene=${scene}`)
.finally(() => (this.loading = false))
if (res) {
// https://testnewm.ydl.com/h5-course/detail/7529
const url = `${hostPrefix}/h5-course/detail/${res.productId}`
// productId 商品id
// activityId 拼团活动id
// channel 活动渠道
// recordId 成团id
// shareUid 分享人id
// moreId 待定
const params = ['activityId', 'channel', 'recordId', 'shareUid'].reduce((acc, key) => {
// groupRecordId
if (res[key] || res[key] === 0) {
// 为了保证参数连贯性,使用通用的 groupRecordId
if (key === 'recordId') {
acc['groupRecordId'] = res[key]
} else {
acc[key] = res[key]
}
}
return acc
}, {})
this.loadUrl = this.setCommonUrlParams(`${url}`, params)
console.log(res, '二维码参数解析')
uni.hideLoading()
} else {
uni.showToast({
title: '二维码解析失败',
icon: 'error',
})
uni.hideLoading()
}
} catch (err) {
console.log(err, '<<<<<请求错误')
}
},
// webview向外部发送消息
handlePostMessage: function (data) {
console.log('接收到消息:' + JSON.stringify(data.detail))
},
// webview向外部发送消息
handleMessage: function (data) {
console.log('接收到消息22 Message:' + JSON.stringify(data.detail))
},
// 更新 url 中的参数
changeURLArg(url, arg, value) {
const pattern = arg + '=([^&]*)'
const replaceText = arg + '=' + value
if (url.match(pattern)) {
const exp = new RegExp(`(${arg}=)([^&]*)`, 'gi')
return url.replace(exp, replaceText)
} else {
if (url.match('[\?]')) {
return url + '&' + replaceText
} else {
return url + '?' + replaceText
}
}
},
// 登录成功后重新初始化
handleLoginSuccess() {
this.init()
},
},
}
</script>
<style lang="less" scoped>
.test-url {
overflow: auto;
}
</style>
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