Skip to content

Commit 529c609

Browse files
committed
添加 html loader,适配 Tpl.html 后缀
添加 alias 作为 require 根路径 新增 getArticleJson 接口 新增 popupList 组件 utils.sameProtocol 兼容只有根路径的情况 css 兼容新旧两版 tenantInfo 新版 tenantInfo 独立目录
1 parent ec575fb commit 529c609

File tree

11 files changed

+410
-29
lines changed

11 files changed

+410
-29
lines changed

src/js/app/modules/apiHelper.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ function getConfig(configId){
175175
}, function(err){
176176
reject(err);
177177
});
178-
179-
180178
});
181179
}
182180
function getProjectId(){
@@ -1112,12 +1110,12 @@ function createWechatImUser(openId){
11121110
emajax({
11131111
url: "/v1/webimplugin/visitors/wechat/"
11141112
+ [
1115-
config.tenantId,
1116-
config.orgName,
1117-
config.appName,
1118-
config.toUser,
1119-
openId,
1120-
].join("_")
1113+
config.tenantId,
1114+
config.orgName,
1115+
config.appName,
1116+
config.toUser,
1117+
openId,
1118+
].join("_")
11211119
+ "?tenantId=" + config.tenantId,
11221120
data: {
11231121
orgName: config.orgName,
@@ -1204,12 +1202,12 @@ function updateCustomerInfo(data){
12041202
]).then(function(result){
12051203
var visitorId = result[0];
12061204
var token = result[1];
1207-
data["visitorId"] = visitorId;
1208-
data["tenantId"] = config.tenantId;
1209-
data["orgName"] = config.orgName;
1210-
data["appName"] = config.appName;
1211-
data["userName"] = config.user.username;
1212-
data["token"] = token;
1205+
data.visitorId = visitorId;
1206+
data.tenantId = config.tenantId;
1207+
data.orgName = config.orgName;
1208+
data.appName = config.appName;
1209+
data.userName = config.user.username;
1210+
data.token = token;
12131211
api("updateCustomerInfo", data, function(msg){
12141212
// resolve(msg.data);
12151213
}, function(err){
@@ -1219,6 +1217,22 @@ function updateCustomerInfo(data){
12191217
});
12201218
}
12211219

1220+
function getArticleJson(data){
1221+
return new Promise(function(resolve, reject){
1222+
api("getArticleJson", {
1223+
media_id: data.media_id,
1224+
tenantId: config.tenantId,
1225+
userId: config.user.userName,
1226+
orgName: config.orgName,
1227+
appName: config.appName,
1228+
token: 0,
1229+
}, function(ret){
1230+
var articles = utils.getDataByPath(ret, "data.entity.articles");
1231+
resolve(articles);
1232+
});
1233+
});
1234+
}
1235+
12221236
module.exports = {
12231237
getCurrentServiceSession: getCurrentServiceSession,
12241238
getToken: getToken,
@@ -1267,6 +1281,7 @@ module.exports = {
12671281
getCustomEmojiFiles: getCustomEmojiFiles,
12681282
getSatisfactionTipWord: getSatisfactionTipWord,
12691283
updateCustomerInfo: updateCustomerInfo,
1284+
getArticleJson: getArticleJson,
12701285

12711286
initApiTransfer: initApiTransfer,
12721287
api: api,

src/js/app/modules/chat.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ var initGetGreetings = require("./chat/initGetGreetings");
2121
var initAgentNicknameUpdate = require("./chat/initAgentNicknameUpdate");
2222
var emojiPanel = require("./chat/emojiPanel");
2323
var extendMessageSender = require("./chat/extendMessageSender");
24+
var TenantInfo = require("@/app/modules/tenantInfo/index");
25+
var tenantInfo;
2426

2527
var isMessageChannelReady;
2628
var config;
@@ -165,21 +167,28 @@ function _setLogo(){
165167
function _setNotice(){
166168
var noticeContent = document.querySelector(".em-widget-tip .content");
167169
var noticeCloseBtn = document.querySelector(".em-widget-tip .tip-close");
168-
169170
apiHelper.getNotice().then(function(notice){
170-
if(!notice.enabled) return;
171171
var slogan = notice.content;
172+
if(!notice.enabled) return;
172173

173-
// 设置信息栏内容
174-
noticeContent.innerHTML = WebIM.utils.parseLink(slogan);
175174
// 显示信息栏
176175
utils.addClass(doms.imChat, "has-tip");
177176

178-
// 隐藏信息栏按钮
179-
utils.on(noticeCloseBtn, utils.click, function(){
180-
// 隐藏信息栏
181-
utils.removeClass(doms.imChat, "has-tip");
182-
});
177+
// 新配置就走新 tenantInfo
178+
if(config.isWebChannelConfig){
179+
tenantInfo = new TenantInfo();
180+
}
181+
else{
182+
(function(){
183+
// 设置信息栏内容
184+
noticeContent.innerHTML = WebIM.utils.parseLink(slogan);
185+
// 隐藏信息栏按钮
186+
utils.on(noticeCloseBtn, utils.click, function(){
187+
// 隐藏信息栏
188+
utils.removeClass(doms.imChat, "has-tip");
189+
});
190+
})();
191+
}
183192
});
184193
}
185194

@@ -423,6 +432,7 @@ function _bindEvents(){
423432
var iframe = articleContainer.querySelector("iframe");
424433
iframe && utils.removeDom(iframe);
425434
articleContainer.style.display = "none";
435+
tenantInfo && tenantInfo.show();
426436
});
427437

428438
utils.live(".article-link", "click", function(e){
@@ -444,6 +454,9 @@ function _bindEvents(){
444454
else{
445455
window.open(url);
446456
}
457+
458+
// 隐藏整个 tenantInfo
459+
tenantInfo && tenantInfo.hide();
447460
});
448461

449462
var messagePredict = _.throttle(function(msg){
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
var apiHelper = require("@/app/modules/apiHelper");
2+
var PopupList = require("@/app/modules/uikit/popupList");
3+
var utils = require("@/common/utils");
4+
var channel = require("@/app/modules/channel");
5+
var tpl = require("./template/indexTpl.html");
6+
7+
module.exports = function(){
8+
// 二级菜单实例
9+
var menuInsArr = [];
10+
var menuArr = [];
11+
var container = document.querySelector(".em-widget-tip");
12+
container.innerHTML = "";
13+
utils.addClass(container, "new");
14+
15+
apiHelper.getNotice()
16+
.then(function(notice){
17+
if(!notice.enabled) return;
18+
19+
20+
21+
// test
22+
// notice.content = [
23+
// {
24+
// name: "菜单",
25+
// sub_button: [
26+
// {
27+
// type: "view",
28+
// name: "搜索2666",
29+
// url: "http://www.soso.com/"
30+
// }
31+
// ]
32+
// },
33+
// {
34+
// name: "222",
35+
// sub_button: [
36+
// {
37+
// type: "media_id",
38+
// name: "111",
39+
// media_id: "75cffa4b-e462-40e8-a517-0ff807db29a6"
40+
// },
41+
// {
42+
// type: "media_id",
43+
// name: "香格里拉",
44+
// media_id: "4150c891-9917-4482-909c-ab7c9954110a"
45+
// }
46+
// ]
47+
// },
48+
// {
49+
// type: "media_id",
50+
// name: "333",
51+
// media_id: "75cffa4b-e462-40e8-a517-0ff807db29a6"
52+
// }
53+
// ];
54+
55+
56+
57+
58+
menuArr = notice.content;
59+
container.innerHTML = _.template(tpl)({
60+
menu: menuArr,
61+
});
62+
createMenu();
63+
utils.live(".tip-btn", "click", onMenuClick, container);
64+
});
65+
66+
// 菜单点击
67+
function onMenuClick(e){
68+
var menuId;
69+
var menuDat;
70+
var target = e.srcElement || e.target;
71+
var targetBounding;
72+
if(utils.hasClass(target.parentNode, "tip-btn")){
73+
target = target.parentNode;
74+
}
75+
menuId = target.getAttribute("menuId");
76+
menuDat = menuArr[menuId];
77+
78+
targetBounding = target.getBoundingClientRect();
79+
handleMenuClick(menuDat, menuId, {
80+
top: targetBounding.top + 48,
81+
left: targetBounding.left + (target.clientWidth * 0.1),
82+
width: target.clientWidth * 0.8,
83+
});
84+
// ie8
85+
// 使得 popupList 可以自动关闭
86+
e.stopPropagation();
87+
return false;
88+
}
89+
90+
function handleMenuClick(menuDat, menuId, pos){
91+
// 有子菜单
92+
if(menuDat.sub_button){
93+
popupList(menuId, pos || {
94+
left: 0,
95+
top: 0,
96+
width: 0,
97+
});
98+
}
99+
// 无子菜单
100+
else{
101+
hideAllSubMenu();
102+
fireMsg(menuDat);
103+
}
104+
}
105+
106+
function fireMsg(dat){
107+
switch(dat.type){
108+
// 发送 article
109+
case "media_id":
110+
fireArticle(dat);
111+
break;
112+
// 发送 url
113+
case "view":
114+
fireUrl(dat);
115+
break;
116+
// 发送 text
117+
case "txt":
118+
fireText(dat);
119+
break;
120+
default:
121+
break;
122+
}
123+
}
124+
125+
function fireArticle(menuDat){
126+
apiHelper.getArticleJson({
127+
media_id: menuDat.media_id
128+
}).then(function(articles){
129+
articles = _.map(articles, function(article){
130+
return {
131+
title: article.title,
132+
digest: article.digest,
133+
description: article.digest,
134+
// url: "/v1/webimplugin/tenants/" + article.tenantId + "/robot/article/html/" + article.articleId,
135+
url: "/v1/Tenants/" + article.tenantId + "/robot/article/html/" + article.articleId,
136+
thumbUrl: "/v1/Tenant/" + article.tenantId + "/MediaFiles/" + article.thumb_media_id,
137+
picurl: "/v1/Tenant/" + article.tenantId + "/MediaFiles/" + article.thumb_media_id,
138+
prop: article.prop,
139+
};
140+
});
141+
channel.handleMessage(
142+
{
143+
ext: {
144+
msgtype: {
145+
articles: articles,
146+
}
147+
},
148+
},
149+
{
150+
type: "article",
151+
noPrompt: true
152+
}
153+
);
154+
});
155+
}
156+
157+
function fireText(menuDat){
158+
159+
}
160+
161+
function fireUrl(menuDat){
162+
163+
}
164+
165+
// 每个 btn 创建一个菜单
166+
function createMenu(){
167+
_.each(menuArr, function(menuDat, menuId){
168+
menuInsArr[menuId] = new PopupList({
169+
items: menuDat.sub_button,
170+
reportClick: handleMenuClick,
171+
});
172+
});
173+
}
174+
175+
// 弹出菜单
176+
function popupList(menuId, pos){
177+
hideAllSubMenu();
178+
menuInsArr[menuId].show(pos);
179+
}
180+
181+
function hideAllSubMenu(){
182+
_.each(menuInsArr, function(menuIns){
183+
menuIns.hide();
184+
});
185+
}
186+
187+
return {
188+
show: function(){
189+
container.style.display = "block";
190+
},
191+
hide: function(){
192+
container.style.display = "none";
193+
}
194+
};
195+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<% _.each(menu, function(itm, menuId){ %>
2+
<div class="tip-btn" menuId="<%= menuId %>">
3+
<i class="icon-list"></i>
4+
<span><%= itm.name %></span>
5+
</div>
6+
<% }) %>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var utils = require("@/common/utils");
2+
var tpl = require("./template/popupListTpl.html");
3+
4+
module.exports = function(opt){
5+
var items = opt.items;
6+
var reportClick = opt.reportClick || utils.noop;
7+
8+
var dom = utils.createElementFromHTML(_.template(tpl)({
9+
items: items
10+
}));
11+
document.body.appendChild(dom);
12+
utils.on(window, "resize", function(){
13+
hide();
14+
});
15+
utils.on(document, "click", function(e){
16+
var target = e.srcElement || e.target;
17+
if(!dom.contains(target)){
18+
hide();
19+
}
20+
});
21+
22+
// 菜单点击
23+
utils.live("li", "click", function(e){
24+
var menuId;
25+
var target = e.srcElement || e.target;
26+
if(utils.hasClass(target.parentNode, "popup-item")){
27+
target = target.parentNode;
28+
}
29+
menuId = target.getAttribute("menuId");
30+
// 上报点击项
31+
reportClick(items[menuId], menuId);
32+
hide();
33+
}, dom);
34+
35+
function show(pos){
36+
utils.removeClass(dom, "hide");
37+
dom.style.left = pos.left + "px";
38+
dom.style.top = pos.top + "px";
39+
pos.width && (dom.style.width = pos.width + "px");
40+
}
41+
42+
function hide(){
43+
utils.addClass(dom, "hide");
44+
}
45+
46+
return {
47+
show: show,
48+
hide: hide,
49+
};
50+
};

0 commit comments

Comments
 (0)