index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <CollapseContainer
  3. class="attachment-container"
  4. title="附件管理"
  5. :canExpan="false"
  6. helpMessage="主要用于管理上传到服务器或第三方存储的数据"
  7. >
  8. <a-button type="default" class="mr-2"> 全部 </a-button>
  9. <a-button type="default" class="mr-2"> 图片 </a-button>
  10. <a-button type="default" class="mr-2"> 音频 </a-button>
  11. <a-button type="default" class="mr-2"> 视频 </a-button>
  12. <a-button type="default" class="mr-2"> 文档 </a-button>
  13. <a-button type="default" class="mr-2"> 应用 </a-button>
  14. <a-button type="default" class="mr-2"> 压缩包 </a-button>
  15. <BasicTable ref="tableRef" :canResize="true" @register="registerTable" showTableSetting>
  16. <template #action="{ record, column }">
  17. <TableAction :actions="createActions(record, column)" stopButtonPropagation />
  18. </template>
  19. <template #toolbar>
  20. <div class="tool-btn-wrap">
  21. <a-upload
  22. :showUploadList="false"
  23. :multiple="false"
  24. :before-upload="beforeUpload"
  25. @change="handleChange"
  26. >
  27. <a-button type="primary" :disabled="disabled">
  28. {{ t('component.upload.upload') }}
  29. </a-button>
  30. </a-upload>
  31. <a-button color="error" @click="deleteBatches">
  32. {{ t('common.delText') }}
  33. </a-button>
  34. </div>
  35. </template>
  36. </BasicTable>
  37. </CollapseContainer>
  38. </template>
  39. <script lang="ts">
  40. import { useMessage } from '/@/hooks/web/useMessage';
  41. import { defineComponent, nextTick, reactive, ref, toRefs, unref } from 'vue';
  42. // import Upload from '/@/components/customComponents/upload.vue';
  43. import { Upload, Progress, Modal } from 'ant-design-vue';
  44. import { CollapseContainer } from '/@/components/Container/index';
  45. import { adapt } from '/@/utils/adapt';
  46. import { useI18n } from '/@/hooks/web/useI18n';
  47. import {
  48. BasicTable,
  49. useTable,
  50. TableAction,
  51. ActionItem,
  52. EditRecordRow,
  53. TableActionType,
  54. } from '/@/components/Table';
  55. import { columns } from './data';
  56. import { getAttachmentList } from '/@/api/sys/general';
  57. import { uploadApi } from '/@/api/sys/upload';
  58. export default defineComponent({
  59. name: 'Attchment',
  60. components: {
  61. CollapseContainer,
  62. BasicTable,
  63. TableAction,
  64. [Upload.name]: Upload,
  65. [Modal.name]: Modal,
  66. [Progress.name]: Progress,
  67. },
  68. setup() {
  69. const { t } = useI18n();
  70. const { createMessage } = useMessage();
  71. const { success, error } = createMessage;
  72. const tableHeight = adapt().tableHeight;
  73. const state = reactive({
  74. groupList: [] as object[],
  75. group: 'basic',
  76. disabled: false,
  77. });
  78. const tableRef = ref<Nullable<TableActionType>>(null);
  79. const [registerTable] = useTable({
  80. columns: columns,
  81. maxHeight: tableHeight,
  82. afterFetch: afterFetch,
  83. api: getAttachmentList,
  84. actionColumn: {
  85. width: 160,
  86. title: '操作',
  87. dataIndex: 'action',
  88. slots: { customRender: 'action' },
  89. fixed: undefined,
  90. },
  91. showIndexColumn: false,
  92. pagination: true,
  93. });
  94. function afterFetch(res) {
  95. console.log(`res`, res);
  96. }
  97. function beforeUpload(file) {
  98. uploadApi({ file })
  99. .then((res) => {
  100. console.log(`res`, res);
  101. success('文件上传成功');
  102. getTableAction().reload();
  103. })
  104. .catch((err) => {
  105. error('文件上传失败');
  106. console.log(`err`, err);
  107. });
  108. }
  109. function getTableAction() {
  110. // 获取组件
  111. const tableAction = unref(tableRef);
  112. if (!tableAction) {
  113. throw new Error('tableAction is null');
  114. }
  115. return tableAction;
  116. }
  117. function handleChange(info) {
  118. console.log(`info`, info);
  119. }
  120. async function handleGroupBtn(group) {
  121. await nextTick();
  122. getTableAction().reload();
  123. state.group = group.toLowerCase();
  124. }
  125. function handleTableReset() {
  126. getTableAction().reload();
  127. }
  128. async function handleEdit(record: Recordable) {
  129. console.log(`record`, record);
  130. console.log('=====编辑');
  131. }
  132. async function handleDelete(record: Recordable) {
  133. console.log(`record`, record);
  134. console.log('删除=====');
  135. }
  136. function createActions(record: EditRecordRow): ActionItem[] {
  137. return [
  138. {
  139. label: '编辑',
  140. icon: 'ant-design:edit-outlined',
  141. color: 'warning',
  142. onClick: handleEdit.bind(null, record),
  143. },
  144. {
  145. label: '删除',
  146. color: 'error',
  147. icon: 'ic:outline-delete-outline',
  148. popConfirm: {
  149. title: '是否确认删除',
  150. confirm: handleDelete.bind(null, record),
  151. },
  152. },
  153. ];
  154. }
  155. return {
  156. t,
  157. createActions,
  158. tableRef,
  159. registerTable,
  160. beforeUpload,
  161. handleChange,
  162. handleGroupBtn,
  163. handleTableReset,
  164. ...toRefs(state),
  165. };
  166. },
  167. });
  168. </script>
  169. <style scoped>
  170. .attachment-container {
  171. position: relative;
  172. }
  173. .vben-collapse-container__body > .mr-2 {
  174. margin-top: 5px;
  175. font-weight: 550 !important;
  176. }
  177. /* .upload-progress {
  178. padding: 20px 30px;
  179. } */
  180. .vben-basic-table-header__toolbar {
  181. justify-content: space-between;
  182. }
  183. .tool-btn-wrap {
  184. flex: 1;
  185. }
  186. .tool-btn-wrap button {
  187. margin-right: 5px;
  188. }
  189. </style>