index.vue 4.6 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
<template>
  <uni-page :data-page="$route.meta.pagePath">
3 4
    <page-head
      v-if="showNavigationBar"
fxy060608's avatar
fxy060608 已提交
5
      v-bind="navigationBar" />
6 7 8 9
    <page-refresh
      v-if="enablePullDownRefresh"
      ref="refresh"
      :color="refreshOptions.color"
fxy060608's avatar
fxy060608 已提交
10
      :offset="refreshOptions.offset" />
11 12 13
    <page-body
      v-if="enablePullDownRefresh"
      @touchstart.native="_touchstart"
fxy060608's avatar
fxy060608 已提交
14
      @touchmove.native="_touchmove"
15
      @touchend.native="_touchend"
fxy060608's avatar
fxy060608 已提交
16 17 18 19 20 21 22 23 24
      @touchcancel.native="_touchend">
      <slot name="page" />
    </page-body>
    <page-body v-else>
      <slot name="page" />
    </page-body>
  </uni-page>
</template>
<style>
25 26 27 28 29
    uni-page {
        display: block;
        width: 100%;
        height: 100%;
    }
fxy060608's avatar
fxy060608 已提交
30 31 32 33
</style>
<script>
import {
  upx2px
fxy060608's avatar
fxy060608 已提交
34
} from 'uni-helpers/index'
fxy060608's avatar
fxy060608 已提交
35 36 37 38 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

import {
  NAVBAR_HEIGHT
} from 'uni-helpers/constants'

import {
  mergeTitleNView
} from 'uni-helpers/patch'

import PageHead from './pageHead'
import PageBody from './pageBody'
import PageRefresh from './pageRefresh'

import pullToRefresh from './pull-to-refresh'

export default {
  name: 'Page',
  mpType: 'page',
  components: {
    PageHead,
    PageBody,
    PageRefresh
  },
  mixins: [pullToRefresh],
  props: {
    isQuit: {
      type: Boolean,
      default: false
    },
    isEntry: {
      type: Boolean,
      default: false
    },
    isTabBar: {
      type: Boolean,
      default: false
    },
    tabBarIndex: {
      type: Number,
      default: -1
    },
    navigationBarBackgroundColor: {
      type: String,
      default: '#000'
    },
    navigationBarTextStyle: {
      default: 'white',
      validator (value) {
        return ['white', 'black'].indexOf(value) !== -1
      }
    },
    navigationBarTitleText: {
      type: String,
      default: ''
    },
    navigationStyle: {
      default: 'default',
      validator (value) {
        return ['default', 'custom'].indexOf(value) !== -1
      }
    },
    backgroundColor: {
      type: String,
      default: '#ffffff'
    },
    backgroundTextStyle: {
      default: 'dark',
      validator (value) {
        return ['dark', 'light'].indexOf(value) !== -1
      }
    },
    backgroundColorTop: {
      type: String,
      default: '#fff'
    },
    backgroundColorBottom: {
      type: String,
      default: '#fff'
    },
    enablePullDownRefresh: {
      type: Boolean,
      default: false
    },
    onReachBottomDistance: {
      type: Number,
      default: 50
    },
    disableScroll: {
      type: Boolean,
      default: false
    },
    titleNView: {
      type: [Boolean, Object],
      default: true
    },
    pullToRefresh: {
      type: Object,
      default () {
        return {}
      }
W
wangyaqi 已提交
135 136 137 138
    },
    titleImage: {
      type: String,
      default: ''
139 140 141 142
    },
    transparentTitle: {
      type: String,
      default: 'none'
雪洛's avatar
雪洛 已提交
143 144 145 146
    },
    titlePenetrate: {
      type: String,
      default: 'NO'
fxy060608's avatar
fxy060608 已提交
147 148
    }
  },
149 150 151 152
  data () {
    const titleNViewTypeList = {
      'none': 'default',
      'auto': 'transparent',
153
      'always': 'float'
154
    }
雪洛's avatar
雪洛 已提交
155 156 157 158 159

    const yesNoParseList = {
      'YES': true,
      'NO': false
    }
160

fxy060608's avatar
fxy060608 已提交
161 162
    const navigationBar = mergeTitleNView({
      loading: false,
163
      backButton: !this.isQuit && !this.$route.meta.isQuit, // redirectTo,reLaunch时可能动态修改 meta.isQuit
fxy060608's avatar
fxy060608 已提交
164 165
      backgroundColor: this.navigationBarBackgroundColor,
      textColor: this.navigationBarTextStyle === 'black' ? '#000' : '#fff',
W
wangyaqi 已提交
166 167
      titleText: this.navigationBarTitleText,
      titleImage: this.titleImage,
fxy060608's avatar
fxy060608 已提交
168
      duration: '0',
169
      timingFunc: '',
170
      type: titleNViewTypeList[this.transparentTitle],
雪洛's avatar
雪洛 已提交
171 172
      transparentTitle: this.transparentTitle,
      titlePenetrate: yesNoParseList[this.titlePenetrate]
fxy060608's avatar
fxy060608 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    }, this.titleNView)

    const showNavigationBar = this.navigationStyle === 'default' && this.titleNView

    const refreshOptions = Object.assign({
      support: true,
      color: '#2BD009',
      style: 'circle',
      height: 70,
      range: 150,
      offset: 0
    }, this.pullToRefresh)

    let offset = upx2px(refreshOptions.offset)

    if (showNavigationBar) {
      if (!(this.titleNView && this.titleNView.type === 'transparent')) {
        offset += NAVBAR_HEIGHT
      }
    }

    refreshOptions.offset = offset
    refreshOptions.height = upx2px(refreshOptions.height)
    refreshOptions.range = upx2px(refreshOptions.range)

    return {
      showNavigationBar,
      navigationBar,
      refreshOptions
    }
203 204 205 206 207
  },
  created () {
    if (__PLATFORM__ === 'h5') {
      document.title = this.navigationBar.titleText
    }
fxy060608's avatar
fxy060608 已提交
208 209
  }
}
210
</script>