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 } from 'vue';
  58. import sheep from '@/sheep';
  59. import { isEmpty } from 'lodash-es';
  60. // #ifdef MP-WEIXIN
  61. import { onShareAppMessage, onShareTimeline, onShow } 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. backgroundColor: '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. // TODO puhui999:是不是应该还是用 color。然后后端装修那,做下调整~
  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. uni.showShareMenu({
  182. withShareTicket: true,
  183. menus: ['shareAppMessage', 'shareTimeline'],
  184. });
  185. // 微信小程序分享好友
  186. onShareAppMessage(() => {
  187. return {
  188. title: shareInfo.value.title,
  189. path: shareInfo.value.path,
  190. imageUrl: shareInfo.value.image,
  191. };
  192. });
  193. // 微信小程序分享朋友圈
  194. onShareTimeline(() => {
  195. return {
  196. title: shareInfo.value.title,
  197. query: shareInfo.value.path,
  198. imageUrl: shareInfo.value.image,
  199. };
  200. });
  201. // #endif
  202. onShow(() => {
  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>