DataSource.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="data-source">
  3. <div class="title">
  4. <span>数据源</span>
  5. <icon-right />
  6. </div>
  7. <div class="select">
  8. <a-select v-model="target_source" @change="handleChange" :style="{ width: '100%' }" placeholder="请选择数据源">
  9. <a-option v-for="item in source_data_options" :key="item.value" :value="item.value">{{ item.label }}</a-option>
  10. </a-select>
  11. </div>
  12. </div>
  13. </template>
  14. <script setup >
  15. import { ref, computed, watch, onMounted } from 'vue';
  16. const props = defineProps({
  17. target_source_id: String,
  18. data_source_list: Array
  19. });
  20. const emit = defineEmits(['change-source']);
  21. const source_data_options = computed(() => {
  22. return (props.data_source_list || []).map((item) => ({
  23. value: item.id,
  24. label: item.metric_name
  25. }));
  26. });
  27. const target_source = ref(props.target_source_id || '');
  28. const handleChange = (value) => {
  29. target_source.value = value;
  30. emit('change-source', value);
  31. };
  32. watch(
  33. () => props.target_source_id,
  34. (newVal, oldVal) => {
  35. console.log(newVal, 9999);
  36. handleChange(newVal);
  37. },
  38. {
  39. immediate: true
  40. }
  41. );
  42. // 当数据源列表变化时,默认选择第一个
  43. // watch(
  44. // () => props.data_source_list,
  45. // (newOptions) => {
  46. // console.log(props.data_source_list[0]?.id, 888888888888888);
  47. // if (props.data_source_list.length > 0) {
  48. // // console.log(props.data_source_list[0]?.id, 888888888888888);
  49. // target_source.value = props.target_source_id || '';
  50. // handleChange(props.target_source_id);
  51. // } else {
  52. // target_source.value = '';
  53. // }
  54. // },
  55. // { immediate: true, deep: true }
  56. // );
  57. </script>
  58. <style scoped lang="css">
  59. .data-source {
  60. margin-bottom: 10px;
  61. }
  62. .data-source .title {
  63. font-weight: 600;
  64. display: flex;
  65. justify-content: space-between;
  66. align-items: center;
  67. margin-bottom: 10px;
  68. }
  69. .data-source .select {
  70. width: 100%;
  71. }
  72. :deep(.arco-select-view-single) {
  73. background-color: var(--bg-title);
  74. color: var(--primary-default);
  75. }
  76. </style>