index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div class="main animate__animated animate__backInRight" v-loading="loading">
  3. <custom-search-bar :fields="fields.filter((f) => f.isSearch)" v-model="searchForm" @search="search" @reset="toReset"></custom-search-bar>
  4. <!-- <custom-button-bar :fields="buttonFields" @add="toAdd"></custom-button-bar> -->
  5. <custom-table :data="data" :fields="fields" @query="search" :total="total" :opera="opera" @edit="toEdit" @delete="toDelete" :select="true"> </custom-table>
  6. <el-dialog v-model="dialog" title="数据维护信息" :destroy-on-close="false" @close="toClose" width="50%">
  7. <custom-form v-model="form" :fields="fields" :rules="{}" @save="toSave"> </custom-form>
  8. </el-dialog>
  9. </div>
  10. </template>
  11. <script setup>
  12. const $checkRes = inject('$checkRes')
  13. import { cloneDeep, get } from 'lodash-es'
  14. const { t } = useI18n()
  15. // 接口
  16. import { RealtimeStore } from '@/store/api/core/realtime'
  17. const store = RealtimeStore()
  18. const data = ref([])
  19. const searchForm = ref({})
  20. const fields = [
  21. { label: '作业Id', model: 'work_id' },
  22. { label: '作业名称', model: 'work_name', isSearch: true },
  23. { label: '用户', model: 'user_name', isSearch: true },
  24. { label: '组织', model: 'organization', isSearch: true },
  25. { label: '状态', model: 'status' },
  26. { label: '运行时长', model: 'time' },
  27. { label: '分区', model: 'partition' },
  28. { label: '节点列表', model: 'node' }
  29. ]
  30. const opera = [
  31. // { label: t('common.update'), method: 'edit' },
  32. // { label: t('common.delete'), method: 'delete', confirm: true, type: 'danger' }
  33. ]
  34. const buttonFields = [{ label: t('common.add'), method: 'add' }]
  35. let skip = 0
  36. let limit = inject('limit')
  37. const total = ref(20)
  38. // 加载中
  39. const loading = ref(false)
  40. const dialog = ref(false)
  41. const form = ref({})
  42. // 请求
  43. onMounted(async () => {
  44. loading.value = true
  45. await search({ skip, limit })
  46. loading.value = false
  47. })
  48. const search = async (query = { skip: 0, limit }) => {
  49. const info = { skip: query.skip, limit: query.limit, ...searchForm.value }
  50. const res = await store.query(info)
  51. if (res.errcode == '0') {
  52. data.value = res.data.data
  53. total.value = res.data.total
  54. }
  55. }
  56. // 添加
  57. const toAdd = () => {
  58. dialog.value = true
  59. }
  60. // 修改
  61. const toEdit = (data) => {
  62. form.value = data
  63. dialog.value = true
  64. }
  65. // 删除
  66. const toDelete = async (data) => {
  67. const res = await store.del(data._id)
  68. if ($checkRes(res, true)) {
  69. search({ skip: 0, limit })
  70. }
  71. }
  72. const toSave = async () => {
  73. const data = cloneDeep(form.value)
  74. let res
  75. if (get(data, '_id')) res = await store.update(data)
  76. else res = await store.create({ ...data })
  77. if ($checkRes(res, true)) {
  78. search({ skip: 0, limit })
  79. toClose()
  80. }
  81. }
  82. // 重置
  83. const toReset = async () => {
  84. searchForm.value = {}
  85. await search({ skip, limit })
  86. }
  87. const toClose = () => {
  88. form.value = {}
  89. dialog.value = false
  90. }
  91. </script>
  92. <style scoped lang="scss"></style>