6bbd7f3e48f27470fabd3f1fd69e6c7cdc2c4663.svn-base 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <!--
  2. <upload ref="uploadFile" url="/biz/hzz/basic/file/upload?bizId=" @uploadOver="uploadOver"></upload>
  3. if (this.$refs.uploadFile.submitUpload(id)) {
  4. // true上传列表为空,直接执行结束操作
  5. this.insertOver()
  6. }
  7. -->
  8. <template>
  9. <div>
  10. <div style="width: 160px;margin: 20px auto;">
  11. <el-upload
  12. ref="upload"
  13. list-type="picture-card"
  14. :action="allurl"
  15. :headers="header"
  16. :show-file-list="false"
  17. :auto-upload="false"
  18. :file-list="fileList"
  19. multiple
  20. :on-preview="handlePictureCardPreview"
  21. :on-change="changeFileList"
  22. :on-success="uploadSuccess"
  23. :on-error="upError"
  24. :before-upload="uploadBefore"
  25. :data="updateData"
  26. >
  27. <i class="el-icon-plus"></i>
  28. </el-upload>
  29. </div>
  30. <div>
  31. <draggable v-model="fileList" :options="{group:'image'}" @change="dragChange">
  32. <div class="img_container" v-for="(item,index) in fileList" :key="index" style="">
  33. <img v-if="item.raw.type.indexOf('image')>-1" :src="item.url" :alt="item.url">
  34. <p v-else>{{item.name}}</p>
  35. <div class="delete_modal">
  36. <i class="el-icon-zoom-in" v-if="item.raw.type.indexOf('image')>-1" @click="handlePictureCardPreview(item)" style="margin-right: 20px;"></i>
  37. <i class="el-icon-delete" @click="deletePic(index)"></i>
  38. </div>
  39. </div>
  40. </draggable>
  41. <el-dialog :visible.sync="dialogVisible" append-to-body>
  42. <img width="100%" :src="dialogImageUrl" alt="">
  43. </el-dialog>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import draggable from "vuedraggable";
  49. export default {
  50. props: ["url"], // 上传基础路径
  51. data() {
  52. return {
  53. fileList: [],
  54. resList: [],
  55. length: 0, // 上传列表长度
  56. sum: 0, // 上传成功次数
  57. allurl: "", // 上传完整路径
  58. header: {
  59. 'persId': localStorage.getItem('userid'),
  60. 'accessToken' : localStorage.getItem('accessToken'),
  61. 'orgId': localStorage.getItem('currentOrgId')
  62. },
  63. dialogImageUrl: '',
  64. dialogVisible: false,
  65. imageList: [],
  66. updateData: {
  67. sn: 0
  68. }
  69. };
  70. },
  71. components:{
  72. draggable
  73. },
  74. computed:{
  75. userid(){
  76. return localStorage.getItem('userid') ? localStorage.getItem('userid') : ''
  77. }
  78. },
  79. methods: {
  80. // 初始化,
  81. init() {
  82. this.$refs.upload.clearFiles();
  83. this.length = 0;
  84. this.sum = 0;
  85. this.allurl = "";
  86. this.resList = [];
  87. },
  88. // 开始上传,文件列表为空直接返回turn表示结束,不为空触发上传并返回false,由uploadOver判断结束时间
  89. submitUpload(id,leng) {
  90. this.updateData.sn = leng ? leng : 0
  91. this.allurl = this.url + id;
  92. if (this.length) {
  93. this.$nextTick(() => {
  94. this.$refs.upload.submit();
  95. });
  96. return true;
  97. } else {
  98. return true;
  99. }
  100. },
  101. // 上传出错,向上触发结束
  102. upError(err, file, fileList) {
  103. this.$message.error("上传出错,请修改文件!");
  104. this.$emit("uploadOver");
  105. this.init();
  106. },
  107. // 全部上传成功,向上触发结束
  108. uploadSuccess(response, file, fileList) {
  109. this.resList.push(response.data);
  110. console.log(this.resList);
  111. this.sum = this.sum + 1;
  112. if (this.sum == this.length) {
  113. this.$emit("uploadOver", this.resList);
  114. this.init();
  115. }
  116. },
  117. uploadBefore(){
  118. this.updateData.sn ++
  119. },
  120. // 及时更新列表长度
  121. changeFileList(file, fileList) {
  122. this.length = fileList.length;
  123. this.fileList = fileList;
  124. },
  125. deletePic(index){
  126. this.fileList.splice(index, 1);
  127. },
  128. handlePictureCardPreview(file) {
  129. this.dialogImageUrl = file.url;
  130. this.dialogVisible = true;
  131. },
  132. dragChange(val){
  133. console.log(val)
  134. console.log(this.fileList)
  135. }
  136. }
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. .img_container{
  141. display:inline-block;
  142. width: 160px;
  143. height:150px;
  144. margin-right:10px;
  145. vertical-align: top;
  146. position: relative;
  147. img{
  148. width: 100%;
  149. max-height: 100%;
  150. min-height:30px;
  151. border:solid 1px #ddd;
  152. border-radius: 5px;
  153. }
  154. p{
  155. border: solid 1px #ddd;
  156. padding: 5px;
  157. border-radius: 5px;
  158. font-weight: bold;
  159. background: #eee;
  160. }
  161. &:hover{
  162. .delete_modal{
  163. display: block;
  164. }
  165. }
  166. .delete_modal{
  167. position: absolute;
  168. bottom: 0;
  169. left: 0;
  170. width: 100%;
  171. height: 36px;
  172. background-color: rgba(0, 0, 0, .6);
  173. text-align: center;
  174. line-height: 36px;
  175. color: #fff;
  176. display: none;
  177. cursor: pointer;
  178. i{
  179. font-size: 18px;
  180. }
  181. }
  182. }
  183. </style>