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; var extConfig = uni.getExtConfigSync(); /* extConfig={ "shopId": "23173848-292E-4AEA-B590-73AC9A763F1D", "url":"https://store-api.qdbtl.cn/", "unionId":"C3748B46-B778-40AA-8C60-A9B0F2FA23A7", "appId":"wxc023ff04deb28f2d" } */ console.log("automaticlogin") console.log(extConfig) return new Promise((resolve, reject) => { if($store.state.userInfo){ resolve() }else{ uni.login({ provider: 'weixin', success: function (loginRes) { //console.log(loginRes); uni.showLoading({ title: '加载中' }); request.http('miniApp2/sys/getWxOpenID', { code:loginRes.code, unionId:extConfig.unionId },'GET').then(res => { uni.hideLoading(); $store.commit('mutationswxOpenData', res.data); var themeColor= res.data.themeColor uni.setStorageSync('themeColor',themeColor); 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{ var extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {shopId:'默认的门店id'}; /* extConfig={ "shopId": "23173848-292E-4AEA-B590-73AC9A763F1D", "url":"https://store-api.qdbtl.cn/", "unionId":"C3748B46-B778-40AA-8C60-A9B0F2FA23A7", "appId":"wxc023ff04deb28f2d" } */ /* "shopId": "E37BB296-5A08-4534-859D-B351BA611AF9", "url":"http://api.dms.66km.com.cn", "unionId":"EEADACCD-8A19-499D-8AD7-6975D2C93243", "appId":"wx33053a645546ec31" */ console.log(extConfig,'extJson对象'); //return extConfig[type]; return extConfig }catch(err){ console.log(err,'getExtStoreId__error') } } function formateTimeStamp (timeStamp) { var hour; var min; var seconds; let today = new Date() // 当前时间 if (Number(new Date(timeStamp).getTime()) < Number(new Date().getTime())) { const zTime = { hour: 0, min: 0, seconds: 0 } return zTime return false } let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间 let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数 let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天 //console.log(shengyuD+'shengyuD') //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数 hour = parseInt(shenyu / (60 * 60 * 1000)) var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数 min = parseInt(afterHour / (60 * 1000)) // 计算整数分 //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数 seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000) if (hour < 10) { hour = '0' + hour } //console.log(hour) if (min < 10) { min = '0' + min; } //console.log(min) if (seconds < 10) { seconds = '0' + seconds; } //console.log(seconds) const restTime = { hour: hour, min: min, seconds: seconds } //console.log(restTime) /// setTimeout(formateTimeStamp(timeStamp), 1000) return restTime } function countdown (timeStamp) { var hour; var min; var seconds; let today = new Date() // 当前时间 let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间 let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数 let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天 //console.log(shengyuD+'shengyuD') //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数 hour = parseInt(shenyu / (60 * 60 * 1000)) var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数 min = parseInt(afterHour / (60 * 1000)) // 计算整数分 //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数 seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000) if (hour < 10) { hour = '0' + hour } console.log(hour) if (min < 10) { min = '0' + min; } //console.log(min) if (seconds < 10) { seconds = '0' + seconds; } const restTime = { hour: hour, min: min, seconds: seconds } var txt = hour+':'+min+':'+seconds; console.log(txt) return txt } export default { commonData:{ companyType:1, }, automaticlogin, isUserId, getExtStoreId, noMultipleClicks, // 禁止多次点击 formateTimeStamp, countdown }