aromeEvent.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Component({
  2. mixins: [],
  3. data: {
  4. params: null,
  5. eventResult: null
  6. },
  7. props: {
  8. isCumulative: {
  9. type: Boolean,
  10. value: true
  11. },
  12. number: {
  13. type: String,
  14. value: ""
  15. },
  16. name: {
  17. type: String,
  18. value: "调用事件"
  19. },
  20. tips: {
  21. type: String,
  22. value: ""
  23. },
  24. aromeCode: {
  25. type: String,
  26. value: "ampeHHCommunication"
  27. },
  28. initParams: {
  29. type: Object,
  30. value: {
  31. action: "xxx",
  32. event: "xxx",
  33. taskId: "88888888",
  34. params: {}
  35. }
  36. }
  37. },
  38. didMount() {
  39. this.reset()
  40. },
  41. didUpdate() { },
  42. didUnmount() { },
  43. methods: {
  44. doEvent() {
  45. let that = this;
  46. let params = null;
  47. try {
  48. params = JSON.parse(that.data.params)
  49. } catch (error) {
  50. my.showToast({
  51. type: 'fail',
  52. content: 'JSON格式有误',
  53. duration: 1500,
  54. });
  55. return;
  56. }
  57. console.log(that.props.aromeCode, 55, params)
  58. if (that.props.aromeCode) {
  59. my.on(that.props.aromeCode, res => {
  60. if (that.props.isCumulative) {
  61. res = (that.data.eventResult || "") + "\n" + JSON.stringify(res)
  62. } else {
  63. res = JSON.stringify(res)
  64. }
  65. that.setData({
  66. eventResult: res
  67. })
  68. });
  69. } else {
  70. my.call("ampeHHCommunication", params, res => {
  71. console.log('ampeHHCommunication', res)
  72. if (that.props.isCumulative) {
  73. res = (that.data.eventResult || "") + "\n" + JSON.stringify(res)
  74. } else {
  75. res = JSON.stringify(res)
  76. }
  77. console.log(res)
  78. that.setData({
  79. eventResult: res
  80. })
  81. });
  82. }
  83. },
  84. handleChange(e) {
  85. let json = e.detail.value
  86. this.setData({
  87. params: json
  88. })
  89. },
  90. close() {
  91. this.setData({
  92. eventResult: null
  93. })
  94. },
  95. reset() {
  96. let that = this;
  97. let params = JSON.parse(JSON.stringify(that.props.initParams))
  98. this.setData({
  99. params: JSON.stringify(params),
  100. eventResult: null
  101. })
  102. }
  103. },
  104. });