set-page-style-disable-pull-down-refresh.uvue 2.7 KB
Newer Older
1 2 3 4 5
<template>
  <page-head title="getCurrentPages"></page-head>
  <view class="uni-padding-wrap">
    <button class="btn btn-get-page-style" type="default" @click="getPageStyle">getPageStyle</button>
    <button class="btn btn-set-page-style-1" type="default" @click="setPageStyle(true)">setPageStyle(true)</button>
6
    <button class="btn btn-set-page-style-0" type="default" @click="setPageStyle(false)">setPageStyle(false)</button>
7
    <text class="page-style">当前 PageStyle</text>
8 9 10 11
    <text class="page-style-value">{{pageStyleText}}</text>
    <text class="status">状态:</text>
    <view class="status-list">
      <text>enablePullDownRefresh: {{enablePullDownRefreshStatus}}</text>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    </view>
    <text class="tips">当前版本仅支持设置属性 enablePullDownRefresh</text>
  </view>
</template>

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

  export default {
    data() {
      return {
        checked: false,
        pages: [] as Page[],
28 29
        currentPageStyle: {} as UTSJSONObject,
        // TODO
30 31 32 33 34 35 36 37
        enablePullDownRefreshStatus: true
      }
    },
    computed: {
      pageStyleText() : string {
        return JSON.stringify(this.currentPageStyle)
      }
    },
38 39 40 41 42 43
    onLoad() {
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1];
      this.currentPageStyle = currentPage.getPageStyle();
      this.enablePullDownRefreshStatus = this.currentPageStyle["enablePullDownRefresh"] as boolean
    },
44 45 46 47 48 49 50 51 52
    onPullDownRefresh() {
      setTimeout(() => {
        uni.stopPullDownRefresh()
      }, 3000)
    },
    methods: {
      getPageStyle() {
        const pages = getCurrentPages();
        const currentPage = pages[pages.length - 1];
53
        this.currentPageStyle = currentPage.getPageStyle();
54 55 56 57 58
      },
      setPageStyle(enable : boolean) {
        // 目前仅支持 enablePullDownRefresh
        const pages = getCurrentPages();
        const currentPage = pages[pages.length - 1];
59
        currentPage.setPageStyle({
60
          enablePullDownRefresh: enable
61
        });
62
        this.enablePullDownRefreshStatus = enable
63 64 65
      },
      startPullDownRefresh() {
        uni.startPullDownRefresh()
66 67 68 69 70 71 72 73 74
      }
    },
  }
</script>


<style>
  .btn {
    margin-top: 10px;
75 76 77 78
  }

  .page-style {
    margin-top: 15px;
79 80 81 82 83
  }

  .page-style-value {
    margin-top: 5px;
    padding: 5px;
84 85 86 87
    background-color: #fff;
    width: 100%;
    /* #ifdef WEB */
    overflow-wrap: break-word;
雪洛's avatar
雪洛 已提交
88
    /* #endif */
89 90 91 92 93 94 95 96
  }

  .status {
    margin-top: 20px;
  }

  .status-list {
    margin-top: 5px;
97 98 99 100 101 102 103
  }

  .tips {
    font-size: 12px;
    margin-top: 15px;
    opacity: .8;
  }
104
</style>