detail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item>
  7. <el-button type="text" @click="backToList" icon="el-icon-back" class="back">返回</el-button>
  8. </el-form-item>
  9. <el-form-item class="divLine"></el-form-item>
  10. <el-form-item>
  11. <span class="workName">{{uName}} / {{date}}</span>
  12. </el-form-item>
  13. <el-form-item style="float:right;">
  14. 今日工作时长:
  15. <span class="workHours">{{uHours}}h</span>
  16. </el-form-item>
  17. </el-form>
  18. </el-col>
  19. <!-- 卡片列表 -->
  20. <div>
  21. <el-col :span="24" class="one_div">
  22. <div id="pie_echarts"></div>
  23. </el-col>
  24. <el-col :span="6" v-for="(item, index) in infoList" :key="index" class="one_div">
  25. <el-card :body-style="{ padding: '0px' }" shadow="hover" class="one_card">
  26. <div class="one_card_img">
  27. <el-image
  28. :src="srcList[index]"
  29. :preview-src-list="getSrcList(index)"
  30. class="image"
  31. lazy
  32. >
  33. <div slot="error" class="image-slot">
  34. <el-image :src="require('../../assets/image/noPic.png')" class="image" lazy></el-image>
  35. </div>
  36. </el-image>
  37. </div>
  38. <div class="one_card_txt">
  39. <span>{{converType(item.type+1)}}</span>
  40. <div class="bottom clearfix">
  41. <time class="time">{{item.time}}</time>
  42. </div>
  43. </div>
  44. </el-card>
  45. </el-col>
  46. </div>
  47. </section>
  48. </template>
  49. <script>
  50. import util from "../../common/js/util";
  51. export default {
  52. data() {
  53. return {
  54. detailId: this.$route.params.id,
  55. date: this.$route.params.date,
  56. user: JSON.parse(sessionStorage.getItem("user")),
  57. uName: "",
  58. uTime: "",
  59. uHours: 0,
  60. timeList: [],
  61. srcList: [],
  62. infoList: [],
  63. myChart: null
  64. };
  65. },
  66. methods: {
  67. //获取个人当天的工作时间数据
  68. getInfo() {
  69. this.listLoading = true;
  70. this.http.post(
  71. this.port.time.getToday,
  72. { userId: this.detailId,date: this.date },
  73. res => {
  74. this.listLoading = false;
  75. if (res.code == "ok") {
  76. //设置数据并绘制echarts
  77. this.uName = res.data.username;
  78. this.uTime = res.data.date;
  79. this.timeList = res.data.timeDistribution;
  80. //注意目前仅第0项即行为代码为0被计入正常工作 后续可能需要修改
  81. this.uHours = res.data.total;
  82. this.setEcharts();
  83. //之后顺便再获取一下截图
  84. this.getScreenshot();
  85. } else {
  86. this.$message({
  87. message: res.msg,
  88. type: "error"
  89. });
  90. }
  91. },
  92. error => {
  93. this.listLoading = false;
  94. this.$message({
  95. message: error,
  96. type: "error"
  97. });
  98. }
  99. );
  100. },
  101. //获取个人当天的截图数据
  102. getScreenshot() {
  103. this.listLoading = true;
  104. this.http.post(
  105. this.port.desktop.listToday,
  106. { userId: this.detailId,date: this.date },
  107. res => {
  108. this.listLoading = false;
  109. if (res.code == "ok") {
  110. this.srcList = res.data.srcList;
  111. this.infoList = res.data.data;
  112. } else {
  113. this.$message({
  114. message: res.msg,
  115. type: "error"
  116. });
  117. }
  118. },
  119. error => {
  120. this.listLoading = false;
  121. this.$message({
  122. message: error,
  123. type: "error"
  124. });
  125. }
  126. );
  127. },
  128. //返回
  129. backToList() {
  130. this.$router.go(-1);
  131. },
  132. setEcharts() {
  133. var myChart = this.echarts.init(document.getElementById("pie_echarts"));
  134. this.myChart = myChart;
  135. var option = {
  136. title: {
  137. text: "工作时长分配",
  138. left: "left"
  139. },
  140. tooltip: {
  141. trigger: "item",
  142. formatter: "{a} <br/>{b} : {c} ({d}%)"
  143. },
  144. legend: {
  145. type: "scroll",
  146. orient: "vertical",
  147. right: 0,
  148. top: 30,
  149. bottom: 20,
  150. data: [
  151. "研发",
  152. "上网",
  153. "文档",
  154. "设计",
  155. // "美工",
  156. // "运营",
  157. "看小说",
  158. "影视娱乐",
  159. // "听音乐",
  160. "聊天",
  161. "其他工作"
  162. ]
  163. },
  164. toolbox: {
  165. show: true,
  166. feature: {
  167. mark: { show: true },
  168. dataView: { show: true, readOnly: false },
  169. magicType: {
  170. show: true,
  171. type: ["pie", "funnel"]
  172. },
  173. restore: { show: true },
  174. saveAsImage: { show: true }
  175. }
  176. },
  177. series: [
  178. {
  179. name: "时长(单位:h)",
  180. type: "pie",
  181. radius: [30, 110],
  182. roseType: "area",
  183. data: [
  184. { value: (this.timeList[1] / 3600).toFixed(2), name: "研发" },
  185. { value: (this.timeList[2] / 3600).toFixed(2), name: "上网" },
  186. { value: (this.timeList[3] / 3600).toFixed(2), name: "文档" },
  187. { value: (this.timeList[4] / 3600).toFixed(2), name: "设计" },
  188. { value: (this.timeList[7] / 3600).toFixed(2), name: "看小说" },
  189. { value: (this.timeList[8] / 3600).toFixed(2), name: "影视娱乐" },
  190. { value: (this.timeList[10] / 3600).toFixed(2), name: "聊天" },
  191. { value: (this.timeList[0] / 3600).toFixed(2), name: "其他工作" }
  192. ]
  193. }
  194. ]
  195. };
  196. myChart.setOption(option,{notMerge: true});
  197. },
  198. getSrcList(index) {
  199. return this.srcList.slice(index).concat(this.srcList.slice(0, index));
  200. },
  201. //类型枚举转换
  202. converType(type) {
  203. switch (type) {
  204. case 0:
  205. return "其他工作";
  206. case 1:
  207. return "研发";
  208. case 2:
  209. return "上网";
  210. case 3:
  211. return "文档";
  212. case 4:
  213. return "设计";
  214. case 5:
  215. return "美工";
  216. case 6:
  217. return "运营";
  218. case 7:
  219. return "看小说";
  220. case 8:
  221. return "影视娱乐";
  222. case 9:
  223. return "听音乐";
  224. case 10:
  225. return "聊天";
  226. default:
  227. return "未知";
  228. }
  229. }
  230. },
  231. created() {},
  232. mounted() {
  233. this.getInfo();
  234. var _this = this;
  235. window.addEventListener("resize", function() {
  236. _this.myChart.resize();
  237. });
  238. }
  239. };
  240. </script>
  241. <style lang="scss" scoped>
  242. .toolbar {
  243. .el-form-item {
  244. font-size: 14px;
  245. vertical-align: middle;
  246. }
  247. .back {
  248. font-size: 16px;
  249. cursor: pointer;
  250. }
  251. .divLine {
  252. width: 2px;
  253. background: #c3c3c3;
  254. height: 100%;
  255. }
  256. .workName {
  257. color: #333;
  258. font-size: 18px;
  259. }
  260. .workHours {
  261. color: #20a0ff;
  262. font-size: 18px;
  263. }
  264. }
  265. .one_div {
  266. padding: 15px;
  267. .one_card {
  268. .image {
  269. width: 100%;
  270. }
  271. .one_card_txt {
  272. padding: 13px;
  273. .bottom {
  274. margin-top: 13px;
  275. line-height: 12px;
  276. i {
  277. color: #9ed0ff;
  278. margin-right: 5px;
  279. }
  280. .time {
  281. margin-top: 2px;
  282. color: #999;
  283. }
  284. }
  285. }
  286. }
  287. #pie_echarts {
  288. display: inline-block;
  289. width: 100%;
  290. height: 100%;
  291. min-height: 350px;
  292. }
  293. }
  294. </style>
  295. <style lang="scss">
  296. .image {
  297. .el-image__inner {
  298. height: 11.6vw !important;
  299. }
  300. }
  301. .el-icon-circle-close {
  302. color: white;
  303. }
  304. </style>