|
@@ -9,11 +9,13 @@ import {
|
|
|
ElOption,
|
|
|
ElIcon
|
|
|
} from 'element-plus'
|
|
|
+import { state as baseSate } from '@/state'
|
|
|
|
|
|
// import white from './while.module.less'
|
|
|
import classes from './index.module.less'
|
|
|
import request from '@/helpers/request'
|
|
|
import searchIcon from './images/searchIcon.png'
|
|
|
+import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
|
|
|
export default defineComponent({
|
|
|
name: 'searchInput',
|
|
|
props: {
|
|
@@ -32,6 +34,10 @@ export default defineComponent({
|
|
|
holder: {
|
|
|
type: String,
|
|
|
default: '搜一搜你想练习的曲目'
|
|
|
+ },
|
|
|
+ type: {
|
|
|
+ type: String,
|
|
|
+ default: 'search'
|
|
|
}
|
|
|
},
|
|
|
emits: ['startSearch'],
|
|
@@ -48,8 +54,10 @@ export default defineComponent({
|
|
|
searchVal => {
|
|
|
// console.log(searchVal,'searchVal')
|
|
|
state.search = searchVal.search ? searchVal.search : ''
|
|
|
- state.subject = Number(props.searchVal.subject || props.searchVal.lessonSubject)
|
|
|
- ? Number(props.searchVal.subject|| props.searchVal.lessonSubject)
|
|
|
+ state.subject = Number(
|
|
|
+ props.searchVal.subject || props.searchVal.lessonSubject
|
|
|
+ )
|
|
|
+ ? Number(props.searchVal.subject || props.searchVal.lessonSubject)
|
|
|
: ''
|
|
|
},
|
|
|
{
|
|
@@ -60,11 +68,47 @@ export default defineComponent({
|
|
|
console.log('调用')
|
|
|
try {
|
|
|
const res = await request.get(
|
|
|
- '/api-website/open/subject/queryPage',
|
|
|
- {params:{rows:9999,page:1}}
|
|
|
+ '/api-website/open/subject/subjectSelect',
|
|
|
+ { params: { type: 'MUSIC' } }
|
|
|
+ )
|
|
|
+ const result = res.data || []
|
|
|
+ const tempSubject: any = []
|
|
|
+ result.forEach((item: any) => {
|
|
|
+ if (item.subjects && item.subjects.length > 0) {
|
|
|
+ item.subjects.forEach((subject: any) => {
|
|
|
+ tempSubject.push(subject)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const subjects: any = useSubjectId(
|
|
|
+ SubjectEnum[props.type === 'search' ? 'SEARCH' : 'VIDEO']
|
|
|
)
|
|
|
+ console.log(subjects, 'subjects found')
|
|
|
+ state.subjectList = tempSubject
|
|
|
+ const subjectIds = baseSate.user.data?.subjectId || ''
|
|
|
+ // 判断是否已有数据
|
|
|
+ if (subjects.id) {
|
|
|
+ state.subject = Number(subjects.id)
|
|
|
+ } else {
|
|
|
+ if (subjectIds) {
|
|
|
+ const subjectId = Number(subjectIds.split(',')[0])
|
|
|
+ state.subject = subjectId
|
|
|
|
|
|
- state.subjectList = res.data.rows
|
|
|
+ tempSubject.forEach((subject: any) => {
|
|
|
+ if (subject.id == subjectId) {
|
|
|
+ // 设置默认查询声部
|
|
|
+ useSubjectId(
|
|
|
+ SubjectEnum[props.type === 'search' ? 'SEARCH' : 'VIDEO'],
|
|
|
+ JSON.stringify({
|
|
|
+ id: subjectId,
|
|
|
+ name: subject.name
|
|
|
+ }),
|
|
|
+ 'set'
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (e) {
|
|
|
console.log(e)
|
|
|
}
|
|
@@ -75,6 +119,22 @@ export default defineComponent({
|
|
|
search: state.search,
|
|
|
subject: state.subject
|
|
|
})
|
|
|
+ const subjects = {
|
|
|
+ id: state.subject,
|
|
|
+ name: ''
|
|
|
+ }
|
|
|
+ state.subjectList.forEach((subject: any) => {
|
|
|
+ if (subject.id == subjects.id) {
|
|
|
+ subjects.name = subject.name
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 设置声部
|
|
|
+ useSubjectId(
|
|
|
+ SubjectEnum[props.type === 'search' ? 'SEARCH' : 'VIDEO'],
|
|
|
+ JSON.stringify(subjects),
|
|
|
+ 'set'
|
|
|
+ )
|
|
|
}
|
|
|
onMounted(() => {
|
|
|
getSubjectList()
|
|
@@ -87,11 +147,11 @@ export default defineComponent({
|
|
|
<div class={[classes.wrap]}>
|
|
|
<div class={classes.selectWrap} id="selectWrap">
|
|
|
<ElSelect
|
|
|
- clearable
|
|
|
+ // clearable
|
|
|
v-model={state.subject}
|
|
|
placeholder="请选择声部"
|
|
|
style="width: 175px"
|
|
|
- class={["subSelect",state.subject?'hasVal':'']}
|
|
|
+ class={['subSelect', state.subject ? 'hasVal' : '']}
|
|
|
v-slots={{
|
|
|
suffix: () => <div class={classes.san}></div>
|
|
|
}}
|
|
@@ -102,7 +162,7 @@ export default defineComponent({
|
|
|
</ElSelect>
|
|
|
<div class={classes.line}></div>
|
|
|
</div>
|
|
|
- <div class={classes.searchWrap} >
|
|
|
+ <div class={classes.searchWrap}>
|
|
|
<img src={searchIcon} alt="" />
|
|
|
</div>
|
|
|
<ElInput
|
|
@@ -116,8 +176,10 @@ export default defineComponent({
|
|
|
// }
|
|
|
// }}
|
|
|
></ElInput>
|
|
|
- <div class={classes.searchline}></div>
|
|
|
- <div class={classes.searchBtn} onClick={startSearch}>搜索</div >
|
|
|
+ <div class={classes.searchline}></div>
|
|
|
+ <div class={classes.searchBtn} onClick={startSearch}>
|
|
|
+ 搜索
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</>
|
|
|
)
|