QuickMonitor.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <script setup>
  2. import commonDialog from '@/components/dialog/Dialog.vue'
  3. import CollectInfo from '@/components/collect-info/CollectInfo.vue'
  4. import MonitorPopover from '@/components/common/MonitorPopover.vue'
  5. import MonitorGroup from '@/composables/quick-monitor/component/MonitorGroup.vue'
  6. import { useQuickMonitorModel } from '@/composables/quick-monitor'
  7. import { getCurrentInstance, ref } from 'vue'
  8. const props = defineProps({
  9. type: String,
  10. params: String,
  11. // 如果需要多个监控复用一个 model,需要传递 true
  12. cache: {
  13. type: Boolean,
  14. default: false
  15. },
  16. // 自动调用 doFetch 获取状态接口
  17. auto: {
  18. type: Boolean,
  19. default: true
  20. },
  21. // 留资来源
  22. source: {
  23. type: Object,
  24. default: () => ({})
  25. }
  26. })
  27. const that = getCurrentInstance().proxy
  28. const groupRef = ref('')
  29. const {
  30. // 基础展示信息
  31. model,
  32. doFetch,
  33. doAddFollow,
  34. TextConfig,
  35. // popover 悬浮信息
  36. monitorPopoverConfig,
  37. doClickMonitorActions,
  38. // dialog 提示弹窗
  39. dialogConfig,
  40. // 留资
  41. collectElement,
  42. // 分组
  43. groupList,
  44. doChangeGroup,
  45. doUpdateGroup,
  46. eleLoading
  47. } = useQuickMonitorModel({
  48. type: props.type,
  49. id: props.params,
  50. cache: props.cache,
  51. source: props.source
  52. })
  53. if (props.auto) {
  54. doFetch()
  55. }
  56. function getParams() {
  57. return props.params
  58. }
  59. function onGroupDisabled(val) {
  60. dialogConfig.value.footerActions.forEach((v) => (v.disabled = val))
  61. that.$forceUpdate()
  62. }
  63. // 新增分组
  64. function onAddGroup(data) {
  65. doUpdateGroup({ type: 'add', name: data?.name })
  66. }
  67. // 编辑分组
  68. function onEditGroup(data) {
  69. doUpdateGroup({ type: 'put', groupId: data?.groupId, name: data?.name })
  70. }
  71. // 选择分组组件change回调事件
  72. function onChangeGroup(id) {
  73. doChangeGroup(id)
  74. }
  75. function doClickMonitorActionsFn(item) {
  76. // 未触发子组件change事件时,手动获取选中的分组
  77. if (groupRef.value) {
  78. const selected = groupRef.value.getSelected()
  79. doChangeGroup(selected)
  80. }
  81. doClickMonitorActions(item.action || 'doCloseDialog')
  82. }
  83. defineExpose({
  84. model,
  85. getParams
  86. })
  87. </script>
  88. <template>
  89. <div class="quick-monitor" v-if="model.canFollow">
  90. <!-- icon + popover -->
  91. <div class="quick-monitor-popover">
  92. <el-popover
  93. popper-class="monitor-popover"
  94. placement="bottom"
  95. :append-to-body="false"
  96. width="224"
  97. trigger="hover"
  98. >
  99. <div
  100. v-loading.lock="eleLoading"
  101. slot="reference"
  102. class="flex-r-c center action-icon"
  103. @click.stop="doAddFollow"
  104. >
  105. <i
  106. class="icon iconfont"
  107. :class="{
  108. 'icon-yijiankong': model.follow,
  109. 'icon-jiankong': !model.follow
  110. }"
  111. ></i>
  112. <span>{{
  113. model.follow ? TextConfig.follow : TextConfig.default
  114. }}</span>
  115. </div>
  116. <monitor-popover
  117. v-bind="monitorPopoverConfig"
  118. @click="doClickMonitorActions"
  119. ></monitor-popover>
  120. </el-popover>
  121. </div>
  122. <!-- 提示弹窗 -->
  123. <common-dialog
  124. center
  125. custom-class="monitor-class"
  126. :width="dialogConfig.width || '380px'"
  127. :destroy-on-close="true"
  128. :visible="dialogConfig.show"
  129. :title="dialogConfig.title"
  130. >
  131. <template #footer>
  132. <button
  133. v-for="(item, index) in dialogConfig.footerActions"
  134. :key="index"
  135. class="action-button"
  136. :class="item.class"
  137. :disabled="item.disabled"
  138. @click="doClickMonitorActionsFn(item)"
  139. >
  140. {{ item.label }}
  141. </button>
  142. </template>
  143. <!-- 选择监控分组 -->
  144. <MonitorGroup
  145. v-if="dialogConfig.template === 'group'"
  146. ref="groupRef"
  147. :list="groupList"
  148. @emitDisabled="onGroupDisabled"
  149. @onChange="onChangeGroup"
  150. @add="onAddGroup"
  151. @edit="onEditGroup"
  152. >
  153. </MonitorGroup>
  154. <div v-else>{{ dialogConfig.content }}</div>
  155. </common-dialog>
  156. <!-- 留资 -->
  157. <collect-info ref="collectElement"></collect-info>
  158. </div>
  159. </template>
  160. <style lang="scss" scoped>
  161. .quick-monitor-popover {
  162. position: relative;
  163. }
  164. .action-icon {
  165. cursor: pointer;
  166. .iconfont {
  167. font-size: 18px;
  168. color: #9b9ca3;
  169. &.icon-yijiankong {
  170. color: #ff9f40;
  171. }
  172. & + span {
  173. margin-left: 2px;
  174. }
  175. }
  176. ::v-deep {
  177. .el-loading-spinner {
  178. margin-top: -12px;
  179. .circular {
  180. width: 24px;
  181. height: 24px;
  182. }
  183. }
  184. }
  185. }
  186. ::v-deep {
  187. .monitor-class {
  188. padding: 32px;
  189. left: 50%;
  190. top: 50%;
  191. transform: translate(-50%, -50%);
  192. margin: 0px !important;
  193. .el-dialog__header {
  194. padding: 0;
  195. }
  196. .el-dialog__body {
  197. padding: 20px 0 32px;
  198. text-align: center;
  199. }
  200. .el-dialog__footer {
  201. padding: 0;
  202. }
  203. }
  204. .action-button.cancel[disabled] {
  205. background-color: #e3e4e5;
  206. color: #999999;
  207. }
  208. }
  209. </style>