he wei
5 天以前 3c3576d5792bfabcef84979757ee344712e71cd3
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<script setup>
import { ref, reactive, computed, watch } from 'vue';
 
const props = defineProps({
  list: {
    type: Array,
    default: () => []
  },
  
});
 
 
// 搜索相关状态
const searchQuery = ref('');
const matches = ref([]);
const currentMatchIndex = ref(-1);
const recentlyEdited = ref([]);
 
// 获取所有分类
const categories = computed(() => {
  return props.list.map((v) => v.almName);
});
 
const allFields = computed(() => {
  return props.list || [];
});
 
// 根据告警ID 创建告警表单
function getFieldsByCategory(category) {
  // TODO
  return allFields.value.filter(field => field.category === category);
}
 
// 处理搜索
function handleSearch() {
  if (!searchQuery.value.trim()) {
    matches.value = [];
    currentMatchIndex.value = -1;
    return;
  }
  
  const query = searchQuery.value.toLowerCase();
  matches.value = allFields.value.filter(field => 
    field.label.toLowerCase().includes(query) || 
    (field.description && field.description.toLowerCase().includes(query))
  );
  
  // 如果有匹配项,高亮第一个
  if (matches.value.length > 0) {
    currentMatchIndex.value = 0;
    scrollToCurrentMatch();
  }
}
 
// 清除搜索
function clearSearch() {
  searchQuery.value = '';
  matches.value = [];
  currentMatchIndex.value = -1;
}
 
// 检查字段是否匹配搜索
function isMatch(field) {
  return matches.value.includes(field);
}
 
// 检查字段是否为当前匹配项
function isCurrentMatch(field) {
  return currentMatchIndex.value >= 0 && 
         matches.value[currentMatchIndex.value] === field;
}
 
// 跳转到下一个匹配项
function goToNextMatch() {
  if (matches.value.length === 0) return;
  currentMatchIndex.value = (currentMatchIndex.value + 1) % matches.value.length;
  scrollToCurrentMatch();
}
 
// 跳转到上一个匹配项
function goToPrevMatch() {
  if (matches.value.length === 0) return;
  currentMatchIndex.value = (currentMatchIndex.value - 1 + matches.value.length) % matches.value.length;
  scrollToCurrentMatch();
}
 
// 滚动到当前匹配项
function scrollToCurrentMatch() {
  if (currentMatchIndex.value < 0) return;
  
  const currentField = matches.value[currentMatchIndex.value];
  if (!currentField) return;
  
  // 找到对应的DOM元素并滚动到视图
  const fieldElement = document.querySelector(`[data-field-key="${currentField.key}"]`);
  if (fieldElement) {
    fieldElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
    
    // 自动聚焦到输入框
    const input = fieldElement.querySelector('input');
    if (input) input.focus();
  }
}
 
// 聚焦到指定字段
function focusOnField(field) {
  // 更新当前匹配项
  const matchIndex = matches.value.indexOf(field);
  if (matchIndex >= 0) {
    currentMatchIndex.value = matchIndex;
  }
  
  // 找到对应的DOM元素并聚焦
  const fieldElement = document.querySelector(`[data-field-key="${field.key}"]`);
  if (fieldElement) {
    const input = fieldElement.querySelector('input');
    if (input) input.focus();
  }
}
 
// 检查字段是否最近被编辑
function isRecentlyEdited(key) {
  return recentlyEdited.value.includes(key);
}
 
// 处理字段变更
function handleFieldChange(field) {
  // 记录字段变更时间
  const now = new Date().getTime();
  
  // 检查字段是否已在最近编辑列表中
  const existingIndex = recentlyEdited.value.findIndex(key => key === field.key);
  
  if (existingIndex > -1) {
    // 将字段移到最近编辑列表的顶部
    recentlyEdited.value.splice(existingIndex, 1);
    recentlyEdited.value.unshift(field.key);
  } else {
    // 添加到最近编辑列表的顶部
    recentlyEdited.value.unshift(field.key);
    
    // 限制列表长度
    if (recentlyEdited.value.length > 5) {
      recentlyEdited.value.pop();
    }
  }
}
 
 
// 监听搜索变化
watch(searchQuery, (newValue, oldValue) => {
  if (newValue !== oldValue) {
    handleSearch();
  }
});
 
