s-layout.vue 5.6 KB

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