SearchInput.vue 2.65 KB
Newer Older
hucy's avatar
hucy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
<script setup lang="ts">
import { ref } from 'vue';

const inputRef = ref<any>(null);
const isActive = ref(false);

function iconClick() {
  isActive.value = !isActive.value;
}

function onClear() {
  inputRef.value.value = null;
}

function onSerch() {
  console.log('onSerch', inputRef.value.value);
}
</script>

<template>
  <div class="content fit center">
    <div class="search" :class="{ active: isActive }">
      <div class="icon" @click="iconClick"></div>
      <div class="input">
        <input
          type="text"
          ref="inputRef"
          placeholder="搜索..."
          @keyup.enter="onSerch"
        />
      </div>
      <span class="clear" @click="onClear"></span>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.content {
  background: #d3e397;
}
.search {
  position: relative;
  width: 60px;
  height: 60px;
  background: #fff;
  border-radius: 60px;
  transition: 0.4s;
  box-shadow: 0 0 5px #bad35b;
  overflow: hidden;
  .icon {
    position: absolute;
    top: 0;
    left: 0;
    width: 60px;
    height: 60px;
    background: #fff;
    border-radius: 60px;

    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    cursor: pointer;

    &::before {
      content: '';
      position: absolute;
      width: 20px;
      height: 20px;
      border: 3px solid #d3e397;
      border-radius: 50%;
      transform: translate(-4px, -4px);
    }

    &::after {
      content: '';
      position: absolute;
      width: 3px;
      height: 18px;
      background: #d3e397;
      border-radius: 50%;
      transform: translate(7px, 7px) rotate(315deg);
    }
  }

  .input {
    position: relative;
    width: 300px;
    height: 60px;
    left: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    input {
      position: absolute;
      top: 0;
      width: 100%;
      height: 100%;
      border: none;
      outline: none;
      font-size: 18px;
      padding: 10px 0;
    }
  }

  .clear {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    right: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    transition: 0.25s;
    &::before {
      position: absolute;
      content: '';
      width: 1px;
      height: 15px;
      transform: rotate(45deg);
      background-color: #999;
    }
    &::after {
      position: absolute;
      content: '';
      width: 1px;
      height: 15px;
      transform: rotate(316deg);
      background-color: #999;
    }
    &:hover {
      background-color: rgba(0, 0, 0, 0.05);
    }
  }
}
.active {
  width: 360px;
}
</style>