</script>
 
<template>
<div class="highlight-form">
    <!-- 顶部工具栏 -->
    <div class="toolbar">
      <div class="search-container">
        <input 
          v-model="searchQuery" 
          placeholder="搜索字段名称或描述..." 
          @keyup="handleSearch"
        >
        <button @click="clearSearch">
          <i class="fa fa-times"></i>
        </button>
      </div>
      
      <div class="quick-actions">
        <button @click="goToNextMatch">
          <i class="fa fa-arrow-down"></i> 下一个
        </button>
        <button @click="goToPrevMatch">
          <i class="fa fa-arrow-up"></i> 上一个
        </button>
        <span v-if="searchQuery">
          找到 {{ matches.length }} 个匹配项 (当前 {{ currentMatchIndex + 1 }})
        </span>
      </div>
    </div>
    
    <!-- 完整表单区域 -->
    <div class="form-content">
      <!-- 类别分隔 -->
      <div v-for="category in categories" :key="category" class="category-section">
        <h3 class="category-title">{{ category }}</h3>
        
        <div class="fields-grid">
          <div 
            v-for="field in getFieldsByCategory(category)" 
            :key="field.key"
            class="form-field"
            :class="{ 
              'search-match': isMatch(field),
              'current-match': isCurrentMatch(field),
              'recently-edited': isRecentlyEdited(field.key)
            }"
            @click="focusOnField(field)"
          >
            <div class="field-header">
              <span class="field-label">{{ field.label }}</span>
              <span v-if="isRecentlyEdited(field.key)" class="recent-tag">最近编辑</span>
            </div>
            
            <div class="field-value">
              <input 
                v-model="formData[field.key]" 
                :type="field.type"
                @change="handleFieldChange(field)"
              >
            </div>
            
            <div class="field-description" v-if="field.description">
              {{ field.description }}
            </div>
          </div>
        </div>
      </div>
    </div>
    
  </div>
</template>
 
<style scoped lang="less">
.highlight-form {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}
 
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
 
.search-container {
  display: flex;
  align-items: center;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
}
 
.search-container input {
  padding: 8px;
  border: none;
  width: 300px;
}
 
.search-container button {
  padding: 8px 12px;
  border: none;
  background-color: #f0f0f0;
  cursor: pointer;
}
 
.quick-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
 
.quick-actions button {
  padding: 6px 10px;
  border: 1px solid #ddd;
  background-color: white;
  cursor: pointer;
  border-radius: 4px;
}
 
.category-section {
  margin-bottom: 30px;
}
 
.category-title {
  font-size: 1.2em;
  font-weight: bold;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}
 
.fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 15px;
}
 
.form-field {
  padding: 15px;
  border: 1px solid #eee;
  border-radius: 4px;
  transition: all 0.2s;
  position: relative;
}
 
.search-match {
  border-color: #42b983;
  background-color: #f9f9f9;
}
 
.current-match {
  border-color: #ff7a45;
  box-shadow: 0 0 0 2px rgba(255, 122, 69, 0.2);
  z-index: 1;
}
 
.recently-edited {
  background-color: #fffbe6;
}
 
.field-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
 
.field-label {
  font-weight: bold;
}
 
.recent-tag {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8em;
  background-color: #fff7e6;
  color: #fa8c16;
}
 
.field-value input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
}
 
.field-description {
  margin-top: 8px;
  color: #666;
  font-size: 0.9em;
}
 
.form-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
 
.form-footer button {
  margin-left: 10px;
}
</style>