From 107b5dd71b1684d9c2d965588674169707d0b7e3 Mon Sep 17 00:00:00 2001
From: ZF sun <34314687@qq.com>
Date: Mon, 25 May 2026 14:06:17 +0800
Subject: [PATCH] =?UTF-8?q?fix(webview):=20=E4=BF=AE=E5=A4=8Durl=E5=AE=9E?=
=?UTF-8?q?=E4=BD=93=E7=BC=96=E7=A0=81=E6=9C=AA=E8=A7=A3=E7=A0=81=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
1. 新增HTML实体解码工具函数decodeEntity
2. 在webview页面和跳转逻辑中调用该函数解码url参数
3. 统一格式化代码缩进风格
---
common/js/util.js | 68 ++++++++++++++++++++++++----------
pages_tool/webview/webview.vue | 6 ++-
2 files changed, 52 insertions(+), 22 deletions(-)
diff --git a/common/js/util.js b/common/js/util.js
index e831c80..8373949 100644
--- a/common/js/util.js
+++ b/common/js/util.js
@@ -5,6 +5,32 @@ import {
Weixin
} from 'common/js/wx-jssdk.js';
+//
+export function decodeEntity(str, amp) {
+ const html4Entities = {
+ nbsp: ' ', iexcl: '¡', cent: '¢', pound: '£', curren: '₣', yen: '¥', brvbar: '§', sect: 'Ş', uml: '¨', copy: '©', ordf: 'ª', laquo: '«', not: '¬', shy: '®', macr: '¯', deg: '°', plusmn: '±', sup2: '²', sup3: '³', acute: '´', micro: 'µ', para: '¶', middot: '·', cedil: '¸', sup1: '¹', ordm: 'º', raquo: '»', frac14: '¼', frac12: '½', frac34: '¾', iquest: '¿', agrave: 'à', aacute: 'á', acirc: 'â', atilde: 'ã', auml: 'ä', aring: 'å', aelig: 'æ', ccedil: 'ç', egrave: 'è', eacute: 'é', ecirc: 'ê', euml: 'ë', igrave: 'ì', iacute: 'í', icirc: 'î', iuml: 'ï', eth: 'ð', ntilde: 'ñ', ograve: 'ò', oacute: 'ó', ocirc: 'ô', otilde: 'õ', ouml: 'ö', times: 'ø', ugrave: 'ù', uacute: 'ú', ucirc: 'û', uuml: 'ü', yacute: 'ý', thorn: 'þ', yuml: 'ÿ', fnof: 'ƒ', alpha: 'α', beta: 'β', gamma: 'γ', delta: 'δ', epsilon: 'ε', zeta: 'ζ', eta: 'η', theta: 'θ', iota: 'ι', kappa: 'κ', lambda: 'λ', mu: 'μ', nu: 'ν', xi: 'ξ', omicron: 'ο', pi: 'π', rho: 'ρ', sigmaf: 'σ', sigma: 'σ', tau: 'τ', upsilon: 'υ', phi: 'φ', chi: 'ψ', omega: 'ω'
+ }
+ amp = amp === undefined ? true : amp
+ let i = str.indexOf('&')
+ while (i !== -1) {
+ const j = str.indexOf(';', i + 3)
+ let code
+ if (j === -1) break
+ if (str[i + 1] === '#') {
+ code = parseInt((str[i + 2] === 'x' ? '0' : '') + str.substring(i + 2, j))
+ if (!isNaN(code)) {
+ str = str.substring(0, i) + String.fromCharCode(code) + str.substring(j + 1)
+ }
+ } else {
+ code = str.substring(i + 1, j)
+ if (html4Entities[code] || (code === 'amp' && amp)) {
+ str = str.substring(0, i) + (html4Entities[code] || '&') + str.substring(j + 1)
+ }
+ }
+ i = str.indexOf('&', i + 1)
+ }
+ return str
+}
// 关于页面路径,使用常量导出
@@ -635,8 +661,10 @@ export default {
* @param {Object} link
*/
diyRedirectTo(link) {
-
//if (link == null || Object.keys(link).length == 1) return;
+ if (link.wap_url) {
+ link.wap_url = decodeEntity(link.wap_url);
+ }
// 外部链接
if (link.wap_url && link.wap_url.indexOf('http') != -1) {
@@ -902,11 +930,11 @@ export default {
},
success: res => {
if (res.code >= 0) {
- uni.removeStorage({
- key: 'source_member',
- success: res => {
- }
- })
+ uni.removeStorage({
+ key: 'source_member',
+ success: res => {
+ }
+ })
}
}
})
@@ -930,23 +958,23 @@ export default {
success: res => {
if (res.data.length) {
// #ifdef MP-WEIXIN
- uni.requestSubscribeMessage({
- tmplIds: res.data,
- success: (res) => {
- },
- fail: (res) => {
- }
- })
+ uni.requestSubscribeMessage({
+ tmplIds: res.data,
+ success: (res) => {
+ },
+ fail: (res) => {
+ }
+ })
// #endif
// #ifdef MP-ALIPAY
- my.requestSubscribeMessage({
- entityIds: res.data,
- success: res => {
- },
- fail: res => {
- }
- });
+ my.requestSubscribeMessage({
+ entityIds: res.data,
+ success: res => {
+ },
+ fail: res => {
+ }
+ });
// #endif
}
}
diff --git a/pages_tool/webview/webview.vue b/pages_tool/webview/webview.vue
index af80af0..36ad4d3 100644
--- a/pages_tool/webview/webview.vue
+++ b/pages_tool/webview/webview.vue
@@ -3,12 +3,14 @@
-
+