MyPoems.vue 6.82 KB
Newer Older
hcyhuchaoyue's avatar
hcyhuchaoyue committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<!--
 * 设计1
  -->
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useQuasar, copyToClipboard } from 'quasar';
import { useMessage } from 'src/common/hooks';
import { myCloneDeep, getRandomInt, isEmpty } from 'src/common/utils';
import { poems } from '../config';
import { QMediaPlayer } from '@quasar/quasar-ui-qmediaplayer';

const defaultStyle = {
  backgroundImage: 'linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%)',
  color: 'white',
};

const $q = useQuasar();
const { info } = useMessage();

// const textcolor = ref('#ffffff');
// const getTextColor = computed(() => {
//   return {
hcyhuchaoyue's avatar
hcyhuchaoyue committed
23 24
//     // color: 'inherit',
//     color: textcolor.value,
hcyhuchaoyue's avatar
hcyhuchaoyue committed
25 26 27 28 29
//   };
// });
const source = ref(require('../media/羽肿-花火が瞬く夜に.mp3'));
const isPlaying = ref(false);
const carouselRef = ref<any>(null);
hucy's avatar
hucy committed
30
const slide = ref('135');
hcyhuchaoyue's avatar
hcyhuchaoyue committed
31 32

onMounted(() => {
hucy's avatar
hucy committed
33
  // rightClick();
hcyhuchaoyue's avatar
hcyhuchaoyue committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
});

function getStyle(data: any) {
  let obj = {} as any;
  if (!isEmpty(data.style)) {
    for (const key in data.style) {
      obj[key] = data.style[key];
    }
  } else {
    obj = myCloneDeep(defaultStyle);
  }
  return obj;
}

function leftClick(data: any) {
  let str = '';
  for (const item of data.content) {
    str += item + '\r\n';
  }
  if (data.author) {
    str += data.author;
  }
  copyToClipboard(str)
    .then(() => {
      info('复制成功');
    })
    .catch(() => {
      // fail
    });
}

function rightClick() {
  const keyList = poems.map((item: any) => item.key);
  const max = keyList.length;

  getValueKey(keyList, max);
}

function getValueKey(keyList: any, max: number) {
  const randomIndex = getRandomInt(0, max);
  const valueKey = keyList[randomIndex];

  if (valueKey === slide.value) {
    getValueKey(keyList, max);
  } else {
    slide.value = valueKey;
  }
}

function toggle() {
  const target = carouselRef.value.$el;
  $q.fullscreen
    .toggle(target)
    .then(() => {
      // success!
    })
    .catch((err) => {
      alert(err);
      // uh, oh, error!!
      // console.error(err)
    });
}

function onPaused() {
  isPlaying.value = false;
}
function onPlaying() {
  isPlaying.value = true;
}
</script>
<template>
  <div class="box container-height">
    <!-- 
      arrows
      navigation
      :autoplay="8000"
     -->
    <q-carousel
      v-model="slide"
      transition-prev="fade"
      transition-next="fade"
      :transition-duration="1500"
hucy's avatar
hucy committed
116
      arrows
hcyhuchaoyue's avatar
hcyhuchaoyue committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
      animated
      infinite
      height="100%"
      ref="carouselRef"
    >
      <q-carousel-slide
        :name="item.key"
        class="my-carousel-slide"
        v-for="item in poems"
        :key="item.key"
      >
        <div class="content" :style="getStyle(item)">
          <section
            title="鼠标左键复制,右键切换"
            @click="leftClick(item)"
            @contextmenu.prevent="rightClick()"
          >
            <!-- 
              :style="getTextColor"
             -->
            <p v-for="(contentItem, index) in item.content" :key="index">
              {{ contentItem }}
            </p>
hcyhuchaoyue's avatar
hcyhuchaoyue committed
140 141 142
            <p class="author" v-if="item.author">
              {{ item.author }}
            </p>
