StoryViewer.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="container">
  3. <div v-if="loading" class="row">
  4. <div class="col-12 mt-5 pt-5">
  5. <div class="text-center">
  6. <div class="spinner-border" role="status">
  7. <span class="sr-only">Loading...</span>
  8. </div>
  9. </div>
  10. </div>
  11. </div>
  12. <div v-if="stories.length != 0">
  13. <div id="storyContainer" class="d-none m-3"></div>
  14. </div>
  15. </div>
  16. </template>
  17. <style type="text/css" scoped>
  18. #storyContainer > .story {
  19. margin-right: 3rem;
  20. }
  21. </style>
  22. <script type="text/javascript">
  23. import 'zuck.js/dist/zuck.css';
  24. import 'zuck.js/dist/skins/snapgram.css';
  25. window.Zuck = require('zuck.js');
  26. export default {
  27. props: ['pid'],
  28. data() {
  29. return {
  30. loading: true,
  31. stories: {},
  32. }
  33. },
  34. beforeMount() {
  35. this.fetchStories();
  36. },
  37. methods: {
  38. fetchStories() {
  39. axios.get('/api/stories/v1/profile/' + this.pid)
  40. .then(res => {
  41. let data = res.data;
  42. if(data.length == 0) {
  43. window.location.href = '/';
  44. return;
  45. }
  46. window._storyData = data;
  47. window.stories = new Zuck('storyContainer', {
  48. stories: data,
  49. localStorage: true,
  50. callbacks: {
  51. onOpen (storyId, callback) {
  52. document.body.style.overflow = "hidden";
  53. callback()
  54. },
  55. onEnd (storyId, callback) {
  56. axios.post('/i/stories/viewed', {
  57. id: storyId
  58. });
  59. callback();
  60. },
  61. onClose (storyId, callback) {
  62. document.body.style.overflow = "auto";
  63. callback();
  64. window.location.href = '/';
  65. },
  66. }
  67. });
  68. this.loading = false;
  69. document.querySelectorAll('#storyContainer .story')[0].click()
  70. })
  71. .catch(err => {
  72. window.location.href = '/';
  73. return;
  74. });
  75. }
  76. }
  77. }
  78. </script>
  79. <style type="text/css">
  80. #storyContainer .story {
  81. margin-right: 2rem;
  82. width: 100%;
  83. max-width: 64px;
  84. }
  85. .stories.carousel .story > .item-link > .item-preview {
  86. height: 64px;
  87. }
  88. #zuck-modal.with-effects {
  89. width: 100%;
  90. }
  91. .stories.carousel .story > .item-link > .info .name {
  92. font-weight: 600;
  93. font-size: 12px;
  94. }
  95. .stories.carousel .story > .item-link > .info {
  96. }
  97. </style>