BlockActionMethodParamItem.jsx 41 KB

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