mobile-main.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div id="mobile-main">
  3. <van-row>
  4. <van-col span="24" class="main" :style="{ height: client.height + 'px' }">
  5. <van-col span="24" class="top" v-if="useTop">
  6. <top :topType="topType" @search="topSearch" :leftArrow="leftArrow" @back="back" :rightArrow="rightArrow" @add="add">
  7. <template v-slot:top>
  8. <slot name="slotTop"></slot>
  9. </template>
  10. </top>
  11. </van-col>
  12. <van-col span="24" class="info" :style="{ height: getHeight() }">
  13. <slot name="info"></slot>
  14. </van-col>
  15. <van-col span="24" class="page" v-if="usePage">
  16. <page :limit="limit" :total="total" @search="search"></page>
  17. </van-col>
  18. <van-col span="24" class="foot" v-if="useNav"><foot :menuList="menuList"></foot></van-col>
  19. </van-col>
  20. </van-row>
  21. </div>
  22. </template>
  23. <script>
  24. import top from './top.vue';
  25. import page from './page.vue';
  26. import foot from './foot.vue';
  27. import { mapState, createNamespacedHelpers } from 'vuex';
  28. export default {
  29. name: 'mobile-main',
  30. props: {
  31. // 头部
  32. useTop: { type: Boolean, default: () => true },
  33. topType: { type: String, default: () => '1' },
  34. leftArrow: { type: Boolean, default: () => true },
  35. rightArrow: { type: Boolean, default: () => true },
  36. // 分页
  37. usePage: { type: Boolean, default: () => true },
  38. limit: { type: Number, default: () => 10 },
  39. total: { type: Number, default: () => 0 },
  40. // 底部菜单
  41. useNav: { type: Boolean, default: () => true },
  42. },
  43. components: {
  44. top,
  45. page,
  46. foot,
  47. },
  48. data: function() {
  49. return {
  50. client: {},
  51. menuList: [
  52. { name: '首页1', index: '/', icon: 'after-sale' },
  53. { name: '首页2', index: '/index', icon: 'cart-o' },
  54. ],
  55. };
  56. },
  57. created() {},
  58. methods: {
  59. // 头部名称查询
  60. topSearch(searchName) {
  61. this.$emit('search', searchName);
  62. },
  63. // 分页查询
  64. search(skip) {
  65. this.$emit('search', skip);
  66. },
  67. // 返回
  68. back() {
  69. this.$emit('back');
  70. },
  71. // 添加
  72. add() {
  73. this.$emit('add');
  74. },
  75. // 计算中间高度
  76. getHeight() {
  77. let windowH = this.client.height;
  78. if (this.useTop) windowH = windowH - 45;
  79. else windowH = windowH - 0;
  80. if (this.usePage) windowH = windowH - 40;
  81. else windowH = windowH - 0;
  82. if (this.useNav) windowH = windowH - 50;
  83. else windowH = windowH - 0;
  84. return windowH + 'px';
  85. },
  86. },
  87. mounted() {
  88. let client = {
  89. height: document.documentElement.clientHeight || document.body.clientHeight,
  90. width: document.documentElement.clientWidth || document.body.clientWidth,
  91. };
  92. this.$set(this, `client`, client);
  93. },
  94. computed: {
  95. ...mapState(['user']),
  96. },
  97. metaInfo() {
  98. return { title: this.$route.meta.title };
  99. },
  100. watch: {
  101. test: {
  102. deep: true,
  103. immediate: true,
  104. handler(val) {},
  105. },
  106. },
  107. };
  108. </script>
  109. <style lang="less" scoped></style>