Blame view

components/Header.vue 3.82 KB
1
2
3
4
5
6
7
<template>
  <v-container>
    <v-row class="tw-m-auto tw-flex tw-items-center">
      <v-col cols="2" class="pa-0 tw-h-[64px]">
        <router-link to="/"><v-img src="/logo.jpg" alt="canrud" /></router-link>
      </v-col>
      <v-col cols="6" md="8" class="px-0">
8
9
10
11
12
13
14
15
16
17
        <v-text-field
          name="keyword"
          label="Search keyword"
          hide-details="auto"
          variant="solo"
          append-inner-icon="mdi-magnify"
          @click:appendInner="handleClick"
          @keydown="handleKeyDown"
          v-model="input"
        >
18
19
20
        </v-text-field>
      </v-col>
      <v-col cols="4" md="2" class="px-0">
21
22
        <v-btn variant="text" href="/contact" color="blue-darken-2 mt-4"
          >Concat Us
23
24
25
26
27
28
        </v-btn>
      </v-col>
    </v-row>
  </v-container>
  <div class="tabs">
    <div class="tw-max-w-[1200px] tw-mx-auto">
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
      <v-tabs
        mobile-breakpoint="580"
        v-model="tab"
        bg-color="blue-darken-1"
        slider-color="grey-lighten-3"
        tab-slider-size="6px"
        selected-class="active"
        :grow="screenWidth > 600 ? false : true"
      >
        <v-tab :value="1" to="/"
          ><span
            @click="handleTabClick"
            class="text-grey-lighten-3 tw-font-bold"
            >Home</span
          >
44
45
        </v-tab>
        <v-tab :value="2" to="/products">
46
47
48
          <span @click="handleTabClick" class="text-grey-lighten-3 tw-font-bold"
            >Products</span
          >
49
        </v-tab>
50
51
52
53
54
55
        <v-tab :value="3" to="/about"
          ><span
            @click="handleTabClick"
            class="text-grey-lighten-3 tw-font-bold"
            >About</span
          >
56
        </v-tab>
57
58
59
60
61
62
        <v-tab :value="4" to="/contact"
          ><span
            @click="handleTabClick"
            class="text-grey-lighten-3 tw-font-bold"
            >Contact</span
          >
63
        </v-tab>
64
65
66
67
68
        <v-tab>
          <span class="text-grey-lighten-3 tw-font-bold">
            <a href="http://blog.canrud.com/" target="" title="Blog">Blog</a>
          </span>
        </v-tab>
69
70
71
72
73
74
75
      </v-tabs>
    </div>
  </div>
  <ContactDialog />
</template>

<script setup lang="ts">
76
77
78
79
80
81
82
import { ref, watchEffect } from "vue";
import ContactDialog from "@/components/ContactDialog.vue";
import { useProductListStore } from "@/stores/product_list";
import { useRouter } from "vue-router";
import { useDialogStore } from "@/stores/dialog";
import { useCategoryStore } from "@/stores/category";
import { useDisplay } from "vuetify";
83
84
const { width: screenWidth } = useDisplay();
85
86
87
const productStore = useProductListStore();
const categoryStore = useCategoryStore();
88
89
const input = ref();
90
91
const router = useRouter();
92
93
const dialog = useDialogStore();
94
95
96
const handleKeyDown = (e: any) => {
  if (e.keyCode == 13) {
97
    handleClick();
98
  }
99
};
100
101

const handleClick = () => {
102
103
104
105
106
  categoryStore.updateDisplay(!input.value);
  productStore.updateKeyword(input.value);
  productStore.updatePageNo(1);
  router.push({ path: "/products", query: { keyword: input.value } });
};
107
108
const tab = ref(1);
109
110

const handleTabClick = () => {
111
112
113
  categoryStore.updateDisplay(true);
  productStore.updateKeyword("");
};
114
115

watchEffect(() => {
116
117
  input.value = productStore.keyword;
});
118
119
120

onMounted(() => {
  // 获取url的参数
121
122
  const url = window.location.href;
  const index = url.indexOf("?");
123
  if (index !== -1) {
124
125
    const params = url.slice(index + 1).split("&");
    const obj: any = {};
126
    params.forEach((item) => {
127
128
129
      const arr = item.split("=");
      obj[arr[0]] = arr[1];
    });
130
131
    // 获取dialog的状态
    if (obj.flag) {
132
      dialog.updateDialog(true);
133
    }
134
135

    if (obj.keyword) {
136
137
      productStore.updateKeyword(obj.keyword);
      categoryStore.updateDisplay(false);
138
    }
139
  }
140
});
141
142
143
144
145
146
147
148
149
150
151
152
153
</script>

<style lang="scss" scoped>
.tabs {
  background-color: #1f88e5;
}

.active :deep {
  .v-tab__slider {
    bottom: 3px;
  }
}
</style>