index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="home-container">
  3. <dv-border-box1 ref="borderRef" style="width: 100%; height: 100%; margin: 0 auto">
  4. <div class="table-box">
  5. <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listTaskApi" :tool-button="false">
  6. <template #tableHeader="">
  7. <el-button type="primary" v-auth="['system:user:add']" :icon="CirclePlus" @click="createTask()"> 创建任务 </el-button>
  8. </template>
  9. <!-- 表格操作 -->
  10. <template #operation="scope">
  11. <el-button type="primary" link icon="View" v-auth="['task:task:query']" @click="viewDetails(scope.row)"> 查看详情 </el-button>
  12. <el-button type="primary" link :icon="View" @click="openDialog(3, '任务查看', scope.row)">查看</el-button>
  13. </template>
  14. </ProTable>
  15. <!-- <ProTable
  16. ref="proTable"
  17. row-key="id"
  18. :columns="columns"
  19. :request-api="listTaskApi"
  20. :request-auto="false"
  21. :tool-button="false"
  22. >
  23. <template #tableHeader="">
  24. <el-button type="primary" v-auth="['system:user:add']" :icon="CirclePlus" @click="createTask()"> 创建任务 </el-button>
  25. </template>
  26. <template #operation="scope">
  27. <el-button type="primary" link :icon="View" @click="openDialog(3, '任务查看', scope.row)">查看</el-button>
  28. </template>
  29. </ProTable> -->
  30. </div>
  31. </dv-border-box1>
  32. </div>
  33. </template>
  34. <script setup lang="tsx" name="homePage">
  35. import { onMounted, reactive, ref } from 'vue'
  36. import { User } from '@/api/interface'
  37. import ProTable from '@/components/ProTable/index.vue'
  38. import FormDialog from '@/components/DialogOld/form.vue'
  39. import { CirclePlus, View } from '@element-plus/icons-vue'
  40. import { useRouter } from 'vue-router'
  41. import { ColumnProps, ProTableInstance } from '@/components/ProTable/interface'
  42. import { addUserApi, updateUserApi, deptTreeSelectApi } from '@/api/modules/system/user'
  43. // import { getTaskApi } from '@/api/modules/taais/task'
  44. import { listTaskApi, getTaskApi } from '@/api/modules/task/task'
  45. import { getDictsApi } from '@/api/modules/system/dictData'
  46. // import taskDataList from '@/assets/mock/taskData.json'
  47. // import { getDictsApi } from '@/api/modules/system/dictData'
  48. onMounted(() => {
  49. getTreeFilter()
  50. })
  51. // ProTable 实例
  52. const proTable = ref<ProTableInstance>()
  53. // 如果表格需要初始化请求参数,直接定义传给 ProTable(之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
  54. const initParam = reactive({ deptId: '' })
  55. // 获取 treeFilter 数据
  56. // 当 proTable 的 requestAuto 属性为 false,不会自动请求表格数据,等待 treeFilter 数据回来之后,更改 initParam.departmentId 的值,才会触发请求 proTable 数据
  57. const treeFilterData = ref<any>([])
  58. const getTreeFilter = async () => {
  59. const { data } = await deptTreeSelectApi()
  60. treeFilterData.value = data
  61. initParam.deptId = treeFilterData.value[0].id
  62. }
  63. // 查看详情
  64. const viewDetails = row => {
  65. router.push({ path: `/task/subtask/`, query: { id: row.id } })
  66. }
  67. // 批量添加用户
  68. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  69. // 打开弹框的功能
  70. const openDialog = async (type: number, title: string, row?: any) => {
  71. let res = getTaskApi(row?.taskId || null)
  72. // 表单项配置
  73. const fieldList: Form.FieldItem[] = [
  74. {
  75. label: '任务名称',
  76. placeholder: '请输入任务名称',
  77. span: 12,
  78. field: 'taskName',
  79. rules: [{ required: true, message: '任务名称不能为空' }]
  80. }
  81. ]
  82. const params = {
  83. title,
  84. width: 680,
  85. isEdit: type !== 3,
  86. fieldList: fieldList,
  87. model: res,
  88. api: type == 1 ? addUserApi : updateUserApi,
  89. getTableList: proTable.value?.getTableList
  90. }
  91. formDialogRef.value?.openDialog(params)
  92. }
  93. const router = useRouter()
  94. // 增加任务
  95. const createTask = () => {
  96. router.push(`/createTask`)
  97. }
  98. // 表格配置项
  99. const columns = reactive<ColumnProps<User.ResUserList>[]>([
  100. // { type: 'selection', fixed: 'left', width: 70 },
  101. { prop: 'name', label: '任务名称' },
  102. {
  103. prop: 'status',
  104. label: '任务状态',
  105. tag: true,
  106. enum: () => getDictsApi('biz_task_status'),
  107. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  108. },
  109. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  110. ])
  111. </script>
  112. <style scoped lang="scss">
  113. @import './index.scss';
  114. </style>