import { J_STORAGE_KEY } from '../config/constant' /** * 获取用户userid * @returns */ export const getBuyerUserId = () => { const userId = uni.getStorageSync(J_STORAGE_KEY).buyerUserId if (!userId) { uni.showModal({ title: '提示', content: '您还未登录,是否去登录?', success(res) { if (res.confirm) { uni.navigateTo({ url: 'pages_category_page2/userModule/login' }) } else if (res.cancel) { // uni.navigateBack(); } } }) return } return userId } /** * 获取用户token * @returns */ export const getUserToken = () => { const token = uni.getStorageSync(J_STORAGE_KEY).token if (!token) { uni.showModal({ title: '提示', content: '您还未登录,是否去登录?', success(res) { if (res.confirm) { uni.navigateTo({ url: 'pages_category_page2/userModule/login' }) } else if (res.cancel) { // uni.navigateBack(); } } }) return } return token } // 判断当前是否处于微信环境 export const isInWx = () => { // #ifdef H5 var ua = navigator.userAgent.toLowerCase() return ua.match(/MicroMessenger/i) == 'micromessenger' // #endif // #ifdef APP return false // #endif } export const getUrlCode = () => { var url = location.search var theRequest = new Object() if (url.indexOf('?') != -1) { var str = url.substr(1) var strs = str.split('&') for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1] } } console.log('code结果', theRequest) return theRequest }