scan.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view>
  3. <!-- <view class="naver" @click="smit">
  4. 扫码登录
  5. </view> -->
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. //潜山
  13. qians:'',
  14. uehg:1
  15. };
  16. },
  17. onLoad() {
  18. // this.uehg = 1
  19. this.scanAction()
  20. },
  21. onShow() {
  22. // this.uehg = 1
  23. // this.scanAction()
  24. },
  25. onHide() {
  26. // this.uehg = 2
  27. },
  28. methods:{
  29. // smit(){
  30. // this.scanAction()
  31. // },
  32. //扫码功能
  33. scanAction() {
  34. // if(this.uehg == 1){
  35. const app = getApp();
  36. wx.scanCode({
  37. onlyFromCamera: true,
  38. scanType: ['qrCode', 'barCode'],
  39. //结果处理
  40. success: res => this.dealScanCode(res.result),
  41. fail: (e) => {
  42. if (e && e.errMsg && e.errMsg.indexOf('scanCode:fail cancel') != -1) {
  43. return;
  44. }
  45. wx.showToast({ title: '扫码失败', icon: 'none', })
  46. }
  47. });
  48. // }else{
  49. // return
  50. // }
  51. },
  52. // 判断连接
  53. dealScanCode(result) {
  54. const app = getApp();
  55. console.log(result,123)
  56. let str = result
  57. // https://qsfy.qs163.cn/
  58. this.qians = str.includes('https://qsdp.qs163.cn/prod-api/auth/scanCode')
  59. console.log(str.includes('https://qsdp.qs163.cn/prod-api/auth/scanCode'))
  60. // 潜山
  61. // this.qians = str.includes('https://qsxyakm.qs163.cn/prod-api/applet/scanQr')
  62. // /、岳西 https://yxxy.qs163.cn https://qsfy.qs163.cn
  63. if(this.qians){
  64. console.log(123098)
  65. // wx.navigateTo({
  66. // url: '/add/pages/addvacfrom/wufa?code=' + this.qians
  67. // })
  68. uni.request({
  69. url: result,
  70. data:{
  71. // pid:this.companyId
  72. },
  73. success: function(res) {
  74. console.log(res.data)
  75. if(res.data.code==200){
  76. wx.navigateTo({
  77. url: '/add/pages/addvacfrom/wufa?code=' + res.data.data
  78. })
  79. console.log(3456)
  80. }else {
  81. wx.navigateBack({
  82. delta: 1 //想要返回的层级
  83. })
  84. wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000})
  85. }
  86. },
  87. });
  88. }else{
  89. wx.navigateBack({
  90. delta: 1 //想要返回的层级
  91. })
  92. uni.showToast({ title: '请扫描正确的二维码', icon: 'none', duration: 3000})
  93. }
  94. // let index = str.indexOf("/");
  95. // console.log(index)
  96. // let id = str.substring('/');
  97. // console.log(id)
  98. // this.bindAccount(result)
  99. // app.log("scan:" + result)
  100. // if (!result || !result.lastIndexOf) {
  101. // wx.showToast({ title: '二维码错误', icon: 'none', duration: 2000 })
  102. // return;
  103. // }
  104. // 具体的连接处理
  105. // if (result.lastIndexOf('synthetical=') != -1) {
  106. // bindAccount(result);
  107. // return;
  108. // }
  109. //无效的二维码
  110. // wx.showToast({ title: '二维码错误', icon: 'none', duration: 2000 })
  111. },
  112. //处理连接
  113. bindAccount(param){
  114. // 截取字符串
  115. let groupNum = getUrlParam(param, 'chatID')
  116. let groupType = getUrlParam(param, 'type');
  117. },
  118. // 提供外部的接口
  119. // module.exports = {
  120. // scanAction,
  121. // dealScanCode,
  122. // getUrlParam
  123. // }
  124. // 正则表达式截取字符串的方法
  125. getUrlParam(url, name) {
  126. // 正则筛选地址栏
  127. let reg = new RegExp("(^|&|/?|//)" + name + "=([^&]*)(&|$)");
  128. // 匹配目标参数
  129. let result = url.substr(1).match(reg);
  130. console.log(result)
  131. //返回参数值
  132. // return result ? decodeURIComponent(result[2]) : null;
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss">
  138. .naver{
  139. width: 85%;
  140. height: 90upx;
  141. font-size: 31upx;
  142. font-family: PingFang SC;
  143. font-weight: 400;
  144. color: #FFFFFF;
  145. line-height: 90upx;
  146. background-color: #1678FF;
  147. margin-left: 50%;
  148. transform: translateX(-50%);
  149. border-radius: 14upx;
  150. text-align: center;
  151. margin-top: 250upx;
  152. }
  153. </style>