s-layout.vue 5.7 KB

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