import $store from '../store' import request from '@/utils/request.js' const isUserId = function() { var userId=uni.getStorageSync("wxOpenData").loginInfo.uid; //console.log("userId---"+userId) if(!userId){ uni.navigateTo({ url:'../login/login' }) } } const automaticlogin = function() { //console.log($store.state.userInfo) var that=this; const extConfig = uni.getExtConfigSync(); //console.log(extConfig) return new Promise((resolve, reject) => { if($store.state.userInfo){ resolve() }else{ uni.login({ provider: 'weixin', success: function (loginRes) { //console.log(loginRes); request.http('miniApp2/sys/getWxOpenID', { code:loginRes.code, unionId:extConfig.unionId },'GET').then(res => { $store.commit('mutationswxOpenData', res.data); if(res.data.loginInfo){ $store.commit('mutationsuserInfo', res.data.loginInfo.openUser) } resolve() }) } }); } }) //return Promise.resolve() } /* const uid =function() { var userId=uni.getStorageSync("logodata").uid; return } */ // 防止处理多次点击 function noMultipleClicks(methods, info) { // methods是点击后需要执行的函数, info是函数需要传的参数 let that = this; if (that.noClick) { // 第一次点击 that.noClick= false; if((info && info !== '') || info ==0) { // info是执行函数需要传的参数 methods(info); } else { methods(); } setTimeout(()=> { that.noClick= true; }, 3000) } else { // 这里是重复点击的判断 } } function getExtStoreId(type){ try{ const extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {shopId:'默认的门店id'} console.log(extConfig,'extJson对象'); //return extConfig[type]; return extConfig }catch(err){ console.log(err,'getExtStoreId__error') } } export default { commonData:{ companyType:1, }, automaticlogin, isUserId, getExtStoreId, noMultipleClicks, // 禁止多次点击 }