瀏覽代碼

获取记录时长和我的乐团

skyblued 2 年之前
父節點
當前提交
8570e6908a
共有 3 個文件被更改,包括 107 次插入125 次删除
  1. 19 5
      src/views/coursewarePlay/playRecordTime.tsx
  2. 82 71
      src/views/mine-orchestra/index.tsx
  3. 6 49
      src/views/mine-orchestra/my-class/index.tsx

+ 19 - 5
src/views/coursewarePlay/playRecordTime.tsx

@@ -18,7 +18,6 @@ export default defineComponent({
     const pageVisibility = usePageVisibility()
 
     watch(pageVisibility, (value) => {
-      console.log("🚀 ~ value", value)
       if (value == 'hidden') {
         clearInterval(timerRecord.value)
         handleRecord()
@@ -33,7 +32,9 @@ export default defineComponent({
       currentTime: 0,
       /**记录的开始时间 */
       startTime: 0,
-      timer: null as any
+      timer: null as any,
+      /** 已经播放的时间 */
+      playTime: 0
     })
     /** 建议学习总时长 */
     const total = computed(() => {
@@ -44,6 +45,19 @@ export default defineComponent({
       return _total
     })
 
+    const getPlayTime = async () => {
+      try {
+        const res: any = await request.post(
+          `${state.platformApi}/courseSchedule/getCoursewarePlayTime?courseScheduleId=${route.query.courseId}`
+        )
+        if (res.data){
+          saveModel.playTime = res.data
+        }
+      } catch (error) {}
+      handleStartInterval()
+    }
+
+    /** 记录时长 */
     const handleRecord = () => {
       saveModel.currentTime++
       const playTime = saveModel.currentTime - saveModel.startTime
@@ -65,7 +79,7 @@ export default defineComponent({
       timerRecord.value = setInterval(handleRecord, 1000)
     }
     onMounted(() => {
-      handleStartInterval()
+      getPlayTime()
     })
     onUnmounted(() => {
       clearInterval(timerRecord.value)
@@ -73,12 +87,12 @@ export default defineComponent({
     return () => (
       <div
         class={styles.playRecordTimeWrap}
-        style={{ display: saveModel.currentTime > total.value ? 'none' : '' }}
+        style={{ display: (saveModel.currentTime + saveModel.playTime) > total.value ? 'none' : '' }}
       >
         <div class={styles.playRecordTime}>
           <div class={styles.timeLoad}></div>
           <div>
-            {getSecondRPM(saveModel.currentTime)} / {getSecondRPM(total.value)}
+            {getSecondRPM(saveModel.currentTime + saveModel.playTime)} / {getSecondRPM(total.value)}
           </div>
         </div>
       </div>

+ 82 - 71
src/views/mine-orchestra/index.tsx

@@ -30,41 +30,54 @@ export default defineComponent({
     /** 学生获取我的乐团 */
     const getStudentOrchestras = () => {
       data.loading = true
-      request.post(`${state.platformApi}/orchestra/studentOrchestra`).then((res: any) => {
-        if (Array.isArray(res?.data)) {
-          data.orchestraList = res.data.map((n: any) => {
-            return {
-              ...n,
-              name: n.name || n.orchestraName || '',
-              id: n.id || n.orchestraId || ''
-            }
-          })
-          modelData.orchestra = data.orchestraList[0] || {}
-        }
-      })
-      setTimeout(() => {
-        data.loading = false
-      }, 300)
+      request
+        .post(`${state.platformApi}/orchestra/studentOrchestra`)
+        .then((res: any) => {
+          if (Array.isArray(res?.data)) {
+            data.orchestraList = res.data.map((n: any) => {
+              return {
+                ...n,
+                name: n.name || n.orchestraName || '',
+                id: n.id || n.orchestraId || ''
+              }
+            })
+            modelData.orchestra = data.orchestraList[0] || {}
+          }
+        })
+        .finally(() => {
+          setTimeout(() => {
+            data.loading = false
+          }, 300)
+        })
     }
-    const getOrchestras = async () => {
+    const getTeacherOrchestras = async () => {
       data.loading = true
-      try {
-        const res: any = await request.post(`${state.platformApi}/orchestra/page`, {
-          data: { page: 1, rows: 1000 }
+      request
+        .post(`${state.platformApi}/orchestra/teacherOrchestra`)
+        .then((res: any) => {
+          if (Array.isArray(res?.data)) {
+            data.orchestraList = res.data.map((n: any) => {
+              return {
+                ...n,
+                name: n.name || n.orchestraName || '',
+                id: n.id || n.orchestraId || ''
+              }
+            })
+            modelData.orchestra = data.orchestraList[0] || {}
+          }
+        })
+        .finally(() => {
+          setTimeout(() => {
+            data.loading = false
+          }, 300)
         })
-        if (Array.isArray(res?.data?.rows)) {
-          data.orchestraList = res.data.rows
-          modelData.orchestra = res.data.rows[0] || {}
-        }
-      } catch {}
-      data.loading = false
     }
     const getData = () => {
-      getStudentOrchestras()
-      // if (state.platformType === 'STUDENT') {
-      // } else {
-      //   getOrchestras()
-      // }
+      if (state.platformType === 'STUDENT') {
+        getStudentOrchestras()
+      } else if (state.platformType === 'TEACHER') {
+        getTeacherOrchestras()
+      }
     }
     onMounted(() => {
       getData()
@@ -119,47 +132,46 @@ export default defineComponent({
           }}
           style="min-height: calc(100vh - var(--van-nav-bar-height) - var(--header-height))"
         >
-          <CellGroup inset>
-            <Cell
-              class={styles.select}
-              center
-              isLink
-              onClick={() => (modelData.orchestraStatus = true)}
-            >
-              {{
-                icon: () => <img class={styles.icon} src={iconOrchestra} />,
-                title: () => <div class="van-ellipsis">{modelData.orchestra.name}</div>
-              }}
-            </Cell>
-          </CellGroup>
           {!data.loading && !!data.orchestraList.length && (
-            <Tabs
-              v-model:active={tabActive.value}
-              class={styles.tabs}
-              lazyRender={true}
-              background="transparent"
-              animated
-              swipeable
-            >
-              <Tab name="course" title="我的班级">
-                <div class={styles.content}>
-                  <MyClass
-                    list={modelData.orchestra?.classGroupIdList || []}
-                    orchestraId={modelData.orchestra?.id || ''}
-                  />
-                </div>
-              </Tab>
-              <Tab name="photo" title="乐团相册">
-                <div class={styles.content}>
-                  <MyPhoto orchestraId={modelData.orchestra?.id || ''} />
-                </div>
-              </Tab>
-              <Tab name="deeds" title="乐团事迹">
-                <div class={styles.content}>
-                  <OrchestraDeeds orchestraId={modelData.orchestra?.id || ''} />
-                </div>
-              </Tab>
-            </Tabs>
+            <>
+              <CellGroup inset>
+                <Cell
+                  class={styles.select}
+                  center
+                  isLink
+                  onClick={() => (modelData.orchestraStatus = true)}
+                >
+                  {{
+                    icon: () => <img class={styles.icon} src={iconOrchestra} />,
+                    title: () => <div class="van-ellipsis">{modelData.orchestra.name}</div>
+                  }}
+                </Cell>
+              </CellGroup>
+              <Tabs
+                v-model:active={tabActive.value}
+                class={styles.tabs}
+                lazyRender={true}
+                background="transparent"
+                animated
+                swipeable
+              >
+                <Tab name="course" title="我的班级">
+                  <div class={styles.content}>
+                    <MyClass list={modelData.orchestra?.classGroupIdList || []} />
+                  </div>
+                </Tab>
+                <Tab name="photo" title="乐团相册">
+                  <div class={styles.content}>
+                    <MyPhoto orchestraId={modelData.orchestra?.id || ''} />
+                  </div>
+                </Tab>
+                <Tab name="deeds" title="乐团事迹">
+                  <div class={styles.content}>
+                    <OrchestraDeeds orchestraId={modelData.orchestra?.id || ''} />
+                  </div>
+                </Tab>
+              </Tabs>
+            </>
           )}
           {!data.loading && !data.orchestraList.length && (
             <OEmpty btnStatus={false} tips="暂无乐团" />
@@ -179,7 +191,6 @@ export default defineComponent({
               }
               const active = data.orchestraList.find((n: any) => n.id == val) || {}
               modelData.orchestra = active
-              console.log(active)
             }}
           />
         </Popup>

+ 6 - 49
src/views/mine-orchestra/my-class/index.tsx

@@ -1,11 +1,9 @@
-import { Cell, CellGroup, Grid, GridItem, Image, List, Tag } from 'vant'
-import { defineComponent, onMounted, reactive } from 'vue'
+import { Cell, Grid, GridItem, Image } from 'vant'
+import { defineComponent, toRefs } from 'vue'
 import styles from './index.module.less'
 import iconTeacher from '@common/images/icon_teacher.png'
 import iconMessage from '@common/images/icon-muit-message.png'
 import { postMessage } from '@/helpers/native-message'
-import request from '@/helpers/request'
-import { state } from '@/state'
 import { openDefaultWebView } from '../../../state'
 
 export default defineComponent({
@@ -14,14 +12,9 @@ export default defineComponent({
     list: {
       type: Object,
       default: () => []
-    },
-    orchestraId: {
-      type: String,
-      default: ''
     }
   },
   setup(props) {
-    console.log("🚀 ~ props", props.list)
     const onMessage = async (item: any) => {
       console.log(item)
       postMessage({
@@ -35,49 +28,13 @@ export default defineComponent({
     const openClassDetail = (item: any) => {
       openDefaultWebView(`/classDetail?classId=${item.id}`)
     }
-    const data = reactive({
-      pages: {
-        page: 1,
-        rows: 20
-      },
-      classList: props.list as any[],
-      loading: false,
-      finished: false
-    })
-    const modelData = reactive({
-      orchestra: {} as any,
-      orchestraStatus: false
-    })
-    const getClassList = async () => {
-      data.loading = true
-      try {
-        const res: any = await request.post(`${state.platformApi}/classGroup/page`, {
-          data: {
-            ...data.pages,
-            orchestraId: props.orchestraId
-          }
-        })
-        console.log(data)
-        data.pages.page += 1
-        if (Array.isArray(res?.data?.rows)) {
-          const list = res.data.rows.map((n: any) => {
-            return {
-              ...n,
-              courseNum: Number(n.courseScheduleNum) - Number(n.completeCourseScheduleNum)
-            }
-          })
-          data.classList = ([] as any[]).concat(data.classList, list)
-          data.finished = res.data.rows.length == 0 ? true : false
-        }
-      } catch {}
-      data.loading = false
-    }
+    const { list } = toRefs(props)
     return () => (
       <div class={styles.myClass}>
-        {Array.isArray(data.classList) &&
-          data.classList.map((item: any) => (
+        {Array.isArray(list.value) &&
+          list.value.map((item: any) => (
             <div class={styles.itemDiv} onClick={() => openClassDetail(item)}>
-              <Cell center label={item.orchestraName}>
+              <Cell center label={item.classGroupId}>
                 {{
                   icon: () => (
                     <Image