get-current-pages.uvue 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<template>
  <page-head title="getCurrentPages"></page-head>
  <view class="uni-padding-wrap">
    <button @click="_getCurrentPages">getCurrentPages</button>
    <view v-if="pages.length" style="padding: 15px 0px">
      <text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
      <template v-for="(page, index) in pages" :key="page.route">
        <text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text>
      </template>
    </view>
H
hdx 已提交
11
    <button class="btn btn-get-page-style" type="default" @click="getPageStyle">getPageStyle</button>
12
    <button class="btn btn-set-page-style-1" type="default" @click="setPageStyle(true)">setPageStyle(true)</button>
H
hdx 已提交
13 14 15 16 17 18 19 20
    <button class="btn btn-set-page-style-0" type="default" @click="setPageStyle(false)">setPageStyle(false)</button>
    <text class="page-style">当前 PageStyle</text>
    <text class="page-style-value">{{pageStyleText}}</text>
    <text class="status">状态:</text>
    <view class="status-list">
      <text>enablePullDownRefresh: {{enablePullDownRefreshStatus}}</text>
    </view>
    <text class="tips">当前版本仅支持设置属性 enablePullDownRefresh</text>
21 22 23 24 25 26 27 28 29 30 31 32 33 34
  </view>
</template>

<script>
  class Page {
    constructor(public route : string) {
    }
  }

  export default {
    data() {
      return {
        checked: false,
        pages: [] as Page[],
H
hdx 已提交
35
        currentPageStyle: {} as UTSJSONObject,
36
        currentPageStyleIsUTSJSONObject: true,
H
hdx 已提交
37 38
        // TODO
        enablePullDownRefreshStatus: true
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
      }
    },
    computed: {
      pageStyleText() : string {
        return JSON.stringify(this.currentPageStyle)
      }
    },
    onPullDownRefresh() {
      setTimeout(() => {
        uni.stopPullDownRefresh()
      }, 3000)
    },
    methods: {
      _getCurrentPages: function () {
        this.pages.length = 0
        const pages = getCurrentPages()
        this.pages.push(new Page(pages[0].route))
        if (this.pages[0].route.includes('/tabBar/')) {
          this.checked = true
        }
        for (let i = 1; i < pages.length; i++) {
          this.pages.push(new Page(pages[i].route))
          if (pages[i].route.includes('/tabBar/')) {
            this.checked = false
          }
        }
      },
      getPageStyle() {
        const pages = getCurrentPages();
        const currentPage = pages[pages.length - 1];
69 70
        this.currentPageStyle = currentPage.$getPageStyle();
        this.currentPageStyleIsUTSJSONObject = this.currentPageStyle instanceof UTSJSONObject
71
      },
H
hdx 已提交
72
      setPageStyle(enable : boolean) {
73 74 75 76
        // 目前仅支持 enablePullDownRefresh
        const pages = getCurrentPages();
        const currentPage = pages[pages.length - 1];
        currentPage.$setPageStyle({
H
hdx 已提交
77 78 79
          enablePullDownRefresh: enable
        });
        this.enablePullDownRefreshStatus = enable
80 81 82 83
      },
      startPullDownRefresh() {
        uni.startPullDownRefresh()
      }
84 85 86 87 88 89 90 91 92 93 94 95 96
      // getCurrentPage(): Page {
      //   const pages = getCurrentPages();
      //   const currentPage = pages[pages.length - 1];
      //   return currentPage;
      // }
    },
  }
</script>


<style>
  .btn {
    margin-top: 10px;
H
hdx 已提交
97 98 99 100
  }

  .page-style {
    margin-top: 15px;
101 102
  }

H
hdx 已提交
103
  .page-style-value {
104 105
    margin-top: 5px;
    padding: 5px;
H
hdx 已提交
106
    background-color: #fff;
雪洛's avatar
雪洛 已提交
107 108
    width: 100%;
    /* #ifdef WEB */
雪洛's avatar
雪洛 已提交
109
    overflow-wrap: break-word;
雪洛's avatar
雪洛 已提交
110
    /* #endif */
H
hdx 已提交
111 112 113 114 115 116 117 118
  }

  .status {
    margin-top: 20px;
  }

  .status-list {
    margin-top: 5px;
119 120 121 122
  }

  .tips {
    font-size: 12px;
H
hdx 已提交
123
    margin-top: 15px;
124 125 126
    opacity: .8;
  }
</style>