resourcesList.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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 tabQueryTip', 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="20" @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: 20,
  205. total: 0,
  206. type: "IMG",
  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 = 20
  258. queryData.total = 0
  259. queryData.sourceType = 5
  260. queryData.name = ""
  261. queryData.materialTagId = ""
  262. queryData.subject = {
  263. id: "",
  264. name: ""
  265. }
  266. handleSubjectDefault()
  267. }
  268. function handleTabChange(sourceType: number) {
  269. clearQueryData()
  270. isExpand.value = true
  271. queryData.sourceType = sourceType
  272. handleQuery()
  273. }
  274. function handleSubjectChange(item: any) {
  275. queryData.subject.id = item.id
  276. queryData.subject.name = item.name
  277. handleQuery()
  278. }
  279. function handleMaterialTagChange(id: string) {
  280. queryData.materialTagId = id
  281. handleQuery()
  282. }
  283. function handleTypeChange(type: string) {
  284. queryData.type = type
  285. handleQuery()
  286. }
  287. function isActiveSubjectPop(item: any) {
  288. return item.instruments.some((i: any) => {
  289. return i.id === queryData.subject.id
  290. })
  291. }
  292. function handleCurrentChange(e: number) {
  293. queryData.page = e
  294. handleGetQuery()
  295. }
  296. function handleQuery() {
  297. queryData.page = 1
  298. queryData.rows = 20
  299. handleGetQuery()
  300. }
  301. let controller: AbortController
  302. function handleGetQuery() {
  303. loading.value = true
  304. let { sourceType, subject, type, materialTagId, name, page, rows } = queryData
  305. let musicalInstrumentId = subject.id
  306. const params = {
  307. name,
  308. type,
  309. sourceType,
  310. musicalInstrumentId,
  311. enableFlag: true,
  312. page,
  313. rows,
  314. materialTagId,
  315. lessonCoursewareKnowledgeId: [2, 5].includes(sourceType) ? queryParams.lessonCoursewareKnowledgeId : "" // 相关资源和共享资源需要这个
  316. }
  317. if (controller) {
  318. controller.abort()
  319. }
  320. controller = new AbortController()
  321. httpAjax(getMaterialQueryPage, params, controller).then(res => {
  322. // 自己关闭的时候不取消加载
  323. if (res.code === CODE_ERR_CANCELED) {
  324. return
  325. }
  326. if (res.code === 200) {
  327. musicList.value = res.data.rows.map((item: any) => {
  328. item.highName = highlightedText(item.name, queryData.name)
  329. return item
  330. })
  331. queryData.total = res.data.total
  332. }
  333. loading.value = false
  334. })
  335. }
  336. function handleFavorite(item: any) {
  337. httpAjax(favoriteApi, {
  338. favoriteFlag: item.favoriteFlag ? 0 : 1,
  339. materialId: item.id,
  340. type: item.type
  341. }).then(res => {
  342. if (res.code === 200) {
  343. item.favoriteFlag = !item.favoriteFlag
  344. }
  345. })
  346. }
  347. const highlightedText = (text: string, query: string) => {
  348. if (!text) {
  349. return ""
  350. }
  351. if (!query) {
  352. return text
  353. }
  354. const regex = new RegExp(`(${query})`, "gi")
  355. return text.replace(regex, '<span class="highlighted">$1</span>')
  356. }
  357. </script>
  358. <style lang="scss" scoped>
  359. .resourcesList {
  360. width: 100%;
  361. height: 100%;
  362. .headCon {
  363. width: 100%;
  364. height: 64px;
  365. border-bottom: 1px solid #eaeaea;
  366. display: flex;
  367. justify-content: space-between;
  368. align-items: center;
  369. .headLeft {
  370. margin-left: 30px;
  371. display: flex;
  372. align-items: center;
  373. .tipImg {
  374. width: 24px;
  375. height: 24px;
  376. }
  377. .title {
  378. font-weight: 600;
  379. font-size: 18px;
  380. color: #131415;
  381. margin-left: 8px;
  382. }
  383. }
  384. .headright {
  385. margin-right: 30px;
  386. display: flex;
  387. align-items: center;
  388. .closeBtn {
  389. width: 24px;
  390. height: 24px;
  391. cursor: pointer;
  392. &:hover {
  393. opacity: 0.8;
  394. }
  395. }
  396. }
  397. }
  398. .content {
  399. width: 100%;
  400. height: calc(100% - 64px);
  401. display: flex;
  402. flex-direction: column;
  403. .tabTools {
  404. flex-shrink: 0;
  405. width: 100%;
  406. padding: 24px 30px;
  407. display: flex;
  408. justify-content: space-between;
  409. align-items: center;
  410. .tabCon {
  411. display: flex;
  412. .tab {
  413. margin-right: 32px;
  414. font-weight: 400;
  415. font-size: 16px;
  416. color: #8b8d98;
  417. line-height: 22px;
  418. cursor: pointer;
  419. &:hover {
  420. opacity: 0.8;
  421. }
  422. &:last-child {
  423. margin-right: 0;
  424. }
  425. &.active {
  426. font-weight: 600;
  427. color: #131415;
  428. position: relative;
  429. &::after {
  430. content: "";
  431. position: absolute;
  432. width: 100%;
  433. height: 10px;
  434. background: linear-gradient(90deg, #77bbff 0%, rgba(163, 231, 255, 0.22) 100%);
  435. bottom: 0;
  436. left: 0;
  437. z-index: -1;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. .typeTools {
  444. flex-shrink: 0;
  445. display: flex;
  446. justify-content: space-between;
  447. align-items: center;
  448. margin: 0 30px;
  449. padding-bottom: 16px;
  450. border-bottom: 1px solid #eaeaea;
  451. .typeTabCon {
  452. display: flex;
  453. align-items: center;
  454. .queryTip {
  455. margin-right: 16px;
  456. font-weight: 400;
  457. font-size: 14px;
  458. color: rgba(0, 0, 0, 0.6);
  459. line-height: 20px;
  460. padding: 6px 20px;
  461. background: #f5f6fa;
  462. border-radius: 16px;
  463. cursor: pointer;
  464. &.active,
  465. &:hover {
  466. background: #d2ecff;
  467. color: rgba(0, 0, 0, 1);
  468. }
  469. &.tabQueryTip {
  470. &:hover {
  471. background: #e8e9ed;
  472. color: #5d5d5e;
  473. }
  474. &.active {
  475. background: #198cfe;
  476. color: #ffffff;
  477. }
  478. }
  479. }
  480. }
  481. .query {
  482. width: 400px;
  483. height: 36px;
  484. &::v-deep(.input) {
  485. align-items: center;
  486. padding: 0 3px 0 12px;
  487. border-radius: 18px;
  488. height: 100%;
  489. &:not(.disabled):hover,
  490. &.focused {
  491. .img {
  492. opacity: 1;
  493. }
  494. .queryBtn {
  495. opacity: 1;
  496. }
  497. }
  498. input {
  499. font-size: 14px;
  500. }
  501. .img {
  502. width: 16px;
  503. height: 16px;
  504. opacity: 0.4;
  505. }
  506. .queryBtn {
  507. width: 60px;
  508. height: 30px;
  509. background: #198cfe;
  510. border-radius: 16px;
  511. font-weight: 500;
  512. font-size: 14px;
  513. color: #ffffff;
  514. line-height: 30px;
  515. text-align: center;
  516. opacity: 0.4;
  517. cursor: pointer;
  518. &:hover {
  519. opacity: 0.8 !important;
  520. }
  521. }
  522. }
  523. }
  524. }
  525. .musicListCon {
  526. padding-top: 16px;
  527. width: 100%;
  528. flex-grow: 1;
  529. overflow: hidden;
  530. display: flex;
  531. flex-direction: column;
  532. .queryFrom {
  533. &.isExpandAct {
  534. height: 42px;
  535. overflow: hidden;
  536. }
  537. flex-shrink: 0;
  538. padding: 0 30px;
  539. .queryFromList {
  540. display: flex;
  541. margin-bottom: 4px;
  542. .tit {
  543. flex-shrink: 0;
  544. font-weight: 500;
  545. font-size: 14px;
  546. color: #131415;
  547. line-height: 32px;
  548. margin-right: 16px;
  549. }
  550. .queryFromCon {
  551. display: flex;
  552. flex-wrap: wrap;
  553. .queryTip {
  554. margin: 0 16px 12px 0;
  555. font-weight: 400;
  556. font-size: 14px;
  557. color: rgba(0, 0, 0, 0.6);
  558. line-height: 20px;
  559. padding: 6px 16px;
  560. background: #f5f6fa;
  561. border-radius: 6px;
  562. cursor: pointer;
  563. display: flex;
  564. align-items: center;
  565. & > img {
  566. width: 7px;
  567. height: 4px;
  568. margin-left: 6px;
  569. }
  570. &.active,
  571. &:hover {
  572. background: #d2ecff;
  573. color: rgba(0, 0, 0, 1);
  574. > img {
  575. transform: rotate(180deg);
  576. }
  577. }
  578. &.hoverActive {
  579. background: #d2ecff;
  580. color: rgba(0, 0, 0, 1);
  581. }
  582. }
  583. }
  584. }
  585. }
  586. .isExpand {
  587. flex-shrink: 0;
  588. margin-bottom: 12px;
  589. cursor: pointer;
  590. display: flex;
  591. justify-content: center;
  592. font-weight: 400;
  593. font-size: 14px;
  594. color: #198cfe;
  595. line-height: 20px;
  596. align-items: center;
  597. &:hover {
  598. opacity: 0.8;
  599. }
  600. &.active > img {
  601. transform: rotate(0deg);
  602. }
  603. & > img {
  604. transform: rotate(180deg);
  605. margin-left: 4px;
  606. width: 10px;
  607. height: 10px;
  608. }
  609. }
  610. .musicListConBox {
  611. flex-grow: 1;
  612. overflow: hidden;
  613. .musicList {
  614. padding: 4px 0;
  615. height: calc(100% - 60px);
  616. overflow: auto;
  617. &.empty {
  618. display: flex;
  619. justify-content: center;
  620. align-items: center;
  621. }
  622. .musicListBox {
  623. width: calc(100% + 24px);
  624. margin-left: -24px;
  625. display: flex;
  626. flex-wrap: wrap;
  627. padding: 0 30px;
  628. .musicCon {
  629. margin-bottom: 24px;
  630. width: calc(25% - 24px);
  631. margin-left: 24px;
  632. border-radius: 12px;
  633. background: linear-gradient(0, #dbf1ff 0%, #e7f9ff 100%);
  634. outline: 1.5px solid #d3eef1;
  635. height: 213px;
  636. display: flex;
  637. flex-direction: column;
  638. overflow: hidden;
  639. &:nth-last-child(-n + 3) {
  640. margin-bottom: 0;
  641. }
  642. &:hover {
  643. outline: 2px solid #198cfe;
  644. }
  645. .coverImgCon {
  646. flex-shrink: 0;
  647. width: 100%;
  648. height: 170px;
  649. position: relative;
  650. .coverImg {
  651. width: 100%;
  652. height: 100%;
  653. object-fit: cover;
  654. object-position: top;
  655. }
  656. .jxImg {
  657. position: absolute;
  658. left: 0px;
  659. top: 0px;
  660. width: 50px;
  661. height: 27px;
  662. }
  663. .addBtn {
  664. position: absolute;
  665. top: 8px;
  666. right: 12px;
  667. width: 54px;
  668. height: 26px;
  669. background: #198cfe;
  670. border-radius: 4px;
  671. font-weight: 600;
  672. font-size: 13px;
  673. color: #ffffff;
  674. line-height: 26px;
  675. text-align: center;
  676. cursor: pointer;
  677. &:hover {
  678. opacity: 0.8;
  679. }
  680. }
  681. }
  682. .musicDetails {
  683. flex-grow: 1;
  684. padding: 0 12px;
  685. display: flex;
  686. align-items: center;
  687. justify-content: space-between;
  688. .musLeft {
  689. display: flex;
  690. align-items: center;
  691. margin-right: 14px;
  692. overflow: hidden;
  693. .labelImg {
  694. flex-shrink: 0;
  695. width: 16px;
  696. height: 16px;
  697. }
  698. .musicTitCon {
  699. margin-left: 6px;
  700. overflow: hidden;
  701. .musicTit {
  702. font-weight: 600;
  703. font-size: 14px;
  704. color: #131415;
  705. line-height: 20px;
  706. &::v-deep(.highlighted) {
  707. color: $themeColor;
  708. }
  709. }
  710. }
  711. }
  712. .musRight {
  713. flex-shrink: 0;
  714. .sc {
  715. width: 26px;
  716. height: 26px;
  717. cursor: pointer;
  718. &:hover {
  719. opacity: 0.8;
  720. }
  721. }
  722. }
  723. }
  724. }
  725. }
  726. }
  727. .pagination {
  728. padding: 0 30px;
  729. display: flex;
  730. justify-content: flex-end;
  731. align-items: center;
  732. height: 60px;
  733. }
  734. }
  735. }
  736. }
  737. }
  738. </style>