BasicHelp.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <script lang="ts">
  2. import type { PropType } from 'vue';
  3. import { defineComponent, computed, unref, h } from 'vue';
  4. import { Tooltip } from 'ant-design-vue';
  5. import { InfoCircleOutlined } from '@ant-design/icons-vue';
  6. import { getPopupContainer } from '/@/utils';
  7. import { isString, isArray } from '/@/utils/is';
  8. import { getSlot } from '/@/utils/helper/tsxHelper';
  9. export default defineComponent({
  10. name: 'BasicHelp',
  11. components: { Tooltip },
  12. props: {
  13. // max-width
  14. maxWidth: {
  15. type: String as PropType<string>,
  16. default: '600px',
  17. },
  18. // Whether to display the serial number
  19. showIndex: {
  20. type: Boolean as PropType<boolean>,
  21. default: false,
  22. },
  23. // Text list
  24. text: {
  25. type: [Array, String] as PropType<string[] | string>,
  26. },
  27. // color
  28. color: {
  29. type: String as PropType<string>,
  30. default: '#ffffff',
  31. },
  32. fontSize: {
  33. type: String as PropType<string>,
  34. default: '14px',
  35. },
  36. absolute: {
  37. type: Boolean as PropType<boolean>,
  38. default: false,
  39. },
  40. // 定位
  41. position: {
  42. type: [Object] as PropType<any>,
  43. default: () => ({
  44. position: 'absolute',
  45. left: 0,
  46. bottom: 0,
  47. }),
  48. },
  49. },
  50. setup(props, { slots }) {
  51. const getOverlayStyleRef = computed(() => {
  52. return {
  53. maxWidth: props.maxWidth,
  54. };
  55. });
  56. const getWrapStyleRef = computed(() => {
  57. return {
  58. color: props.color,
  59. fontSize: props.fontSize,
  60. };
  61. });
  62. const getMainStyleRef = computed(() => {
  63. return props.absolute ? props.position : {};
  64. });
  65. /**
  66. * @description: 渲染内容
  67. */
  68. const renderTitle = () => {
  69. const list = props.text;
  70. if (isString(list)) {
  71. return h('p', list);
  72. }
  73. if (isArray(list)) {
  74. return list.map((item, index) => {
  75. return h('p', { key: item }, [props.showIndex ? `${index + 1}. ` : '', item]);
  76. });
  77. }
  78. return null;
  79. };
  80. return () => {
  81. return h(
  82. Tooltip,
  83. {
  84. title: h(
  85. 'div',
  86. {
  87. style: unref(getWrapStyleRef),
  88. },
  89. [renderTitle()]
  90. ) as any,
  91. overlayClassName: 'base-help__wrap',
  92. autoAdjustOverflow: true,
  93. overlayStyle: unref(getOverlayStyleRef),
  94. placement: 'right',
  95. getPopupContainer: () => getPopupContainer(),
  96. },
  97. {
  98. default: () =>
  99. h(
  100. 'span',
  101. {
  102. class: 'base-help',
  103. style: unref(getMainStyleRef),
  104. },
  105. getSlot(slots) || h(InfoCircleOutlined)
  106. ),
  107. }
  108. );
  109. };
  110. },
  111. });
  112. </script>
  113. <style lang="less">
  114. @import (reference) '../../../design/index.less';
  115. .base-help {
  116. display: inline-block;
  117. margin-left: 6px;
  118. font-size: 14px;
  119. color: @text-color-help-dark;
  120. cursor: pointer;
  121. &:hover {
  122. color: @primary-color;
  123. }
  124. &__wrap {
  125. p {
  126. margin-bottom: 0;
  127. }
  128. }
  129. }
  130. </style>