Compare commits

..

No commits in common. "44409b2bba92bf0f61d1298d87e356e933785f0b" and "3f8a11e1e09ae1a5235163330c89488b50096d7e" have entirely different histories.

12 changed files with 107 additions and 221 deletions

View File

@ -6,13 +6,12 @@ import ConversationSidebarItem from './ConversationSidebarItem'
import ConversationSidebarAdd from './ConversationSidebarAdd' import ConversationSidebarAdd from './ConversationSidebarAdd'
import { addConversation } from '@/stores/conversation' import { addConversation } from '@/stores/conversation'
import { showConversationEditModal } from '@/stores/ui' import { showConversationEditModal } from '@/stores/ui'
import ChatList from '../../pages/chat/datalist'
export default () => { export default () => {
const { t } = useI18n() const { t } = useI18n()
const $conversationMapSortList = useStore(conversationMapSortList) const $conversationMapSortList = useStore(conversationMapSortList)
//设置副标题数字 //设置副标题数字
const setNameNum = (setName: string, numList: any) => { const setNameNum = (setName: string, numList: any) => {
let list = conversationMapSortList.get() let list = conversationMapSortList.get()
let title = '' let title = ''
@ -25,7 +24,7 @@ export default () => {
count = Math.max(count, Number(num[0].replace('(', '').replace(')', ''))) count = Math.max(count, Number(num[0].replace('(', '').replace(')', '')))
} }
}) })
title = count ? `${setName}(${count + 1})` : `${setName}${numList.length > 0 ? '(1)' : ''}` title =count?`${setName}(${count + 1})`:`${setName}${numList.length>0?'(1)':''}`
return title return title
} }
@ -37,50 +36,46 @@ export default () => {
} }
} }
// onMount(() => { onMount(() => {
// return setTimeout(() => {
// setTimeout(() => { let itemList = conversationMapSortList.get()
// let itemList = conversationMapSortList.get() let setName = JSON.parse(sessionStorage.getItem('dialogueName') as any)||'未命名对话'
// let setName = JSON.parse(sessionStorage.getItem('dialogueName') as any) || '未命名对话' let numList: number[] = []
// let numList: number[] = [] itemList.map((res, i) => {
// itemList.map((res, i) => { if (checkName(res.name, setName.name)) numList.push(i)
// if (checkName(res.name, setName.name)) numList.push(i) })
// })
// if (setName.switch) { if(setName.switch){
// addConversation({ name: setNameNum(setName.name, numList), systemInfo: setName.systemInfo }) addConversation({name:setNameNum(setName.name, numList),systemInfo:setName.systemInfo})
// showConversationEditModal.set(true) showConversationEditModal.set(true)
// setName.switch = false setName.switch=false
// sessionStorage.setItem('dialogueName', JSON.stringify({ name: setName.name, switch: false })) sessionStorage.setItem('dialogueName',JSON.stringify({name:setName.name,switch:false}))
// } }
// }, 1000) }, 1000)
// }) })
return ( return (
<div style={{height:'100vh'}}> <div class="h-full flex flex-col bg-sidebar">
<div class="h-full flex flex-col bg-sidebar" style={{height:'50%',overflow:'auto'}}> <header class="h-14 fi justify-between px-4 text-xs uppercase">
<header class="h-14 fi justify-between px-4 text-xs uppercase"> <p class="px-2">{t('conversations.title')}</p>
<p class="px-2">{t('conversations.title')}</p> <div class="fi gap-1">
<div class="fi gap-1"> {/* <Button
{/* <Button
icon="i-carbon-search" icon="i-carbon-search"
onClick={() => {}} onClick={() => {}}
size="sm" size="sm"
/> */} /> */}
<ConversationSidebarAdd /> <ConversationSidebarAdd />
</div> </div>
</header> </header>
<div class="flex-1 overflow-auto"> <div class="flex-1 overflow-auto">
<div class="px-2"> <div class="px-2">
<For each={$conversationMapSortList()}> <For each={$conversationMapSortList()}>
{instance => ( {instance => (
<ConversationSidebarItem instance={instance} /> <ConversationSidebarItem instance={instance} />
)} )}
</For> </For>
</div>
</div> </div>
</div> </div>
<ChatList></ChatList>
</div> </div>
) )
} }

View File

