s-layout.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <view
  3. class="page-app"
  4. >
  5. <view class="page-main" :style="[bgMain]">
  6. <!-- 顶部导航栏-情况1:默认通用顶部导航栏 -->
  7. <su-navbar
  8. v-if="navbar === 'normal'"
  9. :title="title"
  10. statusBar
  11. :color="color"
  12. :tools="tools"
  13. :opacityBgUi="opacityBgUi"
  14. @search="(e) => emits('search', e)"
  15. :defaultSearch="defaultSearch"
  16. :showBackButton="showBackButton"
  17. />
  18. <!-- 顶部导航栏-情况2:装修组件导航栏-标准 -->
  19. <s-custom-navbar
  20. v-else-if="navbar === 'custom' && navbarMode === 'normal'"
  21. :data="navbarStyle"
  22. :showLeftButton="showLeftButton"
  23. />
  24. <view class="page-body" :style="[bgBody]">
  25. <!-- 顶部导航栏-情况3:沉浸式头部 -->
  26. <su-inner-navbar v-if="navbar === 'inner'" :showBackButton="showBackButton" :showLogoutButton="showLogoutButton" :showRecordButton="showRecordButton" :showLeftButton="showLeftButton" :showLeftLogoutButton="showLeftLogoutButton" :showRecordTextButton="showRecordTextButton" :showImportButton="showImportButton" :showExportButton="showExportButton" :alway="alway" :title="title" @logout="state.showLogout=true" @import="onClickImport" @export="onClickExport" />
  27. <view
  28. v-if="navbar === 'inner'"
  29. :style="[{ paddingTop: sheep?.$platform?.navbar + 'px' }]"
  30. ></view>
  31. <!-- 顶部导航栏-情况4:装修组件导航栏-沉浸式 -->
  32. <s-custom-navbar
  33. v-if="navbar === 'custom' && navbarMode === 'inner'"
  34. :data="navbarStyle"
  35. :showLeftButton="showLeftButton"
  36. />
  37. <!-- 页面内容插槽 -->
  38. <slot />
  39. <!-- 底部导航 -->
  40. <s-tabbar v-if="tabbar !== ''" :path="tabbar" />
  41. </view>
  42. </view>
  43. <view class="page-modal">
  44. <!-- 全局授权弹窗 -->
  45. <s-auth-modal />
  46. <!-- 全局快捷入口 -->
  47. <s-menu-tools />
  48. <su-popup :show="state.showLogout" round="20" type="center" :isMaskClick="false" :showClose="false" @close="state.showLogout=false">
  49. <view class="tips_wrap">
  50. <view class="tips_cont">
  51. <view class="label">退出登录</view>
  52. <view class="cont">确认要退出当前账号吗?</view>
  53. </view>
  54. <view class="group_btn">
  55. <view class="item_btn cancel_btn" @tap="state.showLogout=false">取消</view>
  56. <view class="item_btn logout-btn" @tap="logout">确认</view>
  57. </view>
  58. </view>
  59. </su-popup>
  60. </view>
  61. </view>
  62. </template>
  63. <script setup>
  64. /**
  65. * 模板组件 - 提供页面公共组件,属性,方法
  66. */
  67. import { computed, onMounted, reactive } from 'vue';
  68. import AuthUtil from '@/common/api/member/auth';
  69. import sheep from '@/common';
  70. import { isEmpty } from 'lodash-es';
  71. // #ifdef MP-WEIXIN
  72. import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
  73. // #endif
  74. const props = defineProps({
  75. title: {
  76. type: String,
  77. default: '',
  78. },
  79. navbar: {
  80. type: String,
  81. default: 'normal',
  82. },
  83. opacityBgUi: {
  84. type: String,
  85. default: 'bg-white',
  86. },
  87. color: {
  88. type: String,
  89. default: '',
  90. },
  91. tools: {
  92. type: String,
  93. default: 'title',
  94. },
  95. keyword: {
  96. type: String,
  97. default: '',
  98. },
  99. navbarStyle: {
  100. type: Object,
  101. default: () => ({
  102. styleType: '',
  103. type: '',
  104. color: '',
  105. src: '',
  106. list: [],
  107. alwaysShow: 0,
  108. }),
  109. },
  110. bgStyle: {
  111. type: Object,
  112. default: () => ({
  113. src: '',
  114. color: 'var(--ui-BG-1)',
  115. }),
  116. },
  117. tabbar: {
  118. type: [String, Boolean],
  119. default: '',
  120. },
  121. onShareAppMessage: {
  122. type: [Boolean, Object],
  123. default: true,
  124. },
  125. leftWidth: {
  126. type: [Number, String],
  127. default: 100,
  128. },
  129. rightWidth: {
  130. type: [Number, String],
  131. default: 100,
  132. },
  133. defaultSearch: {
  134. type: String,
  135. default: '',
  136. },
  137. //展示返回按钮
  138. showLeftButton: {
  139. type: Boolean,
  140. default: false,
  141. },
  142. showBackButton: {
  143. type: Boolean,
  144. default: false,
  145. },
  146. showRecordButton: {
  147. type: Boolean,
  148. default: false,
  149. },
  150. showLogoutButton: {
  151. type: Boolean,
  152. default: false,
  153. },
  154. showLeftLogoutButton: {
  155. type: Boolean,
  156. default: false,
  157. },
  158. showRecordTextButton: {
  159. type: Boolean,
  160. default: false,
  161. },
  162. showImportButton: {
  163. type: Boolean,
  164. default: false,
  165. },
  166. showExportButton: {
  167. type: Boolean,
  168. default: false,
  169. },
  170. alway: {
  171. type: Boolean,
  172. default: true,
  173. },
  174. opacity: {
  175. type: Boolean,
  176. default: true,
  177. },
  178. });
  179. const state = reactive({
  180. showLogout: false
  181. })
  182. const emits = defineEmits(['search','import', 'export']);
  183. const userStore = sheep.$store('user');
  184. const modalStore = sheep.$store('modal');
  185. // 导航栏模式(因为有自定义导航栏 需要计算)
  186. const navbarMode = computed(() => {
  187. if (props.navbar === 'normal' || props.navbarStyle.styleType === 'normal') {
  188. return 'normal';
  189. }
  190. return 'inner';
  191. });
  192. // 背景1
  193. const bgMain = computed(() => {
  194. if (navbarMode.value === 'inner') {
  195. return {
  196. background: `${props.bgStyle.backgroundColor || props.bgStyle.color}${props.bgStyle.backgroundImage?` url(${props.bgStyle.backgroundImage}) no-repeat top -88rpx center / 100% auto`:''}`,
  197. ...(props.bgStyle.backgroundImage?{height: '100vh',overflowY: 'auto'}:{})
  198. };
  199. }
  200. return {};
  201. });
  202. // 背景2
  203. const bgBody = computed(() => {
  204. if (navbarMode.value === 'normal') {
  205. return {
  206. background: `${props.bgStyle.backgroundColor || props.bgStyle.color}${props.bgStyle.backgroundImage?` url(${props.bgStyle.backgroundImage}) no-repeat top -88rpx center / 100% auto`:''}`,
  207. ...(props.bgStyle.backgroundImage?{height: '100vh',overflowY: 'auto'}:{})
  208. };
  209. }
  210. return {};
  211. });
  212. async function logout(){
  213. const { code } = await AuthUtil.logout()
  214. if (code !== 1) {
  215. return;
  216. }
  217. sheep.$store('user').logout()
  218. state.showLogout = false
  219. sheep.$router.go('/pages/index/index')
  220. }
  221. function onClickImport(){
  222. emits('import')
  223. }
  224. function onClickExport(){
  225. emits('export')
  226. }
  227. // 组件中使用 onMounted 监听页面加载,不是页面组件不使用 onShow
  228. onMounted(()=>{
  229. })
  230. </script>
  231. <style lang="scss" scoped>
  232. .page-app {
  233. position: relative;
  234. color: var(--ui-TC);
  235. background-color: var(--ui-BG-1) !important;
  236. z-index: 2;
  237. display: flex;
  238. width: 750rpx;
  239. height: 100vh;
  240. margin: 0 auto;
  241. .page-main {
  242. position: absolute;
  243. z-index: 1;
  244. width: 100%;
  245. min-height: 100%;
  246. display: flex;
  247. flex-direction: column;
  248. .page-body {
  249. height: 100%;
  250. width: 100%;
  251. position: relative;
  252. z-index: 1;
  253. display: flex;
  254. flex-direction: column;
  255. }
  256. .page-img {
  257. width: 100vw;
  258. height: 100vh;
  259. position: absolute;
  260. top: 0;
  261. left: 0;
  262. z-index: 0;
  263. }
  264. }
  265. }
  266. </style>