JengaDebugBtn.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React from 'react'
  2. import i18n from 'i18next'
  3. import uiActions from 'actions/ui'
  4. import cooperateActions from 'actions/cooperate'
  5. import treeStores from 'stores/tree'
  6. import serviceStores from 'src/stores/service'
  7. import { getEventNodeById } from 'stores/funcs/newEvent'
  8. import { saveCaseBeforeActions } from 'stores/funcs/service'
  9. export default class JengaDebugBtn extends React.Component {
  10. constructor(props) {
  11. super(props)
  12. this.saveCase = this.saveCase.bind(this)
  13. this.debugService = this.debugService.bind(this)
  14. this.onClick = this.onClick.bind(this)
  15. }
  16. saveCase(done) {
  17. uiActions.toggleLoadingBar({
  18. show: true,
  19. title: i18n.t('LoadingBar.debugServiceTitle'),
  20. content: i18n.t('LoadingBar.debugServiceContent'),
  21. progress: 100,
  22. type: 'dbLoading'
  23. })
  24. saveCaseBeforeActions({
  25. success: () => {
  26. done && done()
  27. },
  28. fail: () => {
  29. uiActions.toggleLoadingBar({ show: false })
  30. }
  31. })
  32. }
  33. debugService(cb) {
  34. let node = getEventNodeById(this.props.nodeId)
  35. if (node) {
  36. let { nid, eid, gid, uid, client } = treeStores.curCaseInfo
  37. let data = {
  38. _nid: nid,
  39. _eid: eid,
  40. _gid: gid,
  41. _uid: uid,
  42. _sid: node.id,
  43. _locOffset: new Date().getTimezoneOffset() * -60
  44. }
  45. // 多人开发添加client
  46. cooperateActions.getIsGroupWork(isGroupWork => {
  47. if (isGroupWork) {
  48. data._client = client
  49. }
  50. })
  51. if (
  52. node &&
  53. node.props &&
  54. node.props.inParams &&
  55. node.props.inParams.length > 0
  56. ) {
  57. node.props.inParams.forEach(param => {
  58. if (param.name && (param.default || param.default === 0)) {
  59. data[param.name] = serviceStores.dealDefaultParam(
  60. param.default,
  61. param.type,
  62. true
  63. )
  64. }
  65. })
  66. }
  67. serviceStores.debugService(
  68. data,
  69. code => {
  70. uiActions.toggleLoadingBar({ show: false })
  71. cb && cb(code)
  72. },
  73. true
  74. )
  75. }
  76. }
  77. onClick() {
  78. this.saveCase(() => {
  79. this.debugService(code => {
  80. uiActions.toggleServiceDebug({ show: true, code })
  81. })
  82. })
  83. }
  84. render() {
  85. return (
  86. <button className="btn-clear btn-debug" onClick={this.onClick}>
  87. {i18n.t('EventView.jenga_nav.debug')}
  88. </button>
  89. )
  90. }
  91. }