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 18 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div>
  3. <div style="margin-top: 10px;">
  4. <b class="pro_item">用户分析</b> <span class="update_time">数据更新时间:{{lastUpdatedTime}}/{{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: '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'}],
  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. export2Excel(this.columns,this.tableData,"测试下载excel")
  180. },
  181. handleCurrentChange(currentPage){
  182. this.currentPage = currentPage;
  183. },
  184. formatDate(myyear,mymonth,myweekday) {
  185. // var myyear = this.date.getFullYear();
  186. // var mymonth = this.date.getMonth() + 1;
  187. // var myweekday = this.date.getDate();
  188. if (mymonth < 10) {
  189. mymonth = "0" + mymonth;
  190. }
  191. if (myweekday < 10) {
  192. myweekday = "0" + myweekday;
  193. }
  194. return (myyear + "-" + mymonth + "-" + myweekday);
  195. },
  196. // 获得某月的天数
  197. getMonthDays(nowYear,month){
  198. let monthStartDate = new Date(nowYear, month, 1);
  199. let monthEndDate = new Date(nowYear, month + 1, 1);
  200. let days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
  201. return days;
  202. },
  203. getUserList(type_val,index){
  204. this.dynamic = index;
  205. console.log("dj:"+type_val)
  206. var now = new Date(); // 当前日期
  207. var nowDayOfWeek = now.getDay(); // 今天本周的第几天
  208. var nowDay = now.getDate(); // 当前日
  209. var nowMonth = now.getMonth(); // 当前月
  210. var nowYear = now.getFullYear(); // 当前年
  211. var today = this.formatDate(nowYear,nowMonth+1,nowDay);
  212. let lastMonthDate = new Date(); // 上月日期
  213. lastMonthDate.setDate(1);
  214. lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
  215. let lastYear = lastMonthDate.getYear();
  216. let lastMonth = lastMonthDate.getMonth();
  217. if (typeof type_val=="undefined" || type_val=="null" || type_val==""){
  218. this.params.startDate= this.formatDate(this.value_time[0].getFullYear(),this.value_time[0].getMonth() + 1,this.value_time[0].getDate());
  219. this.params.endDate = this.formatDate(this.value_time[1].getFullYear(),this.value_time[1].getMonth() + 1,this.value_time[1].getDate());
  220. }else{
  221. switch(type_val){
  222. case "yesterday_usr":{
  223. var now = new Date();
  224. var tmp = new Date(now.setTime(now.getTime()-24*60*60*1000));
  225. var yesterday = this.formatDate(tmp.getFullYear(),tmp.getMonth()+1,tmp.getDate());
  226. this.params.startDate = yesterday
  227. this.params.endDate = yesterday
  228. this.value_time=[]
  229. document.getElementById("yesterday_usr").style.backgroundColor="409effd6"
  230. document.getElementById("current_week_usr")
  231. break
  232. }
  233. case "current_week_usr":{
  234. var now = new Date(); // 当前日期
  235. var nowDayOfWeek = now.getDay(); // 今天本周的第几天
  236. var day = nowDayOfWeek || 7;
  237. this.params.startDate = this.formatDate(now.getFullYear(), nowMonth+1, nowDay + 1 - day);
  238. this.params.endDate = today
  239. this.value_time=[]
  240. break
  241. }
  242. case "current_month_usr":{
  243. this.params.startDate = this.formatDate(nowYear,nowMonth+1,1);
  244. this.params.endDate = today
  245. this.value_time=[]
  246. break
  247. }
  248. case "last_month_usr":{
  249. this.params.startDate=this.formatDate(nowYear, lastMonth+1, 1);
  250. this.params.endDate=this.formatDate(nowYear, lastMonth+1, this.getMonthDays(nowYear,lastMonth));
  251. this.value_time=[]
  252. break
  253. }
  254. case "monthly_usr":{
  255. var temp=new Date(now - 1000 * 60 * 60 * 24 * 30)
  256. this.params.startDate = this.formatDate(temp.getFullYear(),temp.getMonth()+1,temp.getDate());
  257. this.params.endDate = today
  258. this.value_time=[]
  259. break
  260. }
  261. case "current_year_usr":{
  262. this.params.startDate = this.formatDate(now.getFullYear(), 1, 1);
  263. this.params.endDate = today
  264. this.value_time=[]
  265. break
  266. }
  267. case "all_usr":{
  268. console.log("e:"+today)
  269. this.params.startDate = this.formatDate(2000, 1, 1); //this.recordBeginTime//
  270. this.params.endDate = today
  271. this.value_time=[]
  272. break
  273. }
  274. }
  275. };
  276. this.$axios.get('../tool/query_user_static',{
  277. params:this.params
  278. }).then((res)=>{
  279. this.currentPage = 1
  280. this.tableData = res.data
  281. })
  282. this.$axios.get('../api/v1/projectboard/project',{
  283. params:this.params_pro
  284. }).then((res)=>{
  285. this.recordBeginTime=res.data.recordBeginTime
  286. this.lastUpdatedTime=res.data.lastUpdatedTime
  287. })
  288. },
  289. searchName(){
  290. // this.params.q = this.search
  291. // this.params.page = 1
  292. // this.getUserList("all_usr")
  293. var search = this.search;
  294. this.getUserList("all_usr",7)
  295. this.tableData = this.tableData.filter(data => !search || data.Name.toLowerCase().includes(search.toLowerCase()))
  296. },
  297. goToDetailPage(pro_id,pro_name){
  298. sessionStorage.setItem("pro_id",pro_id);
  299. sessionStorage.setItem("pro_name",pro_name);
  300. document.getElementById("pro_main").style.display="none";
  301. document.getElementById("pro_detail").style.display="block";
  302. },
  303. tableHeaderStyle({row,column,rowIndex,columnIndex}){
  304. if(rowIndex===0){
  305. return 'background:#f5f5f6;color:#606266'
  306. }
  307. },
  308. cellStyle({row,column,rowIndex,columnIndex}){
  309. if(rowIndex%2 === 1){
  310. return 'background:#f5f5f6;color:#606266'
  311. }
  312. },
  313. },
  314. filters:{
  315. transformTimestamp(timestamp){
  316. console.log("timestamp",timestamp)
  317. let a = new Date(timestamp*1000);
  318. const date = new Date(a);
  319. const Y = date.getFullYear() + '/';
  320. const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
  321. const D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
  322. const h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
  323. const m = (date.getMinutes() <10 ? '0'+date.getMinutes() : date.getMinutes());// + ':' ;
  324. // const s = (date.getSeconds() <10 ? '0'+date.getSeconds() : date.getSeconds()) ; // 秒
  325. const dateString = Y + M + D + h + m ;//+ s;
  326. console.log('dateString', dateString); // > dateString 2021-07-06 14:23
  327. return dateString;
  328. },
  329. // transformTimestamp(timestamp){
  330. // var dateString= new Date(timestamp);
  331. // return dateString.toLocaleDateString().replace(/\//g, "-") + " " + dateString.toTimeString().substr(0, 8);
  332. // },
  333. },
  334. mounted() {
  335. document.getElementById("all_usr").style.outline="none"
  336. document.getElementById("all_usr").focus()
  337. this.getUserList("all_usr",7)
  338. },
  339. created() {
  340. },
  341. watch:{
  342. search(val){
  343. if(!val){
  344. this.getUserList("all_usr",7)
  345. }
  346. }
  347. },
  348. }
  349. </script>
  350. <style scoped>
  351. .pro_item{
  352. font-size: 16px;
  353. color: rgba(16, 16, 16, 100);
  354. font-family: SourceHanSansSC-bold;
  355. }
  356. .sta_item{
  357. font-size: 14px;
  358. color: rgb(0 0 0);
  359. font-family: SourceHanSansSC-bold;
  360. }
  361. .update_time{
  362. line-height: 17px;
  363. font-size: 12px;
  364. color:rgba(187, 187, 187, 100);
  365. margin-left: 10px;
  366. }
  367. .btn{
  368. line-height: 1.5;
  369. margin: -3px;
  370. border: 1px solid #409effd6;
  371. background: #FFFF;
  372. color: #409eff;
  373. width: 60px;
  374. height: 30px;
  375. border-radius:4px ;
  376. }
  377. .btn:focus,
  378. .btn:active{
  379. background-color:#409effd6 ;
  380. }
  381. /deep/ .el-date-picker {
  382. width: 200px;
  383. }
  384. /deep/ .el-table {
  385. font-size: 12px;
  386. }
  387. .colorChange {
  388. background-color: #409effd6;
  389. }
  390. </style>