瀏覽代碼

Merge branch 'iteration_1.3.4' into dev

lex 3 年之前
父節點
當前提交
d3f3a3b6e5

+ 56 - 0
src/helpers/hooks.ts

@@ -1,3 +1,6 @@
+import { reactive } from 'vue'
+import request from './request'
+
 // 搜索关键字
 export const SubjectEnum = {
   SEARCH: 'music-songbook-subject',
@@ -24,3 +27,56 @@ export const useSubjectId = (
     return ''
   }
 }
+
+interface IList {
+  params?: any
+  requestType?: 'json' | 'form'
+  loading: boolean
+  list: any[]
+  dataShow: boolean
+  finished: boolean
+}
+
+let lockLoad = false
+/*
+ * 列表获取数据
+ * @param url 请求地址
+ * @returns {Promise<IList>}
+ */
+export const useList = async (
+  url: string,
+  params: IList,
+  method = 'POST' as 'POST' | 'GET'
+) => {
+  try {
+    if (lockLoad) return params
+    // 上锁
+    lockLoad = true
+    const res =
+      method === 'POST'
+        ? await request.post(url, {
+            requestType: params.requestType || 'json',
+            data: {
+              ...params.params
+            }
+          })
+        : await request.get(url, {
+            requestType: params.requestType || 'json',
+            params: {
+              ...params.params
+            }
+          })
+    params.loading = false
+    const result = res.data || {}
+    params.list = params.list.concat(result.rows || [])
+    params.finished = result.pageNo >= result.totalPage
+    params.params.page = result.pageNo + 1
+    params.dataShow = params.list.length > 0
+  } catch {
+    params.dataShow = false
+    params.finished = true
+  }
+  // 解锁
+  lockLoad = false
+  return params
+}

+ 1 - 0
src/state.ts

