Commit 81141b2a7e8801a9482c19313655b58966fc5f7a
1 parent
a8edc770
廉政风险点、廉洁教育、文件资料已支持附件上传
Showing
3 changed files
with
472 additions
and
13 deletions
trash-ui/src/views/other/documentData/index.vue
| ... | ... | @@ -92,6 +92,14 @@ |
| 92 | 92 | v-hasPermi="['other:documentData:remove']" |
| 93 | 93 | >删除 |
| 94 | 94 | </el-button> |
| 95 | + <el-button | |
| 96 | + size="mini" | |
| 97 | + type="text" | |
| 98 | + icon="el-icon-info" | |
| 99 | + @click="handleInfo(scope.row)" | |
| 100 | + v-hasPermi="['other:documentData:remove']" | |
| 101 | + >查看附件 | |
| 102 | + </el-button> | |
| 95 | 103 | </template> |
| 96 | 104 | </el-table-column> |
| 97 | 105 | </el-table> |
| ... | ... | @@ -108,10 +116,10 @@ |
| 108 | 116 | <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body> |
| 109 | 117 | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| 110 | 118 | <el-form-item label="标题" prop="title"> |
| 111 | - <el-input v-model="form.title" placeholder="请输入标题"/> | |
| 119 | + <el-input v-model="form.title" placeholder="请输入标题" :readonly="infoDisable"/> | |
| 112 | 120 | </el-form-item> |
| 113 | 121 | <el-form-item label="内容" prop="content"> |
| 114 | - <editor v-model="form.content" :min-height="368"/> | |
| 122 | + <editor v-model="form.content" :min-height="368" :readonly="infoDisable"/> | |
| 115 | 123 | </el-form-item> |
| 116 | 124 | <el-row> |
| 117 | 125 | <el-col :span="12"> |
| ... | ... | @@ -125,10 +133,53 @@ |
| 125 | 133 | </el-form-item> |
| 126 | 134 | </el-col> |
| 127 | 135 | </el-row> |
| 128 | - | |
| 136 | + <el-form-item label="附件预览" v-if="fileEntityList.length!==0"> | |
| 137 | + <el-image v-for="item in fileEntityList" | |
| 138 | + v-if="!/\.(pjp|pdf|doc|docx|xls|xlsx)$/.test(item.name)" | |
| 139 | + style="width: 150px; height: 100px; margin: 5px;" | |
| 140 | + :src="createUrl(item)" | |
| 141 | + :preview-src-list="[createUrl(item)]" | |
| 142 | + :z-index="999"> | |
| 143 | + </el-image> | |
| 144 | + </el-form-item> | |
| 145 | + <el-form-item prop="fileEntityList" label="附件" v-if="!infoDisable"> | |
| 146 | + <el-upload | |
| 147 | + ref="upload" | |
| 148 | + action="" | |
| 149 | + accept=".jpg,.jpeg,.png,.gif,.jfif,.pjpeg,.pjp,.pdf,.doc,.docx,.xls,.xlsx" | |
| 150 | + :on-change="fileChange" | |
| 151 | + :auto-upload="false" | |
| 152 | + :show-file-list="false" | |
| 153 | + multiple | |
| 154 | + :file-list="fileEntityList"> | |
| 155 | + <el-button size="small" type="primary" icon="el-icon-upload">上传附件</el-button> | |
| 156 | + </el-upload> | |
| 157 | + </el-form-item> | |
| 158 | + <el-table :data="fileEntityList"> | |
| 159 | + <el-table-column property="name" label="附件名称" header-align="center" align="center"></el-table-column> | |
| 160 | + <el-table-column label="操作" class-name="small-padding fixed-width" header-align="center" align="center"> | |
| 161 | + <template slot-scope="scope"> | |
| 162 | + <el-button | |
| 163 | + size="small" type="success" | |
| 164 | + icon="el-icon-download" | |
| 165 | + @click="tempDownload(scope.row)" | |
| 166 | + v-hasPermi="['other:documentData:edit']" | |
| 167 | + round>下载 | |
| 168 | + </el-button> | |
| 169 | + <el-button | |
| 170 | + size="small" type="danger" | |
| 171 | + v-show="!infoDisable" | |
| 172 | + icon="el-icon-delete" | |
| 173 | + @click="handleDeleteFile(scope.$index)" | |
| 174 | + v-hasPermi="['other:documentData:remove']" | |
| 175 | + round>删除 | |
| 176 | + </el-button> | |
| 177 | + </template> | |
| 178 | + </el-table-column> | |
| 179 | + </el-table> | |
| 129 | 180 | </el-form> |
| 130 | 181 | <div slot="footer" class="dialog-footer"> |
| 131 | - <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 182 | + <el-button type="primary" @click="submitForm" v-show="!infoDisable">确 定</el-button> | |
| 132 | 183 | <el-button @click="cancel">取 消</el-button> |
| 133 | 184 | </div> |
| 134 | 185 | </el-dialog> |
| ... | ... | @@ -146,10 +197,11 @@ import { |
| 146 | 197 | } from "@/api/other/documentData"; |
| 147 | 198 | import Editor from '@/components/2cEditor'; |
| 148 | 199 | import {parseTime} from "../../../utils/trash"; |
| 200 | +import uploadFile from "@/components/FileUpload"; | |
| 149 | 201 | |
| 150 | 202 | export default { |
| 151 | 203 | name: "DocumentData", |
| 152 | - components: {Editor}, | |
| 204 | + components: {Editor, uploadFile}, | |
| 153 | 205 | data() { |
| 154 | 206 | return { |
| 155 | 207 | // 遮罩层 |
| ... | ... | @@ -195,12 +247,31 @@ export default { |
| 195 | 247 | ] |
| 196 | 248 | }, |
| 197 | 249 | fileEntityList: [], |
| 250 | + infoDisable: false | |
| 198 | 251 | }; |
| 199 | 252 | }, |
| 200 | 253 | created() { |
| 201 | 254 | this.getList(); |
| 202 | 255 | }, |
| 203 | 256 | methods: { |
| 257 | + handleInfo(row){ | |
| 258 | + this.reset(); | |
| 259 | + const id = row.id || this.ids | |
| 260 | + getDocumentData(id).then(response => { | |
| 261 | + this.form = response.data; | |
| 262 | + //将附件转换为前端可视化数组 | |
| 263 | + if (this.form.files != null && this.form.files !== "") { | |
| 264 | + let fileList = this.form.files.split(";"); | |
| 265 | + fileList.map(item => { | |
| 266 | + let name = item.substring(item.lastIndexOf("/") + 1); | |
| 267 | + this.fileEntityList.push({name: name, url: item}) | |
| 268 | + }) | |
| 269 | + } | |
| 270 | + this.open = true; | |
| 271 | + this.infoDisable = true; | |
| 272 | + this.title = "查看文件资料"; | |
| 273 | + }); | |
| 274 | + }, | |
| 204 | 275 | toInfo(row){ |
| 205 | 276 | //打开当日报修页签 |
| 206 | 277 | this.$tab.openPage("查看详情","/documentData/info",{"documentData":row}) |
| ... | ... | @@ -232,6 +303,7 @@ export default { |
| 232 | 303 | updateBy: null |
| 233 | 304 | }; |
| 234 | 305 | this.fileEntityList = []; |
| 306 | + this.infoDisable = false; | |
| 235 | 307 | this.resetForm("form"); |
| 236 | 308 | }, |
| 237 | 309 | /** 搜索按钮操作 */ |
| ... | ... | @@ -285,6 +357,18 @@ export default { |
| 285 | 357 | let form = this.form; |
| 286 | 358 | //去掉params属性 |
| 287 | 359 | delete form.params; |
| 360 | + //先清空原有的附件 | |
| 361 | + form.files = null; | |
| 362 | + | |
| 363 | + | |
| 364 | + this.fileEntityList.forEach(item => { | |
| 365 | + if (item.raw != null) { | |
| 366 | + formData.append('fileList', item.raw) | |
| 367 | + } else { | |
| 368 | + //将原有的附件拼接到form中 | |
| 369 | + form.files = form.files !== null ? form.files + ";" + item.url : item.url; | |
| 370 | + } | |
| 371 | + }) | |
| 288 | 372 | |
| 289 | 373 | for (let key in form) { |
| 290 | 374 | formData.append(key, form[key] == null ? "" : form[key]) |
| ... | ... | @@ -333,6 +417,75 @@ export default { |
| 333 | 417 | this.download(response.msg); |
| 334 | 418 | }) |
| 335 | 419 | }, |
| 420 | + /** | |
| 421 | + * 文件改变时,限制文件上传格式和大小 | |
| 422 | + * 文件格式只能为docx/doc/pdf/png/jpeg/png/jpg | |
| 423 | + * 大小不超过20M | |
| 424 | + * */ | |
| 425 | + fileChange(file, fileList) { | |
| 426 | + let count = 0; | |
| 427 | + for (let i = 0; i < fileList.length; i++) { | |
| 428 | + // console.log(fileList.length) | |
| 429 | + // console.log(this.fileEntityList[i].name+"111"+file.name) | |
| 430 | + if (fileList[i].name == file.name) { | |
| 431 | + count++; | |
| 432 | + if (count == 2) { | |
| 433 | + this.$message({ | |
| 434 | + message: '已存在此文件!', | |
| 435 | + type: 'warning' | |
| 436 | + }); | |
| 437 | + for (let j = fileList.length; j > 0; j--) { | |
| 438 | + //如果存在此文件,去除新选择的重复文件 | |
| 439 | + if (fileList[j - 1].name == file.name) { | |
| 440 | + fileList.splice(j - 1, 1); | |
| 441 | + i--; | |
| 442 | + return false; | |
| 443 | + } | |
| 444 | + } | |
| 445 | + } | |
| 446 | + } | |
| 447 | + } | |
| 448 | + let fileType = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase(); | |
| 449 | + //格式符合后判断大小 | |
| 450 | + if ("jpg,jpeg,png,gif,jfif,pjpeg,pjp,pdf,doc,docx,xls,xlsx".indexOf(fileType) != -1) { | |
| 451 | + let max5M = file.size / 1024 / 1024 < 100; | |
| 452 | + if (!max5M) { | |
| 453 | + this.$message({ | |
| 454 | + message: '上传文件大小不得超过100M!', | |
| 455 | + type: 'warning' | |
| 456 | + }); | |
| 457 | + fileList = fileList.splice(fileList.length - 1, 1); | |
| 458 | + } else { | |
| 459 | + //符合条件后进行添加 | |
| 460 | + this.fileEntityList = fileList | |
| 461 | + } | |
| 462 | + } else { | |
| 463 | + this.$message({ | |
| 464 | + message: '上传文件只能是 jpg,jpeg,png,gif,jfif,pjpeg,pjp,pdf,doc,docx,xls,xlsx格式!', | |
| 465 | + type: 'warning' | |
| 466 | + }); | |
| 467 | + fileList = fileList.splice(fileList.length - 1, 1); | |
| 468 | + } | |
| 469 | + }, | |
| 470 | + // 删除文件 | |
| 471 | + handleDeleteFile(index) { | |
| 472 | + this.fileEntityList.splice(index, 1); | |
| 473 | + }, | |
| 474 | + /** 文件下载 */ | |
| 475 | + tempDownload(row) { | |
| 476 | + let name = row.name; | |
| 477 | + let url = ""; | |
| 478 | + if (row.raw != null) { | |
| 479 | + url = URL.createObjectURL(row.raw); | |
| 480 | + } else { | |
| 481 | + url = process.env.VUE_APP_BASE_API + row.url; | |
| 482 | + } | |
| 483 | + const a = document.createElement('a') | |
| 484 | + a.setAttribute('download', name) | |
| 485 | + a.setAttribute('target', '_blank') | |
| 486 | + a.setAttribute('href', url); | |
| 487 | + a.click() | |
| 488 | + }, | |
| 336 | 489 | createUrl(file) { |
| 337 | 490 | if (file.raw != null) { |
| 338 | 491 | return URL.createObjectURL(file.raw); | ... | ... |
trash-ui/src/views/other/incorruptEducation/index.vue
| ... | ... | @@ -92,6 +92,14 @@ |
| 92 | 92 | v-hasPermi="['other:IncorruptEducation:remove']" |
| 93 | 93 | >删除 |
| 94 | 94 | </el-button> |
| 95 | + <el-button | |
| 96 | + size="mini" | |
| 97 | + type="text" | |
| 98 | + icon="el-icon-info" | |
| 99 | + @click="handleInfo(scope.row)" | |
| 100 | + v-hasPermi="['other:documentData:remove']" | |
| 101 | + >查看附件 | |
| 102 | + </el-button> | |
| 95 | 103 | </template> |
| 96 | 104 | </el-table-column> |
| 97 | 105 | </el-table> |
| ... | ... | @@ -108,10 +116,10 @@ |
| 108 | 116 | <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body> |
| 109 | 117 | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| 110 | 118 | <el-form-item label="标题" prop="title"> |
| 111 | - <el-input v-model="form.title" placeholder="请输入标题"/> | |
| 119 | + <el-input v-model="form.title" placeholder="请输入标题" :readonly="infoDisable"/> | |
| 112 | 120 | </el-form-item> |
| 113 | 121 | <el-form-item label="内容" prop="content"> |
| 114 | - <editor v-model="form.content" :min-height="368"/> | |
| 122 | + <editor v-model="form.content" :min-height="368" :readonly="infoDisable"/> | |
| 115 | 123 | </el-form-item> |
| 116 | 124 | <el-row> |
| 117 | 125 | <el-col :span="12"> |
| ... | ... | @@ -125,10 +133,53 @@ |
| 125 | 133 | </el-form-item> |
| 126 | 134 | </el-col> |
| 127 | 135 | </el-row> |
| 128 | - | |
| 136 | + <el-form-item label="附件预览" v-if="fileEntityList.length!==0"> | |
| 137 | + <el-image v-for="item in fileEntityList" | |
| 138 | + v-if="!/\.(pjp|pdf|doc|docx|xls|xlsx)$/.test(item.name)" | |
| 139 | + style="width: 150px; height: 100px; margin: 5px;" | |
| 140 | + :src="createUrl(item)" | |
| 141 | + :preview-src-list="[createUrl(item)]" | |
| 142 | + :z-index="999"> | |
| 143 | + </el-image> | |
| 144 | + </el-form-item> | |
| 145 | + <el-form-item prop="fileEntityList" label="附件" v-if="!infoDisable"> | |
| 146 | + <el-upload | |
| 147 | + ref="upload" | |
| 148 | + action="" | |
| 149 | + accept=".jpg,.jpeg,.png,.gif,.jfif,.pjpeg,.pjp,.pdf,.doc,.docx,.xls,.xlsx" | |
| 150 | + :on-change="fileChange" | |
| 151 | + :auto-upload="false" | |
| 152 | + :show-file-list="false" | |
| 153 | + multiple | |
| 154 | + :file-list="fileEntityList"> | |
| 155 | + <el-button size="small" type="primary" icon="el-icon-upload">上传附件</el-button> | |
| 156 | + </el-upload> | |
| 157 | + </el-form-item> | |
| 158 | + <el-table :data="fileEntityList"> | |
| 159 | + <el-table-column property="name" label="附件名称" header-align="center" align="center"></el-table-column> | |
| 160 | + <el-table-column label="操作" class-name="small-padding fixed-width" header-align="center" align="center"> | |
| 161 | + <template slot-scope="scope"> | |
| 162 | + <el-button | |
| 163 | + size="small" type="success" | |
| 164 | + icon="el-icon-download" | |
| 165 | + @click="tempDownload(scope.row)" | |
| 166 | + v-hasPermi="['other:documentData:edit']" | |
| 167 | + round>下载 | |
| 168 | + </el-button> | |
| 169 | + <el-button | |
| 170 | + size="small" type="danger" | |
| 171 | + icon="el-icon-delete" | |
| 172 | + @click="handleDeleteFile(scope.$index)" | |
| 173 | + v-show="!infoDisable" | |
| 174 | + v-hasPermi="['other:documentData:remove']" | |
| 175 | + round>删除 | |
| 176 | + </el-button> | |
| 177 | + </template> | |
| 178 | + </el-table-column> | |
| 179 | + </el-table> | |
| 129 | 180 | </el-form> |
| 130 | 181 | <div slot="footer" class="dialog-footer"> |
| 131 | - <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 182 | + <el-button type="primary" @click="submitForm" v-show="!infoDisable">确 定</el-button> | |
| 132 | 183 | <el-button @click="cancel">取 消</el-button> |
| 133 | 184 | </div> |
| 134 | 185 | </el-dialog> |
| ... | ... | @@ -146,6 +197,7 @@ import { |
| 146 | 197 | } from "@/api/other/incorruptEducation"; |
| 147 | 198 | import Editor from '@/components/2cEditor'; |
| 148 | 199 | import {parseTime} from "../../../utils/trash"; |
| 200 | +import {getDocumentData} from "@/api/other/documentData"; | |
| 149 | 201 | |
| 150 | 202 | export default { |
| 151 | 203 | name: "IncorruptEducation", |
| ... | ... | @@ -195,12 +247,31 @@ export default { |
| 195 | 247 | ] |
| 196 | 248 | }, |
| 197 | 249 | fileEntityList: [], |
| 250 | + infoDisable:false | |
| 198 | 251 | }; |
| 199 | 252 | }, |
| 200 | 253 | created() { |
| 201 | 254 | this.getList(); |
| 202 | 255 | }, |
| 203 | 256 | methods: { |
| 257 | + handleInfo(row){ | |
| 258 | + this.reset(); | |
| 259 | + const id = row.id || this.ids | |
| 260 | + getIncorruptEducation(id).then(response => { | |
| 261 | + this.form = response.data; | |
| 262 | + //将附件转换为前端可视化数组 | |
| 263 | + if (this.form.files != null && this.form.files !== "") { | |
| 264 | + let fileList = this.form.files.split(";"); | |
| 265 | + fileList.map(item => { | |
| 266 | + let name = item.substring(item.lastIndexOf("/") + 1); | |
| 267 | + this.fileEntityList.push({name: name, url: item}) | |
| 268 | + }) | |
| 269 | + } | |
| 270 | + this.open = true; | |
| 271 | + this.infoDisable = true; | |
| 272 | + this.title = "查看文件资料"; | |
| 273 | + }); | |
| 274 | + }, | |
| 204 | 275 | toInfo(row){ |
| 205 | 276 | //打开当日报修页签 |
| 206 | 277 | this.$tab.openPage("查看详情","/IncorruptEducation/info",{"IncorruptEducation":row}) |
| ... | ... | @@ -232,6 +303,7 @@ export default { |
| 232 | 303 | updateBy: null |
| 233 | 304 | }; |
| 234 | 305 | this.fileEntityList = []; |
| 306 | + this.infoDisable = false; | |
| 235 | 307 | this.resetForm("form"); |
| 236 | 308 | }, |
| 237 | 309 | /** 搜索按钮操作 */ |
| ... | ... | @@ -285,7 +357,18 @@ export default { |
| 285 | 357 | let form = this.form; |
| 286 | 358 | //去掉params属性 |
| 287 | 359 | delete form.params; |
| 360 | + //先清空原有的附件 | |
| 361 | + form.files = null; | |
| 362 | + | |
| 288 | 363 | |
| 364 | + this.fileEntityList.forEach(item => { | |
| 365 | + if (item.raw != null) { | |
| 366 | + formData.append('fileList', item.raw) | |
| 367 | + } else { | |
| 368 | + //将原有的附件拼接到form中 | |
| 369 | + form.files = form.files !== null ? form.files + ";" + item.url : item.url; | |
| 370 | + } | |
| 371 | + }) | |
| 289 | 372 | for (let key in form) { |
| 290 | 373 | formData.append(key, form[key] == null ? "" : form[key]) |
| 291 | 374 | } |
| ... | ... | @@ -333,6 +416,75 @@ export default { |
| 333 | 416 | this.download(response.msg); |
| 334 | 417 | }) |
| 335 | 418 | }, |
| 419 | + /** | |
| 420 | + * 文件改变时,限制文件上传格式和大小 | |
| 421 | + * 文件格式只能为docx/doc/pdf/png/jpeg/png/jpg | |
| 422 | + * 大小不超过20M | |
| 423 | + * */ | |
| 424 | + fileChange(file, fileList) { | |
| 425 | + let count = 0; | |
| 426 | + for (let i = 0; i < fileList.length; i++) { | |
| 427 | + // console.log(fileList.length) | |
| 428 | + // console.log(this.fileEntityList[i].name+"111"+file.name) | |
| 429 | + if (fileList[i].name == file.name) { | |
| 430 | + count++; | |
| 431 | + if (count == 2) { | |
| 432 | + this.$message({ | |
| 433 | + message: '已存在此文件!', | |
| 434 | + type: 'warning' | |
| 435 | + }); | |
| 436 | + for (let j = fileList.length; j > 0; j--) { | |
| 437 | + //如果存在此文件,去除新选择的重复文件 | |
| 438 | + if (fileList[j - 1].name == file.name) { | |
| 439 | + fileList.splice(j - 1, 1); | |
| 440 | + i--; | |
| 441 | + return false; | |
| 442 | + } | |
| 443 | + } | |
| 444 | + } | |
| 445 | + } | |
| 446 | + } | |
| 447 | + let fileType = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase(); | |
| 448 | + //格式符合后判断大小 | |
| 449 | + if ("jpg,jpeg,png,gif,jfif,pjpeg,pjp,pdf,doc,docx,xls,xlsx".indexOf(fileType) != -1) { | |
| 450 | + let max5M = file.size / 1024 / 1024 < 100; | |
| 451 | + if (!max5M) { | |
| 452 | + this.$message({ | |
| 453 | + message: '上传文件大小不得超过100M!', | |
| 454 | + type: 'warning' | |
| 455 | + }); | |
| 456 | + fileList = fileList.splice(fileList.length - 1, 1); | |
| 457 | + } else { | |
| 458 | + //符合条件后进行添加 | |
| 459 | + this.fileEntityList = fileList | |
| 460 | + } | |
| 461 | + } else { | |
| 462 | + this.$message({ | |
| 463 | + message: '上传文件只能是 jpg,jpeg,png,gif,jfif,pjpeg,pjp,pdf,doc,docx,xls,xlsx格式!', | |
| 464 | + type: 'warning' | |
| 465 | + }); | |
| 466 | + fileList = fileList.splice(fileList.length - 1, 1); | |
| 467 | + } | |
| 468 | + }, | |
| 469 | + // 删除文件 | |
| 470 | + handleDeleteFile(index) { | |
| 471 | + this.fileEntityList.splice(index, 1); | |
| 472 | + }, | |
| 473 | + /** 文件下载 */ | |
| 474 | + tempDownload(row) { | |
| 475 | + let name = row.name; | |
| 476 | + let url = ""; | |
| 477 | + if (row.raw != null) { | |
| 478 | + url = URL.createObjectURL(row.raw); | |
| 479 | + } else { | |
| 480 | + url = process.env.VUE_APP_BASE_API + row.url; | |
| 481 | + } | |
| 482 | + const a = document.createElement('a') | |
| 483 | + a.setAttribute('download', name) | |
| 484 | + a.setAttribute('target', '_blank') | |
| 485 | + a.setAttribute('href', url); | |
| 486 | + a.click() | |
| 487 | + }, | |
| 336 | 488 | createUrl(file) { |
| 337 | 489 | if (file.raw != null) { |
| 338 | 490 | return URL.createObjectURL(file.raw); | ... | ... |
trash-ui/src/views/other/incorruptGovernment/index.vue
| ... | ... | @@ -92,6 +92,14 @@ |
| 92 | 92 | v-hasPermi="['other:IncorruptGovernment:remove']" |
| 93 | 93 | >删除 |
| 94 | 94 | </el-button> |
| 95 | + <el-button | |
| 96 | + size="mini" | |
| 97 | + type="text" | |
| 98 | + icon="el-icon-info" | |
| 99 | + @click="handleInfo(scope.row)" | |
| 100 | + v-hasPermi="['other:documentData:remove']" | |
| 101 | + >查看附件 | |
| 102 | + </el-button> | |
| 95 | 103 | </template> |
| 96 | 104 | </el-table-column> |
| 97 | 105 | </el-table> |
| ... | ... | @@ -108,10 +116,10 @@ |
| 108 | 116 | <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body> |
| 109 | 117 | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| 110 | 118 | <el-form-item label="标题" prop="title"> |
| 111 | - <el-input v-model="form.title" placeholder="请输入标题"/> | |
| 119 | + <el-input v-model="form.title" placeholder="请输入标题" :readonly="infoDisable"/> | |
| 112 | 120 | </el-form-item> |
| 113 | 121 | <el-form-item label="内容" prop="content"> |
| 114 | - <editor v-model="form.content" :min-height="368"/> | |
| 122 | + <editor v-model="form.content" :min-height="368" :readonly="infoDisable"/> | |
| 115 | 123 | </el-form-item> |
| 116 | 124 | <el-row> |
| 117 | 125 | <el-col :span="12"> |
| ... | ... | @@ -125,10 +133,53 @@ |
| 125 | 133 | </el-form-item> |
| 126 | 134 | </el-col> |
| 127 | 135 | </el-row> |
| 128 | - | |
| 136 | + <el-form-item label="附件预览" v-if="fileEntityList.length!==0"> | |
| 137 | + <el-image v-for="item in fileEntityList" | |
| 138 | + v-if="!/\.(pjp|pdf|doc|docx|xls|xlsx)$/.test(item.name)" | |
| 139 | + style="width: 150px; height: 100px; margin: 5px;" | |
| 140 | + :src="createUrl(item)" | |
| 141 | + :preview-src-list="[createUrl(item)]" | |
| 142 | + :z-index="999"> | |
| 143 | + </el-image> | |
| 144 | + </el-form-item> | |
| 145 | + <el-form-item prop="fileEntityList" label="附件" v-if="!infoDisable"> | |
| 146 | + <el-upload | |
| 147 | + ref="upload" | |
| 148 | + action="" | |
| 149 | + accept=".jpg,.jpeg,.png,.gif,.jfif,.pjpeg,.pjp,.pdf,.doc,.docx,.xls,.xlsx" | |
| 150 | + :on-change="fileChange" | |
| 151 | + :auto-upload="false" | |
| 152 | + :show-file-list="false" | |
| 153 | + multiple | |
| 154 | + :file-list="fileEntityList"> | |
| 155 | + <el-button size="small" type="primary" icon="el-icon-upload">上传附件</el-button> | |
| 156 | + </el-upload> | |
| 157 | + </el-form-item> | |
| 158 | + <el-table :data="fileEntityList"> | |
| 159 | + <el-table-column property="name" label="附件名称" header-align="center" align="center"></el-table-column> | |
| 160 | + <el-table-column label="操作" class-name="small-padding fixed-width" header-align="center" align="center"> | |
| 161 | + <template slot-scope="scope"> | |
| 162 | + <el-button | |
| 163 | + size="small" type="success" | |
| 164 | + icon="el-icon-download" | |
| 165 | + @click="tempDownload(scope.row)" | |
| 166 | + v-hasPermi="['other:documentData:edit']" | |
| 167 | + round>下载 | |
| 168 | + </el-button> | |
| 169 | + <el-button | |
| 170 | + size="small" type="danger" | |
| 171 | + icon="el-icon-delete" | |
| 172 | + @click="handleDeleteFile(scope.$index)" | |
| 173 | + v-show="!infoDisable" | |
| 174 | + v-hasPermi="['other:documentData:remove']" | |
| 175 | + round>删除 | |
| 176 | + </el-button> | |
| 177 | + </template> | |
| 178 | + </el-table-column> | |
| 179 | + </el-table> | |
| 129 | 180 | </el-form> |
| 130 | 181 | <div slot="footer" class="dialog-footer"> |
| 131 | - <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 182 | + <el-button type="primary" @click="submitForm" v-show="!infoDisable">确 定</el-button> | |
| 132 | 183 | <el-button @click="cancel">取 消</el-button> |
| 133 | 184 | </div> |
| 134 | 185 | </el-dialog> |
| ... | ... | @@ -146,6 +197,7 @@ import { |
| 146 | 197 | } from "@/api/other/incorruptGovernment"; |
| 147 | 198 | import Editor from '@/components/2cEditor'; |
| 148 | 199 | import {parseTime} from "../../../utils/trash"; |
| 200 | +import {getDocumentData} from "@/api/other/documentData"; | |
| 149 | 201 | |
| 150 | 202 | export default { |
| 151 | 203 | name: "IncorruptGovernment", |
| ... | ... | @@ -195,12 +247,31 @@ export default { |
| 195 | 247 | ] |
| 196 | 248 | }, |
| 197 | 249 | fileEntityList: [], |
| 250 | + infoDisable:false | |
| 198 | 251 | }; |
| 199 | 252 | }, |
| 200 | 253 | created() { |
| 201 | 254 | this.getList(); |
| 202 | 255 | }, |
| 203 | 256 | methods: { |
| 257 | + handleInfo(row){ | |
| 258 | + this.reset(); | |
| 259 | + const id = row.id || this.ids | |
| 260 | + getIncorruptGovernment(id).then(response => { | |
| 261 | + this.form = response.data; | |
| 262 | + //将附件转换为前端可视化数组 | |
| 263 | + if (this.form.files != null && this.form.files !== "") { | |
| 264 | + let fileList = this.form.files.split(";"); | |
| 265 | + fileList.map(item => { | |
| 266 | + let name = item.substring(item.lastIndexOf("/") + 1); | |
| 267 | + this.fileEntityList.push({name: name, url: item}) | |
| 268 | + }) | |
| 269 | + } | |
| 270 | + this.open = true; | |
| 271 | + this.infoDisable = true; | |
| 272 | + this.title = "查看文件资料"; | |
| 273 | + }); | |
| 274 | + }, | |
| 204 | 275 | toInfo(row){ |
| 205 | 276 | //打开当日报修页签 |
| 206 | 277 | this.$tab.openPage("查看详情","/IncorruptGovernment/info",{"IncorruptGovernment":row}) |
| ... | ... | @@ -232,6 +303,7 @@ export default { |
| 232 | 303 | updateBy: null |
| 233 | 304 | }; |
| 234 | 305 | this.fileEntityList = []; |
| 306 | + this.infoDisable = false; | |
| 235 | 307 | this.resetForm("form"); |
| 236 | 308 | }, |
| 237 | 309 | /** 搜索按钮操作 */ |
| ... | ... | @@ -285,6 +357,19 @@ export default { |
| 285 | 357 | let form = this.form; |
| 286 | 358 | //去掉params属性 |
| 287 | 359 | delete form.params; |
| 360 | + //先清空原有的附件 | |
| 361 | + form.files = null; | |
| 362 | + | |
| 363 | + | |
| 364 | + this.fileEntityList.forEach(item => { | |
| 365 | + if (item.raw != null) { | |
| 366 | + formData.append('fileList', item.raw) | |
| 367 | + } else { | |
| 368 | + //将原有的附件拼接到form中 | |
| 369 | + form.files = form.files !== null ? form.files + ";" + item.url : item.url; | |
| 370 | + } | |
| 371 | + }) | |
| 372 | + | |
| 288 | 373 | |
| 289 | 374 | for (let key in form) { |
| 290 | 375 | formData.append(key, form[key] == null ? "" : form[key]) |
| ... | ... | @@ -333,6 +418,75 @@ export default { |
| 333 | 418 | this.download(response.msg); |
| 334 | 419 | }) |
| 335 | 420 | }, |
| 421 | + /** | |
| 422 | + * 文件改变时,限制文件上传格式和大小 | |
| 423 | + * 文件格式只能为docx/doc/pdf/png/jpeg/png/jpg | |
| 424 | + * 大小不超过20M | |
| 425 | + * */ | |
| 426 | + fileChange(file, fileList) { | |
| 427 | + let count = 0; | |
| 428 | + for (let i = 0; i < fileList.length; i++) { | |
| 429 | + // console.log(fileList.length) | |
| 430 | + // console.log(this.fileEntityList[i].name+"111"+file.name) | |
| 431 | + if (fileList[i].name == file.name) { | |
| 432 | + count++; | |
| 433 | + if (count == 2) { | |
| 434 | + this.$message({ | |
| 435 | + message: '已存在此文件!', | |
| 436 | + type: 'warning' | |
| 437 | + }); | |
| 438 | + for (let j = fileList.length; j > 0; j--) { | |
| 439 | + //如果存在此文件,去除新选择的重复文件 | |
| 440 | + if (fileList[j - 1].name == file.name) { | |
| 441 | + fileList.splice(j - 1, 1); | |
| 442 | + i--; | |
| 443 | + return false; | |
| 444 | + } | |
| 445 | + } | |
| 446 | + } | |
| 447 | + } | |
| 448 | + } | |
| 449 | + let fileType = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase(); | |
| 450 | + //格式符合后判断大小 | |
| 451 | + if ("jpg,jpeg,png,gif,jfif,pjpeg,pjp,pdf,doc,docx,xls,xlsx".indexOf(fileType) != -1) { | |
| 452 | + let max5M = file.size / 1024 / 1024 < 100; | |
| 453 | + if (!max5M) { | |
| 454 | + this.$message({ | |
| 455 | + message: '上传文件大小不得超过100M!', | |
| 456 | + type: 'warning' | |
| 457 | + }); | |
| 458 | + fileList = fileList.splice(fileList.length - 1, 1); | |
| 459 | + } else { | |
| 460 | + //符合条件后进行添加 | |
| 461 | + this.fileEntityList = fileList | |
| 462 | + } | |
| 463 | + } else { | |
| 464 | + this.$message({ | |
| 465 | + message: '上传文件只能是 jpg,jpeg,png,gif,jfif,pjpeg,pjp,pdf,doc,docx,xls,xlsx格式!', | |
| 466 | + type: 'warning' | |
| 467 | + }); | |
| 468 | + fileList = fileList.splice(fileList.length - 1, 1); | |
| 469 | + } | |
| 470 | + }, | |
| 471 | + // 删除文件 | |
| 472 | + handleDeleteFile(index) { | |
| 473 | + this.fileEntityList.splice(index, 1); | |
| 474 | + }, | |
| 475 | + /** 文件下载 */ | |
| 476 | + tempDownload(row) { | |
| 477 | + let name = row.name; | |
| 478 | + let url = ""; | |
| 479 | + if (row.raw != null) { | |
| 480 | + url = URL.createObjectURL(row.raw); | |
| 481 | + } else { | |
| 482 | + url = process.env.VUE_APP_BASE_API + row.url; | |
| 483 | + } | |
| 484 | + const a = document.createElement('a') | |
| 485 | + a.setAttribute('download', name) | |
| 486 | + a.setAttribute('target', '_blank') | |
| 487 | + a.setAttribute('href', url); | |
| 488 | + a.click() | |
| 489 | + }, | |
| 336 | 490 | createUrl(file) { |
| 337 | 491 | if (file.raw != null) { |
| 338 | 492 | return URL.createObjectURL(file.raw); | ... | ... |