app.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. $(function() {
  2. // 读取body data-type 判断是哪个页面然后执行相应页面方法,方法在下面。
  3. var dataType = $('body').attr('data-type');
  4. console.log(dataType);
  5. for (key in pageData) {
  6. if (key == dataType) {
  7. pageData[key]();
  8. }
  9. }
  10. // // 判断用户是否已有自己选择的模板风格
  11. // if(storageLoad('SelcetColor')){
  12. // $('body').attr('class',storageLoad('SelcetColor').Color)
  13. // }else{
  14. // storageSave(saveSelectColor);
  15. // $('body').attr('class','theme-black')
  16. // }
  17. autoLeftNav();
  18. $(window).resize(function() {
  19. autoLeftNav();
  20. console.log($(window).width())
  21. });
  22. // if(storageLoad('SelcetColor')){
  23. // }else{
  24. // storageSave(saveSelectColor);
  25. // }
  26. })
  27. // 页面数据
  28. var pageData = {
  29. // ===============================================
  30. // 首页
  31. // ===============================================
  32. 'index': function indexData() {
  33. $('#example-r').DataTable({
  34. bInfo: false, //页脚信息
  35. dom: 'ti'
  36. });
  37. // ==========================
  38. // 百度图表A http://echarts.baidu.com/
  39. // ==========================
  40. var echartsA = echarts.init(document.getElementById('tpl-echarts'));
  41. option = {
  42. tooltip: {
  43. trigger: 'axis'
  44. },
  45. grid: {
  46. top: '3%',
  47. left: '3%',
  48. right: '4%',
  49. bottom: '3%',
  50. containLabel: true
  51. },
  52. xAxis: [{
  53. type: 'category',
  54. boundaryGap: false,
  55. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  56. }],
  57. yAxis: [{
  58. type: 'value'
  59. }],
  60. textStyle: {
  61. color: '#838FA1'
  62. },
  63. series: [{
  64. name: '邮件营销',
  65. type: 'line',
  66. stack: '总量',
  67. areaStyle: { normal: {} },
  68. data: [120, 132, 101, 134, 90],
  69. itemStyle: {
  70. normal: {
  71. color: '#1cabdb',
  72. borderColor: '#1cabdb',
  73. borderWidth: '2',
  74. borderType: 'solid',
  75. opacity: '1'
  76. },
  77. emphasis: {
  78. }
  79. }
  80. }]
  81. };
  82. echartsA.setOption(option);
  83. },
  84. // ===============================================
  85. // 图表页
  86. // ===============================================
  87. 'chart': function chartData() {
  88. // ==========================
  89. // 百度图表A http://echarts.baidu.com/
  90. // ==========================
  91. var echartsC = echarts.init(document.getElementById('tpl-echarts-C'));
  92. optionC = {
  93. tooltip: {
  94. trigger: 'axis'
  95. },
  96. legend: {
  97. data: ['蒸发量', '降水量', '平均温度']
  98. },
  99. xAxis: [{
  100. type: 'category',
  101. data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
  102. }],
  103. yAxis: [{
  104. type: 'value',
  105. name: '水量',
  106. min: 0,
  107. max: 250,
  108. interval: 50,
  109. axisLabel: {
  110. formatter: '{value} ml'
  111. }
  112. },
  113. {
  114. type: 'value',
  115. name: '温度',
  116. min: 0,
  117. max: 25,
  118. interval: 5,
  119. axisLabel: {
  120. formatter: '{value} °C'
  121. }
  122. }
  123. ],
  124. series: [{
  125. name: '蒸发量',
  126. type: 'bar',
  127. data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
  128. },
  129. {
  130. name: '降水量',
  131. type: 'bar',
  132. data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
  133. },
  134. {
  135. name: '平均温度',
  136. type: 'line',
  137. yAxisIndex: 1,
  138. data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
  139. }
  140. ]
  141. };
  142. echartsC.setOption(optionC);
  143. var echartsB = echarts.init(document.getElementById('tpl-echarts-B'));
  144. optionB = {
  145. tooltip: {
  146. trigger: 'axis'
  147. },
  148. legend: {
  149. x: 'center',
  150. data: ['某软件', '某主食手机', '某水果手机', '降水量', '蒸发量']
  151. },
  152. radar: [{
  153. indicator: [
  154. { text: '品牌', max: 100 },
  155. { text: '内容', max: 100 },
  156. { text: '可用性', max: 100 },
  157. { text: '功能', max: 100 }
  158. ],
  159. center: ['25%', '40%'],
  160. radius: 80
  161. },
  162. {
  163. indicator: [
  164. { text: '外观', max: 100 },
  165. { text: '拍照', max: 100 },
  166. { text: '系统', max: 100 },
  167. { text: '性能', max: 100 },
  168. { text: '屏幕', max: 100 }
  169. ],
  170. radius: 80,
  171. center: ['50%', '60%'],
  172. },
  173. {
  174. indicator: (function() {
  175. var res = [];
  176. for (var i = 1; i <= 12; i++) {
  177. res.push({ text: i + '月', max: 100 });
  178. }
  179. return res;
  180. })(),
  181. center: ['75%', '40%'],
  182. radius: 80
  183. }
  184. ],
  185. series: [{
  186. type: 'radar',
  187. tooltip: {
  188. trigger: 'item'
  189. },
  190. itemStyle: { normal: { areaStyle: { type: 'default' } } },
  191. data: [{
  192. value: [60, 73, 85, 40],
  193. name: '某软件'
  194. }]
  195. },
  196. {
  197. type: 'radar',
  198. radarIndex: 1,
  199. data: [{
  200. value: [85, 90, 90, 95, 95],
  201. name: '某主食手机'
  202. },
  203. {
  204. value: [95, 80, 95, 90, 93],
  205. name: '某水果手机'
  206. }
  207. ]
  208. },
  209. {
  210. type: 'radar',
  211. radarIndex: 2,
  212. itemStyle: { normal: { areaStyle: { type: 'default' } } },
  213. data: [{
  214. name: '降水量',
  215. value: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 75.6, 82.2, 48.7, 18.8, 6.0, 2.3],
  216. },
  217. {
  218. name: '蒸发量',
  219. value: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 35.6, 62.2, 32.6, 20.0, 6.4, 3.3]
  220. }
  221. ]
  222. }
  223. ]
  224. };
  225. echartsB.setOption(optionB);
  226. var echartsA = echarts.init(document.getElementById('tpl-echarts-A'));
  227. option = {
  228. tooltip: {
  229. trigger: 'axis',
  230. },
  231. legend: {
  232. data: ['邮件', '媒体', '资源']
  233. },
  234. grid: {
  235. left: '3%',
  236. right: '4%',
  237. bottom: '3%',
  238. containLabel: true
  239. },
  240. xAxis: [{
  241. type: 'category',
  242. boundaryGap: true,
  243. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  244. }],
  245. yAxis: [{
  246. type: 'value'
  247. }],
  248. series: [
  249. {
  250. name: '邮件',
  251. type: 'line',
  252. stack: '总量',
  253. areaStyle: { normal: {} },
  254. data: [120, 132, 101, 134, 90, 230, 210],
  255. itemStyle: {
  256. normal: {
  257. color: '#59aea2'
  258. },
  259. emphasis: {
  260. }
  261. }
  262. },
  263. {
  264. name: '媒体',
  265. type: 'line',
  266. stack: '总量',
  267. areaStyle: { normal: {} },
  268. data: [220, 182, 191, 234, 290, 330, 310],
  269. itemStyle: {
  270. normal: {
  271. color: '#e7505a'
  272. }
  273. }
  274. },
  275. {
  276. name: '资源',
  277. type: 'line',
  278. stack: '总量',
  279. areaStyle: { normal: {} },
  280. data: [150, 232, 201, 154, 190, 330, 410],
  281. itemStyle: {
  282. normal: {
  283. color: '#32c5d2'
  284. }
  285. }
  286. }
  287. ]
  288. };
  289. // 通过WebSocket获取数据并刷新图表
  290. var ws = new WebSocket('ws://localhost:8888/ws/charts');
  291. ws.onmessage = function(evt) {
  292. var array = JSON.parse(evt.data);
  293. for (var i = 0; i < array.length; ++i) {
  294. option.series[i].data = array[i];
  295. }
  296. echartsA.setOption(option);
  297. };
  298. }
  299. }
  300. // 风格切换
  301. $('.tpl-skiner-toggle').on('click', function() {
  302. $('.tpl-skiner').toggleClass('active');
  303. })
  304. $('.tpl-skiner-content-bar').find('span').on('click', function() {
  305. $('body').attr('class', $(this).attr('data-color'))
  306. saveSelectColor.Color = $(this).attr('data-color');
  307. // 保存选择项
  308. storageSave(saveSelectColor);
  309. })
  310. // 侧边菜单开关
  311. function autoLeftNav() {
  312. $('.tpl-header-switch-button').on('click', function() {
  313. if ($('.left-sidebar').is('.active')) {
  314. if ($(window).width() > 1024) {
  315. $('.tpl-content-wrapper').removeClass('active');
  316. }
  317. $('.left-sidebar').removeClass('active');
  318. } else {
  319. $('.left-sidebar').addClass('active');
  320. if ($(window).width() > 1024) {
  321. $('.tpl-content-wrapper').addClass('active');
  322. }
  323. }
  324. })
  325. if ($(window).width() < 1024) {
  326. $('.left-sidebar').addClass('active');
  327. } else {
  328. $('.left-sidebar').removeClass('active');
  329. }
  330. }
  331. // 侧边菜单
  332. $('.sidebar-nav-sub-title').on('click', function() {
  333. $(this).siblings('.sidebar-nav-sub').slideToggle(80)
  334. .end()
  335. .find('.sidebar-nav-sub-ico').toggleClass('sidebar-nav-sub-ico-rotate');
  336. })