home.vue 9.3 KB

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