litian
2024-05-23 cc26637f18b8ed178420122d7335b3f89be92ada
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
<template>
  <div class="page">
    <div class="search-Box">
      <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 class="trans">
          <div v-for="item in result.trans" :key="item">
            <div class="itemList">
              <div class="pos">{{item.pos}}.</div>
              <div class="tranCn">{{item.tranCn}}</div>
            </div>
          </div>
        </div>
        <div class="trans">
          <div class="title">词组短语</div>
          <div v-for="(item,index) in result.phrase" :key="item">
            <div class="itemList">
              <div class="index">{{index + 1}}</div>
              <div class="pos">{{item.pContent}}</div>
              <div class="tranCn">{{item.pCn}}</div>
            </div>
          </div>
        </div>
        <div class="trans">
          <div class="title">近义词</div>
          <div v-for="item in result.syno" :key="item">
            <div class="itemList">
              <div class="pos">{{item.pos}}</div>
              <div class="tranCn">{{item.tran}}</div>
            </div>
            <div class="hwds">
              <div v-for="hw in item.hwds" :key="hw" class="">{{hw.w}}</div>
            </div>
          </div>
        </div>
        <div class="trans">
          <div class="title">例句</div>
          <div v-for="(item,index) in result.sentence" :key="item">
            <div class="itemList1">
              <div class="pos"><span class="index">{{index +1}}</span>{{item.sContent}}</div>
              <div class="tranCn">{{item.sCn}}</div>
            </div>
          </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: String
})
const searchContent = ref('')
const isFull = ref(false)
watch(props, (newValue) => {
  // 统监听props的值变化,动态修改isShow的值
  searchContent.value = newValue.searchCon
  getSearchResult()
})
 
onMounted(() => {
  if(props){
    searchContent.value = props.searchCon
    getSearchResult()
  }
})
 
const searchResult = ref([])
 
 
const getSearchResult = () => {
  if (searchContent.value) {
    request({
      url: '/edu/api/FindWords',
      method: 'post',
      data: {
        word: searchContent.value,
        isFull: isFull.value
      }
    }).then((res) => {
      if (res.length > 0) {
        res.map((item) => {
          item.phrase = JSON.parse(item.phrase)
          item.relWord = JSON.parse(item.relWord)
          item.sentence = JSON.parse(item.sentence)
          item.syno = JSON.parse(item.syno)
          item.trans = JSON.parse(item.trans)
        })
        searchResult.value = res
      }
    })
  }
}
</script>
 
<style lang="less">
.page{
  height:100%;
  overflow-y:auto
}
.search-Box {
  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{
  padding:20px;
  .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;
      span{
        margin:0 10px;
      }
    }
  }
  .trans{
    padding:20px 0;
    border-bottom:1px solid #eeeff0;
    .title{
      padding:10px 0;
    }
    .itemList{
      display:flex;
      padding: 10px 0;
      .index{
        margin-right:15px;
      }
      .pos{
        margin-right:30px;
      }
    }
    .hwds{
      display:flex;
      div{
        padding:0 10px;
      }
    }
    .itemList1{
      padding:10px 0;
      .index{
        margin-right:15px;
      }
      .tranCn{
        margin-left:20px;
        margin-top:5px;
      }
    }
  }
}
</style>