index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div class="ma-content-block lg:flex justify-between">
  3. <!-- CRUD 组件 -->
  4. <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
  5. <!-- 搜索区 tableSearch -->
  6. <template #tableSearch>
  7. <a-col :sm="6" :xs="24">
  8. <a-form-item field="name" label="岗位名称">
  9. <a-input v-model="searchForm.name" placeholder="请输入岗位名称" allow-clear />
  10. </a-form-item>
  11. </a-col>
  12. <a-col :sm="6" :xs="24">
  13. <a-form-item field="status" label="状态">
  14. <sa-select v-model="searchForm.status" dict="data_status" placeholder="请选择状态" />
  15. </a-form-item>
  16. </a-col>
  17. <a-col :sm="6" :xs="24">
  18. <a-form-item field="create_time" label="时间范围">
  19. <a-range-picker v-model="searchForm.create_time" style="width: 100%" />
  20. </a-form-item>
  21. </a-col>
  22. </template>
  23. <!-- Table 自定义渲染 -->
  24. <!-- 状态列 -->
  25. <template #status="{ record }">
  26. <sa-switch v-model="record.status" @change="changeStatus($event, record.id)"></sa-switch>
  27. </template>
  28. </sa-table>
  29. <!-- 编辑表单 -->
  30. <edit-form ref="editRef" @success="refresh" />
  31. <!-- 查看表单 -->
  32. <view-form ref="viewRef" @success="refresh" />
  33. </div>
  34. </template>
  35. <script setup>
  36. import { onMounted, ref, reactive } from 'vue'
  37. import { Message } from '@arco-design/web-vue'
  38. import EditForm from './edit.vue'
  39. import ViewForm from './view.vue'
  40. import api from '@/api/system/post'
  41. const crudRef = ref()
  42. const editRef = ref()
  43. const viewRef = ref()
  44. // 搜索表单
  45. const searchForm = ref({
  46. name: '',
  47. status: '',
  48. create_time: [],
  49. })
  50. // 修改状态
  51. const changeStatus = async (status, id) => {
  52. const response = await api.changeStatus({ id, status })
  53. if (response.code === 200) {
  54. Message.success(response.message)
  55. crudRef.value.refresh()
  56. }
  57. }
  58. // SaTable 基础配置
  59. const options = reactive({
  60. api: api.getPageList,
  61. rowSelection: { showCheckedAll: true },
  62. view: {
  63. show: true,
  64. auth: ['/core/post/read'],
  65. func: async (record) => {
  66. viewRef.value?.open(record)
  67. },
  68. },
  69. add: {
  70. show: true,
  71. auth: ['/core/post/save'],
  72. func: async () => {
  73. editRef.value?.open()
  74. },
  75. },
  76. edit: {
  77. show: true,
  78. auth: ['/core/post/update'],
  79. func: async (record) => {
  80. editRef.value?.open('edit')
  81. editRef.value?.setFormData(record)
  82. },
  83. },
  84. delete: {
  85. show: true,
  86. auth: ['/core/post/destroy'],
  87. func: async (params) => {
  88. const resp = await api.destroy(params)
  89. if (resp.code === 200) {
  90. Message.success(`删除成功!`)
  91. crudRef.value?.refresh()
  92. }
  93. },
  94. },
  95. import: {
  96. show: true,
  97. url: '/core/post/import',
  98. templateUrl: '/core/post/downloadTemplate',
  99. auth: ['/core/post/import'],
  100. },
  101. export: { show: true, url: '/core/post/export', auth: ['/core/post/export'] },
  102. })
  103. // SaTable 列配置
  104. const columns = reactive([
  105. { title: 'ID', dataIndex: 'id', width: 80 },
  106. { title: '岗位名称', dataIndex: 'name', width: 120 },
  107. { title: '岗位标识', dataIndex: 'code', width: 180 },
  108. { title: '排序', dataIndex: 'sort', width: 180 },
  109. { title: '状态', dataIndex: 'status', type: 'dict', dict: 'data_status', width: 120 },
  110. { title: '备注', dataIndex: 'remark', width: 180 },
  111. { title: '创建时间', dataIndex: 'create_time', width: 180 },
  112. ])
  113. // 页面数据初始化
  114. const initPage = async () => {}
  115. // SaTable 数据请求
  116. const refresh = async () => {
  117. crudRef.value?.refresh()
  118. }
  119. // 页面加载完成执行
  120. onMounted(async () => {
  121. initPage()
  122. refresh()
  123. })
  124. </script>