upLoad.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. import {deleteAttachment} from "@/api/index";
  174. export default {
  175. props: {
  176. relevantAttachments: {
  177. type: Array,
  178. default: [],
  179. },
  180. createBy: {
  181. type: String,
  182. default: null,
  183. },
  184. browseStatus:{
  185. type: Boolean,
  186. default: false,
  187. }
  188. },
  189. data() {
  190. return {
  191. innerVisible:false,
  192. url:'',
  193. dialogFull: false,
  194. headers: {
  195. Authorization: "Bearer " + getToken(),
  196. },
  197. uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
  198. filesTypeOptions: [],
  199. repeatData: '', //判断文件属性是否有重复
  200. };
  201. },
  202. created() {
  203. this.getDicts("file_type").then((response) => {
  204. this.filesTypeOptions = response.data;
  205. });
  206. },
  207. methods: {
  208. // 新增附件上传
  209. addRelevt() {
  210. this.relevantAttachments.push({
  211. fUrl: null,
  212. fName: null,
  213. createBy: this.createBy,
  214. createTime: Date.parse(new Date()),
  215. });
  216. },
  217. deleteRow(index, rows) {
  218. if (rows[index].fId){
  219. // deleteAttachment(rows[index].fId).then(res=>{
  220. rows.splice(index, 1);
  221. this.$message.success("删除成功");
  222. // })
  223. }else {
  224. rows.splice(index, 1);
  225. this.$message.success("删除成功");
  226. }
  227. },
  228. //附件上传
  229. handleSucces(scope, res, file) {
  230. this.relevantAttachments[scope.$index].fName = res.fileName;
  231. this.relevantAttachments[scope.$index].fUrl = res.url;
  232. if (!this.relevantAttachments[scope.$index].fUrl) {
  233. this.$message.error("上传失败");
  234. } else {
  235. this.$message.success("上传成功");
  236. }
  237. },
  238. //附件查看
  239. checkFile(scope,type) {
  240. if (this.relevantAttachments[scope.$index].fUrl) {
  241. if(type === 0){
  242. 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'){
  243. this.innerVisible = true
  244. this.url = this.relevantAttachments[scope.$index].fUrl
  245. }else {
  246. window.open(this.relevantAttachments[scope.$index].fUrl);
  247. }
  248. }else if(type === 1){
  249. window.open(this.relevantAttachments[scope.$index].fUrl);
  250. }
  251. } else {
  252. this.$message.error("请上传附件");
  253. }
  254. },
  255. // 文件属性上传判断
  256. filesTypeChange(row) {
  257. if (row.fType == 1) {
  258. let repeat = false
  259. for (let k = 0;k < this.relevantAttachments.length - 1;k++) {
  260. if (row.fType == this.relevantAttachments[k].fType) repeat = true
  261. }
  262. if (repeat) {
  263. row.fType = null
  264. this.$message.warning('已存在电子签章')
  265. }
  266. }
  267. },
  268. },
  269. watch: {
  270. relevantAttachments(val) {
  271. this.relevantAttachments = val;
  272. },
  273. createBy(val){
  274. this.createBy=val
  275. },
  276. browseStatus(val){
  277. this.browseStatus=val
  278. }
  279. },
  280. };
  281. </script>
  282. <style scoped lang="scss">
  283. .size-change {
  284. float: right;
  285. margin-right: 20px;
  286. cursor:pointer;
  287. }
  288. .size-change:hover {
  289. color: #00afff;
  290. }
  291. </style>