ApiFieldConfig.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div class="api-field-config-container">
  3. <div class="section-header">
  4. <h3 class="section-title">字段配置</h3>
  5. <div class="add-field-btn-container">
  6. <a-button type="primary" @click="addField"> + 添加字段 </a-button>
  7. </div>
  8. </div>
  9. <div class="table-wrapper">
  10. <table class="field-table">
  11. <thead>
  12. <tr>
  13. <th>字段名称</th>
  14. <th>字段描述</th>
  15. <th>字段类型</th>
  16. <th>字段Key</th>
  17. <th>字段角色</th>
  18. <th>是否可聚合</th>
  19. <th>是否必填</th>
  20. <th>是否支持接口参数</th>
  21. <th>通用配置类型</th>
  22. <th>是否需要展示字段</th>
  23. <th>接口参数是否支持多值</th>
  24. <th>接口参数是否支持模糊查询</th>
  25. <th>多值分隔符</th>
  26. <th>枚举类型ID</th>
  27. <th>日期格式</th>
  28. <th>时间限制</th>
  29. <th>操作</th>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. <tr v-for="(field, index) in metric_fields" :key="index">
  34. <td>
  35. <a-input v-model="field.field_name" placeholder="字段名称" @input="handleFieldChange" />
  36. </td>
  37. <td>
  38. <a-input v-model="field.field_description" placeholder="字段描述" @input="handleFieldChange" />
  39. </td>
  40. <td>
  41. <a-select v-model="field.field_type" @change="handleFieldChange">
  42. <a-option value="int"> int </a-option>
  43. <a-option value="date"> date </a-option>
  44. <a-option value="str"> str </a-option>
  45. </a-select>
  46. </td>
  47. <td>
  48. <a-input v-model="field.field_key" placeholder="字段Key" @input="handleFieldChange" />
  49. </td>
  50. <td>
  51. <a-select v-model="field.column_role" @change="handleFieldChange">
  52. <a-option value="dim"> 维度 </a-option>
  53. <a-option value="meas"> 度量 </a-option>
  54. </a-select>
  55. </td>
  56. <td>
  57. <a-select v-model="field.is_aggregatable" @change="handleFieldChange">
  58. <a-option :value="0"> 否 </a-option>
  59. <a-option :value="1"> 是 </a-option>
  60. </a-select>
  61. </td>
  62. <td>
  63. <a-select v-model="field.is_required" @change="handleFieldChange">
  64. <a-option :value="0"> 否 </a-option>
  65. <a-option :value="1"> 是 </a-option>
  66. </a-select>
  67. </td>
  68. <td>
  69. <a-select v-model="field.is_support_api_query_condition" @change="handleFieldChange">
  70. <a-option :value="0"> 否 </a-option>
  71. <a-option :value="1"> 是 </a-option>
  72. </a-select>
  73. </td>
  74. <td>
  75. <a-input v-model="field.common_config_type" placeholder="通用配置类型" @input="handleFieldChange" />
  76. </td>
  77. <td>
  78. <a-select v-model="field.is_needs_show_fields" @change="handleFieldChange">
  79. <a-option :value="0"> 否 </a-option>
  80. <a-option :value="1"> 是 </a-option>
  81. </a-select>
  82. </td>
  83. <td>
  84. <a-select v-model="field.is_api_support_multi_value" @change="handleFieldChange">
  85. <a-option :value="0"> 否 </a-option>
  86. <a-option :value="1"> 是 </a-option>
  87. </a-select>
  88. </td>
  89. <td>
  90. <a-select v-model="field.is_api_support_fuzzy_query" @change="handleFieldChange">
  91. <a-option :value="0"> 否 </a-option>
  92. <a-option :value="1"> 是 </a-option>
  93. </a-select>
  94. </td>
  95. <td>
  96. <a-input v-model="field.multi_value_delimiter" placeholder="多值分隔符" @input="handleFieldChange" />
  97. </td>
  98. <td>
  99. <a-select v-model="field.enum_type_id" @change="handleFieldChange">
  100. <a-option :value="0"> 无 </a-option>
  101. <a-option :value="1"> 有 </a-option>
  102. </a-select>
  103. </td>
  104. <td>
  105. <a-select v-model="field.format_str" :disabled="field.field_type !== 'date'" @change="handleFieldChange">
  106. <a-option value="year_month"> 精确到年月 </a-option>
  107. <a-option value="date"> 精确到日期 </a-option>
  108. <a-option value="datetime"> 精确到时间 </a-option>
  109. </a-select>
  110. </td>
  111. <td>
  112. <a-select
  113. v-model="field.time_limit"
  114. :disabled="field.field_type !== 'date'"
  115. allow-clear
  116. :style="{ width: '170px' }"
  117. @change="handleFieldChange"
  118. >
  119. <a-option value="limit_to_yesterday_start"> 昨天的 00:00:00 </a-option>
  120. <a-option value="limit_to_yesterday_end"> 昨天的 23:59:59 </a-option>
  121. <a-option value="limit_to_day_start"> 今天的 00:00:00 </a-option>
  122. <a-option value="limit_to_day_end"> 今天的 23:59:59 </a-option>
  123. </a-select>
  124. </td>
  125. <td>
  126. <a-button type="outline" status="danger" @click="deleteField(index)">
  127. <icon-delete />
  128. </a-button>
  129. </td>
  130. </tr>
  131. </tbody>
  132. </table>
  133. </div>
  134. </div>
  135. </template>
  136. <script setup lang="js">
  137. import { ref, watch } from 'vue';
  138. const props = defineProps({
  139. modelValue: {
  140. type: Object,
  141. default: () => ({})
  142. }
  143. });
  144. const emit = defineEmits(['update:modelValue']);
  145. // 使用独立的响应式变量
  146. const metric_fields = ref(props.modelValue.metric_fields || []);
  147. // 监听props变化,更新本地数据
  148. watch(() => props.modelValue, (newValue) => {
  149. metric_fields.value = newValue.metric_fields || [];
  150. }, { deep: true });
  151. // 通知父组件数据变化
  152. const notifyParent = () => {
  153. // 处理非date类型的字段,不保留日期格式和时间限制
  154. const processedFields = metric_fields.value.map(field => {
  155. if (field.field_type !== 'date') {
  156. return {
  157. ...field,
  158. format_str: undefined,
  159. time_limit: undefined
  160. };
  161. }
  162. return field;
  163. });
  164. emit('update:modelValue', {
  165. metric_fields: processedFields
  166. });
  167. };
  168. // 处理字段变化
  169. const handleFieldChange = () => {
  170. notifyParent();
  171. };
  172. // 添加字段
  173. const addField = () => {
  174. metric_fields.value = [...metric_fields.value, {
  175. field_name: '',
  176. field_description: '',
  177. field_type: 'str',
  178. field_key: '',
  179. column_role: 'dim',
  180. is_aggregatable: 0,
  181. is_required: 0,
  182. is_support_api_query_condition: 0,
  183. common_config_type: null,
  184. is_api_support_multi_value: 0,
  185. is_api_support_fuzzy_query: 0,
  186. multi_value_delimiter: ',',
  187. is_needs_show_fields: 1,
  188. enum_type_id: 0,
  189. format_str: 'date', // 默认精确到日期
  190. time_limit: 'limit_to_day_start' // 默认截止到昨天
  191. }];
  192. notifyParent();
  193. };
  194. // 删除字段
  195. const deleteField = (index) => {
  196. metric_fields.value = metric_fields.value.filter((_, i) => i !== index);
  197. notifyParent();
  198. };
  199. </script>
  200. <style scoped lang="css">
  201. .api-field-config-container {
  202. /* width: 90%; */
  203. background-color: #ffffff;
  204. padding: 20px;
  205. border-radius: 8px;
  206. margin-bottom: 20px;
  207. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  208. }
  209. .section-header {
  210. display: flex;
  211. justify-content: space-between;
  212. align-items: center;
  213. }
  214. .section-title {
  215. font-size: 16px;
  216. font-weight: 600;
  217. margin-bottom: 20px;
  218. color: #333;
  219. }
  220. .table-wrapper {
  221. overflow-x: auto;
  222. overflow-y: auto;
  223. max-height: 300px;
  224. margin-bottom: 16px;
  225. }
  226. .field-table {
  227. width: 100%;
  228. border-collapse: collapse;
  229. min-width: 1800px;
  230. }
  231. .field-table thead th {
  232. position: sticky;
  233. top: 0;
  234. z-index: 2;
  235. }
  236. .field-table th,
  237. .field-table td {
  238. min-width: 180px;
  239. padding: 8px;
  240. border: 1px solid #e8e8e8;
  241. text-align: left;
  242. }
  243. .field-table th {
  244. background-color: #f5f5f5;
  245. font-weight: 600;
  246. white-space: nowrap;
  247. }
  248. .field-table td {
  249. white-space: nowrap;
  250. }
  251. .add-field-btn-container {
  252. margin-top: 16px;
  253. }
  254. </style>