home.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view class="home-container">
  3. <!-- 头部区域 -->
  4. <top-box v-bind:timeStamp="timeStamp"></top-box>
  5. <!-- 滚动条 -->
  6. <view class="notice">
  7. <u-notice-bar :text="noticeMsg" mode="closable" bgColor="#4169e140" color="#FFF"
  8. url="/subpkg/mydata/notificationpage"></u-notice-bar>
  9. </view>
  10. <!-- 卡片区域 -->
  11. <view class="card-box">
  12. <!-- 今日课程 -->
  13. <view class="card-item" style="width: 100%;">
  14. <view class="card-info" style="padding-bottom: 20rpx;">
  15. <view :class="icon.class"></view>
  16. <text class="info-text">今日课程</text>
  17. <view style="display: flex; align-items: center;margin: 0 5rpx 0 auto;" @click="navClass"
  18. v-if="classCurrent != -1">
  19. <view class="t-icon t-icon-fenlei"></view>
  20. <view class="msg" style="font-size: 30rpx; margin-left: 5px;color: #4169E1;">课程列表</view>
  21. </view>
  22. </view>
  23. <todayclass-box :classCurrent="classCurrent"></todayclass-box>
  24. </view>
  25. <!-- 今日打卡 -->
  26. <view class="card-item" style="overflow: hidden;height: 400rpx;" @click="navCalendar">
  27. <view class="card-info">
  28. <view class="t-icon t-icon-daka"></view>
  29. <text class="info-text">今日出勤</text>
  30. </view>
  31. <view class="flex" style="flex-direction: column;">
  32. <!-- 是否打卡 -->
  33. <view class="flex">
  34. <view class="index" :style="{backgroundColor: attendance==='已打卡'?'#4169E1':'#f9c752'}"></view>
  35. <view class="text-content" style="z-index: 2;">打卡记录</view>
  36. </view>
  37. <view class="flex">
  38. <view
  39. :class="attendance==='已打卡'?'t-icon t-icon-weizhidaka-dakachenggong':'t-icon t-icon-weizhidaka-dakacuowu'"
  40. style="width:60rpx;height: 60rpx;margin-left: 20rpx;z-index: 2;"></view>
  41. <view class="text-info" style="margin: 20rpx;">{{attendance}}</view>
  42. </view>
  43. <view class="image"
  44. :style="{backgroundImage: attendance==='已打卡'?`url(${image02})`:`url(${image01})`}"></view>
  45. <!-- 打卡时间 -->
  46. <view class="flex">
  47. <view class="index" :style="{backgroundColor: attendance==='已打卡'?'#4169E1':'#f9c752'}"></view>
  48. <view class="text-content">打卡时间</view>
  49. </view>
  50. <view class="flex">
  51. <view class="flex" v-if="attendance==='未打卡'" style="align-items: baseline;">
  52. <view class="text-info" style="margin-left: 30rpx;font-size: 30rpx;">时间</view>
  53. <view class="text-info">未记录</view>
  54. </view>
  55. <view class="flex" v-else style="align-items: baseline;">
  56. <view class="text-info" style="margin-left: 30rpx;font-size: 30rpx;">上午</view>
  57. <view class="text-info">{{attendanceTime.split(':')[0].replace('0','')}}</view>
  58. <view class="text-info" style="font-size: 30rpx;">点</view>
  59. <view class="text-info">{{attendanceTime.split(':')[1]}}</view>
  60. <view class="text-info" style="font-size: 30rpx;">分</view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <!-- 评测 -->
  66. <view class="card-item" @click="navHomework(0)">
  67. <view class="card-info">
  68. <view :class="icon.evaluation"></view>
  69. <text class="info-text">今日评测</text>
  70. </view>
  71. <view class="charts-box">
  72. <qiun-data-charts type="arcbar" :chartData="homeData.evaluationArcbar" :loadingType="4"
  73. :canvas2d='true' canvasId='canvans9313111' :opts="evaluationOpts" />
  74. </view>
  75. </view>
  76. <!-- 作业 -->
  77. <view class="card-item" @click="navHomework(1)">
  78. <view class="card-info">
  79. <view :class="icon.homework"></view>
  80. <text class="info-text">今日作业</text>
  81. </view>
  82. <view class="charts-box">
  83. <qiun-data-charts type="arcbar" :chartData="homeData.homeworkArcbar" :loadingType="4"
  84. :canvas2d='true' canvasId='canvans9327676' :opts="homeworkOpts" />
  85. </view>
  86. </view>
  87. <!-- 问卷 -->
  88. <view class="card-item" @click="navHomework(2)">
  89. <view class="card-info">
  90. <view :class="icon.activity"></view>
  91. <text class="info-text">今日活动</text>
  92. </view>
  93. <view class="charts-box">
  94. <qiun-data-charts type="arcbar" :chartData="homeData.activityArcbar" :loadingType="4"
  95. :canvas2d='true' canvasId='canvans9313176' :opts="activityOpts" />
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. </template>
  101. <script>
  102. import {
  103. mapState
  104. } from 'vuex'
  105. export default {
  106. computed: {
  107. ...mapState('m_chart', ['homeData']),
  108. ...mapState('m_children', ['classList', 'records']),
  109. ...mapState('m_parent', ['myData'])
  110. },
  111. data() {
  112. return {
  113. //滚动通知
  114. noticeMsg: '',
  115. //当前课程索引
  116. classCurrent: '',
  117. attendance: '',
  118. attendanceTime: '',
  119. //属性(不修改)
  120. //评测进度条属性
  121. evaluationOpts: {},
  122. //作业进度条属性
  123. homeworkOpts: {},
  124. //活动进度条属性
  125. activityOpts: {},
  126. //时间戳
  127. timeStamp: '',
  128. //图标
  129. icon: {
  130. class: 't-icon t-icon-banji',
  131. evaluation: 't-icon t-icon-ceping',
  132. homework: 't-icon t-icon-bianji1',
  133. activity: 't-icon t-icon-huodong'
  134. },
  135. image01: 'https://ouch-cdn2.icons8.com/2farWQUdLe8J4mb4oQoEvJpl5OFXtM5P7AZi8nhuOxk/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvOTYz/L2VkZGEwNzAzLTAw/MWYtNGZiZS1hY2I3/LTVlNjRhZGYzNTAx/Mi5zdmc.png',
  136. image02: 'https://ouch-cdn2.icons8.com/6CkTSZQdyBYaGiqmNJRhbqoYi8QDcLFn-04VEQyQaCo/rs:fit:962:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvNzMz/LzlhYmUzYjIyLTRl/ZGQtNDVkMi1iYWEw/LTVjYjk2NThmNDJi/OC5zdmc.png'
  137. }
  138. },
  139. onLoad() {
  140. this.init()
  141. },
  142. onPullDownRefresh() {
  143. this.init()
  144. setTimeout(function() {
  145. uni.stopPullDownRefresh()
  146. }, 1000);
  147. },
  148. methods: {
  149. //页面方法初始化
  150. init() {
  151. this.timeStamp = (new Date()).format("hh:mm")
  152. this.$initHome()
  153. this.setOpts()
  154. this.getNoticeMsg()
  155. this.getClassCurrent()
  156. this.getAttendance()
  157. },
  158. //获取滚动通知
  159. getNoticeMsg() {
  160. this.noticeMsg = `您有 ${this.myData.msgList.length} 个通知,请点击查看`
  161. },
  162. //计算出当前课程
  163. getClassCurrent() {
  164. //当前时间戳是否在课程时间段内
  165. function CompareDate(start, finish) {
  166. //获得当前时间时间戳
  167. let timeNow = (new Date()).format("yyyy-MM-dd hh:mm").replace(new RegExp("-", "gm"), "/")
  168. let timeHaoMiao = (new Date(timeNow)).getTime()
  169. //获得课程开始结束时间戳
  170. let today = (new Date()).format("yyyy-MM-dd ")
  171. let classStart = (today + start).replace(new RegExp("-", "gm"), "/")
  172. let classFinish = (today + finish).replace(new RegExp("-", "gm"), "/")
  173. let classStartHaoMiao = (new Date(classStart)).getTime()
  174. let classFinishHaoMiao = (new Date(classFinish)).getTime()
  175. //比较
  176. if (timeHaoMiao < classFinishHaoMiao) {
  177. if (classStartHaoMiao < timeHaoMiao)
  178. return true
  179. }
  180. return false
  181. }
  182. //获取当前课程索引值
  183. let i = 1
  184. for (let item of this.classList) {
  185. let timeArr = item.time.split("-")
  186. let res = CompareDate(timeArr[0], timeArr[1])
  187. if (res) {
  188. break
  189. }
  190. i++
  191. }
  192. //判断是否不在任意一个时间段内
  193. if (i > this.classList.length) {
  194. i = -1
  195. }
  196. this.classCurrent = i
  197. i = 0
  198. },
  199. //获得今日是否打卡
  200. getAttendance() {
  201. //获得当前时间时间戳
  202. let timeNow = (new Date()).format("yyyy-M-dd")
  203. let timeArr = timeNow.split("-")
  204. let info = this.records.filter(x => x.year == timeArr[0] && x.month == timeArr[1] && x.date == timeArr[2])
  205. if (info.length != 0) {
  206. this.attendance = '已打卡'
  207. this.attendanceTime = info[0].time
  208. } else {
  209. this.attendance = '未打卡'
  210. this.attendanceTime = '未记录'
  211. }
  212. },
  213. //设置圆环图描述更新
  214. setOpts() {
  215. //圆环图标题和副标题动态变化
  216. let evaluation = {
  217. title: {
  218. name: this.homeData.evaluationArcbar.series[0].data * 100 + "%",
  219. color: this.homeData.evaluationArcbar.series[0].color
  220. },
  221. subtitle: {
  222. name: this.homeData.evaluationArcbar.series[0].name
  223. },
  224. }
  225. let homework = {
  226. title: {
  227. name: this.homeData.homeworkArcbar.series[0].data * 100 + "%",
  228. color: this.homeData.homeworkArcbar.series[0].color
  229. },
  230. subtitle: {
  231. name: this.homeData.homeworkArcbar.series[0].name
  232. },
  233. }
  234. let activity = {
  235. title: {
  236. name: this.homeData.activityArcbar.series[0].data * 100 + "%",
  237. color: this.homeData.activityArcbar.series[0].color
  238. },
  239. subtitle: {
  240. name: this.homeData.activityArcbar.series[0].name
  241. },
  242. }
  243. this.evaluationOpts = evaluation;
  244. this.homeworkOpts = homework;
  245. this.activityOpts = activity;
  246. },
  247. //导航
  248. navHomework(index) {
  249. uni.reLaunch({
  250. url: `/pages/homework/homework?index=${index}`
  251. })
  252. },
  253. navCalendar() {
  254. uni.navigateTo({
  255. url: '/subpkg/calendar/calendar'
  256. })
  257. },
  258. navClass() {
  259. uni.navigateTo({
  260. url: '/subpkg/classlist/classlist'
  261. })
  262. },
  263. },
  264. }
  265. </script>
  266. <style lang="scss">
  267. @import '@/pages/common/mainpage.scss';
  268. .flex {
  269. display: flex;
  270. align-items: center;
  271. width: 100%;
  272. }
  273. .text-content {
  274. font-size: 30rpx;
  275. font-weight: bold;
  276. color: $color-title;
  277. margin: 10rpx 0 10rpx 15rpx;
  278. z-index: 2;
  279. }
  280. .text-info {
  281. margin: 10rpx 0 0 10rpx;
  282. font-size: 45rpx;
  283. font-weight: bold;
  284. color: $color-title;
  285. z-index: 2;
  286. }
  287. .t-icon {
  288. background-repeat: no-repeat;
  289. }
  290. .index {
  291. height: 30rpx;
  292. width: 10rpx;
  293. border-radius: 100rpx;
  294. margin-left: 30rpx;
  295. }
  296. .image {
  297. position: absolute;
  298. margin: 20rpx 0 0 50rpx;
  299. height: 300rpx;
  300. width: 300rpx;
  301. background-size: 100%;
  302. background-repeat: no-repeat;
  303. opacity: 0.25;
  304. z-index: 1;
  305. }
  306. </style>