scanTheCode.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 || codeData.type == 15) {
  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 if (result.indexOf('mid') != -1 &&
  58. result.indexOf('sid') != -1 &&
  59. result.indexOf('pid') != -1 &&
  60. result.indexOf('pri') != -1) {
  61. uni.navigateTo({
  62. url: '/pages_basics/views/integralManage/codeSuccess?q=' +
  63. encodeURIComponent(JSON.stringify(result))
  64. });
  65. }else{
  66. chemicalAppletSelectStockInfoF(path,result);
  67. }
  68. }
  69. //通用二维码页面
  70. function goCodePage(path,result){
  71. if(path == 'home'){
  72. uni.reLaunch({
  73. url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(result)
  74. });
  75. }else{
  76. uni.showToast({
  77. mask: true,
  78. icon: "none",
  79. position: "center",
  80. title: "当前页面无法使用该二维码",
  81. duration: 2000
  82. });
  83. setTimeout(() => {
  84. uni.navigateBack();
  85. }, 2000);
  86. }
  87. }
  88. //查询是否是同位素实验并且有签退
  89. async function laboratorySubPassOutIsotopeSubSignF(path,subId,result){
  90. if(path == 'home'){
  91. const {
  92. data
  93. } = await laboratorySubPassOutIsotopeSubSign({subId:subId});
  94. if (data.code == 200) {
  95. if(data.data.isotope){
  96. let obj = {
  97. subId:subId,
  98. subName:data.data.subName,
  99. passOutId:data.data.passOutId,
  100. }
  101. uni.navigateTo({
  102. url: "/pages_basics/views/photoInspection?item=" + encodeURIComponent(JSON.stringify(obj)),
  103. });
  104. }else{
  105. uni.reLaunch({
  106. url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(result)
  107. });
  108. }
  109. }
  110. }else{
  111. uni.showToast({
  112. mask: true,
  113. icon: "none",
  114. position: "center",
  115. title: "当前页面无法使用该二维码",
  116. duration: 2000
  117. });
  118. setTimeout(() => {
  119. uni.navigateBack();
  120. }, 2000);
  121. }
  122. }
  123. //扫码查询-化学品基本信息
  124. async function chemicalAppletSelectStockInfoF(path,code){
  125. if(path == 'home'){
  126. const {
  127. data
  128. } = await chemicalAppletSelectStockInfo({tagCode:code});
  129. if (data.code == 200) {
  130. if(data.data){
  131. data.data.code = code;
  132. //化学品信息
  133. uni.navigateTo({
  134. url: "/pages_basics/views/chemicalsInfo/chemicalsInfo?item=" + encodeURIComponent(JSON.stringify(data.data)),
  135. });
  136. }else{
  137. uni.showToast({
  138. mask: true,
  139. icon: "none",
  140. position: "center",
  141. title: '未找到相关信息,请扫描正确的二维码',
  142. duration: 2000
  143. });
  144. }
  145. }
  146. }else{
  147. uni.showToast({
  148. mask: true,
  149. icon: "none",
  150. position: "center",
  151. title: "当前页面无法使用该二维码",
  152. duration: 2000
  153. });
  154. setTimeout(() => {
  155. uni.navigateBack();
  156. }, 2000);
  157. }
  158. }
  159. export { scanCode , scanTheCodeDataTreating }