index.vue.vm 4.0 KB

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