home.vue 9.4 KB

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