s-layout.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view
  3. class="page-app"
  4. :class="['theme-' + sys.mode, 'main-' + sys.theme, 'font-' + sys.fontSize]"
  5. >
  6. <view class="page-main" :style="[bgMain]">
  7. <!-- 默认通用顶部导航栏 -->
  8. <su-navbar
  9. v-if="navbar === 'normal'"
  10. :title="title"
  11. statusBar
  12. :color="color"
  13. :tools="tools"
  14. :opacityBgUi="opacityBgUi"
  15. @search="(e) => emits('search', e)"
  16. :defaultSearch="defaultSearch"
  17. />
  18. <!-- 装修组件导航栏-普通 -->
  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. <!-- 沉浸式头部 -->
  26. <su-inner-navbar v-if="navbar === 'inner'" :title="title" />
  27. <view
  28. v-if="navbar === 'inner'"
  29. :style="[{ paddingTop: sheep.$platform.navbar + 'px' }]"
  30. ></view>
  31. <!-- 装修组件导航栏-沉浸式 -->
  32. <s-custom-navbar
  33. v-if="navbar === 'custom' && navbarMode === 'inner'"
  34. :data="navbarStyle"
  35. :showLeftButton="showLeftButton"
  36. />
  37. <!-- 页面内容插槽 -->
  38. <slot />
  39. <!-- 悬浮按钮 -->
  40. <s-float-menu v-if="showFloatButton"></s-float-menu>
  41. <!-- 底部导航 -->
  42. <s-tabbar v-if="tabbar !== ''" :path="tabbar" />
  43. </view>
  44. </view>
  45. <view class="page-modal">
  46. <!-- 全局授权弹窗 -->
  47. <s-auth-modal />
  48. <!-- 全局分享弹窗 -->
  49. <s-share-modal :shareInfo="shareInfo" />
  50. <!-- 全局快捷入口 -->
  51. <s-menu-tools />
  52. </view>
  53. </view>
  54. </template>
  55. <script setup>
  56. /**
  57. * 模板组件 - 提供页面公共组件,属性,方法
  58. */
  59. import { computed, reactive, ref } from 'vue';
  60. import sheep from '@/sheep';
  61. import { isEmpty } from 'lodash';
  62. import { onShow } from '@dcloudio/uni-app';
  63. // #ifdef MP-WEIXIN
  64. import { onShareAppMessage } from '@dcloudio/uni-app';
  65. // #endif
  66. const props = defineProps({
  67. title: {
  68. type: String,
  69. default: '',
  70. },
  71. navbar: {
  72. type: String,
  73. default: 'normal',
  74. },
  75. opacityBgUi: {
  76. type: String,
  77. default: 'bg-white',
  78. },
  79. color: {
  80. type: String,
  81. default: '',
  82. },
  83. tools: {
  84. type: String,
  85. default: 'title',
  86. },
  87. keyword: {
  88. type: String,
  89. default: '',
  90. },
  91. navbarStyle: {
  92. type: Object,
  93. default: () => ({
  94. mode: '',
  95. type: '',
  96. color: '',
  97. src: '',
  98. list: [],
  99. alwaysShow: 0,
  100. }),
  101. },
  102. bgStyle: {
  103. type: Object,
  104. default: () => ({
  105. src: '',
  106. color: 'var(--ui-BG-1)',
  107. }),
  108. },
  109. tabbar: {
  110. type: [String, Boolean],
  111. default: '',
  112. },
  113. onShareAppMessage: {
  114. type: [Boolean, Object],
  115. default: true,
  116. },
  117. leftWidth: {
  118. type: [Number, String],
  119. default: 100,
  120. },
  121. rightWidth: {
  122. type: [Number, String],
  123. default: 100,
  124. },
  125. defaultSearch: {
  126. type: String,
  127. default: '',
  128. },
  129. //展示悬浮按钮
  130. showFloatButton: {
  131. type: Boolean,
  132. default: false,
  133. },
  134. //展示返回按钮
  135. showLeftButton: {
  136. type: Boolean,
  137. default: false,
  138. },
  139. });
  140. const emits = defineEmits(['search']);
  141. const sysStore = sheep.$store('sys');
  142. const userStore = sheep.$store('user');
  143. const appStore = sheep.$store('app');
  144. const modalStore = sheep.$store('modal');
  145. const sys = computed(() => sysStore);
  146. // 导航栏模式(因为有自定义导航栏 需要计算)
  147. const navbarMode = computed(() => {
  148. if (props.navbar === 'normal' || props.navbarStyle.mode === 'normal') {
  149. return 'normal';
  150. }
  151. return 'inner';
  152. });
  153. // 背景1
  154. const bgMain = computed(() => {
  155. if (navbarMode.value === 'inner') {
  156. return {
  157. background: `${props.bgStyle.color} url(${sheep.$url.cdn(
  158. props.bgStyle.src,
  159. )}) no-repeat top center / 100% auto`,
  160. };
  161. }
  162. return {};
  163. });
  164. // 背景2
  165. const bgBody = computed(() => {
  166. if (navbarMode.value === 'normal') {
  167. return {
  168. background: `${props.bgStyle.color} url(${sheep.$url.cdn(
  169. props.bgStyle.src,
  170. )}) no-repeat top center / 100% auto`,
  171. };
  172. }
  173. return {};
  174. });
  175. // 分享信息
  176. const shareInfo = computed(() => {
  177. if (props.onShareAppMessage === true) {
  178. return sheep.$platform.share.getShareInfo();
  179. } else {
  180. if (!isEmpty(props.onShareAppMessage)) {
  181. sheep.$platform.share.updateShareInfo(props.onShareAppMessage);
  182. return props.onShareAppMessage;
  183. }
  184. }
  185. return {};
  186. });
  187. // #ifdef MP-WEIXIN
  188. // 微信小程序分享
  189. onShareAppMessage(() => {
  190. return {
  191. title: shareInfo.value.title,
  192. path: shareInfo.value.path,
  193. imageUrl: shareInfo.value.image,
  194. };
  195. });
  196. // #endif
  197. onShow(() => {
  198. if (!isEmpty(shareInfo.value)) {
  199. sheep.$platform.share.updateShareInfo(shareInfo.value);
  200. }
  201. });
  202. </script>
  203. <style lang="scss" scoped>
  204. .page-app {
  205. position: relative;
  206. color: var(--ui-TC);
  207. background-color: var(--ui-BG-1) !important;
  208. z-index: 2;
  209. display: flex;
  210. width: 100%;
  211. height: 100vh;
  212. .page-main {
  213. position: absolute;
  214. z-index: 1;
  215. width: 100%;
  216. min-height: 100%;
  217. display: flex;
  218. flex-direction: column;
  219. .page-body {
  220. width: 100%;
  221. position: relative;
  222. z-index: 1;
  223. flex: 1;
  224. }
  225. .page-img {
  226. width: 100vw;
  227. height: 100vh;
  228. position: absolute;
  229. top: 0;
  230. left: 0;
  231. z-index: 0;
  232. }
  233. }
  234. }
  235. </style>