common.js 3.36 KB
import USERAPI from '~/api/usersApi/index'
import environment from '~/utils/request/environment'
import ActivityApi from '~/api/activityApi/index'

const taskLoginAndRegister = (query, callBack) => {
    if (!query) return callBack && callBack()
    const options = { ...query, ...query.options }
    delete options.options
    console.log(options);
    if (options.merchantId) {
        const sessionId = wx.$storage.get('sessionId')
        if (!sessionId) {
            let para = {
                merchantId: options.merchantId,
                type: 1,
                pages: options.pages
            }
            let temp = encodeURIComponent(JSON.stringify(para))
            wx.navigateTo({
                url: '/packageStoreAssistant/packageAuth/pages/authentication/register/register?data=' + temp,
            });
        } else {
            const USERINFO = wx.$storage.get('userInfo')
            if (USERINFO.merchantId == options.merchantId) {
                USERAPI.checkSession().then(({
                    code
                }) => {
                    if (code == '0') {
                        callBack && callBack()
                    } else {
                        wx.$router.reLaunch('/packageStoreAssistant/packageAuth/pages/authentication/login/login', options)
                    }
                })
            } else {
                let para = {
                    merchantId: options.merchantId,
                    type: 1,
                    pages: options.pages
                }
                let temp = encodeURIComponent(JSON.stringify(para))
                wx.navigateTo({
                    url: '/packageStoreAssistant/packageAuth/pages/authentication/register/register?data=' + temp,
                });
            }
        }
    } else {
        callBack && callBack()
    }
}
const authAvatarAndNickName = () => {
    const {
        domain,
        index
    } = environment,
        redirectUrl = `${domain}/wx-oauth`,
        // redirectUrl = 'http://scrm.dev.glsx.com.cn/wx-oauth',
        // 云商 wx1cf40dc91c28a7fd ,glsxtest02 wx56bed167ad463f70
        appid = index == 1 || index == 2 ? 'wx1cf40dc91c28a7fd' : 'wx56bed167ad463f70',
        wxUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
    console.log(redirectUrl, appid)
    wx.navigateTo({
        url: `/pages/webView/webView?url=${encodeURIComponent(wxUrl)}`,
    })
}
const handlerMiss = (data, query, callBack) => {
    if (!data) return
    if (!query) return
    let { pageNum, orginList, serviceType, listName } = query
    data.data && data.data.forEach((val, index) => {
        val.tabType = serviceType
        val.isCollapse = true
        val.startTime = val.startTime.split(' ')[0]
        val.endTime = val.endTime.split(' ')[0]
    })
    const RESULT = {
        [listName]: pageNum == 1 ? data.data : [...orginList, ...data.data],
        activeTrigger: false,
        total: data.count,
        noResult: pageNum == 1 ? (data.data.length ? false : true) : false
    }
    callBack && callBack(RESULT)
}
const calenderFilter = (arr, length) => {
    var _arr = []
    while (arr.length) {
        _arr.push(arr.splice(0, length))
    }
    return _arr
}
module.exports = {
    taskLoginAndRegister,
    authAvatarAndNickName,
    handlerMiss
}