index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTimeTable">
  4. <template #toolbar>
  5. <a-button type="primary" @click="handleCreate" v-if="getCheckPerm('sceneShare-add')">
  6. 新增</a-button
  7. >
  8. </template>
  9. <template #action="{ record }">
  10. <TableAction
  11. :actions="[
  12. {
  13. label: '删除',
  14. color: 'error',
  15. ifShow: getCheckPerm('sceneShare-del'),
  16. onClick: handleDlet.bind(null, record),
  17. },
  18. ]"
  19. />
  20. </template>
  21. </BasicTable>
  22. <addModal @register="registerAdd" @ok="reload" />
  23. </div>
  24. </template>
  25. <script lang="ts">
  26. import { defineComponent } from 'vue';
  27. import { BasicTable, useTable, FormProps, TableAction } from '/@/components/Table';
  28. import { userShareList, userShareDel } from '/@/api/account';
  29. import { userListSchema } from './data';
  30. import { useI18n } from '/@/hooks/web/useI18n';
  31. import { useModal } from '/@/components/Modal';
  32. import { usePermissionStore } from '/@/store/modules/permission';
  33. import addModal from './addModal.vue';
  34. import { useMessage } from '/@/hooks/web/useMessage';
  35. export default defineComponent({
  36. components: {
  37. BasicTable,
  38. TableAction,
  39. addModal,
  40. },
  41. setup() {
  42. const { t } = useI18n();
  43. const { createMessage, createConfirm } = useMessage();
  44. const permissionStore = usePermissionStore();
  45. const [registerAdd, { openModal: openAddModal }] = useModal();
  46. const { getCheckPerm } = permissionStore;
  47. const searchForm: Partial<FormProps> = {
  48. labelWidth: 100,
  49. schemas: [
  50. {
  51. field: 'ryNickName',
  52. label: '姓名',
  53. component: 'Input',
  54. componentProps: {
  55. maxLength: 100,
  56. },
  57. colProps: {
  58. xl: 6,
  59. xxl: 6,
  60. },
  61. },
  62. {
  63. field: 'ryNo',
  64. label: '人员编号',
  65. component: 'Input',
  66. componentProps: {
  67. maxLength: 100,
  68. },
  69. colProps: {
  70. xl: 8,
  71. xxl: 8,
  72. },
  73. },
  74. ],
  75. };
  76. const [registerTimeTable, { reload }] = useTable({
  77. api: userShareList,
  78. columns: userListSchema,
  79. useSearchForm: true,
  80. formConfig: searchForm,
  81. showTableSetting: true,
  82. showIndexColumn: false,
  83. searchInfo: { type: 0 },
  84. rowKey: 'id',
  85. fetchSetting: {
  86. pageField: 'pageNum',
  87. sizeField: 'pageSize',
  88. listField: 'list',
  89. totalField: 'total',
  90. },
  91. actionColumn: {
  92. width: 100,
  93. title: '操作',
  94. dataIndex: 'action',
  95. slots: { customRender: 'action' },
  96. },
  97. canResize: true,
  98. });
  99. function handleCreate() {
  100. openAddModal(true, {});
  101. }
  102. function tabChange(val: string) {
  103. console.log('tabChange', val);
  104. reload();
  105. }
  106. function handleOpen(record) {
  107. console.log('点击了启用', record);
  108. }
  109. async function handleDlet(record) {
  110. createConfirm({
  111. title: '删除',
  112. content: `确定要删除 ${record.ryNo} 吗?`,
  113. onOk: async () => {
  114. await userShareDel({id: record.id });
  115. createMessage.success('操作成功');
  116. reload();
  117. },
  118. });
  119. }
  120. return {
  121. registerTimeTable,
  122. registerAdd,
  123. handleOpen,
  124. tabChange,
  125. reload,
  126. handleDlet,
  127. getCheckPerm,
  128. handleCreate,
  129. t,
  130. };
  131. },
  132. });
  133. </script>
  134. <style lang="less" scoped>
  135. .desc-wrap-BasicTable {
  136. background-color: #f0f2f5;
  137. .vben-basic-table-form-container {
  138. padding: 0;
  139. }
  140. }
  141. </style>