index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div style="padding: 0px 0px 8px 8px">
  3. <el-row :gutter="8" style="width: 100%">
  4. <el-col :span="24" :xs="24">
  5. <el-card shadow="never" :body-style="{ paddingBottom: '0' }" style="margin-top: 8px">
  6. <el-form :inline="true">
  7. <el-form-item>
  8. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  9. <el-button type="primary" icon="ele-Plus" @click="onAdd"> 新增 </el-button>
  10. </el-form-item>
  11. </el-form>
  12. </el-card>
  13. <el-card shadow="never" style="margin-top: 8px">
  14. <el-table :data="state.listData" style="width: 100%" v-loading="state.loading" row-key="id">
  15. <el-table-column prop="" label="" min-width="120" show-overflow-tooltip />
  16. <el-table-column label="操作" width="160" fixed="right" header-align="center" align="center">
  17. <template #default="{ row }">
  18. <el-button icon="ele-EditPen" size="small" text type="primary" @click="onEdit(row)">编辑</el-button>
  19. <el-button icon="ele-Delete" size="small" text type="danger" @click="onDelete(row)">删除</el-button>
  20. </template>
  21. </el-table-column>
  22. </el-table>
  23. <div class="my-flex my-flex-end view-info-page">
  24. <el-pagination
  25. v-model:currentPage="state.pageInput.currentPage"
  26. v-model:page-size="state.pageInput.pageSize"
  27. :total="state.total"
  28. :page-sizes="state.pageSize"
  29. :layout="state.layout"
  30. @size-change="onSizeChange"
  31. @current-change="onCurrentChange"
  32. ></el-pagination>
  33. </div>
  34. </el-card>
  35. </el-col>
  36. </el-row>
  37. <srm-form ref="srmFormRef" :title="state.srmFormTitle"></srm-form>
  38. </div>
  39. </template>
  40. <script lang="ts" setup>
  41. import { getCurrentInstance, onMounted, onUnmounted, reactive, ref } from 'vue'
  42. import SrmForm from './components/srm-form.vue'
  43. const { proxy } = getCurrentInstance() as any
  44. const srmFormRef = ref()
  45. const state = reactive({
  46. loading: false,
  47. srmFormTitle: '',
  48. total: 0,
  49. pageSize: [10, 20, 50, 100],
  50. layout: 'total, sizes, prev, pager, next',
  51. pageInput: {
  52. currentPage: 1,
  53. pageSize: 10,
  54. },
  55. listData: [],
  56. })
  57. onMounted(() => {
  58. onQuery()
  59. proxy.eventBus.on('refresh', async () => {
  60. onQuery()
  61. })
  62. })
  63. onUnmounted(() => {
  64. proxy.eventBus.off('refresh')
  65. })
  66. const onQuery = async () => {
  67. state.loading = true
  68. const res = {} as any
  69. state.listData = res?.data?.list ?? []
  70. state.total = res?.data?.total ?? 0
  71. state.loading = false
  72. }
  73. const onAdd = () => {
  74. state.srmFormTitle = '新增'
  75. srmFormRef.value.open()
  76. }
  77. const onEdit = (row: any) => {
  78. state.srmFormTitle = '编辑'
  79. srmFormRef.value.open(row)
  80. }
  81. const onDelete = (row: any) => {
  82. proxy.$modal
  83. .confirmDelete(`确定要删除?`)
  84. .then(async () => {
  85. onQuery()
  86. })
  87. .catch(() => {})
  88. }
  89. const onSizeChange = (val: number) => {
  90. state.pageInput.pageSize = val
  91. onQuery()
  92. }
  93. const onCurrentChange = (val: number) => {
  94. state.pageInput.currentPage = val
  95. onQuery()
  96. }
  97. </script>
  98. <script lang="ts">
  99. import { defineComponent } from 'vue'
  100. export default defineComponent({
  101. name: 'admin/srm',
  102. })
  103. </script>
  104. <style lang="scss" scoped></style>