123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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')
- }
- }
- const getHashQuery = function(query) {
- //console.log(location.hash)
- if (location.hash.indexOf(query) > -1) {
- const cur = location.hash.slice(location.hash.indexOf(query) + query.length + 1, location.hash.length)
- if (cur.indexOf('&') > -1) {
- return cur.slice(0, cur.indexOf('&'))
- } else {
- return cur
- }
- } else {
- return false
- }
- }
- export default {
- commonData:{
- companyType:1,
- },
- automaticlogin,
- isUserId,
- getExtStoreId,
- noMultipleClicks, // 禁止多次点击
- getHashQuery,
- }
|