No Description

CourseMat.vue 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <ion-card >
  3. <ion-img :router-link="'/tabs/mat_detail/'+obj.id" alt="Silhouette of mountains" :src="thmb" v-if="thmb" class="img_16_9"/>
  4. <ion-card-header :router-link="'/tabs/mat_detail/'+obj.id">
  5. <ion-card-title>{{ name }}</ion-card-title>
  6. </ion-card-header>
  7. <ion-card-content class='ion-text-wrap ion-no-padding ion-padding-horizontal' :router-link="'/tabs/mat_detail/'+obj.id">
  8. {{ dt }}
  9. </ion-card-content>
  10. <ion-button fill="clear" @click="likeMatClick"><ion-icon :icon="heart" :color="isLike ? 'danger' : 'medium' "></ion-icon>
  11. <template v-if="obj.total_likes > 0">
  12. &nbsp;&nbsp;
  13. {{ Humanize.compactInteger(obj.total_likes, 1) }} {{ pluralize('Like', obj.total_likes) }}
  14. </template>
  15. </ion-button>
  16. </ion-card>
  17. </template>
  18. <script setup lang="ts">
  19. import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonIcon, onIonViewWillEnter, IonCard, IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent, IonImg, IonButton } from '@ionic/vue';
  20. import moment from 'moment'
  21. import { getTrainers, listCourses, isLogin, getPref, likeMat } from '@/composable/settings';
  22. import { ref, onMounted } from 'vue'
  23. import { heart } from 'ionicons/icons';
  24. import pluralize from 'pluralize';
  25. import Humanize from 'humanize-plus/dist/humanize';
  26. const props = defineProps({
  27. obj: Object,
  28. courseName: String,
  29. })
  30. const dt = ref()
  31. const thmb = ref()
  32. const name = ref()
  33. let pref = null
  34. const isLike = ref(false)
  35. onMounted(async() => {
  36. console.log("--- onmounted ---")
  37. console.log("name === ", props.obj)
  38. const obj = props.obj
  39. if(await isLogin()) {
  40. pref = await getPref()
  41. console.debug(" pref = ", pref)
  42. for(const m of pref.mat_likes) {
  43. if(obj.id == m.id) {
  44. isLike.value = true
  45. break
  46. }
  47. }
  48. }
  49. let temp = obj.display_datetime || obj.vimeo_created || obj.created_at
  50. dt.value = moment(temp).format('LLL');
  51. if( obj.gifs && obj.gifs.length > 0 ) {
  52. console.log(obj.gifs)
  53. if(obj.gifs[0].sizes.length > 2 ) {
  54. thmb.value = obj.gifs[0].sizes[2].link
  55. }else {
  56. thmb.value = obj.gifs[0].sizes[0].link
  57. }
  58. }else {
  59. thmb.value = obj.course_image
  60. }
  61. name.value = obj.vimeo_name || props.courseName
  62. })
  63. const likeMatClick = async() => {
  64. console.debug(props.obj)
  65. pref = await likeMat(props.obj.id)
  66. console.debug(pref)
  67. isLike.value = false
  68. for(const m of pref.mat_likes) {
  69. if(props.obj.id == m.id) {
  70. isLike.value = true
  71. props.obj.total_likes += 1
  72. break
  73. }
  74. }
  75. if(isLike.value == false) {
  76. props.obj.total_likes -= 1
  77. }
  78. }
  79. </script>
  80. <style scoped>
  81. #container {
  82. background-color:#f00;
  83. }
  84. ion-card-title {
  85. font-size:1.5em;
  86. }
  87. .img_16_9 {
  88. width:480px;
  89. height:270px;
  90. object-fit:cover;
  91. }
  92. </style>