litian
2024-05-11 576fbe7418510c9f442fe93100db93445fcf3964
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
<template>
  <div>
    <div class="searchBox">
      <el-input class="custom-input" placeholder="请输入内容" v-model="searchContent">
        <template #suffix>
          <el-icon @click="getSearchResult" class="hover"><Search /></el-icon>
        </template>
      </el-input>
    </div>
    <div class="resultBox">
      <div v-for="result in searchResult" :key="result.id">
        <div class="phone_con">
        <div class="per-phone">英/<span>{{result.ukPhone}}</span>/</div>
        <div class="per-phone">美/<span>{{result.usPhone}}</span>/</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, watch, onMounted, inject } from 'vue'
const request = inject('request')
const props = defineProps({
  searchCon: Boolean
})
const searchContent = ref('')
const isFull = ref(false)
watch(props, (newValue) => {
  // 统监听props的值变化,动态修改isShow的值
  searchContent.value = newValue.searchCon
})
 
const searchResult = ref([])
 
const getSearchResult = () => {
  if (searchContent.value) {
    request({
      url: '/edu/api/FindWords',
      method: 'post',
      data: {
        word: searchContent.value,
        isFull: isFull.value
      }
    }).then((res) => {
      console.log(JSON.parse(res[0].sentence)[0].sCn)
      // encodeURIComponent(res[0].syno[0].tran)
      if (res.length > 0) {
        searchResult.value = res
      }
    })
  }
}
</script>
 
<style lang="less">
.searchBox {
  width: 400px;
  margin: 0 auto;
  .custom-input {
    height: 40px;
 
    .el-input__wrapper {
      border-radius: 10px;
      width: 100%;
    }
    .multiselect__single {
      background: none;
      color: #2a2b2e;
      font-size: 0.15rem;
      font-weight: 500;
      margin-bottom: 8px;
      padding-left: 5px;
    }
  }
}
.resultBox{
  .phone_con{
    .per-phone{
      width:150px;
      align-items: center;
      background: #f4f5f7;
      border-radius: 15px;
      box-sizing: border-box;
      color: #666;
      display: flex;
      font-weight: 500;
      margin-right: 10px;
      margin-top: 10px;
      // max-width: 100%;
      padding: 8px 10px;
    }
  }
}
</style>