cwg-page-wrapper.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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"
  5. :sidebarVisible="sidebarVisible" />
  6. <view class="sidebar-mask mask-visible" v-if="sidebarVisible" @click="openLeftDrawer">
  7. </view>
  8. <view class="fixed" v-if=pageTitle></view>
  9. <cwg-header v-if=pageTitle class="custom-header" :title="pageTitle" />
  10. </cwg-match-media>
  11. <cwg-language style="width: 0;display: none;" />
  12. <cwg-progress />
  13. <view class="page-content" :style="{ backgroundColor: bgColor }">
  14. <cwg-match-media :max-width="991" v-if="!isLoginPage">
  15. <view class="left-sidebar" :class="{ 'sidebar-visible': sidebarVisible }">
  16. <cwg-sidebar @handle-click="openLeftDrawer" />
  17. </view>
  18. <view class="sidebar-mask" v-if="sidebarVisible" @click="openLeftDrawer" :style="{
  19. opacity: maskVisible ? 1 : 0,
  20. transition: 'opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1)'
  21. }">
  22. </view>
  23. </cwg-match-media>
  24. <view class="content-info">
  25. <!-- 完善信息提示,-->
  26. <PrefectInfo v-if="!isLoginPage" />
  27. <!-- 申请成为ib,-->
  28. <IbInfo ref="ibRef" v-if="!isLoginPage" />
  29. <view class="content-wrapper" :class="{ 'content-wrapper-padding': isContentPadding }">
  30. <!-- <cwg-header /> -->
  31. <transition name="fade" mode="out-in">
  32. <view>
  33. <slot />
  34. </view>
  35. </transition>
  36. <cwg-custom-footer v-if=!pageTitle />
  37. </view>
  38. </view>
  39. <cwg-match-media :max-width="991">
  40. <view class="chat-icon"
  41. :class="{ 'chat-icon-expanded': isChatIconExpanded, 'chat-icon-hidden': type == 'chat' }"
  42. @click="handleChatIconClick">
  43. <cwg-icon name="chat" color="#fff" />
  44. </view>
  45. </cwg-match-media>
  46. <view :style="{ height: isTabBarPage ? '60px' : '0px' }" />
  47. </view>
  48. </view>
  49. </template>
  50. <script setup lang="ts">
  51. import { ref, computed, onMounted, onUnmounted } from 'vue'
  52. import { onLoad, onShow } from '@dcloudio/uni-app'
  53. import useRoute, { updateRoute } from '@/hooks/useRoute'
  54. import useRouter from '@/hooks/useRouter'
  55. import useUserStore from '@/stores/use-user-store'
  56. import { userApi } from '@/api/user'
  57. import useGlobalStore from '@/stores/use-global-store'
  58. import PrefectInfo from '@/components/PrefectInfo.vue'
  59. import IbInfo from '@/components/IbInfo.vue'
  60. const globalStore = useGlobalStore()
  61. const router = useRouter()
  62. const userStore = useUserStore()
  63. const props = defineProps({
  64. // 是否固定顶部导航栏
  65. isHeaderFixed: {
  66. type: Boolean,
  67. default: false,
  68. },
  69. // 是否登录页,登录页不显示侧边栏和顶部导航,注册忘记密码等页面
  70. isLoginPage: {
  71. type: Boolean,
  72. default: false,
  73. },
  74. // 是否含有padding 默认有
  75. isContentPadding: {
  76. type: Boolean,
  77. default: true,
  78. },
  79. // 主内容背景颜色
  80. bgColor: {
  81. type: String,
  82. default: '',
  83. },
  84. // 顶部导航栏标题
  85. pageTitle: {
  86. type: String,
  87. default: '',
  88. },
  89. type: {
  90. type: String,
  91. default: '',
  92. },
  93. })
  94. const isDark = computed(() => globalStore.theme === 'dark')
  95. const isTabBarPage = ref(false)
  96. const rightDrawerRef = ref<any>(null)
  97. const noticeDrawerRef = ref<any>(null)
  98. const ibRef = ref<any>(null)
  99. const isChatIconExpanded = ref(false)
  100. // 事件处理函数
  101. const handleOpenIb = () => {
  102. if (ibRef.value) ibRef.value?.getInfo()
  103. }
  104. const handleOpenNoticeDrawer = () => {
  105. noticeDrawerRef.value?.open()
  106. }
  107. // 处理聊天图标点击
  108. const handleChatIconClick = () => {
  109. // 如果还没显示 → 先滑出来
  110. if (!isChatIconExpanded.value) {
  111. isChatIconExpanded.value = true
  112. return
  113. }
  114. router.push('/pages/common/chat')
  115. setTimeout(() => {
  116. isChatIconExpanded.value = false
  117. }, 300)
  118. }
  119. const handleOpenRightDrawer = () => {
  120. openRightDrawer()
  121. }
  122. onMounted(() => {
  123. // 只在组件挂载时注册事件监听器
  124. uni.$once('open-ib', handleOpenIb)
  125. uni.$on('open-right-drawer', handleOpenRightDrawer)
  126. })
  127. onUnmounted(() => {
  128. // 在组件销毁时移除事件监听器
  129. uni.$off('open-ib', handleOpenIb)
  130. uni.$off('open-right-drawer', handleOpenRightDrawer)
  131. })
  132. function openRightDrawer() {
  133. rightDrawerRef.value?.open()
  134. }
  135. const sidebarVisible = ref(false)
  136. const maskVisible = ref(false)
  137. function openLeftDrawer() {
  138. // 真正显示时 → 关闭
  139. if (maskVisible.value) {
  140. maskVisible.value = false
  141. setTimeout(() => {
  142. sidebarVisible.value = false
  143. }, 200)
  144. }
  145. // 隐藏时 → 打开
  146. else {
  147. sidebarVisible.value = true
  148. setTimeout(() => {
  149. maskVisible.value = true
  150. }, 200)
  151. }
  152. }
  153. function handleDrawerNavigate(path: string) {
  154. router.push(path)
  155. }
  156. async function handleDrawerLogout() {
  157. try {
  158. const res = await userApi.logout()
  159. if (res.code === 200) {
  160. userStore.clearUserInfo()
  161. router.push('/pages/login/index')
  162. }
  163. } catch (error) {
  164. userStore.clearUserInfo()
  165. router.push('/pages/login/index')
  166. }
  167. }
  168. onLoad(() => {
  169. updateRoute()
  170. })
  171. onShow(() => {
  172. updateRoute()
  173. })
  174. </script>
  175. <style lang="scss" scoped>
  176. @import "@/uni.scss";
  177. .page-wrapper {
  178. height: calc(100vh - (56px + var(--status-bar-height)));
  179. }
  180. .header-box {
  181. width: 100%;
  182. height: calc(56px + var(--status-bar-height));
  183. }
  184. .page-content {
  185. width: 100%;
  186. height: calc(100vh - (56px + var(--status-bar-height)));
  187. overflow: hidden;
  188. display: flex;
  189. flex-direction: column;
  190. position: relative;
  191. box-sizing: border-box;
  192. .content-info {
  193. height: calc(100vh - (56px + var(--status-bar-height)));
  194. overflow: auto;
  195. }
  196. }
  197. .left-sidebar {
  198. width: 0;
  199. overflow: hidden;
  200. position: absolute;
  201. left: 0;
  202. top: 0;
  203. z-index: 1000;
  204. background-color: #fff;
  205. transition: width 81ms cubic-bezier(0.4, 0, 0.2, 1);
  206. }
  207. .sidebar-mask {
  208. position: absolute;
  209. left: 0;
  210. top: 0;
  211. width: 100vw;
  212. height: calc(100vh - (56px + var(--status-bar-height)));
  213. background-color: rgba(0, 0, 0, 0.2);
  214. z-index: 101;
  215. }
  216. .mask-visible {
  217. background-color: rgba(0, 0, 0, 0);
  218. width: 100vw;
  219. height: calc(56px + var(--status-bar-height));
  220. }
  221. .sidebar-visible {
  222. width: px2rpx(280);
  223. }
  224. .content-wrapper {
  225. max-width: px2rpx(1224);
  226. width: 100%;
  227. margin: 0 auto;
  228. padding-top: px2rpx(20);
  229. box-sizing: border-box;
  230. display: flex;
  231. flex-direction: column;
  232. justify-content: space-between;
  233. min-height: calc(100vh - (56px + var(--status-bar-height)));
  234. }
  235. .chat-icon {
  236. width: px2rpx(50);
  237. height: px2rpx(50);
  238. border-radius: 50%;
  239. background-color: #cf1322;
  240. display: flex;
  241. align-items: center;
  242. justify-content: center;
  243. position: fixed;
  244. bottom: px2rpx(25);
  245. right: px2rpx(-25);
  246. z-index: 999;
  247. cursor: pointer;
  248. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  249. box-shadow: 0 px2rpx(8) px2rpx(20) rgba(0, 0, 0, 0.15);
  250. will-change: transform;
  251. }
  252. .chat-icon:hover {
  253. transform: scale(1.1);
  254. }
  255. .chat-icon-expanded {
  256. bottom: px2rpx(20);
  257. right: px2rpx(20);
  258. transform: scale(1.1);
  259. box-shadow: 0 px2rpx(12) px2rpx(30) rgba(0, 0, 0, 0.2);
  260. }
  261. .chat-icon-hidden {
  262. display: none;
  263. }
  264. .fixed {
  265. // position: fixed;
  266. // top: 0;
  267. // left: 0;
  268. width: 100%;
  269. height: calc(56px + var(--status-bar-height));
  270. background-color: var(--color-white);
  271. z-index: 9;
  272. }
  273. .custom-header {
  274. background-color: var(--color-white);
  275. padding: 0 px2rpx(15);
  276. position: fixed;
  277. top: calc(56px + var(--status-bar-height));
  278. left: 0;
  279. }
  280. @media screen and (max-width: 1504px) {
  281. .content-wrapper-padding {
  282. padding: px2rpx(16) px2rpx(16) 0 px2rpx(16);
  283. }
  284. }
  285. @media screen and (max-width: 991px) {
  286. .content-wrapper-padding {
  287. padding: px2rpx(16) px2rpx(16) 0 px2rpx(16);
  288. }
  289. .page-wrapper {
  290. height: 100vh;
  291. }
  292. }
  293. .mobile-menu-btn {
  294. width: px2rpx(64);
  295. height: px2rpx(64);
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. }
  300. /* 页面切换动画 */
  301. .fade-enter-active,
  302. .fade-leave-active {
  303. transition: opacity 0.2s ease;
  304. }
  305. .fade-enter-from,
  306. .fade-leave-to {
  307. opacity: 0;
  308. }
  309. /* 侧边栏动画优化 */
  310. .left-sidebar {
  311. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  312. }
  313. .sidebar-mask {
  314. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  315. }
  316. /* 内容区域动画 */
  317. .content-wrapper {
  318. animation: slideIn 0.2s ease-out;
  319. }
  320. @keyframes slideIn {
  321. from {
  322. transform: translateY(20px);
  323. opacity: 0;
  324. }
  325. to {
  326. transform: translateY(0);
  327. opacity: 1;
  328. }
  329. }
  330. </style>