index.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <!-- 小程序环境 会把$attrs 解析到最外层标签(虚拟标签,导致无效),只能使用自定义参数 -->
  3. <div class="container" :class="props.cusClass" :style="props.cusStyle">
  4. <ay-sticky top="0px" v-if="data.isCustom">
  5. <div class="page-top" :style="{ height: props.topHeight, ...props.pageTopStyle }">
  6. <div class="center page-title" :class="{ 'justify-start': data.titleAlginStart }">
  7. <uni-icons
  8. class="mr-spacd4"
  9. v-if="data.showBackIcon"
  10. type="left"
  11. color=""
  12. size="24"
  13. @click="ay.navigateBack()"
  14. />
  15. <div class="font-bold bs-fz">{{ title }}</div>
  16. </div>
  17. </div>
  18. </ay-sticky>
  19. <div class="pt-spac" v-if="props.showSpac" />
  20. <!-- 小程序内只能用v-if移除组件,如果用v-show条件false时,整个页面不显示。。 -->
  21. <ay-pull v-if="store.curPage.pageConfig?.isPager">
  22. <slot />
  23. </ay-pull>
  24. <slot v-else />
  25. </div>
  26. </template>
  27. <script lang="ts" setup>
  28. defineOptions({
  29. name: 'container',
  30. })
  31. const props = withDefaults(
  32. defineProps<{
  33. cusClass?: AnyObject | string[]
  34. cusStyle?: AnyObject
  35. pageTopStyle?: AnyObject
  36. title?: string
  37. topHeight: string
  38. showSpac: boolean
  39. }>(),
  40. {
  41. showSpac: true,
  42. topHeight: `${config.common.safeAreaTopHeight}px`,
  43. },
  44. )
  45. /** 采用局部数据 代替全局存储数据,防止页面跳转时显示下个页面的标题等信息 */
  46. const data = reactive({
  47. title: '',
  48. showBackIcon: false,
  49. titleAlginStart: true,
  50. isCustom: false,
  51. })
  52. const title = computed(() => props.title || data.title)
  53. onMounted(() => {
  54. data.title = store.curPage.pageConfig.title
  55. data.showBackIcon = ![config.pages.index_index._url, config.pages.login_index._url].includes(
  56. store.curPage.pageConfig._url,
  57. )
  58. data.titleAlginStart = store.curPage.pageConfig._url !== config.pages.login_index._url
  59. data.isCustom = store.curPage.pageConfig.style?.navigationStyle === 'custom'
  60. })
  61. </script>
  62. <style lang="scss" scoped>
  63. .container {
  64. position: relative;
  65. box-sizing: border-box;
  66. min-height: 100vh;
  67. padding: $p-spac;
  68. padding-top: 0;
  69. }
  70. .page-top {
  71. padding: 0 $p-spac;
  72. margin: 0 calc($p-spac / -1);
  73. // margin-bottom: $p-spac;
  74. background-color: #f8f8f8;
  75. @apply flex;
  76. @apply items-end;
  77. }
  78. .page-title {
  79. // position: absolute;
  80. // top: 50px;
  81. // right: 0;
  82. // left: 0;
  83. width: 100%;
  84. height: 44px;
  85. }
  86. </style>