File size: 4,853 Bytes
f0953a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<template>
  <div class="pc-search">
    <!-- 搜索区域 -->
    <div class="pc-search__input">
      <el-input
        v-model="keyword"
        placeholder="请输入搜索关键词或输入链接直接解析"
        clearable
        @keyup.enter="handleSearch"
      >
        <template #prefix>
          <el-icon><Search /></el-icon>
        </template>
        <template #suffix>
          <el-icon v-if="keyword" class="search-icon" @click="handleSearch">
            <ArrowRight />
          </el-icon>
        </template>
      </el-input>
    </div>

    <!-- 用户操作区 -->
    <div class="pc-search__actions">
      <el-tooltip effect="dark" content="退出登录" placement="bottom">
        <el-button class="logout-btn" type="text" @click="handleLogout">
          <el-icon><SwitchButton /></el-icon>
        </el-button>
      </el-tooltip>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, watch } from "vue";
import { useResourceStore } from "@/stores/resource";
import { useRoute, useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { Search, ArrowRight, SwitchButton } from "@element-plus/icons-vue";
import { STORAGE_KEYS } from "@/constants/storage";

// 路由相关
const route = useRoute();
const router = useRouter();
const resourcStore = useResourceStore();

// 响应式数据
const keyword = ref("");
const routeKeyword = computed(() => route.query.keyword as string);

// 退出登录
const handleLogout = () => {
  localStorage.removeItem(STORAGE_KEYS.TOKEN);
  router.push("/login");
  ElMessage.success("已退出登录");
};

// 搜索处理
const handleSearch = async () => {
  const searchText = keyword.value.trim();
  if (!searchText) {
    ElMessage.warning("请输入搜索内容");
    return;
  }

  // 链接解析处理
  if (searchText.startsWith("http")) {
    await resourcStore.parsingCloudLink(searchText);
    return;
  }

  // 关键词搜索
  await resourcStore.searchResources(searchText);
  if (route.path !== "/resource") {
    router.push("/resource");
  }
};

// 监听路由参数变化
watch(
  () => routeKeyword.value,
  (newKeyword) => {
    if (newKeyword) {
      keyword.value = newKeyword;
      handleSearch();
    } else {
      keyword.value = resourcStore.keyword;
    }
  }
);
watch(
  () => resourcStore.keyword,
  (newKeyword) => {
    keyword.value = newKeyword;
  }
);
</script>

<style lang="scss" scoped>
@import "@/styles/common.scss";

.pc-search {
  @include flex-center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;

  // 搜索输入区域
  &__input {
    flex: 1;
    min-width: 0; // 防止溢出

    :deep(.el-input) {
      --el-input-height: 44px;

      .el-input__wrapper {
        @include glass-effect;
        padding: 0 16px;
        border-radius: var(--theme-radius);
        box-shadow:
          inset 0 0 0 1px rgba(255, 255, 255, 0.1),
          0 2px 4px rgba(0, 0, 0, 0.05),
          0 1px 2px rgba(0, 0, 0, 0.1);
        border: 1px solid rgba(0, 0, 0, 0.08);
        transition: var(--theme-transition);
        background: rgba(255, 255, 255, 0.9);

        &:hover {
          border-color: var(--theme-primary);
          box-shadow:
            inset 0 0 0 1px var(--theme-primary),
            0 4px 8px rgba(0, 0, 0, 0.1);
        }

        &.is-focus {
          border-color: var(--theme-primary);
          box-shadow:
            inset 0 0 0 1px var(--theme-primary),
            0 4px 8px rgba(0, 0, 0, 0.1),
            0 0 0 3px rgba(0, 102, 204, 0.1);
          background: #fff;
        }
      }

      .el-input__inner {
        font-size: 15px;
        color: var(--theme-text-primary);
        height: 42px;
        line-height: 42px;

        &::placeholder {
          color: var(--theme-text-secondary);
        }
      }

      .el-input__prefix-inner {
        .el-icon {
          font-size: 18px;
          color: var(--theme-text-secondary);
          margin-right: 8px;
        }
      }

      .search-icon {
        font-size: 18px;
        cursor: pointer;
        color: var(--theme-primary);
        transition: var(--theme-transition);
        margin-left: 8px;

        &:hover {
          transform: scale(1.1);
        }
      }
    }
  }

  // 操作区域
  &__actions {
    .logout-btn {
      @include glass-effect;
      width: 44px;
      height: 44px;
      padding: 0;
      border-radius: var(--theme-radius);
      transition: var(--theme-transition);

      .el-icon {
        font-size: 20px;
        color: var(--theme-text-regular);
        transition: var(--theme-transition);
      }

      &:hover {
        background: var(--theme-primary);
        transform: translateY(-2px);
        box-shadow: var(--theme-shadow-sm);

        .el-icon {
          color: #fff;
        }
      }
    }
  }
}
</style>