models.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <a-card>
  3. <a-table
  4. style="margin-top: 20px;"
  5. :columns="columns"
  6. :data-source="state.dataSource"
  7. :loading="state.loading"
  8. :pagination="queryParamsState"
  9. @change="changePage"
  10. >
  11. <template #bodyCell="{column, record}">
  12. <template v-if="column.key === 'action'" >
  13. <a-space>
  14. <a @click="openModal(record)" >加入</a>
  15. <a >详情</a>
  16. <a >删除</a>
  17. </a-space>
  18. </template>
  19. </template>
  20. </a-table>
  21. </a-card>
  22. <modal-pro
  23. label="选择产品"
  24. :visible="state.visible"
  25. @cancel="state.visible = false"
  26. @ok="ok"
  27. >
  28. <a-form :label-col="{span: 4}" :wrapper-col="{span: 14}">
  29. <a-form-item label="模型名称" v-bind="validateInfos.templateLabel">
  30. <a-input v-model:value="modelRef.templateLabel" />
  31. </a-form-item>
  32. <a-form-item label="产品" v-bind="validateInfos.templateLabel">
  33. <a-select v-model:value="modelRef.modelId" >
  34. <a-select-option
  35. v-for="item in modelState.dataSource"
  36. :key="item.id"
  37. :value="item.id"
  38. >
  39. {{item.modelLabel}}
  40. </a-select-option>
  41. </a-select>
  42. </a-form-item>
  43. </a-form>
  44. </modal-pro>
  45. </template>
  46. <script lang='ts' setup >
  47. import { ModelController } from '@/controller'
  48. import { LeftSquareOutlined } from '@ant-design/icons-vue'
  49. import { onMounted, reactive } from 'vue'
  50. import { Form } from 'ant-design-vue'
  51. const columns = [
  52. {
  53. title: 'id',
  54. dataIndex: 'id',
  55. key: 'id'
  56. },
  57. {
  58. title: '模型名称',
  59. dataIndex: 'templateLabel',
  60. key: 'templateLabel'
  61. },
  62. {
  63. title: '创建时间',
  64. dataIndex: 'createAt',
  65. key: 'createAt'
  66. },
  67. {
  68. title: '修改时间',
  69. dataIndex: 'updateAt',
  70. key: 'updateAt'
  71. },
  72. {
  73. title: '操作',
  74. dataIndex: 'action',
  75. key: 'action'
  76. }
  77. ]
  78. const queryParamsState = reactive({
  79. page: 1,
  80. pageSize: 10,
  81. total: 0,
  82. templateLabel: ''
  83. })
  84. const modelState = reactive({
  85. page: 1,
  86. pageSize: 10,
  87. total: 0,
  88. dataSource: [],
  89. loading: false
  90. })
  91. const state = reactive({
  92. dataSource: [],
  93. loading: false,
  94. opraState: 'add',
  95. visible: false
  96. })
  97. const modelRef = reactive({
  98. templateLabel: '',
  99. modelId: ''
  100. })
  101. const useForm = Form.useForm
  102. const { resetFields, validate, validateInfos } = useForm(modelRef, reactive({
  103. templateLabel: [{ required: true, message: '请填写模型名称' }],
  104. modelId: [{ required: true, message: '请选择模型' }]
  105. }))
  106. const openModal = (record) => {
  107. state.visible = true
  108. getModel()
  109. }
  110. const changePage = ({ current }) => {
  111. queryParamsState.page = current
  112. getModelsPage()
  113. }
  114. const ok = () => {
  115. validate().then(async () => {
  116. })
  117. }
  118. const getModel = async () => {
  119. modelState.loading = true
  120. const { data, sum } = await ModelController.list()
  121. modelState.loading = false
  122. modelState.dataSource = data
  123. }
  124. const getModelsPage = async () => {
  125. state.loading = true
  126. const { data, sum } = await ModelController.modelTemplate(queryParamsState)
  127. state.loading = false
  128. state.dataSource = data
  129. queryParamsState.total = sum
  130. }
  131. onMounted(() => {
  132. getModelsPage()
  133. })
  134. </script>
  135. <style lang='less' scoped >
  136. </style>