wujingjing
2024-11-03 cee87e8401fdfb46f9cb9a4ad2818daeb09a59b4
Merge branch 'test' of http://47.103.154.90:83/r/WI/Web.V1.0 into test
已修改3个文件
135 ■■■■ 文件已修改
src/api/ai/chat.ts 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/chat/components/playBar/PlayBar.vue 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/chat/components/playBar/phrase/CommonPhrases.vue 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/ai/chat.ts
@@ -387,4 +387,21 @@
            'Content-Type': 'application/x-www-form-urlencoded',
        },
    });
}
/**
 * 添加用户自定义例子
 * @param params
 * @param req
 * @returns
 */
export const addUserSample = (params,req:any=request) =>{
    return req({
        url: 'chat/add_user_sample',
        method: 'POST',
        data: params,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
    });
}
src/components/chat/components/playBar/PlayBar.vue
@@ -49,8 +49,10 @@
                class="relative align-bottom set-inputAnswer"
                type="textarea"
                resize="none"
                maxlength="1024"
                :autosize="{ minRows: 1, maxRows: 8 }"
                v-elInputFocus
                show-word-limit
                @keydown="keydownInput"
                @input="inputText"
                v-model="inputValue"
@@ -108,7 +110,13 @@
            @updateInputValue="updateInputValue"
            :isHome="isHome"
        />
        <CommonPhrases v-model:isShow="isShowPhrase" v-show="isShowPhrase" :isHome="isHome"/>
        <CommonPhrases
            v-model:isShow="isShowPhrase"
            v-show="isShowPhrase"
            :isHome="isHome"
            ref="commonPhrasesRef"
            @updateCommonChatInput="updateCommonChatInput"
        />
    </div>
</template>
@@ -429,9 +437,14 @@
//#endregion
//#region ====================== 常用语功能 ======================
const commonPhrasesRef = ref(null);
const commonPhrasesClick = () => {
    isShowPhrase.value = true;
};
const updateCommonChatInput = (val) => {
    inputValue.value = val;
    isShowPhrase.value = false;
};
//#endregion
</script>
<style scoped lang="scss">
src/components/chat/components/playBar/phrase/CommonPhrases.vue
@@ -5,27 +5,27 @@
            <span class="ywifont ywicon-guanbi text-[15px] cursor-pointer text-[#767a97]" @click="closeCommonPhrases"></span>
        </div>
        <div class="container_content">
            <div class="set_phrases" :style="{ height: commonPhrases.length * 40 + 'px' }">
            <div class="set_phrases" :style="{ height: commonPhrases.length * 46 + 'px' }">
                <div class="w-full h-full absolute top-0">
                    <div class="py-0 mt-0 box-border h-full">
                        <div style="overflow-anchor: none" v-for="(item, index) in commonPhrases" :key="index">
                            <div class="phase_item">
                            <div class="phase_item" @click="titleClick(item)">
                                <div class="flex flex-col">
                                    <div class="title">
                                        {{ item.title }}
                                    </div>
                                    <div class="content">
                                    <!-- <div class="content">
                                        {{ item.content }}
                                    </div>
                                    </div> -->
                                </div>
                                <div class="py-2">
                                    <span
                                        class="ywifont ywicon-bianji cursor-pointer text-[#767a97] pt-[4px] pr-[6px] pb-[2px] pl-0 rounded-lg !text-[13px]"
                                        @click="editCommonPhrases(item)"
                                        @click.stop="editCommonPhrases(item)"
                                    ></span>
                                    <span
                                        class="ywifont ywicon-shanchu3 cursor-pointer text-[red] pt-[4px] pr-[6px] pb-[2px] pl-0 rounded-lg"
                                        @click="deleteCommonPhrases(item)"
                                        @click.stop="deleteCommonPhrases(item)"
                                    ></span>
                                </div>
                            </div>
@@ -38,12 +38,20 @@
            <span class="ywifont ywicon-jia text-[15px] cursor-pointer text-[#767a97]"></span>
            <div class="grow">添加常用语</div>
        </div>
        <el-dialog v-model="state.useCommonPhrasesDialog" :title="`${showCommonPhrases}常用语`" width="500" :before-close="handleClose">
            <el-input v-model="state.inputCommonPhrases" :rows="10" type="textarea"></el-input>
        <el-dialog
            v-model="state.useCommonPhrasesDialog"
            :title="`${showCommonPhrases}常用语`"
            width="500"
            :before-close="handleClose"
            style="z-index: 999"
        >
            <el-input v-model="state.inputCommonPhrases" :rows="10" type="textarea" placeholder="自定义常用语"></el-input>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="handleClose">取消</el-button>
                    <el-button type="primary" @click="submitCommonPhrases"> {{ showCommonPhrases }} </el-button>
                    <el-button type="primary" @click="submitCommonPhrases" :disabled="is_input_title">
                        {{ showCommonPhrases }}
                    </el-button>
                </div>
            </template>
        </el-dialog>
