scanCode.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="content">
  3. <image @click="scan" class="img" mode="widthFix" src="../../static/img/lQDPDhs0QZY4xBXNAtDNAZWw7dBth6OpB2gCJkosywCAAA_405_720.jpg" ></image>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. url: '',
  11. shopid:'',
  12. }
  13. },
  14. onLoad() {
  15. },
  16. methods: {
  17. scan(){
  18. var that=this;
  19. uni.scanCode({
  20. success: function (res) {
  21. console.log(res)
  22. console.log('条码类型:' + res.scanType);
  23. if(res.scanType=='WX_CODE'){
  24. that.url=res.path;
  25. that.shopId=that.getHashQuery('scene')
  26. that.shopId=that.insertStr(that.shopId,8,"-");
  27. that.shopId=that.insertStr(that.shopId,13,"-");
  28. that.shopId=that.insertStr(that.shopId,18,"-");
  29. that.shopId=that.insertStr(that.shopId,23,"-");
  30. console.log(that.shopId)
  31. if(that.shopId){
  32. that.gologin()
  33. }else{
  34. uni.showToast({
  35. title: '请扫码正确的二维码',
  36. icon: 'none',
  37. duration: 3000
  38. });
  39. }
  40. }else{
  41. console.log('条码内容:' + res.result);
  42. that.url=res.result;
  43. that.shopId=that.getHashQuery('shopId')
  44. if(that.shopId){
  45. that.gologin()
  46. }else{
  47. uni.showToast({
  48. title: '请扫码正确的二维码',
  49. icon: 'none',
  50. duration: 3000
  51. });
  52. }
  53. }
  54. }
  55. });
  56. },
  57. insertStr(soure, start, newStr){
  58. return soure.slice(0, start) + newStr + soure.slice(start);
  59. },
  60. gologin(){
  61. uni.navigateTo({
  62. url:'../login/login?shopId='+this.shopId
  63. })
  64. },
  65. getHashQuery (query) {
  66. if (this.url.indexOf(query) > -1) {
  67. let cur = this.url.slice(this.url.indexOf(query) + query.length + 1, this.url.length)
  68. if (cur.indexOf('&') > -1) {
  69. return cur.slice(0, cur.indexOf('&'))
  70. } else {
  71. return cur
  72. }
  73. } else {
  74. return false
  75. }
  76. }
  77. }
  78. }
  79. </script>
  80. <style scoped>
  81. .content{
  82. height: 100vh;
  83. background: #000000;
  84. display: flex;
  85. align-items: flex-end;
  86. }
  87. .img{
  88. width: 750rpx;
  89. }
  90. </style>