WBData.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. const ar = async (time) => {
  2. try {
  3. let {data} = await axios({
  4. method: 'get',
  5. url: '/gettime?time=' + time,
  6. });
  7. console.log(data)
  8. } catch (error) {
  9. console.log(error)
  10. }
  11. }
  12. const getlastmonth = () => {
  13. var nowdays = new Date();
  14. var year = nowdays.getFullYear();
  15. var month = nowdays.getMonth();
  16. if(month==0){
  17. month=12;
  18. year=year-1;
  19. }
  20. if (month < 10) {
  21. month = "0" + month;
  22. }
  23. var myDate = new Date(year, month, 0);
  24. var lastDay = year + "-" + month + "-" + myDate.getDate()
  25. return lastDay
  26. }
  27. var fna = 0
  28. var boe = 0
  29. const xuanr = (data) => {
  30. document.querySelector('#der').innerHTML = ''
  31. let checktime=0;
  32. data.map((i)=>{
  33. let d = new Date(i.time)
  34. let times = (d.getMonth() + 1) + '/' + d.getDate()
  35. if(document.getElementById(`${i.id}`)){
  36. let fa = (parseInt(i.fan) - parseInt(fna)).toString()
  37. let bo = (parseInt(i.post) - parseInt(boe)).toString()
  38. if (fa < 0){ var facon = `<div style="background: #ff7b7b">${fa}</div>` } else { var facon = `<div style="background: #a6ff88">+${fa}</div>` }
  39. if (bo < 0){ var faconer = `<div style="background: #ff7b7b">${bo}</div>` } else { var faconer = `<div style="background: #a6ff88">+${bo}</div>` }
  40. let der = document.getElementById(`${i.id}`).parentNode
  41. if(d.getDate()!=checktime+1){
  42. checktime=d.getDate();
  43. der.innerHTML += `
  44. <div class="a4" id=${i.id}>
  45. <div style="background: #ff7b7b">无</div>
  46. <div style="background: #ff7b7b">无</div>
  47. <div style="background: #ff7b7b">无</div>
  48. <div style="background: #ff7b7b">无</div>
  49. </div>
  50. <div class="a4" id=${i.id}>
  51. <div>${i.post}</div>
  52. ${faconer}
  53. <div>${i.fan}</div>
  54. ${facon}
  55. </div>
  56. `
  57. }else{
  58. checktime++;
  59. der.innerHTML += `
  60. <div class="a4" id=${i.id}>
  61. <div>${i.post}</div>
  62. ${faconer}
  63. <div>${i.fan}</div>
  64. ${facon}
  65. </div>
  66. `
  67. }
  68. fna = i.fan
  69. boe = i.post
  70. }else{
  71. checktime=1;
  72. var date = new Date(i.time);
  73. date_value=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
  74. if(getlastmonth() != date_value){
  75. let fa = (parseInt(i.fan) - parseInt(fna)).toString()
  76. let bo = (parseInt(i.post) - parseInt(boe)).toString()
  77. if (fa < 0){ var facon = `<div style="background: #ff7b7b">${fa}</div>` } else { var facon = `<div style="background: #a6ff88">+${fa}</div>` }
  78. if (bo < 0){ var faconer = `<div style="background: #ff7b7b">${bo}</div>` } else { var faconer = `<div style="background: #a6ff88">+${bo}</div>` }
  79. document.querySelector('#der').innerHTML += `
  80. <div class="a1">
  81. <div class="a2">${i.name}</div>
  82. <div class="a3">${i.id}</div>
  83. <div class="a4">
  84. <div>发博数</div>
  85. <div>发博递减</div>
  86. <div>粉丝数</div>
  87. <div>粉丝递减</div>
  88. </div>
  89. <div class="a4" id=${i.id}>
  90. <div>${i.post}</div>
  91. ${faconer}
  92. <div>${i.fan}</div>
  93. ${facon}
  94. </div>
  95. </div>
  96. `
  97. }
  98. fna = i.fan
  99. boe = i.post
  100. }
  101. // boe = i.post
  102. })
  103. let checkdd=0;
  104. for(let der = 0; der < (data.length/45); der ++){
  105. let dd = new Date(data[der].time)
  106. let times = (dd.getMonth() + 1) + '/' + dd.getDate()
  107. let timeser = dd.getFullYear() + '-' + (dd.getMonth() + 1) + '-' + dd.getDate()
  108. if (timeser != getlastmonth()) {
  109. if(dd.getDate()!=checkdd+1){
  110. times = (dd.getMonth()+1) + '/' +(dd.getDate()-1)
  111. document.querySelector('.tim').innerHTML += `<div class="tim1">${times}</div>`
  112. times = (dd.getMonth()+1) + '/' +(dd.getDate())
  113. document.querySelector('.tim').innerHTML += `<div class="tim1">${times}</div>`
  114. checkdd=dd.getDate();
  115. }else{
  116. checkdd++;
  117. document.querySelector('.tim').innerHTML += `<div class="tim1">${times}</div>`
  118. }
  119. }
  120. }
  121. }
  122. var fnaer = 0
  123. var boeer = 0
  124. const chaxun = (data, ad) => {
  125. let checktime=0;
  126. document.querySelector('#der').innerHTML = ''
  127. data.map((i)=>{
  128. let d = new Date(i.time)
  129. let times = (d.getMonth() + 1) + '/' + d.getDate()
  130. let dder = new Date(i.time)
  131. let timeser = dder.getFullYear() + '/' + (dder.getMonth() + 1) + '/' + dder.getDate()
  132. if(document.getElementById(`${i.id}`)){
  133. let fa = (parseInt(i.fan) - parseInt(fnaer)).toString()
  134. let bo = (parseInt(i.post) - parseInt(boeer)).toString()
  135. if (fa < 0){ var facon = `<div style="background: #ff7b7b">${fa}</div>` } else { var facon = `<div style="background: #a6ff88">+${fa}</div>` }
  136. if (bo < 0){ var faconer = `<div style="background: #ff7b7b">${bo}</div>` } else { var faconer = `<div style="background: #a6ff88">+${bo}</div>` }
  137. let der = document.getElementById(`${i.id}`).parentNode
  138. if(d.getDate()!=checktime+1){
  139. checktime=d.getDate();
  140. der.innerHTML += `
  141. <div class="a4" id=${i.id}>
  142. <div style="background: #ff7b7b">无</div>
  143. <div style="background: #ff7b7b">无</div>
  144. <div style="background: #ff7b7b">无</div>
  145. <div style="background: #ff7b7b">无</div>
  146. </div>
  147. <div class="a4" id=${i.id}>
  148. <div>${i.post}</div>
  149. ${faconer}
  150. <div>${i.fan}</div>
  151. ${facon}
  152. </div>
  153. `
  154. }else{
  155. checktime++;
  156. der.innerHTML += `
  157. <div class="a4" id=${i.id}>
  158. <div>${i.post}</div>
  159. ${faconer}
  160. <div>${i.fan}</div>
  161. ${facon}
  162. </div>
  163. `
  164. }
  165. /*der.innerHTML += `
  166. <div class="a4" id=${i.id}>
  167. <div>${i.post}</div>
  168. ${faconer}
  169. <div>${i.fan}</div>
  170. ${facon}
  171. </div>
  172. `*/
  173. fnaer = i.fan
  174. boeer = i.post
  175. }else{
  176. checktime=1;
  177. var date = new Date(i.time);
  178. date_value=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
  179. if(getlastmonth() != date_value){
  180. let fa = (parseInt(i.fan) - parseInt(fnaer)).toString()
  181. let bo = (parseInt(i.post) - parseInt(boeer)).toString()
  182. if (timeser == "2018/10/24") {
  183. fa = 0
  184. bo = 0
  185. }
  186. if (fa < 0){ var facon = `<div style="background: #ff7b7b">${fa}</div>` } else { var facon = `<div style="background: #a6ff88">+${fa}</div>` }
  187. if (bo < 0){ var faconer = `<div style="background: #ff7b7b">${bo}</div>` } else { var faconer = `<div style="background: #a6ff88">+${bo}</div>` }
  188. document.querySelector('#der').innerHTML += `
  189. <div class="a1">
  190. <div class="a2">${i.name}</div>
  191. <div class="a3">${i.id}</div>
  192. <div class="a4">
  193. <div>发博数</div>
  194. <div>发博递减</div>
  195. <div>粉丝数</div>
  196. <div>粉丝递减</div>
  197. </div>
  198. <div class="a4" id=${i.id}>
  199. <div>${i.post}</div>
  200. ${faconer}
  201. <div>${i.fan}</div>
  202. ${facon}
  203. </div>
  204. </div>
  205. `
  206. }
  207. fnaer = i.fan
  208. boeer = i.post
  209. }
  210. // boe = i.post
  211. })
  212. let checkdd=0;
  213. for(let der = 0; der < (data.length/45); der ++){
  214. let dd = new Date(data[der].time)
  215. let times = (dd.getMonth() + 1) + '/' + dd.getDate()
  216. let timeser = dd.getFullYear() + '-' + (dd.getMonth() + 1) + '-' + dd.getDate()
  217. var nowdays = new Date();
  218. var year = nowdays.getFullYear();
  219. var month = nowdays.getMonth();
  220. if(month==0){
  221. month=12;
  222. year=year-1;
  223. }
  224. if (month < 10) {
  225. month = "0" + month;
  226. }
  227. var myDate = new Date(year, month, 0);
  228. var lastDay = year + "-" + month + "-" + myDate.getDate()
  229. //timeser渲染时
  230. //lastDay上个月
  231. if (document.querySelector('#search_begindate').value == dd.getFullYear() + '-' + (dd.getMonth() + 1)) {
  232. if(dd.getDate()!=checkdd+1){
  233. times = (dd.getMonth()+1) + '/' +(dd.getDate()-1)
  234. document.querySelector('.tim').innerHTML += `<div class="tim1">${times}</div>`
  235. times = (dd.getMonth()+1) + '/' +(dd.getDate())
  236. document.querySelector('.tim').innerHTML += `<div class="tim1">${times}</div>`
  237. checkdd=dd.getDate();
  238. }else{
  239. checkdd++;
  240. document.querySelector('.tim').innerHTML += `<div class="tim1">${times}</div>`
  241. }
  242. //document.querySelector('.tim').innerHTML += `<div class="tim1">${times}</div>`
  243. }
  244. }
  245. }
  246. window.onload = async () => {
  247. try {
  248. let {data} = await axios({
  249. method: 'get',
  250. url: '/all',
  251. });
  252. xuanr(data)
  253. } catch (error) {
  254. }
  255. }
  256. const getyue = async () => {
  257. try {
  258. let yue = document.querySelector('#search_begindate').value
  259. let {data} = await axios({
  260. method: 'get',
  261. url: `/getyue?time=${yue}&lasttime=${getlastmonth()}`,
  262. });
  263. document.querySelector('.tim').innerHTML = `<div class="tim1">#</div><div class="tim1">id</div><div class="tim1">日期</div>`
  264. document.querySelector('#der').innerHTML = ''
  265. chaxun(data, '1')
  266. } catch (error) {
  267. }
  268. }
  269. const gettimeer = async () => {
  270. let a = document.querySelector('#datepicker').value
  271. let b = document.querySelector('#datepickerer').value
  272. try {
  273. let url = '/setime?starttime=' + a + '&endtime=' + b
  274. let {data} = await axios({
  275. method: 'get',
  276. url: url,
  277. });
  278. document.querySelector('#der').innerHTML = '数据加载中'
  279. xuanr(data)
  280. } catch (error) {
  281. }
  282. }