index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <a-card :bordered="false" :body-style="{ 'padding-bottom': '0px' }" class="mb-2">
  3. <a-form ref="formRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
  4. <a-row :gutter="24">
  5. <a-col :span="8">
  6. <a-form-item label="名称关键词" name="searchKey">
  7. <a-input v-model:value="searchFormState.searchKey" placeholder="请输入模块名称关键词" />
  8. </a-form-item>
  9. </a-col>
  10. <a-col :span="8">
  11. <a-button type="primary" @click="table.refresh(true)">查询</a-button>
  12. <a-button style="margin: 0 8px" @click="reset">重置</a-button>
  13. </a-col>
  14. </a-row>
  15. </a-form>
  16. </a-card>
  17. <a-card :bordered="false">
  18. <s-table
  19. ref="table"
  20. :columns="columns"
  21. :data="loadData"
  22. :alert="options.alert.show"
  23. bordered
  24. :row-key="(record) => record.id"
  25. :tool-config="toolConfig"
  26. :row-selection="options.rowSelection"
  27. >
  28. <template #operator class="table-operator">
  29. <a-space>
  30. <a-button type="primary" @click="form.onOpen()">
  31. <template #icon><plus-outlined /></template>
  32. 新增模块
  33. </a-button>
  34. <xn-batch-delete :selectedRowKeys="selectedRowKeys" @batchDelete="deleteBatchModule" />
  35. </a-space>
  36. </template>
  37. <template #bodyCell="{ column, record }">
  38. <template v-if="column.dataIndex === 'icon'">
  39. <a-tag :color="record.color">
  40. <component :is="record.icon" />
  41. </a-tag>
  42. </template>
  43. <template v-if="column.dataIndex === 'action'">
  44. <a-space>
  45. <a @click="form.onOpen(record)">编辑</a>
  46. <a-divider type="vertical" />
  47. <a-popconfirm title="确定要删除此模块吗?" @confirm="deleteModule(record)">
  48. <a-button type="link" danger size="small">删除</a-button>
  49. </a-popconfirm>
  50. </a-space>
  51. </template>
  52. </template>
  53. </s-table>
  54. </a-card>
  55. <Form ref="form" @successful="table.refresh(true)" />
  56. </template>
  57. <script setup name="sysModule">
  58. import Form from './form.vue'
  59. import moduleApi from '@/api/sys/resource/moduleApi'
  60. let searchFormState = reactive({})
  61. const formRef = ref()
  62. const table = ref()
  63. let form = ref()
  64. const toolConfig = { refresh: true, height: true, columnSetting: false, striped: false }
  65. const columns = [
  66. {
  67. title: '显示名称',
  68. dataIndex: 'title'
  69. },
  70. {
  71. title: '图标',
  72. dataIndex: 'icon'
  73. },
  74. {
  75. title: '排序',
  76. dataIndex: 'sortCode',
  77. sorter: true
  78. },
  79. {
  80. title: '创建时间',
  81. dataIndex: 'createTime',
  82. sorter: true
  83. },
  84. {
  85. title: '操作',
  86. dataIndex: 'action',
  87. align: 'center',
  88. width: '200px',
  89. fixed: 'right'
  90. }
  91. ]
  92. let selectedRowKeys = ref([])
  93. // 列表选择配置
  94. const options = {
  95. alert: {
  96. show: false,
  97. clear: () => {
  98. selectedRowKeys = ref([])
  99. }
  100. },
  101. rowSelection: {
  102. onChange: (selectedRowKey, selectedRows) => {
  103. selectedRowKeys.value = selectedRowKey
  104. }
  105. }
  106. }
  107. const loadData = (parameter) => {
  108. return moduleApi.modulePage(Object.assign(parameter, searchFormState)).then((res) => {
  109. return res
  110. })
  111. }
  112. // 重置
  113. const reset = () => {
  114. formRef.value.resetFields()
  115. table.value.refresh(true)
  116. }
  117. // 删除
  118. const deleteModule = (record) => {
  119. let params = [
  120. {
  121. id: record.id
  122. }
  123. ]
  124. moduleApi.moduleDelete(params).then(() => {
  125. table.value.refresh(true)
  126. })
  127. }
  128. // 批量删除
  129. const deleteBatchModule = (params) => {
  130. moduleApi.moduleDelete(params).then(() => {
  131. table.value.clearRefreshSelected()
  132. })
  133. }
  134. </script>