123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- <template>
- <div class="danmaku-area" @keydown.stop>
- <div
- class="danmaku-container"
- v-chat-scroll
- v-if="isShowList"
- >
- <!-- <ul class=""> -->
- <transition-group appear tag="ul" class="danmaku-list" name="dm">
- <li
- class="danmaku-list-item"
- v-for="(item) in showDanmakuData"
- :key="item"
- >
- <span v-html="item"></span>
- </li>
- </transition-group>
- </div>
- <div class="input-container" v-if="!isMobile">
- <input @click.stop="toggleSelectMenu" v-model="danmu" type="text" placeholder="请选择弹幕内发送吧~" class="send-choices">
- <div class="send-btn-container">
- <img
- @click="hideList"
- class="show-icon"
- :src="showIcon || ''"
- v-if="isShowList"
- />
- <img
- @click="showList"
- class="close-icon"
- :src="closeIcon || ''"
- v-if="!isShowList"
- />
- <button class="send-btn primary" @click="leaveMsg">发送</button>
- </div>
- <ul class="show-list" v-show="isShowSelectList">
- <li
- class="list-item"
- v-for="(item, key) in quotes"
- :key="key"
- @click="sendDanmaku(key)"
- v-html="item"
- >
- </li>
- </ul>
- </div>
- <div class="input-mobile" v-else>
- <span class="send-choices" @click.stop="toggleSelectMenu">请选择弹幕内发送吧~</span>
- <div class="send-btn-container">
- <img
- @click="hideList"
- class="show-icon"
- :src="showIcon || ''"
- v-if="isShowList"
- />
- <img
- @click="showList"
- class="close-icon"
- :src="closeIcon || ''"
- v-if="!isShowList"
- />
- <!-- <button class="send-btn">发送</button> -->
- </div>
- <ul class="show-list" v-show="isShowSelectList">
- <li
- class="list-item"
- v-for="(item, key) in quotes"
- :key="key"
- @click="sendDanmaku(key)"
- >
- {{ item }}
- </li>
- </ul>
- </div>
- </div>
- </template>
- <script>
- import { saveBarrage } from "@/config/api";
- export default {
- name: "danmaku",
- props: {
- quotes: {
- type: Array,
- default: function() {
- return [
- ];
- },
- },
- danmuArr: {
- type: Array,
- default: function() {
- return [
- ];
- },
- },
- showIcon: {
- type: String,
- required: true,
- },
- closeIcon: {
- type: String,
- required: true,
- },
- arrowIcon: {
- type: String,
- required: true,
- },
- limit: {
- type: Number,
- required: false,
- default: 5000,
- },
- },
- watch: {
- isNotInputAction: function() {},
- },
- data() {
- return {
- danmu:'',
- showDanmakuData: [],
- isShowList: true,
- isShowSelectList: false,
- isNotInputAction: false,
- timer: null,
- autoIndex: 0,
- isMobile: /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)
- };
- },
- methods: {
- toggleSelectMenu() {
- this.isShowSelectList = !this.isShowSelectList;
- },
- showList() {
- this.isShowList = true;
- },
- hideList() {
- this.isShowList = false;
- },
- sendDanmaku(index) {
- const text = this.quotes[index];
- if (this.showDanmakuData.length <= this.limit) {
- this.showDanmakuData.push(text);
- }
- this.isShowSelectList = false;
- this.isNotInputAction = true;
- },
- sendDanmakuSelf(text){
- if (this.showDanmakuData.length <= this.limit) {
- this.showDanmakuData.push(text);
- }
- this.isShowSelectList = false;
- this.isNotInputAction = true;
- this.danmu=''
- },
- async leaveMsg(){
- let tmp = this.danmu.trim()
- if (!tmp) {
- return alert('弹幕不能为空')
- }
- saveBarrage({
- content: tmp,
- },res=>{
- if (res.code==0) {
- this.sendDanmakuSelf(tmp)
- }
- })
- },
- autoPopAnimation() {
- if (!this.isNotInputAction) {
- this.timer = setInterval(() => {
- if (this.autoIndex <= this.danmuArr.length) {
- if (this.danmuArr[this.autoIndex]) {
- this.showDanmakuData.push(this.danmuArr[this.autoIndex]);
- this.autoIndex++;
- } else {
- clearInterval(this.timer);
- }
- }
- }, 2000);
- }
- },
- },
- mounted() {
- this.autoPopAnimation();
- },
- };
- </script>
- <style lang="less" scoped>
- .danmaku-area {
- margin: 0;
- }
- .danmaku-container {
- max-width: 340px;
- max-height: 288px;
- overflow-x: hidden;
- overflow-y: scroll;
- }
- /* .hidedanmu{
- visibility: hidden;
- pointer-events: none;
- } */
- .danmaku-list {
- text-decoration: none;
- max-width: 342px;
- overflow: hidden;
- display: flex;
- flex-direction: column;
- margin: 0;
- padding: 0;
- }
- .danmaku-list li.danmaku-list-item {
- margin-bottom: 10px;
- padding: 0;
- display: block;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- text-align: left;
- }
- .danmaku-list li.danmaku-list-item > span {
- padding: 0 20px;
- line-height: 36px;
- font-size: 14px;
- display: inline-block;
- margin: 0;
- color: #fff;
- border-radius: 20px;
- background: rgba(0, 0, 0, 0.6);
- border: 1px solid hsla(0, 0%, 100%, 0.53);
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- text-align: left;
- max-width: 290px;
- }
- .danmaku-list li.danmaku-list-item:nth-last-child(6) {
- /* visibility: hidden; */
- animation: fadeout 0.3s linear;
- }
- .input-container {
- background: rgba(0, 0, 0, 0.6);
- border-radius: 25px;
- max-width: 350px;
- height: 48px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- position: relative;
- padding: 10px;
- }
- .input-container {
- >span,>input{
- cursor: pointer;
- font-size: 14px;
- height: 48px;
- text-align: left;
- line-height: 48px;
- padding-left: 10px;
- background:none;
- outline:none;
- border:none;
- color: #fff;
- &::placeholder{
- color: rgb(140, 140, 140);
- }
- }
- }
- .input-container > * {
- cursor: pointer;
- }
- .arrow-icon {
- margin-right: 8px;
- width: 18px;
- }
- .send-btn {
- background: rgb(184, 23, 23);
- color: #fff;
- padding: 5px 15px;
- border: 10px;
- outline: 0;
- font-size: 16px;
- cursor: pointer;
- border-radius: 15px;
- margin-left: 5px;
- }
- .send-btn:hover,
- .send-btn:focus {
- background: rgb(153, 17, 17);
- }
- .send-btn-container {
- display: flex;
- align-items: center;
-
- }
- .send-btn-container .show-icon,
- .send-btn-container .close-icon {
- width: 24px;
- margin-right: 4px;
- }
- .input-container .show-list {
- text-decoration: none;
- position: absolute;
- left: 0;
- bottom: 64px;
- background: rgba(0, 0, 0, 0.7);
- width: 340px;
- color: #fff;
- border-radius: 10px;
- max-height: 200px;
- overflow-x: hidden;
- overflow-y: scroll;
- margin: 0;
- padding: 0;
- }
- .input-container .show-list .list-item {
- text-align: left;
- font-size: 14px;
- line-height: 36px;
- text-decoration: none;
- white-space: nowrap;
- text-overflow: ellipsis;
- color: #fff;
- max-width: 100%;
- padding: 0 10px;
- overflow: hidden;
- }
- .input-container .show-list .list-item:hover {
- background: rgb(184, 23, 23);
- }
- .dm-enter {
- opacity: 0;
- transform: translateY(20px);
- }
- .dm-leave-to {
- opacity: 0;
- transform: translateY(-50px);
- }
- .dm-enter-active,
- .dm-leave-active {
- transition: all 0.6s ease;
- }
- .dm-move {
- transition: all 0.6s ease;
- }
- .dm-leave-active {
- position: absolute;
- }
- .input-mobile{
- min-width: 213px;
- height: 40px;
- background: rgba(0, 0, 0, 0.5);
- border-radius: 3px;
- display: flex;
- padding: 10px 10px 10px 20px;
- box-sizing: border-box;
- position: relative;
- justify-content: space-between;
- }
- .input-mobile .send-choices{
- color: #fff;
- font-size: 14px;
- display: inline-block;
- vertical-align: middle;
- line-height: 20px;
- }
- .input-mobile .show-list {
- text-decoration: none;
- position: absolute;
- left: 0;
- bottom: 50px;
- background: rgba(0, 0, 0, 0.9);
- width: 90%;
- color: #fff;
- border-radius: 3px;
- max-height: 200px;
- overflow-x: hidden;
- overflow-y: scroll;
- margin: 0;
- padding: 0;
- }
- .input-mobile .show-list .list-item {
- text-align: left;
- font-size: 14px;
- line-height: 36px;
- text-decoration: none;
- white-space: nowrap;
- text-overflow: ellipsis;
- color: #fff;
- max-width: 100%;
- padding: 0 10px;
- overflow: hidden;
- }
- .input-mobile .show-list .list-item:hover {
- background: rgb(184, 23, 23);
- }
- .input-mobile .send-btn-container{
- margin-left: 10px;
- }
- @keyframes fadeout {
- 0% {
- opacity: 1;
- transform: translateY(10px);
- }
- 50% {
- opacity: 0.7;
- transform: translateY(3px);
- }
- 100% {
- opacity: 0.2;
- transform: translateY(0px);
- }
- }
- @media only screen and (max-width: 500px), (max-height: 487px) {
- .danmaku-list li.danmaku-list-item{
- margin-bottom: 5px;
- }
- .danmaku-list li.danmaku-list-item > span{
- border-radius: 3px;
- border: 0;
- }
- }
- </style>
|