wujingjing
2024-07-22 bc4ab46fb5c4cb4435efabfe4b316be4ace5b026
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
<template>
    <div class="pc-prompts">
        <div class="title flex items-center justify-between">
            <div class="flex item-center">
                <span>提问示例</span>
                <span class="split"></span>
                <span class="change cursor-pointer" @click="advanceExampleClick">高级示例 ></span>
            </div>
            <div class="cursor-pointer">
                <span class="mr-1 changeBatch" @click="batchChange">换一批</span>
                <i class="iconfont icon-shuaxin"></i>
            </div>
        </div>
 
        <div class="main">
            <div
                class="main_item flex items-center cursor-pointer"
                v-for="(item, index) in state.exampleContent"
                :key="index"
                :class="{ main_item_active: item.sample_id === activeSampleId }"
                @click="changeExample(item)"
            >
                <div class="left flex items-center justify-center" :class="['color' + index]">
                    <img :src="item.Icon" alt="" />
                </div>
                <div class="right">
                    <h4>{{ item.sample_title }}</h4>
                    <p>{{ item.sample_question }}</p>
                </div>
            </div>
        </div>
    </div>
</template>
 
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue';
import { getSelectSample } from '/@/api/ai/chat';
import { activeRoomId, activeSampleId, setRoomConfig } from '/@/stores/chatRoom';
import emitter from '/@/utils/mitt';
let state = reactive({
    exampleContent: [],
    exampleRandomContent: [],
});
const exampleList = ref([]); //模版列表
const emits = defineEmits<{
    (event: 'advanceExampleClick', data): void;
    (event:'updateChatInput',val):void;
}>();
onMounted(() => {
    getSelectListSample();
});
const groupedArray = computed(() => {
    const groups = [];
    let i = 0;
    while (state.exampleRandomContent.length > i) {
        groups.push(state.exampleRandomContent.slice(i, (i += 4)));
    }
    return groups;
});
//获取模版列表
const getSelectListSample = async () => {
    const res = await getSelectSample({
        section_b_id: '',
    });
    // console.log(res, 63);
    state.exampleRandomContent = res.samples;
 
    const array = [];
    res.samples.forEach((sample, index) => {
        sample.Icon = '/static/images/wave/ChatImg.png';
        sample.BgColor = randomHexColor();
        if (index < 4) {
            array.push(sample);
        }
    });
    exampleList.value = res.samples;
    state.exampleContent = array;
};
 
const changeExample = (item) => {
    emits('updateChatInput',item.sample_question)
    setRoomConfig(activeRoomId.value, 'isAnswerByLLM', false);
    activeSampleId.value = item.sample_id;
};
//换一批
const batchChange = () => {
    const index = Math.floor(Math.random() * groupedArray.value.length);
    state.exampleContent = groupedArray.value[index];
};
//打开高级示例
const advanceExampleClick = () => {
    emits('advanceExampleClick', true);
};
 
//随机生成颜色
const randomHexColor = () => {
    return `#${Math.floor(Math.random() * 16777215)
        .toString(16)
        .padEnd(6, '0')}`;
};
defineExpose({
    getSelectListSample,
});
</script>
<style scoped lang="scss">
.pc-prompts {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin-top: 40px;
    width: 760px;
    padding: 0;
    font-size: 14px;
    .title {
        color: #999;
        line-height: 14px;
        .split {
            height: 12px;
            width: 2px;
            background-color: #ccc;
            margin: 0 10px;
        }
        span {
            color: rgb(32, 33, 35);
            font-size: 14px;
        }
        .changeBatch {
            color: #999;
            font-size: 12px;
            transition: color 0.2s ease-in-out;
        }
        .change {
            color: #999;
            transition: color 0.2s ease-in-out;
        }
    }
    .main {
        width: calc(100% + 16px);
        display: flex;
        flex-wrap: wrap;
        margin: 4px -8px 0;
        &_item {
            box-sizing: border-box;
            width: calc(50% - 16px);
            margin: 8px;
            padding: 12px;
            border: 1px solid #d9dbde;
            border-radius: 5px;
            background-color: transparent;
            -webkit-transition: border-color 0.2s, background-color 0.2s;
            -o-transition: border-color 0.2s, background-color 0.2s;
            transition: border-color 0.2s, background-color 0.2s;
 
            .left {
                width: 50px;
                height: 50px;
                border-radius: 5px;
            }
            .color0 {
                background: linear-gradient(180deg, #f63c8b, #fd216c);
            }
            .color1 {
                background: linear-gradient(180deg, #0ebfe1, #0ab2d3);
            }
            .color2 {
                background: linear-gradient(180deg, #9647fe, #7b5be8);
            }
            .color3 {
                background: linear-gradient(180deg, #fb894c, #ff7958);
            }
            .right {
                flex: 1;
                min-width: 0;
                margin-left: 12px;
                h4 {
                    color: #202123;
                    font-size: 13px;
                    font-weight: 500;
                    height: 16px;
                    transition: background-color 0.2s;
                }
                p {
                    font-size: 12px;
                    margin-top: 6px;
                    height: 34px;
                    line-height: 17px;
                    color: #8d8e99;
                    overflow: hidden;
                    -o-text-overflow: ellipsis;
                    text-overflow: ellipsis;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                }
            }
        }
        &_item_active {
            border: 1px solid #007aff;
            background-color: #ebeef3;
            .right {
                h4 {
                    color: #007aff;
                }
            }
        }
    }
}
 
:deep(.el-drawer__header) {
    padding: 30px 20px 26px !important;
    box-sizing: border-box;
    width: 100%;
    background-color: #e0e7fb;
 
    position: relative;
 
    height: unset !important;
    margin-bottom: unset !important;
    border-bottom: unset !important;
}
:deep(.el-drawer__body) {
    overflow-x: hidden;
}
</style>