lex-xin 1 ماه پیش
والد
کامیت
241389b7e9
3فایلهای تغییر یافته به همراه32 افزوده شده و 6 حذف شده
  1. 3 1
      src/helpers/hooks.ts
  2. 10 2
      src/views/music/list/index.tsx
  3. 19 3
      src/views/music/search/select-subject.tsx

+ 3 - 1
src/helpers/hooks.ts

@@ -18,7 +18,7 @@ export const SubjectEnum = {
 export const useSubjectId = (
   key: string,
   value?: any,
-  type = 'get' as 'get' | 'set'
+  type = 'get' as 'get' | 'set' | 'remove'
 ) => {
   // 判断是否在关键字
   // console.log(key, value, type)
@@ -27,6 +27,8 @@ export const useSubjectId = (
     let subject = localStorage.getItem(key)
     subject = subject ? JSON.parse(subject) : { name: '', id: '' }
     return subject
+  } else if(type === "remove") {
+    localStorage.removeItem(key)
   } else {
     localStorage.setItem(key, value)
     return ''

+ 10 - 2
src/views/music/list/index.tsx

@@ -243,7 +243,7 @@ export default defineComponent({
       params.subjectIds = item.id
       data.value = null
       subject.instrumentId = item.instrumentId
-      localStorage.setItem('userInstrumentId', item.instrumentId)
+      localStorage.setItem('userInstrumentId', item.instrumentId || "")
       if (baseState.platformType === 'TEACHER') {
         teacherDetaultSubject.value = {
           name: item.name,
@@ -268,11 +268,19 @@ export default defineComponent({
     }
 
     const getSubject: any = useSubjectId(SubjectEnum.SEARCH)
+
+    // 处理存值的问题 - 重置数量
+    let tempInstrumentId = localStorage.getItem('userInstrumentId') || ''
+    if(tempInstrumentId === 'undefined') {
+      useSubjectId(SubjectEnum.SEARCH, "", "remove")
+      tempInstrumentId = ""
+    }
+
     const subject = reactive({
       show: false,
       name: getSubject.id ? getSubject.name : '全部声部',
       id: getSubject.id || '',
-      instrumentId: localStorage.getItem('userInstrumentId') || '',
+      instrumentId: tempInstrumentId,
     })
 
     onMounted(async () => {

+ 19 - 3
src/views/music/search/select-subject.tsx

@@ -37,7 +37,8 @@ export default defineComponent({
     return {
       subject: {
         name: '全部声部',
-        id: ''
+        id: '',
+        instrumentId: ""
       },
       subjectList: [] as any,
       apiSuffix:
@@ -45,10 +46,10 @@ export default defineComponent({
     }
   },
   mounted() {
-    console.log(this.subject, '12')
     this.subject = {
       name: this.searchParams.id ? this.searchParams.name : '全部声部',
-      id: this.searchParams.id || ''
+      id: this.searchParams.id || '',
+      instrumentId: this.searchParams.instrumentId
     }
     this.getList()
   },
@@ -59,7 +60,22 @@ export default defineComponent({
       )
       if (Array.isArray(data)) {
         this.subjectList = data
+
+        // 初始化乐器编号
+        if(this.subject.id) {
+          data.forEach((item: any) => {
+            if(Array.isArray(item.subjects)) {
+              item.subjects.forEach((child: any) => {
+                if(child.id == this.subject.id) {
+                  this.subject.instrumentId = child.instrumentId
+                }
+              })
+            }
+          })
+        }
       }
+
+      
     }
   },
   render() {