fix(webview): 修复url实体编码未解码的问题
1. 新增HTML实体解码工具函数decodeEntity 2. 在webview页面和跳转逻辑中调用该函数解码url参数 3. 统一格式化代码缩进风格
This commit is contained in:
@@ -5,6 +5,32 @@ import {
|
|||||||
Weixin
|
Weixin
|
||||||
} from 'common/js/wx-jssdk.js';
|
} 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
|
* @param {Object} link
|
||||||
*/
|
*/
|
||||||
diyRedirectTo(link) {
|
diyRedirectTo(link) {
|
||||||
|
|
||||||
//if (link == null || Object.keys(link).length == 1) return;
|
//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) {
|
if (link.wap_url && link.wap_url.indexOf('http') != -1) {
|
||||||
@@ -902,11 +930,11 @@ export default {
|
|||||||
},
|
},
|
||||||
success: res => {
|
success: res => {
|
||||||
if (res.code >= 0) {
|
if (res.code >= 0) {
|
||||||
uni.removeStorage({
|
uni.removeStorage({
|
||||||
key: 'source_member',
|
key: 'source_member',
|
||||||
success: res => {
|
success: res => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -930,23 +958,23 @@ export default {
|
|||||||
success: res => {
|
success: res => {
|
||||||
if (res.data.length) {
|
if (res.data.length) {
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
uni.requestSubscribeMessage({
|
uni.requestSubscribeMessage({
|
||||||
tmplIds: res.data,
|
tmplIds: res.data,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
},
|
},
|
||||||
fail: (res) => {
|
fail: (res) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef MP-ALIPAY
|
// #ifdef MP-ALIPAY
|
||||||
my.requestSubscribeMessage({
|
my.requestSubscribeMessage({
|
||||||
entityIds: res.data,
|
entityIds: res.data,
|
||||||
success: res => {
|
success: res => {
|
||||||
},
|
},
|
||||||
fail: res => {
|
fail: res => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { decodeEntity } from '@/common/js/util.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -16,7 +18,7 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
this.src = decodeURIComponent(option.src);
|
this.src = decodeEntity(decodeURIComponent(option.src));
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
navigateBack() {
|
navigateBack() {
|
||||||
|
|||||||
Reference in New Issue
Block a user