ActionRender.vue 930 B

1234567891011121314151617181920212223242526272829303132333435
  1. <template>
  2. <span>
  3. <a-button
  4. v-for="(act, k) in actions"
  5. :key="k"
  6. :class="`mr-3 text-${act.type}` + (act.wrap ? ' display-block' : '')"
  7. @click="actionClick(act)"
  8. >{{act.text}}</a-button>
  9. </span>
  10. </template>
  11. <script lang="ts">
  12. import type { DataModel } from '@imengyu/js-request-transform';
  13. import type { ActionRenderItem } from './ActionRender';
  14. import { defineComponent, type PropType } from "vue";
  15. export default defineComponent({
  16. props: {
  17. rawModel: {
  18. type: Object as PropType<Record<string, unknown>>,
  19. },
  20. actions: {
  21. type: Object as PropType<Array<ActionRenderItem>>,
  22. },
  23. },
  24. methods: {
  25. actionClick(action: ActionRenderItem) {
  26. if (typeof action.onClick === 'function')
  27. action.onClick(action.key, this.rawModel as DataModel);
  28. else
  29. console.warn('action ' + action.key + ' onClick is not a function!');
  30. },
  31. },
  32. });
  33. </script>