Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qianjiangb2b
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AI-甘富林
qianjiangb2b
Commits
8ce2079e
Commit
8ce2079e
authored
Jun 18, 2026
by
AI-甘富林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多轮对话记忆前端修复
parent
50510818
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
14 deletions
+39
-14
useConversations.ts
src/hooks/useConversations.ts
+11
-5
ChatPage.tsx
src/pages/ChatPage.tsx
+9
-2
ShopPage.tsx
src/pages/ShopPage.tsx
+9
-2
idGenerator.ts
src/utils/idGenerator.ts
+10
-5
No files found.
src/hooks/useConversations.ts
View file @
8ce2079e
...
@@ -27,11 +27,17 @@ type LocalConversationStore = {
...
@@ -27,11 +27,17 @@ type LocalConversationStore = {
const
LOCAL_CONVERSATION_STORE_KEY
=
'qianjiang_guest_conversations_v1'
;
const
LOCAL_CONVERSATION_STORE_KEY
=
'qianjiang_guest_conversations_v1'
;
const
createLocalId
=
(
prefix
:
string
)
=>
{
const
createLocalId
=
(
_prefix
:
string
)
=>
{
if
(
typeof
crypto
!==
'undefined'
&&
'randomUUID'
in
crypto
)
{
try
{
return
crypto
.
randomUUID
();
if
(
typeof
crypto
!==
'undefined'
&&
'randomUUID'
in
crypto
)
{
}
return
crypto
.
randomUUID
();
return
`
${
prefix
}
_
${
Date
.
now
()}
_
${
Math
.
random
().
toString
(
36
).
slice
(
2
,
10
)}
`
;
}
}
catch
{
/* 非 HTTPS 环境,使用降级方案 */
}
// Fallback: 生成合法 UUID v4 格式(与 makeUUID 一致,保证 DB 兼容)
return
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.
replace
(
/
[
xy
]
/g
,
c
=>
{
const
r
=
Math
.
random
()
*
16
|
0
;
return
(
c
===
'x'
?
r
:
(
r
&
0x3
|
0x8
)).
toString
(
16
);
});
};
};
const
readLocalStore
=
():
LocalConversationStore
=>
{
const
readLocalStore
=
():
LocalConversationStore
=>
{
...
...
src/pages/ChatPage.tsx
View file @
8ce2079e
...
@@ -46,16 +46,23 @@ import { Label } from "@/components/ui/label";
...
@@ -46,16 +46,23 @@ import { Label } from "@/components/ui/label";
const
GUEST_ID_KEY
=
'qianjiang_guest_uuid'
;
const
GUEST_ID_KEY
=
'qianjiang_guest_uuid'
;
let
_guestIdMemoryFallback
:
string
|
null
=
null
;
let
_guestIdMemoryFallback
:
string
|
null
=
null
;
let
_activeConvId
:
string
|
null
=
null
;
// 模块级变量,绕过 React 闭包
let
_activeConvId
:
string
|
null
=
null
;
// 模块级变量,绕过 React 闭包
function
makeUUID
():
string
{
try
{
return
crypto
.
randomUUID
();
}
catch
{
/* 非 HTTPS 环境 */
}
return
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.
replace
(
/
[
xy
]
/g
,
c
=>
{
const
r
=
Math
.
random
()
*
16
|
0
;
return
(
c
===
'x'
?
r
:
(
r
&
0x3
|
0x8
)).
toString
(
16
);
});
}
function
getOrCreateGuestId
():
string
{
function
getOrCreateGuestId
():
string
{
try
{
try
{
const
existing
=
localStorage
.
getItem
(
GUEST_ID_KEY
);
const
existing
=
localStorage
.
getItem
(
GUEST_ID_KEY
);
if
(
existing
)
return
existing
;
if
(
existing
)
return
existing
;
const
id
=
crypto
.
random
UUID
();
const
id
=
make
UUID
();
localStorage
.
setItem
(
GUEST_ID_KEY
,
id
);
localStorage
.
setItem
(
GUEST_ID_KEY
,
id
);
return
id
;
return
id
;
}
catch
{
}
catch
{
// 无痕浏览等场景下 localStorage 不可用,用内存兜底保证同一会话内 ID 不变
// 无痕浏览等场景下 localStorage 不可用,用内存兜底保证同一会话内 ID 不变
if
(
!
_guestIdMemoryFallback
)
_guestIdMemoryFallback
=
crypto
.
random
UUID
();
if
(
!
_guestIdMemoryFallback
)
_guestIdMemoryFallback
=
make
UUID
();
return
_guestIdMemoryFallback
;
return
_guestIdMemoryFallback
;
}
}
}
}
...
...
src/pages/ShopPage.tsx
View file @
8ce2079e
...
@@ -27,15 +27,22 @@ import { callCozeEdge } from "@/utils/cozeClient";
...
@@ -27,15 +27,22 @@ import { callCozeEdge } from "@/utils/cozeClient";
// ─── 访客 ID + 会话 ID 模块级变量(绕过 React 闭包)───
// ─── 访客 ID + 会话 ID 模块级变量(绕过 React 闭包)───
const
GUEST_ID_KEY
=
'qianjiang_guest_uuid'
;
const
GUEST_ID_KEY
=
'qianjiang_guest_uuid'
;
let
_guestIdMemoryFallback
:
string
|
null
=
null
;
let
_guestIdMemoryFallback
:
string
|
null
=
null
;
function
makeUUID
():
string
{
try
{
return
crypto
.
randomUUID
();
}
catch
{
/* 非 HTTPS 环境 */
}
return
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.
replace
(
/
[
xy
]
/g
,
c
=>
{
const
r
=
Math
.
random
()
*
16
|
0
;
return
(
c
===
'x'
?
r
:
(
r
&
0x3
|
0x8
)).
toString
(
16
);
});
}
function
getOrCreateGuestId
():
string
{
function
getOrCreateGuestId
():
string
{
try
{
try
{
const
existing
=
localStorage
.
getItem
(
GUEST_ID_KEY
);
const
existing
=
localStorage
.
getItem
(
GUEST_ID_KEY
);
if
(
existing
)
return
existing
;
if
(
existing
)
return
existing
;
const
id
=
crypto
.
random
UUID
();
const
id
=
make
UUID
();
localStorage
.
setItem
(
GUEST_ID_KEY
,
id
);
localStorage
.
setItem
(
GUEST_ID_KEY
,
id
);
return
id
;
return
id
;
}
catch
{
}
catch
{
if
(
!
_guestIdMemoryFallback
)
_guestIdMemoryFallback
=
crypto
.
random
UUID
();
if
(
!
_guestIdMemoryFallback
)
_guestIdMemoryFallback
=
make
UUID
();
return
_guestIdMemoryFallback
;
return
_guestIdMemoryFallback
;
}
}
}
}
...
...
src/utils/idGenerator.ts
View file @
8ce2079e
...
@@ -3,9 +3,14 @@
...
@@ -3,9 +3,14 @@
* 优先使用 crypto.randomUUID(),不可用时回退到时间戳+随机数
* 优先使用 crypto.randomUUID(),不可用时回退到时间戳+随机数
*/
*/
export
function
generateUUID
():
string
{
export
function
generateUUID
():
string
{
if
(
typeof
crypto
!==
'undefined'
&&
'randomUUID'
in
crypto
)
{
try
{
return
crypto
.
randomUUID
();
if
(
typeof
crypto
!==
'undefined'
&&
'randomUUID'
in
crypto
)
{
}
return
crypto
.
randomUUID
();
// Fallback: timestamp + random string
}
return
`
${
Date
.
now
().
toString
(
36
)}
_
${
Math
.
random
().
toString
(
36
).
slice
(
2
,
10
)}
`
;
}
catch
{
/* 非 HTTPS 环境,使用降级方案 */
}
// Fallback: UUID v4 格式(保证 DB UUID 列兼容)
return
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.
replace
(
/
[
xy
]
/g
,
c
=>
{
const
r
=
Math
.
random
()
*
16
|
0
;
return
(
c
===
'x'
?
r
:
(
r
&
0x3
|
0x8
)).
toString
(
16
);
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment