ModuleEnhanced.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <!-- 新版模块 -->
  3. <component
  4. :is="getModuleComponent(showStyle.position)"
  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 './enhanced/moduleLeft.vue';
  22. import ModuleRight from './enhanced/moduleRight.vue';
  23. import ModuleBottom from './enhanced/moduleBottom.vue';
  24. import { computed, ref } from 'vue';
  25. import { openWindow } from '/@/utils';
  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(position) {
  49. if (position.includes('bottom')) {
  50. return ModuleBottom;
  51. }
  52. if (position.includes('left')) {
  53. return ModuleLeft;
  54. }
  55. if (position.includes('right')) {
  56. return ModuleRight;
  57. }
  58. return ModuleLeft;
  59. }
  60. function redirectTo() {
  61. const { to } = props.moduleData;
  62. if (!to) return;
  63. openWindow(to);
  64. }
  65. </script>