scode.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import api from './index.js'
  2. export default {
  3. getScode(data){
  4. try{
  5. let res = JSON.parse(data.result)
  6. //用户
  7. if(res.action == 'user'){
  8. let params = `?id=${res.id}&from=qrcode`;
  9. uni.navigateTo({
  10. url:'../friend/detail'+params
  11. })
  12. }
  13. //群组
  14. else if(res.action == "group"){
  15. api.joinGroup({group_id:res.id,userid:uni.getStorageSync('access_token')}).then(()=>{
  16. if(res.data==true){
  17. let params = `?id=${res.id}`
  18. uni.navigateTo({
  19. url:'../group/chat'+params
  20. })
  21. }
  22. else{
  23. uni.showToast({
  24. icon:'none',
  25. title:res.message
  26. })
  27. }
  28. }).catch((e)=>{
  29. if(!e.message){
  30. let params = `?id=${res.id}`
  31. uni.navigateTo({
  32. url:'../group/chat'+params
  33. })
  34. }
  35. })
  36. }
  37. else if(res.action=='login' && res.from=='cj666'){
  38. uni.navigateTo({
  39. url:"/pages/login/qrcode?agent="+res.agent
  40. })
  41. }
  42. }catch(e){
  43. var reg= /(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g;
  44. // console.log(str);
  45. var s = data.result.match(reg);
  46. if(s!=null){
  47. if(data.result.indexOf('detail?from=qrcode&id=')>-1){
  48. var arr=data.result.split('#');
  49. uni.navigateTo({
  50. url:arr[1]
  51. })
  52. }
  53. else if(data.result.indexOf('from=invite&invite_code=')>-1){
  54. var arr=data.result.split('=');
  55. uni.navigateTo({
  56. url:"/pages/login/index?invite_code="+arr[arr.length-1]
  57. })
  58. }
  59. else{
  60. let params = `?url=`+data.result;
  61. uni.navigateTo({
  62. url:'../web/index'+params
  63. })
  64. }
  65. }else{
  66. uni.showToast({
  67. icon:'none',
  68. title:data.result
  69. })
  70. }
  71. }
  72. }
  73. }