index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="content white">
  3. <v-banner class="mb-3">
  4. 训练数据统计
  5. <template v-slot:actions>
  6. <v-btn
  7. text
  8. color="primary"
  9. @click="getStatistics"
  10. >
  11. <v-icon left>mdi-refresh</v-icon>
  12. 刷新
  13. </v-btn>
  14. </template>
  15. </v-banner>
  16. <v-container v-loading="loading">
  17. <v-row >
  18. <v-col
  19. v-for="elevation in elevations"
  20. :key="elevation.value"
  21. >
  22. <v-card
  23. class="pa-2"
  24. tile
  25. height="150"
  26. >
  27. <div class="d-flex align-center justify-center flex-column" style="height: 100%;">
  28. <div class="text-h3" :class="`${elevation.textColor}--text`">{{ itemData[elevation.value] }}</div>
  29. <div>
  30. {{ elevation.text }}
  31. <span class="success--text">
  32. {{ itemData.type_percentages?.[elevation.value] ? `( ${itemData.type_percentages?.[elevation.value]}% )` : null }}
  33. </span>
  34. </div>
  35. </div>
  36. </v-card>
  37. </v-col>
  38. </v-row>
  39. </v-container>
  40. <v-divider class="my-3"></v-divider>
  41. <div class="pa-3">
  42. <MSearch class="mb-3" :option="filter" @search="handleSearch"></MSearch>
  43. <MTable
  44. :headers="headers"
  45. :items="items"
  46. :loading="tableLoading"
  47. :total="total"
  48. :page-info="pageInfo"
  49. @edit="handleEdit"
  50. @delete="handleDelete"
  51. @pageHandleChange="pageHandleChange"
  52. @sort="handleSort"
  53. @add="handleAdd"
  54. >
  55. <template #question="{ item }">
  56. <span style="max-width: 300px;" class="d-inline-block text-truncate">{{ item.question }}</span>
  57. </template>
  58. <template #content="{ item }">
  59. <span style="max-width: 300px;" class="d-inline-block text-truncate">{{ item.content }}</span>
  60. </template>
  61. <template #actions="{ item }">
  62. <v-btn text color="primary" @click="handleDetails(item)">查看</v-btn>
  63. <v-btn text color="error" @click="handleDelete([item.id])">删除</v-btn>
  64. </template>
  65. </MTable>
  66. </div>
  67. <ModelTrainManageEdit ref="ModelTrainManageEditRefs" @success="onOpen"></ModelTrainManageEdit>
  68. </div>
  69. </template>
  70. <script>
  71. import {
  72. getTrainingData,
  73. getTrainingDataList,
  74. deleteTrainingData
  75. } from '@/api/dataChart'
  76. import MTable from '@/components/List/table.vue'
  77. import MSearch from '@/components/Filter'
  78. import ModelTrainManageEdit from './modelTrainManageEdit.vue'
  79. export default {
  80. name: 'ModelTrain',
  81. components: {
  82. MTable,
  83. MSearch,
  84. ModelTrainManageEdit
  85. },
  86. data () {
  87. return {
  88. searchValues: {},
  89. filter: {
  90. list: [
  91. { type: 'textField', value: null, label: '关键词', key: 'search_keyword', placeholder: '请输入关键词' },
  92. {
  93. type: 'autocomplete',
  94. key: 'training_data_type',
  95. value: null,
  96. label: '类型 *',
  97. placeholder: '请选择类型',
  98. items: [
  99. { label: 'sql', value: 'sql' },
  100. { label: 'documentation', value: 'documentation' },
  101. { label: 'ddl', value: 'ddl' },
  102. { label: 'error_sql', value: 'error_sql' }
  103. ]
  104. }
  105. ]
  106. },
  107. loading: false,
  108. elevations: [
  109. { text: '总数据量', value: 'total_count', textColor: 'primary' },
  110. { text: 'DDL类型', value: 'ddl', textColor: 'info' },
  111. { text: 'SQL类型', value: 'sql', textColor: 'info' },
  112. { text: '文档类型', value: 'documentation', textColor: 'info' },
  113. { text: '错误SQL类型', value: 'error_sql', textColor: 'error' }
  114. ],
  115. itemData: {},
  116. tableLoading: false,
  117. headers: [
  118. { text: 'ID', value: 'id' },
  119. { text: '问题', value: 'question' },
  120. { text: '类型', value: 'training_data_type' },
  121. { text: '内容', value: 'content' },
  122. { text: '操作', value: 'actions' }
  123. ],
  124. items: [],
  125. total: 0,
  126. orders: [],
  127. pageInfo: {
  128. size: 5,
  129. current: 1
  130. }
  131. }
  132. },
  133. created () {
  134. this.onOpen()
  135. },
  136. methods: {
  137. onOpen () {
  138. this.init()
  139. this.getStatistics()
  140. },
  141. async getStatistics () {
  142. this.loading = true
  143. try {
  144. const { data } = await getTrainingData()
  145. this.itemData = {
  146. ...data,
  147. ...data.type_breakdown
  148. }
  149. } catch (error) {
  150. this.$snackbar.error(error)
  151. } finally {
  152. this.loading = false
  153. }
  154. },
  155. async init () {
  156. this.tableLoading = true
  157. const orders = {
  158. sort_by: undefined,
  159. sort_order: undefined
  160. }
  161. if (this.orders.length) {
  162. console.log(this.orders[0])
  163. Object.assign(orders, {
  164. sort_by: this.orders[0].column.replace(/`/g, ''),
  165. sort_order: this.orders[0].asc ? 'asc' : 'desc'
  166. })
  167. }
  168. try {
  169. const { data } = await getTrainingDataList({
  170. page: this.pageInfo.current,
  171. page_size: this.pageInfo.size,
  172. ...this.searchValues,
  173. ...orders
  174. })
  175. this.items = data.records
  176. this.total = data.pagination.total
  177. } catch (error) {
  178. this.$snackbar.error(error)
  179. } finally {
  180. this.tableLoading = false
  181. }
  182. },
  183. handleSearch (v) {
  184. this.searchValues = v
  185. this.pageInfo.current = 1
  186. this.init()
  187. },
  188. handleAdd () {
  189. this.$refs.ModelTrainManageEditRefs.open()
  190. },
  191. handleDetails (item) {
  192. this.$refs.ModelTrainManageEditRefs.open(item, true)
  193. },
  194. pageHandleChange (index) {
  195. this.pageInfo.current = index
  196. this.init()
  197. },
  198. handleSort (v) {
  199. this.orders = v
  200. this.init()
  201. },
  202. handleEdit (item) {
  203. this.$refs.ModelTrainManageEditRefs.open(item)
  204. },
  205. handleDelete (ids) {
  206. if (Array.isArray(ids) && !ids.length) {
  207. this.$snackbar.warning('请选择要删除的数据')
  208. return
  209. }
  210. this.$confirm('提示', '确定删除吗?').then(async () => {
  211. try {
  212. await deleteTrainingData({
  213. ids,
  214. confirm: true
  215. })
  216. this.$snackbar.success('删除成功')
  217. this.onOpen()
  218. } catch (error) {
  219. this.$snackbar.error(error)
  220. }
  221. })
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .content {
  228. font-size: 16px;
  229. }
  230. </style>