attachment.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. // 下载文件
  62. function fileDownload(item: any) {
  63. downloadFile(`${item.path}`, item.name)
  64. }
  65. // 删除文件
  66. function deteleFile(item: any) {
  67. const id = item.id
  68. confirmAction(`确定删除【${item.name}】文件吗?`).then(() => {
  69. post(DETELEFILEFILE, { id }).then((_res) => {
  70. globalPopup?.showSuccess('删除成功')
  71. emits('refreshData')
  72. })
  73. })
  74. }
  75. // 保存重命名
  76. function saveEditClue() {
  77. if (!renameVal.value) {
  78. globalPopup?.showWarning('请输入文件名称')
  79. return
  80. }
  81. const bussinessId = information.value.id
  82. post(REFIENAMEFILE, { name: renameVal.value, id: bussinessId }).then((res) => {
  83. if (res.code == 'ok') {
  84. renameDialogVisible.value = false
  85. globalPopup?.showSuccess(res.msg || '')
  86. emits('refreshData')
  87. }
  88. }).catch((_err) => { })
  89. }
  90. // 显示弹窗
  91. function showVisible(item: any) {
  92. renameVal.value = JSON.parse(JSON.stringify(item.name))
  93. renameDialogVisible.value = true
  94. }
  95. // 上传附件
  96. async function httpUploadFile(param: UploadRequestOptions) {
  97. const bussinessId = information.value.id
  98. const formData = new FormData();
  99. formData.append('file', param.file)
  100. formData.append('id', bussinessId)
  101. const res = await uploadFile(UPLOADFILEFILE, formData)
  102. if (res.code == 'ok') {
  103. globalPopup?.showSuccess(res.msg || '')
  104. emits('refreshData');
  105. return
  106. }
  107. globalPopup?.showError(res.msg || '')
  108. return res
  109. }
  110. watchEffect(() => {
  111. information.value = props.information
  112. attachmenttable.value = props.information.uploadFilePList
  113. });
  114. // 生命周期钩子
  115. onMounted(() => { });
  116. </script>
  117. <style scoped lang="scss">
  118. .attachment {
  119. .title {
  120. font-size: 18px;
  121. color: #000
  122. }
  123. }
  124. </style>