detail.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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}} / {{uTime}}</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. user: JSON.parse(sessionStorage.getItem("user")),
  56. uName: "周瑞霆",
  57. uTime: "2020-01-03",
  58. uHours: 20,
  59. timeList: [],
  60. srcList: [],
  61. infoList: [],
  62. myChart: null
  63. };
  64. },
  65. methods: {
  66. //获取个人当天的工作时间数据
  67. getInfo() {
  68. this.listLoading = true;
  69. this.http.post(
  70. this.port.time.getToday,
  71. { userId: this.detailId },
  72. res => {
  73. this.listLoading = false;
  74. if (res.code == "ok") {
  75. //设置数据并绘制echarts
  76. this.uName = res.data.username;
  77. this.uTime = res.data.date;
  78. this.timeList = res.data.timeDistribution;
  79. //注意目前仅第0项即行为代码为0被计入正常工作 后续可能需要修改
  80. this.uHours = res.data.total;
  81. this.setEcharts();
  82. //之后顺便再获取一下截图
  83. this.getScreenshot();
  84. } else {
  85. this.$message({
  86. message: res.msg,
  87. type: "error"
  88. });
  89. }
  90. },
  91. error => {
  92. this.listLoading = false;
  93. this.$message({
  94. message: error,
  95. type: "error"
  96. });
  97. }
  98. );
  99. },
  100. //获取个人当天的截图数据
  101. getScreenshot() {
  102. this.listLoading = true;
  103. this.http.post(
  104. this.port.desktop.listToday,
  105. { userId: this.detailId },
  106. res => {
  107. this.listLoading = false;
  108. if (res.code == "ok") {
  109. this.srcList = res.data.srcList;
  110. this.infoList = res.data.data;
  111. } else {
  112. this.$message({
  113. message: res.msg,
  114. type: "error"
  115. });
  116. }
  117. },
  118. error => {
  119. this.listLoading = false;
  120. this.$message({
  121. message: error,
  122. type: "error"
  123. });
  124. }
  125. );
  126. },
  127. //返回
  128. backToList() {
  129. this.$router.go(-1);
  130. },
  131. setEcharts() {
  132. var myChart = this.echarts.init(document.getElementById("pie_echarts"));
  133. this.myChart = myChart;
  134. var option = {
  135. title: {
  136. text: "工作时长分配",
  137. left: "left"
  138. },
  139. tooltip: {
  140. trigger: "item",
  141. formatter: "{a} <br/>{b} : {c} ({d}%)"
  142. },
  143. legend: {
  144. type: "scroll",
  145. orient: "vertical",
  146. right: 0,
  147. top: 30,
  148. bottom: 20,
  149. data: [
  150. "编程",
  151. "上网",
  152. "文档",
  153. "设计",
  154. "美工",
  155. // "运营",
  156. "看小说",
  157. "影视娱乐",
  158. "听音乐",
  159. "其他"
  160. ]
  161. },
  162. toolbox: {
  163. show: true,
  164. feature: {
  165. mark: { show: true },
  166. dataView: { show: true, readOnly: false },
  167. magicType: {
  168. show: true,
  169. type: ["pie", "funnel"]
  170. },
  171. restore: { show: true },
  172. saveAsImage: { show: true }
  173. }
  174. },
  175. series: [
  176. {
  177. name: "时长(单位:h)",
  178. type: "pie",
  179. radius: [30, 110],
  180. roseType: "area",
  181. data: [
  182. { value: (this.timeList[1]/3600).toFixed(2), name: "编程" },
  183. { value: (this.timeList[2]/3600).toFixed(2), name: "上网" },
  184. { value: (this.timeList[3]/3600).toFixed(2), name: "文档" },
  185. { value: (this.timeList[4]/3600).toFixed(2), name: "设计" },
  186. { value: (this.timeList[5]/3600).toFixed(2), name: "美工" },
  187. // { value: (this.timeList[6]/3600).toFixed(2), name: "运营" },
  188. { value: (this.timeList[6]/3600).toFixed(2), name: "看小说" },
  189. { value: (this.timeList[7]/3600).toFixed(2), name: "影视娱乐" },
  190. { value: (this.timeList[8]/3600).toFixed(2), name: "听音乐" },
  191. { value: (this.timeList[0]/3600).toFixed(2), name: "其他" }
  192. ]
  193. }
  194. ]
  195. };
  196. myChart.setOption(option);
  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. default:
  225. return "未知";
  226. }
  227. }
  228. },
  229. created() {},
  230. mounted() {
  231. this.getInfo();
  232. var _this = this;
  233. window.addEventListener("resize", function() {
  234. _this.myChart.resize();
  235. });
  236. }
  237. };
  238. </script>
  239. <style lang="scss" scoped>
  240. .toolbar {
  241. .el-form-item {
  242. font-size: 14px;
  243. vertical-align: middle;
  244. }
  245. .back {
  246. font-size: 16px;
  247. cursor: pointer;
  248. }
  249. .divLine {
  250. width: 2px;
  251. background: #c3c3c3;
  252. height: 100%;
  253. }
  254. .workName {
  255. color: #333;
  256. font-size: 18px;
  257. }
  258. .workHours {
  259. color: #20a0ff;
  260. font-size: 18px;
  261. }
  262. }
  263. .one_div {
  264. padding: 15px;
  265. .one_card {
  266. .image {
  267. width: 100%;
  268. }
  269. .one_card_txt {
  270. padding: 13px;
  271. .bottom {
  272. margin-top: 13px;
  273. line-height: 12px;
  274. i {
  275. color: #9ed0ff;
  276. margin-right: 5px;
  277. }
  278. .time {
  279. margin-top: 2px;
  280. color: #999;
  281. }
  282. }
  283. }
  284. }
  285. #pie_echarts {
  286. display: inline-block;
  287. width: 100%;
  288. height: 100%;
  289. min-height: 350px;
  290. }
  291. }
  292. </style>
  293. <style lang="scss">
  294. .image {
  295. .el-image__inner {
  296. height: 11.6vw !important;
  297. }
  298. }
  299. </style>