FileSelectDialog.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <SubDialog
  3. :modelValue="modelValue"
  4. @update:modelValue="$emit('update:modelValue', $event)"
  5. title="文件选择"
  6. width="460"
  7. height="430px"
  8. @confirm="handleConfirm"
  9. @cancel="handleCancel"
  10. >
  11. <el-form :model="form" label-position="left">
  12. <el-form-item label="添加文件:" :label-width="formLabelWidth3" style="width: 100%">
  13. <el-row style="width: 100%">
  14. <el-col :span="24">
  15. <el-input
  16. v-model="cloudFileName"
  17. readonly
  18. :step="100"
  19. :min="0"
  20. :max="1000"
  21. controls-position="right"
  22. />
  23. </el-col>
  24. <!-- 文件上传按钮部分 -->
  25. <el-col :span="1" style="display: flex; align-items: center; margin-left: -35px">
  26. <fileUploads
  27. :projectId="projectId"
  28. :solverType="solverType"
  29. accept=".plt"
  30. upId="cloud"
  31. name="点击选择文件"
  32. :imgSrc="meshFileImgSrc"
  33. @upload-success="handleFileUploadSuccess"
  34. @update-fileName="updateFileName"
  35. @update-percentage="updatePercentage"
  36. @upload-status="getUploadStatus"
  37. />
  38. </el-col>
  39. </el-row>
  40. <!-- 进度条 -->
  41. <el-row v-if="showProgress" style="width: 100%; margin-top: 10px;">
  42. <el-col :span="20">
  43. <el-progress :percentage="percentage"></el-progress>
  44. </el-col>
  45. <el-col :span="4">
  46. <div style="line-height: 15px">{{uploadStatus}}</div>
  47. </el-col>
  48. </el-row>
  49. </el-form-item>
  50. <div style="display: flex; flex-direction: row; width: 100%; margin-top: 20px;">
  51. <el-card shadow="hover" style="width: 70%; height: 200px; overflow-y: auto;" >
  52. <el-checkbox-group v-model="selectedFiles">
  53. <el-checkbox
  54. v-for="item in fileList"
  55. :key="item.value"
  56. :label="item.value"
  57. style="display: block"
  58. >
  59. <span style="font-size: 14px">{{ item.label }}</span>
  60. </el-checkbox>
  61. </el-checkbox-group>
  62. </el-card>
  63. <div style="width: 30%; padding-left: 10px;">
  64. <el-button
  65. style="width: 100%; margin-bottom: 10px;"
  66. @click="deleteSelectedFiles"
  67. >
  68. 删除选中文件
  69. </el-button>
  70. <el-button
  71. style="width: 100%; background-color: transparent; margin-left: 0;"
  72. @click="deleteAllFiles"
  73. >
  74. 删除全部文件
  75. </el-button>
  76. </div>
  77. </div>
  78. </el-form>
  79. </SubDialog>
  80. </template>
  81. <script setup>
  82. import { ref, defineProps, defineEmits, computed, watch } from 'vue'
  83. import SubDialog from './SubDialog.vue'
  84. import fileUploads from '@/views/components/fileuploads.vue'
  85. const props = defineProps({
  86. modelValue: Boolean,
  87. projectId: {
  88. type: String,
  89. required: true
  90. },
  91. solverType: {
  92. type: String,
  93. required: true
  94. },
  95. initialFiles: {
  96. type: Array,
  97. default: () => []
  98. }
  99. })
  100. const emit = defineEmits(['update:modelValue', 'confirm', 'cancel'])
  101. // 表单数据
  102. const formLabelWidth = '100px'
  103. const cloudFileName = ref('')
  104. const selectedFiles = ref([])
  105. // const fileList = ref([...props.initialFiles])
  106. const fileList = ref([
  107. {
  108. value: 'file1',
  109. label: '测试文件1.cgns',
  110. raw: {
  111. name: '测试文件1.cgns',
  112. size: 1024 * 1024 * 5 // 5MB
  113. }
  114. },
  115. {
  116. value: 'file2',
  117. label: '测试文件2.xyz',
  118. raw: {
  119. name: '测试文件2.xyz',
  120. size: 1024 * 500 // 500KB
  121. }
  122. },
  123. {
  124. value: 'file3',
  125. label: '测试文件3.bdf',
  126. raw: {
  127. name: '测试文件3.bdf',
  128. size: 1024 * 1024 * 10 // 10MB
  129. }
  130. }
  131. ])
  132. const upId = ref(`file-upload-${Date.now()}`)
  133. const meshFileImgSrc = new URL("@/assets/img/open.png", import.meta.url).href;
  134. let formLabelWidth3 = ref(80)
  135. let uploadStatus = ref('');
  136. let percentage = ref(0);
  137. let fid = ref('');
  138. watch(() => props.modelValue, (newVal) => {
  139. if (!newVal) {
  140. // 当modelValue变为false时,确保完全关闭
  141. emit('cancel')
  142. }
  143. })
  144. // 文件上传成功处理
  145. const handleFileUploadSuccess = (file) => {
  146. //隐藏进度条
  147. setTimeout(() => {
  148. percentage.value = 0;
  149. }, 1000);
  150. const newFile = {
  151. value: file.id || file.name,
  152. label: file.name,
  153. raw: file
  154. }
  155. fileList.value.push(newFile)
  156. cloudFileName.value = file.name
  157. }
  158. // 更新文件名
  159. const updateFileName = (newValue) => {
  160. meshFileName.value = newValue
  161. }
  162. // 更新进度条
  163. const updatePercentage = (newValue) => {
  164. percentage.value = newValue
  165. }
  166. // 更新上传状态
  167. const getUploadStatus = (newValue) => {
  168. uploadStatus.value = newValue
  169. }
  170. // 控制进度条显隐
  171. const showProgress = computed(() => percentage.value > 0 && percentage.value <= 100);
  172. // 删除选中文件
  173. const deleteSelectedFiles = () => {
  174. fileList.value = fileList.value.filter(
  175. file => !selectedFiles.value.includes(file.value)
  176. )
  177. selectedFiles.value = []
  178. }
  179. // 删除全部文件
  180. const deleteAllFiles = () => {
  181. fileList.value = []
  182. selectedFiles.value = []
  183. cloudFileName.value = ''
  184. }
  185. // 确认选择
  186. const handleConfirm = () => {
  187. emit('confirm', {
  188. // selectedFiles: fileList.value.filter(
  189. // file => selectedFiles.value.includes(file.value)
  190. // )
  191. fid: '9305c3e01b5d44e6a1964148d34e02f4'
  192. })
  193. emit('update:modelValue', false)
  194. }
  195. // 取消
  196. const handleCancel = () => {
  197. emit('cancel')
  198. emit('update:modelValue', false)
  199. }
  200. </script>
  201. <style scoped>
  202. .dialog-footer {
  203. display: flex;
  204. justify-content: flex-end;
  205. }
  206. </style>