From 3f8a11e1e09ae1a5235163330c89488b50096d7e Mon Sep 17 00:00:00 2001 From: luJianJun <2587063613@qq.com> Date: Mon, 21 Aug 2023 12:14:31 +0800 Subject: [PATCH] =?UTF-8?q?pnpm-=E7=B3=BB=E7=BB=9F=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../conversations/ConversationSidebar.tsx | 7 +++-- src/http/api.ts | 2 +- src/pages/chat/components/dataList.tsx | 31 ++++++++++++------- src/pages/chat/components/listItem.tsx | 13 ++++---- src/stores/conversation.ts | 2 ++ 5 files changed, 34 insertions(+), 21 deletions(-) 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 () => {
{(instance, i) => ( - + + + )}
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 & { + 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 }`)} >
@@ -81,7 +82,7 @@ export default ({ instanceData, key, setList, infoList, popShow,setErrorFun }: P
popShow('open', null, null, instance.title)} + onClick={(e) => {popShow('open', null, null, instance);e.stopPropagation()}} >
@@ -99,7 +100,7 @@ export default ({ instanceData, key, setList, infoList, popShow,setErrorFun }: P
popShow('delete', e, key())} + onClick={e => {popShow('delete', e, key());e.stopPropagation()}} >
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) => { + 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)