index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <div class="myUpload">
  3. <div class="myUpload1">
  4. <div class="myDemo">
  5. <el-upload
  6. class="upload-demo"
  7. action="#"
  8. :auto-upload="false"
  9. :drag="drag"
  10. :multiple="multiple"
  11. :data="data"
  12. :name="name"
  13. :show-file-list="false"
  14. :accept="accept"
  15. :list-type="listType"
  16. :disabled="disabled"
  17. :limit="limit"
  18. :on-preview="onPreview"
  19. :on-remove="onRemove"
  20. :on-success="onSuccess"
  21. :on-error="onError"
  22. :on-progress="onProgress"
  23. :on-change="onChange"
  24. :on-exceed="onExceed"
  25. style="width: 100%"
  26. >
  27. <i class="el-icon-upload"></i>
  28. <div class="el-upload__text">
  29. <div>将文件拖到此处,或<em>点击上传</em></div>
  30. <div v-if="accept"><span>只能上传{{ accept }}文件</span></div>
  31. </div>
  32. </el-upload>
  33. </div>
  34. <div class="line" v-if="fileList.length > 0"></div>
  35. <div class="fileList" v-if="fileList.length > 0">
  36. <ul>
  37. <li v-for="item in fileList" :key="item.guid">
  38. <div>
  39. <i class="el-icon-document" style="margin-right: 10px"></i
  40. ><span class="name" @click="checkFiles(item)">{{
  41. item.name ? item.name : item.originalName
  42. }}</span>
  43. </div>
  44. <div class="type">{{ item.guid ? "已上传" : "待上传" }}</div>
  45. <div class="icon" @click="onRemove(item, fileList)">
  46. <i class="el-icon-close"></i>
  47. </div>
  48. </li>
  49. </ul>
  50. </div>
  51. </div>
  52. <el-dialog
  53. custom-class="myUpload_dialog"
  54. :visible.sync="dialogVisible"
  55. width="500px"
  56. :before-close="handleClose"
  57. :append-to-body="true">
  58. <div slot="title">提示信息<span class="title" ><i class="el-icon-warning"></i></span></div>
  59. <div>
  60. <div v-if="discontent.length>0">
  61. <div class="content">
  62. <div>
  63. <i class="el-icon-error red"></i>
  64. </div>
  65. <div @click="showDiscontent = !showDiscontent">
  66. <i class="el-icon-caret-right" v-if="!showDiscontent"></i>
  67. <i class="el-icon-caret-bottom" v-else></i>
  68. </div>
  69. <div>
  70. 上传文件格式不正确
  71. </div>
  72. </div>
  73. <div v-if="showDiscontent" class="list showList">
  74. <div v-for="(item,index) in discontent" :key="item.name">{{ item.name }}<span v-if="index != discontent.length-1">,</span></div>
  75. </div>
  76. </div>
  77. <div v-if="exist.length>0">
  78. <div class="content">
  79. <div>
  80. <i class="el-icon-error red"></i>
  81. </div>
  82. <div @click="showExist = !showExist">
  83. <i class="el-icon-caret-right" v-if="!showExist"></i>
  84. <i class="el-icon-caret-bottom" v-else></i>
  85. </div>
  86. <div>
  87. 上传文件名称重复
  88. </div>
  89. </div>
  90. <div v-if="showExist" class="showList">
  91. <div class="list">{{ exist.map((item) => { return item.name;}).join(',') }}</div>
  92. <div class="menu">
  93. <div @click="choose(1)">
  94. <i class="el-icon-check"></i>
  95. <span>替换目标中的文件</span>
  96. </div>
  97. <div @click="choose(2)">
  98. <i class="iconfont icon--skip"></i>
  99. <span>跳过这些文件</span>
  100. </div>
  101. <!-- <div @click="choose(3)">
  102. <i class="iconfont icon-wenbentihuan"></i>
  103. <span>让我决定每个文件</span>
  104. </div> -->
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. <div slot="footer">
  110. <el-button type="primary" size="small" @click="handleClose" >我知道了</el-button>
  111. </div>
  112. </el-dialog>
  113. </div>
  114. </template>
  115. <script>
  116. export default {
  117. components: {},
  118. props: {
  119. //上传的接口或地址
  120. action: {
  121. type: String,
  122. default: "",
  123. },
  124. multiple: {
  125. type: Boolean,
  126. },
  127. data: {
  128. type: Object,
  129. },
  130. name: {
  131. type: String,
  132. default: "",
  133. },
  134. showFileList: {
  135. type: Boolean,
  136. },
  137. drag: {
  138. type: Boolean,
  139. default: true,
  140. },
  141. accept: {
  142. type: String,
  143. default: "",
  144. },
  145. listType: {
  146. type: String,
  147. default: "text",
  148. },
  149. //是否立即上传
  150. autoUpload: {
  151. type: Boolean,
  152. default: false,
  153. },
  154. //文件列表
  155. fileList: {
  156. type: Array,
  157. default: () => {
  158. return [];
  159. },
  160. },
  161. disabled: {
  162. type: Boolean,
  163. default: false,
  164. },
  165. limit: {
  166. type: Number,
  167. },
  168. },
  169. data() {
  170. return {
  171. discontent: [],
  172. showDiscontent:false,
  173. exist:[],
  174. exist2:[],
  175. showExist:false,
  176. dialogVisible:false,
  177. };
  178. },
  179. watch: {},
  180. computed: {},
  181. created() {},
  182. mounted() {},
  183. methods: {
  184. onPreview(file) {
  185. this.$emit("on-preview", file);
  186. },
  187. onRemove(file, fileList) {
  188. this.$emit("on-remove", file, fileList);
  189. },
  190. onSuccess(response, file, fileList) {
  191. this.$emit("on-success", response, file, fileList);
  192. },
  193. onError(err, file, fileList) {
  194. this.$emit("on-error", err, file, fileList);
  195. },
  196. onProgress(event, file, fileList) {
  197. this.$emit("on-progress", event, file, fileList);
  198. },
  199. onChange(file, fileList) {
  200. this.$nextTick(() => {
  201. if(this.discontent.length>0 || this.exist.length>0){
  202. this.open()
  203. }
  204. });
  205. //审核上传文件类型
  206. if (this.accept) {
  207. var arr = this.accept.split(/,|,/g);
  208. var fileType = file.name.substring(file.name.lastIndexOf("."));
  209. var index = arr.findIndex((item) => {
  210. return item == fileType;
  211. });
  212. if (index == -1) {
  213. this.discontent.push(file);
  214. return false;
  215. }
  216. }
  217. //验证是否有重复文件
  218. if(this.fileList.length>0){
  219. var index = this.fileList.findIndex(item =>{
  220. return item.name == file.name || item.originalName == file.name
  221. })
  222. if(index != -1){
  223. this.exist.push(file)
  224. this.exist2.push(this.fileList[index])
  225. return false
  226. }
  227. }
  228. this.$emit("on-change", file);
  229. //是否立即上传
  230. if (this.autoUpload) {
  231. this.uploadFile(file)
  232. return false
  233. }
  234. },
  235. onExceed(file, fileList) {
  236. this.$emit("on-exceed", file, fileList);
  237. },
  238. //查看文件
  239. checkFiles(file) {
  240. if(file.guid){
  241. }else{
  242. }
  243. },
  244. //上传附件
  245. uploadFile(file){
  246. let formData = new FormData()
  247. formData.append('sourceId',this.$constants.sourceId)
  248. formData.append('files',file.raw)
  249. this.$api.uploadFile(formData).then(response=>{
  250. if(response.code == 200){
  251. file.guid = response.data[0]
  252. file.raw.guid = response.data[0]
  253. this.$emit("on-change", file)
  254. }
  255. })
  256. },
  257. //打开提示弹窗
  258. open(){
  259. this.dialogVisible = true
  260. },
  261. //关闭弹窗
  262. handleClose(){
  263. this.dialogVisible = false
  264. this.discontent = []
  265. this.exist = []
  266. this.exist2=[]
  267. this.showDiscontent=false
  268. this.showExist = false
  269. },
  270. //操作
  271. choose(type){
  272. switch(type){
  273. case 1:
  274. this.exist2.forEach((item,index)=>{
  275. this.onRemove(item,this.fileList)
  276. this.$emit("on-change", this.exist[index]);
  277. this.uploadFile(this.exist[index])
  278. })
  279. this.handleClose()
  280. break;
  281. case 2:
  282. this.handleClose()
  283. break;
  284. case 3:
  285. break;
  286. }
  287. },
  288. },
  289. };
  290. </script>
  291. <style lang="scss">
  292. .myUpload1 {
  293. .el-upload {
  294. width: 100%;
  295. height: 100%;
  296. .el-upload-dragger {
  297. width: 100% !important;
  298. height: 100%;
  299. border: none;
  300. border-radius: 0px;
  301. }
  302. .el-upload-dragger:hover {
  303. border: none;
  304. }
  305. }
  306. .el-upload-list {
  307. display: none;
  308. }
  309. }
  310. .myUpload_dialog{
  311. border: 2px solid var(--bg);
  312. box-shadow: none;
  313. --fs:15px;
  314. i{
  315. cursor: pointer;
  316. }
  317. .el-dialog__close{
  318. color: black;
  319. font-weight: bold;
  320. }
  321. .el-dialog__headerbtn{
  322. top: 14px;
  323. }
  324. .el-dialog__header{
  325. border-bottom: 2px solid var(--bg) !important;
  326. color: red;
  327. padding: 10px;
  328. }
  329. .el-dialog__body{
  330. padding: 20px 10px;
  331. }
  332. .el-dialog__footer{
  333. border-top:none !important;
  334. }
  335. .title{
  336. margin-left: 10px;
  337. }
  338. .content{
  339. display: flex;
  340. align-items: center;
  341. padding: 5px 0px;
  342. color: var(--bg);
  343. font-size: var(--fs);
  344. font-family: var(--fm);
  345. font-weight: bold;
  346. }
  347. .red{
  348. color: red;
  349. }
  350. .showList{
  351. padding-left:var(--fs) ;
  352. }
  353. .list{
  354. padding-top: 5px;
  355. padding-bottom: 5px;
  356. font-size: 14px;
  357. display: flex;
  358. flex-wrap: wrap;
  359. // overflow: hidden;
  360. // white-space: nowrap;
  361. // text-overflow:ellipsis;
  362. }
  363. .menu{
  364. font-size: 14px;
  365. i{
  366. font-size: 14px;
  367. }
  368. div{
  369. font-family: var(--fm);
  370. padding: 5px 0;
  371. cursor: pointer;
  372. color: var(--bg);
  373. i{
  374. color: blue;
  375. }
  376. span{
  377. margin-left:10px
  378. }
  379. }
  380. div:hover{
  381. background: #85afd9;
  382. }
  383. }
  384. }
  385. </style>
  386. <style lang="scss" scoped>
  387. .myUpload {
  388. width: calc(100% - 0px);
  389. height: 180px;
  390. padding: 5px;
  391. }
  392. .myUpload1 {
  393. width: calc(100% - 20px);
  394. height: 100%;
  395. padding: 5px;
  396. display: flex;
  397. align-items: center;
  398. background: white;
  399. border: 1px dashed var(--bg);
  400. border-radius: 10px;
  401. .myDemo {
  402. width: 100%;
  403. height: 100%;
  404. flex: 1;
  405. }
  406. .line {
  407. width: 1px;
  408. height: 100%;
  409. background: var(--bg);
  410. }
  411. .fileList {
  412. width: 100%;
  413. height: 100%;
  414. overflow-y: auto;
  415. flex: 2;
  416. ul {
  417. list-style-type: none;
  418. padding: 0 10px;
  419. li {
  420. line-height: initial;
  421. padding: 5px 10px;
  422. border-radius: 5px;
  423. display: flex;
  424. justify-content: space-between;
  425. .type {
  426. display: block;
  427. color: #57a5f7;
  428. }
  429. .icon {
  430. display: none;
  431. }
  432. }
  433. li:hover {
  434. background: #f4f4f4;
  435. .name {
  436. color: #57a5f7;
  437. cursor: pointer;
  438. }
  439. .type {
  440. display: none;
  441. }
  442. .icon {
  443. display: block;
  444. cursor: pointer;
  445. }
  446. }
  447. }
  448. }
  449. }
  450. </style>