modelTrainManageUpload.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <m-dialog title="导入训练数据" :visible.sync="show" @submit="handleSubmit">
  3. <MForm ref="form" :items="formItems" v-model="formValues" v-loading="loading"></MForm>
  4. </m-dialog>
  5. </template>
  6. <script>
  7. import MDialog from '@/components/Dialog'
  8. import MForm from '@/components/MForm'
  9. import {
  10. uploadTrainingData
  11. } from '@/api/dataChart'
  12. export default {
  13. name: 'modelTrainManageUpload',
  14. components: {
  15. MDialog,
  16. MForm
  17. },
  18. data () {
  19. return {
  20. show: false,
  21. loading: false,
  22. formValues: {},
  23. formItems: [
  24. {
  25. label: '训练数据',
  26. key: 'file',
  27. type: 'upload',
  28. multiple: true,
  29. rules: [v => {
  30. if (!v) {
  31. return '请上传文件'
  32. }
  33. if (v.size > 500 * 1024) {
  34. return '文件大小不能超过500KB'
  35. }
  36. }]
  37. },
  38. {
  39. label: '文件类型',
  40. key: 'file_type',
  41. type: 'ifRadio',
  42. items: [
  43. { label: 'ddl', value: 'ddl' },
  44. { label: 'markdown', value: 'markdown' },
  45. { label: 'sql_pair_json', value: 'sql_pair_json' },
  46. { label: 'sql_pair', value: 'sql_pair' },
  47. { label: 'sql', value: 'sql' }
  48. ]
  49. }
  50. ]
  51. }
  52. },
  53. methods: {
  54. open () {
  55. this.show = true
  56. this.formValues = {
  57. file_type: 'ddl',
  58. file: null
  59. }
  60. this.$nextTick(() => {
  61. this.$refs.form.resetValidation()
  62. })
  63. },
  64. async handleSubmit () {
  65. const check = this.$refs.form.validate()
  66. if (!check) {
  67. return
  68. }
  69. this.loading = true
  70. try {
  71. const query = new FormData()
  72. query.append('file', this.formValues.file)
  73. query.append('training_data_type', this.formValues.training_data_type)
  74. await uploadTrainingData()
  75. this.$snackbar.success('导入成功')
  76. this.show = false
  77. this.$emit('success')
  78. } catch (error) {
  79. this.$snackbar.error(error)
  80. } finally {
  81. this.loading = false
  82. }
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. </style>