common.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import $store from '../store'
  2. import request from '@/utils/request.js'
  3. const isUserId = function() {
  4. var userId=uni.getStorageSync("wxOpenData").loginInfo.uid;
  5. //console.log("userId---"+userId)
  6. if(!userId){
  7. uni.navigateTo({
  8. url:'../login/login'
  9. })
  10. }
  11. }
  12. const automaticlogin = function() {
  13. //console.log($store.state.userInfo)
  14. var that=this;
  15. const extConfig = uni.getExtConfigSync();
  16. //console.log(extConfig)
  17. return new Promise((resolve, reject) => {
  18. if($store.state.userInfo){
  19. resolve()
  20. }else{
  21. uni.login({
  22. provider: 'weixin',
  23. success: function (loginRes) {
  24. //console.log(loginRes);
  25. request.http('miniApp2/sys/getWxOpenID', {
  26. code:loginRes.code,
  27. unionId:extConfig.unionId
  28. },'GET').then(res => {
  29. $store.commit('mutationswxOpenData', res.data);
  30. if(res.data.loginInfo){
  31. $store.commit('mutationsuserInfo', res.data.loginInfo.openUser)
  32. }
  33. resolve()
  34. })
  35. }
  36. });
  37. }
  38. })
  39. //return Promise.resolve()
  40. }
  41. /* const uid =function() {
  42. var userId=uni.getStorageSync("logodata").uid;
  43. return
  44. } */
  45. // 防止处理多次点击
  46. function noMultipleClicks(methods, info) {
  47. // methods是点击后需要执行的函数, info是函数需要传的参数
  48. let that = this;
  49. if (that.noClick) {
  50. // 第一次点击
  51. that.noClick= false;
  52. if((info && info !== '') || info ==0) {
  53. // info是执行函数需要传的参数
  54. methods(info);
  55. } else {
  56. methods();
  57. }
  58. setTimeout(()=> {
  59. that.noClick= true;
  60. }, 3000)
  61. } else {
  62. // 这里是重复点击的判断
  63. }
  64. }
  65. function getExtStoreId(type){
  66. try{
  67. const extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {shopId:'默认的门店id'}
  68. console.log(extConfig,'extJson对象');
  69. //return extConfig[type];
  70. return extConfig
  71. }catch(err){
  72. console.log(err,'getExtStoreId__error')
  73. }
  74. }
  75. const getHashQuery = function(query) {
  76. //console.log(location.hash)
  77. if (location.hash.indexOf(query) > -1) {
  78. const cur = location.hash.slice(location.hash.indexOf(query) + query.length + 1, location.hash.length)
  79. if (cur.indexOf('&') > -1) {
  80. return cur.slice(0, cur.indexOf('&'))
  81. } else {
  82. return cur
  83. }
  84. } else {
  85. return false
  86. }
  87. }
  88. export default {
  89. commonData:{
  90. companyType:1,
  91. },
  92. automaticlogin,
  93. isUserId,
  94. getExtStoreId,
  95. noMultipleClicks, // 禁止多次点击
  96. getHashQuery,
  97. }