more.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div class="nfc-popup">
  3. <van-popup v-model="visible" get-container="nfc-popup" lock-scroll :close-on-click-overlay="closeOverlay">
  4. <div class="nfc-panel">
  5. <div>
  6. <p v-if="showBottomBox" class="top-text">将手机背部靠近NFC标签扫描</p>
  7. <div class="image-box">
  8. <img class="nfc-image" v-show="nfcImage" :src="nfcImage" alt="" @click="nfcTakePhotos">
  9. </div>
  10. <div v-if="showBottomBox" class="bottom-box">
  11. <div>
  12. <img :src="require('../../assets/img/icon/NFC扫描-01.png')" />
  13. <span>NFC</span>
  14. </div>
  15. <div>
  16. <img :src="require('../../assets/img/icon/camera.png')" />
  17. <span @click="nfcTakePhotos">拍照</span>
  18. </div>
  19. </div>
  20. <div v-else>
  21. <select-cell title="点击选择NFC列表" @change="changeNFC" v-model="selectNFC" :prop="prop" :dataList="dataList"/>
  22. <van-button v-if="showBtn" type="primary" size="small" block plain @click="onConfirm">确定</van-button>
  23. </div>
  24. </div>
  25. </div>
  26. <input v-show="false" ref="upload" type='file' accept="image/*" @change="fileChange"/>
  27. </van-popup>
  28. </div>
  29. </template>
  30. <script>
  31. import SelectCell from "@/components/selectCell";
  32. import {baseImg} from "@/views/menu/LZRegister/api";
  33. import {upload} from "@/api/public";
  34. import ImageCompressor from "js-image-compressor";
  35. export default {
  36. components:{SelectCell},
  37. data(){
  38. return {
  39. //nfc弹窗
  40. visible:false,
  41. //上传的nfc图片
  42. nfcImage:null,
  43. //是否显示底部按钮
  44. showBottomBox:true,
  45. //nfc数据
  46. dataList:[],
  47. //选中的nfc
  48. selectNFC:null,
  49. //自定义字段
  50. prop:{
  51. label:'checkName',
  52. value:'nfccdoe'
  53. },
  54. //是否可点击遮罩层关闭
  55. closeOverlay:true,
  56. showBtn:false,
  57. }
  58. },
  59. watch:{
  60. visible(val){
  61. if(!this.visible){
  62. this.clear();
  63. }
  64. }
  65. },
  66. methods:{
  67. onConfirm(){
  68. let data = {
  69. nfcCode:this.selectNFC,
  70. url:this.nfcImage,
  71. }
  72. this.$emit('change',data);
  73. this.visible = false;
  74. this.clear();
  75. },
  76. //切换nfc后可点击退出
  77. changeNFC(){
  78. this.showBtn = true;
  79. },
  80. //清空数据
  81. clear(){
  82. this.nfcImage = null;
  83. this.showBottomBox = true;
  84. this.selectNFC = null;
  85. this.dataList = [];
  86. this.closeOverlay = true;
  87. },
  88. //显示弹窗
  89. show(list){
  90. this.visible = true;
  91. this.dataList = list;
  92. console.log(this.dataList,'datalist')
  93. },
  94. //上传前
  95. async fileChange(e){
  96. let file = e.target.files[0];
  97. // let fileName = e.target.files[0].name;
  98. let imgFile = await this.imageCompress(file);
  99. let formData = new FormData();
  100. formData.append('file',imgFile);
  101. upload(formData,'image').then(res=>{
  102. //上传成功后,将图片显示在页面上并禁用退出
  103. this.nfcImage = res.data.url;
  104. this.showBottomBox = false;
  105. this.closeOverlay = false;
  106. })
  107. },
  108. //压缩图片
  109. imageCompress(file){
  110. return new Promise((resolve,reject)=>{
  111. new ImageCompressor({
  112. file,
  113. quality: 0.6,
  114. success: (result) => {
  115. //this.$toast('图片压缩成功')
  116. console.log(result,'图片压缩后')
  117. let img = new File([result], result.name, {
  118. width: result.width,
  119. height: result.height,
  120. type: result.type,
  121. });
  122. resolve(img);
  123. },
  124. error: (e) => {
  125. console.log('imageError:'+e);
  126. this.$toast('图片压缩失败')
  127. reject(e);
  128. },
  129. });
  130. });
  131. },
  132. //拍照
  133. nfcTakePhotos(){
  134. this.$refs.upload.click();
  135. },
  136. }
  137. }
  138. </script>
  139. <style lang="scss">
  140. #app{
  141. .nfc-popup{
  142. .van-popup--center{
  143. border-radius: 20px;
  144. }
  145. }
  146. }
  147. </style>
  148. <style scoped lang="scss">
  149. .nfc-panel{
  150. width: 400px;
  151. background:url('../../assets/img/NFCphone.png') center no-repeat;
  152. background-size: 50%;
  153. >div{
  154. padding: 30px;
  155. }
  156. }
  157. .top-text{
  158. text-align: center;
  159. font-size: 26px;
  160. }
  161. .image-box{
  162. width: 100%;
  163. height: 350px;
  164. padding: 20px;
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. }
  169. .nfc-image{
  170. width: 300px;
  171. height: 300px;
  172. background-color: #fff;
  173. }
  174. .bottom-box{
  175. display: flex;
  176. justify-content: space-around;
  177. align-items: center;
  178. >div{
  179. display: flex;
  180. flex-direction: column;
  181. &:active{
  182. opacity: .5;
  183. }
  184. >img{
  185. width: 70px;
  186. height: 70px;
  187. }
  188. >span{
  189. text-align: center;
  190. font-size: 25px;
  191. }
  192. }
  193. }
  194. </style>