serves.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div>
  3. <el-card>
  4. <!-- 添加el-dialog组件 -->
  5. <el-button type="primary"
  6. @click="() => router.push({ path: '/serves/add'})">添加
  7. </el-button>
  8. <el-table :data="tableData" border style="width: 100%;margin-top:20px">
  9. <el-table-column label="序号" width="60">
  10. <template #default="scope">
  11. {{ scope.$index + 1 }}
  12. </template>
  13. </el-table-column>
  14. <el-table-column prop="title" label="名称" width="180">
  15. <template #default="scope">
  16. {{ scope.row.title }}
  17. </template>
  18. </el-table-column>
  19. <el-table-column prop="synopsis" label="简介" width="180">
  20. <template #default="scope">
  21. {{ scope.row.synopsis }}
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="操作" width="200">
  25. <template #default="scope">
  26. <el-button type="danger" size="small" @click="deleteServe(scope.row.ID)">删除</el-button>
  27. <!-- <el-button type="primary" size="small" @click="deleteResource(scope.row.ID)">修改</el-button>-->
  28. <el-button size="small"
  29. @click="() => router.push({ path: '/serves/detail', query: { id: scope.row.ID } })">详情
  30. </el-button>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. <!-- 分页 -->
  35. <el-pagination style="margin-top:20px" :current-page="searchForm.page" :page-size="searchForm.size"
  36. :total="total"
  37. @current-change="handleCurrentChange"/>
  38. </el-card>
  39. </div>
  40. </template>
  41. <script setup>
  42. import {onMounted, reactive, ref} from "vue";
  43. import {ElMessage, ElMessageBox} from 'element-plus';
  44. import {useRouter} from 'vue-router'
  45. import serve from "../../api/serve.js";
  46. const router = useRouter();
  47. // Dom 挂载之后
  48. onMounted(() => {
  49. getServeAll();
  50. getServeType();
  51. })
  52. // 资源数据
  53. const typeMapping = {
  54. recruit: '招募',
  55. about: '关于我们',
  56. }
  57. const showUpload = ref(false);
  58. const value = ref('');
  59. const showUploadDialog = ref(false);
  60. let tableData = ref([]);
  61. let total = ref(0);
  62. const toggleUpload = () => {
  63. showUpload.value = !showUpload.value;
  64. };
  65. // 搜索条件
  66. const searchForm = reactive({
  67. page: 1,
  68. size: 5,
  69. desc: 'created_at desc'
  70. })
  71. const ServeType = reactive([{}])
  72. // 获取资源列表
  73. const getServeAll = async () => {
  74. const res = await serve.getAllService(searchForm);
  75. tableData.value = res.data.Data.Data;
  76. total.value = res.data.Data.Size;
  77. }
  78. const handleSizeChange = (size) => {
  79. searchForm.size = size;
  80. getServeAll();
  81. }
  82. const handleCurrentChange = (current) => {
  83. searchForm.page = current;
  84. getServeAll();
  85. }
  86. const searchUser = () => {
  87. searchForm.current = 1;
  88. getServeAll();
  89. }
  90. const getServeType = async () => {
  91. const res = await serve.GetServiceType();
  92. ServeType.value = res.data.Data;
  93. console.log(ServeType.value)
  94. }
  95. // 删除资源信息
  96. const deleteServe = (id) => {
  97. ElMessageBox.confirm(
  98. '确定要删除该资源信息吗?',
  99. {
  100. confirmButtonText: '确定',
  101. cancelButtonText: '取消',
  102. type: 'warning',
  103. }
  104. ).then(async () => {
  105. const res = await serve.deleteService({id: id});
  106. if (res.data.Code === 200) {
  107. ElMessage.success("删除成功")
  108. await getServeAll();
  109. } else {
  110. ElMessage.error(res.data.Msg)
  111. }
  112. }).catch(() => {
  113. ElMessage({
  114. type: 'info',
  115. message: '取消删除',
  116. })
  117. })
  118. }
  119. </script>
  120. <style lang="scss" scoped></style>