scancode.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <button type="default" @click="buclick">点击微信扫一扫</button>
  3. </template>
  4. <script>
  5. import { _API_GzhWebInits } from '@/apis/verify.js'
  6. import { mapState } from 'vuex'
  7. export default {
  8. name: 'ShareIndex',
  9. data() {
  10. return {
  11. src: ''
  12. }
  13. },
  14. computed: {
  15. ...mapState([
  16. 'userinfo'
  17. ])
  18. },
  19. created() {
  20. const script = document.createElement('script')
  21. script.type = 'text/javascript'
  22. script.src = 'http://res.wx.qq.com/open/js/jweixin-1.4.0.js'
  23. document.getElementsByTagName('head')[0].appendChild(script)
  24. script.onload = () => {
  25. _API_GzhWebInits().then(res => {
  26. console.log(window.location.pathname.split('/'))
  27. console.log(res)
  28. wx.config({
  29. debug: false, // 开启调试模式
  30. appId: res.appId, // 必填,公众号的唯一标识
  31. timestamp: res.timestamp, // 必填,生成签名的时间戳
  32. nonceStr: res.nonceStr, // 必填,生成签名的随机串
  33. signature: res.signature, // 必填,签名,见附录1
  34. jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  35. });
  36. // wx.config(res)
  37. wx.ready(() => {
  38. wx.scanQRCode({
  39. needResult: 0, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  40. scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
  41. success: function (res) {
  42. var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
  43. alert(result);
  44. }
  45. });
  46. })
  47. })
  48. }
  49. }
  50. }
  51. </script>
  52. <style scoped lang="scss">
  53. #share_container {
  54. width: 100%;
  55. height: 100%;
  56. display: flex;
  57. justify-content: space-between;
  58. flex-direction: column;
  59. }
  60. #imgWrapper {
  61. flex: 1;
  62. @include flex();
  63. .showCan {
  64. width: 680rpx;
  65. height: 960rpx;
  66. border-radius: 14rpx;
  67. box-shadow:0px 0px 23px 2px rgba(194,133,58,0.5);
  68. }
  69. }
  70. .sharetext {
  71. font-size: 80rpx;
  72. text-align: center;
  73. margin: 8rpx 0;
  74. box-sizing: border-box;
  75. padding: 30rpx 24rpx;
  76. }
  77. </style>