cy-element-ui 1.0.57 → 1.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/lib/autocomplete.js +25 -25
  2. package/lib/calendar.js +12 -12
  3. package/lib/carousel-item.js +4 -4
  4. package/lib/carousel.js +4 -4
  5. package/lib/cascader-panel.js +23 -23
  6. package/lib/cascader.js +32 -32
  7. package/lib/checkbox-button.js +4 -4
  8. package/lib/checkbox-group.js +4 -4
  9. package/lib/checkbox.js +4 -4
  10. package/lib/collapse-item.js +8 -8
  11. package/lib/color-picker.js +21 -21
  12. package/lib/date-picker.js +78 -78
  13. package/lib/descriptions.js +2 -2
  14. package/lib/dialog.js +8 -8
  15. package/lib/directives/repeat-click.js +2 -2
  16. package/lib/drawer.js +6 -6
  17. package/lib/dropdown-item.js +4 -4
  18. package/lib/dropdown-menu.js +4 -4
  19. package/lib/dropdown.js +12 -12
  20. package/lib/element-ui.common.js +598 -916
  21. package/lib/empty.js +4 -4
  22. package/lib/fileUpload.js +30 -30
  23. package/lib/form-item.js +8 -8
  24. package/lib/form.js +4 -4
  25. package/lib/image.js +19 -19
  26. package/lib/index.js +1 -1
  27. package/lib/infinite-scroll.js +4 -4
  28. package/lib/input-number.js +15 -15
  29. package/lib/input.js +10 -10
  30. package/lib/loading.js +8 -8
  31. package/lib/locale/format.js +1 -1
  32. package/lib/locale/index.js +1 -1
  33. package/lib/menu-item.js +6 -6
  34. package/lib/menu.js +6 -6
  35. package/lib/message-box.js +20 -20
  36. package/lib/message.js +6 -6
  37. package/lib/mixins/locale.js +1 -1
  38. package/lib/mixins/migrating.js +2 -2
  39. package/lib/notification.js +6 -6
  40. package/lib/option-group.js +4 -4
  41. package/lib/option.js +6 -6
  42. package/lib/page-header.js +4 -4
  43. package/lib/pagination.js +10 -10
  44. package/lib/popconfirm.js +8 -8
  45. package/lib/popover.js +8 -8
  46. package/lib/radio-button.js +4 -4
  47. package/lib/radio-group.js +4 -4
  48. package/lib/radio.js +4 -4
  49. package/lib/rate.js +8 -8
  50. package/lib/scrollbar.js +8 -8
  51. package/lib/select.js +37 -37
  52. package/lib/slider.js +15 -15
  53. package/lib/statistic.js +4 -4
  54. package/lib/steps.js +4 -4
  55. package/lib/submenu.js +6 -6
  56. package/lib/switch.js +8 -8
  57. package/lib/tabDialog.js +6 -6
  58. package/lib/table-column.js +8 -8
  59. package/lib/table.js +41 -41
  60. package/lib/tabs.js +6 -6
  61. package/lib/theme-chalk/alert.css +1 -0
  62. package/lib/theme-chalk/aside.css +1 -0
  63. package/lib/theme-chalk/autocomplete.css +1 -0
  64. package/lib/theme-chalk/avatar.css +1 -0
  65. package/lib/theme-chalk/backtop.css +1 -0
  66. package/lib/theme-chalk/badge.css +1 -0
  67. package/lib/theme-chalk/base.css +1 -1
  68. package/lib/theme-chalk/breadcrumb-item.css +0 -0
  69. package/lib/theme-chalk/breadcrumb.css +1 -0
  70. package/lib/theme-chalk/button-group.css +0 -0
  71. package/lib/theme-chalk/button.css +1 -0
  72. package/lib/theme-chalk/calendar.css +1 -0
  73. package/lib/theme-chalk/card.css +1 -0
  74. package/lib/theme-chalk/carousel-item.css +1 -0
  75. package/lib/theme-chalk/carousel.css +1 -0
  76. package/lib/theme-chalk/cascader-panel.css +1 -0
  77. package/lib/theme-chalk/cascader.css +1 -0
  78. package/lib/theme-chalk/checkbox-button.css +0 -0
  79. package/lib/theme-chalk/checkbox-group.css +0 -0
  80. package/lib/theme-chalk/checkbox.css +1 -0
  81. package/lib/theme-chalk/col.css +1 -0
  82. package/lib/theme-chalk/collapse-item.css +0 -0
  83. package/lib/theme-chalk/collapse.css +1 -0
  84. package/lib/theme-chalk/color-picker.css +1 -0
  85. package/lib/theme-chalk/container.css +1 -0
  86. package/lib/theme-chalk/date-picker.css +1 -0
  87. package/lib/theme-chalk/descriptions-item.css +1 -0
  88. package/lib/theme-chalk/descriptions.css +1 -0
  89. package/lib/theme-chalk/dialog.css +1 -0
  90. package/lib/theme-chalk/display.css +1 -0
  91. package/lib/theme-chalk/divider.css +1 -0
  92. package/lib/theme-chalk/drawer.css +1 -0
  93. package/lib/theme-chalk/dropdown-item.css +0 -0
  94. package/lib/theme-chalk/dropdown-menu.css +0 -0
  95. package/lib/theme-chalk/dropdown.css +1 -0
  96. package/lib/theme-chalk/element.css +1 -1
  97. package/lib/theme-chalk/empty.css +1 -0
  98. package/lib/theme-chalk/fileUpload.css +1 -1
  99. package/lib/theme-chalk/fonts/element-icons.ttf +0 -0
  100. package/lib/theme-chalk/fonts/element-icons.woff +0 -0
  101. package/lib/theme-chalk/footer.css +1 -0
  102. package/lib/theme-chalk/form-item.css +0 -0
  103. package/lib/theme-chalk/form.css +1 -0
  104. package/lib/theme-chalk/header.css +1 -0
  105. package/lib/theme-chalk/icon.css +1 -0
  106. package/lib/theme-chalk/image.css +1 -0
  107. package/lib/theme-chalk/index.css +1 -1
  108. package/lib/theme-chalk/infinite-scroll.css +0 -0
  109. package/lib/theme-chalk/infiniteScroll.css +0 -0
  110. package/lib/theme-chalk/input-number.css +1 -0
  111. package/lib/theme-chalk/input.css +1 -0
  112. package/lib/theme-chalk/link.css +1 -0
  113. package/lib/theme-chalk/loading.css +1 -0
  114. package/lib/theme-chalk/main.css +1 -0
  115. package/lib/theme-chalk/menu-item-group.css +0 -0
  116. package/lib/theme-chalk/menu-item.css +0 -0
  117. package/lib/theme-chalk/menu.css +1 -0
  118. package/lib/theme-chalk/message-box.css +1 -0
  119. package/lib/theme-chalk/message.css +1 -0
  120. package/lib/theme-chalk/notification.css +1 -0
  121. package/lib/theme-chalk/option-group.css +1 -0
  122. package/lib/theme-chalk/option.css +1 -0
  123. package/lib/theme-chalk/page-header.css +1 -0
  124. package/lib/theme-chalk/pagination.css +1 -0
  125. package/lib/theme-chalk/popconfirm.css +1 -0
  126. package/lib/theme-chalk/popover.css +1 -0
  127. package/lib/theme-chalk/popper.css +1 -0
  128. package/lib/theme-chalk/progress.css +1 -0
  129. package/lib/theme-chalk/radio-button.css +1 -0
  130. package/lib/theme-chalk/radio-group.css +1 -0
  131. package/lib/theme-chalk/radio.css +1 -0
  132. package/lib/theme-chalk/rate.css +1 -0
  133. package/lib/theme-chalk/reset.css +1 -0
  134. package/lib/theme-chalk/result.css +1 -0
  135. package/lib/theme-chalk/row.css +1 -0
  136. package/lib/theme-chalk/scrollbar.css +1 -0
  137. package/lib/theme-chalk/select-dropdown.css +1 -0
  138. package/lib/theme-chalk/select.css +1 -0
  139. package/lib/theme-chalk/selectDisplayInput.css +1 -1
  140. package/lib/theme-chalk/skeleton-item.css +1 -0
  141. package/lib/theme-chalk/skeleton.css +1 -0
  142. package/lib/theme-chalk/slider.css +1 -0
  143. package/lib/theme-chalk/spinner.css +1 -0
  144. package/lib/theme-chalk/statistic.css +1 -0
  145. package/lib/theme-chalk/step.css +1 -0
  146. package/lib/theme-chalk/steps.css +1 -0
  147. package/lib/theme-chalk/subTitle.css +1 -1
  148. package/lib/theme-chalk/submenu.css +0 -0
  149. package/lib/theme-chalk/switch.css +1 -0
  150. package/lib/theme-chalk/tab-pane.css +0 -0
  151. package/lib/theme-chalk/tabDialog.css +1 -1
  152. package/lib/theme-chalk/table-column.css +1 -0
  153. package/lib/theme-chalk/table.css +1 -0
  154. package/lib/theme-chalk/tabs.css +1 -0
  155. package/lib/theme-chalk/tag.css +1 -0
  156. package/lib/theme-chalk/time-picker.css +1 -0
  157. package/lib/theme-chalk/time-select.css +1 -0
  158. package/lib/theme-chalk/timeline-item.css +1 -0
  159. package/lib/theme-chalk/timeline.css +1 -0
  160. package/lib/theme-chalk/tooltip.css +1 -0
  161. package/lib/theme-chalk/transfer.css +1 -0
  162. package/lib/theme-chalk/tree.css +1 -0
  163. package/lib/theme-chalk/treeSelect.css +1 -1
  164. package/lib/theme-chalk/upload.css +1 -0
  165. package/lib/time-picker.js +37 -37
  166. package/lib/time-select.js +20 -20
  167. package/lib/tooltip.js +6 -6
  168. package/lib/transfer.js +23 -23
  169. package/lib/transitions/collapse-transition.js +1 -1
  170. package/lib/tree.js +23 -23
  171. package/lib/treeSelect.js +20 -20
  172. package/lib/upload.js +11 -11
  173. package/lib/utils/clickoutside.js +1 -1
  174. package/lib/utils/date-util.js +2 -2
  175. package/lib/utils/popup/index.js +2 -2
  176. package/lib/utils/popup/popup-manager.js +1 -1
  177. package/lib/utils/util.js +1 -1
  178. package/lib/utils/vdom.js +1 -1
  179. package/lib/utils/vue-popper.js +1 -1
  180. package/package.json +2 -2
  181. package/packages/autocomplete/src/autocomplete-suggestions.vue +3 -3
  182. package/packages/autocomplete/src/autocomplete.vue +6 -6
  183. package/packages/calendar/src/date-table.vue +2 -2
  184. package/packages/calendar/src/main.vue +5 -5
  185. package/packages/carousel/src/item.vue +1 -1
  186. package/packages/carousel/src/main.vue +1 -1
  187. package/packages/cascader/src/cascader.vue +15 -15
  188. package/packages/cascader-panel/src/cascader-menu.vue +3 -3
  189. package/packages/cascader-panel/src/cascader-node.vue +3 -3
  190. package/packages/cascader-panel/src/cascader-panel.vue +4 -4
  191. package/packages/cascader-panel/src/node.js +2 -2
  192. package/packages/cascader-panel/src/store.js +1 -1
  193. package/packages/checkbox/src/checkbox-button.vue +1 -1
  194. package/packages/checkbox/src/checkbox-group.vue +1 -1
  195. package/packages/checkbox/src/checkbox.vue +1 -1
  196. package/packages/collapse/src/collapse-item.vue +3 -3
  197. package/packages/color-picker/src/components/picker-dropdown.vue +4 -4
  198. package/packages/color-picker/src/main.vue +2 -2
  199. package/packages/date-picker/src/basic/date-table.vue +3 -3
  200. package/packages/date-picker/src/basic/month-table.vue +4 -4
  201. package/packages/date-picker/src/basic/time-spinner.vue +3 -3
  202. package/packages/date-picker/src/basic/year-table.vue +3 -3
  203. package/packages/date-picker/src/panel/date-range.vue +5 -5
  204. package/packages/date-picker/src/panel/date.vue +5 -5
  205. package/packages/date-picker/src/panel/month-range.vue +5 -5
  206. package/packages/date-picker/src/panel/time-range.vue +2 -2
  207. package/packages/date-picker/src/panel/time-select.vue +2 -2
  208. package/packages/date-picker/src/panel/time.vue +2 -2
  209. package/packages/date-picker/src/picker.vue +6 -6
  210. package/packages/descriptions/src/index.js +1 -1
  211. package/packages/dialog/src/component.vue +3 -3
  212. package/packages/drawer/src/main.vue +2 -2
  213. package/packages/dropdown/src/dropdown-item.vue +1 -1
  214. package/packages/dropdown/src/dropdown-menu.vue +1 -1
  215. package/packages/dropdown/src/dropdown.vue +6 -6
  216. package/packages/empty/src/index.vue +1 -1
  217. package/packages/fileUpload/src/main.vue +430 -430
  218. package/packages/form/src/form-item.vue +3 -3
  219. package/packages/form/src/form.vue +1 -1
  220. package/packages/image/src/image-viewer.vue +3 -3
  221. package/packages/image/src/main.vue +3 -3
  222. package/packages/infinite-scroll/src/main.js +2 -2
  223. package/packages/input/src/input.vue +4 -4
  224. package/packages/input-number/src/input-number.vue +3 -3
  225. package/packages/loading/src/directive.js +3 -3
  226. package/packages/loading/src/index.js +4 -4
  227. package/packages/menu/src/menu-item.vue +2 -2
  228. package/packages/menu/src/menu.vue +4 -4
  229. package/packages/menu/src/submenu.vue +3 -3
  230. package/packages/message/src/main.js +3 -3
  231. package/packages/message-box/src/main.js +2 -2
  232. package/packages/message-box/src/main.vue +7 -7
  233. package/packages/notification/src/main.js +3 -3
  234. package/packages/page-header/src/main.vue +1 -1
  235. package/packages/pagination/src/pagination.js +5 -5
  236. package/packages/popconfirm/src/main.vue +3 -3
  237. package/packages/popover/src/main.vue +4 -4
  238. package/packages/radio/src/radio-button.vue +1 -1
  239. package/packages/radio/src/radio-group.vue +1 -1
  240. package/packages/radio/src/radio.vue +1 -1
  241. package/packages/rate/src/main.vue +3 -3
  242. package/packages/scrollbar/src/bar.js +1 -1
  243. package/packages/scrollbar/src/main.js +3 -3
  244. package/packages/select/src/option-group.vue +1 -1
  245. package/packages/select/src/option.vue +2 -2
  246. package/packages/select/src/select-dropdown.vue +1 -1
  247. package/packages/select/src/select.vue +11 -11
  248. package/packages/selectDisplayInput/src/main.vue +75 -75
  249. package/packages/slider/src/button.vue +1 -1
  250. package/packages/slider/src/main.vue +2 -2
  251. package/packages/statistic/src/main.vue +1 -1
  252. package/packages/steps/src/steps.vue +1 -1
  253. package/packages/switch/src/component.vue +3 -3
  254. package/packages/tabDialog/src/main.vue +277 -277
  255. package/packages/table/src/config.js +1 -1
  256. package/packages/table/src/filter-panel.vue +7 -7
  257. package/packages/table/src/store/current.js +1 -1
  258. package/packages/table/src/store/index.js +1 -1
  259. package/packages/table/src/store/watcher.js +1 -1
  260. package/packages/table/src/table-body.js +4 -4
  261. package/packages/table/src/table-column.js +1 -1
  262. package/packages/table/src/table-header.js +2 -2
  263. package/packages/table/src/table-layout.js +1 -1
  264. package/packages/table/src/table-row.js +1 -1
  265. package/packages/table/src/table.vue +5 -5
  266. package/packages/table/src/util.js +1 -1
  267. package/packages/tabs/src/tab-bar.vue +1 -1
  268. package/packages/tabs/src/tab-nav.vue +1 -1
  269. package/packages/tooltip/src/main.js +3 -3
  270. package/packages/transfer/src/main.vue +4 -4
  271. package/packages/transfer/src/transfer-panel.vue +4 -4
  272. package/packages/tree/src/model/node.js +2 -2
  273. package/packages/tree/src/tree-node.vue +3 -3
  274. package/packages/tree/src/tree.vue +3 -3
  275. package/packages/treeSelect/src/main.vue +325 -325
  276. package/packages/upload/src/index.vue +2 -2
  277. package/packages/upload/src/upload-list.vue +2 -2
  278. package/src/directives/repeat-click.js +2 -2
  279. package/src/index.js +1 -1
  280. package/src/locale/format.js +1 -1
  281. package/src/locale/index.js +1 -1
  282. package/src/mixins/locale.js +1 -1
  283. package/src/mixins/migrating.js +2 -2
  284. package/src/transitions/collapse-transition.js +1 -1
  285. package/src/utils/clickoutside.js +1 -1
  286. package/src/utils/date-util.js +2 -2
  287. package/src/utils/popup/index.js +2 -2
  288. package/src/utils/popup/popup-manager.js +1 -1
  289. package/src/utils/util.js +1 -1
  290. package/src/utils/vdom.js +1 -1
  291. package/src/utils/vue-popper.js +1 -1
