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