upLoad.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div>
  3. <div
  4. class="dialogTableTitle flex a-center jlr"
  5. style="
  6. display: flex;
  7. justify-content: space-between;
  8. align-items: center;
  9. margin: 10px 0;
  10. "
  11. >
  12. <div>
  13. <el-button
  14. size="small"
  15. type="primary"
  16. :disabled="browseStatus"
  17. @click.prevent="addRelevt()"
  18. >新行
  19. </el-button>
  20. </div>
  21. </div>
  22. <el-table
  23. :data="relevantAttachments"
  24. ref="table"
  25. tooltip-effect="dark"
  26. stripe
  27. style="width: 100%"
  28. height="150"
  29. >
  30. <el-table-column label="序号" type="index" width="80"> </el-table-column>
  31. <el-table-column
  32. prop="fName"
  33. header-align="center"
  34. align="center"
  35. label="附件名称"
  36. >
  37. <template slot-scope="scope">
  38. <el-input
  39. v-model="scope.row.fName"
  40. :disabled="browseStatus"
  41. placeholder="附件名称"
  42. show-word-limit
  43. />
  44. </template>
  45. </el-table-column>
  46. <el-table-column
  47. prop="createBy"
  48. header-align="center"
  49. align="center"
  50. label="上传人"
  51. >
  52. <template slot-scope="scope">
  53. <el-input
  54. v-model="scope.row.createBy"
  55. disabled
  56. placeholder="上传人"
  57. show-word-limit
  58. />
  59. </template>
  60. </el-table-column>
  61. <el-table-column
  62. prop="createTime"
  63. header-align="center"
  64. align="center"
  65. label="上传时间"
  66. >
  67. <template slot-scope="scope">
  68. <el-date-picker
  69. v-model="scope.row.createTime"
  70. type="date"
  71. disabled
  72. placeholder="上传时间"
  73. format="yyyy-MM-dd HH:mm"
  74. value-format="timestamp"
  75. ></el-date-picker>
  76. </template>
  77. </el-table-column>
  78. <el-table-column
  79. prop="fUrl"
  80. header-align="center"
  81. align="center"
  82. label="上传附件"
  83. >
  84. <template slot-scope="scope">
  85. <div style="display: flex; justify-content: center">
  86. <el-upload
  87. class="upload-demo"
  88. :action="uploadImgUrl"
  89. :on-success="
  90. (res, file) => {
  91. handleSucces(scope, res, file);
  92. }
  93. "
  94. :headers="headers"
  95. :disabled="browseStatus"
  96. :show-file-list="false"
  97. :limit="1"
  98. >
  99. <el-button size="small" type="text" :disabled="browseStatus"
  100. >点击上传</el-button
  101. >
  102. </el-upload>
  103. </div>
  104. </template>
  105. </el-table-column>
  106. <el-table-column
  107. header-align="center"
  108. align="center"
  109. label="操作"
  110. width="130PX"
  111. fixed="right"
  112. >
  113. <template slot-scope="scope">
  114. <el-button size="small" type="text" @click="checkFile(scope,0)"
  115. >查看</el-button>
  116. <el-button
  117. @click.native.prevent="deleteRow(scope.$index, relevantAttachments)"
  118. :disabled="browseStatus"
  119. size="small"
  120. type="text"
  121. >删除
  122. </el-button>
  123. <el-button size="small" type="text" @click="checkFile(scope,1)"
  124. >下载</el-button>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. <el-dialog
  129. width="80%"
  130. title="附件"
  131. :visible.sync="innerVisible"
  132. append-to-body>
  133. <div style="width: 50%;height: 50%;margin: 0 auto">
  134. <img :src="url" alt="" style="width: 100%;height: 100%;">
  135. </div>
  136. </el-dialog>
  137. </div>
  138. </template>
  139. <script>
  140. import { getToken } from "@/utils/auth";
  141. export default {
  142. props: {
  143. relevantAttachments: {
  144. type: Array,
  145. default: [],
  146. },
  147. createBy: {
  148. type: String,
  149. default: null,
  150. },
  151. browseStatus:{
  152. type: Boolean,
  153. default: false,
  154. }
  155. },
  156. data() {
  157. return {
  158. innerVisible:false,
  159. url:'',
  160. headers: {
  161. Authorization: "Bearer " + getToken(),
  162. },
  163. uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
  164. };
  165. },
  166. methods: {
  167. // 新增附件上传
  168. addRelevt() {
  169. this.relevantAttachments.push({
  170. fUrl: null,
  171. fName: null,
  172. createBy: this.createBy,
  173. createTime: Date.parse(new Date()),
  174. });
  175. },
  176. deleteRow(index, rows) {
  177. rows.splice(index, 1);
  178. },
  179. //附件上传
  180. handleSucces(scope, res, file) {
  181. this.relevantAttachments[scope.$index].fName = res.fileName;
  182. this.relevantAttachments[scope.$index].fUrl = res.url;
  183. if (!this.relevantAttachments[scope.$index].fUrl) {
  184. this.$message.error("上传失败");
  185. } else {
  186. this.$message.success("上传成功");
  187. }
  188. },
  189. //附件查看
  190. checkFile(scope,type) {
  191. if (this.relevantAttachments[scope.$index].fUrl) {
  192. if(type === 0){
  193. if (scope.row.fName.substring(scope.row.fName.lastIndexOf(".")) === '.jpg'||scope.row.fName.substring(scope.row.fName.lastIndexOf(".")) === '.png'||scope.row.fName.substring(scope.row.fName.lastIndexOf(".")) === '.JPG'||scope.row.fName.substring(scope.row.fName.lastIndexOf(".")) === '.PNG'){
  194. this.innerVisible = true
  195. this.url = this.relevantAttachments[scope.$index].fUrl
  196. }else {
  197. window.open(this.relevantAttachments[scope.$index].fUrl);
  198. }
  199. }else if(type === 1){
  200. window.open(this.relevantAttachments[scope.$index].fUrl);
  201. }
  202. } else {
  203. this.$message.error("请上传附件");
  204. }
  205. }
  206. },
  207. watch: {
  208. relevantAttachments(val) {
  209. console.log(val);
  210. this.relevantAttachments = val;
  211. },
  212. createBy(val){
  213. this.createBy=val
  214. },
  215. browseStatus(val){
  216. this.browseStatus=val
  217. }
  218. },
  219. };
  220. </script>
  221. <style scoped lang="scss">
  222. </style>