upload
This commit is contained in:
164
src/pages/xinrui/common/UploadPicts.vue
Normal file
164
src/pages/xinrui/common/UploadPicts.vue
Normal file
@@ -0,0 +1,164 @@
|
||||
<template>
|
||||
<section>
|
||||
<nav-bar :inner="true" title="拍照"></nav-bar>
|
||||
<section class="content mgt186">
|
||||
<div class="image_wraper">
|
||||
<div class="li_box img_box">
|
||||
<img>
|
||||
</div>
|
||||
<div class="li_box iconfont add_pict_icon relative">
|
||||
<input
|
||||
type='file'
|
||||
id='H5moreUp'
|
||||
ref='H5moreUp'
|
||||
accept='image/*'
|
||||
@change="loadImg"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="image_wraper">
|
||||
<div class="image_wraper_i">
|
||||
<img v-show="unimgsrc === ''" src="../../../images/xinrui/nopict.svg">
|
||||
<img v-show="unimgsrc !== ''" id="imgshow">
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="submit-bar">
|
||||
<button class="btn submit-button" :class="{'btn-disabled': formData === ''}" :disabled="disabled" @click="_uploadPict">确认</button>
|
||||
<button class="btn submit-button" @click="handleDelImg">取消</button>
|
||||
<div class="btn submit-button relative">
|
||||
上传
|
||||
<input
|
||||
type='file'
|
||||
id='H5moreUp'
|
||||
ref='H5moreUp'
|
||||
accept='image/*'
|
||||
@change="loadImg"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import NavBar from '@components/NavBar.vue'
|
||||
import {uploadPict, rawmaterialSava} from '@config/getData2.js'
|
||||
// import {rawmaterialSava} from '@config/getData2.js'
|
||||
// import axios from 'axios'
|
||||
// import qs from 'qs'
|
||||
export default {
|
||||
name: 'UploadPicts',
|
||||
components: {
|
||||
NavBar
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
upImgUrl: '',
|
||||
unimgsrc: '',
|
||||
formData: '',
|
||||
disabled: false,
|
||||
result: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loadImg () {
|
||||
// 获取文件
|
||||
let file = document.getElementById('H5moreUp').files[0]
|
||||
// 创建读取文件的对象
|
||||
let reader = new FileReader()
|
||||
// 创建文件读取相关的变量
|
||||
let imgFile
|
||||
// 为文件读取成功设置事件
|
||||
reader.onload = (e) => {
|
||||
imgFile = e.target.result
|
||||
document.getElementById('imgshow').setAttribute('src', imgFile)
|
||||
this.unimgsrc = imgFile
|
||||
}
|
||||
// 正式读取文件
|
||||
reader.readAsDataURL(file)
|
||||
this.formData = new FormData()
|
||||
this.formData.append('file', file)
|
||||
this.formData.append('user', 'laotie')
|
||||
},
|
||||
async _uploadPict () {
|
||||
this.disabled = true
|
||||
if (this.formData === '') {
|
||||
this.disabled = false
|
||||
return
|
||||
}
|
||||
// let uploadUrl = this.$store.getters.imgip + '/api/localStorage/pictures/'
|
||||
// axios.post(this.$store.getters.imgip + '/api/localStorage/pictures/', this.formData, {
|
||||
// Headers: {
|
||||
// 'Content-type': 'application/x-www-form-urlencoded'
|
||||
// }
|
||||
// }).then(res => {
|
||||
// if (res.code === '1') {
|
||||
// this.toast(res.desc)
|
||||
// }
|
||||
// })
|
||||
try {
|
||||
let data = {
|
||||
'formData': this.formData,
|
||||
'flag': true
|
||||
}
|
||||
let res = await uploadPict(data)
|
||||
if (res.code === '1') {
|
||||
// this.upImgUrl = uploadUrl + res.result.path
|
||||
this.toast(res.desc)
|
||||
this.result = res.result
|
||||
// this.formData = ''
|
||||
this._rawmaterialSava()
|
||||
} else {
|
||||
this.Dialog(res.desc)
|
||||
}
|
||||
this.disabled = false
|
||||
} catch (e) {
|
||||
this.disabled = false
|
||||
}
|
||||
},
|
||||
async _rawmaterialSava () {
|
||||
let obj = this.$store.getters.materObj !== '' ? Object.assign({}, this.$store.getters.materObj, this.result, {business_type: '01'}) : Object.assign({}, this.result, {business_type: '01'})
|
||||
let res = await rawmaterialSava(obj)
|
||||
if (res.code === '1') {
|
||||
this.$router.back()
|
||||
} else {
|
||||
this.Dialog(res.desc)
|
||||
}
|
||||
},
|
||||
handleDelImg () {
|
||||
this.unimgsrc = ''
|
||||
this.formData = ''
|
||||
this.$refs.H5moreUp.value = ''
|
||||
document.getElementById('imgshow').removeAttribute('src')
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="stylus" scoped>
|
||||
@import '~@style/mixin'
|
||||
// >>>.content
|
||||
// height calc(100% - 2rem)
|
||||
.image_wraper
|
||||
width 100%
|
||||
padding-top .5rem
|
||||
.li_box
|
||||
float left
|
||||
width 30%
|
||||
.image_wraper_i
|
||||
position relative
|
||||
_wh(100%, 100%)
|
||||
overflow-y auto
|
||||
z-index 99
|
||||
img
|
||||
_wh(100%, auto)
|
||||
z-index 99
|
||||
border-radius .1rem
|
||||
#H5moreUp
|
||||
position absolute
|
||||
top 0
|
||||
left 0
|
||||
_wh(100%, 100%)
|
||||
opacity 0
|
||||
z-index 100
|
||||
</style>
|
||||
@@ -160,7 +160,7 @@ export default {
|
||||
},
|
||||
UploadPict () {
|
||||
this.$router.push({
|
||||
path: '/UploadPict',
|
||||
path: '/UploadPicts',
|
||||
query: {url: 'EquipRepair'}
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user