s-layout.vue 6.0 KB

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