@@ -1,430 +1,430 @@
1
- <template>
2
- <div class="cy-file-upload">
3
- <div class="cy-file-upload-btn-box">
4
- <template v-if="showImportTemplate">
5
- <!-- 下载模板按钮 -->
6
- <el-button size="mini" type="success" :size="btnSize" class="cy-file-upload-uploader" style="margin-right: 10px;" @click="importTemplate">下载模板</el-button>
7
- </template>
8
-
9
- <el-upload
10
- v-if="!disabled"
11
- :action="baseUrl + uploadFileUrl"
12
- :before-upload="handleBeforeUpload"
13
- :data="data"
14
- :name="name"
15
- :file-list="fileList"
16
- :limit="limit"
17
- :accept="fileAccept"
18
- :on-error="handleUploadError"
19
- :on-exceed="handleExceed"
20
- :on-success="handleUploadSuccess"
21
- :show-file-list="false"
22
- :headers="headers"
23
- class="cy-file-upload-uploader"
24
- ref="upload"
25
- >
26
- <!-- 上传按钮 -->
27
- <el-button :size="btnSize" :type="btnColor" :loading="downloadLoading" :icon="btnIcon" :plain="btnPlain">{{ btnText }}</el-button>
28
- </el-upload>
29
- </div>
30
-
31
- <!-- 上传提示 -->
32
- <div class="el-upload__tip" slot="tip" v-if="showTip && !onlyBtn && !disabled">
33
- 请上传
34
- <template v-if="fileSize"> 大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b></template>
35
- <template v-if="fileType && !fileType.includes('*')"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b></template>
36
- 的文件
37
- </div>
38
-
39
- <!-- 文件列表 -->
40
- <template v-if="!onlyBtn">
41
- <ul v-if="!isThumbnail" class="cy-file-upload-list el-upload-list el-upload-list--text">
42
- <li v-for="(file, index) in fileList" :key="file.id" class="el-upload-list__item ele-upload-list__item-content">
43
- <el-link class="link_icon" :underline="false" @click.native="downloadAttach(file)">
44
- <span class="el-icon-document"> {{ getFileName(file.file_name) }} </span>
45
- </el-link>
46
- <div class="ele-upload-list__item-content-action flex_shrink">
47
- <el-link v-if="isDownload" :underline="false" @click="downloadAttach(file)" type="primary">下载</el-link>
48
- <el-link v-if="isPreview" :underline="false" @click="previewFile(file)" type="primary">预览</el-link>
49
- <el-link v-if="!disabled" :underline="false" @click="handleDelete(index)" type="danger">删除</el-link>
50
- </div>
51
- </li>
52
- </ul>
53
-
54
- <!-- <FileTypeList-->
55
- <!-- v-else-->
56
- <!-- :list="fileList"-->
57
- <!-- :disabled="disabled"-->
58
- <!-- :isDownload="isDownload"-->
59
- <!-- :isPreview="isPreview"-->
60
- <!-- :imgRatio="imgRatio"-->
61
- <!-- @download="downloadAttach"-->
62
- <!-- @click="previewFile"-->
63
- <!-- @delete="handleDelete"-->
64
- <!-- ></FileTypeList>-->
65
- </template>
66
- </div>
67
- </template>
68
-
69
- <script>
70
- import ElUpload from 'cy-element-ui/packages/upload';
71
- import ElLink from 'cy-element-ui/packages/link';
72
- import ElButton from 'cy-element-ui/packages/button';
73
-
74
- export default {
75
- name: 'CyFileUpload',
76
- component: [
77
- ElUpload,
78
- ElLink,
79
- ElButton,
80
- ],
81
- props: {
82
- // 值
83
- value: {
84
- type: [Array, String],
85
- default: () => [],
86
- },
87
- // 数量限制
88
- limit: {
89
- type: Number,
90
- default: 1000,
91
- },
92
- // 大小限制(MB)
93
- fileSize: {
94
- type: Number,
95
- default: 1000,
96
- },
97
- // 文件类型, ['*']不限制文件类型, 例如['png', 'jpg', 'jpeg']
98
- fileType: {
99
- type: Array,
100
- default: () => ['jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf'],
101
- },
102
- // 是否显示提示
103
- isShowTip: {
104
- type: Boolean,
105
- default: true
106
- },
107
- // 上传的图片服务器地址
108
- uploadFileUrl: {
109
- type: String,
110
- default: '/system/resource_file/upload_file'
111
- },
112
- // 请求参数
113
- data: {
114
- type: Object,
115
- default: () => {
116
- return {}
117
- }
118
- },
119
- // 上传时的文件字段名
120
- name: {
121
- type: String,
122
- default: 'file'
123
- },
124
- disabled: {
125
- type: Boolean,
126
- default: false
127
- },
128
- // 是否显示预览按钮
129
- isPreview: {
130
- type: Boolean,
131
- default: true
132
- },
133
- // 只显示上传按钮
134
- onlyBtn: {
135
- type: Boolean,
136
- default: false
137
- },
138
- // 上传按钮 文字
139
- btnText: {
140
- type: String,
141
- default: '选取文件'
142
- },
143
- // 上传按钮 大小
144
- btnSize: {
145
- type: String,
146
- default: 'mini'
147
- },
148
- // 上传按钮 颜色
149
- btnColor: {
150
- type: String,
151
- default: 'primary'
152
- },
153
- // 上传按钮 图标
154
- btnIcon: {
155
- type: String,
156
- default: ''
157
- },
158
- // 上传按钮 是否为朴素按钮
159
- btnPlain: {
160
- type: Boolean,
161
- default: false
162
- },
163
- // 是否显示上传成功提示
164
- isSuccessMsg: {
165
- type: Boolean,
166
- default: true
167
- },
168
- // 是否显示下载模板按钮
169
- showImportTemplate: {
170
- type: Boolean,
171
- default: false
172
- },
173
- // 下载模板地址
174
- importTemplateName: {
175
- type: String,
176
- default: 'template.xls'
177
- },
178
- // 列表是否以缩略图展示
179
- isThumbnail: {
180
- type: Boolean,
181
- default: false
182
- },
183
- // 图片预览压缩率0-1,仅isThumbnail为true有效
184
- imgRatio: {
185
- type: Number,
186
- default: 1
187
- },
188
- // 是否允许下载
189
- isDownload: {
190
- type: Boolean,
191
- default: true,
192
- },
193
- // 删除前回调, 必须为Promise
194
- deleteBefore: {
195
- type: Function,
196
- },
197
-
198
- // 服务器转发代理规则,匹配请求路径的前缀
199
- baseUrl: {
200
- type: String,
201
- default: ''
202
- },
203
- // 获取token的方法
204
- getToken: {
205
- type: Function,
206
- default: () => {
207
- return ''
208
- }
209
- },
210
- // 下载接口方法,必须返回一个Promise
211
- fileDownLoad: {
212
- type: Function,
213
- default: () => Promise.resolve()
214
- },
215
- // 文件预览方法
216
- getFilePreviewUrl: {
217
- type: Function,
218
- default: () => {
219
- return ''
220
- }
221
- }
222
- },
223
- data() {
224
- return {
225
- fileList: [],
226
- downloadLoading: false,
227
- };
228
- },
229
- watch: {
230
- value: {
231
- handler(val) {
232
- if (val) {
233
- if (typeof val === 'string') {
234
- this.fileList = [{
235
- file_name: this.getFileName(val),
236
- file_path: val,
237
- id: this.createUUID(),
238
- }];
239
- } else {
240
- this.fileList = val.map(item => {
241
- return Object.assign({}, item);
242
- });
243
- }
244
- } else {
245
- this.fileList = [];
246
- return [];
247
- }
248
- },
249
- deep: true,
250
- immediate: true
251
- }
252
- },
253
- computed: {
254
- // 是否显示提示
255
- showTip() {
256
- return this.isShowTip && ((this.fileType && !this.fileType.includes('*')) || this.fileSize);
257
- },
258
- fileAccept() {
259
- let arr = this.fileType.includes('*') ? [] : this.fileType.map(item => '.' + item);
260
- return arr.join()
261
- },
262
- headers() {
263
- return {
264
- Authorization: 'Bearer ' + this.getToken(),
265
- }
266
- }
267
- },
268
- methods: {
269
- /**
270
- * 上传前校检格式和大小
271
- */
272
- handleBeforeUpload(file) {
273
- this.downloadLoading = true;
274
- // 校检文件类型
275
- if (this.fileType && !this.fileType.includes('*')) {
276
- let fileExtension = this.getFileExtension(file.name);
277
- if (!this.fileType.includes(fileExtension)) {
278
- this.$message.error(`文件格式不正确, 请上传${ this.fileType.join('/') }格式文件!`);
279
- this.downloadLoading = false;
280
- return false;
281
- }
282
- }
283
- // 校检文件大小
284
- if (this.fileSize) {
285
- const isLt = file.size / 1024 / 1024 < this.fileSize;
286
- if (!isLt) {
287
- this.$message.error(`上传文件大小不能超过 ${ this.fileSize } MB!`);
288
- this.downloadLoading = false;
289
- return false;
290
- }
291
- }
292
- return true;
293
- },
294
-
295
- /**
296
- * 文件个数超出
297
- */
298
- handleExceed() {
299
- if (this.limit === 1) {
300
- this.$message.error('只能上传单个文件!');
301
- } else {
302
- this.$message.error(`上传文件数量不能超过 ${ this.limit } 个!`);
303
- }
304
- this.downloadLoading = false;
305
- },
306
-
307
- /**
308
- * 上传失败
309
- */
310
- handleUploadError(err) {
311
- this.$message.error('上传失败, 请重试');
312
- this.downloadLoading = false;
313
- },
314
-
315
- /**
316
- * 上传成功回调
317
- */
318
- handleUploadSuccess(res, file) {
319
- if (res.code !== 200) {
320
- this.$message.error(res.msg);
321
- } else {
322
- if (this.isSuccessMsg) this.$message.success('上传成功');
323
- this.fileList.push(res.data);
324
- }
325
- this.downloadLoading = false;
326
- this.$emit('input', this.fileList);
327
- },
328
-
329
- /**
330
- * 删除文件
331
- */
332
- async handleDelete(index) {
333
- if (this.deleteBefore) {
334
- try {
335
- const res = await this.deleteBefore(this.fileList[index], index);
336
- if (!res) return;
337
- } catch (e) {
338
- console.log(e);
339
- return;
340
- }
341
- }
342
- this.fileList.splice(index, 1);
343
- this.$emit('input', this.fileList);
344
- },
345
-
346
- /**
347
- * 获取文件名称
348
- */
349
- getFileName(name) {
350
- if (name.lastIndexOf('/') > -1) {
351
- return name.slice(name.lastIndexOf('/') + 1).toLowerCase();
352
- } else {
353
- return name;
354
- }
355
- },
356
-
357
- /**
358
- * 获取文件类型,后缀
359
- */
360
- getFileExtension(name) {
361
- if (name.lastIndexOf('.') > -1) {
362
- return name.slice(name.lastIndexOf('.') + 1).toLowerCase();
363
- }
364
- return ''
365
- },
366
-
367
- /**
368
- * 查看 预览
369
- */
370
- previewFile(file) {
371
- window.open(this.getFilePreviewUrl(file));
372
- },
373
-
374
- /**
375
- * 附件下载
376
- * */
377
- downloadAttach(file) {
378
- if (!this.isDownload) return;
379
-
380
- let { id, file_name, file_type } = file;
381
- this.downloadLoading = true;
382
- this.fileDownLoad(id).then(res => {
383
- const blob = new Blob([res]);
384
- if ('download' in document.createElement('a')) {
385
- const link = document.createElement('a');
386
- link.download = file_name;
387
- link.style.display = 'none';
388
- link.href = URL.createObjectURL(blob);
389
- document.body.appendChild(link);
390
- link.click();
391
- URL.revokeObjectURL(link.href);
392
- document.body.removeChild(link);
393
- } else {
394
- navigator.msSaveBlob(blob, file_name);
395
- }
396
- this.downloadLoading = false;
397
- })
398
- .catch((err) => {
399
- this.downloadLoading = false;
400
- console.log(err);
401
- this.$message.error('文件下载失败!');
402
- });
403
- },
404
-
405
- /**
406
- * 下载模板操作
407
- */
408
- importTemplate() {
409
- const link = document.createElement('a');
410
- link.style.display = 'none';
411
- link.setAttribute('href', '/static/' + this.importTemplateName);
412
- link.download = this.importTemplateName; // 下载的文件名
413
- document.body.appendChild(link);
414
- link.click();
415
- document.body.removeChild(link);
416
- },
417
-
418
- /**
419
- * 自定义生成UUID
420
- */
421
- createUUID() {
422
- return 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, c => {
423
- let r = Math.random() * 16 | 0;
424
- let v = c === 'x' ? r : (r & 0x3 | 0x8);
425
- return v.toString(16);
426
- })
427
- }
428
- }
429
- }
430
- </script>
1
+ <template>
2
+ <div class="cy-file-upload">
3
+ <div class="cy-file-upload-btn-box">
4
+ <template v-if="showImportTemplate">
5
+ <!-- 下载模板按钮 -->
6
+ <el-button size="mini" type="success" :size="btnSize" class="cy-file-upload-uploader" style="margin-right: 10px;" @click="importTemplate">下载模板</el-button>
7
+ </template>
8
+
9
+ <el-upload
10
+ v-if="!disabled"
11
+ :action="baseUrl + uploadFileUrl"
12
+ :before-upload="handleBeforeUpload"
13
+ :data="data"
14
+ :name="name"
15
+ :file-list="fileList"
16
+ :limit="limit"
17
+ :accept="fileAccept"
18
+ :on-error="handleUploadError"
19
+ :on-exceed="handleExceed"
20
+ :on-success="handleUploadSuccess"
21
+ :show-file-list="false"
22
+ :headers="headers"
23
+ class="cy-file-upload-uploader"
24
+ ref="upload"
25
+ >
26
+ <!-- 上传按钮 -->
27
+ <el-button :size="btnSize" :type="btnColor" :loading="downloadLoading" :icon="btnIcon" :plain="btnPlain">{{ btnText }}</el-button>
28
+ </el-upload>
29
+ </div>
30
+
31
+ <!-- 上传提示 -->
32
+ <div class="el-upload__tip" slot="tip" v-if="showTip && !onlyBtn && !disabled">
33
+ 请上传
34
+ <template v-if="fileSize"> 大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b></template>
35
+ <template v-if="fileType && !fileType.includes('*')"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b></template>
36
+ 的文件
37
+ </div>
38
+
39
+ <!-- 文件列表 -->
40
+ <template v-if="!onlyBtn">
41
+ <ul v-if="!isThumbnail" class="cy-file-upload-list el-upload-list el-upload-list--text">
42
+ <li v-for="(file, index) in fileList" :key="file.id" class="el-upload-list__item ele-upload-list__item-content">
43
+ <el-link class="link_icon" :underline="false" @click.native="downloadAttach(file)">
44
+ <span class="el-icon-document"> {{ getFileName(file.file_name) }} </span>
45
+ </el-link>
46
+ <div class="ele-upload-list__item-content-action flex_shrink">
47
+ <el-link v-if="isDownload" :underline="false" @click="downloadAttach(file)" type="primary">下载</el-link>
48
+ <el-link v-if="isPreview" :underline="false" @click="previewFile(file)" type="primary">预览</el-link>
49
+ <el-link v-if="!disabled" :underline="false" @click="handleDelete(index)" type="danger">删除</el-link>
50
+ </div>
51
+ </li>
52
+ </ul>
53
+
54
+ <!-- <FileTypeList-->
55
+ <!-- v-else-->
56
+ <!-- :list="fileList"-->
57
+ <!-- :disabled="disabled"-->
58
+ <!-- :isDownload="isDownload"-->
59
+ <!-- :isPreview="isPreview"-->
60
+ <!-- :imgRatio="imgRatio"-->
61
+ <!-- @download="downloadAttach"-->
62
+ <!-- @click="previewFile"-->
63
+ <!-- @delete="handleDelete"-->
64
+ <!-- ></FileTypeList>-->
65
+ </template>
66
+ </div>
67
+ </template>
68
+
69
+ <script>
70
+ import ElUpload from 'element-ui/packages/upload';
71
+ import ElLink from 'element-ui/packages/link';
72
+ import ElButton from 'element-ui/packages/button';
73
+
74
+ export default {
75
+ name: 'CyFileUpload',
76
+ component: [
77
+ ElUpload,
78
+ ElLink,
79
+ ElButton,
80
+ ],
81
+ props: {
82
+ // 值
83
+ value: {
84
+ type: [Array, String],
85
+ default: () => [],
86
+ },
87
+ // 数量限制
88
+ limit: {
89
+ type: Number,
90
+ default: 1000,
91
+ },
92
+ // 大小限制(MB)
93
+ fileSize: {
94
+ type: Number,
95
+ default: 1000,
96
+ },
97
+ // 文件类型, ['*']不限制文件类型, 例如['png', 'jpg', 'jpeg']
98
+ fileType: {
99
+ type: Array,
100
+ default: () => ['jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf'],
101
+ },
102
+ // 是否显示提示
103
+ isShowTip: {
104
+ type: Boolean,
105
+ default: true
106
+ },
107
+ // 上传的图片服务器地址
108
+ uploadFileUrl: {
109
+ type: String,
110
+ default: '/system/resource_file/upload_file'
111
+ },
112
+ // 请求参数
113
+ data: {
114
+ type: Object,
115
+ default: () => {
116
+ return {}
117
+ }
118
+ },
119
+ // 上传时的文件字段名
120
+ name: {
121
+ type: String,
122
+ default: 'file'
123
+ },
124
+ disabled: {
125
+ type: Boolean,
126
+ default: false
127
+ },
128
+ // 是否显示预览按钮
129
+ isPreview: {
130
+ type: Boolean,
131
+ default: true
132
+ },
133
+ // 只显示上传按钮
134
+ onlyBtn: {
135
+ type: Boolean,
136
+ default: false
137
+ },
138
+ // 上传按钮 文字
139
+ btnText: {
140
+ type: String,
141
+ default: '选取文件'
142
+ },
143
+ // 上传按钮 大小
144
+ btnSize: {
145
+ type: String,
146
+ default: 'mini'
147
+ },
148
+ // 上传按钮 颜色
149
+ btnColor: {
150
+ type: String,
151
+ default: 'primary'
152
+ },
153
+ // 上传按钮 图标
154
+ btnIcon: {
155
+ type: String,
156
+ default: ''
157
+ },
158
+ // 上传按钮 是否为朴素按钮
159
+ btnPlain: {
160
+ type: Boolean,
161
+ default: false
162
+ },
163
+ // 是否显示上传成功提示
164
+ isSuccessMsg: {
165
+ type: Boolean,
166
+ default: true
167
+ },
168
+ // 是否显示下载模板按钮
169
+ showImportTemplate: {
170
+ type: Boolean,
171
+ default: false
172
+ },
173
+ // 下载模板地址
174
+ importTemplateName: {
175
+ type: String,
176
+ default: 'template.xls'
177
+ },
178
+ // 列表是否以缩略图展示
179
+ isThumbnail: {
180
+ type: Boolean,
181
+ default: false
182
+ },
183
+ // 图片预览压缩率0-1,仅isThumbnail为true有效
184
+ imgRatio: {
185
+ type: Number,
186
+ default: 1
187
+ },
188
+ // 是否允许下载
189
+ isDownload: {
190
+ type: Boolean,
191
+ default: true,
192
+ },
193
+ // 删除前回调, 必须为Promise
194
+ deleteBefore: {
195
+ type: Function,
196
+ },
197
+
198
+ // 服务器转发代理规则,匹配请求路径的前缀
199
+ baseUrl: {
200
+ type: String,
201
+ default: ''
202
+ },
203
+ // 获取token的方法
204
+ getToken: {
205
+ type: Function,
206
+ default: () => {
207
+ return ''
208
+ }
209
+ },
210
+ // 下载接口方法,必须返回一个Promise
211
+ fileDownLoad: {
212
+ type: Function,
213
+ default: () => Promise.resolve()
214
+ },
215
+ // 文件预览方法
216
+ getFilePreviewUrl: {
217
+ type: Function,
218
+ default: () => {
219
+ return ''
220
+ }
221
+ }
222
+ },
223
+ data() {
224
+ return {
225
+ fileList: [],
226
+ downloadLoading: false,
227
+ };
228
+ },
229
+ watch: {
230
+ value: {
231
+ handler(val) {
232
+ if (val) {
233
+ if (typeof val === 'string') {
234
+ this.fileList = [{
235
+ file_name: this.getFileName(val),
236
+ file_path: val,
237
+ id: this.createUUID(),
238
+ }];
239
+ } else {
240
+ this.fileList = val.map(item => {
241
+ return Object.assign({}, item);
242
+ });
243
+ }
244
+ } else {
245
+ this.fileList = [];
246
+ return [];
247
+ }
248
+ },
249
+ deep: true,
250
+ immediate: true
251
+ }
252
+ },
253
+ computed: {
254
+ // 是否显示提示
255
+ showTip() {
256
+ return this.isShowTip && ((this.fileType && !this.fileType.includes('*')) || this.fileSize);
257
+ },
258
+ fileAccept() {
259
+ let arr = this.fileType.includes('*') ? [] : this.fileType.map(item => '.' + item);
260
+ return arr.join()
261
+ },
262
+ headers() {
263
+ return {
264
+ Authorization: 'Bearer ' + this.getToken(),
265
+ }
266
+ }
267
+ },
268
+ methods: {
269
+ /**
270
+ * 上传前校检格式和大小
271
+ */
272
+ handleBeforeUpload(file) {
273
+ this.downloadLoading = true;
274
+ // 校检文件类型
275
+ if (this.fileType && !this.fileType.includes('*')) {
276
+ let fileExtension = this.getFileExtension(file.name);
277
+ if (!this.fileType.includes(fileExtension)) {
278
+ this.$message.error(`文件格式不正确, 请上传${ this.fileType.join('/') }格式文件!`);
279
+ this.downloadLoading = false;
280
+ return false;
281
+ }
282
+ }
283
+ // 校检文件大小
284
+ if (this.fileSize) {
285
+ const isLt = file.size / 1024 / 1024 < this.fileSize;
286
+ if (!isLt) {
287
+ this.$message.error(`上传文件大小不能超过 ${ this.fileSize } MB!`);
288
+ this.downloadLoading = false;
289
+ return false;
290
+ }
291
+ }
292
+ return true;
293
+ },
294
+
295
+ /**
296
+ * 文件个数超出
297
+ */
298
+ handleExceed() {
299
+ if (this.limit === 1) {
300
+ this.$message.error('只能上传单个文件!');
301
+ } else {
302
+ this.$message.error(`上传文件数量不能超过 ${ this.limit } 个!`);
303
+ }
304
+ this.downloadLoading = false;
305
+ },
306
+
307
+ /**
308
+ * 上传失败
309
+ */
310
+ handleUploadError(err) {
311
+ this.$message.error('上传失败, 请重试');
312
+ this.downloadLoading = false;
313
+ },
314
+
315
+ /**
316
+ * 上传成功回调
317
+ */
318
+ handleUploadSuccess(res, file) {
319
+ if (res.code !== 200) {
320
+ this.$message.error(res.msg);
321
+ } else {
322
+ if (this.isSuccessMsg) this.$message.success('上传成功');
323
+ this.fileList.push(res.data);
324
+ }
325
+ this.downloadLoading = false;
326
+ this.$emit('input', this.fileList);
327
+ },
328
+
329
+ /**
330
+ * 删除文件
331
+ */
332
+ async handleDelete(index) {
333
+ if (this.deleteBefore) {
334
+ try {
335
+ const res = await this.deleteBefore(this.fileList[index], index);
336
+ if (!res) return;
337
+ } catch (e) {
338
+ console.log(e);
339
+ return;
340
+ }
341
+ }
342
+ this.fileList.splice(index, 1);
343
+ this.$emit('input', this.fileList);
344
+ },
345
+
346
+ /**
347
+ * 获取文件名称
348
+ */
349
+ getFileName(name) {
350
+ if (name.lastIndexOf('/') > -1) {
351
+ return name.slice(name.lastIndexOf('/') + 1).toLowerCase();
352
+ } else {
353
+ return name;
354
+ }
355
+ },
356
+
357
+ /**
358
+ * 获取文件类型,后缀
359
+ */
360
+ getFileExtension(name) {
361
+ if (name.lastIndexOf('.') > -1) {
362
+ return name.slice(name.lastIndexOf('.') + 1).toLowerCase();
363
+ }
364
+ return ''
365
+ },
366
+
367
+ /**
368
+ * 查看 预览
369
+ */
370
+ previewFile(file) {
371
+ window.open(this.getFilePreviewUrl(file));
372
+ },
373
+
374
+ /**
375
+ * 附件下载
376
+ * */
377
+ downloadAttach(file) {
378
+ if (!this.isDownload) return;
379
+
380
+ let { id, file_name, file_type } = file;
381
+ this.downloadLoading = true;
382
+ this.fileDownLoad(id).then(res => {
383
+ const blob = new Blob([res]);
384
+ if ('download' in document.createElement('a')) {
385
+ const link = document.createElement('a');
386
+ link.download = file_name;
387
+ link.style.display = 'none';
388
+ link.href = URL.createObjectURL(blob);
389
+ document.body.appendChild(link);
390
+ link.click();
391
+ URL.revokeObjectURL(link.href);
392
+ document.body.removeChild(link);
393
+ } else {
394
+ navigator.msSaveBlob(blob, file_name);
395
+ }
396
+ this.downloadLoading = false;
397
+ })
398
+ .catch((err) => {
399
+ this.downloadLoading = false;
400
+ console.log(err);
401
+ this.$message.error('文件下载失败!');
402
+ });
403
+ },
404
+
405
+ /**
406
+ * 下载模板操作
407
+ */
408
+ importTemplate() {
409
+ const link = document.createElement('a');
410
+ link.style.display = 'none';
411
+ link.setAttribute('href', '/static/' + this.importTemplateName);
412
+ link.download = this.importTemplateName; // 下载的文件名
413
+ document.body.appendChild(link);
414
+ link.click();
415
+ document.body.removeChild(link);
416
+ },
417
+
418
+ /**
419
+ * 自定义生成UUID
420
+ */
421
+ createUUID() {
422
+ return 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, c => {
423
+ let r = Math.random() * 16 | 0;
424
+ let v = c === 'x' ? r : (r & 0x3 | 0x8);
425
+ return v.toString(16);
426
+ })
427
+ }
428
+ }
429
+ }
430
+ </script>