common.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. export default {
  76. commonData:{
  77. companyType:1,
  78. },
  79. automaticlogin,
  80. isUserId,
  81. getExtStoreId,
  82. noMultipleClicks, // 禁止多次点击
  83. }