@@ -9,6 +9,7 @@ export const state = reactive({
     data: {} as any
   },
   platformType: '' as 'STUDENT' | 'TEACHER',
+  platformApi: '/api-student' as '/api-student' | '/api-teacher',
   version: '', // 版本号 例如: 1.0.0
   ossUploadUrl: 'https://ks3-cn-beijing.ksyuncs.com/',
   musicCertStatus: false as boolean, // 是否音乐认证

+ 5 - 0
src/student/main.ts

@@ -33,6 +33,11 @@ if (browser().isTeacher) {
 } else {
   state.platformType = 'STUDENT'
 }
+if (state.platformType === 'TEACHER') {
+  state.platformApi = '/api-teacher'
+} else {
+  state.platformApi = '/api-student'
+}
 
 dayjs.locale('zh-ch')
 app.config.globalProperties.$dayjs = dayjs

+ 5 - 0
src/teacher/main.ts

@@ -45,6 +45,11 @@ if (browser().isTeacher) {
 } else {
   state.platformType = 'TEACHER'
 }
+if (state.platformType === 'TEACHER') {
+  state.platformApi = '/api-teacher'
+} else {
+  state.platformApi = '/api-student'
+}
 
 dayjs.locale('zh-ch')
 app.config.globalProperties.$dayjs = dayjs

+ 18 - 27
src/views/coupons/list.tsx

@@ -1,4 +1,5 @@
 import ColResult from '@/components/col-result'
+import { useList } from '@/helpers/hooks'
 import request from '@/helpers/request'
 import { state } from '@/state'
 import { List } from 'vant'
@@ -18,10 +19,11 @@ export default defineComponent({
   data() {
     return {
       list: [] as any,
-      dataShow: true, // 判断是否有数据
-      loading: false,
-      finished: false,
-      lockLoad: false,
+      listState: {
+        dataShow: true, // 判断是否有数据
+        loading: false,
+        finished: false
+      },
       params: {
         useState: this.useState,
         page: 1,
@@ -35,38 +37,27 @@ export default defineComponent({
   methods: {
     async getList() {
       try {
-        if (this.lockLoad) return
-        // 上锁
-        this.lockLoad = true
-        // 判断是哪个端
-        const url =
-          state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
-        const res = await request.post(`${url}/couponInfo/page`, {
-          data: {
-            ...this.params
-          }
+        const result = await useList(`${state.platformApi}/couponInfo/page`, {
+          params: this.params,
+          list: this.list,
+          ...this.listState
         })
-        this.loading = false
-        const result = res.data || {}
-        this.list = this.list.concat(result.rows || [])
-        this.finished = result.pageNo >= result.totalPage
-        this.params.page = result.pageNo + 1
-        this.dataShow = this.list.length > 0
-        // 解锁
-        this.lockLoad = false
+        const { params, list, ...res } = result
+        this.params = params
+        this.list = list
+        this.listState = res
       } catch {
-        this.dataShow = false
-        this.finished = true
+        //
       }
     }
   },
   render() {
     return (
       <>
-        {this.dataShow ? (
+        {this.listState.dataShow ? (
           <List
-            v-model:loading={this.loading}
-            finished={this.finished}
+            v-model:loading={this.listState.loading}
+            finished={this.listState.finished}
             finishedText=" "
             // 为了处理体验问题
             class={[this.list.length > 0 && styles.list]}

+ 5 - 4
src/views/live-class/index.tsx

@@ -14,7 +14,9 @@ import OrganSearch from '@/student/practice-class/model/organ-search'
 export default defineComponent({
   name: 'liveClass',
   data() {
-    const sessionSubjectId = sessionStorage.getItem('liveClassSubjectId')
+    const sessionSubjectId = Number(
+      sessionStorage.getItem('liveClassSubjectId')
+    )
     const subjectIds = state.user.data?.subjectId || ''
     const subjectId = subjectIds ? Number(subjectIds.split(',')[0]) : null
 
@@ -59,8 +61,7 @@ export default defineComponent({
     for (let i = 0; i < list.length; i++) {
       const subjects = (list[i] as any).subjects || []
       for (let j = 0; j < subjects.length; j++) {
-        if (userSubjectId.includes(subjects[j].id + '')) {
-          console.log('true')
+        if (userSubjectId.includes(subjects[j].id)) {
           this.params.subjectId = subjects[j].id
           this.params.subjectName = subjects[j].name
           isRest = false
@@ -68,7 +69,7 @@ export default defineComponent({
         }
       }
     }
-    console.log(isRest, 'isRest')
+    // console.log(isRest, 'isRest')
     if (isRest && list.length && (list[0] as any).subjects) {
       this.params.subjectId = (list[0] as any).subjects[0].id
       this.params.subjectName = (list[0] as any).subjects[0].name

+ 25 - 0
src/views/music/search/header.tsx

@@ -15,6 +15,7 @@ import SelectTag from './select-tag'
 import { getRandomKey, musicBuy } from '../music'
 import SelectSubject from './select-subject'
 import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
+import { state } from '@/state'
 
 export const mitter = mitt()
 
@@ -23,6 +24,30 @@ const selectTagRef = ref()
 export default defineComponent({
   name: 'MusicSearchHeader',
   setup() {
+    console.log(state.user.data, 'music-search-header')
+    const subjects: any = useSubjectId(SubjectEnum.SEARCH)
+    // 判断是否已有数据
+    if (!subjects.id) {
+      const users = state.user.data
+      const subjectId = users.subjectId
+        ? Number(users.subjectId.split(',')[0])
+        : ''
+      const subjectName = users.subjectName
+        ? users.subjectName.split(',')[0]
+        : ''
+      console.log(subjectName, subjectId, subjects)
+      if (subjectId) {
+        useSubjectId(
+          SubjectEnum.SEARCH,
+          JSON.stringify({
+            id: subjectId,
+            name: subjectName
+          }),
+          'set'
+        )
+      }
+    }
+
     const searchInputRef = ref()
     localStorage.setItem('behaviorId', getRandomKey())
     const router = useRouter()

+ 7 - 7
src/views/music/songbook/list.tsx

@@ -14,23 +14,23 @@ export default defineComponent({
   name: 'Songbook',
   setup() {
     const router = useRouter()
-    const route = useRoute()
-    const params: any = {}
+    const params: any = {
+      myself: false
+    }
     // 学生端才会有version
     if (tempState.version) {
       params.version = tempState.version || '' // 处理ios审核版本
       params.platform =
         tempState.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher'
     }
-    const apiSuffix =
-      tempState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
-    // if (tempState.platformType === 'TEACHER') {
-    params.myself = false
-    // }
+    console.log('music-list')
     const getSubject: any = useSubjectId(SubjectEnum.SEARCH)
     if (getSubject) {
       params.subjectIds = getSubject.id
     }
+
+    const apiSuffix =
+      tempState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
     const { isLoading, state } = useAsyncState(
       request.post(`${apiSuffix}/music/sheet/list`, {
         data: {

+ 2 - 51
src/views/order-detail/use-coupons/choice-coupon.tsx

@@ -6,52 +6,6 @@ import { Button, Loading } from 'vant'
 import { defineComponent } from 'vue'
 import styles from './index.module.less'
 
-export const list = [
-  {
-    couponType: 'FULL_DISCOUNT',
-    discountPrice: '2',
-    useLimit: '30',
-    endTime: new Date(),
-    id: 1,
-    couponName: '小酷Ai充值券',
-    startTime: new Date(),
-    useState: 'USABLE',
-    useTime: new Date()
-  },
-  {
-    couponType: 'FULL_DISCOUNT',
-    discountPrice: '5',
-    useLimit: '20',
-    endTime: new Date(),
-    id: 2,
-    couponName: '小酷Ai充值券',
-    startTime: new Date(),
-    useState: 'USABLE',
-    useTime: new Date()
-  },
-  {
-    couponType: 'FULL_DISCOUNT',
-    discountPrice: '3',
-    useLimit: '10',
-    endTime: new Date(),
-    id: 3,
-    couponName: '小酷Ai充值券',
-    startTime: new Date(),
-    useState: 'USABLE',
-    useTime: new Date()
-  },
-  {
-    couponType: 'FULL_DISCOUNT',
-    discountPrice: '1',
-    useLimit: '29',
-    endTime: new Date(),
-    id: 0,
-    couponName: '小酷Ai充值券',
-    startTime: new Date(),
-    useState: 'USABLE',
-    useTime: new Date()
-  }
-]
 export default defineComponent({
   name: 'choice-coupon',
   props: {
@@ -83,15 +37,12 @@ export default defineComponent({
   },
   methods: {
     async getList() {
+      if (this.dataLoading) return
       this.dataLoading = true
       try {
-        // 判断是哪个端
-        const url =
-          state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
-        const res = await request.post(`${url}/couponInfo/page`, {
+        const res = await request.post(`${state.platformApi}/couponInfo/page`, {
           data: {
             useState: 'USABLE',
-
             page: 1,
             rows: 100
           }

+ 4 - 3
src/views/video-class/index.tsx

@@ -14,7 +14,9 @@ import OrganSearch from '@/student/practice-class/model/organ-search'
 export default defineComponent({
   name: 'VideoClass',
   data() {
-    const sessionSubjectId = sessionStorage.getItem('videoClassSubjectId')
+    const sessionSubjectId = Number(
+      sessionStorage.getItem('videoClassSubjectId')
+    )
     const subjectIds = state.user.data?.subjectId || ''
     const subjectId = subjectIds ? Number(subjectIds.split(',')[0]) : null
     return {
@@ -25,7 +27,6 @@ export default defineComponent({
       dataShow: true, // 判断是否有数据
       loading: false,
       finished: false,
-      sessionSubjectId,
       params: {
         search: '',
         lessonSubject: (sessionSubjectId || subjectId || null) as any,
@@ -57,7 +58,7 @@ export default defineComponent({
     for (let i = 0; i < list.length; i++) {
       const subjects = (list[i] as any).subjects || []
       for (let j = 0; j < subjects.length; j++) {
-        if (userSubjectId.includes(subjects[j].id + '')) {
+        if (userSubjectId.includes(subjects[j].id)) {
           this.params.lessonSubject = subjects[j].id
           this.params.subjectName = subjects[j].name
           isRest = false