UpLoadComponentV2.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <!--文件上传组件-->
  2. <template>
  3. <div>
  4. <el-divider v-if="showDivider" content-position="left"><i class="el-icon-document"></i> {{ dividerName
  5. }}</el-divider>
  6. <el-upload ref="upload" style="display: inline-block; :show-header='status'" action="" :limit="999"
  7. :http-request="httpRequest" multiple :on-exceed="(files, fileList) => {
  8. $message.warning(`当前限制选择 999 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
  9. }" :show-file-list="false" :on-change="changes" :on-progress="uploadVideoProcess" :file-list="fileList">
  10. <template v-if="auth === 'view' && uploadFlag === false" #tip>
  11. <el-button :loading="loading" type="primary" size="default" :disabled="true"> 点击上传 </el-button>
  12. </template>
  13. <template v-else #trigger>
  14. <el-button :loading="loading" type="primary" size="default"> 点击上传 </el-button>
  15. </template>
  16. <AttachmentLib :directory="directory" @onDownToOss="handleOnDownToOss"></AttachmentLib>
  17. </el-upload>
  18. <div style="height: calc(100% - 80px);margin-top: 10px">
  19. <!-- 进度条 -->
  20. <el-progress style="margin-left: 5em" v-if="progressFlag" :percentage="loadProgress"></el-progress>
  21. <el-table ref="uploadTable" :key="tableKey" @row-click="tableRowClick" :row-class-name="tableRowClassName"
  22. v-loading="loading" :data="dataListNew">
  23. <el-table-column type="seq" width="40"></el-table-column>
  24. <el-table-column label="文件名称" prop="name" align="center">
  25. <template #default="scope">
  26. <div v-if="ifName(scope.row) === true">
  27. <el-image style="width: 30px; height: 30px;padding-top: 4px" :src="scope.row.lsUrl"
  28. :preview-src-list="[scope.row.lsUrl]"></el-image>
  29. </div>
  30. <div v-else>
  31. <el-link type="primary" :underline="false" @click="showFile(scope.row)">{{ scope.row.name }}</el-link>
  32. </div>
  33. </template>
  34. </el-table-column>
  35. <el-table-column v-if="auth !== 'view'" label="创建人" prop="createBy.name" align="center"></el-table-column>
  36. <el-table-column v-if="auth !== 'view'" label="创建时间" prop="createDate" align="center"></el-table-column>
  37. <el-table-column label="文件大小" prop="size" align="center">
  38. <template #default="scope">
  39. {{ getSize(scope.row.size) }}
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="文件类型" prop="fileType" align="center">
  43. <template #default="scope">
  44. <component :is="scope.row.fileTypeComponent || 'fileTypeComponentA'"
  45. :options="$dictUtils.getDictList('cw_project_report_file_type')" :value="scope.row.fileType"
  46. @updateFileType="updateFileType"></component>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="盖章类型" prop="sealType" align="center">
  50. <template #default="scope">
  51. <component :is="scope.row.sealTypeComponent || 'sealTypeComponentA'"
  52. :options="$dictUtils.getDictList('cw_seal_type')" :value="scope.row.sealType" :scope="scope"
  53. @updateSealType="updateSealType"></component>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="备注" prop="remarks" align="center">
  57. <template #default="scope">
  58. <component :is="scope.row.remarksComponent || 'remarksComponentA'" :value="scope.row.remarks"
  59. @updateRemarks="updateRemarks"></component>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="操作" width="200px" fixed="right" align="center">
  63. <template #default="scope">
  64. <el-button text type="primary" icon="el-icon-edit" size="small" @click="toHref(scope.row)"
  65. :disabled="false">下载</el-button>
  66. <el-button text type="primary" icon="el-icon-delete" size="small"
  67. @click="deleteById(scope.row, scope.$index, fileList)"
  68. :disabled="auth === 'view' && delFlag === false && createBy !== scope.row.createBy.name">删除</el-button>
  69. <!--<el-button size="small" type="text" icon="el-icon-edit"
  70. @click="handleUpdate(scope.row, scope.$index)"
  71. >{{ scope.row.btn || "修改" }}</el-button>-->
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. </div>
  76. <!-- <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="[url]" :zIndex=9999></el-image-viewer>-->
  77. </div>
  78. </template>
  79. <script>
  80. // eslint-disable-next-line no-unused-vars
  81. import OSSSerivce, {
  82. httpRequest,
  83. // eslint-disable-next-line no-unused-vars
  84. handleRemove,
  85. fileName,
  86. // eslint-disable-next-line no-unused-vars
  87. beforeAvatarUpload,
  88. // eslint-disable-next-line no-unused-vars
  89. openWindowOnUrl,
  90. // eslint-disable-next-line no-unused-vars
  91. toHref
  92. } from '@/api/sys/OSSService'
  93. // import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
  94. import moment from 'moment'
  95. import AttachmentLib from './AttachmentLib.vue'
  96. export default {
  97. data() {
  98. return {
  99. progressFlag: false,
  100. loadProgress: 0,
  101. fileList: [],
  102. dataList: [],
  103. dataListNew: [],
  104. url: '',
  105. showViewer: false,
  106. ossService: null,
  107. auth: '',
  108. directory: 'public',
  109. maxValue: 300,
  110. tableKey: '',
  111. fileLoading: true,
  112. dividerName: '',
  113. uploadFlag: false,
  114. delFlag: false,
  115. createBy: '',
  116. showDivider: true,
  117. fileType: '',
  118. sealType: '',
  119. remarks: '',
  120. loading: false
  121. }
  122. },
  123. watch: {
  124. },
  125. created() {
  126. this.ossService = new OSSSerivce()
  127. },
  128. components: {
  129. AttachmentLib,
  130. // ElImageViewer,
  131. fileTypeComponentA: {
  132. render: function (h) {
  133. return h('span', {
  134. domProps: {
  135. innerText: this.$dictUtils.getDictLabel('cw_project_report_file_type', this.value, '')
  136. }
  137. })
  138. },
  139. props: ['options', 'value']
  140. },
  141. fileTypeComponentB: {
  142. data() {
  143. return { fileType: '' }
  144. },
  145. props: ['options', 'value'],
  146. mounted() {
  147. this.fileType = this.value
  148. },
  149. render: function (h) {
  150. return h(
  151. 'el-select',
  152. {
  153. attrs: {
  154. placeholder: '请选择',
  155. value: this.$dictUtils.getDictLabel('cw_project_report_file_type', this.fileType, ''),
  156. size: 'small',
  157. clearable: true
  158. },
  159. props: ['value'],
  160. on: {
  161. change: (value) => {
  162. this.fileType = value
  163. this.$emit('updateFileType', value)
  164. }
  165. }
  166. },
  167. [
  168. this.options.map((item) => {
  169. let { label, value } = item
  170. return h('el-option', {
  171. props: {
  172. label,
  173. value: parseInt(value),
  174. key: value
  175. }
  176. })
  177. })
  178. ]
  179. )
  180. }
  181. },
  182. sealTypeComponentA: {
  183. render: function (h) {
  184. return h('span', {
  185. domProps: {
  186. innerText: this.$dictUtils.getDictLabel('cw_seal_type', this.value, '')
  187. }
  188. })
  189. },
  190. props: ['options', 'value']
  191. },
  192. sealTypeComponentB: {
  193. data() {
  194. return { sealType: '' }
  195. },
  196. props: ['options', 'value', 'scope'],
  197. mounted() {
  198. this.sealType = this.value
  199. },
  200. render: function (h) {
  201. return h(
  202. 'el-select',
  203. {
  204. attrs: {
  205. placeholder: '请选择',
  206. value: this.$dictUtils.getDictLabel('cw_seal_type', this.sealType, ''),
  207. size: 'small',
  208. clearable: true
  209. },
  210. props: ['value'],
  211. on: {
  212. change: (value) => {
  213. let suffix = this.scope.row.name.substring(this.scope.row.name.lastIndexOf('.') + 1)
  214. if (parseInt(value) === 1) {
  215. if (suffix === 'pdf' || suffix === 'doc' || suffix === 'docx') {
  216. this.sealType = value
  217. this.$emit('updateSealType', value)
  218. } else {
  219. this.$message.error('只有“pdf、doc、docx”格式文件的盖章类型可以是“电子章”')
  220. this.sealType = ''
  221. this.$emit('updateSealType', '')
  222. }
  223. } else {
  224. this.sealType = value
  225. this.$emit('updateSealType', value)
  226. }
  227. }
  228. }
  229. },
  230. [
  231. this.options.map((item) => {
  232. let { label, value } = item
  233. return h('el-option', {
  234. props: {
  235. label,
  236. value: parseInt(value),
  237. key: value
  238. }
  239. })
  240. })
  241. ]
  242. )
  243. }
  244. },
  245. remarksComponentA: {
  246. render: function (h) {
  247. return h('span', {
  248. domProps: {
  249. innerText: this.value
  250. }
  251. })
  252. },
  253. props: ['value']
  254. },
  255. remarksComponentB: {
  256. data() {
  257. return { remarks: '' }
  258. },
  259. props: ['value'],
  260. mounted() {
  261. this.remarks = this.value
  262. },
  263. render: function (h) {
  264. return h(
  265. 'el-input',
  266. {
  267. attrs: {
  268. placeholder: '请输入',
  269. value: this.remarks,
  270. size: 'small',
  271. clearable: true
  272. },
  273. props: ['value'],
  274. on: {
  275. input: (value) => {
  276. this.remarks = value
  277. this.$emit('updateRemarks', value)
  278. }
  279. }
  280. }
  281. )
  282. }
  283. }
  284. },
  285. mounted() {
  286. window.onPreview = this.onPreview
  287. },
  288. methods: {
  289. /**
  290. * dividerName: 组件中divider的名称赋值
  291. * showDivider: ‘附件‘Divider是否展示
  292. * 注:值为空时,默认值为true
  293. * showDivider=false时 ‘附件‘Divider隐藏
  294. **/
  295. setDividerName(dividerName, showDivider) {
  296. if (this.commonJS.isNotEmpty(dividerName)) {
  297. this.dividerName = dividerName
  298. }
  299. if (this.commonJS.isNotEmpty(showDivider)) {
  300. if (showDivider === false) {
  301. this.showDivider = false
  302. } else {
  303. this.showDivider = true
  304. }
  305. } else {
  306. this.showDivider = true
  307. }
  308. },
  309. /**
  310. * 文件上传组件初始化
  311. * @param auth
  312. * auth的值为"view"时,不可上传/编辑文件
  313. * auth为其他值时,可上传/编辑文件
  314. * @param fileList 要显示到文件上传列表中的文件。
  315. * 注:文件必须要有url属性并且文件的url属性值必须是在oss中的路径值
  316. * 例:'/attachment-file/xxx/xxx/2022/9/08/xxx.jpg'
  317. * @param directory 要存放到oss的哪个文件夹下。
  318. * 注:值为空时,默认存放到"public"文件夹
  319. * @param maxValue 上传文件允许的最大值,单位:MB
  320. * 注:值为空时,默认值为300MB
  321. * @param dividerName 组件中divider的名称
  322. * 注:值为空时,默认值为‘附件’
  323. * @param uploadFlag ‘上传文件’按钮是否禁用
  324. * 注:值为空时,默认值为false
  325. * auth=view&&uploadFlag=false时 ‘上传文件’按钮禁用
  326. * @param delFlag ‘删除’按钮是否禁用
  327. * 注:值为空时,默认值为false
  328. * auth=view&&delFlag=false时 ‘删除’按钮禁用
  329. * @param showDivider ‘附件‘Divider是否展示
  330. * 注:值为空时,默认值为true
  331. * showDivider=false时 ‘附件‘Divider隐藏
  332. */
  333. async newUpload(auth, fileList, directory, maxValue, dividerName, uploadFlag, delFlag, showDivider) {
  334. await this.fileLoadingFalse()
  335. if (this.commonJS.isEmpty(dividerName)) {
  336. this.dividerName = '附件'
  337. } else {
  338. this.dividerName = dividerName
  339. }
  340. if (directory !== undefined && directory !== null && directory !== '' && directory !== {}) {
  341. this.directory = directory
  342. } else {
  343. this.directory = 'public'
  344. }
  345. if (maxValue !== undefined && maxValue !== null && maxValue !== '' && maxValue !== 0) {
  346. this.maxValue = maxValue
  347. } else {
  348. this.maxValue = 300
  349. }
  350. this.auth = auth
  351. if (this.commonJS.isEmpty(uploadFlag)) {
  352. this.uploadFlag = false
  353. } else {
  354. if (uploadFlag !== true && uploadFlag !== false) {
  355. this.uploadFlag = false
  356. } else {
  357. this.uploadFlag = uploadFlag
  358. }
  359. }
  360. if (this.commonJS.isEmpty(delFlag)) {
  361. this.delFlag = false
  362. } else {
  363. if (delFlag !== true && delFlag !== false) {
  364. this.delFlag = false
  365. this.createBy = delFlag
  366. } else {
  367. this.delFlag = delFlag
  368. }
  369. }
  370. if (this.commonJS.isEmpty(fileList)) {
  371. this.fileLoading = true
  372. }
  373. for await (let item of fileList) {
  374. await this.ossService.getFileSizeByUrl(item.url).then((data) => {
  375. item.lsUrl = data.url
  376. item.size = data.size
  377. this.dataList.push(item)
  378. this.dataListNew.push(item)
  379. this.fileList.push(item)
  380. if (this.dataList.length === fileList.length) {
  381. this.fileLoading = true
  382. }
  383. })
  384. }
  385. // this.dataList = JSON.parse(JSON.stringify(fileList))
  386. // this.dataListNew = JSON.parse(JSON.stringify(fileList))
  387. if (this.commonJS.isEmpty(showDivider)) {
  388. this.showDivider = true
  389. } else {
  390. if (showDivider === false) {
  391. this.showDivider = false
  392. } else {
  393. this.showDivider = true
  394. }
  395. }
  396. },
  397. async httpRequest(file) {
  398. await httpRequest(file, fileName(file), this.directory, this.maxValue)
  399. },
  400. uploadVideoProcess(event, file, fileList) {
  401. this.progressFlag = true // 显示进度条
  402. this.loadProgress = parseInt(event.percent) // 动态获取文件上传进度
  403. if (this.loadProgress >= 100) {
  404. this.loadProgress = 100
  405. setTimeout(() => {
  406. this.progressFlag = false
  407. }, 1000) // 一秒后关闭进度条
  408. }
  409. },
  410. getSize(value) {
  411. if (this.commonJS.isEmpty(value)) {
  412. return '0 B'
  413. } else {
  414. let val = parseInt(value)
  415. if (this.commonJS.isEmpty(val)) {
  416. return '0 B'
  417. }
  418. if (isNaN(val)) {
  419. return '0 B'
  420. }
  421. if (val === 0) {
  422. return '0 B'
  423. }
  424. let k = 1024
  425. let sizes = ['B', 'KB', 'MB', 'GB', 'PB', 'TB', 'EB', 'ZB', 'YB']
  426. let i = Math.floor(Math.log(val) / Math.log(k))
  427. return (val / Math.pow(k, i)).toPrecision(3) + '' + sizes[i]
  428. }
  429. },
  430. async changes(file, fileList) {
  431. if (file.status !== 'ready') {
  432. let fileListNamesList = []
  433. for (let fileItem of this.fileList) {
  434. fileListNamesList.push(fileItem.name)
  435. }
  436. if (fileListNamesList.indexOf(file.name) != -1) {
  437. this.$message.error(`${file.name}已存在,无法重复上传`)
  438. return
  439. } else {
  440. if (!beforeAvatarUpload(file, fileList, this.maxValue)) {
  441. this.$message.error('文件大小不能超过 ' + this.maxValue + ' MB!')
  442. return
  443. }
  444. // this.dataListNew = []
  445. // this.dataList.forEach((item) => {
  446. // this.dataListNew.push(item)
  447. // })
  448. var fileListNames = []
  449. for (let fileItem of this.fileList) {
  450. fileListNames.push(fileItem.name)
  451. }
  452. // for (let item of fileList) {
  453. let item1 = JSON.parse(JSON.stringify(file))
  454. // if (fileListNames.length === 0 || fileListNames.indexOf(item1.name) === -1) {
  455. this.fileList.push(item1)
  456. // }
  457. item1.createTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  458. item1.createBy = {
  459. id: '',
  460. name: ''
  461. }
  462. item1.createBy.id = this.$store.state.user.id
  463. item1.createBy.name = this.$store.state.user.name
  464. this.dataListNew.push(item1)
  465. this.dataList.push(item1)
  466. // }
  467. for (let item of this.dataListNew) {
  468. if (item.raw !== undefined && item.raw !== null && item.raw !== {}) {
  469. item.url = item.raw.url
  470. if (item.raw.url !== undefined && item.raw.url !== null && item.raw.url !== {}) {
  471. this.ossService.getTemporaryUrl(item.raw.url).then((data) => {
  472. item.lsUrl = data
  473. })
  474. }
  475. }
  476. }
  477. }
  478. }
  479. },
  480. handleOnDownToOss(row, url) {
  481. this.ossService.getFileSizeByUrl(url).then((data) => {
  482. let file = {
  483. lsUrl: data.url,
  484. size: data.size,
  485. createBy: {
  486. id: this.$store.state.user.id,
  487. name: this.$store.state.user.name,
  488. },
  489. createTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
  490. name: row.fileName,
  491. percentage: 100,
  492. status: "success",
  493. url: url
  494. }
  495. this.dataList.push(file)
  496. this.dataListNew.push(file)
  497. this.fileList.push(file)
  498. })
  499. },
  500. showFile(row) {
  501. openWindowOnUrl(row)
  502. },
  503. onPreview(url) {
  504. this.url = url
  505. this.showViewer = true
  506. },
  507. // 关闭查看器
  508. closeViewer() {
  509. this.url = ''
  510. this.showViewer = false
  511. },
  512. toHref(row) {
  513. toHref(row)
  514. },
  515. async deleteById(row, index, fileList) {
  516. // this.$refs.upload.handleRemove(this.dataListNew[index])
  517. await this.dataListNew.splice(index, 1)
  518. await this.dataList.splice(index, 1)
  519. var newFileList = [];
  520. for (var i = 0; i < fileList.length; i++) {
  521. if (fileList[i].name !== row.name) {
  522. newFileList.push(fileList[i])
  523. }
  524. }
  525. this.fileList = newFileList;
  526. },
  527. /**
  528. * 关闭dialog时使用 清除el-upload中上传的文件
  529. */
  530. clearUpload() {
  531. this.$refs.upload.uploadFiles = []
  532. this.dataList = []
  533. this.dataListNew = []
  534. this.fileList = []
  535. this.createBy = ''
  536. },
  537. /**
  538. * 获取当前文件列表中的文件数据
  539. */
  540. getDataList() {
  541. let _this = this
  542. const waitForEach = function () {
  543. return new Promise(function (resolve, reject) {
  544. _this.dataListNew.forEach((item, index) => {
  545. if (item.btnType === 'save') {
  546. _this.dataListNew[index].fileTypeComponent = 'fileTypeComponentA'
  547. _this.dataListNew[index].sealTypeComponent = 'sealTypeComponentA'
  548. _this.dataListNew[index].remarksComponent = 'remarksComponentA'
  549. _this.dataListNew[index].btn = '修改'
  550. _this.dataListNew[index].btnType = 'edit'
  551. _this.dataListNew[index].fileType = _this.fileType
  552. _this.dataListNew[index].sealType = _this.sealType
  553. _this.dataListNew[index].remarks = _this.remarks
  554. }
  555. })
  556. _this.tableKey = Math.random()
  557. resolve(_this.dataListNew)
  558. })
  559. }
  560. return waitForEach()
  561. },
  562. /**
  563. * 判断进度条是否结束,附件是否加载完成
  564. * @returns {boolean}
  565. */
  566. checkProgress() {
  567. if (this.progressFlag === true) {
  568. this.$message.warning('请等待附件上传完成再进行操作')
  569. return true
  570. }
  571. if (this.fileLoading === false) {
  572. this.$message.warning('请等待附件加载完成再进行操作')
  573. return true
  574. }
  575. return false
  576. },
  577. ifName(row) {
  578. if (this.commonJS.isEmpty(row.name)) {
  579. row.name = '---'
  580. return false
  581. }
  582. let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
  583. if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
  584. return true
  585. } else {
  586. return false
  587. }
  588. },
  589. fileLoadingFalse() {
  590. this.fileLoading = false
  591. },
  592. /** 修改||保存按钮操作 */
  593. handleUpdate: async function (row, rowIndex) {
  594. if (row.btnType === 'edit' || this.commonJS.isEmpty(row.btnType)) {
  595. let _this = this
  596. const waitForEach = function () {
  597. return new Promise(function (resolve, reject) {
  598. _this.dataListNew.forEach((item, index) => {
  599. if (item.btnType === 'save') {
  600. _this.dataListNew[index].fileTypeComponent = 'fileTypeComponentA'
  601. _this.dataListNew[index].sealTypeComponent = 'sealTypeComponentA'
  602. _this.dataListNew[index].remarksComponent = 'remarksComponentA'
  603. _this.dataListNew[index].btn = '修改'
  604. _this.dataListNew[index].btnType = 'edit'
  605. _this.dataListNew[index].fileType = _this.fileType
  606. _this.dataListNew[index].sealType = _this.sealType
  607. _this.dataListNew[index].remarks = _this.remarks
  608. }
  609. })
  610. resolve()
  611. })
  612. }
  613. waitForEach().then(() => {
  614. this.dataListNew[rowIndex].fileTypeComponent = 'fileTypeComponentB'
  615. this.dataListNew[rowIndex].sealTypeComponent = 'sealTypeComponentB'
  616. this.dataListNew[rowIndex].remarksComponent = 'remarksComponentB'
  617. this.dataListNew[rowIndex].btn = '保存'
  618. this.dataListNew[rowIndex].btnType = 'save'
  619. })
  620. } else {
  621. this.dataListNew[rowIndex].fileTypeComponent = 'fileTypeComponentA'
  622. this.dataListNew[rowIndex].sealTypeComponent = 'sealTypeComponentA'
  623. this.dataListNew[rowIndex].remarksComponent = 'remarksComponentA'
  624. this.dataListNew[rowIndex].btn = '修改'
  625. this.dataListNew[rowIndex].btnType = 'edit'
  626. this.dataListNew[rowIndex].fileType = this.fileType
  627. this.dataListNew[rowIndex].sealType = this.sealType
  628. this.dataListNew[rowIndex].remarks = this.remarks
  629. }
  630. this.tableKey = Math.random()
  631. },
  632. updateFileType(fileType) {
  633. this.fileType = fileType
  634. },
  635. updateSealType(sealType) {
  636. this.sealType = sealType
  637. },
  638. updateRemarks(remarks) {
  639. this.remarks = remarks
  640. },
  641. tableRowClassName({ row, rowIndex }) {
  642. row.index = rowIndex
  643. },
  644. // 行点击事件
  645. tableRowClick(row, column) {
  646. if (this.auth !== 'view') {
  647. if (column.label !== '备注' && column.label !== '文件名称' && column.label !== '操作') {
  648. let _this = this
  649. const waitForEach = function () {
  650. return new Promise(function (resolve, reject) {
  651. _this.dataListNew.forEach((item, index) => {
  652. if (item.btnType === 'save') {
  653. _this.dataListNew[index].fileTypeComponent = 'fileTypeComponentA'
  654. _this.dataListNew[index].sealTypeComponent = 'sealTypeComponentA'
  655. _this.dataListNew[index].remarksComponent = 'remarksComponentA'
  656. _this.dataListNew[index].btn = '修改'
  657. _this.dataListNew[index].btnType = 'edit'
  658. _this.dataListNew[index].fileType = _this.fileType
  659. _this.dataListNew[index].sealType = _this.sealType
  660. _this.dataListNew[index].remarks = _this.remarks
  661. }
  662. })
  663. resolve()
  664. })
  665. }
  666. waitForEach().then(() => {
  667. this.fileType = this.dataListNew[row.index].fileType
  668. this.sealType = this.dataListNew[row.index].sealType
  669. this.remarks = this.dataListNew[row.index].remarks
  670. this.dataListNew[row.index].fileTypeComponent = 'fileTypeComponentB'
  671. this.dataListNew[row.index].sealTypeComponent = 'sealTypeComponentB'
  672. this.dataListNew[row.index].remarksComponent = 'remarksComponentB'
  673. this.dataListNew[row.index].btn = '保存'
  674. this.dataListNew[row.index].btnType = 'save'
  675. })
  676. this.tableKey = Math.random()
  677. }
  678. }
  679. },
  680. // 点击上传文件按钮的时候,把未保存的文件保存一下
  681. clickHandel() {
  682. this.dataListNew.forEach((item, index) => {
  683. if (item.btnType === 'save') {
  684. this.dataListNew[index].fileTypeComponent = 'fileTypeComponentA'
  685. this.dataListNew[index].sealTypeComponent = 'sealTypeComponentA'
  686. this.dataListNew[index].remarksComponent = 'remarksComponentA'
  687. this.dataListNew[index].btn = '修改'
  688. this.dataListNew[index].btnType = 'edit'
  689. this.dataListNew[index].fileType = this.fileType
  690. this.dataListNew[index].sealType = this.sealType
  691. this.dataListNew[index].remarks = this.remarks
  692. }
  693. })
  694. },
  695. // 开启/关闭页面的加载中状态
  696. changeLoading(loading) {
  697. if (this.commonJS.isNotEmpty(loading)) {
  698. this.loading = loading
  699. } else {
  700. this.loading = false
  701. }
  702. }
  703. }
  704. }
  705. </script>