diff --git a/src/components/conversations/ConversationSidebar.tsx b/src/components/conversations/ConversationSidebar.tsx index bd7032a..337dddd 100644 --- a/src/components/conversations/ConversationSidebar.tsx +++ b/src/components/conversations/ConversationSidebar.tsx @@ -5,6 +5,7 @@ import { conversationMapSortList } from '@/stores/conversation' import ConversationSidebarItem from './ConversationSidebarItem' import ConversationSidebarAdd from './ConversationSidebarAdd' import { addConversation } from '@/stores/conversation' +import { showConversationEditModal } from '@/stores/ui' export default () => { const { t } = useI18n() @@ -21,10 +22,9 @@ export default () => { 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 =count?`${setName}(${count + 1})`:`${setName}` + title =count?`${setName}(${count + 1})`:`${setName}${numList.length>0?'(1)':''}` return title } @@ -46,7 +46,8 @@ export default () => { }) if(setName.switch){ - addConversation({name:setNameNum(setName.name, numList)}) + addConversation({name:setNameNum(setName.name, numList),systemInfo:setName.systemInfo}) + showConversationEditModal.set(true) setName.switch=false sessionStorage.setItem('dialogueName',JSON.stringify({name:setName.name,switch:false})) } diff --git a/src/http/api.ts b/src/http/api.ts index a6d6c09..2891613 100644 --- a/src/http/api.ts +++ b/src/http/api.ts @@ -5,7 +5,7 @@ interface Data {} interface ResponseData { code: number; message: string; - data: Array; + data: any; url: string; } diff --git a/src/pages/chat/components/dataList.tsx b/src/pages/chat/components/dataList.tsx index 58b1237..6cfe669 100644 --- a/src/pages/chat/components/dataList.tsx +++ b/src/pages/chat/components/dataList.tsx @@ -8,12 +8,12 @@ import { fetchData } from '../../../http/api' export default () => { // dataItemLists.set([{id:'1'},{id:'2'},{id:'3'},{id:'4'},{id:'5'},{id:'6'}]) const [list, setList] = createStore({ - data: [{ id: '1', Topping: false }, { id: '2', Topping: false }, { id: '3', Topping: false }, { id: '4', Topping: false }, { id: '5', Topping: false }, { id: '6', Topping: false }] + data: [{title:''}] }) - type errorObj={ - show:boolean, - message:string + type errorObj = { + show: boolean, + message: string } let [errorShow, setErrorShow] = createSignal({ @@ -25,12 +25,17 @@ export default () => { fetchData({}, function (data) { if (data.code === 200) { setList('data', () => [...data.data]) + } else { + setErrorFun(data.message) } }, '/chat/api', 'GET'); } //标题 - let dialogueName = '' + let dialogue = { + systemmessage:'', + title:'' + } //新建对话框 const newlyAdded = () => { @@ -64,20 +69,21 @@ export default () => { let [pop, setPop] = createSignal(false) let [popType, setPopType] = createSignal('open') - const popShow = (type: string, e: any, key: number, name: string = '未命名对话') => { + const popShow = (type: string, e: any, key: number, dialogueObj: any = {}) => { setPopType(type) if (type == 'delete') { deleteItem['key'] = key as any deleteItem['e'] = e } - if (type === 'open') dialogueName = name + if (type === 'open') dialogue = dialogueObj setPop(!pop()) } //确认按钮 const determineBtn = () => { if (popType() === 'open') { - sessionStorage.setItem('dialogueName', JSON.stringify({ name: dialogueName, switch: true })) + console.log(dialogue) + sessionStorage.setItem('dialogueName', JSON.stringify({ name: dialogue.title, switch: true,systemInfo:dialogue.systemmessage })) if (isMobile()) { location.pathname = '/' } else { @@ -90,10 +96,11 @@ export default () => { } //显示错误提示 - const setErrorFun=(message:string)=>{ + const setErrorFun = (message: string) => { + // console.log(message) setErrorShow({ message, - show:true + show: true }) } @@ -147,7 +154,9 @@ export default () => { <div class="px-2"> <For each={list.data}> {(instance, i) => ( - <ConversationSidebarItem popShow={popShow} setErrorFun={setErrorFun} instanceData={{ ...instance }} infoList={list.data} key={i as any} setList={setList} /> + <Show when={instance.title}> + <ConversationSidebarItem popShow={popShow} setErrorFun={setErrorFun} instanceData={{ ...instance }} infoList={list.data} key={i as any} setList={setList} /> + </Show> )} </For> </div> diff --git a/src/pages/chat/components/listItem.tsx b/src/pages/chat/components/listItem.tsx index 65d819b..dc6099b 100644 --- a/src/pages/chat/components/listItem.tsx +++ b/src/pages/chat/components/listItem.tsx @@ -8,9 +8,10 @@ type dataList = { } interface Props { - instanceData: Omit<dataList, 'messages'> & { + instanceData: { title?:string, - istop?:number + istop?:number, + uniqid?:string }, key: any, setList: Function, @@ -23,7 +24,7 @@ export default ({ instanceData, key, setList, infoList, popShow,setErrorFun }: P //设置数据 const instanceItem = instanceData - let instance = instanceItem || { id: '', name: '' } + let instance = instanceItem || { id: '', name: '',uniqid:'' } const isTouchDevice = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0 //置顶数据排序 @@ -71,7 +72,7 @@ export default ({ instanceData, key, setList, infoList, popShow,setErrorFun }: P class={[ 'group fi h-10 my-0.5 px-2 gap-2 hv-base rounded-md' ].join(' ')} - + onClick={()=>window.open(`${location.protocol}//${window.location.host}/share/?id=${ instance.uniqid }`)} > <div class="fcc w-8 h-8 rounded-full text-xl shrink-0"> <div class="text-base i-carbon-chat" /> @@ -81,7 +82,7 @@ export default ({ instanceData, key, setList, infoList, popShow,setErrorFun }: P <div class={[isTouchDevice ? '' : 'hidden group-hover:block'].join('')}> <div class="inline-flex p-2 items-center gap-1 rounded-md hv-base" - onClick={() => popShow('open', null, null, instance.title)} + onClick={(e) => {popShow('open', null, null, instance);e.stopPropagation()}} > <div class='add-new-icon'></div> </div> @@ -99,7 +100,7 @@ export default ({ instanceData, key, setList, infoList, popShow,setErrorFun }: P <div class={isTouchDevice ? '' : 'hidden group-hover:block'}> <div class="inline-flex p-2 items-center gap-1 rounded-md hv-base" - onClick={e => popShow('delete', e, key())} + onClick={e => {popShow('delete', e, key());e.stopPropagation()}} > <div class="i-carbon-close" /> </div> diff --git a/src/stores/conversation.ts b/src/stores/conversation.ts index 6193d6c..c893b36 100644 --- a/src/stores/conversation.ts +++ b/src/stores/conversation.ts @@ -55,6 +55,7 @@ export const rebuildConversationStore = async() => { } export const addConversation = action(conversationMap, 'addConversation', (map, instance?: Partial<Conversation>) => { + console.log(conversationMap,instance) const instanceId = instance?.id || `id_${Date.now()}` const conversation: Conversation = { id: instanceId, @@ -62,6 +63,7 @@ export const addConversation = action(conversationMap, 'addConversation', (map, name: instance?.name || '', icon: instance?.icon || '', lastUseTime: Date.now(), + systemInfo:instance?.systemInfo } map.setKey(instanceId, conversation) db.setItem(instanceId, conversation)