HttpNode1.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <!--
  2. * @Author: liuJie
  3. * @Date: 2026-01-25 15:18:09
  4. * @LastEditors: liuJie
  5. * @LastEditTime: 2026-01-25 19:05:43
  6. * @Describe: http节点
  7. -->
  8. <script setup lang="ts">
  9. import { Position } from '@vue-flow/core'
  10. import CanvasHandle from '../handles/CanvasHandle.vue'
  11. import { Icon } from '@repo/ui'
  12. interface HttpConfig {
  13. method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
  14. url?: string
  15. timeout?: number
  16. }
  17. interface Props {
  18. data: {
  19. label?: string
  20. description?: string
  21. config?: HttpConfig
  22. [key: string]: any
  23. }
  24. selected?: boolean
  25. }
  26. const props = withDefaults(defineProps<Props>(), {
  27. selected: false
  28. })
  29. console.log(props.data.id, '1212121')
  30. // 请求方法对应的颜色
  31. const methodColors: Record<string, string> = {
  32. GET: '#1890ff',
  33. POST: '#52c41a',
  34. PUT: '#faad14',
  35. DELETE: '#ff4d4f',
  36. PATCH: '#722ed1'
  37. }
  38. const currentMethod = props.data.config?.method || 'GET'
  39. const methodColor = methodColors[currentMethod]
  40. </script>
  41. <template>
  42. <div
  43. class="relative min-w-[240px] transition-all duration-300 ease-out hover:-translate-y-0.5"
  44. :class="{ 'scale-105': selected }"
  45. >
  46. <!-- 节点主体 -->
  47. <div
  48. class="bg-gradient-to-br from-white to-blue-50 border-2 rounded-xl shadow-md transition-all duration-300 relative overflow-hidden"
  49. :class="
  50. selected
  51. ? 'border-blue-500 shadow-blue-200 shadow-lg'
  52. : 'border-blue-300 hover:shadow-lg hover:shadow-blue-100'
  53. "
  54. >
  55. <!-- 左侧装饰条 -->
  56. <div
  57. class="absolute left-0 top-0 bottom-0 w-1 bg-gradient-to-b from-blue-500 to-blue-400 rounded-l-xl"
  58. ></div>
  59. <!-- 头部 -->
  60. <div class="flex items-center gap-3 px-4 py-3 border-b border-blue-100">
  61. <!-- 图标 -->
  62. <div
  63. class="relative flex-shrink-0 flex items-center justify-center w-10 h-10 bg-gradient-to-br from-blue-500 to-blue-400 rounded-lg shadow-md shadow-blue-200"
  64. >
  65. <div
  66. class="absolute inset-0 bg-gradient-to-br from-white/30 to-transparent rounded-lg"
  67. ></div>
  68. <Icon icon="lucide:cloud" color="#ffffff" class="relative z-10" :size="20" />
  69. </div>
  70. <!-- 标题 -->
  71. <div class="flex-1 min-w-0">
  72. <div class="text-sm font-semibold text-gray-800 truncate">
  73. {{ data.label || 'HTTP 请求' }}
  74. </div>
  75. <div v-if="data.description" class="text-xs text-gray-500 mt-0.5 truncate">
  76. {{ data.description }}
  77. </div>
  78. </div>
  79. <!-- 请求方法标签 -->
  80. <div
  81. class="flex-shrink-0 px-2 py-1 rounded text-xs font-bold text-white"
  82. :style="{ backgroundColor: methodColor }"
  83. >
  84. {{ currentMethod }}
  85. </div>
  86. </div>
  87. <!-- 配置信息 -->
  88. <div class="px-4 py-3 space-y-2">
  89. <!-- URL -->
  90. <div class="flex items-start gap-2">
  91. <Icon icon="lucide:link" color="#94a3b8" :size="14" class="flex-shrink-0 mt-0.5" />
  92. <div class="flex-1 min-w-0">
  93. <div class="text-xs text-gray-500 mb-0.5">请求地址</div>
  94. <div class="text-xs text-gray-700 font-mono bg-gray-50 px-2 py-1 rounded truncate">
  95. {{ data.config?.url || '未配置' }}
  96. </div>
  97. </div>
  98. </div>
  99. <!-- 超时时间 -->
  100. <div v-if="data.config?.timeout" class="flex items-center gap-2">
  101. <Icon icon="lucide:clock" color="#94a3b8" :size="14" class="flex-shrink-0" />
  102. <div class="text-xs text-gray-600">
  103. <span class="text-gray-500">超时:</span>
  104. <span class="font-medium ml-1">{{ data.config.timeout }}ms</span>
  105. </div>
  106. </div>
  107. </div>
  108. <!-- 底部状态栏 -->
  109. <div
  110. class="flex items-center justify-between px-4 py-2 bg-blue-50/50 border-t border-blue-100"
  111. >
  112. <div class="flex items-center gap-1.5">
  113. <div class="w-1.5 h-1.5 bg-blue-500 rounded-full"></div>
  114. <span class="text-xs text-gray-500">就绪</span>
  115. </div>
  116. <Icon
  117. icon="lucide:settings"
  118. color="#94a3b8"
  119. :size="14"
  120. class="cursor-pointer hover:text-blue-500 transition-colors"
  121. />
  122. </div>
  123. </div>
  124. <!-- 输入连接点 -->
  125. <CanvasHandle
  126. handle-id="http-node-input"
  127. type="target"
  128. :connections-count="1"
  129. :position="Position.Left"
  130. />
  131. <!-- 输出连接点 -->
  132. <CanvasHandle
  133. handle-id="http-node-output"
  134. type="source"
  135. :connections-count="1"
  136. :position="Position.Right"
  137. />
  138. </div>
  139. </template>
  140. <style scoped lang="less"></style>