client.js 1.09 KB
/**
 * 客服用户端 controller
 *
 * @author: liqi <qi.li@yoho.cn>
 * @date: 2016/11/4
 */

'use strict';
const aes = require('./aes-pwd');
const common = require('../../../config/common');
const clientService = require('../models/client-service');

/**
 * 在线客服客户端
 */
const index = (req, res, next) => {

    let reg = /MSIE\s?[987]\.0/i;
    let userAgent = req.headers['user-agent'];
    let unSupport = reg.test(userAgent);
    let type = 2;
    let imgSize = '86x120';
    let encryptedUid = aes.encryptionUid(req.user.uid);
    let data = {
        encryptedUid,
        layout: false
    };

    if (unSupport) {
        res.render('unsupport', {
            layout: false
        });
    } else {
        clientService.getClientData(type, encryptedUid, imgSize)
            .then(result => {
                res.render('client', Object.assign(data, result));
            })
            .catch(next);
    }
};

/**
 * 在线客服客户端
 */
const domains = (req, res) => {
    // 返回当前环境的配置信息
    res.json(common.domains);
};


module.exports = {
    index,
    domains
};