upLoad.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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="fType"
  48. header-align="center"
  49. align="center"
  50. label="文件属性">
  51. <template slot-scope="scope">
  52. <el-select
  53. v-model="scope.row.fType"
  54. clearable
  55. filterable
  56. :disabled="browseStatus"
  57. @change="filesTypeChange(scope.row)"
  58. >
  59. <el-option
  60. v-for="(item, index) in filesTypeOptions"
  61. :value="item.dictValue"
  62. :label="item.dictLabel"
  63. :key="index"
  64. ></el-option>
  65. </el-select>
  66. </template>
  67. </el-table-column>
  68. <el-table-column
  69. prop="createBy"
  70. header-align="center"
  71. align="center"
  72. label="上传人"
  73. >
  74. <template slot-scope="scope">
  75. <el-input
  76. v-model="scope.row.createBy"
  77. disabled
  78. placeholder="上传人"
  79. show-word-limit
  80. />
  81. </template>
  82. </el-table-column>
  83. <el-table-column
  84. prop="createTime"
  85. header-align="center"
  86. align="center"
  87. label="上传时间"
  88. >
  89. <template slot-scope="scope">
  90. <el-date-picker
  91. v-model="scope.row.createTime"
  92. type="date"
  93. disabled
  94. placeholder="上传时间"
  95. format="yyyy-MM-dd HH:mm"
  96. value-format="timestamp"
  97. ></el-date-picker>
  98. </template>
  99. </el-table-column>
  100. <el-table-column
  101. prop="fUrl"
  102. header-align="center"
  103. align="center"
  104. label="上传附件"
  105. >
  106. <template slot-scope="scope">
  107. <div style="display: flex; justify-content: center">
  108. <el-upload
  109. class="upload-demo"
  110. :action="uploadImgUrl"
  111. :on-success="
  112. (res, file) => {
  113. handleSucces(scope, res, file);
  114. }
  115. "
  116. :headers="headers"
  117. :disabled="browseStatus"
  118. :show-file-list="false"
  119. :limit="1"
  120. >
  121. <el-button size="small" type="text" :disabled="browseStatus"
  122. >点击上传</el-button
  123. >
  124. </el-upload>
  125. </div>
  126. </template>
  127. </el-table-column>
  128. <el-table-column
  129. header-align="center"
  130. align="center"
  131. label="操作"
  132. width="130PX"
  133. fixed="right"
  134. >
  135. <template slot-scope="scope">
  136. <el-button size="small" type="text" @click="checkFile(scope,0)"
  137. >查看</el-button>
  138. <el-button
  139. @click.native.prevent="deleteRow(scope.$index, relevantAttachments)"
  140. :disabled="browseStatus"
  141. size="small"
  142. type="text"
  143. >删除
  144. </el-button>
  145. <el-button size="small" type="text" @click="checkFile(scope,1)"
  146. >下载</el-button>
  147. </template>
  148. </el-table-column>
  149. </el-table>
  150. <el-dialog
  151. width="80%"
  152. title="附件"
  153. :fullscreen="dialogFull"
  154. :visible.sync="innerVisible"
  155. append-to-body>
  156. <template slot="title">
  157. <span class="el-dialog__title">
  158. <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
  159. 附件
  160. </span>
  161. <div class="size-change" @click="dialogFull? dialogFull=false: dialogFull=true">
  162. <i class="el-icon-full-screen"></i>
  163. </div>
  164. </template>
  165. <div style="width: 50%;height: 50%;margin: 0 auto">
  166. <img :src="url" alt="" style="width: 100%;height: 100%;">
  167. </div>
  168. </el-dialog>
  169. </div>
  170. </template>
  171. <script>
  172. import { getToken } from "@/utils/auth";
  173. export default {
  174. props: {
  175. relevantAttachments: {
  176. type: Array,
  177. default: [],
  178. },
  179. createBy: {
  180. type: String,
  181. default: null,
  182. },
  183. browseStatus:{
  184. type: Boolean,
  185. default: false,
  186. }
  187. },
  188. data() {
  189. return {
  190. innerVisible:false,
  191. url:'',
  192. dialogFull: false,
  193. headers: {
  194. Authorization: "Bearer " + getToken(),
  195. },
  196. uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
  197. filesTypeOptions: [],
  198. repeatData: '', //判断文件属性是否有重复
  199. };
  200. },
  201. created() {
  202. this.getDicts("file_type").then((response) => {
  203. this.filesTypeOptions = response.data;
  204. });
  205. },
  206. methods: {
  207. // 新增附件上传
  208. addRelevt() {
  209. this.relevantAttachments.push({
  210. fUrl: null,
  211. fName: null,
  212. createBy: this.createBy,
  213. createTime: Date.parse(new Date()),
  214. });
  215. },
  216. deleteRow(index, rows) {
  217. rows.splice(index, 1);
  218. },
  219. //附件上传
  220. handleSucces(scope, res, file) {
  221. this.relevantAttachments[scope.$index].fName = res.fileName;
  222. this.relevantAttachments[scope.$index].fUrl = res.url;
  223. if (!this.relevantAttachments[scope.$index].fUrl) {
  224. this.$message.error("上传失败");
  225. } else {
  226. this.$message.success("上传成功");
  227. }
  228. },
  229. //附件查看
  230. checkFile(scope,type) {
  231. if (this.relevantAttachments[scope.$index].fUrl) {
  232. if(type === 0){
  233. 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'){
  234. this.innerVisible = true
  235. this.url = this.relevantAttachments[scope.$index].fUrl
  236. }else {
  237. window.open(this.relevantAttachments[scope.$index].fUrl);
  238. }
  239. }else if(type === 1){
  240. window.open(this.relevantAttachments[scope.$index].fUrl);
  241. }
  242. } else {
  243. this.$message.error("请上传附件");
  244. }
  245. },
  246. // 文件属性上传判断
  247. filesTypeChange(row) {
  248. if (row.fType == 1) {
  249. let repeat = false
  250. for (let k = 0;k < this.relevantAttachments.length - 1;k++) {
  251. if (row.fType == this.relevantAttachments[k].fType) repeat = true
  252. }
  253. if (repeat) {
  254. row.fType = null
  255. this.$message.warning('已存在电子签章')
  256. }
  257. }
  258. },
  259. },
  260. watch: {
  261. relevantAttachments(val) {
  262. this.relevantAttachments = val;
  263. },
  264. createBy(val){
  265. this.createBy=val
  266. },
  267. browseStatus(val){
  268. this.browseStatus=val
  269. }
  270. },
  271. };
  272. </script>
  273. <style scoped lang="scss">
  274. .size-change {
  275. float: right;
  276. margin-right: 20px;
  277. cursor:pointer;
  278. }
  279. .size-change:hover {
  280. color: #00afff;
  281. }
  282. </style>