index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. const $ = require("jquery");
  2. require("babel-polyfill");
  3. const echarts = require("echarts");
  4. require("./../css/knowledgeMap.less");
  5. require("./../css/common.less");
  6. // require("ztree");
  7. require('./../resources/images/icon.png');
  8. require('./../resources/images/iconOpen.png');
  9. require('./../resources/images/iconClose.png');
  10. require('./../resources/images/node.png');
  11. require('./../resources/images/radioUnSelect.png');
  12. require('./../resources/images/radioSelect.png');
  13. require('./../resources/images/iconSlideUp.png');
  14. require('./../resources/images/iconSlideDown.png');
  15. require('./../resources/images/iconSelect.png');
  16. require('./../resources/images/syflogo.png');
  17. require('./../resources/images/logo.png');
  18. require('./../resources/images/logo_shaoyifu.png');
  19. require('./../resources/zTree/js/jquery.ztree.core.min.js');
  20. require('./../resources/zTree/js/jquery.ztree.excheck.min.js')
  21. require('./../resources/zTree/css/zTreeStyle/zTreeStyle.css');
  22. const iconUp = require('./../resources/images/iconUp.png');
  23. const iconDown = require('./../resources/images/iconDown.png');
  24. const { post, api, ifHideLogo, getUrlArgObject } = require('./api.js');
  25. const { mapData, zTreeData, mapData3, zTreeData3 } = require('./data.js');
  26. const { drawGraph, updateTree, getGraph, getTree, getNode, getTab, renderTab, setTabBottomHei, selectedZTreeNode,
  27. setSelectName, hideHideTab, hideSlide, reDrawGraph } = require('./graphMap.js');
  28. /**右侧侧边栏折叠*/
  29. let isRightCollapse = false
  30. let input = getUrlArgObject("input") || ""
  31. let label = getUrlArgObject("label") || ""
  32. let noTree = getUrlArgObject("no-tree") || false
  33. window.select_type = "疾病";
  34. window.select_type_noSearch = "疾病";
  35. window.refreshTree = true
  36. let disease = getUrlArgObject("disease")
  37. // 用来存储节点操作的数据
  38. window.knowledgeMapData = {}//当前右键节点数据
  39. window.graphMapUpdatedData = null //实时更新的关系图数据
  40. window.graphMap = null //当前关系图实例对象
  41. window.knowledgeMapSetting = {
  42. operation: "view", //操作类型,修改
  43. draggable: true, //是否能拖拽节点
  44. zTree: !noTree,//是否有zTree
  45. expandPropertyId: [],//存储展开属性的nodeId
  46. expandRelationshipsId: [],//存储展开关系的nodeId
  47. currentNodeId: -1,//存储右侧显示的节点的nodeId
  48. legends: [],//图例
  49. selected: {},//选中的数据
  50. showLegend: true, //是否显示图例
  51. showLegendNum: 0,//展示图例的数量
  52. showLegendAll: false,//是否展示全部图例
  53. records: [],//历史记录
  54. }
  55. if (noTree) {
  56. $(".content .right").css('display', 'none')
  57. $(".content .left").css("width", "100%")
  58. } else {
  59. $(".content .right").css('display', 'block')
  60. }
  61. setHei()
  62. ifHideLogo();
  63. function setHei() {
  64. const clientHei = $(window).height()
  65. const contentHei = 580
  66. $(".left").css("height", contentHei + 'px')
  67. $(".right").css("height", contentHei + 'px')
  68. if (select_type == "疾病") {
  69. setTabBottomHei(1)
  70. } else {
  71. setTabBottomHei(2)
  72. }
  73. $("#main").css("height", contentHei - 20 - 20 - 10 + 'px')
  74. }
  75. $(window).resize(function () {
  76. setHei()
  77. // getGraph(graphTxt,select_type);
  78. })
  79. // window.onload = function () {
  80. // console.log("notTree", notTree)
  81. // }
  82. //关系图
  83. getGraph(disease || input || "艾滋病", label || select_type);
  84. getTree(1, 1, disease || "艾滋病");
  85. $('#searchInp').val(disease || "艾滋病")
  86. //选择类型
  87. $('.select').click(function (e) {
  88. e.stopPropagation();
  89. hideSlide('selectList')
  90. const selectListShow = $('.selectList').css('display')
  91. if (selectListShow == 'none') {
  92. $('.iconSlide').attr('src', './images/iconSlideUp.png')
  93. } else {
  94. $('.iconSlide').attr('src', './images/iconSlideDown.png')
  95. }
  96. $('.selectList').fadeToggle()
  97. })
  98. $('.selectList .selectItem').click(function () {
  99. select_type_noSearch = $(this).attr('data-id')
  100. const txt = $(this).text()
  101. const oldTxt = $(".selectedName").html()
  102. setSelectName(txt)
  103. $("#searchInp").attr("placeholder", `请输入${txt}名称`)
  104. if (txt != oldTxt) {
  105. $('#searchInp').val("")
  106. }
  107. })
  108. //搜索节点名
  109. $("#searchInp").bind("input propertychange", function (event) {
  110. const val = $("#searchInp").val().trim()
  111. if (val) {
  112. getNode(val, select_type_noSearch)
  113. } else {
  114. $(".tabNameList").hide()
  115. }
  116. });
  117. //切换条目
  118. $('.radioItem').click(function (e) {
  119. $('.radioItem').css('color', '#333333')
  120. $(this).css("color", '#409EF1')
  121. const dataId = $(".showTabList .tab.activeTab").attr("data-id")
  122. const initDiag = dataId == "疾病" ? "艾滋病" : "过氧化氢溶液"
  123. const type = +$(this).attr('data-type')
  124. const subType = +$(this).attr('sub-type')
  125. // $(this).children('img').attr('src')
  126. $('.iconRadio').attr('src', '/images/radioUnSelect.png')
  127. $(this).children('img').attr('src', '/images/radioSelect.png')
  128. $('#searchInp').val(initDiag)
  129. getTree(subType, type, initDiag);
  130. getGraph(initDiag, select_type);
  131. // updateTree(initDiag)
  132. })
  133. //搜索
  134. $('#searchBtn').click(function (e) {
  135. e.stopPropagation()
  136. hideSlide()
  137. const val = $('#searchInp').val().trim()
  138. if (val) {
  139. const clientHei = $(window).height()
  140. const contentHei = clientHei - 80
  141. $(".tabNameList").hide()
  142. getGraph(val, select_type_noSearch).then(() => {
  143. if (!window.refreshTree) {
  144. return
  145. }
  146. select_type = select_type_noSearch
  147. if (select_type == '疾病') {
  148. // $('#searchInp').val("高血压3级")
  149. getTree(1, 1, val);
  150. } else if (select_type == '药品') {
  151. getTree(0, 2, val);
  152. } else if (select_type == '症状') {
  153. getTree(0, 3, val);
  154. }
  155. // else if (select_type == '手术和操作') {
  156. // getTree(0, 4, val);
  157. // }
  158. else if (select_type == '实验室检查') {
  159. getTree(0, 5, val);
  160. } else if (select_type == '辅助检查') {
  161. getTree(0, 6, val);
  162. }
  163. if (select_type == '疾病') {
  164. $('.iconRadio').attr('src', '/images/radioUnSelect.png')
  165. $('.ICD10 img').attr('src', '/images/radioSelect.png')
  166. $(".radioList").show()
  167. $(".radioList .radioItem").hide()
  168. $(".radioList .disease").show()
  169. setTabBottomHei(1)
  170. } else if (select_type == '药品') {
  171. $('.iconRadio').attr('src', '/images/radioUnSelect.png')
  172. $('.general img').attr('src', '/images/radioSelect.png')
  173. $(".radioList").show()
  174. $(".radioList .radioItem").hide()
  175. $(".radioList .medicine").show()
  176. setTabBottomHei(1)
  177. }
  178. else {
  179. $(".radioList").hide()
  180. setTabBottomHei(2)
  181. }
  182. let renderTabInfo = getTab(select_type)
  183. renderTab(renderTabInfo)
  184. })
  185. } else {
  186. $('.tabNameListNoSearch').show()
  187. }
  188. })
  189. let renderTabInfo = getTab("疾病")
  190. renderTab(renderTabInfo)
  191. $(".tabList").click(function (e) {
  192. e.stopPropagation()
  193. hideSlide()
  194. })
  195. $(".hideTabList").click(function (e) {
  196. e.stopPropagation()
  197. hideSlide()
  198. })
  199. //点击页面其他地方关闭下拉
  200. $('html').click(function () {
  201. hideSlide()
  202. // const selectListShow = $('.selectList').css('display')
  203. // const tabNameListShow = $('.tabNameList').css('display')
  204. // const tabNameListNoSearchShow = $('.tabNameListNoSearch').css('display')
  205. // const hideTabListShow = $('.hideTabList').css('display')
  206. // if(selectListShow == 'block'){
  207. // $('.selectList').hide()
  208. // $('.iconSlide').attr('src','./images/iconSlideDown.png')
  209. // }
  210. // if(tabNameListShow == 'block'){
  211. // $('.tabNameList').hide()
  212. // }
  213. // if(tabNameListNoSearchShow == 'block'){
  214. // $('.tabNameListNoSearch').hide()
  215. // }
  216. // if(hideTabListShow == 'block'){
  217. // hideHideTab()
  218. // }
  219. })
  220. // $(function () {
  221. // $(".right-aside-collapse").on("click", function () {
  222. // isRightCollapse = !isRightCollapse
  223. // if (isRightCollapse) {
  224. // $("#tabList > .toggleTab").hide()
  225. // $(".right").animate({ "width": '150px' })
  226. // } else {
  227. // $(".right").animate({ "width": '394px' })
  228. // }
  229. // })
  230. // })
  231. let toggleTabHtml = ""
  232. $(".right-aside-collapse").on("click", function () {
  233. isRightCollapse = !isRightCollapse
  234. if (isRightCollapse) {
  235. $(this).attr('class', 'right-aside-collapsed')
  236. toggleTabHtml = $("#tabList > .toggleTab").html()
  237. $("#tabList > .toggleTab").empty()
  238. // document.querySelector('.toggleTab').style.display = 'none';
  239. $(".right").animate({ "width": '150px' }, function () {
  240. })
  241. const contentWidth = $(".content").width()
  242. const leftWidth = (contentWidth - 150).toString() + 'px'
  243. // console.log("contentWidth", leftWidth);
  244. $(".content .left").animate({ 'width': leftWidth, }, function () {
  245. window.graphMap.resize()
  246. // console.log("graphMap", window.graphMap)
  247. })
  248. } else {
  249. $(this).attr('class', 'right-aside-collapse')
  250. $("#tabList > .toggleTab").html(toggleTabHtml)
  251. $(".right").animate({ "width": '461px' })
  252. const contentWidth = $(".content").width()
  253. const leftWidth = (contentWidth - 461).toString() + 'px'
  254. $(".content .left").animate({ 'width': leftWidth, }, function () {
  255. window.graphMap.resize()
  256. // console.log("graphMap", window.graphMap)
  257. })
  258. }
  259. })
  260. window.addEventListener("message", function (event) {
  261. // console.log("message", event.data);
  262. if (event.data.operation == "left-collapse") {
  263. const contentWidth = $(".content").width()
  264. // console.log("contentWidth", contentWidth)
  265. let leftWidth = 0
  266. if (isRightCollapse) {
  267. leftWidth = (contentWidth - 150).toString() + 'px'
  268. $(".content .left").css('width', leftWidth)
  269. } else {
  270. leftWidth = (contentWidth - 461).toString() + 'px'
  271. $(".content .left").css('width', leftWidth)
  272. }
  273. // console.log("leftWidth", leftWidth);
  274. window.graphMap.resize()
  275. }
  276. })
  277. $(".record .selectedData,.record").on("click", function (event) {
  278. // console.log("event-record", event)
  279. event.stopPropagation()
  280. // event.preventDefault()
  281. $(".record .selectList-record").slideToggle()
  282. $(".record .selectList-record .selectItem-record").on("click", function (event) {
  283. // event.stopPropagation()
  284. // console.log("eve")
  285. const name = $(this).attr("name")
  286. const label = $(this).attr("label")
  287. // reDrawGraph(name, label)
  288. getGraph(name, label)
  289. // $(".record .selectList-record").slideUp()
  290. })
  291. })
  292. module.exports = {
  293. getTab,
  294. renderTab
  295. }