天天看點

【快應用】快應用使用者協定、隐私政策内容中可以多次跳轉,點選傳回未能傳回上一級頁面,該如何處理?

 【現象描述】

使用者協定和隐私政策内容中有連結跳轉,多次跳轉後,點選左上角傳回後,不會傳回到上一級連結頁面,而是傳回到使用者協定和隐私政策頁面

【問題分析】

進行多次連結跳轉後,點選傳回,直接傳回到使用者協定和隐私政策頁面,是因為是在同一個頁面實作的跳轉,沒有對傳回鍵進行事件處理

【解決辦法】

需要處理傳回鍵事件,以實作點選傳回鍵傳回上一頁面

onBackPress() {
            this.$element('web').canBack({
                callback: function (e) {
                    if (e) {
                        this.$element('web').back();
                    } else {
                        router.back();
                    }
                }.bind(this)
            });
            return true;
        },      
【快應用】快應用使用者協定、隐私政策内容中可以多次跳轉,點選傳回未能傳回上一級頁面,該如何處理?

代碼如下

service.ux

<template>
  <web id="web" src="{{openUrl}}"></web>
</template>
<script>
    import router from '@system.router'
    export default {
        public: {
            openUrl: '',
            menuTitle: ''
        },
        onInit() {
            let { openUrl, menuTitle } = this
            this.openUrl = openUrl
            this.$page.setTitleBar({ text: menuTitle, textColor: '#000', backgroundColor: '#FFFFFF', backgroundOpacity: 0.5, menu: true })
        },
        onBackPress() {
            this.$element('web').canBack({
                callback: function (e) {
                    if (e) {
                        this.$element('web').back();
                    } else {
                        router.back();
                    }
                }.bind(this)
            });
            return true;
        },
 
    }
</script>      
【快應用】快應用使用者協定、隐私政策内容中可以多次跳轉,點選傳回未能傳回上一級頁面,該如何處理?

userAgreement.ux

<template>
  <div class="label">
    <div class="content">
      <div class="title"><text>使用者協定和隐私政策</text></div>
 
      <list class="content-warp">
        <list-item class="first-line" type="list-item">
          <text>歡迎使用快應用:</text>
        </list-item>
 
        <list-item class="primary-line" type="list-item-content">
          <text>我們鄭重承諾重視并保護使用者的個人資訊。我們秉承“一切以使用者價值為依歸”的理念,增強您對資訊管理的便捷性,保障您的資訊及通信安全。我們嚴格遵守法律法規,遵循以下隐私保護原則,為您提供更加安全、可靠的服務。</text>
          <text>
            點選“同意”,即表示您同意上述内容及
            <a @click="openPage(1)" class="service">《使用者協定》</a>
            與
            <a @click="openPage(2)" class="service">《隐私政策》</a>
          </text>
        </list-item>
      </list>
      <div @click="agree" class="handle-btn">
        <text>同意</text>
      </div>
      <div @click="cancel" class="disagree-btn">
        <text>不同意</text>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    onInit() {
 
    },
    openPage(flag) {
      this.$emit('openServicePage', { flag })
    },
    agree() {
      this.$dispatch("dispatchEvent", {
        display: false,
        isagree: "agree"
      });
    },
    cancel() {
      this.$app.exit();
    }
  }
</script>
 
<style lang="less">
  .content {
    padding: 30px;
    border-radius: 12px;
    width: 600px;
    flex-direction: column;
    align-items: center;
    background-color: #fff;
    .title {
      text {
        font-weight: bold;
        color: #000000;
        font-size: 36px;
      }
    }
    .content-warp {
      height: 500px;
      flex-direction: column;
      .service {
        color: #007aff;
        text-decoration: underline;
      }
      .first-line {
        flex-direction: column;
        text {
          font-weight: bold;
          color: #000000;
          font-size: 32px;
        }
      }
      .primary-line {
        flex-direction: column;
        text {
          text-indent: 40px;
        }
      }
    }
    .handle-btn {
      width: 474px;
      height: 82px;
      border-radius: 41px;
      justify-content: center;
      align-items: center;
      background-color: #d63016;
      margin-top: 30px;
      text {
        font-weight: 600;
        color: #fff;
        font-size: 34px;
      }
    }
    .disagree-btn {
      margin-top: 30px;
      text {
        font-weight: 600;
        font-size: 34px;
      }
    }
  }
  .label {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
</style>      
【快應用】快應用使用者協定、隐私政策内容中可以多次跳轉,點選傳回未能傳回上一級頁面,該如何處理?
<import name="userAgreement" src="./UserAgreement/userAgreement.ux"></import>
<template>
  <!-- Only one root node is allowed in template. -->
  <div class="container">
    <stack>
      <text class="title" onclick="save">Hello World</text>
      <block if="{{ display }}">
        <userAgreement onopen-service-page="openServicePage"></userAgreement>
      </block>
    </stack>
  </div>
</template>
<style>.container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color:#d39b75;
  }
  .title {
    font-size:100px;
  }</style>
<script>"@system.storage";
  import router from '@system.router'
  module.exports = {
    private: {
      display: false,
      isagree: "disagree"
    },
    onInit() {
      this.$page.setTitleBar({
        text: "hello",
        textColor: "#ffffff",
        backgroundColor: "#007DFF",
        backgroundOpacity: 0.5,
        menu: true
      });
    },
    openServicePage({ detail: { flag } }) {
      let openUrl, menuTitle
      switch (flag) {
        case 1:
          openUrl = '*'
          menuTitle = '使用者協定'
          break;
        case 2:
          openUrl = '*'
          menuTitle = '隐私政策'
          break;
        default:
          break;
      }
 
      router.push({
        uri: 'Hello/Service',
        params: {
          openUrl,
          menuTitle
        }
      })
    },
    onShow(options) {
      var that = this;
      that.get()
      setTimeout(() => {
        if (that.isagree === "agree") {
          that.display = false;
        } else {
          setTimeout(() => {
            that.display = true;
          }, 100);
        }
      }, 500);
      console.log("message:", that.isagree);
      this.$on("dispatchEvent", this.dispatchEvent);
    },
    dispatchEvent(evt) {
      this.display = evt.detail.display;
      this.isagree = evt.detail.isagree;
      this.save(this.isagree);
    },
    save(params) {
      storage.set({
        key: "agreeFlag",
        value: params,
        success: function (data)
          console.log("handling success");
        },
        fail: function (data, code)
          console.log("handling fail, code = " + code);
        }
      });
    },
    get() {
      var that = this;
      storage.get({
        key: "agreeFlag",
        success: function (data)
          that.isagree = data;
          console.log("handling success", data);
        },
        fail: function (data, code)
          console.log("handling fail, code = "</script>