cwg-page-wrapper.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view :class="['page-wrapper', { dark: isDark }]">
  3. <cwg-match-media :max-width="991" v-if="!isLoginPage">
  4. <cwg-pc-header @open-right-drawer="openRightDrawer" @open-left-drawer="openLeftDrawer" class="header-box"
  5. :sidebarVisible="sidebarVisible" />
  6. <!-- 占位-->
  7. <view class="fixed"></view>
  8. </cwg-match-media>
  9. <LanguageDropdown style="width: 0;display: none;" />
  10. <cwg-progress />
  11. <view class="page-content" :style="{ backgroundColor: bgColor }">
  12. <cwg-match-media :max-width="991" v-if="!isLoginPage">
  13. <view class="left-sidebar" :class="{ 'sidebar-visible': sidebarVisible }">
  14. <cwg-sidebar />
  15. </view>
  16. <view class="sidebar-mask" v-if="sidebarVisible" @click="openLeftDrawer" :style="{
  17. opacity: sidebarVisible ? 1 : 0,
  18. transition: 'opacity 281ms cubic-bezier(0.4, 0, 0.2, 1)'
  19. }">
  20. </view>
  21. </cwg-match-media>
  22. <view class="content-info">
  23. <!-- 完善信息提示,-->
  24. <PrefectInfo />
  25. <view class="content-wrapper" :class="{ 'content-wrapper-padding': isContentPadding }">
  26. <!-- <cwg-header /> -->
  27. <slot />
  28. <cwg-custom-footer />
  29. </view>
  30. </view>
  31. <view :style="{ height: isTabBarPage ? '60px' : '0px' }" />
  32. </view>
  33. <cwg-match-media :max-width="991">
  34. <cwg-tab-bar v-model:isTabBarPage="isTabBarPage" />
  35. </cwg-match-media>
  36. <cwg-right-drawer v-if="!isLoginPage" ref="rightDrawerRef" @navigate="handleDrawerNavigate"
  37. @logout="handleDrawerLogout" />
  38. <cwg-notice-drawer v-if="!isLoginPage" ref="noticeDrawerRef" @navigate="handleDrawerNavigate"
  39. @logout="handleDrawerLogout" />
  40. </view>
  41. </template>
  42. <script setup lang="ts">
  43. import { ref, computed } from "vue";
  44. import { onLoad, onShow } from '@dcloudio/uni-app'
  45. import { updateRoute } from '@/hooks/useRoute'
  46. import useRouter from '@/hooks/useRouter'
  47. import useUserStore from '@/stores/use-user-store'
  48. import { userApi } from '@/api/user'
  49. import useGlobalStore from '@/stores/use-global-store'
  50. import LanguageDropdown from './LanguageDropdown.vue'
  51. import PrefectInfo from '@/components/PrefectInfo.vue'
  52. const globalStore = useGlobalStore()
  53. const router = useRouter()
  54. const userStore = useUserStore()
  55. const props = defineProps({
  56. // 是否固定顶部导航栏
  57. isHeaderFixed: {
  58. type: Boolean,
  59. default: false
  60. },
  61. // 是否登录页,登录页不显示侧边栏和顶部导航,注册忘记密码等页面
  62. isLoginPage: {
  63. type: Boolean,
  64. default: false
  65. },
  66. // 是否含有padding 默认有
  67. isContentPadding: {
  68. type: Boolean,
  69. default: true
  70. },
  71. // 主内容背景颜色
  72. bgColor: {
  73. type: String,
  74. default: ''
  75. }
  76. })
  77. const isDark = computed(() => globalStore.theme === 'dark')
  78. const isTabBarPage = ref(false)
  79. const rightDrawerRef = ref<any>(null)
  80. const noticeDrawerRef = ref<any>(null)
  81. uni.$on('open-notice-drawer', (data) => {
  82. console.log(121212)
  83. noticeDrawerRef.value?.open()
  84. })
  85. uni.$on('open-right-drawer', (data) => {
  86. openRightDrawer()
  87. })
  88. function openRightDrawer() {
  89. rightDrawerRef.value?.open()
  90. }
  91. const sidebarVisible = ref(false)
  92. function openLeftDrawer() {
  93. sidebarVisible.value = !sidebarVisible.value;
  94. }
  95. function handleDrawerNavigate(path: string) {
  96. router.push(path)
  97. }
  98. async function handleDrawerLogout() {
  99. try {
  100. const res = await userApi.logout()
  101. if (res.code === 200) {
  102. userStore.clearUserInfo()
  103. router.push('/pages/login/index')
  104. }
  105. } catch (error) {
  106. userStore.clearUserInfo()
  107. router.push('/pages/login/index')
  108. }
  109. }
  110. onLoad(() => {
  111. updateRoute()
  112. })
  113. onShow(() => {
  114. updateRoute()
  115. })
  116. </script>
  117. <style lang="scss" scoped>
  118. @import "@/uni.scss";
  119. .page-wrapper {
  120. height: calc(100vh - 56px);
  121. }
  122. .header-box {
  123. width: 100%;
  124. height: 56px;
  125. }
  126. .page-content {
  127. width: 100%;
  128. height: calc(100vh - 56px);
  129. overflow: hidden;
  130. display: flex;
  131. flex-direction: column;
  132. position: relative;
  133. box-sizing: border-box;
  134. .content-info {
  135. height: calc(100vh - 56px);
  136. overflow: auto;
  137. }
  138. }
  139. .left-sidebar {
  140. width: 0;
  141. overflow: hidden;
  142. position: absolute;
  143. left: 0;
  144. top: 0;
  145. z-index: 1000;
  146. background-color: #fff;
  147. transition: width 281ms cubic-bezier(0.4, 0, 0.2, 1);
  148. }
  149. .sidebar-mask {
  150. position: absolute;
  151. left: 0;
  152. top: 0;
  153. width: 100vw;
  154. height: calc(100vh - 56px);
  155. background-color: rgba(0, 0, 0, 0.2);
  156. z-index: 999;
  157. }
  158. .sidebar-visible {
  159. width: px2rpx(280);
  160. }
  161. .content-wrapper {
  162. max-width: px2rpx(1224);
  163. width: 100%;
  164. margin: 0 auto;
  165. box-sizing: border-box;
  166. // border: 1px solid rgba(108, 133, 149, 0.12);
  167. }
  168. .fixed {
  169. // position: fixed;
  170. // top: 0;
  171. // left: 0;
  172. width: 100%;
  173. height: 56px;
  174. background-color: var(--color-white);
  175. z-index: 9;
  176. }
  177. @media screen and (max-width: 1504px) {
  178. .content-wrapper-padding {
  179. padding: px2rpx(20);
  180. }
  181. }
  182. @media screen and (max-width: 991px) {
  183. .page-wrapper {
  184. height: 100vh;
  185. }
  186. }
  187. .mobile-menu-btn {
  188. width: px2rpx(64);
  189. height: px2rpx(64);
  190. display: flex;
  191. align-items: center;
  192. justify-content: center;
  193. }
  194. // 针对不同屏幕尺寸的响应式调整
  195. @media screen and (max-width: 767px) {
  196. .content-wrapper-padding {
  197. padding: px2rpx(0) !important;
  198. }
  199. }
  200. </style>