NodeServiceParams.jsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. import React from 'react'
  2. import { Select, Switch, message } from 'antd'
  3. import i18n from 'i18next'
  4. import cls from 'classnames'
  5. import treeActions from 'actions/tree'
  6. import uiActions from 'actions/ui'
  7. import serviceActions from 'actions/service'
  8. import widgetStore from 'stores/widget'
  9. import treeStore from 'stores/tree'
  10. import newEventStores from 'stores/newEvent'
  11. import serviceStore from 'stores/service'
  12. import { getEventNodeById } from 'stores/funcs/newEvent'
  13. import { isValidParamName } from 'stores/funcs/event/eventUtils'
  14. import { nodeIsNormalService } from 'stores/funcs/nodeType'
  15. import { saveCaseBeforeActions } from 'stores/funcs/service'
  16. import propType from 'const/propType'
  17. const { Option } = Select
  18. export default class NodeServiceParams extends React.Component {
  19. constructor(props) {
  20. super(props)
  21. this.state = {
  22. inParams: this.getInParams(),
  23. outParams: this.getOutParams(),
  24. title: this.getTitleName(),
  25. paramWarning: undefined,
  26. allowConfigShare: false, // true, false, reload, loading
  27. isShared: false,
  28. sharedTitle: '', // 服务的title
  29. sharedDesc: '' // 服务的desc
  30. }
  31. this.sharedServiceInfo = undefined // 读取的共享服务信息需要使用的部分
  32. this.types = [
  33. {
  34. name: i18n.t('FunctionView.Any'),
  35. value: 'undefined'
  36. },
  37. {
  38. name: i18n.t('FunctionView.Number'),
  39. value: propType.Number
  40. },
  41. {
  42. name: i18n.t('FunctionView.String'),
  43. value: propType.String
  44. },
  45. {
  46. name: i18n.t('FunctionView.Boolean'),
  47. value: propType.Boolean
  48. },
  49. {
  50. name: i18n.t('FunctionView.Object'),
  51. value: 'Object'
  52. }
  53. ]
  54. this.loadSharedService = this.loadSharedService.bind(this)
  55. this.configResult = this.configResult.bind(this)
  56. this.reloadAction = this.reloadAction.bind(this)
  57. this.onAddParam = this.onAddParam.bind(this)
  58. this.saveCase = this.saveCase.bind(this)
  59. this.onChangeShared = this.onChangeShared.bind(this)
  60. this.onChangeSharedInfo = this.onChangeSharedInfo.bind(this)
  61. this.getSharedData = this.getSharedData.bind(this)
  62. this.addShareData = this.addShareData.bind(this)
  63. this.modifySharedData = this.modifySharedData.bind(this)
  64. this.deleteShareData = this.deleteShareData.bind(this)
  65. this.getInParams = this.getInParams.bind(this)
  66. this.getOutParams = this.getOutParams.bind(this)
  67. this.getInParamsName = this.getInParamsName.bind(this)
  68. this.getOutParamsName = this.getOutParamsName.bind(this)
  69. this.getTitleName = this.getTitleName.bind(this)
  70. this.genAddButton = this.genAddButton.bind(this)
  71. this.getInParamsCom = this.getInParamsCom.bind(this)
  72. this.genInput = this.genInput.bind(this)
  73. this.genError = this.genError.bind(this)
  74. this.getSharedConfig = this.getSharedConfig.bind(this)
  75. }
  76. componentDidMount() {
  77. this.loadSharedService()
  78. }
  79. componentDidUpdate(preProps) {
  80. if (preProps.nodeId !== this.props.nodeId) {
  81. this.setState(
  82. {
  83. inParams: this.getInParams(),
  84. outParams: this.getOutParams(),
  85. title: this.getTitleName(),
  86. paramWarning: undefined,
  87. allowConfigShare: false
  88. },
  89. () => {
  90. this.loadSharedService()
  91. }
  92. )
  93. }
  94. }
  95. loadSharedService() {
  96. // 小模块不需要
  97. if (
  98. treeStore.curClassId ||
  99. !(treeStore.curCaseInfo.eid || treeStore.curCaseInfo.gid)
  100. ) {
  101. this.setState({
  102. allowConfigShare: false
  103. })
  104. return
  105. }
  106. let nodeId = this.props.nodeId
  107. let node = getEventNodeById(nodeId)
  108. if (nodeIsNormalService(node && node.type)) {
  109. this.setState({
  110. allowConfigShare: 'loading'
  111. })
  112. serviceStore.loadSharedService({ nodeId }).then(result => {
  113. // 保证修改的nodeId正确
  114. let _nodeId = result && result.nodeId
  115. if (_nodeId !== nodeId) {
  116. return
  117. }
  118. let obj = {
  119. allowConfigShare: true
  120. }
  121. this.sharedServiceInfo = undefined
  122. if (result === false) {
  123. obj.allowConfigShare = 'reload'
  124. } else if (result && result.id) {
  125. obj.isShared = true
  126. obj = this.configResult(obj, result, nodeId)
  127. } else {
  128. obj.isShared = false
  129. obj.inParams = []
  130. obj.outParams = []
  131. let node = getEventNodeById(nodeId)
  132. if (node) {
  133. obj.inParams = node.props.inParams || []
  134. obj.outParams = node.props.outParams || []
  135. }
  136. }
  137. this.setState(obj)
  138. })
  139. } else {
  140. this.setState({
  141. allowConfigShare: false
  142. })
  143. }
  144. }
  145. configResult(obj, result, nodeId) {
  146. this.sharedServiceInfo = { id: result.id, uri: result.uri, gid: result.gid } // 记录当前的共享服务id
  147. if (result.content) {
  148. let params = undefined
  149. try {
  150. params = JSON.parse(result.content)
  151. } catch (e) {}
  152. if (params) {
  153. obj.sharedTitle = result.filename
  154. obj.sharedDesc = params.desc
  155. let inParams = params.inParams || []
  156. let outParams = params.outParams || []
  157. let inParamsSame = false
  158. let outParamsSame = false
  159. try {
  160. inParamsSame =
  161. JSON.stringify(inParams) === JSON.stringify(this.state.inParams)
  162. } catch (e) {}
  163. try {
  164. inParamsSame =
  165. JSON.stringify(outParams) === JSON.stringify(this.state.outParams)
  166. } catch (e) {}
  167. if (!inParamsSame || !outParamsSame) {
  168. obj.inParams = inParams
  169. obj.outParams = outParams
  170. treeActions.changeNodeProps({
  171. nodeId: nodeId,
  172. props: {
  173. inParams: inParams,
  174. outParams: outParams
  175. },
  176. addRecord: false
  177. })
  178. this.reloadAction()
  179. }
  180. }
  181. }
  182. return obj
  183. }
  184. reloadAction() {
  185. newEventStores.reloadAction(this.props.nodeId)
  186. }
  187. onAddParam(type) {
  188. let obj = { paramWarning: undefined }
  189. let params = undefined
  190. switch (type) {
  191. case 'in':
  192. params = this.state.inParams
  193. params.push({
  194. name: 'param' + (this.state.inParams.length + 1)
  195. })
  196. obj.inParams = params
  197. break
  198. case 'out':
  199. params = this.state.outParams
  200. params.push('param' + (this.state.outParams.length + 1))
  201. obj.outParams = params
  202. break
  203. }
  204. this.setState(obj, () => {
  205. delete obj.paramWarning
  206. this.modifySharedData(type, params)
  207. treeActions.changeNodeProps({
  208. nodeId: this.props.nodeId,
  209. props: obj
  210. })
  211. this.reloadAction()
  212. })
  213. }
  214. onDeleteParam(index, type) {
  215. let obj = { paramWarning: undefined }
  216. let params = undefined
  217. switch (type) {
  218. case 'in':
  219. params = this.state.inParams
  220. params.splice(index, 1)
  221. obj.inParams = params
  222. break
  223. case 'out':
  224. params = this.state.outParams
  225. params.splice(index, 1)
  226. obj.outParams = params
  227. break
  228. }
  229. this.setState(obj, () => {
  230. delete obj.paramWarning
  231. this.modifySharedData(type, params)
  232. treeActions.changeNodeProps({
  233. nodeId: this.props.nodeId,
  234. props: obj
  235. })
  236. this.reloadAction()
  237. })
  238. }
  239. onChangeType(index, type, paramType, applyChange, e) {
  240. let value = e === 'undefined' ? undefined : e
  241. this.onChangeParam(index, type, paramType, applyChange, value)
  242. }
  243. onChangeParam(index, type, paramType, applyChange, e) {
  244. let value = e && e.target ? e.target.value : e
  245. let obj = {}
  246. let params = undefined
  247. // 处理有问题字段
  248. if (type === 'out' || (type === 'in' && paramType === 'name')) {
  249. if (applyChange && !isValidParamName(value)) {
  250. let errorValue = value
  251. if (value !== 'detail') {
  252. // outParam为detail时,不对其强行修改,只给出提示.其余情况将值改为paramX
  253. value = 'param' + (index + 1)
  254. }
  255. obj.paramWarning = {
  256. error: 'paramError',
  257. type: type,
  258. index,
  259. value: errorValue
  260. }
  261. } else {
  262. obj.paramWarning = undefined
  263. }
  264. }
  265. switch (type) {
  266. case 'in':
  267. params = this.state.inParams
  268. params[index][paramType] = value
  269. if (paramType === 'required' && !value) {
  270. // 为false不需要保存
  271. delete params[index][paramType]
  272. }
  273. obj.inParams = params
  274. break
  275. case 'out':
  276. params = this.state.outParams
  277. params[index] = value
  278. obj.outParams = params
  279. break
  280. }
  281. let nodeId = this.props.nodeId
  282. this.setState(obj, () => {
  283. if (applyChange) {
  284. delete obj.paramWarning
  285. this.modifySharedData(type, params)
  286. treeActions.changeNodeProps({
  287. nodeId: nodeId,
  288. props: obj
  289. })
  290. if (type === 'out' || (type === 'in' && paramType === 'name')) {
  291. this.reloadAction()
  292. }
  293. }
  294. })
  295. }
  296. saveCase(done) {
  297. let nodeId = this.props.nodeId
  298. let node = getEventNodeById(nodeId)
  299. if (node && nodeIsNormalService(node.type) && node.uis && node.uis.new) {
  300. saveCaseBeforeActions({
  301. success: () => {
  302. done && done()
  303. },
  304. fail: () => {
  305. uiActions.toggleLoadingBar({ show: false })
  306. }
  307. })
  308. } else {
  309. done && done()
  310. }
  311. }
  312. onChangeShared(value) {
  313. if (value) {
  314. // 添加共享
  315. uiActions.toggleLoadingBar({
  316. show: true,
  317. title: i18n.t('LoadingBar.addSharedServiceTitle'),
  318. content: i18n.t('LoadingBar.addSharedServiceContent'),
  319. progress: 100,
  320. type: 'dbLoading'
  321. })
  322. this.saveCase(() => {
  323. let nodeId = this.props.nodeId
  324. let node = getEventNodeById(nodeId)
  325. this.addShareData({
  326. name: (node && node.uis && node.uis.name) || undefined
  327. }).then(result => {
  328. uiActions.toggleLoadingBar({ show: false })
  329. // 添加后操作
  330. if (result && result.isSuccess) {
  331. this.sharedServiceInfo = {
  332. id: result.id,
  333. uri: result.uri,
  334. gid: result.gid
  335. }
  336. this.setState({
  337. isShared: value,
  338. sharedTitle: result.title,
  339. sharedDesc: result.desc
  340. })
  341. if (result.gid) {
  342. serviceActions.clearGroupCache({ gid: result.gid })
  343. }
  344. } else if (result.err) {
  345. message.error(result.err)
  346. }
  347. })
  348. })
  349. } else {
  350. // 删除共享
  351. uiActions.toggleLoadingBar({
  352. show: true,
  353. title: i18n.t('LoadingBar.delSharedServiceTitle'),
  354. content: i18n.t('LoadingBar.delSharedServiceContent'),
  355. progress: 100,
  356. type: 'dbLoading'
  357. })
  358. this.deleteShareData().then(result => {
  359. uiActions.toggleLoadingBar({ show: false })
  360. // 删除后操作
  361. if (result) {
  362. this.sharedServiceInfo = undefined
  363. this.setState({
  364. isShared: value,
  365. sharedTitle: '',
  366. sharedDesc: ''
  367. })
  368. }
  369. })
  370. }
  371. }
  372. onChangeSharedInfo(type, applyChange, e) {
  373. let value = e && e.target ? e.target.value : e
  374. let obj = undefined
  375. if (type === 'title') {
  376. obj = {
  377. sharedTitle: value
  378. }
  379. } else if (type === 'desc') {
  380. obj = {
  381. sharedDesc: value
  382. }
  383. }
  384. if (obj) {
  385. this.setState(obj, () => {
  386. if (applyChange) {
  387. this.modifySharedData(type, value)
  388. }
  389. })
  390. }
  391. }
  392. getSharedData(final) {
  393. let result = {
  394. fileName: this.state.sharedTitle,
  395. content: {
  396. desc: this.state.sharedDesc,
  397. inParams: this.state.inParams,
  398. outParams: this.state.outParams
  399. }
  400. }
  401. if (final) {
  402. result.content = JSON.stringify(result.content)
  403. }
  404. return result
  405. }
  406. addShareData({ name }) {
  407. return new Promise(resolve => {
  408. let { nid, gid } = treeStore.curCaseInfo
  409. let uri = this.props.nodeId + '-' + nid
  410. let data = this.getSharedData()
  411. data.fileName = name || i18n.t('EventView.jenga_extra.defaultServiceName')
  412. data.content.desc = i18n.t('EventView.jenga_extra.defaultServiceDesc')
  413. data.scope = gid ? 1 : 2
  414. data.uri = uri
  415. if (gid) {
  416. data.gid = gid
  417. }
  418. // json化
  419. data.content = JSON.stringify(data.content)
  420. if (this.sharedServiceInfo) {
  421. resolve({ isSuccess: false })
  422. return
  423. }
  424. // 添加发送请求
  425. serviceStore.addSharedService({ data }).then(result => {
  426. if (result && result.isSuccess && result.data) {
  427. let id = result.data.id
  428. let title = result.data.filename
  429. let desc = ''
  430. try {
  431. let params = JSON.parse(result.data.content)
  432. desc = params.desc
  433. } catch (e) {}
  434. resolve({ isSuccess: true, id, uri, gid, title, desc })
  435. } else {
  436. resolve({ isSuccess: false, err: result.err })
  437. }
  438. })
  439. })
  440. }
  441. modifySharedData(type, value) {
  442. if (!this.sharedServiceInfo) {
  443. return
  444. }
  445. // content形如:{desc: xxx, inParams: xxx, outParams: xxx}
  446. let data = this.getSharedData()
  447. switch (type) {
  448. case 'title':
  449. data.fileName = value
  450. break
  451. case 'desc':
  452. data.content.desc = value
  453. break
  454. case 'in':
  455. data.content.inParams = value
  456. break
  457. case 'out':
  458. data.content.outParams = value
  459. break
  460. }
  461. // json化
  462. data.content = JSON.stringify(data.content)
  463. let { uri, gid, id } = this.sharedServiceInfo
  464. data.uri = uri
  465. if (gid) {
  466. data.gid = gid
  467. }
  468. // 修改发送请求
  469. serviceStore.modifySharedService({ id, data })
  470. }
  471. deleteShareData() {
  472. return new Promise(resolve => {
  473. if (!this.sharedServiceInfo) {
  474. resolve(false)
  475. return
  476. }
  477. // 发送删除请求
  478. let { uri, gid, id } = this.sharedServiceInfo
  479. let data = {
  480. uri: uri
  481. }
  482. if (gid) {
  483. data.gid = gid
  484. }
  485. serviceStore.delSharedService({ id, data }).then(result => {
  486. resolve(result)
  487. })
  488. })
  489. }
  490. getInParams() {
  491. let inParams = []
  492. let node = getEventNodeById(this.props.nodeId)
  493. if (node) {
  494. inParams = node.props.inParams || inParams
  495. }
  496. return inParams
  497. }
  498. getOutParams() {
  499. let outParams = []
  500. let node = getEventNodeById(this.props.nodeId)
  501. if (node) {
  502. outParams = node.props.outParams || outParams
  503. }
  504. return outParams
  505. }
  506. getInParamsName() {
  507. let title = ''
  508. let node = getEventNodeById(this.props.nodeId)
  509. if (node && widgetStore.widget[node.type]) {
  510. let prop = widgetStore.widget[node.type].map.propsMap['inParams']
  511. title = prop.locale ? prop.locale[i18n.language] : prop.name
  512. }
  513. return title + ':'
  514. }
  515. getOutParamsName() {
  516. let title = ''
  517. let node = getEventNodeById(this.props.nodeId)
  518. if (node && widgetStore.widget[node.type]) {
  519. let prop = widgetStore.widget[node.type].map.propsMap['outParams']
  520. title = prop.locale ? prop.locale[i18n.language] : prop.name
  521. }
  522. return title + ':'
  523. }
  524. getTitleName(range) {
  525. let title = ''
  526. let node = getEventNodeById(this.props.nodeId)
  527. if (node && widgetStore.widget[node.type]) {
  528. let map = widgetStore.widget[node.type].map
  529. title = map.locale ? map.locale[i18n.language] : map.name
  530. }
  531. let text = range ? 'range' : 'define'
  532. return title ? title + i18n.t('EventView.jenga_extra.' + text) : title
  533. }
  534. genAddButton(type) {
  535. return (
  536. <button
  537. className="btn-clear btn-add-param"
  538. onClick={this.onAddParam.bind(this, type)}
  539. >
  540. <div className="icon">
  541. <span className="horizon" />
  542. <span className="vertical" />
  543. </div>
  544. </button>
  545. )
  546. }
  547. getInParamsCom(param, index, type) {
  548. let length = this.state.inParams.length
  549. let extraBtn = length - 1 === index ? this.genAddButton(type) : null
  550. return (
  551. <div
  552. className={cls('param-item f--hlc', {
  553. 'param-item-bottom': length > 0 && index !== length - 1
  554. })}
  555. key={index}
  556. >
  557. <div className="item-name">
  558. {i18n.t('EventView.jenga_extra.param') + (index + 1)}
  559. </div>
  560. <div className="item-input-wrap f--hlc flex-1">
  561. <div className="item-name first inner-name">
  562. {i18n.t('EventView.jenga_extra.name')}
  563. </div>
  564. <input
  565. className="service-input"
  566. value={param.name}
  567. onChange={this.onChangeParam.bind(this, index, type, 'name', false)}
  568. onBlur={this.onChangeParam.bind(this, index, type, 'name', true)}
  569. />
  570. <div className="item-name inner-name">
  571. {i18n.t('EventView.jenga_extra.type')}
  572. </div>
  573. <Select
  574. onChange={this.onChangeType.bind(this, index, type, 'type', true)}
  575. value={param.type}
  576. placeholder={i18n.t('FunctionView.Any')}
  577. className="prop-select prop-pair-select"
  578. dropdownClassName="prop-select-dropdown"
  579. >
  580. {this.types.map((item, index) => {
  581. return (
  582. <Option key={index} value={item.value} title={item.name}>
  583. {item.name}
  584. </Option>
  585. )
  586. })}
  587. </Select>
  588. <div className="item-name inner-name">
  589. {i18n.t('EventView.jenga_extra.required')}
  590. </div>
  591. <Switch
  592. className="service-switch"
  593. checked={param.required || false}
  594. onChange={this.onChangeParam.bind(
  595. this,
  596. index,
  597. type,
  598. 'required',
  599. true
  600. )}
  601. />
  602. <div className="f--hlc default-wrap">
  603. <div className="item-name inner-name">
  604. {i18n.t('EventView.jenga_extra.default')}
  605. </div>
  606. <input
  607. className="service-input"
  608. value={param.default || ''}
  609. placeholder={i18n.t('EventView.jenga_extra.debug-placeholder')}
  610. onChange={this.onChangeParam.bind(
  611. this,
  612. index,
  613. type,
  614. 'default',
  615. false
  616. )}
  617. onBlur={this.onChangeParam.bind(
  618. this,
  619. index,
  620. type,
  621. 'default',
  622. true
  623. )}
  624. />
  625. </div>
  626. <button
  627. className="btn-clear btn-delete-param"
  628. onClick={this.onDeleteParam.bind(this, index, type)}
  629. />
  630. </div>
  631. {extraBtn}
  632. </div>
  633. )
  634. }
  635. genInput(value, index, type) {
  636. let length =
  637. type === 'in' ? this.state.inParams.length : this.state.outParams.length
  638. let extraBtn = length - 1 === index ? this.genAddButton(type) : null
  639. return (
  640. <div
  641. className={cls('param-item f--hlc', {
  642. 'param-item-left': index % 3 !== 0,
  643. 'param-item-bottom': length > 3 && index < length - (length % 3 || 3)
  644. })}
  645. key={index}
  646. >
  647. <div className="item-name">
  648. {i18n.t('EventView.jenga_extra.param') + (index + 1)}
  649. </div>
  650. <div className="item-input-wrap f--hlc flex-1">
  651. <input
  652. value={value}
  653. onChange={this.onChangeParam.bind(
  654. this,
  655. index,
  656. type,
  657. undefined,
  658. false
  659. )}
  660. onBlur={this.onChangeParam.bind(this, index, type, undefined, true)}
  661. />
  662. <button
  663. className="btn-clear btn-delete-param"
  664. onClick={this.onDeleteParam.bind(this, index, type)}
  665. />
  666. </div>
  667. {extraBtn}
  668. </div>
  669. )
  670. }
  671. genError(type) {
  672. return this.state.paramWarning && this.state.paramWarning.type === type ? (
  673. <div className="param-warning f--hlc">
  674. {'* ' +
  675. i18n.t('EventView.jenga_extra.param') +
  676. (this.state.paramWarning.index + 1) +
  677. i18n.t('EventView.jenga_extra.setAs') +
  678. '"' +
  679. this.state.paramWarning.value +
  680. '"' +
  681. ',' +
  682. i18n.t('EventView.jenga_extra.' + this.state.paramWarning.error)}
  683. </div>
  684. ) : null
  685. }
  686. getSharedConfig() {
  687. let { allowConfigShare, isShared, sharedTitle, sharedDesc } = this.state
  688. return allowConfigShare ? (
  689. <div
  690. className={cls('shared-service-config', isShared ? 'f--h' : 'f--hlc')}
  691. >
  692. <div className="title">
  693. {treeStore.curCaseInfo.gid
  694. ? i18n.t('EventView.jenga_extra.shared_group_service')
  695. : treeStore.curCaseInfo.eid
  696. ? i18n.t('EventView.jenga_extra.shared_enterprise_service')
  697. : i18n.t('EventView.jenga_extra.shared_service')}
  698. {isShared && (
  699. <span className="shared-service-tips">
  700. {i18n.t('EventView.jenga_extra.shared-service-tips')}
  701. </span>
  702. )}
  703. </div>
  704. {allowConfigShare === 'loading' ? (
  705. <div>{i18n.t('EventView.jenga_extra.loading-data')}</div>
  706. ) : allowConfigShare === 'reload' ? (
  707. <button
  708. className="btn-clear btn-reload"
  709. onClick={this.loadSharedService}
  710. >
  711. {i18n.t('EventView.jenga_extra.reload-data')}
  712. </button>
  713. ) : (
  714. <div className="f--h">
  715. <Switch
  716. checked={isShared}
  717. onChange={this.onChangeShared}
  718. className="shared-service-switch"
  719. />
  720. {isShared ? (
  721. <>
  722. <div className="shared-item f--h">
  723. <div className="item-title">
  724. {i18n.t('EventView.jenga_extra.service-title')}
  725. </div>
  726. <input
  727. value={sharedTitle}
  728. onChange={this.onChangeSharedInfo.bind(
  729. this,
  730. 'title',
  731. false
  732. )}
  733. onBlur={this.onChangeSharedInfo.bind(this, 'title', true)}
  734. />
  735. </div>
  736. <div className="shared-item f--h">
  737. <div className="item-title">
  738. {i18n.t('EventView.jenga_extra.service-desc')}
  739. </div>
  740. <textarea
  741. value={sharedDesc}
  742. onChange={this.onChangeSharedInfo.bind(this, 'desc', false)}
  743. onBlur={this.onChangeSharedInfo.bind(this, 'desc', true)}
  744. />
  745. </div>
  746. </>
  747. ) : null}
  748. </div>
  749. )}
  750. </div>
  751. ) : null
  752. }
  753. render() {
  754. return (
  755. <div className="jenga-node-params jenga-normal-service-params">
  756. {this.getSharedConfig()}
  757. <div
  758. className={cls(
  759. 'params params-in no-border',
  760. this.state.inParams.length > 0 ? 'f--h' : 'f--hlc'
  761. )}
  762. >
  763. <div
  764. className={cls(
  765. 'params-title params-in-title',
  766. this.state.inParams.length > 1
  767. ? 'params-title-top f--h'
  768. : 'f--hlc'
  769. )}
  770. >
  771. {this.getInParamsName()}
  772. </div>
  773. <div>
  774. <div className="main-wrap f--hlc">
  775. {this.state.inParams.length === 0
  776. ? this.genAddButton('in')
  777. : this.state.inParams.map((param, index) => {
  778. return this.getInParamsCom(param, index, 'in')
  779. })}
  780. </div>
  781. {this.genError('in')}
  782. </div>
  783. </div>
  784. <div
  785. className={cls(
  786. 'params params-out',
  787. this.state.outParams.length > 0 ? 'f--h' : 'f--hlc'
  788. )}
  789. >
  790. <div
  791. className={cls(
  792. 'params-title params-out-title',
  793. this.state.outParams.length > 3
  794. ? 'params-title-top f--h'
  795. : 'f--hlc'
  796. )}
  797. >
  798. {this.getOutParamsName()}
  799. </div>
  800. <div>
  801. <div className="main-wrap f--hlc">
  802. {this.state.outParams.length === 0
  803. ? this.genAddButton('out')
  804. : this.state.outParams.map((param, index) => {
  805. return this.genInput(param, index, 'out')
  806. })}
  807. </div>
  808. {this.genError('out')}
  809. </div>
  810. </div>
  811. <div className="params-title params-def-title params-service-title f--hlc">
  812. <div className="flex-1">{this.getTitleName()}</div>
  813. </div>
  814. </div>
  815. )
  816. }
  817. }