ModuleOriginal.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <!-- 原版模块 -->
  3. <component
  4. :is="getModuleComponent(showStyle)"
  5. :style="style"
  6. :title="moduleName"
  7. :visible="visible"
  8. :class="{ 'cursor-pointer': !!moduleData.to }"
  9. @close="$emit('close')"
  10. @click="redirectTo"
  11. >
  12. <slot>
  13. <Header :deviceType="deviceType" :moduleData="moduleData" :data="data" @select="selectedData = $event" />
  14. <Content :style="{ height: header.show ? 'calc(100% - 30px)' : '100%' }" :moduleData="moduleData" :data="selectedData" />
  15. </slot>
  16. </component>
  17. </template>
  18. <script lang="ts" setup>
  19. import Header from './header.vue';
  20. import Content from './content.vue';
  21. import ModuleLeft from './original/moduleLeft.vue';
  22. import ModuleBottom from './original/moduleBottom.vue';
  23. import { computed, ref } from 'vue';
  24. import { openWindow } from '/@/utils';
  25. import { getFormattedText } from '../hooks/helper';
  26. // import { ModuleProps } from '../types';
  27. const props = defineProps<{
  28. /** 配置的详细模块信息 */
  29. moduleData: any;
  30. /** 配置的详细样式信息 */
  31. showStyle: any;
  32. /** 该模块配置中的设备标识符 */
  33. deviceType: string;
  34. /** api返回的数据 */
  35. data: any;
  36. moduleName: string;
  37. visible: boolean;
  38. }>();
  39. defineEmits(['close', 'click']);
  40. const { header } = props.moduleData;
  41. const selectedData = ref();
  42. const style = computed(() => {
  43. const size = props.showStyle.size;
  44. const position = props.showStyle.position;
  45. return size + position;
  46. });
  47. // 根据配置里的定位判断应该使用哪个module组件
  48. function getModuleComponent({ size, position }) {
  49. const [_, width] = size.match(/width:([0-9]+)px/) || [];
  50. if (position.includes('bottom') || parseInt(width) > 800) {
  51. return ModuleBottom;
  52. }
  53. if (position.includes('left')) {
  54. return ModuleLeft;
  55. }
  56. if (position.includes('right')) {
  57. return ModuleLeft;
  58. }
  59. return ModuleBottom;
  60. }
  61. function redirectTo() {
  62. const { to } = props.moduleData;
  63. if (!to) return;
  64. openWindow(getFormattedText(selectedData.value, to));
  65. }
  66. </script>