link.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div>
  3. <el-card>
  4. <el-button type="primary"
  5. @click="() => router.push({ path: '/links/add'})">添加
  6. </el-button>
  7. <!-- 添加el-dialog组件 -->
  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. <el-input v-model="scope.row.title" @change="UpData(scope.row.ID,'title',scope.row.title)" size="mini" />
  17. </template>
  18. </el-table-column>
  19. <el-table-column prop="types" label="链接" width="280">
  20. <template #default="scope">
  21. <el-input v-model="scope.row.url" @change="UpData(scope.row.ID,'url',scope.row.url)" size="mini" />
  22. </template>
  23. </el-table-column>
  24. <el-table-column prop="nums" label="排序" width="180">
  25. <template #default="scope">
  26. <el-input-number v-model="scope.row.sort" @change="UpData(scope.row.ID,'sort',scope.row.sort)" size="mini" />
  27. </template>
  28. </el-table-column>
  29. <el-table-column label="操作" width="200">
  30. <template #default="scope">
  31. <el-button type="danger" size="small" @click="deleteData(scope.row.ID)">删除</el-button>
  32. <!-- <el-button type="primary" size="small" @click="deleteResource(scope.row.ID)">修改</el-button>-->
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. <!-- 分页 -->
  37. <el-pagination style="margin-top:20px" :current-page="searchForm.page" :page-size="searchForm.size"
  38. :total="total"
  39. @current-change="handleCurrentChange"/>
  40. </el-card>
  41. </div>
  42. </template>
  43. <script setup>
  44. import {onMounted, reactive, ref} from "vue";
  45. import {ElMessage, ElMessageBox} from 'element-plus';
  46. import {useRouter} from 'vue-router'
  47. import link from "../../api/links.js";
  48. const dataType = reactive([])
  49. const router = useRouter();
  50. // Dom 挂载之后
  51. onMounted(() => {
  52. getDataAll();
  53. })
  54. let tableData = ref([]);
  55. let total = ref(0);
  56. // 搜索条件
  57. const searchForm = reactive({
  58. page: 1,
  59. size: 10,
  60. desc: 'created_at desc'
  61. })
  62. const UpData = async (id,field,value) => {
  63. const res = await link.UpdateLinks({
  64. id: parseInt(id),
  65. [field]: value,
  66. });
  67. if (res.data.Code === 200) {
  68. ElMessage.success("修改成功")
  69. await getDataAll();
  70. } else {
  71. ElMessage.error(res.data.Msg)
  72. }
  73. }
  74. // 获取资源列表
  75. const getDataAll = async () => {
  76. const res = await link.getalllinks(searchForm);
  77. tableData.value = res.data.Data.Data;
  78. total.value = res.data.Data.Size;
  79. }
  80. const handleCurrentChange = (current) => {
  81. searchForm.page = current;
  82. getDataAll();
  83. }
  84. // 删除资源信息
  85. const deleteData = (id) => {
  86. ElMessageBox.confirm(
  87. '确定要删除该资源信息吗?',
  88. {
  89. confirmButtonText: '确定',
  90. cancelButtonText: '取消',
  91. type: 'warning',
  92. }
  93. ).then(async () => {
  94. const res = await link.deletelinks({id: id});
  95. if (res.data.code === 200) {
  96. ElMessage.success("删除成功")
  97. await getDataAll();
  98. } else {
  99. ElMessage.error(res.data.msg)
  100. }
  101. }).catch(() => {
  102. ElMessage({
  103. type: 'info',
  104. message: '取消删除',
  105. })
  106. })
  107. }
  108. </script>
  109. <style lang="scss" scoped></style>