event-item.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. 'use strict';
  2. const defaultParams = {
  3. string: 'param',
  4. number: 0,
  5. boolean: false,
  6. };
  7. exports.template = /* html */`
  8. <div @change.stop="onConfirm" v-if="event">
  9. <ui-section expand>
  10. <div slot="header" class="header" @click.stop>
  11. <ui-input name="funcName" placeholder="function Name"
  12. :value="event.func"
  13. :index="index"
  14. ></ui-input>
  15. <span @mousedown="onMouseDown">
  16. <ui-icon value="del"
  17. name="delFunc"
  18. tooltip="i18n:animator.event.del_func"
  19. :index="index"
  20. ></ui-icon>
  21. </span>
  22. </div>
  23. <div class="params">
  24. <div class="line">
  25. <span>params</span>
  26. <span @mousedown="onMouseDown">
  27. <ui-icon value="add"
  28. name="addParams"
  29. tooltip="i18n:animator.event.add_params"
  30. :index="index"
  31. ></ui-icon>
  32. <ui-icon value="clear"
  33. name="clearParams"
  34. tooltip="i18n:animator.event.clear_params"
  35. :index="index"
  36. ></ui-icon>
  37. </span>
  38. </div>
  39. <div class="line" v-for="(val, paramIndex) in event.params">
  40. <span class="name">{{paramIndex + 1}}</span>
  41. <ui-select :value="typeof(val)" name="changeParamType"
  42. :index="paramIndex"
  43. >
  44. <option value="string">string</option>
  45. <option value="number">number</option>
  46. <option value="boolean">boolean</option>
  47. </ui-select>
  48. <ui-input v-if="typeof(val) === 'string'"
  49. name="param"
  50. :value="val"
  51. :index="paramIndex"
  52. ></ui-input>
  53. <ui-num-input v-if="typeof(val) === 'number'"
  54. name="param"
  55. :value="val"
  56. :index="paramIndex"
  57. ></ui-num-input>
  58. <ui-checkbox v-if="typeof(val) === 'boolean'"
  59. name="param"
  60. :value="val"
  61. :index="paramIndex"
  62. ></ui-checkbox>
  63. <span class="operate" @mousedown="onMouseDown">
  64. <ui-icon value="del"
  65. name="delParams"
  66. tooltip="i18n:animator.event.del_params"
  67. :index="paramIndex"
  68. ></ui-icon>
  69. </span>
  70. </div>
  71. </div>
  72. </ui-section>
  73. </div>
  74. `;
  75. exports.props = [
  76. 'event',
  77. 'index',
  78. ];
  79. exports.methods = {
  80. onConfirm(event) {
  81. const that = this;
  82. const name = event.target.getAttribute('name');
  83. if (!name) {
  84. return;
  85. }
  86. let index = event.target.getAttribute('index');
  87. const value = event.target.value;
  88. const eventInfo = that.event;
  89. let params = [];
  90. switch (name) {
  91. case 'funcName':
  92. if (value === event.func) {
  93. return;
  94. }
  95. eventInfo.func = value;
  96. break;
  97. case 'changeParamType':
  98. params = eventInfo.params;
  99. params.splice(index, 1, defaultParams[value]);
  100. break;
  101. case 'param':
  102. params = eventInfo.params;
  103. if (params[index] === value) {
  104. return;
  105. }
  106. params.splice(index, 1, value);
  107. break;
  108. }
  109. that.$emit('update', that.event, that.index);
  110. },
  111. async onMouseDown(event) {
  112. const that = this;
  113. const name = event.target.getAttribute('name');
  114. let index = event.target.getAttribute('index');
  115. switch (name) {
  116. case 'delFunc':
  117. that.$emit('delete', that.index);
  118. return;
  119. case 'addParams':
  120. that.event.params.splice(that.event.params.length - 1, 0, 'param');
  121. break;
  122. case 'delParams':
  123. that.event.params.splice(index, 1);
  124. break;
  125. case 'clearParams':
  126. that.event.params = [];
  127. break;
  128. }
  129. that.$emit('update', that.event, that.index);
  130. },
  131. };