1、视图模板

  1. <template>
  2. <div class="container">
  3. <a-card class="form-search" :bordered="false" :style="{ marginBottom: '20px' }">
  4. <a-form layout="inline" :form="form" @submit="handleSubmit">
  5. <a-row class="form-row" :gutter="16">
  6. <a-form-item label="项目名称">
  7. <a-input v-model="formData.name" maxlength="100" placeholder="项目名称" :allowClear="true"></a-input>
  8. </a-form-item>
  9. <a-form-item label="项目状态">
  10. <a-select default-value="" v-model="formData.status" style="width:80px;">
  11. <a-select-option value="">
  12. 全部
  13. </a-select-option>
  14. <a-select-option value="doing">
  15. 进行中
  16. </a-select-option>
  17. <a-select-option value="wait">
  18. 已延期
  19. </a-select-option>
  20. <a-select-option value="done">
  21. 已完成
  22. </a-select-option>
  23. </a-select>
  24. </a-form-item>
  25. <a-form-item>
  26. <a-button type="primary" html-type="submit">
  27. 查询
  28. </a-button>
  29. </a-form-item>
  30. </a-row>
  31. </a-form>
  32. </a-card>
  33. <a-card class="datatable" :bordered="false">
  34. <a-table
  35. :columns="columns"
  36. :rowKey="row => row.id"
  37. :data-source="data"
  38. :pagination="pagination"
  39. :loading="loading"
  40. @change="handleTableChange">
  41. <span slot="action" slot-scope="record">
  42. <a-button class="btn-action" type="link" @click="detal(record)">详情</a-button>
  43. <!--
  44. <a-divider type="vertical" />
  45. <a-button class="btn-action" type="link" @click="clickTask(record)">任务统计</a-button>
  46. <a-divider type="vertical" />
  47. <a-button class="btn-action" type="link" @click="clickBug(record)">BUG统计</a-button>
  48. -->
  49. </span>
  50. </a-table>
  51. </a-card>
  52. </div>
  53. </template>

2、JS脚本

  1. <script>
  2. import { findPage } from '@/api/project'
  3. function renderStatus (text, record, index) {
  4. if(text == 'doing') {
  5. return '进行中'
  6. } else if (text == 'done') {
  7. return '已完成'
  8. } else if (text == 'wait') {
  9. return '已延期'
  10. }
  11. }
  12. function renderProjectType (text, record, index) {
  13. if(text == 'sprint') {
  14. return '短期项目'
  15. } else if (text == 'waterfall') {
  16. return '长期项目'
  17. } else {
  18. return '维护项目'
  19. }
  20. }
  21. function formatDate (text, record, index) {
  22. return text ? text.substr(0, 10) : text;
  23. }
  24. // 表格字段属性
  25. const columns = [
  26. {
  27. title: 'ID', // 表头文字
  28. dataIndex: 'id', // 字段索引,列数据在数据项中对应的key
  29. key: 'id' // Vue需要的 key,如果已经设置了唯一的dataIndex,可以忽略这个属性
  30. },
  31. {
  32. title: '项目名称',
  33. dataIndex: 'name',
  34. key: 'name'
  35. },
  36. {
  37. title: '项目代号',
  38. dataIndex: 'code',
  39. key: 'code'
  40. },
  41. {
  42. title: '项目类型',
  43. dataIndex: 'type',
  44. key: 'type',
  45. customRender: renderProjectType
  46. },
  47. {
  48. title: '开始时间',
  49. key: 'begin',
  50. dataIndex: 'begin',
  51. customRender: formatDate
  52. },
  53. {
  54. title: '结束日期',
  55. key: 'end',
  56. dataIndex: 'end',
  57. customRender: formatDate
  58. },
  59. {
  60. title: '项目状态',
  61. key: 'status',
  62. dataIndex: 'status',
  63. customRender: renderStatus
  64. },
  65. {
  66. title: '操作',
  67. key: 'action',
  68. scopedSlots: { customRender: 'action' }
  69. }
  70. ];
  71. export default {
  72. name: 'Project',
  73. data () {
  74. return {
  75. formData: {
  76. name: '',
  77. owner: '',
  78. status: ''
  79. },
  80. form: this.$form.createForm(this),
  81. pagination: {
  82. pageSize: 20,
  83. current: 1
  84. },
  85. loading: false,
  86. columns,
  87. data: []
  88. }
  89. },
  90. mounted () {
  91. this.fetch(this.formData)
  92. },
  93. methods: {
  94. handleSubmit (e) {
  95. e.preventDefault()
  96. this.pagination.current = 1
  97. this.pagination.pageNo = 1
  98. this.fetch(this.formData)
  99. },
  100. fetch (param = {}) {
  101. this.loading = true;
  102. const postData = { pageNo: this.pagination.current, ...param, ...this.pagination }
  103. console.log('postData:', postData);
  104. findPage(postData).then(res => {
  105. const pagination = { ...this.pagination };
  106. // pagination.total = data.totalCount;
  107. pagination.total = res.data.total;
  108. this.loading = false;
  109. this.data = res.data.data;
  110. this.pagination = pagination;
  111. });
  112. },
  113. detal (row) {
  114. console.log('row', row)
  115. this.$router.push({
  116. name: 'detail',
  117. params: { projectId: row.id }
  118. })
  119. },
  120. handleTableChange (pagination, filters, sorter) {
  121. console.log(pagination);
  122. const pager = { ...this.pagination };
  123. pager.current = pagination.current;
  124. this.pagination = pager;
  125. this.fetch({
  126. results: pagination.pageSize,
  127. page: pagination.current,
  128. sortField: sorter.field,
  129. sortOrder: sorter.order,
  130. ...filters,
  131. });
  132. }
  133. }
  134. }
  135. </script>

3、CSS样式

  1. <style lang="less" scoped>
  2. .btn-action {
  3. padding: 0;
  4. }
  5. </style>