-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加 alias 作为 require 根路径 新增 getArticleJson 接口 新增 popupList 组件 utils.sameProtocol 兼容只有根路径的情况 css 兼容新旧两版 tenantInfo 新版 tenantInfo 独立目录
- Loading branch information
Showing
11 changed files
with
410 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
var apiHelper = require("@/app/modules/apiHelper"); | ||
var PopupList = require("@/app/modules/uikit/popupList"); | ||
var utils = require("@/common/utils"); | ||
var channel = require("@/app/modules/channel"); | ||
var tpl = require("./template/indexTpl.html"); | ||
|
||
module.exports = function(){ | ||
// 二级菜单实例 | ||
var menuInsArr = []; | ||
var menuArr = []; | ||
var container = document.querySelector(".em-widget-tip"); | ||
container.innerHTML = ""; | ||
utils.addClass(container, "new"); | ||
|
||
apiHelper.getNotice() | ||
.then(function(notice){ | ||
if(!notice.enabled) return; | ||
|
||
|
||
|
||
// test | ||
// notice.content = [ | ||
// { | ||
// name: "菜单", | ||
// sub_button: [ | ||
// { | ||
// type: "view", | ||
// name: "搜索2666", | ||
// url: "http://www.soso.com/" | ||
// } | ||
// ] | ||
// }, | ||
// { | ||
// name: "222", | ||
// sub_button: [ | ||
// { | ||
// type: "media_id", | ||
// name: "111", | ||
// media_id: "75cffa4b-e462-40e8-a517-0ff807db29a6" | ||
// }, | ||
// { | ||
// type: "media_id", | ||
// name: "香格里拉", | ||
// media_id: "4150c891-9917-4482-909c-ab7c9954110a" | ||
// } | ||
// ] | ||
// }, | ||
// { | ||
// type: "media_id", | ||
// name: "333", | ||
// media_id: "75cffa4b-e462-40e8-a517-0ff807db29a6" | ||
// } | ||
// ]; | ||
|
||
|
||
|
||
|
||
menuArr = notice.content; | ||
container.innerHTML = _.template(tpl)({ | ||
menu: menuArr, | ||
}); | ||
createMenu(); | ||
utils.live(".tip-btn", "click", onMenuClick, container); | ||
}); | ||
|
||
// 菜单点击 | ||
function onMenuClick(e){ | ||
var menuId; | ||
var menuDat; | ||
var target = e.srcElement || e.target; | ||
var targetBounding; | ||
if(utils.hasClass(target.parentNode, "tip-btn")){ | ||
target = target.parentNode; | ||
} | ||
menuId = target.getAttribute("menuId"); | ||
menuDat = menuArr[menuId]; | ||
|
||
targetBounding = target.getBoundingClientRect(); | ||
handleMenuClick(menuDat, menuId, { | ||
top: targetBounding.top + 48, | ||
left: targetBounding.left + (target.clientWidth * 0.1), | ||
width: target.clientWidth * 0.8, | ||
}); | ||
// ie8 | ||
// 使得 popupList 可以自动关闭 | ||
e.stopPropagation(); | ||
return false; | ||
} | ||
|
||
function handleMenuClick(menuDat, menuId, pos){ | ||
// 有子菜单 | ||
if(menuDat.sub_button){ | ||
popupList(menuId, pos || { | ||
left: 0, | ||
top: 0, | ||
width: 0, | ||
}); | ||
} | ||
// 无子菜单 | ||
else{ | ||
hideAllSubMenu(); | ||
fireMsg(menuDat); | ||
} | ||
} | ||
|
||
function fireMsg(dat){ | ||
switch(dat.type){ | ||
// 发送 article | ||
case "media_id": | ||
fireArticle(dat); | ||
break; | ||
// 发送 url | ||
case "view": | ||
fireUrl(dat); | ||
break; | ||
// 发送 text | ||
case "txt": | ||
fireText(dat); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function fireArticle(menuDat){ | ||
apiHelper.getArticleJson({ | ||
media_id: menuDat.media_id | ||
}).then(function(articles){ | ||
articles = _.map(articles, function(article){ | ||
return { | ||
title: article.title, | ||
digest: article.digest, | ||
description: article.digest, | ||
// url: "/v1/webimplugin/tenants/" + article.tenantId + "/robot/article/html/" + article.articleId, | ||
url: "/v1/Tenants/" + article.tenantId + "/robot/article/html/" + article.articleId, | ||
thumbUrl: "/v1/Tenant/" + article.tenantId + "/MediaFiles/" + article.thumb_media_id, | ||
picurl: "/v1/Tenant/" + article.tenantId + "/MediaFiles/" + article.thumb_media_id, | ||
prop: article.prop, | ||
}; | ||
}); | ||
channel.handleMessage( | ||
{ | ||
ext: { | ||
msgtype: { | ||
articles: articles, | ||
} | ||
}, | ||
}, | ||
{ | ||
type: "article", | ||
noPrompt: true | ||
} | ||
); | ||
}); | ||
} | ||
|
||
function fireText(menuDat){ | ||
|
||
} | ||
|
||
function fireUrl(menuDat){ | ||
|
||
} | ||
|
||
// 每个 btn 创建一个菜单 | ||
function createMenu(){ | ||
_.each(menuArr, function(menuDat, menuId){ | ||
menuInsArr[menuId] = new PopupList({ | ||
items: menuDat.sub_button, | ||
reportClick: handleMenuClick, | ||
}); | ||
}); | ||
} | ||
|
||
// 弹出菜单 | ||
function popupList(menuId, pos){ | ||
hideAllSubMenu(); | ||
menuInsArr[menuId].show(pos); | ||
} | ||
|
||
function hideAllSubMenu(){ | ||
_.each(menuInsArr, function(menuIns){ | ||
menuIns.hide(); | ||
}); | ||
} | ||
|
||
return { | ||
show: function(){ | ||
container.style.display = "block"; | ||
}, | ||
hide: function(){ | ||
container.style.display = "none"; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% _.each(menu, function(itm, menuId){ %> | ||
<div class="tip-btn" menuId="<%= menuId %>"> | ||
<i class="icon-list"></i> | ||
<span><%= itm.name %></span> | ||
</div> | ||
<% }) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var utils = require("@/common/utils"); | ||
var tpl = require("./template/popupListTpl.html"); | ||
|
||
module.exports = function(opt){ | ||
var items = opt.items; | ||
var reportClick = opt.reportClick || utils.noop; | ||
|
||
var dom = utils.createElementFromHTML(_.template(tpl)({ | ||
items: items | ||
})); | ||
document.body.appendChild(dom); | ||
utils.on(window, "resize", function(){ | ||
hide(); | ||
}); | ||
utils.on(document, "click", function(e){ | ||
var target = e.srcElement || e.target; | ||
if(!dom.contains(target)){ | ||
hide(); | ||
} | ||
}); | ||
|
||
// 菜单点击 | ||
utils.live("li", "click", function(e){ | ||
var menuId; | ||
var target = e.srcElement || e.target; | ||
if(utils.hasClass(target.parentNode, "popup-item")){ | ||
target = target.parentNode; | ||
} | ||
menuId = target.getAttribute("menuId"); | ||
// 上报点击项 | ||
reportClick(items[menuId], menuId); | ||
hide(); | ||
}, dom); | ||
|
||
function show(pos){ | ||
utils.removeClass(dom, "hide"); | ||
dom.style.left = pos.left + "px"; | ||
dom.style.top = pos.top + "px"; | ||
pos.width && (dom.style.width = pos.width + "px"); | ||
} | ||
|
||
function hide(){ | ||
utils.addClass(dom, "hide"); | ||
} | ||
|
||
return { | ||
show: show, | ||
hide: hide, | ||
}; | ||
}; |
Oops, something went wrong.