@ -3,7 +3,6 @@ import { currentConversationId, deleteConversationById } from '@/stores/conversa
import { showConversationSidebar } from '@/stores/ui' import { showConversationSidebar } from '@/stores/ui'
import { useI18n } from '@/hooks' import { useI18n } from '@/hooks'
import type { Conversation } from '@/types/conversation' import type { Conversation } from '@/types/conversation'
import { chatShow } from '@/pages/chat/ts/store'
interface Props { interface Props {
instance: Omit<Conversation, 'messages'> & { instance: Omit<Conversation, 'messages'> & {
@ -17,7 +16,6 @@ export default ({ instance }: Props) => {
const isTouchDevice = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0 const isTouchDevice = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0
const handleClick = () => { const handleClick = () => {
chatShow.set(false)
currentConversationId.set(instance.id) currentConversationId.set(instance.id)
showConversationSidebar.set(false) showConversationSidebar.set(false)
} }

View File

@ -1,4 +1,4 @@
import { Match, Switch, createEffect, Show } from 'solid-js' import { Match, Switch, createEffect,onMount } from 'solid-js'
import { useStore } from '@nanostores/solid' import { useStore } from '@nanostores/solid'
import { conversationMap, currentConversationId } from '@/stores/conversation' import { conversationMap, currentConversationId } from '@/stores/conversation'
import { conversationMessagesMap } from '@/stores/messages' import { conversationMessagesMap } from '@/stores/messages'
@ -10,8 +10,6 @@ import Welcome from './Welcome'
import Continuous from './Continuous' import Continuous from './Continuous'
import Single from './Single' import Single from './Single'
import Image from './Image' import Image from './Image'
import { chatShow } from '@/pages/chat/ts/store'
import Iframe from '@/pages/chat/components/iframe'
export default () => { export default () => {
const { t } = useI18n() const { t } = useI18n()
@ -35,7 +33,7 @@ export default () => {
createEffect(() => { createEffect(() => {
const conversation = currentConversation() const conversation = currentConversation()
const currentDomain = window.location.hostname; const currentDomain = window.location.hostname;
const contentDomain = currentDomain == 'gtering.com' ? 'Gtering.com' : 'Ansnid.Com'; const contentDomain = currentDomain=='gtering.com'?'Gtering.com':'Ansnid.Com';
document.title = conversation ? `${(conversation.name || t('conversations.untitled'))} - ` + contentDomain : contentDomain document.title = conversation ? `${(conversation.name || t('conversations.untitled'))} - ` + contentDomain : contentDomain
const link = document.querySelector("link[rel~='icon']") as HTMLLinkElement const link = document.querySelector("link[rel~='icon']") as HTMLLinkElement
@ -45,45 +43,34 @@ export default () => {
} }
}) })
let chat: any = null
chat = useStore(chatShow)
return ( return (
<> <Switch
<Show when={!chat()}> fallback={(
<Switch <Welcome />
fallback={( )}
<Welcome /> >
)} <Match when={$currentConversationId() && !currentConversationMessages().length}>
> <ConversationEmpty conversation={currentConversation()} />
<Match when={$currentConversationId() && !currentConversationMessages().length}> </Match>
<ConversationEmpty conversation={currentConversation()} /> <Match when={currentBot()?.type === 'chat_continuous'}>
</Match> <Continuous
<Match when={currentBot()?.type === 'chat_continuous'}> conversationId={$currentConversationId()}
<Continuous messages={currentConversationMessages}
conversationId={$currentConversationId()} />
messages={currentConversationMessages} </Match>
/> <Match when={currentBot()?.type === 'chat_single'}>
</Match> <Single
<Match when={currentBot()?.type === 'chat_single'}> conversationId={$currentConversationId()}
<Single messages={currentConversationMessages}
conversationId={$currentConversationId()} />
messages={currentConversationMessages} </Match>
/> <Match when={currentBot()?.type === 'image_generation'}>
</Match> <Image
<Match when={currentBot()?.type === 'image_generation'}> // conversationId={$currentConversationId()}
<Image messages={currentConversationMessages}
// conversationId={$currentConversationId()} // fetching={isLoading() || !isStreaming()}
messages={currentConversationMessages} />
// fetching={isLoading() || !isStreaming()} </Match>
/> </Switch>
</Match>
</Switch>
</Show>
<Show when={chat()}>
<Iframe></Iframe>
</Show>
</>
) )
} }

View File

@ -1,8 +1,7 @@
import type { JSXElement } from 'solid-js' import type { JSXElement } from 'solid-js'
import '../../pages/chat/css/list.css'
interface Props { interface Props {
direction: 'left' | 'right' | 'none' direction: 'left' | 'right'
class?: string class?: string
children: JSXElement children: JSXElement
} }
@ -11,7 +10,6 @@ export default (props: Props) => {
const containerBaseClass = { const containerBaseClass = {
left: 'w-[260px] h-100dvh border-r', left: 'w-[260px] h-100dvh border-r',
right: 'w-[300px] h-100dvh border-l', right: 'w-[300px] h-100dvh border-l',
none:'w-100'
}[props.direction] }[props.direction]
return ( return (

View File

@ -3,16 +3,12 @@ import ConversationSidebarItem from './listItem'
import { createStore } from "solid-js/store"; import { createStore } from "solid-js/store";
import '../css/list.css' import '../css/list.css'
import { fetchData } from '../../../http/api' import { fetchData } from '../../../http/api'
import { addConversation } from '@/stores/conversation'
import { showConversationEditModal } from '@/stores/ui'
import { conversationMapSortList } from '@/stores/conversation'
import { chatShow,uniqid } from '../ts/store';
import { showConversationSidebar } from '@/stores/ui'
export default () => { export default () => {
// dataItemLists.set([{id:'1'},{id:'2'},{id:'3'},{id:'4'},{id:'5'},{id:'6'}]) // dataItemLists.set([{id:'1'},{id:'2'},{id:'3'},{id:'4'},{id:'5'},{id:'6'}])
const [list, setList] = createStore({ const [list, setList] = createStore({
data: [{ title: '' }] data: [{title:''}]
}) })
type errorObj = { type errorObj = {
@ -37,14 +33,14 @@ export default () => {
//标题 //标题
let dialogue = { let dialogue = {
systemmessage: '', systemmessage:'',
title: '' title:''
} }
// //新建对话框 //新建对话框
// const newlyAdded = () => { const newlyAdded = () => {
// window.open(`${location.protocol}//${location.host}`) window.open(`${location.protocol}//${location.host}`)
// } }
//删除记录 //删除记录
let deleteItem = { key: null, e: null } let deleteItem = { key: null, e: null }
@ -83,54 +79,16 @@ export default () => {
setPop(!pop()) setPop(!pop())
} }
//设置副标题数字
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(')', '')))
}
})
title = count ? `${setName}(${count + 1})` : `${setName}${numList.length > 0 ? '(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
}
}
//确认按钮 //确认按钮
const determineBtn = () => { const determineBtn = () => {
if (popType() === 'open') { if (popType() === 'open') {
sessionStorage.setItem('dialogueName', JSON.stringify({ name: dialogue.title, switch: true, systemInfo: dialogue.systemmessage })) console.log(dialogue)
// if (isMobile()) { sessionStorage.setItem('dialogueName', JSON.stringify({ name: dialogue.title, switch: true,systemInfo:dialogue.systemmessage }))
// location.pathname = '/' if (isMobile()) {
// } else { location.pathname = '/'
// newlyAdded() } else {
let itemList = conversationMapSortList.get() newlyAdded()
let setName = JSON.parse(sessionStorage.getItem('dialogueName') as any) || '未命名对话' }
let numList: number[] = []
itemList.map((res, i) => {
if (checkName(res.name, setName.name)) numList.push(i)
})
if (setName.switch) {
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 }))
}
chatShow.set(false)
// }
} else if (popType() === 'delete') { } else if (popType() === 'delete') {
handleDelete(deleteItem['e'] as any, deleteItem['key'] as any) handleDelete(deleteItem['e'] as any, deleteItem['key'] as any)
} }
@ -146,13 +104,6 @@ export default () => {
}) })
} }
//查看记录内容
const chatWatch = (id:string='')=>{
chatShow.set(true)
showConversationSidebar.set(false)
uniqid.set(id)
}
//提示弹窗 //提示弹窗
const ErrorState = () => ( const ErrorState = () => (
<div class='tps-error-box'> <div class='tps-error-box'>
@ -175,7 +126,7 @@ export default () => {
}) })
return ( return (
<div class="h-full flex flex-col bg-sidebar"> <div class="h-full flex flex-col bg-sidebar max-w-350 min-w-260">
<Show when={pop()}> <Show when={pop()}>
<div class='pop center-f'> <div class='pop center-f'>
<div class='center-f text-box'> <div class='center-f text-box'>
@ -199,12 +150,12 @@ export default () => {
<Show when={errorShow().show}> <Show when={errorShow().show}>
<ErrorState /> <ErrorState />
</Show> </Show>
<div class="overflow-auto px-2"> <div class="flex-1 overflow-auto">
<div style={{ width: '100%' }}> <div class="px-2">
<For each={list.data}> <For each={list.data}>
{(instance, i) => ( {(instance, i) => (
<Show when={instance.title}> <Show when={instance.title}>
<ConversationSidebarItem chatWatch={chatWatch} popShow={popShow} setErrorFun={setErrorFun} instanceData={{ ...instance }} infoList={list.data} key={i as any} setList={setList} /> <ConversationSidebarItem popShow={popShow} setErrorFun={setErrorFun} instanceData={{ ...instance }} infoList={list.data} key={i as any} setList={setList} />
</Show> </Show>
)} )}
</For> </For>

View File

@ -1,19 +0,0 @@
import { keys } from 'idb-keyval'
import '../css/list.css'
import { createSignal } from 'solid-js'
import { uniqid } from '@/pages/chat/ts/store'
import { useStore } from '@nanostores/solid'
interface Props {
}
export default () => {
let id: any = ''
id = useStore(uniqid) as any
return (
<div style={{width:'100%',height:'100%'}}>
<iframe src={`https://ansnid.com/share/?id=${id()}`} style={{width:'100%',height:'100%'}}></iframe>
</div>
)
}

View File

@ -17,11 +17,10 @@ interface Props {
setList: Function, setList: Function,
infoList: any, infoList: any,
popShow: Function, popShow: Function,
setErrorFun:Function, setErrorFun:Function
chatWatch:Function
} }
export default ({ instanceData, key, setList, infoList, popShow,setErrorFun,chatWatch }: Props) => { export default ({ instanceData, key, setList, infoList, popShow,setErrorFun }: Props) => {
//设置数据 //设置数据
const instanceItem = instanceData const instanceItem = instanceData
@ -73,7 +72,7 @@ export default ({ instanceData, key, setList, infoList, popShow,setErrorFun,chat
class={[ class={[
'group fi h-10 my-0.5 px-2 gap-2 hv-base rounded-md' 'group fi h-10 my-0.5 px-2 gap-2 hv-base rounded-md'
].join(' ')} ].join(' ')}
onClick={()=>chatWatch(instance.uniqid)} 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="fcc w-8 h-8 rounded-full text-xl shrink-0">
<div class="text-base i-carbon-chat" /> <div class="text-base i-carbon-chat" />

View File

@ -97,21 +97,4 @@
height:10rem; height:10rem;
background:rgba(246, 246, 246, 1); background:rgba(246, 246, 246, 1);
width:100%; width:100%;
}
.chat-list-title{
font-size:0.75rem;
line-height:1rem;
height:3.5rem;
text-transform:uppercase;
padding:0 1rem;
display: flex;
align-items: center;
}
.top-bor{
border-top:1px solid #e9ecef;
}
.chat-list-box{
max-height:;
} }

View File

@ -0,0 +1,21 @@
---
import Layout from '@/layouts/Layout.astro'
import Main from '@/components/Main.astro'
import ConversationSidebar from './components/dataList'
import ModalsLayer from '@/components/ModalsLayer'
import Sidebar from '@/components/ui/Sidebar'
import BuildStores from '@/components/client-only/BuildStores'
import './css/list.css'
---
<Layout title="Ansnid">
<div class="h-100vh w-screen flex">
<Sidebar direction="left" class='w-100'>
<ConversationSidebar client:only="solid-js" />
</Sidebar>
<!-- <Main /> -->
</div>
<!-- <ModalsLayer client:only />
<BuildStores client:only /> -->
</Layout>

View File

@ -1,23 +0,0 @@
import ConversationSidebar from './components/dataList'
import Sidebar from '@/components/ui/Sidebar'
import './css/list.css'
export default () => {
return (
<div class='top-bor' style={{height:'50%',overflow:'auto'}}>
<div class='chat-list-title'>
</div>
<div class="flex">
<Sidebar direction="none" class=''>
<ConversationSidebar />
</Sidebar>
</div>
{/* <ModalsLayer />
<BuildStores/> */}
</div>
)
}

View File

@ -1,3 +0,0 @@
import { atom } from 'nanostores';
export const chatShow=atom(false)
export const uniqid=atom('')

View File

@ -6,7 +6,6 @@ import Settings from '@/components/settings/SettingsSidebar'
import ModalsLayer from '@/components/ModalsLayer' import ModalsLayer from '@/components/ModalsLayer'
import Sidebar from '@/components/ui/Sidebar' import Sidebar from '@/components/ui/Sidebar'
import BuildStores from '@/components/client-only/BuildStores' import BuildStores from '@/components/client-only/BuildStores'
--- ---
<Layout title="Ansnid"> <Layout title="Ansnid">