common.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. var themeColor= res.data.themeColor
  31. uni.setStorageSync('themeColor',themeColor);
  32. if(res.data.loginInfo){
  33. $store.commit('mutationsuserInfo', res.data.loginInfo.openUser)
  34. }
  35. resolve()
  36. })
  37. }
  38. });
  39. }
  40. })
  41. //return Promise.resolve()
  42. }
  43. /* const uid =function() {
  44. var userId=uni.getStorageSync("logodata").uid;
  45. return
  46. } */
  47. // 防止处理多次点击
  48. function noMultipleClicks(methods, info) {
  49. // methods是点击后需要执行的函数, info是函数需要传的参数
  50. let that = this;
  51. if (that.noClick) {
  52. // 第一次点击
  53. that.noClick= false;
  54. if((info && info !== '') || info ==0) {
  55. // info是执行函数需要传的参数
  56. methods(info);
  57. } else {
  58. methods();
  59. }
  60. setTimeout(()=> {
  61. that.noClick= true;
  62. }, 3000)
  63. } else {
  64. // 这里是重复点击的判断
  65. }
  66. }
  67. function getExtStoreId(type){
  68. try{
  69. var extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {shopId:'默认的门店id'};
  70. // extConfig={
  71. // "shopId": "E37BB296-5A08-4534-859D-B351BA611AF9",
  72. // "url":"http://api.dms.66km.com.cn",
  73. // "unionId":"EEADACCD-8A19-499D-8AD7-6975D2C93243",
  74. // "appId":"wx33053a645546ec31"
  75. // }
  76. console.log(extConfig,'extJson对象');
  77. //return extConfig[type];
  78. return extConfig
  79. }catch(err){
  80. console.log(err,'getExtStoreId__error')
  81. }
  82. }
  83. export default {
  84. commonData:{
  85. companyType:1,
  86. },
  87. automaticlogin,
  88. isUserId,
  89. getExtStoreId,
  90. noMultipleClicks, // 禁止多次点击
  91. }