WorkflowGlobalData.vue 1008 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <div class="global-data">
  3. <p class="text-right" title="Characters limit">
  4. {{ globalData.length }}/{{ maxLength.toLocaleString() }}
  5. </p>
  6. <shared-codemirror
  7. v-model="globalData"
  8. style="height: calc(100vh - 10rem)"
  9. lang="json"
  10. />
  11. </div>
  12. </template>
  13. <script setup>
  14. import { ref, watch, defineAsyncComponent } from 'vue';
  15. import { debounce } from '@/utils/helper';
  16. const SharedCodemirror = defineAsyncComponent(() =>
  17. import('@/components/newtab/shared/SharedCodemirror.vue')
  18. );
  19. const props = defineProps({
  20. workflow: {
  21. type: Object,
  22. default: () => ({}),
  23. },
  24. });
  25. const emit = defineEmits(['update']);
  26. const maxLength = 1e4;
  27. const globalData = ref(`${props.workflow.globalData}`);
  28. watch(
  29. globalData,
  30. debounce((value) => {
  31. let newValue = value;
  32. if (value.length > maxLength) {
  33. newValue = value.slice(0, maxLength);
  34. globalData.value = newValue;
  35. }
  36. emit('update', { globalData: newValue });
  37. }, 250)
  38. );
  39. </script>