Authored by 陈轩

im app

... ... @@ -24,6 +24,11 @@ exports.appAdapter = (req, res, next) => {
exports.page = (req, res, next) => {
let uid = req.user.uid;
if (!uid) {
uid = req.query.uid;
}
userApi.profile(req.user.uid)
.then(userinfo => {
userinfo = userinfo.data;
... ... @@ -49,12 +54,18 @@ exports.page = (req, res, next) => {
};
exports.getOrders = (req, res, next) => {
let uid = req.user.uid;
if (!uid) {
uid = req.query.uid;
}
orderModel.getOrders({
type: req.query.type || 1,
page: req.query.page || 1,
gender: req.query.gender || '1,3',
yh_channel: req.query.channel || 1,
uid: req.user.uid
uid
}).then(result => {
res.render('chat/chat-order', {
layout: false,
... ... @@ -69,7 +80,12 @@ exports.getOrders = (req, res, next) => {
*
*/
exports.fetchHistory = (req, res) => {
const uid = req.user.uid;
let uid = req.user.uid;
if (!uid) {
uid = req.query.uid;
}
const endTime = req.query.endTime;
imApi.fetchImHistory(uid, endTime).then(result => {
... ... @@ -79,7 +95,12 @@ exports.fetchHistory = (req, res) => {
exports.msghistory = (req, res) => {
const uid = req.user.uid;
let uid = req.user.uid;
if (!uid) {
uid = req.query.uid;
}
imApi.fetchImHistory(uid).then(result => {
res.json(result);
... ... @@ -94,7 +115,12 @@ exports.msghistory = (req, res) => {
* content 留言内容
*/
exports.saveMSG = (req, res) => {
const uid = req.user.uid;
let uid = req.user.uid;
if (!uid) {
uid = req.body.uid;
}
const conversationId = req.body.conversationId;
const content = req.body.content;
... ... @@ -113,7 +139,12 @@ exports.saveMSG = (req, res) => {
* 2. 失败情况
*/
exports.fetchOrders = (req, res) => {
const uid = req.user.uid;
let uid = req.user.uid;
if (!uid) {
uid = req.query.uid;
}
imApi.fetchOrderList(uid)
.then(result => {
... ... @@ -128,7 +159,12 @@ exports.fetchOrders = (req, res) => {
};
exports.saveEvalute = (req, res) => {
const uid = req.user.uid;
let uid = req.user.uid;
if (!uid) {
uid = req.body.uid;
}
const conversationId = req.body.conversationId;
const promoter = req.body.promoter;
... ... @@ -148,7 +184,12 @@ exports.saveEvalute = (req, res) => {
exports.queryGlobalOrder = (req, res) => {
const uid = req.user.uid;
let uid = req.user.uid;
if (!uid) {
uid = req.query.uid;
}
let emptyOrder = {
code: 200,
... ...
... ... @@ -19,13 +19,6 @@ module.exports = () => {
req.user.uid = cookie.getUid(req);
}
// app 特殊读法
let userAgent = _.get(req.headers, 'user-agent', '');
if (!req.user.uid && userAgent.indexOf('YohoBuy') >= 0) {
req.user.uid = req.cookies._YOHOUID || 0;
}
next();
};
};
... ...
... ... @@ -851,23 +851,58 @@ $('#chat-window').on('click', '.chat-image', function() {
});
function tellAppSuccess() {
window.setTimeout(() => {
appBridge.invokeMethod('im.page_success', {url: location.href});
}, 1000);
window.addEventListener('pageshow', tellAppSuccess);
}
function setChannelColor(channel) {
var dict = {
1: 'boys',
2: 'girls',
3: 'kids',
4: 'lifestyle'
};
$(document.body)
.removeClass('boys girls kids lifestyle')
.addClass(dict[channel]);
}
if (appBridge.isApp && /YohoBuy-iOS/i.test(navigator.userAgent)) {
document.body.classList.add('app-ios');
}
if (/YohoBuy-android/i.test(navigator.userAgent)) {
$('#js-back').removeAttr('href').on('click', function(e) {
e.preventDefault();
window.im.goBack();
});
setChannelColor(qs.yh_channel);
} else if (appBridge.isApp) {
$('#js-back').removeAttr('href').on('click', function(e) {
e.preventDefault();
appBridge.invokeMethod('go.back', {});
});
tellAppSuccess();
setChannelColor(qs.yh_channel);
}
window.channelChanged = function(channel) {
setChannelColor(channel);
};
window.$ = $;
window.chat = chat;
window.cmEntity = cmEntity;
... ...
... ... @@ -5,6 +5,8 @@ const socketConf = require('./socket-config');
const conversation = socketConf.conversationMessage;
const slice = Array.prototype.slice;
let uid = $('#js-uid').val();
// EventEmitter
//--------------------------------------------------------
const EventEmitter = function() {};
... ... @@ -53,6 +55,7 @@ let api = {
return $.post('/service/leavemsg/save.json', {
conversationId: conversation.conversationId,
content,
uid
});
},
... ... @@ -64,7 +67,7 @@ let api = {
fetchOrders: function(type) {
let url = `/service/im/${type}-list`;
return $.get(url);
return $.get(url, {uid});
},
// 获取10条历史记录
... ... @@ -81,6 +84,7 @@ let api = {
},
saveEvalute: function(data) {
data.uid = uid;
return $.post('/service/im/saveEvalute', data);
}
};
... ...
... ... @@ -149,11 +149,33 @@
}
}
body.app-ios {
margin-top: 20PX;
margin-top: 6PX;
#chat-window {
margin-top: 20PX;
#chat-window,
.connection-failed,
.chat-page {
margin-top: 6PX;
}
}
body.boys, .boys .chat-header {
background-color: #414141 !important;
background-image: none;
}
body.girls, .girls .chat-header {
background-color: #ff88ae !important;
background-image: none;
}
body.kids, .kids .chat-header {
background-color: #7ad9f9 !important;
background-image: none;
}
body.lifestyle, .lifestyle .chat-header {
background-color: #4f4138 !important;
background-image: none;
}
\ No newline at end of file
... ...