scanTheCode.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*************** 扫码相关方法 ***************/
  2. import {
  3. chemicalAppletSelectStockInfo,
  4. laboratorySubPassOutIsotopeSubSign,
  5. } from '@/pages/api/index.js'
  6. // 公共扫码-方法
  7. function scanCode(path){
  8. /*************** H5方法 ***************/
  9. // #ifdef WEB
  10. uni.navigateTo({
  11. url: "/pages/views/scanCodePage?path="+path,
  12. });
  13. // #endif
  14. /*************** 微信方法 ***************/
  15. // #ifdef MP-WEIXIN
  16. uni.scanCode({
  17. onlyFromCamera: true,
  18. success: function (res) {
  19. scanTheCodeDataTreating(path,res.result);
  20. },
  21. fail: (err) => {
  22. uni.showToast({
  23. mask: true,
  24. icon: "none",
  25. position: "center",
  26. title: err,
  27. duration: 2000
  28. });
  29. return false
  30. }
  31. });
  32. // #endif
  33. }
  34. //公共扫码-参数处理方法
  35. function scanTheCodeDataTreating(path,result){
  36. if(result.indexOf('type') != -1){
  37. //项目二维码
  38. let list = result.split("?")[1].split("&");
  39. let codeData = {};
  40. list.forEach((item) => {
  41. codeData[item.split("=")[0]] = item.split("=")[1];
  42. })
  43. if (codeData.type == 1 || codeData.type == 2 || codeData.type == 3 || codeData.type == 7 ||
  44. codeData.type == 8 || codeData.type == 10 ||
  45. codeData.type == 11 || codeData.type == 12 || codeData.type == 13 || codeData.type == 14) {
  46. // 基础扫码逻辑
  47. goCodePage(path,result);
  48. }else if(codeData.type == 5){
  49. // 同位素实验室相关-暂时注释
  50. // laboratorySubPassOutIsotopeSubSignF(path,codeData.subId,result);
  51. uni.reLaunch({
  52. url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(result)
  53. });
  54. }else if(codeData.type == 9){
  55. chemicalAppletSelectStockInfoF(path,codeData.code);
  56. }
  57. }else{
  58. chemicalAppletSelectStockInfoF(path,result);
  59. }
  60. }
  61. //通用二维码页面
  62. function goCodePage(path,result){
  63. if(path == 'home'){
  64. uni.reLaunch({
  65. url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(result)
  66. });
  67. }else{
  68. uni.showToast({
  69. mask: true,
  70. icon: "none",
  71. position: "center",
  72. title: "当前页面无法使用该二维码",
  73. duration: 2000
  74. });
  75. setTimeout(() => {
  76. uni.navigateBack();
  77. }, 2000);
  78. }
  79. }
  80. //查询是否是同位素实验并且有签退
  81. async function laboratorySubPassOutIsotopeSubSignF(path,subId,result){
  82. if(path == 'home'){
  83. const {
  84. data
  85. } = await laboratorySubPassOutIsotopeSubSign({subId:subId});
  86. if (data.code == 200) {
  87. if(data.data.isotope){
  88. let obj = {
  89. subId:subId,
  90. subName:data.data.subName,
  91. passOutId:data.data.passOutId,
  92. }
  93. uni.navigateTo({
  94. url: "/pages_basics/views/photoInspection?item=" + encodeURIComponent(JSON.stringify(obj)),
  95. });
  96. }else{
  97. uni.reLaunch({
  98. url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(result)
  99. });
  100. }
  101. }
  102. }else{
  103. uni.showToast({
  104. mask: true,
  105. icon: "none",
  106. position: "center",
  107. title: "当前页面无法使用该二维码",
  108. duration: 2000
  109. });
  110. setTimeout(() => {
  111. uni.navigateBack();
  112. }, 2000);
  113. }
  114. }
  115. //扫码查询-化学品基本信息
  116. async function chemicalAppletSelectStockInfoF(path,code){
  117. if(path == 'home'){
  118. const {
  119. data
  120. } = await chemicalAppletSelectStockInfo({tagCode:code});
  121. if (data.code == 200) {
  122. if(data.data){
  123. data.data.code = code;
  124. //化学品信息
  125. uni.navigateTo({
  126. url: "/pages_basics/views/chemicalsInfo/chemicalsInfo?item=" + encodeURIComponent(JSON.stringify(data.data)),
  127. });
  128. }else{
  129. uni.showToast({
  130. mask: true,
  131. icon: "none",
  132. position: "center",
  133. title: '未找到相关信息,请扫描正确的二维码',
  134. duration: 2000
  135. });
  136. }
  137. }
  138. }else{
  139. uni.showToast({
  140. mask: true,
  141. icon: "none",
  142. position: "center",
  143. title: "当前页面无法使用该二维码",
  144. duration: 2000
  145. });
  146. setTimeout(() => {
  147. uni.navigateBack();
  148. }, 2000);
  149. }
  150. }
  151. export { scanCode , scanTheCodeDataTreating }