hcyhuchaoyue's avatar
hcyhuchaoyue committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
          </section>
        </div>
      </q-carousel-slide>

      <template v-slot:control>
        <q-carousel-control position="top-right" :offset="[18, 18]">
          <q-btn
            round
            flat
            :icon="$q.fullscreen.isActive ? 'fullscreen_exit' : 'fullscreen'"
            :title="$q.fullscreen.isActive ? '退出全屏' : '全屏'"
            @click="toggle"
          />
        </q-carousel-control>

        <!-- 
          style="left: 50%; transform: translateX(-50px); width: 100px"
         -->
        <q-carousel-control
          position="top"
          :offset="[0, 18]"
          style="left: 50%; transform: translateX(-140px); width: 280px"
        >
          <div>
            <!-- 
              autoplay
              width: 100px;
              min-width: 100px !important;
              dense
             -->
            <q-media-player
hcyhuchaoyue's avatar
hcyhuchaoyue committed
174
              class="my-media-player"
hcyhuchaoyue's avatar
hcyhuchaoyue committed
175 176 177 178 179 180 181 182 183 184
              type="audio"
              dense
              loop
              hide-volume-btn
              no-video
              :source="source"
              style="
                border-radius: 20px;
                width: 280px;
                min-width: 280px !important;
hcyhuchaoyue's avatar
hcyhuchaoyue committed
185 186 187 188
                --mediaplayer-background: #dfdbca;
                --mediaplayer-background-dark: #dfdbca;
                --mediaplayer-color: #306e8a;
                --mediaplayer-color-dark: #306e8a;
hcyhuchaoyue's avatar
hcyhuchaoyue committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
              "
              @paused="onPaused"
              @playing="onPlaying"
            >
              <template #play>
                <q-btn
                  round
                  flat
                  :icon="
                    isPlaying
                      ? 'fa-solid fa-compact-disc'
                      : 'bi-play-circle-fill'
                  "
                  :class="{ 'rotate-animate': isPlaying }"
                  style="
                    font-size: 1rem;
                    padding: 4px;
                    min-width: 40px;
                    max-width: 40px;
                    min-height: 40px;
                    max-height: 40px;
                  "
                />
              </template>

              <!-- <template #positionSlider> </template> -->
              <!-- <template #durationTime></template> -->
            </q-media-player>
          </div>
        </q-carousel-control>
      </template>
    </q-carousel>
  </div>
  <!-- <div class="text z-top">
    <q-input filled v-model="textcolor" class="my-input">
      <template v-slot:append>
        <q-icon name="colorize" class="cursor-pointer">
          <q-popup-proxy cover transition-show="scale" transition-hide="scale">
            <q-color v-model="textcolor" />
          </q-popup-proxy>
        </q-icon>
      </template>
    </q-input>
  </div> -->
</template>

<style lang="scss" scoped>
// .text {
//   position: fixed;
//   top: 10px;
//   left: 10px;
//   box-sizing: border-box;
// }
@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
.box {
  box-sizing: border-box;
  overflow: hidden;
}
.my-carousel-slide {
  padding: 0;
}
.content {
  box-sizing: border-box;
  height: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
hucy's avatar
hucy committed
264
  font-family: '华文中宋', '新宋体', '楷体';
hcyhuchaoyue's avatar
hcyhuchaoyue committed
265 266 267 268 269 270 271 272 273 274 275 276
  p {
    font-size: 24px;
  }
  .author {
    font-size: 15px;
    text-align: right;
  }
}

.rotate-animate {
  animation: rotate 3s linear infinite;
}
hucy's avatar
hucy committed
277 278 279 280 281 282 283
:deep(
    .my-media-player
      .q-media__controls
      .q-slider
      .q-slider__track-container
      .q-slider__track
  ) {
hcyhuchaoyue's avatar
hcyhuchaoyue committed
284
  color: #306e8a;
hcyhuchaoyue's avatar
hcyhuchaoyue committed
285
}
hucy's avatar
hucy committed
286 287 288 289 290 291 292 293
:deep(
    .my-media-player
      .q-media__controls
      .q-slider
      .q-slider__track-container
      .q-slider__track
      .q-slider__thumb
  ) {
hcyhuchaoyue's avatar
hcyhuchaoyue committed
294
  color: #306e8a;
hcyhuchaoyue's avatar
hcyhuchaoyue committed
295 296
}
</style>