lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
  <div class="rating-page">
    <div class="page-card">
      <h3 class="card-title">评分模板管理</h3>
      
      <!-- 操作栏 -->
      <div class="toolbar">
        <el-button type="success" @click="handleAdd">
          <el-icon><Plus /></el-icon>
          新增模板
        </el-button>
      </div>
 
      <!-- 模板列表 -->
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column prop="name" label="模板名称" min-width="200" />
        <el-table-column prop="totalScore" label="模板总分" width="120" align="center" />
        <el-table-column prop="itemCount" label="评分条目数" width="120" align="center" />
        <el-table-column prop="createTime" label="创建时间" width="180" />
        <el-table-column label="操作" width="150" fixed="right">
          <template #default="{ row }">
            <div class="table-actions">
              <el-button type="warning" size="small" @click="handleEdit(row)">
                编辑
              </el-button>
              <el-button type="danger" size="small" @click="handleDelete(row)">
                删除
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
 
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          v-model:current-page="pagination.page"
          v-model:page-size="pagination.size"
          :page-sizes="[10, 20, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'
import { getRatingSchemes, deleteRatingScheme } from '@/api/rating.js'
 
const loading = ref(false)
 
// 分页信息
const pagination = reactive({
  page: 1,
  size: 10,
  total: 0
})
 
// 表格数据
const tableData = ref([])
 
// 新增模板
const router = useRouter()
 
const handleAdd = () => {
  router.push('/rating-scheme/new')
}
 
// 编辑模板
const handleEdit = (row: any) => {
  router.push(`/rating-scheme/edit/${row.id}`)
}
 
// 删除模板
const handleDelete = async (row: any) => {
  try {
    await ElMessageBox.confirm(`确定要删除评分模板"${row.name}"吗?`, '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    // 调用后端删除
    await deleteRatingScheme(row.id)
    ElMessage.success('删除成功')
    loadData()
  } catch (e) {
    if (e) {
      ElMessage.error(e.message || '删除失败')
    }
  }
}
 
// 分页大小改变
const handleSizeChange = (size: number) => {
  pagination.size = size
  loadData()
}
 
// 当前页改变
const handleCurrentChange = (page: number) => {
  pagination.page = page
  loadData()
}
 
// 加载数据
const loadData = async () => {
  loading.value = true
  try {
    const data = await getRatingSchemes(pagination.page - 1, pagination.size)
    tableData.value = (data && data.content) ? data.content : []
    pagination.total = (data && data.totalElements) ? data.totalElements : 0
  } catch (e) {
    ElMessage.error((e && e.message) ? e.message : '加载评分模板失败')
  } finally {
    loading.value = false
  }
}
 
onMounted(() => {
  loadData()
})
</script>
 
<style lang="scss" scoped>
.rating-page {
  .card-title {
    margin-bottom: 20px;
    color: #303133;
    font-size: 16px;
    font-weight: 500;
  }
  
  .toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: center;
  }
  
  .table-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  
  .pagination {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
  }
}
</style>