BlockActionMethodParamItem.jsx 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. import React from 'react'
  2. import cls from 'classnames'
  3. import i18n from 'i18next'
  4. import { Tooltip } from 'antd'
  5. import { is } from 'immutable'
  6. import newEventActions from 'actions/newEvent'
  7. import newEventStores from 'stores/newEvent'
  8. import widgetStore from 'stores/widget'
  9. import userStore from 'stores/user'
  10. import treeStores from 'stores/tree'
  11. import uiStore from 'stores/ui'
  12. import {
  13. getActionBlockObjNode,
  14. getEventBlockByBid,
  15. layerWidth,
  16. getBlockObj
  17. } from 'stores/funcs/newEvent'
  18. import { getNodeFromMap } from 'stores/funcs/tree'
  19. import { getDbHeaderName } from 'stores/funcs/db'
  20. import {
  21. getCloneNode,
  22. getDynamicParamName,
  23. getModuleInstanceNameLocale,
  24. smsTemplate
  25. } from 'stores/funcs/event/methodUtils'
  26. import {
  27. nodeIsDbNormal,
  28. nodeIsDbRouter,
  29. nodeIsDbVoteCandidate,
  30. nodeIsDynamoDb
  31. } from 'src/stores/funcs/nodeType'
  32. import { shallowEqualImmutable, cpJson } from 'utils/utils'
  33. import { prop2id } from 'utils/convertModName'
  34. import { isHySa } from 'utils/commons/ctrlHide'
  35. import {
  36. getSpecialParamFormulaParams,
  37. getParamsAffectArea
  38. } from 'src/components/common/formulaEditor/utils'
  39. import propType from 'const/propType'
  40. import { EVENT_BLOCK_TYPE, BLOCK_OP_TYPE } from 'src/const/const'
  41. import { consFormulaShow } from 'src/utils/commons/ctrlHide'
  42. // import {
  43. // getActionDbNodeType,
  44. // getActionDbId,
  45. // getNode
  46. // } from './dbComs/actionDbFuncs'
  47. // import BlockSelect from 'src/components/common/select/BlockSelect'
  48. import BlockActionBoolean from 'src/components/common/event/normalComs/BlockActionBoolean'
  49. // import DbSearchRange from 'src/components/common/event/dbComs/DbSearchRange'
  50. // import BlockActionKeyValue from './normalComs/BlockActionKeyValue'
  51. // import KeyValueJson from './normalComs/KeyValueJson'
  52. // import BlockActionColRowValue from './normalComs/BlockActionColRowValue'
  53. // import BlockActionNormalCons from './normalComs/BlockActionNormalCons'
  54. // import BlockActionNormalOrders from './normalComs/BlockActionNormalOrders'
  55. // import BlockActionObjSelect from './normalComs/BlockActionObjSelect'
  56. // import BlockActionJsonParam from './normalComs/BlockActionJsonParam'
  57. // import BlockActionJsonParamMult from './normalComs/BlockActionJsonParamMult'
  58. // import DbConditionalSelector from './dbComs/DbConditionalSelector'
  59. // import DbOrderSelector from './dbComs/DbOrderSelector'
  60. // import DbNumColSelector from './dbComs/DbNumColSelector'
  61. // import DbUpdateSelector from './dbComs/DbUpdateSelector'
  62. // import DbColsSelector from './dbComs/DbColsSelector'
  63. // import DbGroupByCols from './dbComs/DbGroupByCols'
  64. // import DbGroupCols from './dbComs/DbGroupCols'
  65. // import BlockActionDbRange from './dbComs/DbRangeSelector'
  66. // import DyQueryCons from './dyComs/DyQueryCons'
  67. // import DyUpdate from './dyComs/DyUpdate'
  68. // import DyCons from './dyComs/DyCons'
  69. // import SubChildren from './subChildren/SubChildren'
  70. import FormulaEditor from 'src/components/common/formulaEditor/EventFormulaEditor'
  71. import EventJsonEditor from 'src/components/common/formulaEditor/EventJsonEditor'
  72. import iconStrObj from 'src/assets/icons/iconsStr'
  73. export default class BlockActionMethodParamItem extends React.Component {
  74. constructor(props) {
  75. super(props)
  76. this.state = {
  77. param: this.getParamItem(props.param),
  78. value: this.getParamValue(),
  79. widthDelta: uiStore.jengaViewWidthDelta
  80. }
  81. this.onEventChange = this.onEventChange.bind(this)
  82. this.onUiChange = this.onUiChange.bind(this)
  83. this.onChangeValue = this.onChangeValue.bind(this)
  84. // this.getObject = this.getObject.bind(this)
  85. this.getParamValue = this.getParamValue.bind(this)
  86. this.getName = this.getName.bind(this)
  87. this.getParamName = this.getParamName.bind(this)
  88. this.getParamPropsMap = this.getParamPropsMap.bind(this)
  89. this.getCloneNodeId = this.getCloneNodeId.bind(this)
  90. this.getParamItem = this.getParamItem.bind(this)
  91. this.getParamNameStyle = this.getParamNameStyle.bind(this)
  92. this.getParamValueStyle = this.getParamValueStyle.bind(this)
  93. this.getWholeParamStyle = this.getWholeParamStyle.bind(this)
  94. this.paramValueCom = this.paramValueCom.bind(this)
  95. this.getItemValueCom = this.getItemValueCom.bind(this)
  96. this.getItemTips = this.getItemTips.bind(this)
  97. this.getItemPlaceholder = this.getItemPlaceholder.bind(this)
  98. // this.paramIsInDbSearch = this.paramIsInDbSearch.bind(this)
  99. this.getOptionFonts = this.getOptionFonts.bind(this)
  100. this.getOptionIcons = this.getOptionIcons.bind(this)
  101. }
  102. shouldComponentUpdate(nextProps, nextState) {
  103. return (
  104. !shallowEqualImmutable(this.props, nextProps) ||
  105. !shallowEqualImmutable(this.state, nextState)
  106. )
  107. }
  108. componentDidMount() {
  109. this.unsubscribe = newEventStores.listen(this.onEventChange)
  110. this.unsubscribeUI = uiStore.listen(this.onUiChange)
  111. }
  112. componentWillUnmount() {
  113. this.unsubscribe()
  114. this.unsubscribeUI()
  115. }
  116. componentDidUpdate(preProps) {
  117. let param = this.getParamItem()
  118. if (!is(this.state.param, param)) {
  119. this.setState({
  120. param: param
  121. })
  122. }
  123. }
  124. onEventChange(status) {
  125. let obj = {}
  126. if (status) {
  127. if (
  128. status.types.includes('changeActionBlockParamsValue') &&
  129. this.props.bid === status.data.affectBlockId &&
  130. status.data.index === this.props.index
  131. ) {
  132. let value = this.getParamValue()
  133. if (!is(this.state.value, value)) {
  134. obj.value = value
  135. } else {
  136. obj.value = { ...value }
  137. }
  138. }
  139. }
  140. if (Object.keys(obj).length > 0) {
  141. this.setState(obj)
  142. }
  143. }
  144. onUiChange(status) {
  145. if (status && status.types) {
  146. if (status.types.includes('changeJengaViewWidthDelta')) {
  147. if (status.data.jengaViewWidthDelta !== this.state.widthDelta) {
  148. this.setState({
  149. widthDelta: status.data.jengaViewWidthDelta
  150. })
  151. }
  152. }
  153. }
  154. }
  155. getParamValue() {
  156. // 获取param的值
  157. let value = null
  158. let eventNodeId = this.props.eventNodeId || newEventStores.curEventNodeId
  159. let block = getEventBlockByBid(this.props.bid, eventNodeId)
  160. let paramName = this.props.param.name
  161. switch (block.op) {
  162. case BLOCK_OP_TYPE.SET:
  163. let args_set = block.args
  164. let targetParam_set = args_set.find(item => {
  165. return item.op === 'prop' && item.val === paramName
  166. })
  167. if (
  168. targetParam_set &&
  169. targetParam_set.args &&
  170. targetParam_set.args[0]
  171. ) {
  172. let op = targetParam_set.args[0].op
  173. value =
  174. op === 'var'
  175. ? targetParam_set.args[0].expVal
  176. : targetParam_set.args[0].val
  177. }
  178. break
  179. case BLOCK_OP_TYPE.CALL:
  180. let args_call = block.args
  181. let targetParam_call = args_call.find(item => {
  182. return item.key === paramName
  183. })
  184. if (targetParam_call) {
  185. let op = targetParam_call.op
  186. value = op === 'var' ? targetParam_call.expVal : targetParam_call.val
  187. }
  188. break
  189. case BLOCK_OP_TYPE.LET:
  190. if (
  191. block.args &&
  192. block.args[0] &&
  193. block.args[0].op === 'call' &&
  194. block.args[0].args
  195. ) {
  196. let args_let = block.args[0].args
  197. let targetParam_let = args_let.find(item => {
  198. return item.key === paramName
  199. })
  200. if (targetParam_let) {
  201. let op = targetParam_let.op
  202. value = op === 'var' ? targetParam_let.expVal : targetParam_let.val
  203. }
  204. }
  205. break
  206. }
  207. return value
  208. }
  209. onChangeValue(index, value, addRecord) {
  210. let paramName = this.state.param.name
  211. let actionName = this.getName()
  212. let reloadMethod = false
  213. // 引起参数变化
  214. if (
  215. (actionName === 'clone' && paramName === 'cloneId' && index === 0) ||
  216. (['sendSMS', 'sendSMS_stage'].indexOf(actionName) >= 0 &&
  217. paramName === 'template' &&
  218. index === 1) ||
  219. (['sendTemplate'].indexOf(actionName) >= 0 && paramName === 'mode') ||
  220. (['shareApp'].indexOf(actionName >= 0) && paramName === 'type') ||
  221. (['toDataURL'].indexOf(actionName) >= 0 && paramName === 'imgType') ||
  222. (['browsePic', 'browseMutiPic'].indexOf(actionName) >= 0 &&
  223. paramName === 'outputBase64') ||
  224. (['createPayInfo', 'refund', 'orderquery'].indexOf(actionName) >= 0 &&
  225. paramName === 'mode')
  226. ) {
  227. reloadMethod = true
  228. }
  229. let obj = {
  230. nodeId: this.props.eventNodeId || newEventStores.curEventNodeId,
  231. blockId: this.props.bid,
  232. index,
  233. paramName,
  234. value,
  235. reloadMethod
  236. }
  237. if (this.state.param.mini) {
  238. obj.mini = true
  239. }
  240. this.setState({
  241. value: value
  242. })
  243. this.forceUpdate()
  244. newEventActions.changeActionParamValue(obj)
  245. }
  246. // getObject() {
  247. // let _obj = null
  248. // let block = getEventBlockByBid(this.props.bid)
  249. // if (block) {
  250. // _obj = block.object
  251. // }
  252. // return _obj
  253. // }
  254. getName() {
  255. return this.props.actionName ? this.props.actionName || null : null
  256. }
  257. getParamName() {
  258. let name = this.state.param.name
  259. let locale = this.state.param.locale
  260. let isDbHeader = this.state.param.isDbHeader
  261. let isMini = this.state.param.mini
  262. let isProp = this.state.param.isProp
  263. let actionName = this.getName()
  264. let nodeId = this.props.eventNodeId || newEventStores.curEventNodeId
  265. let block = getEventBlockByBid(this.props.bid, nodeId)
  266. let obj = getBlockObj({ block })
  267. if (block && obj && actionName) {
  268. let node = getActionBlockObjNode({
  269. obj,
  270. nodeId
  271. })
  272. if (node) {
  273. if (isMini) {
  274. name = getModuleInstanceNameLocale({
  275. nodeId: node.id,
  276. type: 'props',
  277. name: prop2id(name)
  278. })
  279. // } else if (actionName === 'clone' && this.props.index >= 3) {
  280. // let cloneNode = getCloneNode(this.props.bid)
  281. // if (cloneNode) {
  282. // let propsMap =
  283. // widgetStore.widget[cloneNode.type] &&
  284. // widgetStore.widget[cloneNode.type].map &&
  285. // widgetStore.widget[cloneNode.type].map.propsMap
  286. // if (propsMap && propsMap[name] && propsMap[name].locale) {
  287. // name = propsMap[name].locale[i18n.language]
  288. // }
  289. // }
  290. // } else if (
  291. // ['sendSMS', 'sendSMS_stage'].indexOf(actionName) >= 0 &&
  292. // this.props.index >= 2
  293. // ) {
  294. // if (block.action && block.action.params && block.action.params[1]) {
  295. // let tempInfo = smsTemplate[block.action.params[1].value]
  296. // if (tempInfo && tempInfo.args) {
  297. // let param = tempInfo.args.find(arg => {
  298. // return arg.name === name
  299. // })
  300. // if (param && param.locale) {
  301. // name = param.locale[i18n.language]
  302. // }
  303. // }
  304. // }
  305. } else if (actionName === 'setProps' || isProp) {
  306. let propsMap =
  307. widgetStore.widget[node.type] &&
  308. widgetStore.widget[node.type].map &&
  309. widgetStore.widget[node.type].map.propsMap
  310. if (propsMap && propsMap[name] && propsMap[name].locale) {
  311. name = propsMap[name].locale[i18n.language]
  312. }
  313. // } else if (isDbHeader) {
  314. // let actionDbNodeType = getActionDbNodeType({
  315. // node,
  316. // bid: this.props.bid
  317. // })
  318. // if (nodeIsDynamoDb(actionDbNodeType)) {
  319. // let dbInfo = this.props.dbInfo
  320. // let dbCols = dbInfo ? dbInfo.dbCols || [] : undefined
  321. // if (dbCols) {
  322. // let item = dbCols.find(col => {
  323. // return col.name === name
  324. // })
  325. // if (item) {
  326. // if (isDbHeader === 'internal') {
  327. // let header = { name: name, internal: true }
  328. // let transName =
  329. // 'DbView.dyHeader.' +
  330. // getDbHeaderName(header, actionDbNodeType)
  331. // if (i18n.exists(transName)) {
  332. // name = item.alias
  333. // ? item.alias +
  334. // i18n.t('DbParamPanel.left_bracket') +
  335. // i18n.t(transName) +
  336. // i18n.t('DbParamPanel.right_bracket')
  337. // : i18n.t(transName)
  338. // }
  339. // } else {
  340. // name = item.alias
  341. // }
  342. // }
  343. // }
  344. // } else {
  345. // if (isDbHeader === 'internal') {
  346. // let header = { name: name, internal: true }
  347. // let transName =
  348. // 'DbView.header.' + getDbHeaderName(header, actionDbNodeType)
  349. // if (i18n.exists(transName)) {
  350. // name = i18n.t(transName)
  351. // }
  352. // } else if (locale) {
  353. // name = locale[i18n.language] || name
  354. // }
  355. // }
  356. } else {
  357. if (['setObjTransition', 'tweenTo'].indexOf(actionName) >= 0) {
  358. let propsMap =
  359. widgetStore.widget[node.type] &&
  360. widgetStore.widget[node.type].map &&
  361. widgetStore.widget[node.type].map.propsMap
  362. if (propsMap && propsMap[name] && propsMap[name].locale) {
  363. name = propsMap[name].locale[i18n.language]
  364. }
  365. }
  366. let actionsMap =
  367. widgetStore.widget[node.type] &&
  368. widgetStore.widget[node.type].map &&
  369. widgetStore.widget[node.type].map.methodsMap
  370. if (
  371. actionsMap &&
  372. actionsMap[actionName] &&
  373. actionsMap[actionName].params
  374. ) {
  375. let params = actionsMap[actionName].params
  376. // 由于tweenTo在原方法修改,故在不修改方法的前提下处理,只取最后2个参数
  377. if (actionName === 'tweenTo' && params.length >= 2) {
  378. params = [params[params.length - 2], params[params.length - 1]]
  379. }
  380. let param = params.find(param => {
  381. return param.name === name
  382. })
  383. if (param && param.locale) {
  384. name = param.locale[i18n.language] || name
  385. }
  386. // if (nodeIsDynamoDb(node.type)) {
  387. // let dbInfo = this.props.dbInfo
  388. // let dbCols = dbInfo ? dbInfo.dbCols || [] : undefined
  389. // name = getDynamicParamName(
  390. // node.type,
  391. // dbCols,
  392. // actionName,
  393. // this.state.param.name,
  394. // name
  395. // )
  396. // }
  397. }
  398. }
  399. }
  400. }
  401. return name
  402. }
  403. getParamPropsMap() {
  404. let paramName = this.state.param.name
  405. let isProp = this.state.param.isProp
  406. let actionName = this.getName()
  407. let nodeId = this.props.eventNodeId || newEventStores.curEventNodeId
  408. let block = getEventBlockByBid(this.props.bid, nodeId)
  409. let obj = getBlockObj({ block })
  410. if (block && obj && actionName) {
  411. let node = getActionBlockObjNode({
  412. obj,
  413. nodeId
  414. })
  415. if (node) {
  416. if (actionName === 'setProps' || isProp) {
  417. let propsMap =
  418. widgetStore.widget[node.type] &&
  419. widgetStore.widget[node.type].map &&
  420. widgetStore.widget[node.type].map.propsMap
  421. return propsMap[paramName]
  422. } else {
  423. let actionsMap =
  424. widgetStore.widget[node.type] &&
  425. widgetStore.widget[node.type].map &&
  426. widgetStore.widget[node.type].map.methodsMap
  427. if (
  428. actionsMap &&
  429. actionsMap[actionName] &&
  430. actionsMap[actionName].params
  431. ) {
  432. let params = actionsMap[actionName].params
  433. return params.find(param => {
  434. return param.name === paramName
  435. })
  436. }
  437. }
  438. }
  439. }
  440. }
  441. getCloneNodeId() {
  442. let node = getCloneNode(this.props.bid)
  443. if (node) {
  444. return node.id
  445. }
  446. return undefined
  447. }
  448. getParamItem(param) {
  449. return param !== undefined ? param : this.props.param
  450. }
  451. getParamNameStyle() {
  452. const groupLayer = this.props.groupLayer > 0 ? this.props.groupLayer : 0
  453. const nestingLayer =
  454. this.props.nestGroupLayer > 0 ? this.props.nestGroupLayer - 1 : 0
  455. const extraGapGroupLayer =
  456. this.props.extraGapGroupLayer > 0
  457. ? (this.props.extraGapGroupLayer - 1) * 2
  458. : 0
  459. const originWidth =
  460. 324 - (groupLayer + nestingLayer) * 2 - extraGapGroupLayer
  461. let width = layerWidth({
  462. originWidth: originWidth,
  463. decreaseFactor: 21,
  464. layer: this.props.layer
  465. })
  466. return {
  467. width: width + 'px',
  468. minWidth: width + 'px'
  469. }
  470. }
  471. getParamValueStyle() {
  472. return {
  473. width: 275 + this.state.widthDelta + 'px'
  474. }
  475. }
  476. getWholeParamStyle() {
  477. let width = layerWidth({
  478. originWidth: 608 + this.state.widthDelta,
  479. decreaseFactor: 21,
  480. layer: this.props.layer
  481. })
  482. return {
  483. width: width + 'px',
  484. minWidth: width + 'px'
  485. }
  486. }
  487. // paramIsInDbSearch() {
  488. // let result = false
  489. // let node = getNode({ bid: this.props.bid, actionName: this.getName() })
  490. // if (
  491. // node &&
  492. // (nodeIsDbNormal(node.type) ||
  493. // nodeIsDbRouter(node.type) ||
  494. // nodeIsDbVoteCandidate(node.type))
  495. // ) {
  496. // let block = getEventBlockByBid(this.props.bid)
  497. // if (
  498. // block &&
  499. // block.object &&
  500. // block.type === EVENT_BLOCK_TYPE.ACTION &&
  501. // block.action &&
  502. // [
  503. // 'dbSmartSearch_stage',
  504. // 'dbSmartSearch',
  505. // 'dbCustomizeSearch_stage',
  506. // 'dbCustomizeSearch'
  507. // ].indexOf(block.action.name) >= 0
  508. // ) {
  509. // result = true
  510. // }
  511. // }
  512. // return result
  513. // }
  514. paramIsPath() {
  515. let result = false
  516. let eventNodeId = this.props.eventNodeId || newEventStores.curEventNodeId
  517. let block = getEventBlockByBid(this.props.bid, eventNodeId)
  518. let obj = getBlockObj({ block })
  519. let actionName = this.getName()
  520. if (
  521. block &&
  522. obj &&
  523. actionName &&
  524. ['setCusPathValue'].indexOf(actionName) >= 0 &&
  525. this.state.param &&
  526. this.state.param.name === 'path'
  527. ) {
  528. result = true
  529. }
  530. return result
  531. }
  532. paramIsAsync() {
  533. let result = false
  534. let eventNodeId = this.props.eventNodeId || newEventStores.curEventNodeId
  535. let block = getEventBlockByBid(this.props.bid, eventNodeId)
  536. let obj = getBlockObj({ block })
  537. let actionName = this.getName()
  538. if (
  539. block &&
  540. obj &&
  541. actionName &&
  542. ['setLog'].indexOf(actionName) >= 0 &&
  543. this.state.param &&
  544. this.state.param.name === 'topic'
  545. ) {
  546. result = 'serviceTopic'
  547. }
  548. return result
  549. }
  550. paramIsBlock(widgetName, actionName, paramName) {
  551. let result = false
  552. if (widgetName && actionName && paramName) {
  553. let widgets = widgetStore.widget
  554. if (
  555. widgets &&
  556. widgets[widgetName] &&
  557. widgets[widgetName].map &&
  558. widgets[widgetName].map.methodsMap &&
  559. widgets[widgetName].map.methodsMap[actionName] &&
  560. widgets[widgetName].map.methodsMap[actionName].params
  561. ) {
  562. let params = widgets[widgetName].map.methodsMap[actionName].params
  563. let param = params.find(param => param.name === paramName)
  564. if (param) {
  565. if (param.isBlock) {
  566. result = true
  567. }
  568. }
  569. }
  570. }
  571. return result
  572. }
  573. getOptionFonts(propsMap) {
  574. let options = []
  575. let optionLocales = {}
  576. let addedOptions = {}
  577. if (userStore.fontsList) {
  578. userStore.fontsList.forEach(fontItem => {
  579. let font = fontItem.font || fontItem.url
  580. if (!addedOptions[font]) {
  581. options.push(font)
  582. optionLocales[font] = {
  583. zh: fontItem.name,
  584. en: fontItem.name
  585. }
  586. }
  587. addedOptions[font] = true
  588. })
  589. }
  590. if (propsMap && propsMap.hasDefaultOptions) {
  591. // 添加默认
  592. options = options.concat(propsMap.options)
  593. optionLocales = Object.assign(optionLocales, propsMap.optionLocales)
  594. }
  595. return { options, optionLocales }
  596. }
  597. getOptionIcons(propsMap) {
  598. let options = []
  599. let optionLocales = {}
  600. let addedOptions = {}
  601. if (userStore.iconsList) {
  602. userStore.iconsList.forEach(fontItem => {
  603. if (!addedOptions[fontItem.url]) {
  604. options.push(fontItem.url)
  605. optionLocales[fontItem.url] = {
  606. zh: fontItem.name,
  607. en: fontItem.name
  608. }
  609. }
  610. addedOptions[fontItem.url] = true
  611. })
  612. }
  613. // 默认图标
  614. if (userStore.defaultIcons) {
  615. userStore.defaultIcons.forEach(fontItem => {
  616. options.push(fontItem.url)
  617. optionLocales[fontItem.url] = {
  618. zh: fontItem.name,
  619. en: fontItem.name
  620. }
  621. })
  622. }
  623. // 添加默认
  624. // options = options.concat(propsMap.options)
  625. // optionLocales = Object.assign(optionLocales, propsMap.optionLocales)
  626. return { options, optionLocales }
  627. }
  628. paramValueCom(propsMap) {
  629. let type = this.state.param.type
  630. let index = this.props.index
  631. let eventNodeId = this.props.eventNodeId || newEventStores.curEventNodeId
  632. let block = getEventBlockByBid(this.props.bid, eventNodeId)
  633. let obj = getBlockObj({ block })
  634. let node = getActionBlockObjNode({ obj, eventNodeId })
  635. let actionName = this.getName()
  636. // let _dbId = node ? getActionDbId({ node, bid: this.props.bid }) : undefined
  637. // let dbInfo = this.props.dbInfo
  638. // let dbId = dbInfo
  639. // ? dbInfo.dbId
  640. // : getActionDbId({ node, bid: this.props.bid })
  641. // let nodeType = dbInfo
  642. // ? dbInfo.dbNodeType
  643. // : getActionDbNodeType({ node, bid: this.props.bid })
  644. // let dbCols = dbInfo ? dbInfo.dbCols || [] : undefined
  645. // if (_dbId !== dbId) {
  646. // dbId = undefined // 与当前action不符合的dbid不传入组件(避免覆盖问题)
  647. // dbCols = undefined
  648. // }
  649. let com = undefined
  650. let paramName = this.state.param.name
  651. let value = this.state.value
  652. switch (type) {
  653. // 百分比也用formula处理
  654. case propType.Formula:
  655. case propType.FormulaColor:
  656. // 部分特殊参数注入公式的params
  657. let formulaParams = getSpecialParamFormulaParams({
  658. paramName,
  659. isNewEvent: true,
  660. objNode: node,
  661. actionName
  662. })
  663. let placeholder = this.getItemPlaceholder(propsMap)
  664. if (
  665. ['esInsert', 'esInsert_stage'].indexOf(actionName) >= 0 &&
  666. paramName === '_id'
  667. ) {
  668. placeholder = i18n.t(
  669. 'EventView.jenga_action_block.insert_id_placeholder'
  670. )
  671. }
  672. let hasColorPicker = type === propType.FormulaColor
  673. let paramIsPath = this.paramIsPath()
  674. let paramIsAsync = this.paramIsAsync()
  675. let widgetName = node ? node.type : ''
  676. let paramIsBlock = this.paramIsBlock(widgetName, actionName, paramName)
  677. if (!paramIsBlock) {
  678. com = (
  679. <FormulaEditor
  680. className="action-formula-editor"
  681. bid={this.props.bid}
  682. uid={this.props.bid}
  683. paramName={paramName}
  684. hasColorPicker={hasColorPicker}
  685. value={value}
  686. placeholder={placeholder}
  687. params={formulaParams}
  688. isPath={paramIsPath}
  689. paramIsAsync={paramIsAsync}
  690. onChangeCode={this.onChangeValue.bind(this, index)}
  691. hasCons={consFormulaShow()}
  692. />
  693. )
  694. } else {
  695. com = (
  696. <EventJsonEditor
  697. height="200px"
  698. className="action-formula-editor"
  699. bid={this.props.bid}
  700. uid={this.props.bid}
  701. value={value}
  702. placeholder={placeholder}
  703. params={formulaParams}
  704. onChangeCode={this.onChangeValue.bind(this, index)}
  705. isBlock={paramIsBlock}
  706. />
  707. )
  708. }
  709. break
  710. case propType.FormulaJson:
  711. // 部分特殊参数注入公式的params
  712. let fEditorParams = getSpecialParamFormulaParams({
  713. paramName,
  714. isNewEvent: true,
  715. objNode: node,
  716. actionName
  717. })
  718. let jsonPlaceholder = this.getItemPlaceholder(propsMap)
  719. com = (
  720. <EventJsonEditor
  721. className="action-formula-editor"
  722. bid={this.props.bid}
  723. uid={this.props.bid}
  724. value={value}
  725. placeholder={jsonPlaceholder}
  726. params={fEditorParams}
  727. onChangeCode={this.onChangeValue.bind(this, index)}
  728. />
  729. )
  730. break
  731. case propType.Boolean:
  732. com = (
  733. <BlockActionBoolean
  734. className="action-block-action"
  735. type="boolean"
  736. bid={this.props.bid}
  737. uid={this.props.bid}
  738. value={value}
  739. noDefault={this.state.param.noDefault}
  740. onChange={this.onChangeValue.bind(this, index)}
  741. />
  742. )
  743. break
  744. // case propType.Select:
  745. // case propType.SelectUpload:
  746. // case propType.FontSelect:
  747. // case propType.IconSelect:
  748. // let groups = propsMap && propsMap.optionGroup
  749. // let options = propsMap && propsMap.options
  750. // let optionsLocales = propsMap && propsMap.optionLocales
  751. // if (propsMap && type === propType.FontSelect) {
  752. // let temp = this.getOptionFonts(propsMap)
  753. // options = temp.options
  754. // optionsLocales = temp.optionLocales
  755. // } else if (propsMap && type === propType.IconSelect) {
  756. // let temp = this.getOptionIcons(propsMap)
  757. // options = temp.options
  758. // optionsLocales = temp.optionLocales
  759. // }
  760. // com = propsMap && (
  761. // <BlockSelect
  762. // className="action-block-select"
  763. // type="select"
  764. // value={value}
  765. // isMultiple={!!propsMap.isMultiple}
  766. // placeholder={propsMap.placeholder}
  767. // optionsInfo={{
  768. // optionsGroup: groups,
  769. // options: options,
  770. // optionLocales: optionsLocales
  771. // }}
  772. // onChange={this.onChangeValue.bind(this, index)}
  773. // />
  774. // )
  775. // break
  776. // case propType.MultiKeyValue:
  777. // case propType.MultiPureKeyValue:
  778. // case propType.MultiValue:
  779. // com = (
  780. // <BlockActionKeyValue
  781. // className="action-key-value-group"
  782. // type={type}
  783. // bid={this.props.bid}
  784. // uid={this.props.bid}
  785. // value={value}
  786. // onChangeValue={this.onChangeValue.bind(this, index)}
  787. // />
  788. // )
  789. // break
  790. // case propType.KeyValueJson:
  791. // let kvPlaceholder = this.getItemPlaceholder(propsMap)
  792. // com = (
  793. // <KeyValueJson
  794. // keyValueClassName="action-key-value-group"
  795. // bid={this.props.bid}
  796. // uid={this.props.bid}
  797. // placeholder={kvPlaceholder}
  798. // value={value}
  799. // onChange={this.onChangeValue.bind(this, index)}
  800. // />
  801. // )
  802. // break
  803. // case propType.ArrColValue:
  804. // case propType.ArrMultiValue:
  805. // let arrParams = getSpecialParamFormulaParams({
  806. // paramName,
  807. // isNewEvent: true,
  808. // objNode: node,
  809. // actionName
  810. // })
  811. // let affectArea = getParamsAffectArea({
  812. // node,
  813. // actionName
  814. // })
  815. // com = (
  816. // <BlockActionColRowValue
  817. // className="action-col-row-value-group"
  818. // type={type}
  819. // bid={this.props.bid}
  820. // uid={this.props.bid}
  821. // value={value}
  822. // params={arrParams}
  823. // paramsValid={affectArea}
  824. // visible={this.props.visible}
  825. // onChangeValue={this.onChangeValue.bind(this, index)}
  826. // />
  827. // )
  828. // break
  829. // case propType.NormalCons:
  830. // com = (
  831. // <BlockActionNormalCons
  832. // className="action-normal-cons-group"
  833. // type={type}
  834. // bid={this.props.bid}
  835. // uid={this.props.bid}
  836. // value={value}
  837. // onChangeValue={this.onChangeValue.bind(this, index)}
  838. // />
  839. // )
  840. // break
  841. // case propType.NormalUpdates:
  842. // com = (
  843. // <DbUpdateSelector
  844. // value={value}
  845. // bid={this.props.bid}
  846. // uid={this.props.bid}
  847. // type={'normal'}
  848. // onChange={this.onChangeValue.bind(this, index)}
  849. // />
  850. // )
  851. // break
  852. // case propType.NormalOrders:
  853. // com = (
  854. // <BlockActionNormalOrders
  855. // className="action-normal-orders-group"
  856. // type={type}
  857. // bid={this.props.bid}
  858. // uid={this.props.bid}
  859. // value={value}
  860. // onChangeValue={this.onChangeValue.bind(this, index)}
  861. // />
  862. // )
  863. // break
  864. // case propType.DbRange:
  865. // com = (
  866. // <BlockActionDbRange
  867. // className="action-db-range-group"
  868. // type={type}
  869. // bid={this.props.bid}
  870. // uid={this.props.bid}
  871. // value={value}
  872. // onChangeValue={this.onChangeValue.bind(this, index)}
  873. // />
  874. // )
  875. // break
  876. // case propType.DbCons:
  877. // com = (
  878. // <DbConditionalSelector
  879. // value={value}
  880. // dbId={dbId}
  881. // nodeType={nodeType}
  882. // dbCols={dbCols}
  883. // bid={this.props.bid}
  884. // uid={this.props.bid}
  885. // isDbSearch={this.paramIsInDbSearch()}
  886. // onChange={this.onChangeValue.bind(this, index)}
  887. // />
  888. // )
  889. // break
  890. // case propType.DbOrders:
  891. // com = (
  892. // <DbOrderSelector
  893. // value={value}
  894. // dbId={dbId}
  895. // nodeType={nodeType}
  896. // dbCols={dbCols}
  897. // bid={this.props.bid}
  898. // uid={this.props.bid}
  899. // isDbSearch={this.paramIsInDbSearch()}
  900. // onChange={this.onChangeValue.bind(this, index)}
  901. // />
  902. // )
  903. // break
  904. // case propType.DbNumCol:
  905. // com = (
  906. // <DbNumColSelector
  907. // value={value}
  908. // dbId={dbId}
  909. // dbCols={dbCols}
  910. // nodeType={nodeType}
  911. // bid={this.props.bid}
  912. // uid={this.props.bid}
  913. // onChange={this.onChangeValue.bind(this, index)}
  914. // />
  915. // )
  916. // break
  917. // case propType.DbUpdate:
  918. // com = (
  919. // <DbUpdateSelector
  920. // value={value}
  921. // dbId={dbId}
  922. // dbCols={dbCols}
  923. // nodeType={nodeType}
  924. // bid={this.props.bid}
  925. // uid={this.props.bid}
  926. // onChange={this.onChangeValue.bind(this, index)}
  927. // />
  928. // )
  929. // break
  930. // case propType.ObjSelect:
  931. // case propType.ObjResult:
  932. // case propType.ObjSelectCb:
  933. // let allowTypes = true
  934. // let childOnly = false
  935. // if (propsMap) {
  936. // allowTypes =
  937. // propsMap.allowTypes !== undefined ? propsMap.allowTypes : true
  938. // childOnly =
  939. // propsMap.childOnly !== undefined ? propsMap.childOnly : childOnly
  940. // }
  941. // com = (
  942. // <BlockActionObjSelect
  943. // className="action-obj-select-group"
  944. // type={type}
  945. // bid={this.props.bid}
  946. // uid={this.props.bid}
  947. // value={value}
  948. // allowTypes={allowTypes}
  949. // childOnly={childOnly}
  950. // onChangeValue={this.onChangeValue.bind(this, index)}
  951. // />
  952. // )
  953. // break
  954. // case propType.ObjJsonParamsSelect:
  955. // com = (
  956. // <BlockActionJsonParam
  957. // bid={this.props.bid}
  958. // value={value}
  959. // onChangeValue={this.onChangeValue.bind(this, index)}
  960. // />
  961. // )
  962. // break
  963. // case propType.ObjJsonMultiPaths:
  964. // com = (
  965. // <BlockActionJsonParamMult
  966. // bid={this.props.bid}
  967. // value={value}
  968. // onChangeValue={this.onChangeValue.bind(this, index)}
  969. // />
  970. // )
  971. // break
  972. // case propType.JsonEditor:
  973. // // 部分特殊参数注入公式的params
  974. // let editorParams = getSpecialParamFormulaParams({
  975. // paramName,
  976. // isNewEvent: true,
  977. // objNode: node,
  978. // actionName
  979. // })
  980. // let jsonEditorPlaceholder = undefined
  981. // if (this.state.param.isApiHeader || this.state.param.isApiBody) {
  982. // let phOptions = {
  983. // zh: "例如:{'name0':'value1','name1':'value2'}",
  984. // en: "Ex: {'name0':'value1','name1':'value2'}"
  985. // }
  986. // jsonEditorPlaceholder = phOptions[i18n.language]
  987. // } else {
  988. // jsonEditorPlaceholder = this.getItemPlaceholder(propsMap)
  989. // }
  990. // com = (
  991. // <div className="item-value" style={this.getWholeParamStyle()}>
  992. // <EventJsonEditor
  993. // className="action-formula-editor"
  994. // bid={this.props.bid}
  995. // uid={this.props.bid}
  996. // value={value}
  997. // params={editorParams}
  998. // placeholder={jsonEditorPlaceholder}
  999. // onChangeCode={this.onChangeValue.bind(this, index)}
  1000. // />
  1001. // </div>
  1002. // )
  1003. // break
  1004. // case propType.CloneChild:
  1005. // let styles = {
  1006. // name: this.getParamNameStyle(),
  1007. // value: this.getParamValueStyle()
  1008. // }
  1009. // com = (
  1010. // <SubChildren
  1011. // cloneId={this.getCloneNodeId()}
  1012. // index={index}
  1013. // value={value}
  1014. // bid={this.props.bid}
  1015. // uid={this.props.bid}
  1016. // propStyles={styles}
  1017. // />
  1018. // )
  1019. // break
  1020. // case propType.DbCols:
  1021. // let dbColsPlaceholder = this.getItemPlaceholder(propsMap)
  1022. // let params = getSpecialParamFormulaParams({
  1023. // paramName,
  1024. // isNewEvent: true,
  1025. // objNode: node,
  1026. // actionName
  1027. // })
  1028. // com = (
  1029. // <DbColsSelector
  1030. // value={value}
  1031. // dbId={dbId}
  1032. // nodeType={nodeType}
  1033. // dbCols={dbCols}
  1034. // params={params}
  1035. // bid={this.props.bid}
  1036. // uid={this.props.bid}
  1037. // placeholder={dbColsPlaceholder}
  1038. // onChange={this.onChangeValue.bind(this, index)}
  1039. // />
  1040. // )
  1041. // break
  1042. // case propType.DbSearchRange:
  1043. // let searchRangePlaceholder = this.getItemPlaceholder(propsMap)
  1044. // let rangeParams = getSpecialParamFormulaParams({
  1045. // paramName,
  1046. // isNewEvent: true,
  1047. // objNode: node,
  1048. // actionName
  1049. // })
  1050. // com = (
  1051. // <DbSearchRange
  1052. // value={value}
  1053. // dbId={dbId}
  1054. // nodeType={nodeType}
  1055. // dbCols={dbCols}
  1056. // params={rangeParams}
  1057. // bid={this.props.bid}
  1058. // uid={this.props.bid}
  1059. // placeholder={searchRangePlaceholder}
  1060. // isDbSearch={this.paramIsInDbSearch()}
  1061. // onChange={this.onChangeValue.bind(this, index)}
  1062. // />
  1063. // )
  1064. // break
  1065. // case propType.DbGroupByCols:
  1066. // com = (
  1067. // <DbGroupByCols
  1068. // value={value}
  1069. // dbId={dbId}
  1070. // nodeType={nodeType}
  1071. // dbCols={dbCols}
  1072. // onChange={this.onChangeValue.bind(this, index)}
  1073. // />
  1074. // )
  1075. // break
  1076. // case propType.DbGroupCols:
  1077. // case propType.DbSelectCols:
  1078. // com = (
  1079. // <DbGroupCols
  1080. // value={value}
  1081. // dbId={dbId}
  1082. // nodeType={nodeType}
  1083. // dbCols={dbCols}
  1084. // onChange={this.onChangeValue.bind(this, index)}
  1085. // />
  1086. // )
  1087. // break
  1088. // case propType.DyQueryCons:
  1089. // let dyStyles = {
  1090. // name: this.getParamNameStyle(),
  1091. // value: this.getParamValueStyle()
  1092. // }
  1093. // let tips = propsMap && propsMap.desc && propsMap.desc[i18n.language]
  1094. // com = (
  1095. // <DyQueryCons
  1096. // value={value}
  1097. // dbId={dbId}
  1098. // nodeType={nodeType}
  1099. // dbCols={dbCols}
  1100. // bid={this.props.bid}
  1101. // uid={this.props.bid}
  1102. // paramStyle={this.props.paramStyle}
  1103. // paramClass={this.props.paramClass}
  1104. // tips={tips}
  1105. // styles={dyStyles}
  1106. // onChange={this.onChangeValue.bind(this, index)}
  1107. // />
  1108. // )
  1109. // break
  1110. // case propType.DyUpdate:
  1111. // com = (
  1112. // <DyUpdate
  1113. // value={value}
  1114. // dbId={dbId}
  1115. // dbCols={dbCols}
  1116. // nodeType={nodeType}
  1117. // bid={this.props.bid}
  1118. // uid={this.props.bid}
  1119. // onChange={this.onChangeValue.bind(this, index)}
  1120. // />
  1121. // )
  1122. // break
  1123. // case propType.DyCons:
  1124. // com = (
  1125. // <DyCons
  1126. // value={value}
  1127. // dbId={dbId}
  1128. // nodeType={nodeType}
  1129. // dbCols={dbCols}
  1130. // bid={this.props.bid}
  1131. // uid={this.props.bid}
  1132. // onChange={this.onChangeValue.bind(this, index)}
  1133. // />
  1134. // )
  1135. // break
  1136. default:
  1137. // com = <div className="f--hlc">UNDEFINED-TODO</div>
  1138. // 暂时默认用FormulaEditor
  1139. let _formulaParams = getSpecialParamFormulaParams({
  1140. paramName,
  1141. isNewEvent: true,
  1142. objNode: node,
  1143. actionName
  1144. })
  1145. let _placeholder = this.getItemPlaceholder(propsMap)
  1146. let _widgetName = node ? node.type : ''
  1147. com = (
  1148. <FormulaEditor
  1149. className="action-formula-editor"
  1150. bid={this.props.bid}
  1151. uid={this.props.bid}
  1152. paramName={paramName}
  1153. value={value}
  1154. placeholder={_placeholder}
  1155. params={_formulaParams}
  1156. onChangeCode={this.onChangeValue.bind(this, index)}
  1157. />
  1158. )
  1159. }
  1160. return com
  1161. }
  1162. getItemValueCom(propsMap) {
  1163. return (
  1164. <div className="item-value" style={this.getParamValueStyle()}>
  1165. {this.paramValueCom(propsMap)}
  1166. </div>
  1167. )
  1168. }
  1169. getItemTips(propsMap) {
  1170. if (!isHySa() && propsMap && propsMap.desc) {
  1171. let tips = propsMap.desc[i18n.language]
  1172. let eventView = document.querySelector('.event-view')
  1173. return (
  1174. <Tooltip
  1175. title={tips}
  1176. arrowPointAtCenter={true}
  1177. placement="right"
  1178. overlayClassName="param-tips-tooltip"
  1179. getPopupContainer={() => eventView}
  1180. >
  1181. <span
  1182. className="param-tips"
  1183. dangerouslySetInnerHTML={{ __html: iconStrObj.help }}
  1184. />
  1185. </Tooltip>
  1186. )
  1187. }
  1188. return null
  1189. }
  1190. getItemPlaceholder(propsMap) {
  1191. let placeholder = undefined
  1192. if (propsMap && propsMap.placeholder) {
  1193. placeholder =
  1194. typeof propsMap.placeholder === 'string'
  1195. ? propsMap.placeholder
  1196. : propsMap.placeholder[i18n.language]
  1197. }
  1198. return placeholder
  1199. }
  1200. render() {
  1201. let propsMap = this.getParamPropsMap()
  1202. // 处理小模块中的文本变量公共数据,当类型为select时需另外获取propsMap
  1203. if (
  1204. this.state.param.type === 'Select' &&
  1205. this.state.param.mini &&
  1206. !propsMap
  1207. ) {
  1208. let nodeId = this.eventNodeId || newEventStores.curEventNodeId
  1209. let block = getEventBlockByBid(this.props.bid, nodeId)
  1210. let obj = getBlockObj({ block })
  1211. if (block && obj) {
  1212. let node = getActionBlockObjNode({
  1213. obj,
  1214. nodeId
  1215. })
  1216. if (node && node.props && node.props.classId) {
  1217. let classId = node.props.classId
  1218. const nodeInfo = getNodeFromMap({
  1219. nodeId: this.state.param.name.split('_')[1],
  1220. caseId: treeStores.curCaseId,
  1221. classId
  1222. })
  1223. if (nodeInfo) {
  1224. propsMap = {
  1225. options: nodeInfo.props.options.split(',')
  1226. }
  1227. }
  1228. }
  1229. }
  1230. }
  1231. // method的param的map的hideKeep控制参数显隐,运行时该参数仍会传入方法中
  1232. // 在需要改动方法参数的需求中,可在需要隐藏的param加上hideKeep:true,
  1233. // 则参数不会显示在编辑界面中,运行时候仍会传入方法中,保持新旧项目中同一方法参数和表现一致
  1234. if (propsMap && propsMap.hideKeep) {
  1235. return null
  1236. }
  1237. // 在group内隐藏
  1238. // if (this.state.param && this.state.param.pGroupHide) {
  1239. // return null
  1240. // }
  1241. return this.state.param &&
  1242. [propType.CloneChild, propType.JsonEditor, propType.DyQueryCons].indexOf(
  1243. this.state.param.type
  1244. ) >= 0 ? (
  1245. this.paramValueCom()
  1246. ) : this.state.param.type !== propType.Hidden ? (
  1247. <div
  1248. className={cls('param-item f--h', this.props.paramClass)}
  1249. style={this.props.paramStyle}
  1250. >
  1251. <div
  1252. className="item-name f--hlc"
  1253. title={this.getParamName()}
  1254. style={this.getParamNameStyle()}
  1255. >
  1256. {this.getParamName()}
  1257. {this.getItemTips(propsMap)}
  1258. </div>
  1259. <div className="item-equal">=</div>
  1260. {this.getItemValueCom(propsMap)}
  1261. </div>
  1262. ) : null
  1263. }
  1264. }