scan.vue 4.5 KB

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