Commit 04104c20 by 李嘉林

feat: 优化

parent 2afaa98a
......@@ -65,7 +65,8 @@ export default {
let pageUrl1 = (this.page.startsWith('http://') || this.page.startsWith('https://'))? (this.page + this.params) : this.link+this.page+this.params
let pageUrl = forUrlAddKey(decodeURIComponent(pageUrl1));
console.log(pageUrl,'--pageUrl')
return pageUrl + this.ss + this.timestamp;
let newPageUrl = this.removeEmptyQueryParams(pageUrl + this.ss + this.timestamp);
return newPageUrl;
}
},
onLoad(options) {
......@@ -122,7 +123,7 @@ export default {
});
}
}
this.pageUrl1 = this.pageUrl;
this.pageUrl1 = this.removeEmptyQueryParams(this.pageUrl);
},
onShow(){
console.log('--onShow--')
......@@ -141,7 +142,7 @@ export default {
setTimeout(() => {
this.showPage = true;
}, 0);
this.pageUrl1 = this.pageUrl + `&tim=${new Date().getTime()}`
this.pageUrl1 = this.removeEmptyQueryParams(this.pageUrl + `&tim=${new Date().getTime()}`)
wx.removeStorageSync("reloadTabbarPage");
console.log(this.pageUrl1,'--this.pageUrl1')
}
......@@ -155,6 +156,31 @@ export default {
getMessage(res) {
this.$emit("getMessage",res);
},
// 将多余的参数删除: ?abc=&cba=1 => ?cba=1
removeEmptyQueryParams(url) {
try {
// 分割URL,分离基础URL和查询字符串
const [baseUrl, queryPart] = url.split('?');
// 若没有查询字符串,直接返回基础URL
if (!queryPart) return baseUrl;
// 分割查询字符串为参数数组
const queryParams = queryPart.split('&');
// 过滤掉空值参数
const filteredParams = queryParams.filter(param => {
const [key, value] = param.split('=');
return value;
});
// 重新组合查询字符串并附加到基础URL上
const cleanedQuery = filteredParams.join('&');
return baseUrl + (cleanedQuery ? `?${cleanedQuery}` : '');
} catch (err) {
console.log('parseUrlError:', err);
return url;
}
}
},
};
</script>
\ No newline at end of file
......@@ -479,6 +479,11 @@ export default {
employeeId: paramsObj.setGuideEmployeeId,
})
}
} else {
// 不是导购进入移除参数
wx.removeStorageSync(this.$store.state.mixid+'setGuideEmployeeId');
wx.removeStorageSync(this.$store.state.mixid+'guide_QRCodeType');
wx.removeStorageSync(this.$store.state.mixid+'temp_QRCodeType');
}
if (paramsObj.QRCodeType) {
wx.setStorageSync(this.$store.state.mixid+'guide_QRCodeType', paramsObj.QRCodeType);
......
......@@ -374,10 +374,15 @@ export default {
// 判断是否为导购分享进入
if (paramsObj.setGuideEmployeeId) {
wx.setStorageSync(this.$store.state.mixid + 'setGuideEmployeeId', paramsObj.setGuideEmployeeId);
}
if (paramsObj.QRCodeType) {
wx.setStorageSync(this.$store.state.mixid+'guide_QRCodeType', paramsObj.QRCodeType);
wx.setStorageSync(this.$store.state.mixid+'temp_QRCodeType', paramsObj.QRCodeType);
if (paramsObj.QRCodeType) {
wx.setStorageSync(this.$store.state.mixid+'guide_QRCodeType', paramsObj.QRCodeType);
wx.setStorageSync(this.$store.state.mixid+'temp_QRCodeType', paramsObj.QRCodeType);
}
} else {
// 非导购方式进入移除本地缓存
wx.removeStorageSync(this.$store.state.mixid+'setGuideEmployeeId');
wx.removeStorageSync(this.$store.state.mixid+'guide_QRCodeType');
wx.removeStorageSync(this.$store.state.mixid+'temp_QRCodeType');
}
wx.setStorageSync('attractingCustomerChannelId',paramsObj.attractingCustomerChannelId);
wx.setStorageSync(this.$store.state.mixid+'storeId',paramsObj.storeId);
......
......@@ -212,13 +212,13 @@ export default {
if (wx.getStorageSync("_ma_sid")) {
this.link += `&_ma_sid=${wx.getStorageSync("_ma_sid")}`;
}
this.useLink = this.link;
this.useLink = this.removeEmptyQueryParams(this.link);
console.log(this.useLink,'--this.useLink')
},
},
methods: {
setLink(data) {
this.link = data;
this.link = this.removeEmptyQueryParams(data);
console.log(this.useLink,89999999)
},
getSsoBcakUrl(link) {
......@@ -290,6 +290,31 @@ export default {
title: "网页加载失败 请右上角刷新",
});
},
// 将多余的参数删除: ?abc=&cba=1 => ?cba=1
removeEmptyQueryParams(url) {
try {
// 分割URL,分离基础URL和查询字符串
const [baseUrl, queryPart] = url.split('?');
// 若没有查询字符串,直接返回基础URL
if (!queryPart) return baseUrl;
// 分割查询字符串为参数数组
const queryParams = queryPart.split('&');
// 过滤掉空值参数
const filteredParams = queryParams.filter(param => {
const [key, value] = param.split('=');
return value;
});
// 重新组合查询字符串并附加到基础URL上
const cleanedQuery = filteredParams.join('&');
return baseUrl + (cleanedQuery ? `?${cleanedQuery}` : '');
} catch (err) {
console.log('parseUrlError:', err);
return url;
}
}
},
};
</script>
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