resourcesList.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. <template>
  2. <div class="resourcesList">
  3. <div class="headCon">
  4. <div class="headLeft">
  5. <img class="tipImg" src="@/views/Editor/CanvasTool/imgs/zyk.png" alt="" />
  6. <div class="title">资源库</div>
  7. </div>
  8. <div class="headright">
  9. <img @click="emits('close')" class="closeBtn" src="../../cloudCoachElement/cloudCoachList/imgs/close.png" alt="" />
  10. </div>
  11. </div>
  12. <div class="content">
  13. <div class="tabTools">
  14. <div class="tabCon">
  15. <div
  16. class="tab"
  17. @click="handleTabChange(item.value)"
  18. :class="{ active: item.value === queryData.sourceType }"
  19. v-for="item in tabData"
  20. :key="item.value"
  21. >
  22. {{ item.label }}
  23. </div>
  24. </div>
  25. <div></div>
  26. </div>
  27. <div class="typeTools">
  28. <div class="typeTabCon">
  29. <div
  30. v-for="item in resourcesTypeOption"
  31. :key="item.value"
  32. @click="handleTypeChange(item.value)"
  33. :class="['queryTip', queryData.type === item.value && 'active']"
  34. >
  35. {{ item.text }}
  36. </div>
  37. </div>
  38. <div class="query">
  39. <Input :placeholder="'请输入搜索关键词'" v-model:value="queryData.name" @enter="handleQuery">
  40. <template #prefix>
  41. <img class="img" src="../../cloudCoachElement/cloudCoachList/imgs/query.png" alt="" />
  42. </template>
  43. <template #suffix>
  44. <div class="queryBtn" @click="handleQuery">搜索</div>
  45. </template>
  46. </Input>
  47. </div>
  48. </div>
  49. <div class="musicListCon">
  50. <div class="queryFrom" :class="{ isExpandAct: !isExpand }">
  51. <div class="queryFromList">
  52. <div class="tit">乐器:</div>
  53. <div class="queryFromCon">
  54. <template v-for="item in subjectList">
  55. <div
  56. :class="['queryTip', queryData.subject.id === item.instruments[0].id && 'active']"
  57. @click="handleSubjectChange(item.instruments[0])"
  58. v-if="item.instruments.length === 1"
  59. :key="item.id"
  60. >
  61. {{ item.instruments[0].name }}
  62. </div>
  63. <Popover v-model:value="item.isExpand" trigger="mouseenter" v-else :offset="-4" :key="item.id + '_'">
  64. <template #content>
  65. <PopoverMenuItem
  66. @click="
  67. () => {
  68. item.isExpand = false
  69. handleSubjectChange(row)
  70. }
  71. "
  72. v-for="row in item.instruments"
  73. :key="row.id"
  74. :active="row.id === queryData.subject.id"
  75. >{{ row.name }}</PopoverMenuItem
  76. >
  77. </template>
  78. <div class="queryTip" :class="{ hoverActive: isActiveSubjectPop(item) }">
  79. <div>{{ isActiveSubjectPop(item) ? queryData.subject.name : item.name }}</div>
  80. <img src="../../cloudCoachElement/cloudCoachList/imgs/jt.png" alt="" />
  81. </div>
  82. </Popover>
  83. </template>
  84. </div>
  85. </div>
  86. <div class="queryFromList">
  87. <div class="tit">标签:</div>
  88. <div class="queryFromCon">
  89. <div
  90. v-for="item in materialTagList"
  91. :key="item.id"
  92. @click="handleMaterialTagChange(item.id)"
  93. :class="['queryTip', queryData.materialTagId === item.id && 'active']"
  94. >
  95. {{ item.name }}
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. <!-- <div v-show="queryData.sourceType === 2" @click="isExpand = !isExpand" class="isExpand" :class="{ active: isExpand }">
  101. <div>{{ isExpand ? "收起" : "展开" }}</div>
  102. <img src="../../cloudCoachElement/cloudCoachList/imgs/jiao.png" alt="" />
  103. </div> -->
  104. <div class="musicListConBox" v-loading="loading">
  105. <div class="musicList" :class="{ empty: !musicList.length && !loading }">
  106. <div class="musicListBox" v-if="musicList.length && !loading">
  107. <div class="musicCon" v-for="item in musicList" :key="item.id">
  108. <div class="coverImgCon">
  109. <img v-if="item.sourceFrom === 'PLATFORM'" class="jxImg" src="./imgs/jxImg.png" alt="" />
  110. <div class="addBtn" @click="handleAddResources(item)">添加</div>
  111. <img class="coverImg" :src="item.coverImg" />
  112. </div>
  113. <div class="musicDetails">
  114. <div class="musLeft">
  115. <img class="labelImg" :src="item.type === 'IMG' ? imgImg : item.type === 'SONG' ? audioImg : videoImg" />
  116. <div class="musicTitCon">
  117. <EllipsisScroll class="musicTit" :title="item.highName || ''" />
  118. </div>
  119. </div>
  120. <div class="musRight">
  121. <img
  122. v-if="queryParams.fromType !== 'PLATFORM'"
  123. class="sc"
  124. @click="handleFavorite(item)"
  125. :src="item.favoriteFlag ? scActImg : scImg"
  126. alt=""
  127. />
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. <Empty v-if="!musicList.length && !loading" />
  133. </div>
  134. <div class="pagination" v-show="musicList.length">
  135. <el-pagination layout="prev, pager, next" :default-page-size="21" @current-change="handleCurrentChange" :total="queryData.total" />
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. </template>
  142. <script setup lang="ts">
  143. import { ElLoading, ElPagination } from "element-plus"
  144. import Input from "@/components/Input.vue"
  145. import Popover from "@/components/Popover.vue"
  146. import PopoverMenuItem from "@/components/PopoverMenuItem.vue"
  147. import Empty from "@/components/Empty"
  148. import EllipsisScroll from "@/components/ellipsisScroll"
  149. import { reactive, ref } from "vue"
  150. import { getMaterialQueryPage, getSubjectListApi, favoriteApi, getMaterialTagApi } from "@/api/pptOperate"
  151. import { httpAjax } from "@/plugins/httpAjax"
  152. import queryParams from "@/queryParams"
  153. import scActImg from "../../cloudCoachElement/cloudCoachList/imgs/scAct.png"
  154. import scImg from "../../cloudCoachElement/cloudCoachList/imgs/sc.png"
  155. import audioImg from "./imgs/audio.png"
  156. import imgImg from "./imgs/img.png"
  157. import videoImg from "./imgs/video.png"
  158. import { CODE_ERR_CANCELED } from "@/libs/auth"
  159. const emits = defineEmits<{
  160. (event: "update", item: Record<string, any>): void
  161. (event: "close"): void
  162. }>()
  163. function handleAddResources(item: Record<string, any>) {
  164. emits("update", item)
  165. }
  166. const tabData =
  167. queryParams.fromType === "PLATFORM"
  168. ? [
  169. {
  170. label: "共享资源",
  171. value: 2
  172. }
  173. ]
  174. : [
  175. {
  176. label: "相关资源",
  177. value: 5
  178. },
  179. {
  180. label: "共享资源",
  181. value: 2
  182. },
  183. {
  184. label: "我的资源",
  185. value: 3
  186. },
  187. {
  188. label: "我的收藏",
  189. value: 4
  190. }
  191. ]
  192. // 资源类型
  193. const resourcesTypeOption = [
  194. { text: "图片", value: "IMG" },
  195. { text: "音频", value: "SONG" },
  196. { text: "视频", value: "VIDEO" }
  197. ]
  198. // 标签
  199. const materialTagList = ref<any[]>([])
  200. // 乐器
  201. const subjectList = ref<any[]>([])
  202. const queryData = reactive({
  203. page: 1,
  204. rows: 21,
  205. total: 0,
  206. type: "SONG",
  207. materialTagId: "",
  208. sourceType: tabData[0].value,
  209. name: "",
  210. subject: {
  211. id: "",
  212. name: ""
  213. }
  214. })
  215. const musicList = ref<any[]>([])
  216. const loading = ref(true)
  217. const vLoading = ElLoading.directive
  218. const isExpand = ref(true)
  219. getQueryList()
  220. function getQueryList() {
  221. Promise.all([httpAjax(getSubjectListApi), httpAjax(getMaterialTagApi)]).then(res => {
  222. const [subjectListRes, materialTagRes] = res
  223. if (subjectListRes.code === 200) {
  224. subjectList.value = subjectListRes.data.map((item: any) => {
  225. return item.instruments.length > 1 ? Object.assign(item, { isExpand: ref(false) }) : item
  226. })
  227. // 赋默认值
  228. handleSubjectDefault()
  229. }
  230. if (materialTagRes.code === 200) {
  231. materialTagList.value = [{ id: "", name: "全部" }, ...(materialTagRes.data?.rows || [])]
  232. }
  233. handleQuery()
  234. })
  235. }
  236. function handleSubjectDefault() {
  237. if (subjectList.value.length > 0) {
  238. const instruments = subjectList.value.reduce((arr, item) => {
  239. arr.push(...item.instruments)
  240. return arr
  241. }, [])
  242. const instrumentId = queryParams.instrumentId
  243. // 有id 就用id,没有就默认第一个
  244. const instrumentObj = instrumentId
  245. ? instruments.find((i: any) => {
  246. return i.id === instrumentId
  247. })
  248. : instruments[0]
  249. if (instrumentObj) {
  250. queryData.subject.id = instrumentObj.id
  251. queryData.subject.name = instrumentObj.name
  252. }
  253. }
  254. }
  255. function clearQueryData() {
  256. queryData.page = 1
  257. queryData.rows = 21
  258. queryData.total = 0
  259. queryData.sourceType = 5
  260. queryData.name = ""
  261. queryData.type = "SONG"
  262. queryData.materialTagId = ""
  263. queryData.subject = {
  264. id: "",
  265. name: ""
  266. }
  267. handleSubjectDefault()
  268. }
  269. function handleTabChange(sourceType: number) {
  270. clearQueryData()
  271. isExpand.value = true
  272. queryData.sourceType = sourceType
  273. handleQuery()
  274. }
  275. function handleSubjectChange(item: any) {
  276. queryData.subject.id = item.id
  277. queryData.subject.name = item.name
  278. handleQuery()
  279. }
  280. function handleMaterialTagChange(id: string) {
  281. queryData.materialTagId = id
  282. handleQuery()
  283. }
  284. function handleTypeChange(type: string) {
  285. queryData.type = type
  286. handleQuery()
  287. }
  288. function isActiveSubjectPop(item: any) {
  289. return item.instruments.some((i: any) => {
  290. return i.id === queryData.subject.id
  291. })
  292. }
  293. function handleCurrentChange(e: number) {
  294. queryData.page = e
  295. handleGetQuery()
  296. }
  297. function handleQuery() {
  298. queryData.page = 1
  299. queryData.rows = 21
  300. handleGetQuery()
  301. }
  302. let controller: AbortController
  303. function handleGetQuery() {
  304. loading.value = true
  305. let { sourceType, subject, type, materialTagId, name, page, rows } = queryData
  306. let musicalInstrumentId = subject.id
  307. const params = {
  308. name,
  309. type,
  310. sourceType,
  311. musicalInstrumentId,
  312. enableFlag: true,
  313. page,
  314. rows,
  315. materialTagId,
  316. lessonCoursewareKnowledgeId: [2, 5].includes(sourceType) ? queryParams.lessonCoursewareKnowledgeId : "" // 相关资源和共享资源需要这个
  317. }
  318. if (controller) {
  319. controller.abort()
  320. }
  321. controller = new AbortController()
  322. httpAjax(getMaterialQueryPage, params, controller).then(res => {
  323. // 自己关闭的时候不取消加载
  324. if (res.code === CODE_ERR_CANCELED) {
  325. return
  326. }
  327. if (res.code === 200) {
  328. musicList.value = res.data.rows.map((item: any) => {
  329. item.highName = highlightedText(item.name, queryData.name)
  330. return item
  331. })
  332. queryData.total = res.data.total
  333. }
  334. loading.value = false
  335. })
  336. }
  337. function handleFavorite(item: any) {
  338. httpAjax(favoriteApi, {
  339. favoriteFlag: item.favoriteFlag ? 0 : 1,
  340. materialId: item.id,
  341. type: item.type
  342. }).then(res => {
  343. if (res.code === 200) {
  344. item.favoriteFlag = !item.favoriteFlag
  345. }
  346. })
  347. }
  348. const highlightedText = (text: string, query: string) => {
  349. if (!text) {
  350. return ""
  351. }
  352. if (!query) {
  353. return text
  354. }
  355. const regex = new RegExp(`(${query})`, "gi")
  356. return text.replace(regex, '<span class="highlighted">$1</span>')
  357. }
  358. </script>
  359. <style lang="scss" scoped>
  360. .resourcesList {
  361. width: 100%;
  362. height: 100%;
  363. .headCon {
  364. width: 100%;
  365. height: 64px;
  366. border-bottom: 1px solid #eaeaea;
  367. display: flex;
  368. justify-content: space-between;
  369. align-items: center;
  370. .headLeft {
  371. margin-left: 30px;
  372. display: flex;
  373. align-items: center;
  374. .tipImg {
  375. width: 24px;
  376. height: 24px;
  377. }
  378. .title {
  379. font-weight: 600;
  380. font-size: 18px;
  381. color: #131415;
  382. margin-left: 8px;
  383. }
  384. }
  385. .headright {
  386. margin-right: 30px;
  387. display: flex;
  388. align-items: center;
  389. .closeBtn {
  390. width: 24px;
  391. height: 24px;
  392. cursor: pointer;
  393. &:hover {
  394. opacity: 0.8;
  395. }
  396. }
  397. }
  398. }
  399. .content {
  400. width: 100%;
  401. height: calc(100% - 64px);
  402. display: flex;
  403. flex-direction: column;
  404. .tabTools {
  405. flex-shrink: 0;
  406. width: 100%;
  407. padding: 24px 30px;
  408. display: flex;
  409. justify-content: space-between;
  410. align-items: center;
  411. .tabCon {
  412. display: flex;
  413. .tab {
  414. margin-right: 32px;
  415. font-weight: 400;
  416. font-size: 16px;
  417. color: #8b8d98;
  418. line-height: 22px;
  419. cursor: pointer;
  420. &:hover {
  421. opacity: 0.8;
  422. }
  423. &:last-child {
  424. margin-right: 0;
  425. }
  426. &.active {
  427. font-weight: 600;
  428. color: #131415;
  429. position: relative;
  430. &::after {
  431. content: "";
  432. position: absolute;
  433. width: 100%;
  434. height: 10px;
  435. background: linear-gradient(90deg, #77bbff 0%, rgba(163, 231, 255, 0.22) 100%);
  436. bottom: 0;
  437. left: 0;
  438. z-index: -1;
  439. }
  440. }
  441. }
  442. }
  443. }
  444. .typeTools {
  445. flex-shrink: 0;
  446. display: flex;
  447. justify-content: space-between;
  448. align-items: center;
  449. margin: 0 30px;
  450. padding-bottom: 16px;
  451. border-bottom: 1px solid #eaeaea;
  452. .typeTabCon {
  453. display: flex;
  454. align-items: center;
  455. .queryTip {
  456. margin-right: 16px;
  457. font-weight: 400;
  458. font-size: 14px;
  459. color: rgba(0, 0, 0, 0.6);
  460. line-height: 20px;
  461. padding: 6px 20px;
  462. background: #f5f6fa;
  463. border-radius: 16px;
  464. cursor: pointer;
  465. &.active,
  466. &:hover {
  467. background: #d2ecff;
  468. color: rgba(0, 0, 0, 1);
  469. }
  470. }
  471. }
  472. .query {
  473. width: 400px;
  474. height: 36px;
  475. &::v-deep(.input) {
  476. align-items: center;
  477. padding: 0 3px 0 12px;
  478. border-radius: 18px;
  479. height: 100%;
  480. &:not(.disabled):hover,
  481. &.focused {
  482. .img {
  483. opacity: 1;
  484. }
  485. .queryBtn {
  486. opacity: 1;
  487. }
  488. }
  489. input {
  490. font-size: 14px;
  491. }
  492. .img {
  493. width: 16px;
  494. height: 16px;
  495. opacity: 0.4;
  496. }
  497. .queryBtn {
  498. width: 60px;
  499. height: 30px;
  500. background: #198cfe;
  501. border-radius: 16px;
  502. font-weight: 500;
  503. font-size: 14px;
  504. color: #ffffff;
  505. line-height: 30px;
  506. text-align: center;
  507. opacity: 0.4;
  508. cursor: pointer;
  509. &:hover {
  510. opacity: 0.8 !important;
  511. }
  512. }
  513. }
  514. }
  515. }
  516. .musicListCon {
  517. padding-top: 16px;
  518. width: 100%;
  519. flex-grow: 1;
  520. overflow: hidden;
  521. display: flex;
  522. flex-direction: column;
  523. .queryFrom {
  524. &.isExpandAct {
  525. height: 42px;
  526. overflow: hidden;
  527. }
  528. flex-shrink: 0;
  529. padding: 0 30px;
  530. .queryFromList {
  531. display: flex;
  532. margin-bottom: 4px;
  533. .tit {
  534. flex-shrink: 0;
  535. font-weight: 500;
  536. font-size: 14px;
  537. color: #131415;
  538. line-height: 32px;
  539. margin-right: 16px;
  540. }
  541. .queryFromCon {
  542. display: flex;
  543. flex-wrap: wrap;
  544. .queryTip {
  545. margin: 0 16px 12px 0;
  546. font-weight: 400;
  547. font-size: 14px;
  548. color: rgba(0, 0, 0, 0.6);
  549. line-height: 20px;
  550. padding: 6px 16px;
  551. background: #f5f6fa;
  552. border-radius: 6px;
  553. cursor: pointer;
  554. display: flex;
  555. align-items: center;
  556. & > img {
  557. width: 7px;
  558. height: 4px;
  559. margin-left: 6px;
  560. }
  561. &.active,
  562. &:hover {
  563. background: #d2ecff;
  564. color: rgba(0, 0, 0, 1);
  565. > img {
  566. transform: rotate(180deg);
  567. }
  568. }
  569. &.hoverActive {
  570. background: #d2ecff;
  571. color: rgba(0, 0, 0, 1);
  572. }
  573. }
  574. }
  575. }
  576. }
  577. .isExpand {
  578. flex-shrink: 0;
  579. margin-bottom: 12px;
  580. cursor: pointer;
  581. display: flex;
  582. justify-content: center;
  583. font-weight: 400;
  584. font-size: 14px;
  585. color: #198cfe;
  586. line-height: 20px;
  587. align-items: center;
  588. &:hover {
  589. opacity: 0.8;
  590. }
  591. &.active > img {
  592. transform: rotate(0deg);
  593. }
  594. & > img {
  595. transform: rotate(180deg);
  596. margin-left: 4px;
  597. width: 10px;
  598. height: 10px;
  599. }
  600. }
  601. .musicListConBox {
  602. flex-grow: 1;
  603. overflow: hidden;
  604. .musicList {
  605. padding: 4px 0;
  606. height: calc(100% - 60px);
  607. overflow: auto;
  608. &.empty {
  609. display: flex;
  610. justify-content: center;
  611. align-items: center;
  612. }
  613. .musicListBox {
  614. width: calc(100% + 24px);
  615. margin-left: -24px;
  616. display: flex;
  617. flex-wrap: wrap;
  618. padding: 0 30px;
  619. .musicCon {
  620. margin-bottom: 24px;
  621. width: calc(25% - 24px);
  622. margin-left: 24px;
  623. border-radius: 12px;
  624. background: linear-gradient(0, #dbf1ff 0%, #e7f9ff 100%);
  625. outline: 1.5px solid #d3eef1;
  626. height: 213px;
  627. display: flex;
  628. flex-direction: column;
  629. overflow: hidden;
  630. &:nth-last-child(-n + 3) {
  631. margin-bottom: 0;
  632. }
  633. &:hover {
  634. outline: 2px solid #198cfe;
  635. }
  636. .coverImgCon {
  637. flex-shrink: 0;
  638. width: 100%;
  639. height: 170px;
  640. position: relative;
  641. .coverImg {
  642. width: 100%;
  643. height: 100%;
  644. object-fit: cover;
  645. object-position: top;
  646. }
  647. .jxImg {
  648. position: absolute;
  649. left: 0;
  650. top: 0;
  651. width: 50px;
  652. height: 27px;
  653. }
  654. .addBtn {
  655. position: absolute;
  656. top: 8px;
  657. right: 12px;
  658. width: 54px;
  659. height: 26px;
  660. background: #198cfe;
  661. border-radius: 4px;
  662. font-weight: 600;
  663. font-size: 13px;
  664. color: #ffffff;
  665. line-height: 26px;
  666. text-align: center;
  667. cursor: pointer;
  668. &:hover {
  669. opacity: 0.8;
  670. }
  671. }
  672. }
  673. .musicDetails {
  674. flex-grow: 1;
  675. padding: 0 12px;
  676. display: flex;
  677. align-items: center;
  678. justify-content: space-between;
  679. .musLeft {
  680. display: flex;
  681. align-items: center;
  682. margin-right: 14px;
  683. overflow: hidden;
  684. .labelImg {
  685. flex-shrink: 0;
  686. width: 16px;
  687. height: 16px;
  688. }
  689. .musicTitCon {
  690. margin-left: 6px;
  691. overflow: hidden;
  692. .musicTit {
  693. font-weight: 600;
  694. font-size: 14px;
  695. color: #131415;
  696. line-height: 20px;
  697. &::v-deep(.highlighted) {
  698. color: $themeColor;
  699. }
  700. }
  701. }
  702. }
  703. .musRight {
  704. flex-shrink: 0;
  705. .sc {
  706. width: 26px;
  707. height: 26px;
  708. cursor: pointer;
  709. &:hover {
  710. opacity: 0.8;
  711. }
  712. }
  713. }
  714. }
  715. }
  716. }
  717. }
  718. .pagination {
  719. padding: 0 30px;
  720. display: flex;
  721. justify-content: flex-end;
  722. align-items: center;
  723. height: 60px;
  724. }
  725. }
  726. }
  727. }
  728. }
  729. </style>