|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <nav-bar/> |
| 4 | + |
| 5 | + <el-container> |
| 6 | + <el-header>图片识别模块</el-header> |
| 7 | + <el-container> |
| 8 | + <el-aside width="500px"> |
| 9 | + |
| 10 | + <div>点击下面的加号 上传图片</div> |
| 11 | + <el-upload |
| 12 | + :data="dataObj" |
| 13 | + :action="uploadUrl" |
| 14 | + :limit="100" |
| 15 | + :on-preview="handlePictureCardPreview" |
| 16 | + :before-upload="handleBeforeUpload" |
| 17 | + :on-success="handleSuccess" |
| 18 | + :on-remove="handleRemove" |
| 19 | + list-type="picture-card"> |
| 20 | + <i class="el-icon-plus" /> |
| 21 | + </el-upload> |
| 22 | + <el-dialog :visible.sync="dialogVisible"> |
| 23 | + <img :src="dialogImageUrl" width="100%" alt=""> |
| 24 | + </el-dialog> |
| 25 | + |
| 26 | + </el-aside> |
| 27 | + <el-main> |
| 28 | + <el-input v-model="desc" type="textarea" rows="50"/> |
| 29 | + </el-main> |
| 30 | + </el-container> |
| 31 | + </el-container> |
| 32 | + </div> |
| 33 | +</template> |
| 34 | + |
| 35 | +<script> |
| 36 | +import request from '../../utils/request' |
| 37 | +
|
| 38 | +export default { |
| 39 | + name: 'Upload', |
| 40 | + data() { |
| 41 | + return { |
| 42 | + uploadUrl: 'http://up.qiniu.com', |
| 43 | + dialogImageUrl: '', |
| 44 | + dialogVisible: false, |
| 45 | + desc: '', |
| 46 | + dataObj: {} |
| 47 | + } |
| 48 | + }, |
| 49 | + created() { |
| 50 | + // 加载页面时候需要获取本次上传七牛的 Token ,并且赋值 |
| 51 | + const that = this |
| 52 | + request.get('/api/getToken').then(res => { |
| 53 | + // console.log(that.dataObj) |
| 54 | + that.dataObj = { 'token': res.data.token } |
| 55 | + console.log(that.dataObj) |
| 56 | + }) |
| 57 | + }, |
| 58 | + methods: { |
| 59 | + handleRemove(file, fileList) { |
| 60 | + console.log(file, fileList) |
| 61 | + }, |
| 62 | + handlePictureCardPreview(file) { |
| 63 | + console.log(file) |
| 64 | + this.dialogImageUrl = file.url |
| 65 | + this.dialogVisible = true |
| 66 | + }, |
| 67 | + handleBeforeUpload(file) { |
| 68 | + const name = file.name |
| 69 | + // 上传文件后缀 |
| 70 | + const extName = name.substring(name.lastIndexOf('.'), name.length).toLowerCase() |
| 71 | + const data = new Date() |
| 72 | + const year = data.getFullYear() |
| 73 | + const month = data.getMonth() + 1 |
| 74 | + const day = data.getDate() |
| 75 | + const dataOrder = year + '' + month + '' + day + '' + data.getHours() + '' + data.getMinutes() |
| 76 | + this.dataObj.key = dataOrder + '_' + Math.floor(Math.random() * 10000) + extName |
| 77 | + console.log(this.dataObj) |
| 78 | + }, |
| 79 | + handleSuccess(response, file) { |
| 80 | + console.log(file) |
| 81 | + console.log(response) |
| 82 | + this.desc = response.data.words |
| 83 | + }, |
| 84 | + handleUpload(response) { |
| 85 | + console.log(response) |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | +</script> |
| 90 | + |
| 91 | +<style scoped> |
| 92 | + .el-header, .el-footer { |
| 93 | + background-color: #B3C0D1; |
| 94 | + color: #333; |
| 95 | + text-align: center; |
| 96 | + line-height: 60px; |
| 97 | + } |
| 98 | +
|
| 99 | + .el-aside { |
| 100 | + background-color: #D3DCE6; |
| 101 | + color: #333; |
| 102 | + text-align: center; |
| 103 | + line-height: 200px; |
| 104 | + } |
| 105 | +
|
| 106 | + .el-main { |
| 107 | + background-color: #E9EEF3; |
| 108 | + color: #333; |
| 109 | + text-align: center; |
| 110 | + line-height: 160px; |
| 111 | + } |
| 112 | +
|
| 113 | + body > .el-container { |
| 114 | + margin-bottom: 40px; |
| 115 | + } |
| 116 | +
|
| 117 | + .el-container:nth-child(5) .el-aside, |
| 118 | + .el-container:nth-child(6) .el-aside { |
| 119 | + line-height: 260px; |
| 120 | + } |
| 121 | +
|
| 122 | + .el-container:nth-child(7) .el-aside { |
| 123 | + line-height: 320px; |
| 124 | + } |
| 125 | +</style> |
0 commit comments