Danmaku.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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">
  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>
  51. </template>
  52. <script>
  53. import Vue from "vue";
  54. import VueChatScroll from "vue-chat-scroll";
  55. Vue.use(VueChatScroll);
  56. export default {
  57. name: "danmaku",
  58. props: {
  59. quotes: {
  60. type: Array,
  61. default: function() {
  62. return [
  63. "向英雄致敬!铁骨铮铮,保家卫国。",
  64. "向英雄致敬!",
  65. "向英雄致敬!铁骨铮铮",
  66. "向英雄致敬!铁骨铮铮,保家卫国。",
  67. "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。",
  68. "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。牢记历史,珍惜现在!牢记志愿军英烈的伟大贡献,珍惜现在的幸福生活",
  69. "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。牢记历史,珍惜现在!牢记志愿军英烈的伟大贡献,珍惜现在的幸福生活",
  70. "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。牢记历史,珍惜现在!牢记志愿军英烈的伟大贡献,珍惜现在的幸福生活",
  71. "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。牢记历史,珍惜现在!牢记志愿军英烈的伟大贡献,珍惜现在的幸福生活",
  72. "向英雄致敬!",
  73. ];
  74. },
  75. },
  76. showIcon: {
  77. type: String,
  78. required: true,
  79. },
  80. closeIcon: {
  81. type: String,
  82. required: true,
  83. },
  84. arrowIcon: {
  85. type: String,
  86. required: true,
  87. },
  88. limit: {
  89. type: Number,
  90. required: false,
  91. default: 5000,
  92. },
  93. },
  94. watch: {
  95. isNotInputAction: function() {},
  96. },
  97. data() {
  98. return {
  99. showDanmakuData: [],
  100. isShowList: true,
  101. isShowSelectList: false,
  102. isNotInputAction: false,
  103. timer: null,
  104. autoIndex: 0,
  105. };
  106. },
  107. methods: {
  108. toggleSelectMenu() {
  109. this.isShowSelectList = !this.isShowSelectList;
  110. },
  111. showList() {
  112. this.isShowList = true;
  113. },
  114. hideList() {
  115. this.isShowList = false;
  116. },
  117. sendDanmaku(index) {
  118. const text = this.quotes[index];
  119. if (this.showDanmakuData.length <= this.limit) {
  120. this.showDanmakuData.push(text);
  121. }
  122. this.isShowSelectList = false;
  123. this.isNotInputAction = true;
  124. },
  125. autoPopAnimation() {
  126. if (!this.isNotInputAction) {
  127. this.timer = setInterval(() => {
  128. if (this.autoIndex <= this.quotes.length) {
  129. if (this.quotes[this.autoIndex]) {
  130. this.showDanmakuData.push(this.quotes[this.autoIndex]);
  131. this.autoIndex++;
  132. } else {
  133. clearInterval(this.timer);
  134. }
  135. }
  136. }, 2000);
  137. }
  138. },
  139. },
  140. mounted() {
  141. this.autoPopAnimation();
  142. },
  143. };
  144. </script>
  145. <!-- Add "scoped" attribute to limit CSS to this component only -->
  146. <style scoped>
  147. .danmaku-area {
  148. min-height: 350px;
  149. }
  150. .danmaku-container {
  151. max-width: 340px;
  152. height: 288px;
  153. overflow-x: hidden;
  154. overflow-y: scroll;
  155. }
  156. .danmaku-list {
  157. text-decoration: none;
  158. max-width: 342px;
  159. overflow: hidden;
  160. display: flex;
  161. flex-direction: column;
  162. margin: 0;
  163. padding: 0;
  164. }
  165. .danmaku-list li.danmaku-list-item {
  166. margin-bottom: 10px;
  167. padding: 0;
  168. display: block;
  169. overflow: hidden;
  170. white-space: nowrap;
  171. text-overflow: ellipsis;
  172. text-align: left;
  173. }
  174. .danmaku-list li.danmaku-list-item > span {
  175. padding: 0 20px;
  176. line-height: 36px;
  177. font-size: 14px;
  178. display: inline-block;
  179. margin: 0;
  180. color: #fff;
  181. border-radius: 20px;
  182. background: rgba(0, 0, 0, 0.6);
  183. border: 1px solid hsla(0, 0%, 100%, 0.53);
  184. overflow: hidden;
  185. white-space: nowrap;
  186. text-overflow: ellipsis;
  187. text-align: left;
  188. max-width: 290px;
  189. }
  190. .danmaku-list li.danmaku-list-item:nth-last-child(6) {
  191. /* visibility: hidden; */
  192. animation: fadeout 0.3s linear;
  193. }
  194. .input-container {
  195. background: rgba(0, 0, 0, 0.6);
  196. border-radius: 20px;
  197. max-width: 320px;
  198. display: flex;
  199. flex-flow: row nowrap;
  200. justify-content: space-between;
  201. align-items: center;
  202. position: relative;
  203. padding: 10px;
  204. }
  205. .input-container span {
  206. color: rgb(140, 140, 140);
  207. cursor: pointer;
  208. flex: 1;
  209. height: 100%;
  210. text-align: left;
  211. line-height: 34px;
  212. }
  213. .input-container > * {
  214. cursor: pointer;
  215. }
  216. .arrow-icon {
  217. margin-right: 8px;
  218. }
  219. .send-btn {
  220. background: rgb(184, 23, 23);
  221. color: #fff;
  222. padding: 5px 15px;
  223. border: 10px;
  224. outline: 0;
  225. font-size: 16px;
  226. cursor: pointer;
  227. border-radius: 15px;
  228. margin-left: 5px;
  229. }
  230. .send-btn:hover,
  231. .send-btn:focus {
  232. background: rgb(153, 17, 17);
  233. }
  234. .send-btn-container {
  235. display: flex;
  236. flex-flow: row nowrap;
  237. }
  238. .send-btn-container .show-icon,
  239. .send-btn-container .close-icon {
  240. width: 30px;
  241. height: 30px;
  242. }
  243. .input-container .show-list {
  244. text-decoration: none;
  245. position: absolute;
  246. left: 0;
  247. bottom: 64px;
  248. background: rgba(0, 0, 0, 0.7);
  249. width: 340px;
  250. color: #fff;
  251. border-radius: 15px;
  252. max-height: 200px;
  253. overflow-x: hidden;
  254. overflow-y: scroll;
  255. margin: 0;
  256. padding: 0;
  257. }
  258. .input-container .show-list .list-item {
  259. text-align: left;
  260. font-size: 14px;
  261. line-height: 36px;
  262. text-decoration: none;
  263. white-space: nowrap;
  264. text-overflow: ellipsis;
  265. color: #fff;
  266. max-width: 100%;
  267. padding: 0 10px;
  268. overflow: hidden;
  269. }
  270. .input-container .show-list .list-item:hover {
  271. background: rgb(184, 23, 23);
  272. }
  273. .dm-enter {
  274. opacity: 0;
  275. transform: translateY(20px);
  276. }
  277. .dm-leave-to {
  278. opacity: 0;
  279. transform: translateY(-50px);
  280. }
  281. .dm-enter-active,
  282. .dm-leave-active {
  283. transition: all 0.6s ease;
  284. }
  285. .dm-move {
  286. transition: all 0.6s ease;
  287. }
  288. .dm-leave-active {
  289. position: absolute;
  290. }
  291. @keyframes fadeout {
  292. 0% {
  293. opacity: 1;
  294. transform: translateY(10px);
  295. }
  296. 50% {
  297. opacity: 0.7;
  298. transform: translateY(3px);
  299. }
  300. 100% {
  301. opacity: 0.2;
  302. transform: translateY(0px);
  303. }
  304. }
  305. </style>