Explorar o código

优化部分功能

wolyshaw %!s(int64=3) %!d(string=hai) anos
pai
achega
155ebd5d8b

+ 301 - 295
src/student/member-center/member-record.tsx

@@ -1,295 +1,301 @@
-import ColHeader from '@/components/col-header'
-import { defineComponent } from 'vue'
-import styles from './member-record.module.less'
-import {
-  Cell,
-  CellGroup,
-  DatetimePicker,
-  Grid,
-  GridItem,
-  Icon,
-  Image,
-  List,
-  Popup,
-  Sticky
-} from 'vant'
-import { levelMember } from '@/constant'
-import request from '@/helpers/request'
-import { formatterDate } from '@/helpers/utils'
-import dayjs from 'dayjs'
-import ColResult from '@/components/col-result'
-import { postMessage } from '@/helpers/native-message'
-
-export const getAssetsHomeFile = (fileName: string) => {
-  const path = `./images/${fileName}`
-  const modules = import.meta.globEager('./images/*')
-  return modules[path].default
-}
-
-export default defineComponent({
-  name: 'memberRecord',
-  data() {
-    return {
-      userTrainOverView: {
-        trainDays: 0,
-        trainNum: 0,
-        trainTime: 0
-      },
-      timeStatus: false,
-      currentDate: new Date(),
-      list: [],
-      dataShow: true, // 判断是否有数据
-      loading: false,
-      finished: false,
-      params: {
-        page: 1,
-        rows: 20
-      }
-    }
-  },
-  async mounted() {
-    this.getList()
-  },
-  methods: {
-    onSearch() {
-      this.timeStatus = false
-      this.dataShow = true
-      this.loading = false
-      this.finished = false
-      this.list = []
-      this.params.page = 1
-      this.getList()
-    },
-    async getList() {
-      try {
-        let params = this.params
-        const res = await request.get(
-          '/api-student/sysMusicRecord/studentTrainData',
-          {
-            params: {
-              ...params,
-              startTime: dayjs(this.currentDate).format('YYYY-MM-DD')
-            }
-          }
-        )
-        this.loading = false
-        const result = res.data || {}
-        this.userTrainOverView = result.userTrainOverView
-        // 处理重复请求数据
-        if (this.list.length > 0 && result.detail.pageNo === 1) {
-          return
-        }
-        this.list = this.list.concat(result.detail.rows || [])
-        this.finished = result.detail.pageNo >= result.detail.totalPage
-        this.params.page = result.detail.pageNo + 1
-        this.dataShow = this.list.length > 0
-      } catch {
-        this.dataShow = false
-        this.finished = true
-      }
-    }
-  },
-  render() {
-    return (
-      <div class={styles['member-record']}>
-        {/* <Sticky position="top" offsetTop={0}> */}
-        <ColHeader
-          class={styles.memberHeader}
-          background="#00d1a1"
-          backIconColor="white"
-          border={false}
-          color="#fff"
-          // isFixed={false}
-          v-slots={{
-            default: () => (
-              <div class={styles.headerContent}>
-                <Image
-                  class={styles.headerImg}
-                  src={getAssetsHomeFile('record_bg.png')}
-                />
-
-                <div class={styles.headerCount}>
-                  <div class={styles.headerItem}>
-                    <span class={styles.num}>
-                      {this.userTrainOverView.trainDays}天
-                    </span>
-                    <span>累计训练天数</span>
-                  </div>
-                  <div class={styles.headerItem}>
-                    <span class={styles.num}>
-                      {this.userTrainOverView.trainTime}分钟
-                    </span>
-                    <span>累计训练时长</span>
-                  </div>
-                  <div class={styles.headerItem}>
-                    <span class={styles.num}>
-                      {this.userTrainOverView.trainNum}次
-                    </span>
-                    <span>累计训练次数</span>
-                  </div>
-                </div>
-              </div>
-              //   <div class={[styles.certHeader, this.headStatus ? styles.certWhite : null]}>
-              //     老师认证
-              //   </div>
-            )
-          }}
-        />
-        {/* </Sticky> */}
-
-        <div style={{ overflow: 'hidden', paddingBottom: '12px' }}>
-          <Cell
-            class={styles.memberCell}
-            v-slots={{
-              title: () => (
-                <div class={styles.rTitle}>
-                  <span>评测记录</span>
-                </div>
-              ),
-              default: () => (
-                <div
-                  class={styles.dataItem}
-                  onClick={() => (this.timeStatus = true)}
-                >
-                  {dayjs(this.currentDate).format('YYYY年MM月DD日')}
-                  <Icon
-                    classPrefix="iconfont"
-                    name="down"
-                    size={8}
-                    color="var(--van-primary)"
-                  />
-                </div>
-              )
-            }}
-          ></Cell>
-
-          <Popup show={this.timeStatus} position="bottom" round closeOnPopstate>
-            <DatetimePicker
-              type="date"
-              v-model={this.currentDate}
-              formatter={formatterDate}
-              onCancel={() => {
-                this.timeStatus = false
-              }}
-              onConfirm={this.onSearch}
-            />
-          </Popup>
-          {this.dataShow ? (
-            <List
-              v-model:loading={this.loading}
-              finished={this.finished}
-              finishedText=" "
-              immediateCheck={false}
-              class={[styles.liveList, 'mb12']}
-              onLoad={this.getList}
-            >
-              {this.list.map((item: any) => (
-                <CellGroup
-                  class={styles['data-content']}
-                  border={false}
-                  onClick={() => {
-                    postMessage({
-                      api: 'openAccompanyWebView',
-                      content: {
-                        url: location.origin + '/accompany?id=' + item.id,
-                        orientation: 0,
-                        isHideTitle: true,
-                        statusBarTextColor: false,
-                        isOpenLight: true
-                      }
-                    })
-                    return
-                  }}
-                >
-                  <Cell
-                    center
-                    v-slots={{
-                      title: () => (
-                        <div class={styles.dataTitle}>
-                          <span>{item.sysMusicScoreName}</span>
-                          {item.videoFilePath && (
-                            <Icon
-                              name={getAssetsHomeFile('icon_video.png')}
-                              size={20}
-                            />
-                          )}
-                        </div>
-                      ),
-                      default: () => (
-                        <div class={styles.dataItem}>
-                          {dayjs(item.createTime).format('YYYY/MM/DD HH:mm')}
-                        </div>
-                      )
-                    }}
-                  ></Cell>
-                  <Cell
-                    center
-                    style={{ paddingLeft: '5px', paddingRight: '5px' }}
-                    v-slots={{
-                      title: () => (
-                        <Grid border={false} columnNum={5}>
-                          <GridItem
-                            text="评测难度"
-                            v-slots={{
-                              icon: () => (
-                                <span style={{ color: '#000000' }}>
-                                  {levelMember[item.heardLevel]}
-                                </span>
-                              )
-                            }}
-                          ></GridItem>
-                          <GridItem
-                            text="评测分数"
-                            v-slots={{
-                              icon: () => (
-                                <span style={{ color: '#000000' }}>
-                                  {item.score}分
-                                </span>
-                              )
-                            }}
-                          ></GridItem>
-                          <GridItem
-                            text="音准"
-                            v-slots={{
-                              icon: () => (
-                                <span style={{ color: '#01C1B5' }}>
-                                  {item.intonation}分
-                                </span>
-                              )
-                            }}
-                          ></GridItem>
-                          <GridItem
-                            text="节奏"
-                            v-slots={{
-                              icon: () => (
-                                <span style={{ color: '#FF802C' }}>
-                                  {item.cadence}分
-                                </span>
-                              )
-                            }}
-                          ></GridItem>
-                          <GridItem
-                            text="完成度"
-                            v-slots={{
-                              icon: () => (
-                                <span style={{ color: '#F79C00' }}>
-                                  {item.integrity}分
-                                </span>
-                              )
-                            }}
-                          ></GridItem>
-                        </Grid>
-                      )
-                    }}
-                  ></Cell>
-                </CellGroup>
-              ))}
-            </List>
-          ) : (
-            <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无记录" />
-          )}
-        </div>
-      </div>
-    )
-  }
-})
+import ColHeader from '@/components/col-header'
+import { defineComponent } from 'vue'
+import styles from './member-record.module.less'
+import {
+  Cell,
+  CellGroup,
+  DatetimePicker,
+  Grid,
+  GridItem,
+  Icon,
+  Image,
+  List,
+  Popup,
+  Sticky
+} from 'vant'
+import { levelMember } from '@/constant'
+import request from '@/helpers/request'
+import { formatterDate } from '@/helpers/utils'
+import dayjs from 'dayjs'
+import ColResult from '@/components/col-result'
+import { postMessage } from '@/helpers/native-message'
+
+export const getAssetsHomeFile = (fileName: string) => {
+  const path = `./images/${fileName}`
+  const modules = import.meta.globEager('./images/*')
+  return modules[path].default
+}
+
+export default defineComponent({
+  name: 'memberRecord',
+  data() {
+    return {
+      userTrainOverView: {
+        trainDays: 0,
+        trainNum: 0,
+        trainTime: 0
+      },
+      timeStatus: false,
+      currentDate: new Date(),
+      list: [],
+      dataShow: true, // 判断是否有数据
+      loading: false,
+      finished: false,
+      params: {
+        page: 1,
+        rows: 20
+      }
+    }
+  },
+  async mounted() {
+    this.getList()
+  },
+  methods: {
+    onSearch() {
+      this.timeStatus = false
+      this.dataShow = true
+      this.loading = false
+      this.finished = false
+      this.list = []
+      this.params.page = 1
+      this.getList()
+    },
+    async getList() {
+      try {
+        let params = this.params
+        const res = await request.get(
+          '/api-student/sysMusicRecord/studentTrainData',
+          {
+            params: {
+              ...params,
+              startTime: dayjs(this.currentDate).format('YYYY-MM-DD')
+            }
+          }
+        )
+        this.loading = false
+        const result = res.data || {}
+        this.userTrainOverView = result.userTrainOverView
+        // 处理重复请求数据
+        if (this.list.length > 0 && result.detail.pageNo === 1) {
+          return
+        }
+        this.list = this.list.concat(result.detail.rows || [])
+        this.finished = result.detail.pageNo >= result.detail.totalPage
+        this.params.page = result.detail.pageNo + 1
+        this.dataShow = this.list.length > 0
+      } catch {
+        this.dataShow = false
+        this.finished = true
+      }
+    }
+  },
+  render() {
+    return (
+      <div class={styles['member-record']}>
+        {/* <Sticky position="top" offsetTop={0}> */}
+        <ColHeader
+          class={styles.memberHeader}
+          background="#00d1a1"
+          backIconColor="white"
+          border={false}
+          color="#fff"
+          // isFixed={false}
+          v-slots={{
+            default: () => (
+              <div class={styles.headerContent}>
+                <Image
+                  class={styles.headerImg}
+                  src={getAssetsHomeFile('record_bg.png')}
+                />
+
+                <div class={styles.headerCount}>
+                  <div class={styles.headerItem}>
+                    <span class={styles.num}>
+                      {this.userTrainOverView.trainDays}天
+                    </span>
+                    <span>累计训练天数</span>
+                  </div>
+                  <div class={styles.headerItem}>
+                    <span class={styles.num}>
+                      {this.userTrainOverView.trainTime}分钟
+                    </span>
+                    <span>累计训练时长</span>
+                  </div>
+                  <div class={styles.headerItem}>
+                    <span class={styles.num}>
+                      {this.userTrainOverView.trainNum}次
+                    </span>
+                    <span>累计训练次数</span>
+                  </div>
+                </div>
+              </div>
+              //   <div class={[styles.certHeader, this.headStatus ? styles.certWhite : null]}>
+              //     老师认证
+              //   </div>
+            )
+          }}
+        />
+        {/* </Sticky> */}
+
+        <div style={{ overflow: 'hidden', paddingBottom: '12px' }}>
+          <Cell
+            class={styles.memberCell}
+            v-slots={{
+              title: () => (
+                <div class={styles.rTitle}>
+                  <span>评测记录</span>
+                </div>
+              ),
+              default: () => (
+                <div
+                  class={styles.dataItem}
+                  onClick={() => (this.timeStatus = true)}
+                >
+                  {dayjs(this.currentDate).format('YYYY年MM月DD日')}
+                  <Icon
+                    classPrefix="iconfont"
+                    name="down"
+                    size={8}
+                    color="var(--van-primary)"
+                  />
+                </div>
+              )
+            }}
+          ></Cell>
+
+          <Popup show={this.timeStatus} position="bottom" round closeOnPopstate>
+            <DatetimePicker
+              type="date"
+              v-model={this.currentDate}
+              formatter={formatterDate}
+              onCancel={() => {
+                this.timeStatus = false
+              }}
+              onConfirm={this.onSearch}
+            />
+          </Popup>
+          {this.dataShow ? (
+            <List
+              v-model:loading={this.loading}
+              finished={this.finished}
+              finishedText=" "
+              immediateCheck={false}
+              class={[styles.liveList, 'mb12']}
+              onLoad={this.getList}
+            >
+              {this.list.map((item: any) => (
+                <CellGroup
+                  class={styles['data-content']}
+                  border={false}
+                  onClick={() => {
+                    const behaviorId = localStorage.getItem('behaviorId')
+                    postMessage({
+                      api: 'openAccompanyWebView',
+                      content: {
+                        url:
+                          location.origin +
+                          '/accompany?id=' +
+                          item.id +
+                          '&behaviorId=' +
+                          behaviorId,
+                        orientation: 0,
+                        isHideTitle: true,
+                        statusBarTextColor: false,
+                        isOpenLight: true
+                      }
+                    })
+                    return
+                  }}
+                >
+                  <Cell
+                    center
+                    v-slots={{
+                      title: () => (
+                        <div class={styles.dataTitle}>
+                          <span>{item.sysMusicScoreName}</span>
+                          {item.videoFilePath && (
+                            <Icon
+                              name={getAssetsHomeFile('icon_video.png')}
+                              size={20}
+                            />
+                          )}
+                        </div>
+                      ),
+                      default: () => (
+                        <div class={styles.dataItem}>
+                          {dayjs(item.createTime).format('YYYY/MM/DD HH:mm')}
+                        </div>
+                      )
+                    }}
+                  ></Cell>
+                  <Cell
+                    center
+                    style={{ paddingLeft: '5px', paddingRight: '5px' }}
+                    v-slots={{
+                      title: () => (
+                        <Grid border={false} columnNum={5}>
+                          <GridItem
+                            text="评测难度"
+                            v-slots={{
+                              icon: () => (
+                                <span style={{ color: '#000000' }}>
+                                  {levelMember[item.heardLevel]}
+                                </span>
+                              )
+                            }}
+                          ></GridItem>
+                          <GridItem
+                            text="评测分数"
+                            v-slots={{
+                              icon: () => (
+                                <span style={{ color: '#000000' }}>
+                                  {item.score}分
+                                </span>
+                              )
+                            }}
+                          ></GridItem>
+                          <GridItem
+                            text="音准"
+                            v-slots={{
+                              icon: () => (
+                                <span style={{ color: '#01C1B5' }}>
+                                  {item.intonation}分
+                                </span>
+                              )
+                            }}
+                          ></GridItem>
+                          <GridItem
+                            text="节奏"
+                            v-slots={{
+                              icon: () => (
+                                <span style={{ color: '#FF802C' }}>
+                                  {item.cadence}分
+                                </span>
+                              )
+                            }}
+                          ></GridItem>
+                          <GridItem
+                            text="完成度"
+                            v-slots={{
+                              icon: () => (
+                                <span style={{ color: '#F79C00' }}>
+                                  {item.integrity}分
+                                </span>
+                              )
+                            }}
+                          ></GridItem>
+                        </Grid>
+                      )
+                    }}
+                  ></Cell>
+                </CellGroup>
+              ))}
+            </List>
+          ) : (
+            <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无记录" />
+          )}
+        </div>
+      </div>
+    )
+  }
+})

