scanC.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="box">
  3. <button type="default" @click="getCode">点击扫一扫</button>
  4. <view class="">
  5. <view class="">
  6. 昵称: {{ data.nickname }}
  7. </view>
  8. <view class="">
  9. 手机号: {{ data.phone }}
  10. </view>
  11. <view class="">
  12. 款式: {{ data.style }}
  13. </view>
  14. <view class="">
  15. 价格: {{ data.price }}
  16. </view>
  17. <view class="">
  18. 出库时间: {{ data.time }}
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import {
  25. LookTime
  26. } from '../../apis/fangwei.js'
  27. import {
  28. location,
  29. } from '../../apis/user.js';
  30. var jweixin = require('jweixin-module');
  31. export default {
  32. name: 'ShareIndex',
  33. data() {
  34. return {
  35. model: '',
  36. data: {},
  37. }
  38. },
  39. onLoad: function(option) {
  40. // const result = 'http://fangw.jiuweiyun.cn/api/auth/2212091738582BQYOWI60104'
  41. // var site = result.lastIndexOf('\/')
  42. // var params = result.substring(site + 1, result.length)
  43. // this.code = window.encodeURIComponent(params)
  44. // this.getTime(this.code)
  45. // 用于扫码发货
  46. uni.getSystemInfo({
  47. success: res => {
  48. this.model = res.model
  49. }
  50. })
  51. if (this.model == 'iPhone') {
  52. uni.setStorageSync('url', window.location.href.split('#')[0])
  53. }
  54. },
  55. methods: {
  56. getTime(params) {
  57. LookTime({ code: params }).then(res => {
  58. if (res.code == 200) {
  59. this.data = res.data
  60. } else {
  61. uni.showModal({
  62. title: '错误提示',
  63. content: res.message || '获取信息失败',
  64. showCancel: false
  65. })
  66. }
  67. })
  68. },
  69. getCode() {
  70. let link = window.location.href;
  71. let url = this.model == 'iPhone' ? uni.getStorageSync('url') : link
  72. location({
  73. url
  74. }).then(res => {
  75. if (res.code == 200) {
  76. let data = JSON.parse(res.data);
  77. // 判断是否支持扫码
  78. jweixin.config({
  79. debug: false, //开启debug模式.正式环境设置为false,测试环境设置为true
  80. appId: data.appId,
  81. timestamp: data.timestamp,
  82. nonceStr: data.nonceStr,
  83. signature: data.signature,
  84. jsApiList: ['scanQRCode'] //根据需要看需要哪些SDK的功能
  85. });
  86. // sdk加载完成后执行
  87. jweixin.ready(() => {
  88. jweixin.checkJsApi({
  89. jsApiList: ['scanQRCode'],
  90. success: res => {
  91. if (res.checkResult.scanQRCode == false) {
  92. alert('你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!');
  93. return;
  94. }
  95. }
  96. });
  97. jweixin.error(res => {
  98. console.log(res.errMsg, '错误消息');
  99. });
  100. //扫码
  101. jweixin.scanQRCode({
  102. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  103. scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  104. success: res => {
  105. var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
  106. var site = result.lastIndexOf('\/')
  107. var params = result.substring(site + 1, result.length)
  108. this.code = window.encodeURIComponent(params)
  109. this.getTime(this.code)
  110. },
  111. fail: () => {
  112. location.href = location.protocol + '//' + location.host +
  113. "/pages/scanC/scanC";
  114. },
  115. });
  116. });
  117. } else {
  118. uni.showModal({
  119. title: '错误提示',
  120. content: res.message || '获取信息失败',
  121. showCancel: false
  122. })
  123. }
  124. })
  125. }
  126. }
  127. }
  128. </script>
  129. <style scoped lang="scss" scoped>
  130. .box {
  131. padding: 30rpx;
  132. font-size: 30rpx;
  133. view {
  134. margin-top: 20rpx;
  135. }
  136. }
  137. #share_container {
  138. width: 100%;
  139. height: 100%;
  140. display: flex;
  141. justify-content: space-between;
  142. flex-direction: column;
  143. }
  144. #imgWrapper {
  145. flex: 1;
  146. @include flex();
  147. .showCan {
  148. width: 680rpx;
  149. height: 960rpx;
  150. border-radius: 14rpx;
  151. box-shadow:0px 0px 23px 2px rgba(194,133,58,0.5);
  152. }
  153. }
  154. .sharetext {
  155. font-size: 80rpx;
  156. text-align: center;
  157. margin: 8rpx 0;
  158. box-sizing: border-box;
  159. padding: 30rpx 24rpx;
  160. }
  161. </style>