s-layout.vue 5.6 KB

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