|
|
@@ -19,7 +19,7 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <input v-show="false" ref="upload" type="file" accept="image/*" @change="fileChange" />
|
|
|
+ <!-- <input v-show="false" ref="upload" type="file" accept="image/*" @change="fileChange" /> -->
|
|
|
<!-- <uploader v-show="false" ref="imageUpload" v-model="nfcImage" multiple :maxCount="1" :deletable="false"/>-->
|
|
|
</van-popup>
|
|
|
</div>
|
|
|
@@ -27,13 +27,14 @@
|
|
|
|
|
|
<script>
|
|
|
import { baseImg } from '@/views/menu/LZRegister/api'
|
|
|
-import { upload } from '@/api/public'
|
|
|
+import { upload, uploadBase64 } from '@/api/public'
|
|
|
import ImageCompressor from 'js-image-compressor'
|
|
|
import { Toast } from 'vant'
|
|
|
export default {
|
|
|
name: 'index',
|
|
|
data() {
|
|
|
return {
|
|
|
+ imageList:[],
|
|
|
//nfc弹窗
|
|
|
visible: false,
|
|
|
//nfc图片(base64)
|
|
|
@@ -52,64 +53,43 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
window.openNFCScanCallBack = this.openNFCScanCallBack
|
|
|
+ window.openCameraCallBack = this.openCameraCallBack
|
|
|
},
|
|
|
methods: {
|
|
|
- //上传前
|
|
|
- async fileChange(e) {
|
|
|
- let file = e.target.files[0]
|
|
|
- let fileName = e.target.files[0].name
|
|
|
- let imgFile = await this.imageCompress(file)
|
|
|
- console.log(imgFile, 'imgFile')
|
|
|
- let formData = new FormData()
|
|
|
- formData.append('file', imgFile)
|
|
|
- upload(formData, 'image').then(res => {
|
|
|
- console.log(res, 'resssss')
|
|
|
- // this.nfcImage = baseImg.base;
|
|
|
- this.$emit('change', baseImg)
|
|
|
- this.visible = false
|
|
|
-
|
|
|
- // this.showBottomBox = false;
|
|
|
- })
|
|
|
- },
|
|
|
- //压缩图片
|
|
|
- imageCompress(file) {
|
|
|
- let imageCom = new Promise((resolve, reject) => {
|
|
|
- new ImageCompressor({
|
|
|
- file,
|
|
|
- quality: 0.6,
|
|
|
- success: result => {
|
|
|
- console.log(result, '图片压缩后')
|
|
|
- let img = new File([result], result.name, {
|
|
|
- width: result.width,
|
|
|
- height: result.height,
|
|
|
- type: result.type
|
|
|
- })
|
|
|
- resolve(img)
|
|
|
- },
|
|
|
- error: e => {
|
|
|
- console.log('imageError:' + e)
|
|
|
- this.$toast('图片压缩失败')
|
|
|
- reject(e)
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- return imageCom
|
|
|
- },
|
|
|
nfcTakePhotos() {
|
|
|
- this.$refs.upload.click()
|
|
|
+ this.useCamera(1)
|
|
|
},
|
|
|
submitNFC() {
|
|
|
this.useNFC()
|
|
|
- // Toast.success(this.openNFCScanCallBack())
|
|
|
-
|
|
|
- // alert(this.objNfc)
|
|
|
+ },
|
|
|
+ openCameraCallBack(data) {
|
|
|
+ let img = JSON.parse(data)
|
|
|
+ this.content = data
|
|
|
+ let params = {
|
|
|
+ extension: img.extension,
|
|
|
+ content: img.content
|
|
|
+ }
|
|
|
+ uploadBase64(params)
|
|
|
+ .then(res => {
|
|
|
+ /*上传成功*/
|
|
|
+ this.$toast.success('上传成功')
|
|
|
+ this.visible=false
|
|
|
+ this.imageList.push({ name: res.data.name, url: imgUrl(res.data.url), imgPath: res.data.url })
|
|
|
+ this.$emit('input', this.imageList)
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ /*上传失败*/
|
|
|
+
|
|
|
+ this.$toast.fail('上传失败')
|
|
|
+ this.fileList.splice(this.fileList.length - 1, 1)
|
|
|
+ })
|
|
|
},
|
|
|
openNFCScanCallBack(data) {
|
|
|
this.objNfc = JSON.parse(data)
|
|
|
if (this.objNfc.errorCode == 0) {
|
|
|
this.$emit('changeNFC', this.objNfc.content)
|
|
|
Toast.success('扫描成功')
|
|
|
-
|
|
|
+
|
|
|
this.visible = false
|
|
|
} else {
|
|
|
Toast.error(this.objNfc.errorString)
|