+ 2 - 1
src/student/music/album-detail/index.tsx

@@ -10,7 +10,7 @@ import FavoritedIcon from '../album/favorited.svg'
 import styles from './index.module.less'
 import Item from '../list/item'
 import { useRect } from '@vant/use'
-import { musicBuy } from '../music'
+import { getRandomKey, musicBuy } from '../music'
 
 const noop = () => {}
 
@@ -23,6 +23,7 @@ export default defineComponent({
     }
   },
   setup({ onItemClick }) {
+    localStorage.setItem('behaviorId', getRandomKey())
     const params = reactive({
       search: '',
       page: 1

+ 6 - 4
src/student/music/list/index.tsx

@@ -7,7 +7,7 @@ import SelectTag from '../search/select-tag'
 import { useRoute, useRouter } from 'vue-router'
 import ColResult from '@/components/col-result'
 import styles from './index.module.less'
-import { musicBuy } from '../music'
+import { getRandomKey, musicBuy } from '../music'
 
 const noop = () => {}
 
@@ -32,6 +32,7 @@ export default defineComponent({
     }
   },
   setup({ hideSearch, defauleParams, onItemClick, teacherId }, { expose }) {
+    localStorage.setItem('behaviorId', getRandomKey())
     const route = useRoute()
     const router = useRouter()
     const params = reactive({
@@ -81,9 +82,10 @@ export default defineComponent({
     }
 
     const onComfirm = tags => {
-      const data = Object.values(tags).flat().filter(Boolean).join(',')
-      params.musicTagIds = data
+      const d = Object.values(tags).flat().filter(Boolean).join(',')
+      params.musicTagIds = d
       params.page = 1
+      data.value = null
       FetchList()
       tagVisibility.value = false
     }
@@ -123,7 +125,7 @@ export default defineComponent({
                     if (onItemClick === noop) {
                       musicBuy(item)
                     } else {
-                      onItemClick(item)
+                      onItemClick?.(item)
                     }
                   }}
                 />

+ 12 - 1
src/student/music/music.ts

@@ -2,11 +2,22 @@ import { orderStatus } from '@/views/order-detail/orderStatus'
 import { postMessage } from '@/helpers/native-message'
 import { Dialog } from 'vant'
 
+export const getRandomKey = () => {
+  const key = '' + new Date().getTime() + Math.floor(Math.random() * 1000000)
+  return key
+}
+
 export const musicBuy = (item: any, callBack?: any) => {
+  const behaviorId = localStorage.getItem('behaviorId')
   postMessage({
     api: 'openAccompanyWebView',
     content: {
-      url: location.origin + '/accompany?id=' + item.id,
+      url:
+        location.origin +
+        '/accompany?id=' +
+        item.id +
+        '&behaviorId=' +
+        behaviorId,
       // url: 'http://192.168.3.13:3000/colexiu.html?id=' + item.id,
       orientation: 0,
       isHideTitle: true,

+ 2 - 0
src/student/music/personal/index.tsx

@@ -7,10 +7,12 @@ import Collection from './collection'
 import Album from './album'
 
 import styles from './index.module.less'
+import { getRandomKey } from '../music'
 
 export default defineComponent({
   name: 'MusicPersonal',
   setup() {
+    localStorage.setItem('behaviorId', getRandomKey())
     const activeTab = ref('personal')
     const personal = ref()
     const collection = ref()

+ 2 - 1
src/student/music/search/index.tsx

@@ -13,11 +13,12 @@ import SelectTag from './select-tag'
 import ColResult from '@/components/col-result'
 import { orderStatus } from '@/views/order-detail/orderStatus'
 import { useRouter } from 'vue-router'
-import { musicBuy } from '../music'
+import { getRandomKey, musicBuy } from '../music'
 
 export default defineComponent({
   name: 'MusicSearch',
   setup() {
+    localStorage.setItem('behaviorId', getRandomKey())
     const router = useRouter()
     const loading = ref(false)
     const keyword = ref('')

+ 2 - 0
src/student/music/songbook/index.tsx

@@ -5,10 +5,12 @@ import Album from './album'
 import List from './list'
 import styles from './index.module.less'
 import { useRouter } from 'vue-router'
+import { getRandomKey } from '../music'
 
 export default defineComponent({
   name: 'Songbook',
   setup() {
+    localStorage.setItem('behaviorId', getRandomKey())
     const router = useRouter()
     return () => (
       <div class={styles.songbook}>