s-layout.vue 6.4 KB

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