Browse Source

base init component

gemer 4 years ago
parent
commit
957c7e184c

+ 2 - 4
babel.config.js

@@ -1,5 +1,3 @@
 module.exports = {
-  presets: [
-    '@vue/cli-plugin-babel/preset'
-  ]
-}
+  presets: [["@vue/cli-plugin-babel/preset", { useBuiltIns: "entry" }]],
+};

+ 3 - 0
cspell.json

@@ -0,0 +1,3 @@
+{
+  "ignoreWords": ["danmaku","Danmaku"]
+}

File diff suppressed because it is too large
+ 11456 - 0
package-lock.json


+ 8 - 2
package.json

@@ -2,14 +2,20 @@
   "name": "@wujing/danmaku",
   "version": "0.1.0",
   "private": true,
+  "author": {
+    "email": "gemercheung@gmail.com",
+    "name": "gemer"
+  },
+  "main":"./dist/danmaku.common.js",
   "scripts": {
     "serve": "vue-cli-service serve",
-    "build": "vue-cli-service build",
+    "build-bundle": "vue-cli-service build --target lib --name danmaku ./src/components/Danmaku.vue",
     "lint": "vue-cli-service lint"
   },
   "dependencies": {
     "core-js": "^3.6.5",
-    "vue": "^2.6.11"
+    "vue": "^2.6.11",
+    "vue-chat-scroll": "^2.0.0-alpha.4"
   },
   "devDependencies": {
     "@vue/cli-plugin-babel": "~4.5.0",

+ 19 - 7
src/App.vue

@@ -1,19 +1,24 @@
 <template>
   <div id="app">
-    <img alt="Vue logo" src="./assets/logo.png">
-    <HelloWorld msg="Welcome to Your Vue.js App"/>
+    <div class="demo-container">
+      <Danmaku
+        class="demo-danmaku"
+        :sendIcon="require('./assets/list-enable-btn.png')"
+        :closeIcon="require('./assets/list-disable-btn.png')"
+      />
+    </div>
   </div>
 </template>
 
 <script>
-import HelloWorld from './components/HelloWorld.vue'
+import Danmaku from "./components/Danmaku.vue";
 
 export default {
-  name: 'App',
+  name: "App",
   components: {
-    HelloWorld
-  }
-}
+    Danmaku,
+  },
+};
 </script>
 
 <style>
@@ -25,4 +30,11 @@ export default {
   color: #2c3e50;
   margin-top: 60px;
 }
+/* .demo-container {
+  width: 600px;
+} */
+.demo-danmaku {
+  margin: 0 auto;
+  background: orangered;
+}
 </style>

BIN
src/assets/list-disable-btn.png


BIN
src/assets/list-enable-btn.png


+ 231 - 0
src/components/Danmaku.vue

@@ -0,0 +1,231 @@
+<template>
+  <div class="danmaku-area">
+    <div
+      class="danmaku-container"
+      v-chat-scroll
+      :style="{ visibility: isShowList ? 'visible' : 'hidden' }"
+    >
+      <!-- <ul class=""> -->
+      <transition-group appear tag="ul" class="danmaku-list">
+        <li
+          class="danmaku-list-item"
+          v-for="(item, key) in showDanmakuData"
+          :key="key"
+        >
+          <span> {{ item }}</span>
+        </li>
+      </transition-group>
+    </div>
+    <div class="input-container">
+      <span class="send-choices" @click.stop="toggleSelectMenu"
+        >请选择弹幕内发送吧~</span
+      >
+      <div class="send-btn-container">
+        <img
+          @click="hideList"
+          class="send-icon"
+          :src="sendIcon || ''"
+          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 Vue from "vue";
+import VueChatScroll from "vue-chat-scroll";
+Vue.use(VueChatScroll);
+export default {
+  name: "danmaku",
+  props: {
+    quotes: {
+      type: Array,
+      default: function() {
+        return [
+          "向英雄致敬!铁骨铮铮,保家卫国。",
+          "向英雄致敬!",
+          "向英雄致敬!铁骨铮铮",
+          "向英雄致敬!铁骨铮铮,保家卫国。",
+          "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。",
+          "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。牢记历史,珍惜现在!牢记志愿军英烈的伟大贡献,珍惜现在的幸福生活",
+          "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。牢记历史,珍惜现在!牢记志愿军英烈的伟大贡献,珍惜现在的幸福生活",
+          "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。牢记历史,珍惜现在!牢记志愿军英烈的伟大贡献,珍惜现在的幸福生活",
+          "向英雄致敬!铁骨铮铮,保家卫国。抗美援朝战争的伟大胜利,宣告着中华民族巍巍屹立与东方。牢记历史,珍惜现在!牢记志愿军英烈的伟大贡献,珍惜现在的幸福生活",
+          "向英雄致敬!",
+        ];
+      },
+    },
+    sendIcon: {
+      type: String,
+      required: true,
+    },
+    closeIcon: {
+      type: String,
+      required: true,
+    },
+  },
+
+  data() {
+    return {
+      showDanmakuData: [],
+      isShowList: true,
+      isShowSelectList: false,
+    };
+  },
+  methods: {
+    toggleSelectMenu() {
+      this.isShowSelectList = !this.isShowSelectList;
+    },
+    showList() {
+      this.isShowList = true;
+    },
+    hideList() {
+      this.isShowList = false;
+    },
+    sendDanmaku(index) {
+      const text = this.quotes[index];
+      console.log("text", text);
+      this.showDanmakuData.push(text);
+      this.isShowSelectList = false;
+    },
+  },
+};
+</script>
+
+<!-- Add "scoped" attribute to limit CSS to this component only -->
+<style scoped>
+.danmaku-area {
+  min-height: 350px;
+}
+.danmaku-container {
+  max-width: 340px;
+  height: 288px;
+  overflow-x: hidden;
+  overflow-y: scroll;
+}
+.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;
+}
+.input-container {
+  background: rgba(0, 0, 0, 0.6);
+  border-radius: 20px;
+  max-width: 320px;
+  display: flex;
+  flex-flow: row nowrap;
+  justify-content: space-between;
+  align-items: center;
+  position: relative;
+  padding: 10px;
+}
+.input-container span {
+  color: rgb(140, 140, 140);
+  cursor: pointer;
+  flex: 1;
+  height: 100%;
+  text-align: left;
+  line-height: 34px;
+}
+.input-container > * {
+  cursor: pointer;
+}
+
+.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;
+  flex-flow: row nowrap;
+}
+.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: 15px;
+  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);
+}
+</style>

+ 0 - 58
src/components/HelloWorld.vue

@@ -1,58 +0,0 @@
-<template>
-  <div class="hello">
-    <h1>{{ msg }}</h1>
-    <p>
-      For a guide and recipes on how to configure / customize this project,<br>
-      check out the
-      <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
-    </p>
-    <h3>Installed CLI Plugins</h3>
-    <ul>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
-    </ul>
-    <h3>Essential Links</h3>
-    <ul>
-      <li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
-      <li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
-      <li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
-      <li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
-      <li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
-    </ul>
-    <h3>Ecosystem</h3>
-    <ul>
-      <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
-      <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
-      <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
-      <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
-      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
-    </ul>
-  </div>
-</template>
-
-<script>
-export default {
-  name: 'HelloWorld',
-  props: {
-    msg: String
-  }
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped>
-h3 {
-  margin: 40px 0 0;
-}
-ul {
-  list-style-type: none;
-  padding: 0;
-}
-li {
-  display: inline-block;
-  margin: 0 10px;
-}
-a {
-  color: #42b983;
-}
-</style>