fix: hide admin buttons when viewing course package via 试看 preview

"试看" (preview) from the storefront should show a read-only view without
admin operations (编辑, 删除, 发布上架, 下架). Add preview=1 query param
to distinguish preview from direct management navigation. Also limit
previewable sections to first one in preview mode, consistent with
non-owner experience.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-02 09:32:33 +08:00
parent 18548cc1a4
commit ba05fc1b3a
2 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ export default defineComponent({
const onPreview = (pkg: CoursePackage) => {
if (isLoggedIn()) {
router.push(`/course/course-package/detail?id=${pkg.id}`);
router.push(`/course/course-package/detail?id=${pkg.id}&preview=1`);
} else {
showDialog({
title: '提示',
+4 -3
View File
@@ -42,7 +42,7 @@
</div>
</div>
</div>
<div class="footer" v-if="isOwner">
<div class="footer" v-if="isOwner && !isPreview">
<van-button v-if="!isActive" type="primary" @click="onEdit">编辑</van-button>
<van-button v-if="!isActive" type="danger" @click="onDelete">删除</van-button>
<van-button v-if="!isActive" type="success" @click="onPublish">发布上架</van-button>
@@ -87,6 +87,7 @@ export default defineComponent({
if (!pkg.value?.created_by || !userStore.current?.hty_id) return false;
return pkg.value.created_by === userStore.current.hty_id;
});
const isPreview = computed(() => route.query.preview === '1');
const loadData = async () => {
const id = route.query.id as string;
@@ -173,7 +174,7 @@ export default defineComponent({
const isPreviewable = (section: CourseSection) => {
if (!section.id) return false;
if (isOwner.value) return true;
if (isOwner.value && !isPreview.value) return true;
return section.id === firstSectionId.value;
};
@@ -192,7 +193,7 @@ export default defineComponent({
onMounted(loadData);
return {
pkg, courseGroups, loading, isActive, isPublished, isOwner, isLoggedIn,
pkg, courseGroups, loading, isActive, isPublished, isOwner, isLoggedIn, isPreview,
onEdit, onDelete, onPublish, onUnpublish, previewSection, goBack,
isPreviewable, handleSectionClick,
};