diff --git a/src/components/conversations/ConversationSidebar.tsx b/src/components/conversations/ConversationSidebar.tsx index c700cee..de63aea 100644 --- a/src/components/conversations/ConversationSidebar.tsx +++ b/src/components/conversations/ConversationSidebar.tsx @@ -1,14 +1,53 @@ -import { For } from 'solid-js' +import { For, onMount } from 'solid-js' import { useStore } from '@nanostores/solid' import { useI18n } from '@/hooks' import { conversationMapSortList } from '@/stores/conversation' import ConversationSidebarItem from './ConversationSidebarItem' import ConversationSidebarAdd from './ConversationSidebarAdd' +import { addConversation } from '@/stores/conversation' export default () => { const { t } = useI18n() const $conversationMapSortList = useStore(conversationMapSortList) + //设置副标题数字 + const setNameNum = (setName: string, numList: any) => { + let list = conversationMapSortList.get() + let title = '' + let count = 0 + numList.map((res: number) => { + let regex1 = new RegExp("" + setName + '\\(\\d+\\)', 'g') + let seachText = list[res].name.match(regex1) || 'null' + let num = seachText[0].match(/\(\d+\)/g) || 'null' + if (num !== 'null') { + count = Math.max(count, Number(num[0].replace('(', '').replace(')', ''))) + console.log(count, Number(num[0].replace('(', '').replace(')', ''))) + } + }) + title = `${setName}(${count + 1})` + return title + } + + //查重 + const checkName = (name: string, setName: string) => { + let setNameReg = new RegExp(setName, 'g') + if (setNameReg.test(name) && name.replace(/\(\d+\)/g, '') === setName) { + return true + } + } + + onMount(() => { + setTimeout(() => { + let itemList = conversationMapSortList.get() + let setName = '1' + let numList: number[] = [] + itemList.map((res, i) => { + if (checkName(res.name, setName)) numList.push(i) + }) + addConversation({name:setNameNum(setName, numList)}) + }, 1000) + }) + return (