mx-index-menus.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view class="mx-30 mx-card bg-white overflow-hidden">
  3. <view v-if="pageSize<=1" :class="containerWrapClass">
  4. <mx-index-paged-menus v-bind="props" @click="handleMenuClick"/>
  5. </view>
  6. <uv-swiper v-else :height="swiperHeight" :indicator-active-color="theme.brands.primary" :list="pagedData"
  7. bg-color="white" circular indicator indicator-inactive-color="#ccc" interval="10000">
  8. <template #default="{item}">
  9. <mx-index-paged-menus class="flex-1 mb-60 mt-40" v-bind="props" @click="handleMenuClick"/>
  10. </template>
  11. </uv-swiper>
  12. </view>
  13. </template>
  14. <script setup>
  15. import {computed} from "vue";
  16. import {shareProps} from "./shareProps";
  17. import _ from "lodash";
  18. import {useTheme} from "@/hooks/useTheme";
  19. import MxIndexPagedMenus from "@/components/mx-index-menus/mx-index-paged-menus.vue";
  20. import {useTransfer} from "@/hooks/useTransfer";
  21. import {func} from "@/uni_modules/uv-ui-tools/libs/function/test";
  22. import {openAppLink} from "@/utils/plus-helper";
  23. import {createPropDefine} from "@/utils";
  24. // NOTE:这样写idea才能正常提示!
  25. // defineProps(shareProps) 在本页template无法直接提示shareProps中的属性;无法在外部使用时提示包含的属性
  26. const props = defineProps({
  27. ...shareProps,
  28. containerWrapClass: createPropDefine('py-40 px-20', [String, Object]),
  29. customAction: createPropDefine(false, Boolean)
  30. });
  31. const emits = defineEmits(["click"]);
  32. const {theme} = useTheme();
  33. const {transferTo} = useTransfer();
  34. const pagedData = computed(() => {
  35. if (props.columns <= 0 || props.rows <= 0 || !props.data.length) return [props.data];
  36. return _.chunk(props.data, props.columns * props.rows);
  37. });
  38. const pageSize = computed(() => pagedData.value.length);
  39. const swiperHeight = computed(() => props.rows * 70 + 60); // 这个高度并不太准,只保证少量几行没问题
  40. const handleMenuClick = function (menu) {
  41. if (menu.customAction || props.customAction) return emits("click", menu);
  42. if (func(menu.handler)) {
  43. menu.handler(menu);
  44. return;
  45. }
  46. if (!menu?.path) return;
  47. if (menu.appLink) {
  48. openAppLink(menu.path);
  49. return;
  50. }
  51. transferTo(menu.path, menu.nextData);
  52. };
  53. </script>
  54. <style scoped>
  55. </style>