index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. return false;
  109. }
  110. function getTableAction() {
  111. // 获取组件
  112. const tableAction = unref(tableRef);
  113. if (!tableAction) {
  114. throw new Error('tableAction is null');
  115. }
  116. return tableAction;
  117. }
  118. function handleChange(info) {
  119. console.log(`info`, info);
  120. }
  121. async function handleGroupBtn(group) {
  122. await nextTick();
  123. getTableAction().reload();
  124. state.group = group.toLowerCase();
  125. }
  126. function handleTableReset() {
  127. getTableAction().reload();
  128. }
  129. async function handleEdit(record: Recordable) {
  130. console.log(`record`, record);
  131. console.log('=====编辑');
  132. }
  133. async function handleDelete(record: Recordable) {
  134. console.log(`record`, record);
  135. console.log('删除=====');
  136. }
  137. function createActions(record: EditRecordRow): ActionItem[] {
  138. return [
  139. {
  140. label: '编辑',
  141. icon: 'ant-design:edit-outlined',
  142. color: 'warning',
  143. onClick: handleEdit.bind(null, record),
  144. },
  145. {
  146. label: '删除',
  147. color: 'error',
  148. icon: 'ic:outline-delete-outline',
  149. popConfirm: {
  150. title: '是否确认删除',
  151. confirm: handleDelete.bind(null, record),
  152. },
  153. },
  154. ];
  155. }
  156. return {
  157. t,
  158. createActions,
  159. tableRef,
  160. registerTable,
  161. beforeUpload,
  162. handleChange,
  163. handleGroupBtn,
  164. handleTableReset,
  165. ...toRefs(state),
  166. };
  167. },
  168. });
  169. </script>
  170. <style scoped>
  171. .attachment-container {
  172. position: relative;
  173. }
  174. .vben-collapse-container__body > .mr-2 {
  175. margin-top: 5px;
  176. font-weight: 550 !important;
  177. }
  178. /* .upload-progress {
  179. padding: 20px 30px;
  180. } */
  181. .vben-basic-table-header__toolbar {
  182. justify-content: space-between;
  183. }
  184. .tool-btn-wrap {
  185. flex: 1;
  186. }
  187. .tool-btn-wrap button {
  188. margin-right: 5px;
  189. }
  190. </style>