feat(form): add url params透传和member_id上报功能
1. 为form和formdata页面新增通用URL参数透传逻辑,过滤保留字段后收集参数 2. 处理scene参数中的额外透传参数 3. 提交请求时携带url_params和当前会员ID 4. 修复代码格式问题
This commit is contained in:
@@ -29,7 +29,8 @@
|
||||
detail: null,
|
||||
isRepeat: false,
|
||||
complete: false,
|
||||
scroll:true
|
||||
scroll: true,
|
||||
urlParams: {}
|
||||
};
|
||||
},
|
||||
onLoad(data) {
|
||||
@@ -39,12 +40,27 @@
|
||||
// #endif
|
||||
|
||||
this.id = data.id || 0;
|
||||
|
||||
// 通用 URL 参数收集:除 id/scene 外的所有参数都透传给后端
|
||||
// 后端会做卫生过滤并广播事件,供 recommend 等插件消费
|
||||
const reservedKeys = ['uniacid', 'id', 'scene'];
|
||||
this.urlParams = {};
|
||||
for (let key in data) {
|
||||
if (reservedKeys.indexOf(key) !== -1) continue;
|
||||
this.urlParams[key] = data[key];
|
||||
}
|
||||
|
||||
if (data.scene) {
|
||||
var sceneParams = decodeURIComponent(data.scene);
|
||||
sceneParams = sceneParams.split('&');
|
||||
if (sceneParams.length) {
|
||||
sceneParams.forEach(item => {
|
||||
if (item.indexOf('id') != -1) this.id = item.split('-')[1];
|
||||
// scene 中也可能携带其他参数
|
||||
let pair = item.split('=');
|
||||
if (pair.length === 2 && pair[0] !== 'id') {
|
||||
this.urlParams[pair[0]] = pair[1];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -89,7 +105,9 @@
|
||||
url: '/form/api/form/create',
|
||||
data: {
|
||||
form_id: this.id,
|
||||
form_data: typeof this.$refs.form.formData === 'string' ? this.$refs.form.formData : JSON.stringify(this.$refs.form.formData)
|
||||
form_data: typeof this.$refs.form.formData === 'string' ? this.$refs.form.formData : JSON.stringify(this.$refs.form.formData),
|
||||
url_params: JSON.stringify(this.urlParams),
|
||||
member_id: this.memberInfo ? this.memberInfo.id : 0
|
||||
},
|
||||
success: res => {
|
||||
if (res.code == 0) {
|
||||
@@ -162,4 +180,4 @@
|
||||
bottom: 180rpx !important;
|
||||
/* #endif */
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -43,6 +43,7 @@ export default {
|
||||
uniacid: 0,
|
||||
isFromMpWebView: false, // 是否是从微信小程序的WebView跳转过来的
|
||||
hideNavbar: false, // 查询参数中支持隐藏Navbar
|
||||
urlParams: {}, // 通用 URL 透传参数收集
|
||||
|
||||
// #ifdef H5
|
||||
formTitle: '', // 查询参数传入的Title
|
||||
@@ -92,6 +93,15 @@ export default {
|
||||
this.isFromMpWebView = options.from === 'mp-webview';
|
||||
this.hideNavbar = Boolean(options?.hide_navbar);
|
||||
|
||||
// 通用 URL 参数收集:除业务保留字段外,其余全部透传给后端
|
||||
// 后端会做卫生过滤并广播事件,供 recommend 等插件消费
|
||||
const reservedKeys = ['uniacid', 'id', 'scene', 'from', 'hide_navbar', 'title', 'enable_set_title'];
|
||||
this.urlParams = {};
|
||||
for (let key in options) {
|
||||
if (reservedKeys.indexOf(key) !== -1) continue;
|
||||
this.urlParams[key] = options[key];
|
||||
}
|
||||
|
||||
if (options.scene) {
|
||||
const scene = decodeURIComponent(options.scene)
|
||||
const params = scene.split('&')
|
||||
@@ -99,6 +109,11 @@ export default {
|
||||
if (item.indexOf('id') != -1) {
|
||||
this.id = item.split('-')[1]
|
||||
}
|
||||
// scene 中也可能携带其他参数
|
||||
let pair = item.split('=');
|
||||
if (pair.length === 2 && pair[0] !== 'id') {
|
||||
this.urlParams[pair[0]] = pair[1];
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -162,7 +177,9 @@ export default {
|
||||
data: {
|
||||
form_id: this.id,
|
||||
form_data: typeof formData === 'string' ? formData : JSON.stringify(formData),
|
||||
uniacid: this.uniacid
|
||||
uniacid: this.uniacid,
|
||||
url_params: JSON.stringify(this.urlParams),
|
||||
member_id: this.memberInfo ? this.memberInfo.id : 0
|
||||
},
|
||||
success: res => {
|
||||
if (res.code == 0) {
|
||||
|
||||
Reference in New Issue
Block a user