mesh.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import request, { tenantRequest } from '@/utils/request'
  2. import {
  3. add,
  4. update,
  5. del,
  6. addTenant,
  7. messageSend
  8. } from './base'
  9. export function getMeshes (query) {
  10. const { pageNum: pageIndex, pageSize, ...params } = query
  11. return tenantRequest({
  12. url: '/device/mesh/pageQuery',
  13. method: 'GET',
  14. params: addTenant({
  15. pageIndex, pageSize,
  16. ...params
  17. })
  18. })
  19. }
  20. export function addMesh (data) {
  21. return add({
  22. url: '/device/mesh',
  23. method: 'POST',
  24. data: addTenant(data)
  25. }, tenantRequest)
  26. }
  27. export function deleteMesh ({ meshId, name }) {
  28. return del({
  29. url: '/device/mesh',
  30. method: 'DELETE',
  31. params: { meshId }
  32. }, name)
  33. }
  34. export function updateMesh (data) {
  35. return update({
  36. url: '/device/mesh',
  37. method: 'PUT',
  38. data
  39. })
  40. }
  41. export function getMesh (meshId) {
  42. return request({
  43. url: '/device/mesh/getMeshStructure',
  44. method: 'GET',
  45. params: { meshId }
  46. })
  47. }
  48. export function addNodeToMesh (meshId, node) {
  49. return add({
  50. url: '/device/mesh/node',
  51. method: 'POST',
  52. data: {
  53. meshId,
  54. ...node
  55. }
  56. })
  57. }
  58. export function updateNode (node) {
  59. return update({
  60. url: '/device/mesh/node',
  61. method: 'PUT',
  62. data: node
  63. })
  64. }
  65. export function deleteNode ({ id }) {
  66. return messageSend({
  67. url: '/device/mesh/node',
  68. method: 'DELETE',
  69. params: { nodeId: id }
  70. }, '删除')
  71. }
  72. export function addNodeAfterNode (targetNode, node, port = -1) {
  73. return add({
  74. url: '/device/bind/insertAfter',
  75. method: 'POST',
  76. data: {
  77. id: targetNode.id,
  78. port,
  79. node: {
  80. meshId: targetNode.meshId,
  81. ...node
  82. }
  83. }
  84. })
  85. }
  86. export function addNodeBeforeNode (targetNode, node, port = -1) {
  87. return add({
  88. url: '/device/bind/insertAhead',
  89. method: 'POST',
  90. data: {
  91. id: targetNode.id,
  92. port,
  93. node: {
  94. meshId: targetNode.meshId,
  95. ...node
  96. }
  97. }
  98. })
  99. }
  100. export function insertNodeToEdge (edge, node, port = -1) {
  101. return add({
  102. url: '/device/bind/insertBetween',
  103. method: 'POST',
  104. data: {
  105. id: edge.nodeBondId,
  106. port,
  107. node: {
  108. meshId: edge.meshId,
  109. ...node
  110. }
  111. }
  112. })
  113. }
  114. export function addEdgeToMesh (meshId, sourceNode, targetNode, port = -1) {
  115. return messageSend({
  116. url: '/device/bind/nodeBond',
  117. method: 'POST',
  118. data: {
  119. meshId,
  120. preNodeId: sourceNode.id,
  121. preNodeType: sourceNode.nodeType,
  122. nextNodeId: targetNode.id,
  123. nextNodeType: targetNode.nodeType,
  124. port
  125. }
  126. }, '连接')
  127. }
  128. export function deleteEdge ({ nodeBondId }) {
  129. return messageSend({
  130. url: `/device/bind/nodeBond?bondId=${nodeBondId}`,
  131. method: 'DELETE'
  132. }, '删除连接')
  133. }
  134. export function updateEdgePort ({ meshId, nodeBondId, preNodeId, preNodeType, nextNodeId, nextNodeType }, port) {
  135. const edge = {
  136. meshId,
  137. nodeBondId,
  138. preNodeId,
  139. preNodeType,
  140. nextNodeId,
  141. nextNodeType,
  142. port
  143. }
  144. return messageSend({
  145. url: '/device/bind/nodeBond',
  146. method: 'PUT',
  147. data: edge
  148. }, '更新端口').then(() => {
  149. return { data: edge }
  150. })
  151. }
  152. export function reverseEdge ({ meshId, nodeBondId, preNodeId, preNodeType, nextNodeId, nextNodeType, port }) {
  153. const edge = {
  154. meshId,
  155. nodeBondId,
  156. preNodeId: nextNodeId,
  157. preNodeType: nextNodeType,
  158. nextNodeId: preNodeId,
  159. nextNodeType: preNodeType,
  160. port
  161. }
  162. return messageSend({
  163. url: '/device/bind/nodeBond',
  164. method: 'PUT',
  165. data: edge
  166. }, '反转').then(() => {
  167. return { data: edge }
  168. })
  169. }
  170. export function bindInstanceToNode ({ meshId, id, nodeType }, instance) {
  171. return messageSend({
  172. url: '/device/mesh/nodeAndInstance',
  173. method: 'POST',
  174. data: {
  175. meshId, id, nodeType,
  176. instanceId: instance.id
  177. }
  178. }, '绑定')
  179. }
  180. export function releaseInstanceFormNode ({ id }) {
  181. return messageSend({
  182. url: `/device/bind/nodeAndInstance?nodeId=${id}`,
  183. method: 'DELETE'
  184. }, '解绑')
  185. }
  186. export function getMeshByBox (deviceId) {
  187. return request({
  188. url: '/device/mesh/getStructureByDeviceId',
  189. method: 'GET',
  190. params: { deviceId }
  191. })
  192. }
  193. export function getMeshByInstance (instanceId) {
  194. return request({
  195. url: '/device/mesh/getMeshByInstanceId',
  196. method: 'GET',
  197. params: { instanceId }
  198. })
  199. }
  200. export function getThirdPartyDevicesByThirdPartyDevice (instanceId, typeList, options) {
  201. return request({
  202. url: '/device/bind/listAssignedNode',
  203. method: 'POST',
  204. data: {
  205. instanceId,
  206. typeList
  207. },
  208. ...options
  209. })
  210. }
  211. export function getFollowThirdPartyDevicesByThirdPartyDevice (instanceId, typeList, options) {
  212. return request({
  213. url: '/device/bind/listAssignedBindNode',
  214. method: 'POST',
  215. data: {
  216. instanceId,
  217. typeList
  218. },
  219. ...options
  220. })
  221. }