|
@@ -1,10 +1,12 @@
|
|
|
-import { defineComponent } from 'vue'
|
|
|
+import { defineComponent, ref } from 'vue'
|
|
|
import { Button, Icon, Image, Tag } from 'vant'
|
|
|
import classNames from 'classnames'
|
|
|
import MusicIcon from './icons/music-icon.png'
|
|
|
import InitUserIcon from './icons/init-user-icon.png'
|
|
|
import FavoriteIcon from '../album/favorite.svg'
|
|
|
+import FavoritedIcon from '../album/favorited.svg'
|
|
|
import styles from './item.module.less'
|
|
|
+import request from '@/helpers/request'
|
|
|
|
|
|
const chargeTypes = {
|
|
|
CHARGE: '点播',
|
|
@@ -21,6 +23,21 @@ export default defineComponent({
|
|
|
}
|
|
|
},
|
|
|
setup({ data }) {
|
|
|
+ const favorite = ref(data.favorite)
|
|
|
+ const favoriteLoading = ref(false)
|
|
|
+
|
|
|
+ const toggleFavorite = async () => {
|
|
|
+ favoriteLoading.value = true
|
|
|
+ try {
|
|
|
+ await request.post('/api-student/music/sheet/favorite', {
|
|
|
+ params: {
|
|
|
+ id: data.id
|
|
|
+ }
|
|
|
+ })
|
|
|
+ favorite.value = !favorite.value
|
|
|
+ } catch (error) {}
|
|
|
+ favoriteLoading.value = false
|
|
|
+ }
|
|
|
return () => (
|
|
|
<div class={styles.item}>
|
|
|
<header class={styles.header}>
|
|
@@ -58,7 +75,16 @@ export default defineComponent({
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class={styles.icons}>
|
|
|
- <Icon class={styles.favorite} name={FavoriteIcon} />
|
|
|
+ <Button
|
|
|
+ style={{ border: 'none' }}
|
|
|
+ onClick={toggleFavorite}
|
|
|
+ loading={favoriteLoading.value}
|
|
|
+ >
|
|
|
+ <Icon
|
|
|
+ class={styles.favorite}
|
|
|
+ name={favorite.value ? FavoritedIcon : FavoriteIcon}
|
|
|
+ />
|
|
|
+ </Button>
|
|
|
</div>
|
|
|
</footer>
|
|
|
</div>
|