zhengyiming
2025-02-13 20619871d0db98f3f298a04e200005e84e0bc6be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
135
136
137
138
139
140
141
<template>
  <Portal.Host>
    <div class="page-layout-wrapper" v-bind="$attrs">
      <slot v-if="showNavigationBar" name="navigationBar">
        <CommonNavigationBar v-bind="_commonNavigationBarProps" />
      </slot>
 
      <slot name="bg">
        <div
          v-if="hasLinearBg"
          class="page-layout-linear-bg"
          :style="{
            height: Taro.pxTransform(props.linearBgHeight),
          }"
        ></div>
      </slot>
 
      <div class="page-layout-scroll-view-wrapper" :style="{ height: scrollViewHeight }">
        <slot :scrollViewHeight="scrollViewHeight" v-if="isAuth"></slot>
        <!-- <template v-if="isAuth">
          <slot v-if="useView" :scrollViewHeight="scrollViewHeight"></slot>
          <scroll-view
            v-else
            class="page-scrollview"
            :scroll-y="true"
            :style="{ height: scrollViewHeight }"
          >
            <slot :scrollViewHeight="scrollViewHeight"></slot>
          </scroll-view>
        </template> -->
      </div>
      <div v-if="!pageHeightWithTabBar" class="safe-area-bottom"></div>
    </div>
  </Portal.Host>
</template>
 
<script setup lang="ts">
// import LoadingLayout from './LoadingLayout.vue';
// import { loadingLayoutProps } from './layout';
import CommonNavigationBar from '../NavigationBar/CommonNavigationBar.vue';
import { commonNavigationBarProps } from '../NavigationBar/commonNavigationBar';
import { useSystemStore } from '@/stores/modules/system';
import Taro from '@tarojs/taro';
import { TabBarPageRouter } from '@/constants';
import { useAuth } from '@/hooks';
import { Portal } from 'senin-mini/components';
import { usePickProps } from 'senin-mini/hooks';
 
defineOptions({
  name: 'PageLayout',
  inheritAttrs: false,
});
 
const props = defineProps({
  ...commonNavigationBarProps,
  needAuth: {
    type: Boolean,
    default: true,
  },
  useView: {
    type: Boolean,
    default: false,
  },
  hasLinearBg: {
    type: Boolean,
    default: false,
  },
  linearBgHeight: {
    type: Number,
    default: 388,
  },
});
 
const _commonNavigationBarProps = usePickProps(props, commonNavigationBarProps);
 
const { isAuth } = useAuth({
  needAuth: props.needAuth,
});
 
const systemStore = useSystemStore();
const router = Taro.useRouter();
 
const pageHeightWithTabBar = computed(() =>
  Object.values(TabBarPageRouter).some((x) => x.toLowerCase() === router.path.toLowerCase())
);
 
const navigationBarHeight = computed(
  () => systemStore.info.statusBarHeight + systemStore.navigationBarHeight
);
 
const scrollViewHeight = computed(() => {
  let pageHeight = pageHeightWithTabBar.value
    ? systemStore.pageHeightWithTab
    : systemStore.pageHeight;
  pageHeight = pageHeight + (props.showNavigationBar ? 0 : navigationBarHeight.value);
  return pageHeight + 'px';
});
 
Taro.getSetting({
  success: function (res) {
    if (!res.authSetting['scope.userLocation']) {
      Taro.authorize({
        scope: 'scope.userLocation',
      });
    }
  },
});
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.page-layout-wrapper {
  // background-color: $body-background-color;
 
  .page-layout-scroll-view-wrapper {
    display: flex;
    flex-direction: column;
 
    .page-scrollview {
      box-sizing: border-box;
    }
  }
 
  .page-layout-linear-bg {
    position: fixed;
    z-index: -1;
    top: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(
      180deg,
      boleGetCssVar('color', 'primary') 0%,
      #5a86f6 56%,
      #f9f9fb 100%
    );
    filter: blur(0px);
    border-radius: 0px 0px 20px 20px;
  }
}
</style>