s-float-menu.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <!-- TODO-jj: 点击遮罩关闭 -->
  3. <view>
  4. <view v-if="data?.show === 1">
  5. <uni-fab
  6. ref="fabRef"
  7. :pattern="state.pattern"
  8. :content="state.content"
  9. horizontal="right"
  10. vertical="bottom"
  11. :direction="state.direction"
  12. @trigger="trigger"
  13. @fabClick="fabClick"
  14. :popMenu="true"
  15. ></uni-fab>
  16. </view>
  17. <view :class="state.show ? 'float-bg' : ''" @click="onTap"></view>
  18. </view>
  19. </template>
  20. <script setup>
  21. import sheep from '@/sheep';
  22. import { computed, reactive, ref, unref, getCurrentInstance } from 'vue';
  23. import { onBackPress } from '@dcloudio/uni-app';
  24. const data = computed(() => sheep.$store('app').template.basic?.floatMenu);
  25. const state = reactive({
  26. pattern: [],
  27. content: [],
  28. direction: '',
  29. show: false,
  30. });
  31. const fabRef = ref(null);
  32. const vm = getCurrentInstance();
  33. if (data.value?.mode === 1) {
  34. state.direction = 'vertical';
  35. } else {
  36. state.direction = 'horizontal';
  37. }
  38. data.value?.list.forEach((i) => {
  39. if (data.value?.isText === 0) {
  40. state.content.push({ iconPath: sheep.$url.cdn(i.src), url: i.url });
  41. } else {
  42. state.content.push({ iconPath: sheep.$url.cdn(i.src), text: i.title.text + '', url: i.url });
  43. }
  44. state.pattern.push({ color: i.title.color });
  45. });
  46. function trigger(e) {
  47. sheep.$router.go(e.item.url);
  48. }
  49. function onTap() {
  50. if (state.show) {
  51. state.show = false;
  52. vm.refs.fabRef.close();
  53. } else {
  54. state.show = true;
  55. vm.refs.fabRef.open();
  56. }
  57. }
  58. function fabClick() {
  59. state.show = !state.show;
  60. }
  61. onBackPress(() => {
  62. if (unref(fabRef).isShow) {
  63. unref(fabRef).close();
  64. return true;
  65. } else {
  66. return false;
  67. }
  68. });
  69. </script>
  70. <style lang="scss" scoped>
  71. .float-bg {
  72. position: fixed;
  73. left: 0;
  74. top: 0;
  75. z-index: 11;
  76. width: 100%;
  77. height: 100%;
  78. background-color: rgba(#000000, 0.4);
  79. }
  80. </style>