sdk-tour-play.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. <style>
  8. [v-cloak] {
  9. display: none;
  10. }
  11. ul,
  12. li {
  13. padding: 0;
  14. margin: 0;
  15. list-style: none;
  16. }
  17. html,
  18. body {
  19. width: 100%;
  20. height: 100%;
  21. margin: 0;
  22. overflow: hidden;
  23. }
  24. .scene {
  25. width: 100%;
  26. height: 100%;
  27. }
  28. #app {
  29. position: absolute;
  30. pointer-events: none;
  31. left: 0;
  32. top: 0;
  33. width: 100%;
  34. height: 100%;
  35. z-index: 100;
  36. }
  37. .progress {
  38. display: none;
  39. position: absolute;
  40. left: 0;
  41. bottom: 0;
  42. width: 100%;
  43. height: 4px;
  44. }
  45. .progress div {
  46. height: 100%;
  47. width: 0;
  48. background-color: #f60;
  49. }
  50. #parts ul,
  51. #frames ul {
  52. display: flex;
  53. }
  54. #parts li {
  55. position: relative;
  56. color: #fff;
  57. padding: 5px;
  58. margin-right: 10px;
  59. cursor: pointer;
  60. }
  61. #parts li:hover,
  62. #parts li.active {
  63. color: #f60;
  64. }
  65. #parts li.active .progress {
  66. display: block;
  67. }
  68. #frames li {
  69. position: relative;
  70. margin-left: 5px;
  71. border: solid 1px transparent;
  72. cursor: pointer;
  73. }
  74. #frames li span {
  75. display: none;
  76. position: absolute;
  77. right: 0px;
  78. top: 0px;
  79. width: 16px;
  80. height: 16px;
  81. background-color: #fff;
  82. text-align: center;
  83. }
  84. #frames li.active {
  85. border: solid 1px #f60;
  86. }
  87. #frames li.active .progress {
  88. display: block;
  89. }
  90. .toolbar {
  91. pointer-events: all;
  92. position: absolute;
  93. left: 50%;
  94. top: 0;
  95. transform: translateX(-50%);
  96. }
  97. .bottom {
  98. pointer-events: all;
  99. position: absolute;
  100. left: 0;
  101. bottom: 0;
  102. width: 100%;
  103. height: 200px;
  104. background-color: rgba(0, 0, 0, 0.5);
  105. }
  106. .bottom.disable {
  107. pointer-events: none;
  108. opacity: 0.5;
  109. }
  110. [xui_tags_view] .tag-body {
  111. max-width: 300px;
  112. position: absolute;
  113. left: 50%;
  114. bottom: 50px;
  115. transform: translateX(-50%) scale(0);
  116. transform-origin: bottom;
  117. transition: all 0.3s cubic-bezier(0.35, 0.32, 0.65, 0.63);
  118. }
  119. [xui_tags_view] .tag-body.show {
  120. transform: translateX(-50%) scale(1);
  121. }
  122. [xui_tags_view] .tag-body .tag-image {
  123. min-width: 230px;
  124. height: 76px;
  125. background: hsla(0, 0%, 100%, 0.8);
  126. box-shadow: 0 3px 6px 0 rgb(0 0 0 / 16%);
  127. border-radius: 2px;
  128. position: relative;
  129. margin-bottom: 30px;
  130. }
  131. [xui_tags_view] .tag-body .tag-image::before {
  132. content: '';
  133. display: inline-block;
  134. left: 50%;
  135. transform: translateX(-50%);
  136. width: 2px;
  137. height: 28px;
  138. bottom: -30px;
  139. background: linear-gradient(145deg, hsla(0, 0%, 100%, 0.8), hsla(0, 0%, 100%, 0));
  140. position: absolute;
  141. }
  142. [xui_tags_view] .tag-body .tag-image .tag-avatar {
  143. position: absolute;
  144. z-index: 99;
  145. width: 80px;
  146. height: 80px;
  147. background: #fff;
  148. box-shadow: 0 3px 6px 0 rgb(0 0 0 / 16%);
  149. border-radius: 2px;
  150. top: -14px;
  151. left: -12px;
  152. background-size: cover;
  153. pointer-events: none;
  154. }
  155. [xui_tags_view] .tag-body .tag-image .tag-title {
  156. padding: 10px 10px 10px 76px;
  157. overflow: hidden;
  158. text-overflow: ellipsis;
  159. white-space: nowrap;
  160. width: 240px;
  161. }
  162. [xui_tags_view] .tag-body .tag-image .tag-info {
  163. padding: 0 20px 0 76px;
  164. font-size: 12px;
  165. overflow: hidden;
  166. text-overflow: ellipsis;
  167. white-space: nowrap;
  168. }
  169. </style>
  170. </head>
  171. <body>
  172. <div id="scene" class="scene"></div>
  173. <div id="app" v-cloak>
  174. <div class="toolbar">
  175. <button @click="play">{{ playing?'暂停':'播放' }}</button>
  176. </div>
  177. <div class="bottom" :class="{disable:disable}">
  178. <div id="parts">
  179. <ul>
  180. <li v-for="(part,index) in tours" :class="{active:index == partId}" @click="selectPart(index)">
  181. {{part.name || '片段_'+index}}
  182. <div class="progress"><div :style="{width:progressPart+'%'}"></div></div>
  183. </li>
  184. </ul>
  185. </div>
  186. <div id="frames" :partid="partId" :frameid="frameId">
  187. <div v-for="(part,index) in tours" v-show="partId == index" :length="part.list.length">
  188. <ul>
  189. <li v-for="(frame,index) in part.list" :class="{active:index == frameId}" @click="selectFrame(index)">
  190. <img style="width: 200px; height: 140px" :src="frame.enter.cover" />
  191. <div class="progress"><div :style="{width:progress+'%'}"></div></div>
  192. </li>
  193. </ul>
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. <script src="../dist/sdk/kankan-sdk-deps.js"></script>
  199. <script src="../dist/sdk/kankan-sdk.js"></script>
  200. <script src="./js/vue.min.js"></script>
  201. <script>
  202. var app = null
  203. new Vue({
  204. el: '#app',
  205. data() {
  206. return {
  207. tours: [],
  208. partId: 0,
  209. frameId: 0,
  210. progress: 0,
  211. progressPart: 0,
  212. disable: false,
  213. playing: false,
  214. }
  215. },
  216. mounted() {
  217. app = new KanKan({
  218. dom: '#scene',
  219. num: 't-JKNqv1o',
  220. })
  221. app.use('TagView', {
  222. render(data) {
  223. return `
  224. <span class="tag-icon animate" style="background-image:url(${data.icon})"></span>
  225. <div class="tag-body">
  226. <div class="tag-image">
  227. <div class="tag-avatar"></div>
  228. <div class="tag-title">${data.title}</div>
  229. <div class="tag-info">${data.content}</div>
  230. </div>
  231. </div>
  232. `
  233. },
  234. }).then(view => {
  235. view.on('rendered', () => {
  236. view.on('click', e => {
  237. var tag = e.data
  238. // 聚焦当前点击的热点
  239. view.focus(tag.sid)
  240. })
  241. view.on('focus', e => {
  242. document.querySelectorAll('[xui_tags_view] >div').forEach(el => {
  243. el.querySelector('.tag-body').classList.remove('show')
  244. })
  245. e.target.querySelector('.tag-body').classList.add('show')
  246. })
  247. })
  248. })
  249. app.use('TourPlayer').then(player => {
  250. player.on('play', ({ partId, frameId }) => (this.playing = true))
  251. player.on('pause', ({ partId, frameId }) => (this.playing = false))
  252. player.on('end', () => {
  253. this.playing = false
  254. // 兼容最后一个画面没有进度的问题
  255. this.progressPart = 100
  256. })
  257. var currPartId
  258. var currFrames
  259. var currProgress
  260. player.on('progress', ({ partId, frameId, progress }) => {
  261. // 画面进度
  262. this.partId = partId
  263. this.frameId = frameId
  264. this.progress = Number(progress * 100).toFixed(5)
  265. // 片段进度
  266. if (this.tours.length == 1) {
  267. this.progressPart = this.progress
  268. } else {
  269. if (currPartId != partId) {
  270. currPartId = partId
  271. currFrames = this.tours[partId].list.length
  272. this.progressPart = 0
  273. }
  274. this.progressPart += progress / currFrames
  275. }
  276. })
  277. })
  278. // 需要双向绑定时,重新设置数据
  279. app.TourManager.on('loaded', tours => {
  280. this.tours = tours
  281. app.TourManager.load(this.tours)
  282. })
  283. app.render()
  284. },
  285. methods: {
  286. async selectPart(partId) {
  287. if (this.disable) {
  288. return
  289. }
  290. this.partId = partId
  291. this.frameId = 0
  292. this.disable = true
  293. this.progress = 0
  294. this.progressPart = 0
  295. var player = await app.TourManager.player
  296. await player.selectPart(partId)
  297. this.disable = false
  298. },
  299. async selectFrame(frameId) {
  300. if (this.disable) {
  301. return
  302. }
  303. this.frameId = frameId
  304. this.disable = true
  305. this.progress = 0
  306. this.progressPart = 0
  307. var player = await app.TourManager.player
  308. await player.selectFrame(frameId)
  309. this.disable = false
  310. },
  311. async play() {
  312. var player = await app.TourManager.player
  313. this.progress = 0
  314. if (this.playing) {
  315. player.pause()
  316. } else {
  317. player.play()
  318. }
  319. },
  320. },
  321. })
  322. </script>
  323. </body>
  324. </html>