You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserAnalysis.vue 19 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <div>
  3. <div style="margin-top: 10px;">
  4. <b class="pro_item">用户分析</b> <span class="update_time">数据更新时间:</span><span style="font-size: 12px;">{{lastUpdatedTime}} &nbsp/&nbsp从{{recordBeginTime}}开始统计</span>
  5. </div>
  6. <div style="margin-top: 20px;">
  7. <span class="sta_iterm">统计周期:</span>
  8. <button type="button" class='btn' id ="yesterday_usr" v-bind:class="{colorChange:1==dynamic}" @click="getUserList('yesterday_usr',1)">昨天</button>
  9. <button type="button" class='btn' id = "current_week_usr" v-bind:class="{colorChange:2==dynamic}" @click="getUserList('current_week_usr',2)">本周</button>
  10. <button type="button" class='btn' id = "current_month_usr" v-bind:class="{colorChange:3==dynamic}" @click="getUserList('current_month_usr',3)">本月</button>
  11. <button type="button" class='btn' id = "last_month_usr" v-bind:class="{colorChange:4==dynamic}" @click="getUserList('last_month_usr',4)">上月</button>
  12. <button type="button" class='btn' id = "monthly_usr" v-bind:class="{colorChange:5==dynamic}" @click="getUserList('monthly_usr',5)">近30天</button>
  13. <button type="button" class='btn' id = "current_year_usr" v-bind:class="{colorChange:6==dynamic}" @click="getUserList('current_year_usr',6)">今年</button>
  14. <button type="button" class='btn' id = "all_usr" v-bind:class="{colorChange:7==dynamic}" @click="getUserList('all_usr',7)">所有</button>
  15. <span style="margin-left: 20px;">
  16. <el-date-picker
  17. v-model="value_time"
  18. prefix-icon="el-icon-time"
  19. @change="getUserList('',0)"
  20. type="daterange"
  21. size='small'
  22. unlink-panels
  23. range-separator="至"
  24. start-placeholder="开始日期"
  25. end-placeholder="结束日期">
  26. </el-date-picker>
  27. </span>
  28. <span style="float:right; margin-right: 20px;" >
  29. <a style="display:inline-block;margin-left: 20px; " id = 'download'>
  30. <i class="el-icon-download"></i>
  31. <span ><a @click="exportData()">下载报告</a> </span>
  32. </a>
  33. <span style="display:inline-block;margin-left: 20px; ">
  34. <el-input size="small" placeholder="输入用户名搜索" v-model="search" class="input-with-select" @keyup.enter.native="searchName() "><i slot="suffix" class="el-input__icon el-icon-search"></i>
  35. </el-input>
  36. </span>
  37. </span>
  38. </div>
  39. <div style="margin-top: 30px;">
  40. <el-table
  41. :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
  42. style="width: 100%"
  43. :header-cell-style="tableHeaderStyle"
  44. :cell-style='cellStyle'>
  45. <el-table-column
  46. label="ID"
  47. prop="ID"
  48. align="center"
  49. stripe
  50. >
  51. </el-table-column>
  52. <el-table-column
  53. label="用户名"
  54. align="center"
  55. prop="Name"
  56. width="100px">
  57. </el-table-column>
  58. <el-table-column
  59. prop="CodeMergeCount"
  60. label="PR数"
  61. align="center">
  62. </el-table-column>
  63. <el-table-column
  64. prop="CommitCount"
  65. label="commit数"
  66. align="center">
  67. </el-table-column>
  68. <el-table-column
  69. prop="IssueCount"
  70. label="提出任务数"
  71. align="center">
  72. </el-table-column>
  73. <el-table-column
  74. prop="CommentCount"
  75. label="评论数"
  76. align="center">
  77. </el-table-column>
  78. <el-table-column
  79. prop="FocusRepoCount"
  80. label="关注项目数"
  81. align="center">
  82. </el-table-column>
  83. <el-table-column
  84. prop="StarRepoCount"
  85. label="点赞项目数"
  86. align="center">
  87. </el-table-column>
  88. <el-table-column
  89. prop="LoginCount"
  90. label="登录次数"
  91. align="center">
  92. </el-table-column>
  93. <el-table-column
  94. prop="WatchedCount"
  95. label="关注者数"
  96. align="center">
  97. </el-table-column>
  98. <el-table-column
  99. prop="CommitCodeSize"
  100. label="commit代码行数"
  101. width="115px"
  102. align="center">
  103. </el-table-column>
  104. <el-table-column
  105. prop="SolveIssueCount"
  106. label="已解决任务数"
  107. align="center">
  108. </el-table-column>
  109. <el-table-column
  110. prop="EncyclopediasCount"
  111. label="百科页面贡献次数"
  112. width="130px"
  113. align="center">
  114. </el-table-column>
  115. <el-table-column
  116. prop="CreateRepoCount"
  117. label="创建项目"
  118. align="center">
  119. </el-table-column>
  120. <el-table-column
  121. prop="RegistDate"
  122. label="用户注册时间"
  123. width="120px"
  124. align="center">
  125. <!-- <template slot-scope="scope">
  126. {{scope.row.RegistDate | transformTimestamp}}
  127. </template> -->
  128. </el-table-column>
  129. <el-table-column
  130. prop="CountDate"
  131. label="系统统计时间"
  132. width="120px"
  133. align="center">
  134. <!-- <template slot-scope="scope">
  135. {{scope.row.CountDate | transformTimestamp}}
  136. </template> -->
  137. </el-table-column>
  138. </el-table>
  139. </div>
  140. <div style="margin-top:50px;text-align:center">
  141. <el-pagination
  142. background
  143. @current-change="handleCurrentChange"
  144. :current-page="currentPage"
  145. :page-size="pageSize"
  146. layout="prev, pager, next"
  147. :total="tableData.length">
  148. </el-pagination>
  149. </div>
  150. </div>
  151. </template>
  152. <script>
  153. import { export2Excel } from '../excel/util.js'
  154. export default{
  155. name:'UserAnalysis',
  156. data() {
  157. return {
  158. type_val:'',
  159. recordBeginTime:'',
  160. lastUpdatedTime:'',
  161. currentPage:1,
  162. pageSize:10,
  163. params:{startDate:'',endDate:''},
  164. tableData: [],
  165. pickerOptions: {
  166. },
  167. value_time: '',
  168. search:'',
  169. data:'',
  170. columns: [{title: 'ID',key: 'ID'},{title: '用户名',key: 'Name'},{title: 'PR数',key: 'CodeMergeCount'},{title: 'cimmit数',key:'CommitCount'},{title: '提出任务数',key: 'IssueCount'},{title: '评论数',key: 'CommentCount'},{title: '关注项目数',key: 'FocusRepoCount'},{title: '点赞项目数',key: 'StarRepoCount'},{title: '登录次数',key: 'LoginCount'},{title:'关注者数',key:'WatchedCount'},{title:'commit代码行数',key:'CommitCodeSize'},{title:'已解决任务数',key:'SolveIssueCount'},{title:'百科页面贡献次数',key:'EncyclopediasCount'},{title:'创建项目',key:'CreateRepoCount'},{title:'用户注册时间',key:'RegistDate'},{title:'系统统计时间',key:'CountDate'}],
  171. blob:'',
  172. fileName:'',
  173. dynamic:7,
  174. params_pro:{type:'all',page:1,pagesize:10,beginTime:'',endTime:'',q:'',sort:'openi'},
  175. };
  176. },
  177. methods: {
  178. exportData(){
  179. // this.getUserList('all_usr',7)
  180. var saveFileName = this.getFileName()
  181. export2Excel(this.columns,this.tableData,saveFileName)
  182. },
  183. getFileName(){
  184. var saveFileName=''
  185. var Date=(this.params.startDate).split('-')
  186. var startDate=Date[0]+''+Date[1]+''+Date[2]
  187. console.log(startDate)
  188. Date=(this.params.endDate).split('-')
  189. var endDate=Date[0]+Date[1]+Date[2]
  190. saveFileName = '用户分析_'+this.search+''+startDate+'_'+endDate
  191. if (this.type_val=='all_usr'){
  192. saveFileName = '用户分析_'+this.search+'_all'
  193. }
  194. return saveFileName
  195. },
  196. handleCurrentChange(currentPage){
  197. this.currentPage = currentPage;
  198. },
  199. formatDate(myyear,mymonth,myweekday) {
  200. // var myyear = this.date.getFullYear();
  201. // var mymonth = this.date.getMonth() + 1;
  202. // var myweekday = this.date.getDate();
  203. if (mymonth < 10) {
  204. mymonth = "0" + mymonth;
  205. }
  206. if (myweekday < 10) {
  207. myweekday = "0" + myweekday;
  208. }
  209. return (myyear + "-" + mymonth + "-" + myweekday);
  210. },
  211. // 获得某月的天数
  212. getMonthDays(nowYear,month){
  213. let monthStartDate = new Date(nowYear, month, 1);
  214. let monthEndDate = new Date(nowYear, month + 1, 1);
  215. let days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
  216. return days;
  217. },
  218. getUserList(type_val,index){
  219. this.type_val = type_val
  220. this.dynamic = index;
  221. console.log("dj:"+type_val)
  222. var now = new Date(); // 当前日期
  223. var nowDayOfWeek = now.getDay(); // 今天本周的第几天
  224. var nowDay = now.getDate(); // 当前日
  225. var nowMonth = now.getMonth(); // 当前月
  226. var nowYear = now.getFullYear(); // 当前年
  227. var today = this.formatDate(nowYear,nowMonth+1,nowDay);
  228. let lastMonthDate = new Date(); // 上月日期
  229. lastMonthDate.setDate(1);
  230. lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
  231. let lastYear = lastMonthDate.getYear();
  232. let lastMonth = lastMonthDate.getMonth();
  233. if (typeof type_val=="undefined" || type_val=="null" || type_val==""){
  234. this.params.startDate= this.formatDate(this.value_time[0].getFullYear(),this.value_time[0].getMonth() + 1,this.value_time[0].getDate());
  235. this.params.endDate = this.formatDate(this.value_time[1].getFullYear(),this.value_time[1].getMonth() + 1,this.value_time[1].getDate());
  236. }else{
  237. switch(type_val){
  238. case "yesterday_usr":{
  239. var now = new Date();
  240. var tmp = new Date(now.setTime(now.getTime()-24*60*60*1000));
  241. var yesterday = this.formatDate(tmp.getFullYear(),tmp.getMonth()+1,tmp.getDate());
  242. this.params.startDate = yesterday
  243. this.params.endDate = yesterday
  244. this.value_time=[]
  245. // document.getElementById("yesterday_usr").style.backgroundColor="409effd6"
  246. // document.getElementById("current_week_usr")
  247. break
  248. }
  249. case "current_week_usr":{
  250. var now = new Date(); // 当前日期
  251. var nowDayOfWeek = now.getDay(); // 今天本周的第几天
  252. var day = nowDayOfWeek || 7;
  253. this.params.startDate = this.formatDate(now.getFullYear(), nowMonth+1, nowDay + 1 - day);
  254. this.params.endDate = today
  255. this.value_time=[]
  256. break
  257. }
  258. case "current_month_usr":{
  259. this.params.startDate = this.formatDate(nowYear,nowMonth+1,1);
  260. this.params.endDate = today
  261. this.value_time=[]
  262. break
  263. }
  264. case "last_month_usr":{
  265. this.params.startDate=this.formatDate(nowYear, lastMonth+1, 1);
  266. this.params.endDate=this.formatDate(nowYear, lastMonth+1, this.getMonthDays(nowYear,lastMonth));
  267. this.value_time=[]
  268. break
  269. }
  270. case "monthly_usr":{
  271. var temp=new Date(now - 1000 * 60 * 60 * 24 * 30)
  272. this.params.startDate = this.formatDate(temp.getFullYear(),temp.getMonth()+1,temp.getDate());
  273. this.params.endDate = today
  274. this.value_time=[]
  275. break
  276. }
  277. case "current_year_usr":{
  278. this.params.startDate = this.formatDate(now.getFullYear(), 1, 1);
  279. this.params.endDate = today
  280. this.value_time=[]
  281. break
  282. }
  283. case "all_usr":{
  284. console.log("e:"+today)
  285. this.params.startDate = this.recordBeginTime//this.formatDate(2000, 1, 1); //
  286. this.params.endDate = today
  287. this.value_time=[]
  288. break
  289. }
  290. }
  291. };
  292. this.$axios.get('../tool/query_user_static',{
  293. params:this.params
  294. }).then((res)=>{
  295. this.currentPage = 1
  296. this.tableData = res.data
  297. console.log(" this.tableData:", this.tableData.length)
  298. for(var i=0;i<this.tableData.length;i++){
  299. this.tableData[i].RegistDate = this.transformTimestamp(this.tableData[i].RegistDate)
  300. this.tableData[i].CountDate = this.transformTimestamp(this.tableData[i].CountDate)
  301. console.log(" this.tableData:", this.tableData[i].RegistDate)
  302. }
  303. })
  304. this.$axios.get('../api/v1/projectboard/project',{
  305. params:this.params_pro
  306. }).then((res)=>{
  307. this.recordBeginTime=res.data.recordBeginTime
  308. this.lastUpdatedTime=res.data.lastUpdatedTime
  309. })
  310. },
  311. searchName(){
  312. // this.params.q = this.search
  313. // this.params.page = 1
  314. // this.getUserList("all_usr")
  315. var search = this.search;
  316. this.getUserList("all_usr",7)
  317. this.tableData = this.tableData.filter(data => !search || data.Name.toLowerCase().includes(search.toLowerCase()))
  318. },
  319. goToDetailPage(pro_id,pro_name){
  320. sessionStorage.setItem("pro_id",pro_id);
  321. sessionStorage.setItem("pro_name",pro_name);
  322. document.getElementById("pro_main").style.display="none";
  323. document.getElementById("pro_detail").style.display="block";
  324. },
  325. tableHeaderStyle({row,column,rowIndex,columnIndex}){
  326. if(rowIndex===0){
  327. return 'background:#f5f5f6;color:#606266'
  328. }
  329. },
  330. cellStyle({row,column,rowIndex,columnIndex}){
  331. if(rowIndex%2 === 1){
  332. return 'background:#f5f5f6;color:#606266'
  333. }
  334. },
  335. transformTimestamp(timestamp){
  336. console.log("timestamp",timestamp)
  337. let a = new Date(timestamp*1000);
  338. const date = new Date(a);
  339. const Y = date.getFullYear() + '/';
  340. const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
  341. const D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
  342. const h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
  343. const m = (date.getMinutes() <10 ? '0'+date.getMinutes() : date.getMinutes());// + ':' ;
  344. // const s = (date.getSeconds() <10 ? '0'+date.getSeconds() : date.getSeconds()) ; // 秒
  345. const dateString = Y + M + D + h + m ;//+ s;
  346. console.log('dateString', dateString); // > dateString 2021-07-06 14:23
  347. return dateString;
  348. },
  349. },
  350. filters:{
  351. // transformTimestamp(timestamp){
  352. // var dateString= new Date(timestamp);
  353. // return dateString.toLocaleDateString().replace(/\//g, "-") + " " + dateString.toTimeString().substr(0, 8);
  354. // },
  355. },
  356. mounted() {
  357. document.getElementById("all_usr").style.outline="none"
  358. document.getElementById("all_usr").focus()
  359. this.getUserList("all_usr",7)
  360. },
  361. created() {
  362. },
  363. watch:{
  364. search(val){
  365. if(!val){
  366. this.getUserList("all_usr",7)
  367. }
  368. }
  369. },
  370. }
  371. </script>
  372. <style scoped>
  373. .pro_item{
  374. font-size: 16px;
  375. color: rgba(16, 16, 16, 100);
  376. font-family: SourceHanSansSC-bold;
  377. }
  378. .sta_item{
  379. font-size: 14px;
  380. color: rgb(0 0 0);
  381. font-family: SourceHanSansSC-bold;
  382. }
  383. .update_time{
  384. line-height: 17px;
  385. font-size: 12px;
  386. color:rgba(187, 187, 187, 100);
  387. margin-left: 10px;
  388. }
  389. .btn{
  390. line-height: 1.5;
  391. margin: -3px;
  392. border: 1px solid #409effd6;
  393. background: #FFFF;
  394. color: #409eff;
  395. width: 60px;
  396. height: 30px;
  397. border-radius:4px ;
  398. }
  399. /* .btn:focus,
  400. .btn:active{
  401. background-color:#409effd6 ;
  402. } */
  403. /deep/ .el-date-picker {
  404. width: 200px;
  405. }
  406. /deep/ .el-table {
  407. font-size: 12px;
  408. }
  409. .colorChange {
  410. background-color: #409effd6;
  411. color: #FFFF;
  412. }
  413. </style>