Danmaku.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div class="danmaku-area">
  3. <div
  4. class="danmaku-container"
  5. v-chat-scroll
  6. :style="{ visibility: isShowList ? 'visible' : 'hidden' }"
  7. >
  8. <!-- <ul class=""> -->
  9. <transition-group appear tag="ul" class="danmaku-list" name="dm">
  10. <li
  11. class="danmaku-list-item"
  12. v-for="(item, key) in showDanmakuData"
  13. :key="key"
  14. >
  15. <span> {{ item }}</span>
  16. </li>
  17. </transition-group>
  18. </div>
  19. <div class="input-container" v-if="!isMobile">
  20. <img class="arrow-icon" :src="arrowIcon || ''" />
  21. <span class="send-choices" @click.stop="toggleSelectMenu"
  22. >请选择弹幕内发送吧~</span
  23. >
  24. <div class="send-btn-container">
  25. <img
  26. @click="hideList"
  27. class="show-icon"
  28. :src="showIcon || ''"
  29. v-if="isShowList"
  30. />
  31. <img
  32. @click="showList"
  33. class="close-icon"
  34. :src="closeIcon || ''"
  35. v-if="!isShowList"
  36. />
  37. <!-- <button class="send-btn">发送</button> -->
  38. </div>
  39. <ul class="show-list" v-show="isShowSelectList">
  40. <li
  41. class="list-item"
  42. v-for="(item, key) in quotes"
  43. :key="key"
  44. @click="sendDanmaku(key)"
  45. >
  46. {{ item }}
  47. </li>
  48. </ul>
  49. </div>
  50. <div class="input-mobile">
  51. <span class="send-choices" @click.stop="toggleSelectMenu">请选择弹幕内发送吧~</span>
  52. <div class="send-btn-container">
  53. <img
  54. @click="hideList"
  55. class="show-icon"
  56. :src="showIcon || ''"
  57. v-if="isShowList"
  58. />
  59. <img
  60. @click="showList"
  61. class="close-icon"
  62. :src="closeIcon || ''"
  63. v-if="!isShowList"
  64. />
  65. <!-- <button class="send-btn">发送</button> -->
  66. </div>
  67. <ul class="show-list" v-show="isShowSelectList">
  68. <li
  69. class="list-item"
  70. v-for="(item, key) in quotes"
  71. :key="key"
  72. @click="sendDanmaku(key)"
  73. >
  74. {{ item }}
  75. </li>
  76. </ul>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import Vue from "vue";
  82. import VueChatScroll from "vue-chat-scroll";
  83. Vue.use(VueChatScroll);
  84. export default {
  85. name: "danmaku",
  86. props: {
  87. quotes: {
  88. type: Array,
  89. default: function() {
  90. return [
  91. ];
  92. },
  93. },
  94. showIcon: {
  95. type: String,
  96. required: true,
  97. },
  98. closeIcon: {
  99. type: String,
  100. required: true,
  101. },
  102. arrowIcon: {
  103. type: String,
  104. required: true,
  105. },
  106. limit: {
  107. type: Number,
  108. required: false,
  109. default: 5000,
  110. },
  111. },
  112. watch: {
  113. isNotInputAction: function() {},
  114. },
  115. data() {
  116. return {
  117. showDanmakuData: [],
  118. isShowList: true,
  119. isShowSelectList: false,
  120. isNotInputAction: false,
  121. timer: null,
  122. autoIndex: 0,
  123. isMobile: /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)
  124. };
  125. },
  126. methods: {
  127. toggleSelectMenu() {
  128. this.isShowSelectList = !this.isShowSelectList;
  129. },
  130. showList() {
  131. this.isShowList = true;
  132. },
  133. hideList() {
  134. this.isShowList = false;
  135. },
  136. sendDanmaku(index) {
  137. const text = this.quotes[index];
  138. if (this.showDanmakuData.length <= this.limit) {
  139. this.showDanmakuData.push(text);
  140. }
  141. this.isShowSelectList = false;
  142. this.isNotInputAction = true;
  143. },
  144. autoPopAnimation() {
  145. if (!this.isNotInputAction) {
  146. this.timer = setInterval(() => {
  147. if (this.autoIndex <= this.quotes.length) {
  148. if (this.quotes[this.autoIndex]) {
  149. this.showDanmakuData.push(this.quotes[this.autoIndex]);
  150. this.autoIndex++;
  151. } else {
  152. clearInterval(this.timer);
  153. }
  154. }
  155. }, 2000);
  156. }
  157. },
  158. },
  159. mounted() {
  160. this.autoPopAnimation();
  161. },
  162. };
  163. </script>
  164. <!-- Add "scoped" attribute to limit CSS to this component only -->
  165. <style scoped>
  166. .danmaku-area {
  167. min-height: 350px;
  168. margin: 0;
  169. }
  170. .danmaku-container {
  171. max-width: 340px;
  172. height: 288px;
  173. overflow-x: hidden;
  174. overflow-y: scroll;
  175. }
  176. .danmaku-list {
  177. text-decoration: none;
  178. max-width: 342px;
  179. overflow: hidden;
  180. display: flex;
  181. flex-direction: column;
  182. margin: 0;
  183. padding: 0;
  184. }
  185. .danmaku-list li.danmaku-list-item {
  186. margin-bottom: 10px;
  187. padding: 0;
  188. display: block;
  189. overflow: hidden;
  190. white-space: nowrap;
  191. text-overflow: ellipsis;
  192. text-align: left;
  193. }
  194. .danmaku-list li.danmaku-list-item > span {
  195. padding: 0 20px;
  196. line-height: 36px;
  197. font-size: 14px;
  198. display: inline-block;
  199. margin: 0;
  200. color: #fff;
  201. border-radius: 20px;
  202. background: rgba(0, 0, 0, 0.6);
  203. border: 1px solid hsla(0, 0%, 100%, 0.53);
  204. overflow: hidden;
  205. white-space: nowrap;
  206. text-overflow: ellipsis;
  207. text-align: left;
  208. max-width: 290px;
  209. }
  210. .danmaku-list li.danmaku-list-item:nth-last-child(6) {
  211. /* visibility: hidden; */
  212. animation: fadeout 0.3s linear;
  213. }
  214. .input-container {
  215. background: rgba(0, 0, 0, 0.6);
  216. border-radius: 25px;
  217. max-width: 350px;
  218. height: 48px;
  219. display: flex;
  220. flex-flow: row nowrap;
  221. justify-content: space-between;
  222. align-items: center;
  223. position: relative;
  224. padding: 10px;
  225. }
  226. .input-container span {
  227. color: rgb(140, 140, 140);
  228. cursor: pointer;
  229. flex: 1;
  230. height: 48px;
  231. text-align: left;
  232. line-height: 48px;
  233. }
  234. .input-container > * {
  235. cursor: pointer;
  236. }
  237. .arrow-icon {
  238. margin-right: 8px;
  239. width: 18px;
  240. }
  241. .send-btn {
  242. background: rgb(184, 23, 23);
  243. color: #fff;
  244. padding: 5px 15px;
  245. border: 10px;
  246. outline: 0;
  247. font-size: 16px;
  248. cursor: pointer;
  249. border-radius: 15px;
  250. margin-left: 5px;
  251. }
  252. .send-btn:hover,
  253. .send-btn:focus {
  254. background: rgb(153, 17, 17);
  255. }
  256. .send-btn-container {
  257. display: flex;
  258. flex-flow: row nowrap;
  259. }
  260. .send-btn-container .show-icon,
  261. .send-btn-container .close-icon {
  262. width: 24px;
  263. height: 24px;
  264. }
  265. .input-container .show-list {
  266. text-decoration: none;
  267. position: absolute;
  268. left: 0;
  269. bottom: 64px;
  270. background: rgba(0, 0, 0, 0.7);
  271. width: 340px;
  272. color: #fff;
  273. border-radius: 10px;
  274. max-height: 200px;
  275. overflow-x: hidden;
  276. overflow-y: scroll;
  277. margin: 0;
  278. padding: 0;
  279. }
  280. .input-container .show-list .list-item {
  281. text-align: left;
  282. font-size: 14px;
  283. line-height: 36px;
  284. text-decoration: none;
  285. white-space: nowrap;
  286. text-overflow: ellipsis;
  287. color: #fff;
  288. max-width: 100%;
  289. padding: 0 10px;
  290. overflow: hidden;
  291. }
  292. .input-container .show-list .list-item:hover {
  293. background: rgb(184, 23, 23);
  294. }
  295. .dm-enter {
  296. opacity: 0;
  297. transform: translateY(20px);
  298. }
  299. .dm-leave-to {
  300. opacity: 0;
  301. transform: translateY(-50px);
  302. }
  303. .dm-enter-active,
  304. .dm-leave-active {
  305. transition: all 0.6s ease;
  306. }
  307. .dm-move {
  308. transition: all 0.6s ease;
  309. }
  310. .dm-leave-active {
  311. position: absolute;
  312. }
  313. .input-mobile{
  314. min-width: 213px;
  315. height: 40px;
  316. background: rgba(0, 0, 0, 0.5);
  317. border-radius: 3px;
  318. display: flex;
  319. padding: 10px;
  320. box-sizing: border-box;
  321. position: relative;
  322. justify-content: space-between;
  323. }
  324. .input-mobile .send-choices{
  325. color: #fff;
  326. font-size: 14px;
  327. }
  328. .input-mobile .show-list {
  329. text-decoration: none;
  330. position: absolute;
  331. left: 0;
  332. bottom: 50px;
  333. background: rgba(0, 0, 0, 0.9);
  334. width: 90%;
  335. color: #fff;
  336. border-radius: 3px;
  337. max-height: 200px;
  338. overflow-x: hidden;
  339. overflow-y: scroll;
  340. margin: 0;
  341. padding: 0;
  342. }
  343. .input-mobile .show-list .list-item {
  344. text-align: left;
  345. font-size: 14px;
  346. line-height: 36px;
  347. text-decoration: none;
  348. white-space: nowrap;
  349. text-overflow: ellipsis;
  350. color: #fff;
  351. max-width: 100%;
  352. padding: 0 10px;
  353. overflow: hidden;
  354. }
  355. .input-mobile .show-list .list-item:hover {
  356. background: rgb(184, 23, 23);
  357. }
  358. .input-mobile .send-btn-container{
  359. margin-left: 10px;
  360. }
  361. @keyframes fadeout {
  362. 0% {
  363. opacity: 1;
  364. transform: translateY(10px);
  365. }
  366. 50% {
  367. opacity: 0.7;
  368. transform: translateY(3px);
  369. }
  370. 100% {
  371. opacity: 0.2;
  372. transform: translateY(0px);
  373. }
  374. }
  375. @media only screen and (max-width: 500px), (max-height: 487px) {
  376. .danmaku-list li.danmaku-list-item{
  377. margin-bottom: 5px;
  378. }
  379. .danmaku-list li.danmaku-list-item > span{
  380. border-radius: 3px;
  381. border: 0;
  382. }
  383. }
  384. </style>