scan.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view>
  3. <div class="jhyyes">
  4. <img src="/static/sm.png" alt="" class="img">
  5. </div>
  6. <view class="naver" @click="smit">
  7. 扫码粗查
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import url from "@/util/url";
  13. export default {
  14. data() {
  15. return {
  16. //潜山
  17. qians:'',
  18. uehg:1,
  19. phonhe:'',
  20. url:url
  21. };
  22. },
  23. onLoad() {
  24. // this.uehg = 1
  25. // this.params.parentPhone = uni.getStorageSync('phone')
  26. console.log(url.host,345)
  27. let token = uni.getStorageSync('phone')
  28. this.phonhe = token
  29. // if(!token){
  30. // uni.redirectTo({
  31. // url: '/pages/login/login'
  32. // })
  33. // return false
  34. // }
  35. this.scanAction()
  36. },
  37. onShow() {
  38. // this.uehg = 1
  39. // this.scanAction()
  40. console.log(34)
  41. },
  42. onHide() {
  43. // this.uehg = 2
  44. console.log(344)
  45. },
  46. methods:{
  47. smit(){
  48. this.scanAction()
  49. },
  50. //扫码功能
  51. scanAction() {
  52. // if(this.uehg == 1){
  53. const app = getApp();
  54. wx.scanCode({
  55. onlyFromCamera: true,
  56. scanType: ['qrCode', 'barCode'],
  57. //结果处理
  58. success: res => this.dealScanCode(res.result),
  59. fail: (e) => {
  60. if (e && e.errMsg && e.errMsg.indexOf('scanCode:fail cancel') != -1) {
  61. return;
  62. }
  63. wx.showToast({ title: '扫码失败', icon: 'none', })
  64. }
  65. });
  66. // }else{
  67. // return
  68. // }
  69. },
  70. // 判断连接
  71. dealScanCode(result) {
  72. // console.log(result)
  73. const app = getApp();
  74. console.log(result,123)
  75. let str = result
  76. // 潜山
  77. // this.qians = str.includes('https://qsxyakm.qs163.cn/prod-api/applet/scanQr')
  78. // /、岳西 https://yxxy.qs163.cn
  79. this.qians = str
  80. // console.log(str.includes('https://yuexi.0da.com/applet/scanQr'))
  81. // url.host
  82. if(this.qians){
  83. console.log(123098)
  84. uni.request({
  85. url: url.host + '/gateway/query/queryReportNum',
  86. method: 'POST',
  87. header: {
  88. 'Content-Type': 'application/x-www-form-urlencoded',
  89. 'X-Requested-With': 'xmlhttprequest'
  90. },
  91. data:{
  92. queryPhone:this.phonhe,
  93. reportNumber:result
  94. // pid:this.companyId
  95. },
  96. success: function(res) {
  97. console.log(res.data)
  98. if(res.data.code==200){
  99. let hjees = JSON.stringify(res.data.data)
  100. wx.redirectTo({
  101. url: '/pages/home/recordtwo?code=' + hjees
  102. })
  103. console.log(3456)
  104. }else {
  105. wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000})
  106. setTimeout(function () {
  107. wx.navigateBack({
  108. delta: 1 //想要返回的层级
  109. })
  110. }, 1000);
  111. }
  112. },
  113. });
  114. }else{
  115. uni.showToast({ title: '请扫描正确的二维码', icon: 'none', duration: 3000})
  116. wx.navigateBack({
  117. delta: 1 //想要返回的层级
  118. })
  119. }
  120. // let index = str.indexOf("/");
  121. // console.log(index)
  122. // let id = str.substring('/');
  123. // console.log(id)
  124. // this.bindAccount(result)
  125. // app.log("scan:" + result)
  126. // if (!result || !result.lastIndexOf) {
  127. // wx.showToast({ title: '二维码错误', icon: 'none', duration: 2000 })
  128. // return;
  129. // }
  130. // 具体的连接处理
  131. // if (result.lastIndexOf('synthetical=') != -1) {
  132. // bindAccount(result);
  133. // return;
  134. // }
  135. //无效的二维码
  136. // wx.showToast({ title: '二维码错误', icon: 'none', duration: 2000 })
  137. },
  138. //处理连接
  139. bindAccount(param){
  140. // 截取字符串
  141. let groupNum = getUrlParam(param, 'chatID')
  142. let groupType = getUrlParam(param, 'type');
  143. },
  144. // 提供外部的接口
  145. // module.exports = {
  146. // scanAction,
  147. // dealScanCode,
  148. // getUrlParam
  149. // }
  150. // 正则表达式截取字符串的方法
  151. getUrlParam(url, name) {
  152. // 正则筛选地址栏
  153. let reg = new RegExp("(^|&|/?|//)" + name + "=([^&]*)(&|$)");
  154. // 匹配目标参数
  155. let result = url.substr(1).match(reg);
  156. console.log(result)
  157. //返回参数值
  158. // return result ? decodeURIComponent(result[2]) : null;
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss">
  164. .jhyyes{
  165. display: flex;
  166. justify-content: center;
  167. margin-top: 200upx;
  168. }
  169. .img{
  170. width: 258upx;
  171. height: 251upx;
  172. // margin: auto;
  173. // margin-left: 50%;
  174. // transform: translateX(-50%);
  175. }
  176. .naver{
  177. width: 85%;
  178. height: 90upx;
  179. font-size: 31upx;
  180. font-family: PingFang SC;
  181. font-weight: 400;
  182. color: #FFFFFF;
  183. line-height: 90upx;
  184. background-color: #1678FF;
  185. margin-left: 50%;
  186. transform: translateX(-50%);
  187. border-radius: 14upx;
  188. text-align: center;
  189. margin-top: 150upx;
  190. }
  191. </style>