BlockActionMethodParams.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. import React from 'react'
  2. import i18n from 'i18next'
  3. import { is } from 'immutable'
  4. import newEventActions from 'actions/newEvent'
  5. import newEventStores from 'stores/newEvent'
  6. import {
  7. getActionBlockObjNode,
  8. getEventBlockByBid
  9. } from 'stores/funcs/newEvent'
  10. import {
  11. hasEsDbSeniorSearch,
  12. isApiMethod,
  13. paramIsHideKeep,
  14. isDbMallMethodShouldReload
  15. } from 'stores/funcs/event/methodUtils'
  16. import { shallowEqualImmutable } from 'utils/utils'
  17. import { EVENT_BLOCK_TYPE } from 'const/const'
  18. import propType from 'const/propType'
  19. // import {
  20. // getActionDbNodeType,
  21. // getDbCols,
  22. // getNode,
  23. // getActionDbId
  24. // } from './dbComs/actionDbFuncs'
  25. import BlockActionMethodParamItem from './BlockActionMethodParamItem'
  26. // import BlockActionMethodParamApiToggle from './BlockActionMethodParamApiToggle'
  27. // import BlockActionMethodParamEsSeniorSearch from './BlockActionMethodParamEsSeniorSearch'
  28. export default class BlockActionMethodParams extends React.Component {
  29. constructor(props) {
  30. super(props)
  31. this.state = {
  32. // paramsValue: this.getParamsValue(),
  33. // dbInfo: {}
  34. }
  35. this.onEventChange = this.onEventChange.bind(this)
  36. // this.updateDbInfo = this.updateDbInfo.bind(this)
  37. this.paramShouldShow = this.paramShouldShow.bind(this)
  38. // this.updateMethod = this.updateMethod.bind(this)
  39. this.getObject = this.getObject.bind(this)
  40. this.getName = this.getName.bind(this)
  41. // this.getParamsValue = this.getParamsValue.bind(this)
  42. // this.getInfo = this.getInfo.bind(this)
  43. this.getVisible = this.getVisible.bind(this)
  44. // this.replenishApiParams = this.replenishApiParams.bind(this)
  45. this.renderInfo = this.renderInfo.bind(this)
  46. }
  47. shouldComponentUpdate(nextProps, nextState) {
  48. return (
  49. !shallowEqualImmutable(this.props, nextProps) ||
  50. !shallowEqualImmutable(this.state, nextState)
  51. )
  52. }
  53. componentDidMount() {
  54. this.unsubscribe = newEventStores.listen(this.onEventChange)
  55. // this.updateDbInfo()
  56. }
  57. componentWillUnmount() {
  58. this.unsubscribe()
  59. }
  60. componentDidUpdate(preProps) {
  61. // if (preProps.bid !== this.props.bid) {
  62. // this.setState({
  63. // paramsValue: this.getParamsValue()
  64. // })
  65. // this.updateDbInfo()
  66. // } else if (
  67. // !preProps.actionName &&
  68. // preProps.actionName !== this.props.actionName
  69. // ) {
  70. // // actionName由无到有
  71. // process.nextTick(() => {
  72. // this.updateDbInfo()
  73. // })
  74. // } else if (
  75. // // DbMall比较特殊,切换不同方法时需要重新获取DbCols
  76. // preProps.actionName !== this.props.actionName &&
  77. // isDbMallMethodShouldReload(this.props.actionName)
  78. // ) {
  79. // process.nextTick(() => {
  80. // this.updateDbInfo()
  81. // })
  82. // }
  83. }
  84. onEventChange(status) {
  85. // let obj = {}
  86. // if (status) {
  87. // if (
  88. // status.types.includes('updateBlockProp') &&
  89. // this.props.bid === status.data.affectBlockId &&
  90. // ['object', 'action'].indexOf(status.data.prop) >= 0
  91. // ) {
  92. // let paramsValue = this.getParamsValue()
  93. // if (!is(this.state.params, params)) {
  94. // obj.params = params
  95. // }
  96. // // 切换对象时检查
  97. // if (['object'].indexOf(status.data.prop) >= 0) {
  98. // this.updateDbInfo()
  99. // }
  100. // } else if (
  101. // status.types.includes('reloadParamsItemMethod') &&
  102. // this.props.bid === status.data.affectBlockId
  103. // ) {
  104. // this.updateMethod()
  105. // }
  106. // }
  107. // if (Object.keys(obj).length > 0) {
  108. // this.setState(obj)
  109. // }
  110. }
  111. // updateDbInfo() {
  112. // let { bid } = this.props
  113. // let node = getNode({
  114. // bid: this.props.bid,
  115. // obj: this.getObject(),
  116. // useObj: true,
  117. // actionName: this.getName()
  118. // })
  119. // let dbId = getActionDbId({ node: node, bid: bid })
  120. // let dbNodeType = getActionDbNodeType({
  121. // node: node,
  122. // bid: bid
  123. // })
  124. // if (dbId) {
  125. // getDbCols({
  126. // dbId: dbId,
  127. // nodeType: dbNodeType,
  128. // cb: dbCols => {
  129. // this.setState({
  130. // dbInfo: { dbId, dbCols, dbNodeType }
  131. // })
  132. // }
  133. // })
  134. // } else {
  135. // if (Object.keys(this.state.dbInfo).length >= 0) {
  136. // this.setState({
  137. // dbInfo: {}
  138. // })
  139. // }
  140. // }
  141. // }
  142. paramShouldShow(param, index) {
  143. let result = true
  144. switch (this.getVisible()) {
  145. case 'part':
  146. if (
  147. (!param.value && param.value !== 0 && param.value !== false) ||
  148. ((param.type === propType.Formula ||
  149. param.type === propType.FormulaColor ||
  150. param.type === propType.FormulaJson) &&
  151. param.value &&
  152. !param.value.code)
  153. ) {
  154. result = false
  155. }
  156. break
  157. }
  158. if (
  159. result &&
  160. paramIsHideKeep({
  161. param: param,
  162. bid: this.props.bid,
  163. actionName: this.getName(),
  164. index: index,
  165. nodeId: this.props.eventNodeId || newEventStores.curEventNodeId,
  166. isNewEvent: true
  167. })
  168. ) {
  169. result = false
  170. }
  171. return result
  172. }
  173. // updateMethod() {
  174. // let objNode = getActionBlockObjNode({
  175. // obj: this.getObject(),
  176. // blockId: this.props.bid
  177. // })
  178. // if (objNode) {
  179. // newEventActions.updateActionMethod({
  180. // nodeId: objNode.id,
  181. // targetBlockId: this.props.bid,
  182. // methods: [this.getName()]
  183. // })
  184. // }
  185. // }
  186. getObject() {
  187. let _obj = null
  188. let block = getEventBlockByBid(this.props.bid)
  189. if (block) {
  190. _obj = block.object
  191. }
  192. return _obj
  193. }
  194. getName() {
  195. return this.props.actionName ? this.props.actionName || null : null
  196. }
  197. // getParamsValue() {
  198. // let result = []
  199. // let block = getEventBlockByBid(this.props.bid)
  200. // if (
  201. // block &&
  202. // block.type === EVENT_BLOCK_TYPE.ACTION &&
  203. // block.action &&
  204. // block.action.params
  205. // ) {
  206. // result = block.action.params
  207. // }
  208. // return result
  209. // }
  210. getVisible() {
  211. return this.props.paramsVisible ? this.props.paramsVisible || 'all' : 'all'
  212. }
  213. // getInfo() {
  214. // let result = undefined
  215. // let block = getEventBlockByBid(this.props.bid)
  216. // if (
  217. // block &&
  218. // block.type === EVENT_BLOCK_TYPE.ACTION &&
  219. // block.action &&
  220. // block.action.info
  221. // ) {
  222. // result = block.action.info
  223. // }
  224. // return result
  225. // }
  226. // replenishApiParams(apiGroups, result) {
  227. // let groupHeader = (title, index) => {
  228. // let className = 'params-group'
  229. // if (index === 0) {
  230. // className += ' first'
  231. // }
  232. // return (
  233. // <div className={className} key={index + title}>
  234. // <div className="title">{title}</div>
  235. // <BlockActionMethodParamApiToggle
  236. // group={title}
  237. // bid={this.props.bid}
  238. // actionName={this.props.actionName}
  239. // />
  240. // </div>
  241. // )
  242. // }
  243. // let addGroupParams = (name, index, groupParams) => {
  244. // let groupIndex = apiGroups.findIndex(group => group.name === name)
  245. // if (groupIndex < 0) {
  246. // groupParams.push(groupHeader(name, index))
  247. // } else {
  248. // let group = apiGroups[groupIndex]
  249. // groupParams.push(group.header)
  250. // groupParams = groupParams.concat(group.coms)
  251. // apiGroups.splice(groupIndex, 1)
  252. // }
  253. // return groupParams
  254. // }
  255. // // 默认title
  256. // let defaultHeaders = ['Header', 'Body']
  257. // let groupParams = []
  258. // defaultHeaders.forEach((header, index) => {
  259. // groupParams = addGroupParams(header, index, groupParams)
  260. // })
  261. // // 把剩余的加上
  262. // if (apiGroups.length > 0) {
  263. // apiGroups.forEach(group => {
  264. // groupParams.push(group.header)
  265. // groupParams = groupParams.concat(group.coms)
  266. // })
  267. // }
  268. // result = result.concat(groupParams)
  269. // return result
  270. // }
  271. // replenishSeniorSearchParams(searchParams, result) {
  272. // let groupParams = []
  273. // let groupHeader = title => {
  274. // let className = 'params-group first'
  275. // return (
  276. // <div className={className} key={title}>
  277. // <BlockActionMethodParamEsSeniorSearch
  278. // group={title}
  279. // bid={this.props.bid}
  280. // actionName={this.props.actionName}
  281. // />
  282. // </div>
  283. // )
  284. // }
  285. // let addGroupParams = name => {
  286. // groupParams.push(groupHeader(name))
  287. // groupParams = groupParams.concat(searchParams[0].coms)
  288. // return groupParams
  289. // }
  290. // if (searchParams && searchParams.length > 0) {
  291. // groupParams = addGroupParams('SeniorEsSearch')
  292. // if (result && result.length > 0) {
  293. // if (
  294. // result[0].props &&
  295. // result[0].props.param &&
  296. // result[0].props.param.name === 'query'
  297. // ) {
  298. // let pre = result.slice(0, 1)
  299. // let sub = result.slice(1, result.length)
  300. // result = pre.concat(groupParams).concat(sub)
  301. // } else {
  302. // result = groupParams.concat(result)
  303. // }
  304. // } else {
  305. // result = groupParams
  306. // }
  307. // }
  308. // return result
  309. // }
  310. renderInfo() {
  311. let params = this.props.params
  312. let visible = this.getVisible()
  313. let shouldRender = 0
  314. let normal = [] // 普通params
  315. let cloneChild = [] // 克隆对象params
  316. let groups = [] // 带pGroup的params {name, coms}
  317. let groupStyle = isApiMethod(this.props.actionName)
  318. ? {
  319. backgroundColor: '#385452',
  320. marginBottom: 0,
  321. paddingBottom: '2px'
  322. }
  323. : undefined
  324. let groupClass = undefined
  325. params.map((param, index) => {
  326. groupClass =
  327. hasEsDbSeniorSearch(this.props.actionName) && param.pGroup
  328. ? 'group-param-item'
  329. : groupClass
  330. if (this.paramShouldShow(param, index)) {
  331. shouldRender += 1
  332. if (param.pGroup && false) {
  333. let pGroup = groups.find(item => {
  334. return item.name === param.pGroup
  335. })
  336. if (pGroup) {
  337. pGroup.coms.push(
  338. <BlockActionMethodParamItem
  339. key={index}
  340. paramStyle={groupStyle}
  341. paramClass={groupClass}
  342. bid={this.props.bid}
  343. layer={this.props.layer}
  344. groupLayer={this.props.groupLayer}
  345. nestGroupLayer={this.props.nestGroupLayer}
  346. extraGapGroupLayer={this.props.extraGapGroupLayer}
  347. actionName={this.props.actionName}
  348. index={index}
  349. param={param}
  350. dbInfo={this.state.dbInfo}
  351. visible={visible}
  352. />
  353. )
  354. } else {
  355. let className = 'params-group'
  356. if (groups.length === 0) {
  357. className += ' first'
  358. }
  359. let groupName = i18n.exists('EventView.DbHeader.' + param.pGroup)
  360. ? i18n.t('EventView.DbHeader.' + param.pGroup)
  361. : param.pGroup
  362. let group = {
  363. name: param.pGroup,
  364. header: (
  365. <div className={className} key={index + param.pGroup}>
  366. <div className="title">{groupName}</div>
  367. {isApiMethod(this.props.actionName) ? (
  368. <BlockActionMethodParamApiToggle
  369. group={param.pGroup}
  370. bid={this.props.bid}
  371. actionName={this.props.actionName}
  372. />
  373. ) : null}
  374. </div>
  375. ),
  376. coms: [
  377. <BlockActionMethodParamItem
  378. key={index}
  379. paramStyle={groupStyle}
  380. paramClass={groupClass}
  381. bid={this.props.bid}
  382. layer={this.props.layer}
  383. groupLayer={this.props.groupLayer}
  384. nestGroupLayer={this.props.nestGroupLayer}
  385. extraGapGroupLayer={this.props.extraGapGroupLayer}
  386. actionName={this.props.actionName}
  387. index={index}
  388. param={param}
  389. dbInfo={this.state.dbInfo}
  390. visible={visible}
  391. />
  392. ]
  393. }
  394. groups.push(group)
  395. }
  396. } else if (param.type === propType.CloneChild && false) {
  397. cloneChild.push(
  398. <BlockActionMethodParamItem
  399. key={index}
  400. bid={this.props.bid}
  401. layer={this.props.layer}
  402. groupLayer={this.props.groupLayer}
  403. nestGroupLayer={this.props.nestGroupLayer}
  404. extraGapGroupLayer={this.props.extraGapGroupLayer}
  405. actionName={this.props.actionName}
  406. index={index}
  407. param={param}
  408. dbInfo={this.state.dbInfo}
  409. visible={visible}
  410. />
  411. )
  412. } else {
  413. normal.push(
  414. <BlockActionMethodParamItem
  415. key={index}
  416. bid={this.props.bid}
  417. layer={this.props.layer}
  418. groupLayer={this.props.groupLayer}
  419. nestGroupLayer={this.props.nestGroupLayer}
  420. extraGapGroupLayer={this.props.extraGapGroupLayer}
  421. actionName={this.props.actionName}
  422. index={index}
  423. param={param}
  424. dbInfo={this.state.dbInfo}
  425. visible={visible}
  426. eventNodeId={this.props.eventNodeId}
  427. />
  428. )
  429. }
  430. }
  431. })
  432. let result = normal
  433. // if (isApiMethod(this.props.actionName)) {
  434. // result = this.replenishApiParams(groups, result)
  435. // } else if (hasEsDbSeniorSearch(this.props.actionName)) {
  436. // result = this.replenishSeniorSearchParams(groups, result)
  437. // } else {
  438. // if (groups.length !== 0) {
  439. // let groupParams = []
  440. // groups.forEach(group => {
  441. // groupParams.push(group.header)
  442. // groupParams = groupParams.concat(group.coms)
  443. // })
  444. // result = result.concat(groupParams)
  445. // }
  446. // }
  447. return {
  448. renderParams: result,
  449. shouldRender: shouldRender,
  450. cloneChildParams: cloneChild
  451. }
  452. }
  453. render() {
  454. let { shouldRender, renderParams, cloneChildParams } = this.renderInfo()
  455. return shouldRender > 0 ? (
  456. <div className="params-wrap">
  457. <div className="params">{renderParams}</div>
  458. {/* {cloneChildParams && cloneChildParams.length > 0
  459. ? cloneChildParams
  460. : null} */}
  461. </div>
  462. ) : null
  463. }
  464. }