cwg-page-wrapper.vue 5.3 KB

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