@@ -53,35 +61,32 @@
<script setup lang="ts">
import { ElMessageBox } from 'element-plus';
import { computed, reactive, ref } from 'vue';
import { addUserSample } from '/@/api/ai/chat';
import { activeGroupType, activeRoomId, activeSampleId, setRoomConfig } from '/@/stores/chatRoom';
const state = reactive({
    useCommonPhrasesDialog: false,
    show_sample_title: false,
    inputCommonPhrases: '',
    sample_title: null,
});
const commonPhrases = ref([
    {
        id: 1,
        title: '你好,请问有什么可以帮助您?',
        content: '您好,我想咨询一下关于您的订单。',
    },
    {
        id: 2,
        title: '测试1?',
        content: '我想咨询一下关于您的订单。',
    },
    {
        id: 3,
        title: '测试2?',
        content: '我想咨询一下关于您的订单。',
    },
]);
const commonPhrases = ref([]);
const props = defineProps(['isHome']);
const closeCommonPhrases = () => {};
const isShow = defineModel('isShow', {
    type: Boolean,
});
//#region ====================== 是否显示常用语 ======================
const showCommonPhrases = computed(() => {
    return state.show_sample_title == true ? (state.sample_title = '编辑') : (state.sample_title = '添加');
});
const is_input_title = computed(() => {
    return state.inputCommonPhrases == '' ? true : false;
});
const closeCommonPhrases = () => {
    isShow.value = false;
};
//#endregion
//#region ====================== 添加常用语 ======================
//关闭常用语弹窗
const handleClose = () => {
    state.useCommonPhrasesDialog = false;
@@ -94,8 +99,8 @@
};
const editCommonPhrases = (item) => {
    state.useCommonPhrasesDialog = true;
    state.inputCommonPhrases = item.content;
    state.show_sample_title = true;
    state.inputCommonPhrases = item.title;
};
const deleteCommonPhrases = (item) => {
    ElMessageBox.confirm(`你确定要删除常用语吗?<div style="white-space: pre-line;">[${item.title}]</div>`, '提示', {
@@ -108,13 +113,36 @@
    });
};
//提交常用语
const submitCommonPhrases = () => {};
const submitCommonPhrases = async () => {
    const res = await addUserSample({
        question: state.inputCommonPhrases,
        group_type: activeGroupType.value,
    });
    if (res.json_ok) {
        commonPhrases.value.push({
            id: res.sample_id,
            title: state.inputCommonPhrases,
        });
        state.useCommonPhrasesDialog = false;
    }
};
//#endregion
//#region ====================== 常用语到对话框 ======================
const emits = defineEmits<{
    (event: 'updateCommonChatInput', val): void;
}>();
const titleClick = (item) => {
    emits('updateCommonChatInput', item.title);
    setRoomConfig(activeRoomId.value, 'isAnswerByLLM', false);
    activeSampleId.value = item.id;
};
//#endregion
</script>
<style scoped lang="scss">
.container {
    position: absolute;
    width: 100%;
    max-height: 45vh;
    max-height: 40vh;
    padding: 0 8px 8px;
    left: 0px;
    border-radius: 12px;
@@ -123,7 +151,7 @@
    box-shadow: 0px 8px 25px 0px #0000000d;
    display: flex;
    flex-direction: column;
    z-index: 100;
    z-index: 990;
    &_header {
        width: 100%;
        display: flex;
@@ -144,8 +172,9 @@
    }
    &_content {
        width: 100%;
        max-height: 40vh;
        max-height: 35vh;
        height: fit-content;
        overflow-y: auto;
        .set_phrases {
            outline: none;
            overflow-y: auto;
@@ -167,14 +196,17 @@
                }
                .title {
                    font-size: 14px;
                    color: #060607;
                    font-family: PingFang HK;
                    font-weight: 600;
                    color: #8d8e99;
                    font-weight: 400;
                    font-style: normal;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    overflow: hidden;
                    &:hover {
                        color: #060607;
                    }
                }
                .content {
                    font-size: 12px;
                    color: #5e6772;
@@ -200,4 +232,3 @@
    }
}
</style>
import { ElMessageBox } from 'element-plus';