index.vue 5.0 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
<template>
  <uni-page :data-page="$route.meta.pagePath">
Q
qiang 已提交
3 4
    <page-head
      v-if="navigationBar.type!=='none'"
fxy060608's avatar
fxy060608 已提交
5
      v-bind="navigationBar" />
6 7 8 9
    <page-refresh
      v-if="enablePullDownRefresh"
      ref="refresh"
      :color="refreshOptions.color"
Q
qiang 已提交
10 11
      :offset="refreshOptions.offset"
    />
12 13 14
    <page-body
      v-if="enablePullDownRefresh"
      @touchstart.native="_touchstart"
fxy060608's avatar
fxy060608 已提交
15
      @touchmove.native="_touchmove"
16
      @touchend.native="_touchend"
Q
qiang 已提交
17 18
      @touchcancel.native="_touchend"
    >
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24 25 26
      <slot name="page" />
    </page-body>
    <page-body v-else>
      <slot name="page" />
    </page-body>
  </uni-page>
</template>
<style>
Q
qiang 已提交
27 28 29 30 31
uni-page {
  display: block;
  width: 100%;
  height: 100%;
}
fxy060608's avatar
fxy060608 已提交
32 33 34 35
</style>
<script>
import {
  upx2px
fxy060608's avatar
fxy060608 已提交
36
} from 'uni-helpers/index'
fxy060608's avatar
fxy060608 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

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'

Q
qiang 已提交
52 53
import safeAreaInsets from 'safe-area-insets'

fxy060608's avatar
fxy060608 已提交
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
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: {
Q
qiang 已提交
131 132
      type: [Boolean, Object, String],
      default: ''
fxy060608's avatar
fxy060608 已提交
133 134 135 136 137 138
    },
    pullToRefresh: {
      type: Object,
      default () {
        return {}
      }
Q
qiang 已提交
139 140 141 142 143 144 145 146 147 148 149 150
    },
    titleImage: {
      type: String,
      default: ''
    },
    transparentTitle: {
      type: String,
      default: ''
    },
    titlePenetrate: {
      type: String,
      default: 'NO'
fxy060608's avatar
fxy060608 已提交
151 152
    }
  },
Q
qiang 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
  data () {
    const titleNViewTypeList = {
      'none': 'default',
      'auto': 'transparent',
      'always': 'float'
    }
    // 将 navigationStyle 和 transparentTitle 都合并到 titleNView
    let titleNView = this.titleNView
    titleNView = Object.assign({}, {
      type: this.navigationStyle === 'custom' ? 'none' : 'default'
    }, this.transparentTitle in titleNViewTypeList ? {
      type: titleNViewTypeList[this.transparentTitle],
      backgroundColor: 'rgba(0,0,0,0)'
    } : null, typeof titleNView === 'object' ? titleNView : (typeof titleNView === 'boolean' ? {
      type: titleNView ? 'default' : 'none'
    } : null))

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

fxy060608's avatar
fxy060608 已提交
175 176
    const navigationBar = mergeTitleNView({
      loading: false,
177
      backButton: !this.isQuit && !this.$route.meta.isQuit, // redirectTo,reLaunch时可能动态修改 meta.isQuit
fxy060608's avatar
fxy060608 已提交
178 179
      backgroundColor: this.navigationBarBackgroundColor,
      textColor: this.navigationBarTextStyle === 'black' ? '#000' : '#fff',
Q
qiang 已提交
180
      titleText: this.navigationBarTitleText,
W
wangyaqi 已提交
181
      titleImage: this.titleImage,
fxy060608's avatar
fxy060608 已提交
182
      duration: '0',
Q
qiang 已提交
183
      timingFunc: '',
雪洛's avatar
雪洛 已提交
184
      titlePenetrate: yesNoParseList[this.titlePenetrate]
Q
qiang 已提交
185
    }, titleNView)
fxy060608's avatar
fxy060608 已提交
186 187 188 189 190 191 192 193 194 195 196 197

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

    let offset = upx2px(refreshOptions.offset)

Q
qiang 已提交
198
    if (titleNView.type !== 'none' && titleNView.type !== 'transparent') {
Q
qiang 已提交
199
      offset += NAVBAR_HEIGHT + safeAreaInsets.top
fxy060608's avatar
fxy060608 已提交
200 201 202 203 204 205 206 207 208 209
    }

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

    return {
      navigationBar,
      refreshOptions
    }
210 211 212 213 214
  },
  created () {
    if (__PLATFORM__ === 'h5') {
      document.title = this.navigationBar.titleText
    }
fxy060608's avatar
fxy060608 已提交
215 216
  }
}
217
</script>