Commit 26aab41c7fb7a49d46b91f364e7c0ee2a0a18f67

Authored by zhiyangdu
1 parent f3b4f0f5

返回按钮按服务号要求兼容

Showing 1 changed file with 21 additions and 10 deletions
src/pages/mall/mall.vue
... ... @@ -155,16 +155,27 @@ export default {
155 155 /**
156 156 * 后退
157 157 */
158   - back() {
159   - // 判断是否有后退函数
160   - if (typeof this.$parent.back === "function") {
161   - // 调用后退
162   - this.$parent.back();
163   - } else {
164   - // 后退
165   - window.history.go(-1);
166   - }
167   - },
  158 + back() {
  159 +
  160 + // App内
  161 + if (this.isCNLive.value) {
  162 +
  163 + // 调用App,返回按键
  164 + if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.pop) {
  165 +
  166 + // App内,iOS销毁WebView
  167 + window.webkit.messageHandlers.pop.postMessage({body: {}});
  168 + } else if (window.obj && window.obj.finish) {
  169 +
  170 + // App内,Android销毁WebView
  171 + window.obj.finish();
  172 + }
  173 + } else {
  174 +
  175 + // 后退
  176 + window.history.go(-1);
  177 + }
  178 + },
168 179 /**
169 180 * 获取优选库精选活动
170 181 */
... ...