index.vue - Copy.vm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div>
  3. <BasicTable @@register="registerTable">
  4. <template #toolbar>
  5. <a-button type="primary" @@click="handleCreate" :disabled="!hasPermission('@(@Model.ClassName):add')">新增@(@Model.BusName)</a-button>
  6. </template>
  7. @foreach (var column in Model.TableField){
  8. if(@column.EffectType == "Upload"){
  9. @:<template #@(@column.LowerColumnName)="{ text, record }">
  10. <TableImg
  11. v-if="record.@(@column.LowerColumnName)Attachment"
  12. :size="60"
  13. :simpleShow="true"
  14. :showBadge="false"
  15. :imgList="[downUrl + '/' + record.@(@column.LowerColumnName)Attachment.id + record.@(@column.LowerColumnName)Attachment.suffix]"
  16. />
  17. </template>
  18. }
  19. }
  20. <template #bodyCell="{ column, record }">
  21. <template v-if="column.key === 'action'">
  22. <TableAction
  23. :actions="[
  24. {
  25. icon: 'clarity:note-edit-line',
  26. label: '编辑',
  27. onClick: handleEdit.bind(null, record),
  28. disabled: !hasPermission('@(@Model.ClassName):edit'),
  29. },
  30. {
  31. icon: 'ant-design:delete-outlined',
  32. color: 'error',
  33. label: '删除',
  34. ifShow: hasPermission('@(@Model.ClassName):delete'),
  35. popConfirm: {
  36. title: '是否确认删除',
  37. placement: 'left',
  38. confirm: handleDelete.bind(null, record),
  39. },
  40. },
  41. ]"
  42. />
  43. </template>
  44. </template>
  45. </BasicTable>
  46. <@(@Model.ClassName)Modal @@register="registerModal" @@success="handleSuccess" />
  47. </div>
  48. </template>
  49. <script lang="ts">
  50. import { defineComponent } from 'vue';
  51. import { usePermission } from '/@@/hooks/web/usePermission';
  52. @if(Model.IsUpload){
  53. @:import { BasicTable, useTable, TableAction, TableImg } from '/@@/components/Table';
  54. }else{
  55. @:import { BasicTable, useTable, TableAction } from '/@@/components/Table';
  56. }
  57. import { useModal } from '/@@/components/Modal';
  58. import @(@Model.ClassName)Modal from './dataModal.vue';
  59. import { columns, searchFormSchema } from './data.data';
  60. import { useMessage } from '/@@/hooks/web/useMessage';
  61. import { get@(@Model.ClassName)PageList, delete@(@Model.ClassName) } from '/@@/api/main/@(@Model.ClassName)';
  62. export default defineComponent({
  63. @if(Model.IsUpload){
  64. @:components: { BasicTable, @(@Model.ClassName)Modal, TableAction, TableImg },
  65. }else{
  66. @:components:{ BasicTable, @(@Model.ClassName)Modal, TableAction },
  67. }
  68. setup() {
  69. const { hasPermission } = usePermission();
  70. const { createMessage } = useMessage();
  71. const [registerModal, { openModal }] = useModal();
  72. const hasPage = hasPermission('@(@Model.ClassName):page');
  73. const [registerTable, { reload }] = useTable({
  74. title: '@(@Model.BusName)列表',
  75. api: get@(@Model.ClassName)PageList,
  76. pagination: true,
  77. rowKey: 'id',
  78. columns,
  79. formConfig: {
  80. labelWidth: 120,
  81. schemas: searchFormSchema,
  82. autoSubmitOnEnter: true,
  83. },
  84. useSearchForm: hasPage,
  85. immediate: hasPage,
  86. showTableSetting: hasPage,
  87. bordered: true,
  88. canResize: true,
  89. actionColumn: {
  90. width: 160,
  91. title: '操作',
  92. dataIndex: 'action',
  93. //slots: { customRender: 'action' },
  94. },
  95. });
  96. function handleCreate() {
  97. openModal(true, {
  98. isUpdate: false,
  99. });
  100. }
  101. function handleEdit(record: Recordable) {
  102. openModal(true, {
  103. record,
  104. isUpdate: true,
  105. });
  106. }
  107. async function handleDelete(record: Recordable) {
  108. await delete@(@Model.ClassName)(record);
  109. reload();
  110. createMessage.success('删除成功!');
  111. }
  112. function handleSuccess() {
  113. reload();
  114. }
  115. return {
  116. hasPermission,
  117. registerTable,
  118. registerModal,
  119. handleCreate,
  120. handleEdit,
  121. handleDelete,
  122. handleSuccess,
  123. @if(@Model.IsUpload){
  124. @:downUrl: import.meta.env.VITE_GLOB_DOWNLOAD_URL,
  125. }
  126. };
  127. },
  128. });
  129. </script>