Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Q
qiyouxue
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
xuchentao
qiyouxue
Commits
22513c25
Commit
22513c25
authored
Aug 14, 2026
by
tao355667
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: keep article page after publishing
parent
e5f96e5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
6 deletions
+49
-6
app.js
public/admin/app.js
+49
-6
No files found.
public/admin/app.js
View file @
22513c25
...
...
@@ -16,6 +16,26 @@ let consultationTeachers = [];
let
staffAccounts
=
[];
let
activeConsultationUser
=
null
;
const
consultationStatusLabels
=
{
unprocessed
:
"未处理"
,
added
:
"已添加"
,
not_added
:
"未添加"
};
const
ADMIN_STATE_KEY
=
"qiyouxue-admin-state"
;
function
readAdminState
()
{
try
{
const
value
=
JSON
.
parse
(
sessionStorage
.
getItem
(
ADMIN_STATE_KEY
)
||
"null"
);
return
value
&&
typeof
value
===
"object"
?
value
:
{};
}
catch
{
return
{};
}
}
function
updateAdminState
(
patch
)
{
try
{
const
next
=
{
...
readAdminState
(),
...
patch
};
if
(
next
.
view
!==
"articles"
)
delete
next
.
editorSlug
;
sessionStorage
.
setItem
(
ADMIN_STATE_KEY
,
JSON
.
stringify
(
next
));
}
catch
{
// Session storage may be unavailable in privacy-restricted browsers.
}
}
async
function
api
(
path
,
options
=
{})
{
const
endpoint
=
path
.
startsWith
(
"/"
)
?
path
:
`/
${
path
}
`
;
...
...
@@ -101,10 +121,21 @@ async function enterApp(user) {
document
.
querySelectorAll
(
".content-role"
).
forEach
((
element
)
=>
element
.
classList
.
toggle
(
"hidden"
,
customerService
));
$
(
"#account-role"
).
textContent
=
admin
?
"管理员账号"
:
operator
?
"运营账号"
:
"客服账号"
;
$
(
"#account-name"
).
textContent
=
user
?.
name
||
""
;
await
showAdminView
(
operator
?
"articles"
:
"consultations"
);
const
rememberedState
=
readAdminState
();
const
initialView
=
operator
?
"articles"
:
customerService
?
"consultations"
:
rememberedState
.
view
||
"consultations"
;
await
showAdminView
(
initialView
);
if
(
admin
||
operator
)
{
await
loadCategories
();
loadArticles
();
if
(
initialView
===
"articles"
&&
rememberedState
.
editorSlug
)
{
try
{
await
openEditor
(
rememberedState
.
editorSlug
);
}
catch
{
updateAdminState
({
editorSlug
:
null
});
await
loadArticles
();
}
}
else
{
await
loadArticles
();
}
}
}
...
...
@@ -118,8 +149,10 @@ const adminViews = {
async
function
showAdminView
(
name
)
{
Object
.
values
(
adminViews
).
forEach
(([
selector
])
=>
hide
(
selector
));
hide
(
"#edit-view"
);
const
allowedName
=
currentUser
?.
role
===
"operator"
?
"articles"
:
name
;
const
view
=
adminViews
[
allowedName
]
||
adminViews
.
consultations
;
const
requestedName
=
currentUser
?.
role
===
"operator"
?
"articles"
:
name
;
const
allowedName
=
adminViews
[
requestedName
]
?
requestedName
:
"consultations"
;
const
view
=
adminViews
[
allowedName
];
updateAdminState
({
view
:
allowedName
});
show
(
view
[
0
]);
$
(
"#page-title"
).
textContent
=
view
[
1
];
$
(
"#page-subtitle"
).
textContent
=
view
[
2
];
...
...
@@ -884,6 +917,7 @@ function setEditorStatus(status) {
async function openEditor(slug) {
editingSlug = slug;
updateAdminState({ view: "
articles
", editorSlug: slug || null });
dirty = false;
fillCategories();
$("
#
preview
").innerHTML = "";
...
...
@@ -962,6 +996,7 @@ $("#article-file").addEventListener("change", async (event) => {
});
$("
#
back
").addEventListener("
click
", () => {
if (dirty && !confirm("
还有未保存的内容,确定返回文章列表吗?
")) return;
updateAdminState({ view: "
articles
", editorSlug: null });
setView(false);
loadArticles();
});
...
...
@@ -979,6 +1014,7 @@ async function save() {
? await api(`/articles/${editingSlug}`, { method: "
PUT
", body: payload() })
: await api("
/
articles
", { method: "
POST
", body: payload() });
editingSlug = result.slug;
updateAdminState({ view: "
articles
", editorSlug: editingSlug });
dirty = false;
setEditorStatus(result.publishStatus);
return result.slug;
...
...
@@ -993,7 +1029,9 @@ $("#edit-form").addEventListener("submit", async (event) => {
} catch (error) { $("
#
message
").textContent = error.message; }
});
$("
#
publish
").addEventListener("
click
", async () => {
$("
#
publish
").addEventListener("
click
", async (event) => {
event.preventDefault();
event.stopPropagation();
$("
#
message
").textContent = "
正在保存草稿…
";
try {
const slug = await save();
...
...
@@ -1009,7 +1047,11 @@ $("#discard").addEventListener("click", async () => {
try {
const result = await api(`/articles/${editingSlug}/draft`, { method: "
DELETE
" });
dirty = false;
if (result.removed) { setView(false); loadArticles(); }
if (result.removed) {
updateAdminState({ view: "
articles
", editorSlug: null });
setView(false);
loadArticles();
}
else await openEditor(editingSlug);
} catch (error) { $("
#
message
").textContent = error.message; }
});
...
...
@@ -1039,6 +1081,7 @@ $("#delete-article").addEventListener("click", async () => {
await runContentAction(`/articles/${editingSlug}`, { method: "
DELETE
" });
dirty = false;
editingSlug = null;
updateAdminState({ view: "
articles
", editorSlug: null });
setView(false);
await loadArticles();
} catch (error) { $("
#
message
").textContent = error.message; }
...
...
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