attachment.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="attachment pl-4 pr-4 pt-3 pb-3 h-full flex flex-col">
  3. <div class="flex justify-between">
  4. <div class="title">附件</div>
  5. <div>
  6. <el-upload ref="uploadRef" :http-request="httpUploadFile" :limit="1" :show-file-list="false"
  7. element-loading-text="正在上传">
  8. <template #trigger>
  9. <el-button type="primary">上传</el-button>
  10. </template>
  11. </el-upload>
  12. </div>
  13. </div>
  14. <div class="flex-1 overflow-auto pt-3">
  15. <el-table :data="attachmenttable" border style="width: 100%;height: 200px;">
  16. <el-table-column prop="name" label="附件名称" width="180" />
  17. <el-table-column prop="size" label="附件大小" width="120" />
  18. <el-table-column prop="userName" label="上传人" width="120" />
  19. <el-table-column prop="createTime" label="上传时间" width="180" />
  20. <el-table-column label="操作" width="180" fixed="right">
  21. <template #default="scope">
  22. <el-button link type="primary" size="large" @click="fileDownload(scope.row)">下载</el-button>
  23. <el-button link type="primary" size="large" @click="showVisible(scope.row)">重命名</el-button>
  24. <el-button link type="danger" size="large" @click="deteleFile(scope.row)">删除</el-button>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. </div>
  29. <!-- 弹窗 -->
  30. <el-dialog v-model="renameDialogVisible" width="800" :show-close="false" top="10vh">
  31. <template #header="{ close, titleId, titleClass }">
  32. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  33. <h4 :id="titleId">{{ '文件重命名' }}</h4>
  34. <div>
  35. <el-button type="primary" @click="saveEditClue()">保存</el-button>
  36. <el-button @click="renameDialogVisible = false">取消</el-button>
  37. </div>
  38. </div>
  39. </template>
  40. <div class="pt-3">
  41. <el-input v-model.trim="renameVal" style="width: 100%" class="pb-3" clearable />
  42. </div>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script lang="ts" setup>
  47. import { ElMessageBox, UploadRequestOptions } from 'element-plus';
  48. import { post, uploadFile } from '@/utils/request';
  49. import { confirmAction, downloadFile } from '@/utils/tools';
  50. import { ref, reactive, onMounted, onUnmounted, defineEmits, defineExpose, inject, watchEffect } from 'vue'
  51. import { DETELEFILEFILE, REFIENAMEFILE, UPLOADFILEFILE } from '../api';
  52. const emits = defineEmits(['refreshData']);
  53. const globalPopup = inject<GlobalPopup>('globalPopup')
  54. const props = defineProps<{
  55. information: any
  56. }>()
  57. const attachmenttable = ref([])
  58. const information = ref<any>({})
  59. const renameDialogVisible = ref(false)
  60. const renameVal = ref('')
  61. const uploadRef = ref<any>()
  62. // 下载文件
  63. function fileDownload(item: any) {
  64. downloadFile(`${item.path}`, item.name)
  65. }
  66. // 删除文件
  67. function deteleFile(item: any) {
  68. const id = item.id
  69. confirmAction(`确定删除【${item.name}】文件吗?`).then(() => {
  70. post(DETELEFILEFILE, { id }).then((_res) => {
  71. globalPopup?.showSuccess('删除成功')
  72. emits('refreshData')
  73. })
  74. })
  75. }
  76. // 保存重命名
  77. function saveEditClue() {
  78. if (!renameVal.value) {
  79. globalPopup?.showWarning('请输入文件名称')
  80. return
  81. }
  82. const bussinessId = information.value.id
  83. post(REFIENAMEFILE, { name: renameVal.value, id: bussinessId }).then((res) => {
  84. renameDialogVisible.value = false
  85. globalPopup?.showSuccess(res.msg || '')
  86. emits('refreshData')
  87. }).catch((_err) => { })
  88. }
  89. // 显示弹窗
  90. function showVisible(item: any) {
  91. renameVal.value = JSON.parse(JSON.stringify(item.name))
  92. renameDialogVisible.value = true
  93. }
  94. // 上传附件
  95. async function httpUploadFile(param: UploadRequestOptions) {
  96. const bussinessId = information.value.id
  97. const formData = new FormData();
  98. formData.append('file', param.file)
  99. formData.append('id', bussinessId)
  100. const res = await uploadFile(UPLOADFILEFILE, formData).finally(() => {
  101. uploadRef.value.clearFiles()
  102. })
  103. if (res.code == 'ok') {
  104. globalPopup?.showSuccess(res.msg || '')
  105. emits('refreshData');
  106. return
  107. }
  108. globalPopup?.showError(res.msg || '')
  109. return res
  110. }
  111. watchEffect(() => {
  112. information.value = props.information
  113. attachmenttable.value = (props.information.uploadFilePList || [])
  114. });
  115. // 生命周期钩子
  116. onMounted(() => { });
  117. </script>
  118. <style scoped lang="scss">
  119. .attachment {
  120. .title {
  121. font-size: 18px;
  122. color: #000
  123. }
  124. }
  125. </style>