feat:作业纸
This commit is contained in:
@@ -41,6 +41,11 @@ Component({
|
||||
type: Object,
|
||||
value: {},
|
||||
},
|
||||
/** 页面可指定发布弹窗的默认裁剪模式,未指定时沿用仅裁头部。 */
|
||||
defaultCropMode: {
|
||||
type: String,
|
||||
value: 'header-only',
|
||||
},
|
||||
},
|
||||
|
||||
data: {
|
||||
@@ -83,7 +88,7 @@ Component({
|
||||
formSubtitle: meta?.subtitle ?? '',
|
||||
formTags: meta?.tags?.join(', ') ?? '',
|
||||
formStatus: meta?.status ?? 'draft',
|
||||
formCropMode: 'header-only', // 默认裁剪头部
|
||||
formCropMode: this.properties.defaultCropMode,
|
||||
formQuality: DEBUG_PUBLISH_DEFAULT_QUALITY,
|
||||
formWidth: DEBUG_PUBLISH_DEFAULT_WIDTH,
|
||||
});
|
||||
|
||||
@@ -152,7 +152,7 @@
|
||||
bindchange="onWidthChange" />
|
||||
</view>
|
||||
<text class="debug-publish-tools__hint">
|
||||
默认按文档规则裁掉页眉和页脚,并尽量压缩到 {{maxSizeKB}}KB 内。
|
||||
按所选裁剪模式处理图片,并尽量压缩到 {{maxSizeKB}}KB 内。
|
||||
</text>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// };
|
||||
|
||||
/** 当前应用版本号;profile 页和首页公告共用 */
|
||||
export const APP_VERSION = '3.4.0';
|
||||
export const APP_VERSION = '3.6.0';
|
||||
|
||||
export const defaultPrintConfig: PrintConfig = {
|
||||
// header: 'LogoImage',
|
||||
|
||||
@@ -1,26 +1,72 @@
|
||||
import type { WorksheetDefinition } from './types';
|
||||
|
||||
export const PAPER_SHEET_WORKSHEET_DEFINITIONS = [
|
||||
/** 业务条目与绘制方式分离;颜色等用户参数不另建 worksheet。 */
|
||||
export const PAPER_TYPES = [
|
||||
{ id: 'tian', name: '田字格', desc: '汉字练习' },
|
||||
{ id: 'mi', name: '米字格', desc: '书法练习' },
|
||||
{ id: 'square', name: '方格', desc: '书法练字纸' },
|
||||
{ id: 'four-line', name: '四线三格', desc: '拼音 / 字母' },
|
||||
{ id: 'letter', name: '信纸', desc: '横线信笺' },
|
||||
{ id: 'horizontal', name: '横线', desc: '横线本' },
|
||||
{ id: 'vertical', name: '竖线', desc: '竖排书写' },
|
||||
{ id: 'dictation-hanzi', name: '汉字听写', desc: '田字格 + 订正栏' },
|
||||
{
|
||||
id: 'paper-sheet',
|
||||
icon: 'draw-o',
|
||||
title: '作业纸',
|
||||
subtitle: '田字格 / 方格 / 信纸等多种作业纸一键打印',
|
||||
ageMin: 3,
|
||||
ageMax: 12,
|
||||
difficulty: 1,
|
||||
tags: [
|
||||
'作业纸',
|
||||
'田字格',
|
||||
'米字格',
|
||||
'方格',
|
||||
'四线三格',
|
||||
'信纸',
|
||||
'横线',
|
||||
'竖线',
|
||||
'听写',
|
||||
'作业登记表',
|
||||
],
|
||||
sortOrder: 50,
|
||||
id: 'dictation-pinyin',
|
||||
name: '拼音/英语听写',
|
||||
desc: '四线三格 + 订正栏',
|
||||
},
|
||||
] as const satisfies ReadonlyArray<WorksheetDefinition>;
|
||||
{ id: 'homework-log', name: '作业登记表', desc: '分科登记' },
|
||||
] as const;
|
||||
|
||||
export type PaperType = (typeof PAPER_TYPES)[number]['id'];
|
||||
|
||||
/** 原综合入口始终保留,不重分配历史收藏和统计。 */
|
||||
export const PAPER_SHEET_WORKSHEET_ID = 'paper-sheet';
|
||||
|
||||
export interface PaperSheetDefinition extends WorksheetDefinition {
|
||||
rendererKey: 'paper-sheet';
|
||||
renderConfig: { paperType?: PaperType };
|
||||
}
|
||||
|
||||
export const PAPER_SHEET_WORKSHEET_DEFINITIONS: ReadonlyArray<PaperSheetDefinition> =
|
||||
[
|
||||
{
|
||||
id: PAPER_SHEET_WORKSHEET_ID,
|
||||
rendererKey: 'paper-sheet',
|
||||
renderConfig: {},
|
||||
icon: 'draw-o',
|
||||
title: '作业纸',
|
||||
subtitle: '田字格 / 方格 / 信纸等多种作业纸一键打印',
|
||||
ageMin: 3,
|
||||
ageMax: 12,
|
||||
difficulty: 1,
|
||||
tags: [
|
||||
'作业纸',
|
||||
'田字格',
|
||||
'米字格',
|
||||
'方格',
|
||||
'四线三格',
|
||||
'信纸',
|
||||
'横线',
|
||||
'竖线',
|
||||
'听写',
|
||||
'作业登记表',
|
||||
],
|
||||
sortOrder: 50,
|
||||
},
|
||||
...PAPER_TYPES.map(
|
||||
(paper, index): PaperSheetDefinition => ({
|
||||
id: `paper-${paper.id}`,
|
||||
rendererKey: 'paper-sheet',
|
||||
renderConfig: { paperType: paper.id },
|
||||
icon: 'draw-o',
|
||||
title: paper.name,
|
||||
subtitle: `${paper.desc},一键生成打印`,
|
||||
ageMin: 3,
|
||||
ageMax: 12,
|
||||
difficulty: 1,
|
||||
tags: ['作业纸', paper.name, paper.desc],
|
||||
sortOrder: 51 + index,
|
||||
}),
|
||||
),
|
||||
];
|
||||
|
||||
@@ -77,7 +77,7 @@ export const HOME_NOTICES: HomeNotice[] = [
|
||||
},
|
||||
{
|
||||
id: `update-${APP_VERSION}`,
|
||||
text: `${APP_VERSION} 上线:新增幼儿认识时钟,连线练习题`,
|
||||
text: `${APP_VERSION} 上线:新增作业纸`,
|
||||
path: '/mathPages/clockReading/clockReading?id=clock-connect',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -134,18 +134,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
.home-hero-placeholder {
|
||||
margin: @section-gap @page-padding-x 0;
|
||||
height: 450rpx;
|
||||
border-radius: 40rpx;
|
||||
background: rgba(50, 46, 37, 0.04);
|
||||
/** 紧凑预览轮播:按发布时仅裁头部后的比例展示,标题悬浮于图内。 */
|
||||
.home-hero-gallery {
|
||||
margin-top: 16rpx;
|
||||
background: radial-gradient(ellipse at center, #f3e8cc 0%, @bg-page 70%);
|
||||
}
|
||||
|
||||
/** 首页顶部「精选」swiper 轮播 */
|
||||
.home-hero-swiper {
|
||||
margin-top: 16rpx;
|
||||
width: 100%;
|
||||
height: 450rpx;
|
||||
// 单张宽 750 - 156 * 2 - 16 * 2 = 406rpx;裁头后预览约高 500rpx。
|
||||
// 包含上下阴影留白,不再给副标题、年龄等信息预留高度。
|
||||
height: 548rpx;
|
||||
}
|
||||
|
||||
.home-hero-swiper-item {
|
||||
@@ -153,115 +152,134 @@
|
||||
}
|
||||
|
||||
.home-hero-card-wrap {
|
||||
padding: 24rpx;
|
||||
padding: 16rpx 16rpx 28rpx;
|
||||
box-sizing: border-box;
|
||||
transition: transform 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94),
|
||||
opacity 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
||||
transform: scale(0.9);
|
||||
opacity: 0.5;
|
||||
transform-origin: center center;
|
||||
transform: translateY(12rpx) scale(0.88);
|
||||
opacity: 0.55;
|
||||
transition:
|
||||
transform 0.45s ease,
|
||||
opacity 0.45s ease;
|
||||
}
|
||||
|
||||
.home-hero-card-wrap--active {
|
||||
transform: scale(1);
|
||||
transform: translateY(0) scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.home-hero-card {
|
||||
width: 100%;
|
||||
border-radius: 32rpx;
|
||||
overflow: visible;
|
||||
position: relative;
|
||||
border-radius: 16rpx;
|
||||
overflow: hidden;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 10rpx 28rpx rgba(50, 46, 37, 0.08);
|
||||
box-shadow:
|
||||
0 12rpx 30rpx rgba(96, 75, 33, 0.12),
|
||||
0 2rpx 6rpx rgba(96, 75, 33, 0.06);
|
||||
}
|
||||
|
||||
.home-hero-card__top {
|
||||
height: 260rpx;
|
||||
width: 100%;
|
||||
height: 0;
|
||||
// 与 debugPublish 的 header-only 一致:595 × (842 - 110)。
|
||||
padding-top: 123.02521%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
/* 顶部背景用自身圆角裁切,替代 card 的 overflow: hidden */
|
||||
border-top-left-radius: 32rpx;
|
||||
border-top-right-radius: 32rpx;
|
||||
overflow: hidden;
|
||||
border-bottom: 1rpx solid rgba(50, 46, 37, 0.08);
|
||||
background: #f5edd8;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.home-hero-card__cover {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
object-fit: cover;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.home-hero-card__fallback {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 24rpx;
|
||||
background: #fffdf7;
|
||||
}
|
||||
|
||||
.home-hero-card__icon {
|
||||
font-size: 96rpx;
|
||||
line-height: 1;
|
||||
font-size: 100rpx;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.home-hero-card__badge {
|
||||
.home-hero-card__title-overlay {
|
||||
position: absolute;
|
||||
top: 24rpx;
|
||||
right: 24rpx;
|
||||
padding: 8rpx 18rpx;
|
||||
border-radius: 999rpx;
|
||||
background: rgba(50, 46, 37, 0.12);
|
||||
font-size: 22rpx;
|
||||
color: @text-title;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.home-hero-card__body {
|
||||
padding: 28rpx @page-padding-inner-x 30rpx;
|
||||
}
|
||||
|
||||
.home-hero-card__title-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
/* 允许 flex 子项在文本过长时正确截断 */
|
||||
min-width: 0;
|
||||
left: 12rpx;
|
||||
right: 12rpx;
|
||||
bottom: 12rpx;
|
||||
padding: 10rpx 16rpx;
|
||||
border-radius: 12rpx;
|
||||
background: rgba(255, 252, 244, 0.94);
|
||||
box-shadow: 0 2rpx 12rpx rgba(50, 46, 37, 0.08);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.home-hero-card__title {
|
||||
font-size: 34rpx;
|
||||
line-height: 1.35;
|
||||
display: block;
|
||||
color: @text-title;
|
||||
font-size: 28rpx;
|
||||
line-height: 40rpx;
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
/* 标题与 meta 同行:超出后省略号(避免高度抖动) */
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.home-hero-card__sub {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.4;
|
||||
color: @text-secondary;
|
||||
/* 第二行:超出后省略号 */
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
.home-hero-pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16rpx;
|
||||
height: 32rpx;
|
||||
}
|
||||
|
||||
.home-hero-pagination__dots {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.home-hero-card__meta {
|
||||
margin: 0;
|
||||
font-size: 22rpx;
|
||||
.home-hero-pagination__target {
|
||||
min-width: 32rpx;
|
||||
height: 40rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.home-hero-pagination__dot {
|
||||
width: 8rpx;
|
||||
height: 8rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #d5c9ad;
|
||||
transition:
|
||||
width 0.3s ease,
|
||||
background 0.3s ease;
|
||||
}
|
||||
|
||||
.home-hero-pagination__dot--active {
|
||||
width: 28rpx;
|
||||
background: @text-title;
|
||||
}
|
||||
|
||||
.home-hero-pagination__count {
|
||||
color: @text-gray;
|
||||
/* meta 也做单行截断,防止极端长文本把布局挤爆 */
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
font-size: 20rpx;
|
||||
line-height: 28rpx;
|
||||
}
|
||||
|
||||
.home-section-panel {
|
||||
@@ -477,7 +495,6 @@
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
.home-page .category-tabs {
|
||||
background: @bg-page;
|
||||
}
|
||||
@@ -512,11 +529,11 @@
|
||||
pointer-events: none;
|
||||
|
||||
.home-hero-card__top {
|
||||
background: #f3efe5;
|
||||
animation: home-skeleton-pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.home-hero-card__title,
|
||||
.home-hero-card__sub {
|
||||
.home-hero-card__title {
|
||||
background: #e8e2d5;
|
||||
border-radius: 8rpx;
|
||||
color: transparent;
|
||||
@@ -527,11 +544,6 @@
|
||||
width: 50%;
|
||||
height: 36rpx;
|
||||
}
|
||||
|
||||
.home-hero-card__sub {
|
||||
width: 70%;
|
||||
height: 26rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.home-hot-card--skeleton {
|
||||
@@ -558,4 +570,4 @@
|
||||
width: 65%;
|
||||
height: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,6 +279,19 @@ Page({
|
||||
this.setData({ heroSwiperCurrent: e.detail.current });
|
||||
},
|
||||
|
||||
/** 指示点与手势共用 swiper current,单张内容不自动轮播。 */
|
||||
onTapHeroDot(e: WechatMiniprogram.TouchEvent) {
|
||||
const index = Number(e.currentTarget.dataset.index);
|
||||
if (
|
||||
this.data.loading ||
|
||||
!Number.isInteger(index) ||
|
||||
index < 0 ||
|
||||
index >= this.data.featuredItems.length
|
||||
)
|
||||
return;
|
||||
this.setData({ heroSwiperCurrent: index });
|
||||
},
|
||||
|
||||
onTabChange(e: WechatMiniprogram.CustomEvent) {
|
||||
const id = e.detail.id as string | undefined;
|
||||
if (!id) return;
|
||||
|
||||
@@ -59,63 +59,76 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<swiper
|
||||
class="home-hero-swiper"
|
||||
previous-margin="80rpx"
|
||||
next-margin="80rpx"
|
||||
circular="{{featuredItems.length > 1 && !loading}}"
|
||||
autoplay="{{!loading}}"
|
||||
interval="{{4000}}"
|
||||
duration="{{600}}"
|
||||
easing-function="easeInOutCubic"
|
||||
bindchange="onHeroSwiperChange">
|
||||
<swiper-item
|
||||
wx:for="{{featuredItems}}"
|
||||
wx:key="id"
|
||||
class="home-hero-swiper-item">
|
||||
<view
|
||||
class="home-hero-card-wrap {{heroSwiperCurrent === index ? 'home-hero-card-wrap--active' : ''}}">
|
||||
<view
|
||||
wx:if="{{loading || featuredItems.length > 0}}"
|
||||
class="home-hero-gallery">
|
||||
<!-- 按发布时仅裁页眉后的画幅展示,标题悬浮,不额外占用卡片高度。 -->
|
||||
<swiper
|
||||
class="home-hero-swiper"
|
||||
previous-margin="156rpx"
|
||||
next-margin="156rpx"
|
||||
current="{{heroSwiperCurrent}}"
|
||||
circular="{{featuredItems.length > 1 && !loading}}"
|
||||
autoplay="{{featuredItems.length > 1 && !loading}}"
|
||||
interval="{{5200}}"
|
||||
duration="{{500}}"
|
||||
easing-function="easeInOutCubic"
|
||||
bindchange="onHeroSwiperChange">
|
||||
<swiper-item
|
||||
wx:for="{{featuredItems}}"
|
||||
wx:key="id"
|
||||
class="home-hero-swiper-item">
|
||||
<view
|
||||
class="home-hero-card {{item.skeleton ? 'home-hero-card--skeleton' : ''}}"
|
||||
data-title="{{item.title}}"
|
||||
data-path="{{item.path}}"
|
||||
bindtap="{{item.skeleton ? '' : 'onTapFeatured'}}">
|
||||
<view class="home-hero-card__top">
|
||||
<image
|
||||
wx:if="{{!item.skeleton && item.previewImg}}"
|
||||
class="home-hero-card__cover"
|
||||
src="{{item.previewImg}}"
|
||||
mode="aspectFill" />
|
||||
<text
|
||||
wx:if="{{!item.skeleton && !item.previewImg}}"
|
||||
class="home-hero-card__icon"
|
||||
>{{item.icon}}</text
|
||||
>
|
||||
<text
|
||||
wx:if="{{item.badge}}"
|
||||
class="home-hero-card__badge"
|
||||
>{{item.badge}}</text
|
||||
>
|
||||
</view>
|
||||
<view class="home-hero-card__body">
|
||||
<view class="home-hero-card__title-row">
|
||||
class="home-hero-card-wrap {{heroSwiperCurrent === index ? 'home-hero-card-wrap--active' : ''}}">
|
||||
<view
|
||||
class="home-hero-card {{item.skeleton ? 'home-hero-card--skeleton' : ''}}"
|
||||
data-title="{{item.title}}"
|
||||
data-path="{{item.path}}"
|
||||
bindtap="{{item.skeleton ? '' : 'onTapFeatured'}}">
|
||||
<view class="home-hero-card__top">
|
||||
<image
|
||||
wx:if="{{!item.skeleton && item.previewImg}}"
|
||||
class="home-hero-card__cover"
|
||||
src="{{item.previewImg}}"
|
||||
mode="aspectFit" />
|
||||
<view
|
||||
wx:if="{{!item.skeleton && !item.previewImg}}"
|
||||
class="home-hero-card__fallback">
|
||||
<text class="home-hero-card__icon"
|
||||
>{{item.icon}}</text
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
<view class="home-hero-card__title-overlay">
|
||||
<text class="home-hero-card__title"
|
||||
>{{item.title}}</text
|
||||
>
|
||||
<text
|
||||
wx:if="{{!item.skeleton}}"
|
||||
class="home-hero-card__meta"
|
||||
>{{item.ageBand}}·{{item.difficulty}}</text
|
||||
>
|
||||
</view>
|
||||
<text class="home-hero-card__sub"
|
||||
>{{item.subtitle}}</text
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view
|
||||
wx:if="{{!loading && featuredItems.length > 1}}"
|
||||
class="home-hero-pagination">
|
||||
<view class="home-hero-pagination__dots">
|
||||
<view
|
||||
wx:for="{{featuredItems}}"
|
||||
wx:key="id"
|
||||
class="home-hero-pagination__target"
|
||||
data-index="{{index}}"
|
||||
bindtap="onTapHeroDot"
|
||||
aria-role="button"
|
||||
aria-label="{{'查看第' + (index + 1) + '张练习纸'}}">
|
||||
<view
|
||||
class="home-hero-pagination__dot {{heroSwiperCurrent === index ? 'home-hero-pagination__dot--active' : ''}}" />
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<text class="home-hero-pagination__count"
|
||||
>{{heroSwiperCurrent + 1}} / {{featuredItems.length}}</text
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="home-section-panel">
|
||||
<view class="home-section-head">
|
||||
|
||||
@@ -1,53 +1,42 @@
|
||||
import type { DebugPublishMeta } from '../../utils/debugPublish';
|
||||
import { inferGradeFromAge } from '../../utils/debugPublish';
|
||||
import { PAPER_SHEET_WORKSHEET_DEFINITIONS } from '../../config/worksheets/papers';
|
||||
import {
|
||||
PAPER_SHEET_WORKSHEET_DEFINITIONS,
|
||||
PAPER_SHEET_WORKSHEET_ID,
|
||||
PAPER_TYPES,
|
||||
type PaperType,
|
||||
} from '../../config/worksheets/papers';
|
||||
|
||||
type PaperSheetWorksheetRow =
|
||||
(typeof PAPER_SHEET_WORKSHEET_DEFINITIONS)[number];
|
||||
export { PAPER_SHEET_WORKSHEET_ID, type PaperType };
|
||||
export const PAPER_TYPE_OPTIONS = PAPER_TYPES;
|
||||
|
||||
const WORKSHEET_BY_ID = Object.fromEntries(
|
||||
PAPER_SHEET_WORKSHEET_DEFINITIONS.map((m) => [m.id, m]),
|
||||
) as Record<string, PaperSheetWorksheetRow>;
|
||||
const WORKSHEET_BY_ID = new Map(
|
||||
PAPER_SHEET_WORKSHEET_DEFINITIONS.map((entry) => [entry.id, entry]),
|
||||
);
|
||||
|
||||
export const PAPER_SHEET_WORKSHEET_ID = PAPER_SHEET_WORKSHEET_DEFINITIONS[0].id;
|
||||
|
||||
/** 纸张类型 id */
|
||||
export type PaperType =
|
||||
| 'tian'
|
||||
| 'mi'
|
||||
| 'square'
|
||||
| 'four-line'
|
||||
| 'letter'
|
||||
| 'horizontal'
|
||||
| 'vertical'
|
||||
| 'dictation-hanzi'
|
||||
| 'dictation-pinyin'
|
||||
| 'homework-log';
|
||||
|
||||
export interface PaperTypeOption {
|
||||
id: PaperType;
|
||||
name: string;
|
||||
/** 次要说明 */
|
||||
desc: string;
|
||||
/** 只接收已注册条目;旧综合入口继续支持 type,并兼容分享中的 mode。 */
|
||||
export function resolvePaperEntry(options: {
|
||||
id?: string;
|
||||
type?: string;
|
||||
mode?: string;
|
||||
}) {
|
||||
const id = options.id || PAPER_SHEET_WORKSHEET_ID;
|
||||
const entry = WORKSHEET_BY_ID.get(id);
|
||||
if (!entry) throw new Error('当前作业纸暂不可用,请更新小程序');
|
||||
const legacyType = options.type || options.mode;
|
||||
const paperType =
|
||||
entry.renderConfig.paperType ||
|
||||
(legacyType && isValidPaperType(legacyType)
|
||||
? legacyType
|
||||
: DEFAULT_PAPER_TYPE);
|
||||
return { entry, paperType };
|
||||
}
|
||||
|
||||
/** 纸张类型选项(展示顺序与用户需求一致) */
|
||||
export const PAPER_TYPE_OPTIONS: PaperTypeOption[] = [
|
||||
{ id: 'tian', name: '田字格', desc: '汉字练习' },
|
||||
{ id: 'mi', name: '米字格', desc: '书法练习' },
|
||||
{ id: 'square', name: '方格', desc: '书法练字纸' },
|
||||
{ id: 'four-line', name: '四线三格', desc: '拼音 / 字母' },
|
||||
{ id: 'letter', name: '信纸', desc: '横线信笺' },
|
||||
{ id: 'horizontal', name: '横线', desc: '横线本' },
|
||||
{ id: 'vertical', name: '竖线', desc: '竖排书写' },
|
||||
{ id: 'dictation-hanzi', name: '汉字听写', desc: '田字格 + 订正栏' },
|
||||
{
|
||||
id: 'dictation-pinyin',
|
||||
name: '拼音/英语听写',
|
||||
desc: '四线三格 + 订正栏',
|
||||
},
|
||||
{ id: 'homework-log', name: '作业登记表', desc: '分科登记' },
|
||||
];
|
||||
export function getWorksheetIdForPaperType(paperType: PaperType): string {
|
||||
return PAPER_SHEET_WORKSHEET_DEFINITIONS.find(
|
||||
(entry) => entry.renderConfig.paperType === paperType,
|
||||
)!.id;
|
||||
}
|
||||
|
||||
export interface PaperColorOption {
|
||||
id: string;
|
||||
@@ -75,16 +64,16 @@ export function isValidPaperType(id: string): id is PaperType {
|
||||
}
|
||||
|
||||
export function getModeInfo(id: string) {
|
||||
const m = WORKSHEET_BY_ID[id];
|
||||
const m = WORKSHEET_BY_ID.get(id);
|
||||
return m ? { title: m.title, desc: m.subtitle } : undefined;
|
||||
}
|
||||
|
||||
export function isValidMode(id: string): boolean {
|
||||
return id in WORKSHEET_BY_ID;
|
||||
return WORKSHEET_BY_ID.has(id);
|
||||
}
|
||||
|
||||
export function getPublishMetaByMode(id: string): DebugPublishMeta | null {
|
||||
const m = WORKSHEET_BY_ID[id];
|
||||
const m = WORKSHEET_BY_ID.get(id);
|
||||
if (!m) return null;
|
||||
return {
|
||||
id: m.id,
|
||||
|
||||
@@ -8,9 +8,16 @@ import {
|
||||
getModeInfo,
|
||||
getPublishMetaByMode,
|
||||
isValidPaperType,
|
||||
resolvePaperEntry,
|
||||
getWorksheetIdForPaperType,
|
||||
type PaperType,
|
||||
} from './paperSheet.config';
|
||||
import { createPage, type CanvasDataState } from '../../base/pageMixin';
|
||||
import {
|
||||
createPage,
|
||||
getPageCommonMethods,
|
||||
type CanvasDataState,
|
||||
} from '../../base/pageMixin';
|
||||
import { getWorksheet } from '../../services/content-api';
|
||||
import { defaultShareConfig } from '../../config/config';
|
||||
import type { DebugPublishMeta } from '../../utils/debugPublish';
|
||||
import {
|
||||
@@ -20,6 +27,10 @@ import {
|
||||
} from '../../utils/favorites';
|
||||
|
||||
const pageInfoLookup = getModeInfo;
|
||||
const commonMethods = getPageCommonMethods({
|
||||
pageInfoLookup,
|
||||
shareConfig: defaultShareConfig,
|
||||
});
|
||||
|
||||
type PageData = CanvasDataState & {
|
||||
worksheetId: string;
|
||||
@@ -28,6 +39,8 @@ type PageData = CanvasDataState & {
|
||||
selectedPaperType: PaperType;
|
||||
selectedColor: string;
|
||||
isPreviewFavorite: boolean;
|
||||
isWorksheetReady: boolean;
|
||||
favoriteLoading: boolean;
|
||||
isDevEnv: boolean;
|
||||
debugPublishVisible: boolean;
|
||||
debugPublishLoading: boolean;
|
||||
@@ -42,6 +55,8 @@ createPage(
|
||||
boxWidth: 0,
|
||||
drawService: null as PaperDrawService | null,
|
||||
_favoritedMap: {} as Record<string, boolean>,
|
||||
_entryRequest: 0,
|
||||
_favoriteVersions: {} as Record<string, number>,
|
||||
|
||||
data: {
|
||||
pageTitle: '作业纸',
|
||||
@@ -54,28 +69,77 @@ createPage(
|
||||
selectedPaperType: DEFAULT_PAPER_TYPE,
|
||||
selectedColor: DEFAULT_PAPER_COLOR,
|
||||
isPreviewFavorite: false,
|
||||
isWorksheetReady: false,
|
||||
favoriteLoading: false,
|
||||
isDevEnv: false,
|
||||
debugPublishVisible: false,
|
||||
debugPublishLoading: false,
|
||||
debugPublishMeta: null,
|
||||
} as unknown as PageData,
|
||||
|
||||
onLoad(options: { id?: string; type?: string }) {
|
||||
async onLoad(options: { id?: string; type?: string; mode?: string }) {
|
||||
this.syncDebugPublishEnv();
|
||||
|
||||
const initialType =
|
||||
options.type && isValidPaperType(options.type)
|
||||
? (options.type as PaperType)
|
||||
: DEFAULT_PAPER_TYPE;
|
||||
|
||||
this.setData({
|
||||
selectedPaperType: initialType,
|
||||
});
|
||||
|
||||
this.initPageInfo(PAPER_SHEET_WORKSHEET_ID, '作业纸');
|
||||
await this.openEntry(options);
|
||||
this.loadFavoritedMap();
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
this._entryRequest++;
|
||||
},
|
||||
|
||||
/** 开发版直接预览已注册配置以制作封面;体验/正式版切换前校验公开状态。 */
|
||||
async openEntry(options: {
|
||||
id?: string;
|
||||
type?: string;
|
||||
mode?: string;
|
||||
}) {
|
||||
const request = ++this._entryRequest;
|
||||
this.setData({
|
||||
isWorksheetReady: false,
|
||||
hasContent: false,
|
||||
// 换纸张即丢弃旧发布表单,防止旧条目元数据配上新封面。
|
||||
debugPublishVisible: false,
|
||||
debugPublishMeta: null,
|
||||
});
|
||||
try {
|
||||
const { entry, paperType } = resolvePaperEntry(options);
|
||||
// 草稿在公开详情中固定为 404;开发版使用本地注册配置,不通过失败请求判断预览权限。
|
||||
if (!this.data.isDevEnv) {
|
||||
const remote = await getWorksheet(entry.id);
|
||||
if (
|
||||
entry.id !== PAPER_SHEET_WORKSHEET_ID &&
|
||||
(remote.rendering?.rendererKey !== entry.rendererKey ||
|
||||
remote.rendering?.paperType !== paperType)
|
||||
) {
|
||||
throw new Error('作业纸配置暂不可用,请更新小程序');
|
||||
}
|
||||
}
|
||||
if (request !== this._entryRequest) return;
|
||||
this.setData({
|
||||
worksheetId: entry.id,
|
||||
selectedPaperType: paperType,
|
||||
// 综合入口分享保留所选纸张;独立条目由 ID 唯一确定纸张类型。
|
||||
currentMode:
|
||||
entry.id === PAPER_SHEET_WORKSHEET_ID
|
||||
? paperType
|
||||
: entry.id,
|
||||
isPreviewFavorite: this._favoritedMap[entry.id] === true,
|
||||
isWorksheetReady: true,
|
||||
});
|
||||
this.initPageInfo(entry.id, entry.title);
|
||||
await this.drawCanvas();
|
||||
} catch (error) {
|
||||
if (request !== this._entryRequest) return;
|
||||
wx.showToast({
|
||||
title:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: '作业纸加载失败',
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onCanvasReady(e: WechatMiniprogram.CustomEvent) {
|
||||
this.initCanvasFromComponent(e.detail, {
|
||||
createDrawService: (
|
||||
@@ -93,23 +157,35 @@ createPage(
|
||||
},
|
||||
|
||||
async drawCanvas() {
|
||||
if (!this.drawService) return;
|
||||
if (!this.drawService || !this.data.isWorksheetReady) return;
|
||||
const request = this._entryRequest;
|
||||
try {
|
||||
await (this.drawService as PaperDrawService).draw(
|
||||
this.data.selectedPaperType,
|
||||
this.data.selectedColor,
|
||||
);
|
||||
this.setData({ hasContent: true });
|
||||
if (
|
||||
request === this._entryRequest &&
|
||||
this.data.isWorksheetReady
|
||||
)
|
||||
this.setData({ hasContent: true });
|
||||
} catch (err) {
|
||||
console.error('paperSheet draw failed', err);
|
||||
this.setData({ hasContent: false });
|
||||
if (request === this._entryRequest)
|
||||
this.setData({ hasContent: false });
|
||||
}
|
||||
},
|
||||
|
||||
onSelectPaperType(e: WechatMiniprogram.TouchEvent) {
|
||||
const id = e.currentTarget.dataset.id as PaperType | undefined;
|
||||
if (!id || id === this.data.selectedPaperType) return;
|
||||
this.setData({ selectedPaperType: id }, () => this.drawCanvas());
|
||||
const id = e.currentTarget.dataset.id as string | undefined;
|
||||
if (!id || !isValidPaperType(id)) return;
|
||||
const worksheetId = getWorksheetIdForPaperType(id);
|
||||
if (
|
||||
worksheetId === this.data.worksheetId &&
|
||||
this.data.isWorksheetReady
|
||||
)
|
||||
return;
|
||||
return this.openEntry({ id: worksheetId });
|
||||
},
|
||||
|
||||
onSelectColor(e: WechatMiniprogram.TouchEvent) {
|
||||
@@ -124,33 +200,77 @@ createPage(
|
||||
|
||||
onShare() {},
|
||||
|
||||
async onPreviewFavorite() {
|
||||
const next = !this.data.isPreviewFavorite;
|
||||
this.setData({ isPreviewFavorite: next });
|
||||
const id = this.data.worksheetId;
|
||||
if (id) {
|
||||
this._favoritedMap[id] = next;
|
||||
if (next) {
|
||||
addFavorite(id);
|
||||
} else {
|
||||
removeFavorite(id);
|
||||
}
|
||||
async exportToPrint() {
|
||||
if (!this.data.isWorksheetReady || !this.data.hasContent) return;
|
||||
return commonMethods.exportToPrint.call(this);
|
||||
},
|
||||
|
||||
async onShareSuccess() {
|
||||
if (!this.data.isWorksheetReady || !this.data.hasContent) {
|
||||
this.setData({ showShareDialog: false });
|
||||
return;
|
||||
}
|
||||
return commonMethods.onShareSuccess.call(this);
|
||||
},
|
||||
|
||||
/** 请求失败不显示收藏成功,且响应只更新操作时的条目。 */
|
||||
async onPreviewFavorite() {
|
||||
if (!this.data.isWorksheetReady || this.data.favoriteLoading)
|
||||
return;
|
||||
const id = this.data.worksheetId;
|
||||
const next = !this.data.isPreviewFavorite;
|
||||
this._favoriteVersions[id] = (this._favoriteVersions[id] || 0) + 1;
|
||||
this.setData({ favoriteLoading: true });
|
||||
try {
|
||||
const ok = await (next ? addFavorite(id) : removeFavorite(id));
|
||||
if (ok) {
|
||||
this._favoritedMap[id] = next;
|
||||
if (this.data.worksheetId === id)
|
||||
this.setData({ isPreviewFavorite: next });
|
||||
}
|
||||
wx.showToast({
|
||||
title: ok
|
||||
? next
|
||||
? '收藏成功'
|
||||
: '已取消收藏'
|
||||
: '收藏操作失败,请重试',
|
||||
icon: 'none',
|
||||
});
|
||||
} finally {
|
||||
this.setData({ favoriteLoading: false });
|
||||
}
|
||||
wx.showToast({
|
||||
title: next ? '收藏成功' : '已取消收藏',
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
|
||||
async loadFavoritedMap() {
|
||||
const ids = [PAPER_SHEET_WORKSHEET_ID];
|
||||
this._favoritedMap = await batchCheckFavorited(ids);
|
||||
if (this._favoritedMap[this.data.worksheetId]) {
|
||||
this.setData({ isPreviewFavorite: true });
|
||||
const ids = [
|
||||
PAPER_SHEET_WORKSHEET_ID,
|
||||
...PAPER_TYPE_OPTIONS.map((paper) =>
|
||||
getWorksheetIdForPaperType(paper.id),
|
||||
),
|
||||
];
|
||||
const versions = { ...this._favoriteVersions };
|
||||
try {
|
||||
const map = await batchCheckFavorited(ids);
|
||||
// 慢速初次查询不能覆盖查询期间完成的收藏操作。
|
||||
for (const id of ids) {
|
||||
if (versions[id] === this._favoriteVersions[id])
|
||||
this._favoritedMap[id] = map[id] === true;
|
||||
}
|
||||
this.setData({
|
||||
isPreviewFavorite:
|
||||
this._favoritedMap[this.data.worksheetId] === true,
|
||||
});
|
||||
} catch {
|
||||
// 收藏加载失败不阻止预览;后续操作仍以服务端写入结果为准。
|
||||
}
|
||||
},
|
||||
|
||||
getWorksheetStatsId(): string {
|
||||
return this.data.worksheetId;
|
||||
},
|
||||
|
||||
getPublishMeta(): DebugPublishMeta {
|
||||
if (!this.data.isWorksheetReady) throw new Error('请先加载作业纸');
|
||||
const meta = getPublishMetaByMode(this.data.worksheetId);
|
||||
if (!meta) {
|
||||
throw new Error('当前题型配置不存在');
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<nav-bar title="作业纸" />
|
||||
<nav-bar title="{{pageTitle}}" />
|
||||
|
||||
<view class="ps-page">
|
||||
<view class="ps-main">
|
||||
<preview-card
|
||||
id="previewCard"
|
||||
showRefresh="{{true}}"
|
||||
showFavorite="{{true}}"
|
||||
showFavorite="{{isWorksheetReady && !favoriteLoading}}"
|
||||
favorited="{{isPreviewFavorite}}"
|
||||
bind:canvas-ready="onCanvasReady"
|
||||
bind:refresh="onPreviewRefresh"
|
||||
@@ -63,6 +63,7 @@
|
||||
<debug-publish-tools
|
||||
wx:if="{{isDevEnv && hasContent}}"
|
||||
id="debugPublishTools"
|
||||
defaultCropMode="none"
|
||||
visible="{{debugPublishVisible}}"
|
||||
loading="{{debugPublishLoading}}"
|
||||
meta="{{debugPublishMeta}}"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { PaperType } from '../config/worksheets/papers';
|
||||
import { apiRequest } from './api-request';
|
||||
|
||||
/** 小程序使用的公开接口字段,不复用旧云集合的 _id 和管理配置。 */
|
||||
@@ -10,6 +11,7 @@ export interface ApiCategory {
|
||||
}
|
||||
|
||||
export interface ApiWorksheet {
|
||||
rendering?: { rendererKey: 'paper-sheet'; paperType: PaperType };
|
||||
id: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
|
||||
Reference in New Issue
Block a user