yinbangzhong
2024-08-27 361d46d0e2a9c5f795f766ed819037faef612167
src/views/sessionManager/index.vue
@@ -99,55 +99,101 @@
                        backgroundColor:
                          theme === 'light' ? '#ffffff' : '#000000',
                      }"
                      style="border: none; display: inline"
                      v-for="(item, tipIndex) in tipMatch(sessionDetail)"
                      style="border: none;"
                      v-for="(breakContent, breakIndex) in breakLine(sessionDetail.content)"
                    >
                      <span v-if="tipIndex == 0">
                        {{ sessionDetail.content.substring(0, item.index) }}
                        <a-tooltip
                          background-color="#3491FA"
                          :content="
                            getTipContent(messagenList.reference, index)
                          "
                        >
                          <img
                            style="width: 20px; height: 20px"
                            :src="tipImage"
                          />
                        </a-tooltip>
                      </span>
                      <span v-else>
                        {{
                          sessionDetail.content.substring(
                            item.preIndex + item.item.length,
                            item.index
                          )
                        }}
                        <a-tooltip
                          background-color="#3491FA"
                          :content="
                            getTipContent(messagenList.reference, index)
                          "
                        >
                          <img
                            style="width: 20px; height: 20px"
                            :src="tipImage"
                          />
                        </a-tooltip>
                      </span>
                    </div>
                  </a-card>
                  <a-card v-else>
                    <div
                      :class="{ chatItemAnswer: theme === 'light' }"
                      :style="{
                      <div
                        :class="{ chatItemAnswer: theme === 'light' }"
                        :style="{
                        backgroundColor:
                          theme === 'light' ? '#ffffff' : '#000000',
                      }"
                        style="border: none;"
                      v-if="isExistTip(breakContent)">
                        <div
                          :class="{ chatItemAnswer: theme === 'light' }"
                          :style="{
                        backgroundColor:
                          theme === 'light' ? '#ffffff' : '#000000',
                      }"
                          style="border: none;"
                          v-for="(item, tipIndex) in tipMatch(breakContent)"
                        >
                      <span v-if="tipIndex == 0">
                        {{ breakContent.substring(0, item.index) }}
                        <a-tooltip
                          background-color="#3491FA"
                          :content="
                            getTipContent(messagenList.reference, index)
                          "
                        >
                          <img
                            style="width: 20px; height: 20px"
                            :src="tipImage"
                          />
                        </a-tooltip>
                      </span>
                          <span v-else-if ="tipIndex == item.len - 1">
                        {{
                              breakContent.substring(
                                item.preIndex + item.item.length,
                                item.index
                              )
                            }}
                        <a-tooltip
                          background-color="#3491FA"
                          :content="
                            getTipContent(messagenList.reference, index)
                          "
                        >
                          <img
                            style="width: 20px; height: 20px"
                            :src="tipImage"
                          />
                        </a-tooltip>
                        {{
                              breakContent.substring(item.index+5)
                            }}
                      </span>
                          <span v-else>
                        {{
                              breakContent.substring(
                                item.preIndex + item.item.length,
                                item.index
                              )
                            }}
                        <a-tooltip
                          background-color="#3491FA"
                          :content="
                            getTipContent(messagenList.reference, index)
                          "
                        >
                          <img
                            style="width: 20px; height: 20px"
                            :src="tipImage"
                          />
                        </a-tooltip>
                      </span>
                        </div>
                      </div>
                      <div v-else>
                        {{ breakContent }}
                      </div>
                    </div>
                  </a-card>
                  <a-card v-else>
                    <a-textarea
                      readonly
                      auto-size
                      v-model="sessionDetail.content"
                      :class="{ chatItemAnswer: theme === 'light' }"
                      :style="{
                      backgroundColor:
                        theme === 'light' ? '#ffffff' : '#000000',
                    }"
                      style="border: none"
                    >
                      {{ sessionDetail.content }}
                    </div>
                    </a-textarea>
                  </a-card>
                </template>
                <!-- <div>{{ sessionDetail.role === 'assistant' }}</div> -->
@@ -456,6 +502,7 @@
  import docx from '@/views/dmx/knowledgeLib/components/docx.vue';
  import excel from '@/views/dmx/knowledgeLib/components/excel.vue';
  import txtPdf from '@/views/dmx/knowledgeLib/components/txtPdf.vue';
  import { is } from "immutable";
  // const url = ref('../../assets/session/PDF.png');
@@ -539,13 +586,20 @@
    }
  };
  const tipMatch = (session: any): any[] => {
  const breakLine = (message: string): string[] => {
    //按\n分割字符串
    let arr = message.split('\n');
    return arr
  }
  const tipMatch = (msg: string): any[] => {
    //match session.content中的##[0-9]$$的索引
    let indexs: any[] = [];
    let preTip = 0;
    session.content.match(/##([0-9]+)\$\$/g)?.map((item) => {
      let i = session.content.indexOf(item);
      indexs.push({ index: i, item: item, preIndex: preTip });
    let matches=msg.match(/##([0-9]+)\$\$/g)
    matches?.map((item) => {
      let i = msg.indexOf(item);
      indexs.push({ index: i, item: item, preIndex: preTip, len: matches.length });
      preTip = i;
    });
    return indexs;