shopidgo.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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(opt) {
  15. if(opt.scene){
  16. var num=opt.scene;
  17. //var num = 'AFA7C75619124C70802A19437DDD80A7'
  18. var shopId=this.insertStr(num,8,"-");
  19. shopId=this.insertStr(shopId,13,"-");
  20. shopId=this.insertStr(shopId,18,"-");
  21. shopId=this.insertStr(shopId,23,"-");
  22. console.log(shopId)
  23. uni.reLaunch ({
  24. url:'../login/empower?shopId='+shopId
  25. })
  26. }else{
  27. //var shopId='1F12DB68-D8E8-4B76-9E20-287ACB72889F'
  28. uni.reLaunch ({
  29. url:'../login/empower'
  30. })
  31. }
  32. },
  33. methods: {
  34. insertStr(soure, start, newStr){
  35. return soure.slice(0, start) + newStr + soure.slice(start);
  36. },
  37. scan(){
  38. var that=this;
  39. uni.scanCode({
  40. success: function (res) {
  41. console.log('条码类型:' + res.scanType);
  42. console.log('条码内容:' + res.result);
  43. that.url=res.result;
  44. that.shopId=that.getHashQuery('shopId')
  45. if(that.shopId){
  46. that.gologin()
  47. }else{
  48. uni.showToast({
  49. title: '请扫码正确的二维码',
  50. icon: 'none',
  51. duration: 3000
  52. });
  53. }
  54. console.log(that.shopId)
  55. }
  56. });
  57. },
  58. gologin(){
  59. uni.navigateTo({
  60. url:'../login/login?shopId='+this.shopId
  61. })
  62. },
  63. getHashQuery (query) {
  64. if (this.url.indexOf(query) > -1) {
  65. let cur = this.url.slice(this.url.indexOf(query) + query.length + 1, this.url.length)
  66. if (cur.indexOf('&') > -1) {
  67. return cur.slice(0, cur.indexOf('&'))
  68. } else {
  69. return cur
  70. }
  71. } else {
  72. return false
  73. }
  74. }
  75. }
  76. }
  77. </script>
  78. <style scoped>
  79. </style>