StoryTimelineComponent.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div>
  3. <div v-if="stories.length != 0">
  4. <div id="storyContainer" class="m-3"></div>
  5. </div>
  6. </div>
  7. </template>
  8. <style type="text/css" scoped>
  9. #storyContainer > .story {
  10. margin-right: 3rem;
  11. }
  12. </style>
  13. <script type="text/javascript">
  14. import 'zuck.js/dist/zuck.css';
  15. import 'zuck.js/dist/skins/snapgram.css';
  16. let Zuck = require('zuck.js');
  17. export default {
  18. data() {
  19. return {
  20. stories: {},
  21. }
  22. },
  23. mounted() {
  24. this.fetchStories();
  25. },
  26. methods: {
  27. fetchStories() {
  28. axios.get('/api/stories/v1/recent')
  29. .then(res => {
  30. let data = res.data;
  31. let stories = new Zuck('storyContainer', {
  32. stories: data,
  33. localStorage: true,
  34. callbacks: {
  35. onOpen (storyId, callback) {
  36. document.body.style.overflow = "hidden";
  37. callback()
  38. },
  39. onEnd (storyId, callback) {
  40. axios.post('/i/stories/viewed', {
  41. id: storyId
  42. });
  43. callback();
  44. },
  45. onClose (storyId, callback) {
  46. document.body.style.overflow = "auto";
  47. callback();
  48. },
  49. }
  50. });
  51. data.forEach(d => {
  52. let url = '/api/stories/v1/fetch/' + d.pid;
  53. axios.get(url)
  54. .then(res => {
  55. res.data.forEach(item => {
  56. let img = new Image();
  57. img.src = item.src;
  58. stories.addItem(d.id, item);
  59. });
  60. });
  61. });
  62. });
  63. }
  64. }
  65. }
  66. </script>
  67. <style type="text/css">
  68. #storyContainer .story {
  69. margin-right: 2rem;
  70. width: 100%;
  71. max-width: 64px;
  72. }
  73. .stories.carousel .story > .item-link > .item-preview {
  74. height: 64px;
  75. }
  76. #zuck-modal.with-effects {
  77. width: 100%;
  78. }
  79. .stories.carousel .story > .item-link > .info .name {
  80. font-weight: 600;
  81. font-size: 12px;
  82. }
  83. .stories.carousel .story > .item-link > .info {
  84. }
  85. </style>