a8ca9e0f8c965db456e60e6933397b4ca9c6ea79.svn-base 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div>
  3. <template v-if="hasFile" v-for="(file, fileKey) of [innerFile || {}]">
  4. <div :key="fileKey" style="position: relative;">
  5. <a-tooltip v-if="file.status==='uploading'" :title="`上传中(${Math.floor(file.percent)}%)`">
  6. <a-icon type="loading"/>
  7. <span style="margin-left:5px">上传中…</span>
  8. </a-tooltip>
  9. <a-tooltip v-else-if="file.status==='done'" :title="file.name">
  10. <a-icon type="paper-clip"/>
  11. <span style="margin-left:5px">{{ ellipsisFileName }}</span>
  12. </a-tooltip>
  13. <a-tooltip v-else :title="file.message||'上传失败'">
  14. <a-icon type="exclamation-circle" style="color:red;"/>
  15. <span style="margin-left:5px">{{ ellipsisFileName }}</span>
  16. </a-tooltip>
  17. <template style="width: 30px">
  18. <a-dropdown :trigger="['click']" placement="bottomRight" style="margin-left: 10px;">
  19. <a-tooltip title="操作">
  20. <a-icon
  21. v-if="file.status!=='uploading'"
  22. type="setting"
  23. style="cursor: pointer;"/>
  24. </a-tooltip>
  25. <a-menu slot="overlay">
  26. <a-menu-item v-if="originColumn.allowDownload !== false" @click="handleClickDownloadFile">
  27. <span><a-icon type="download"/>&nbsp;下载</span>
  28. </a-menu-item>
  29. <a-menu-item v-if="originColumn.allowRemove !== false" @click="handleClickDeleteFile">
  30. <span><a-icon type="delete"/>&nbsp;删除</span>
  31. </a-menu-item>
  32. <a-menu-item @click="handleMoreOperation(originColumn)">
  33. <span><a-icon type="bars"/> 更多</span>
  34. </a-menu-item>
  35. </a-menu>
  36. </a-dropdown>
  37. </template>
  38. </div>
  39. </template>
  40. <a-upload
  41. v-show="!hasFile"
  42. name="file"
  43. :data="{'isup': 1}"
  44. :multiple="false"
  45. :action="uploadAction"
  46. :headers="uploadHeaders"
  47. :showUploadList="false"
  48. v-bind="cellProps"
  49. @change="handleChangeUpload"
  50. >
  51. <a-button icon="upload">{{originColumn.btnText || '上传文件'}}</a-button>
  52. </a-upload>
  53. <j-file-pop ref="filePop" @ok="handleFileSuccess" :number="number"/>
  54. </div>
  55. </template>
  56. <script>
  57. import { getFileAccessHttpUrl } from '@api/manage'
  58. import JVxeCellMixins from '@/components/jeecg/JVxeTable/mixins/JVxeCellMixins'
  59. import { ACCESS_TOKEN } from '@/store/mutation-types'
  60. import JFilePop from '@/components/jeecg/minipop/JFilePop'
  61. import JVxeUploadCell from '@/components/jeecg/JVxeTable/components/cells/JVxeUploadCell'
  62. export default {
  63. name: 'JVxeFileCell',
  64. mixins: [JVxeCellMixins],
  65. components: {JFilePop},
  66. props: {},
  67. data() {
  68. return {
  69. innerFile: null,
  70. number:0,
  71. }
  72. },
  73. computed: {
  74. /** upload headers */
  75. uploadHeaders() {
  76. let {originColumn: col} = this
  77. let headers = {}
  78. if (col.token === true) {
  79. headers['X-Access-Token'] = this.$ls.get(ACCESS_TOKEN)
  80. }
  81. return headers
  82. },
  83. /** 上传请求地址 */
  84. uploadAction() {
  85. if (!this.originColumn.action) {
  86. return window._CONFIG['domianURL'] + '/sys/common/upload'
  87. } else {
  88. return this.originColumn.action
  89. }
  90. },
  91. hasFile() {
  92. return this.innerFile != null
  93. },
  94. ellipsisFileName() {
  95. let length = 5
  96. let file = this.innerFile
  97. if (!file || !file.name) {
  98. return ''
  99. }
  100. if (file.name.length > length) {
  101. return file.name.substr(0, length) + '…'
  102. }
  103. return file.name
  104. },
  105. responseName() {
  106. if (this.originColumn.responseName) {
  107. return this.originColumn.responseName
  108. } else {
  109. return 'message'
  110. }
  111. },
  112. },
  113. watch: {
  114. innerValue: {
  115. immediate: true,
  116. handler() {
  117. if (this.innerValue) {
  118. this.innerFile = this.innerValue
  119. } else {
  120. this.innerFile = null
  121. }
  122. },
  123. },
  124. },
  125. methods: {
  126. // 点击更多按钮
  127. handleMoreOperation(originColumn) {
  128. //update-begin-author:wangshuai date:20201021 for:LOWCOD-969 判断传过来的字段是否存在number,用于控制上传文件
  129. if (originColumn.number) {
  130. this.number = originColumn.number
  131. } else {
  132. this.number = 0
  133. }
  134. //update-end-author:wangshuai date:20201021 for:LOWCOD-969 判断传过来的字段是否存在number,用于控制上传文件
  135. if(originColumn && originColumn.fieldExtendJson){
  136. let json = JSON.parse(originColumn.fieldExtendJson);
  137. this.number = json.uploadnum?json.uploadnum:0;
  138. }
  139. let path = ''
  140. if (this.innerFile) {
  141. path = this.innerFile.path
  142. }
  143. this.$refs.filePop.show('', path)
  144. },
  145. // 更多上传回调
  146. handleFileSuccess(file) {
  147. if (file) {
  148. this.innerFile.path = file.path
  149. this.handleChangeCommon(this.innerFile)
  150. }
  151. },
  152. handleChangeUpload(info) {
  153. let {originColumn: col} = this
  154. let {file} = info
  155. let value = {
  156. name: file.name,
  157. type: file.type,
  158. size: file.size,
  159. status: file.status,
  160. percent: file.percent
  161. }
  162. if (file.response) {
  163. value['responseName'] = file.response[this.responseName]
  164. }
  165. if (file.status === 'done') {
  166. if (typeof file.response.success === 'boolean') {
  167. if (file.response.success) {
  168. value['path'] = file.response[this.responseName]
  169. this.handleChangeCommon(value)
  170. } else {
  171. value['status'] = 'error'
  172. value['message'] = file.response.message || '未知错误'
  173. }
  174. } else {
  175. // 考虑到如果设置action上传路径为非jeecg-boot后台,可能不会返回 success 属性的情况,就默认为成功
  176. value['path'] = file.response[this.responseName]
  177. this.handleChangeCommon(value)
  178. }
  179. } else if (file.status === 'error') {
  180. value['message'] = file.response.message || '未知错误'
  181. }
  182. this.innerFile = value
  183. },
  184. handleClickDownloadFile() {
  185. let {url, path} = this.innerFile || {}
  186. if (!url || url.length === 0) {
  187. if (path && path.length > 0) {
  188. url = getFileAccessHttpUrl(path.split(',')[0])
  189. }
  190. }
  191. if (url) {
  192. window.open(url)
  193. }
  194. },
  195. handleClickDeleteFile() {
  196. this.handleChangeCommon(null)
  197. },
  198. },
  199. // 【组件增强】注释详见:JVxeCellMixins.js
  200. enhanced: {
  201. switches: {visible: true},
  202. getValue: value => JVxeUploadCell.enhanced.getValue(value),
  203. setValue: value => JVxeUploadCell.enhanced.setValue(value),
  204. }
  205. }
  206. </script>
  207. <style scoped lang="less">
  208. </style>