feat(image-tools): 上传前模板墙——未选图就能看到全部17套模板
- 抽 text-tpls.ts 共享模块(TextTpl/TEXT_TPLS/tplStyle),画布侧栏
模板区与上传前模板墙共用一套数据
- 图片编辑 tab 空态:上传区平铺模板预览墙(真实文案小样+花字样式),
网格置顶、上传提示压成底部一行,min-height 322 保证 17/17 首屏全露出
- chooseTpl:点模板记住 pendingTpl → pickFiles 选图 → PsEditor 新增
autoTpl prop,init 完成后自动 applyTpl(autoTplConsumed 一次性标记,
emit('applied') 回清父状态)
- 底部"点这里选择图片"加 .stop 防容器冒泡双开文件框
- 实测:空态 wall 可见 17/17 首屏无滚动、foot 可见;点高光模板→选图
→自动插入2行(历史「套用模板「黑底黄字·高光」(2行)」)
This commit is contained in:
1 parent
c54799fd89
commit
a12886ea90
4 files changed
+192
-59
No files matched your search
@@ -3,9 +3,11 @@
|
||||
// 图层类型:image(底图) / paint(画笔涂改层) / text(文字层) / fill(色块擦除层)
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { licenseHeaders } from '@/tools/license/license';
|
||||
import { TEXT_TPLS, tplStyle, type TextTpl } from './text-tpls';
|
||||
|
||||
const props = defineProps<{ file: File }>();
|
||||
const emit = defineEmits<{ (e: 'error', msg: string): void }>();
|
||||
const props = defineProps<{ file: File; autoTpl?: TextTpl | null }>();
|
||||
const emit = defineEmits<{ (e: 'error', msg: string): void; (e: 'applied'): void }>();
|
||||
let autoTplConsumed = false; // 上传前模板墙套用一次性标记
|
||||
|
||||
// ---------- 文档状态 ----------
|
||||
const docW = ref(0);
|
||||
@@ -25,32 +27,7 @@ interface TextLayer {
|
||||
badge?: string | null; // 色块底(红底白字类)
|
||||
}
|
||||
|
||||
// ---------- 文字花字模板(成套文案:点击一次插入整组标题+副标题,源自封面模板库文案) ----------
|
||||
interface TextTpl {
|
||||
id: string; name: string; color: string;
|
||||
parts: string[]; // 主标题 → 副标题 → 小字,逐行成组插入
|
||||
grad?: [string, string]; bold?: boolean;
|
||||
stroke?: string; strokeW?: number; shadow?: string; badge?: string;
|
||||
}
|
||||
const TEXT_TPLS: TextTpl[] = [
|
||||
{ id: 'wp', name: '白字黑描边·搞怪', color: '#ffffff', stroke: '#1a1a1a', strokeW: 0.10, bold: true, parts: ['最强拉轰!', '《躲汉子》'] },
|
||||
{ id: 'yp', name: '黄字紫描边·热榜', color: '#ffe14d', stroke: '#7b2cbf', strokeW: 0.10, bold: true, parts: ['B站史上', '点击最高的10首MV'] },
|
||||
{ id: 'wpu', name: '白字紫描边·科普', color: '#ffffff', stroke: '#8e44ad', strokeW: 0.09, bold: true, parts: ['熬夜', '如何科学修仙'] },
|
||||
{ id: 'yc', name: '黄字青描边·美食', color: '#ffeb3b', stroke: '#00e5ff', strokeW: 0.11, bold: true, parts: ['辣到没朋友!川菜', '辣子鸡 · 水煮肉片'] },
|
||||
{ id: 'rb', name: '红底白字·冠军', color: '#ffffff', badge: '#e53935', bold: true, parts: ['收视冠军?'] },
|
||||
{ id: 'bb', name: '蓝底白字·力作', color: '#ffffff', badge: '#1e88e5', bold: true, parts: ['翻身力作?'] },
|
||||
{ id: 'kb', name: '黑底黄字·高光', color: '#ffd600', badge: '#212121', bold: true, parts: ['秀翻全场!', 'ALL KILL!'] },
|
||||
{ id: 'gd', name: '鎏金渐变·打卡', color: '#ffcc00', grad: ['#fff3b0', '#ff9500'], stroke: '#7a4a00', strokeW: 0.07, bold: true, parts: ['香浓拿铁', '网红打卡'] },
|
||||
{ id: 'fg', name: '烈焰渐变·社会', color: '#ff4d4f', grad: ['#ff5252', '#ff8f00'], stroke: '#7a1f00', strokeW: 0.08, bold: true, parts: ['男子医院体验', '竟查出有孕在身'] },
|
||||
{ id: 'ws', name: '白字投影·Vlog', color: '#ffffff', shadow: 'rgba(0,0,0,0.75)', bold: true, parts: ['Vlog', '我的旅行日记'] },
|
||||
{ id: 'cb', name: '青字黑描边·热梗', color: '#18ffff', stroke: '#00364d', strokeW: 0.10, bold: true, parts: ['年轻人', '耗子尾汁'] },
|
||||
{ id: 'pb', name: '粉底白字·生活', color: '#ffffff', badge: '#ec407a', bold: true, parts: ['我的', '上海日租生活'] },
|
||||
{ id: 'ol', name: '空心描边·搞笑', color: 'rgba(255,255,255,0.06)', stroke: '#2962ff', strokeW: 0.10, bold: true, parts: ['你根本', '不会上厕所'] },
|
||||
{ id: 'gb', name: '荧光绿描边·攻略', color: '#76ff03', stroke: '#1b3d00', strokeW: 0.09, bold: true, parts: ['角色养成攻略', '躺平吧 赶紧的'] },
|
||||
{ id: 'wp2', name: '白字蓝边·职场', color: '#ffffff', stroke: '#0d47a1', strokeW: 0.10, bold: true, parts: ['合法打工人', 'SLAVE の一天 DAILY'] },
|
||||
{ id: 'gd2', name: '金渐变·B站', color: '#ffe082', grad: ['#fffde7', '#ffb300'], stroke: '#5d4037', strokeW: 0.07, bold: true, parts: ['B站', '崛起的十二年'] },
|
||||
{ id: 'rb2', name: '红底白字·毕业', color: '#ffffff', badge: '#c62828', bold: true, parts: ['毕业后找工作', '如此简单!'] },
|
||||
];
|
||||
|
||||
interface FillLayer {
|
||||
id: string; type: 'fill'; name: string; visible: boolean; opacity: number;
|
||||
x: number; y: number; w: number; h: number; color: string;
|
||||
@@ -777,35 +754,7 @@ function applyTpl(t: TextTpl): void {
|
||||
scheduleRender();
|
||||
}
|
||||
|
||||
// 模板 chip 的 CSS 预览样式
|
||||
function tplStyle(t: TextTpl): Record<string, string> {
|
||||
const s: Record<string, string> = { fontWeight: '700' };
|
||||
if (t.badge) {
|
||||
s.background = t.badge;
|
||||
s.color = t.color;
|
||||
s.padding = '4px 7px';
|
||||
s.borderRadius = '5px';
|
||||
}
|
||||
else if (t.grad) {
|
||||
s.backgroundImage = `linear-gradient(90deg, ${t.grad[0]}, ${t.grad[1]})`;
|
||||
s.backgroundClip = 'text';
|
||||
s.WebkitBackgroundClip = 'text';
|
||||
s.color = 'transparent';
|
||||
if (t.stroke) {
|
||||
s.WebkitTextStroke = `1px ${t.stroke}`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
s.color = t.color;
|
||||
if (t.stroke) {
|
||||
s.WebkitTextStroke = `${Math.max(1, Math.round((t.strokeW ?? 0.08) * 16))}px ${t.stroke}`;
|
||||
}
|
||||
}
|
||||
if (t.shadow) {
|
||||
s.textShadow = `2px 2px 3px ${t.shadow}`;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
function removeLayer(id: string): void {
|
||||
const i = layers.value.findIndex(l => l.id === id);
|
||||
@@ -1853,6 +1802,12 @@ async function init(): Promise<void> {
|
||||
hist.value = [];
|
||||
hIdx.value = -1;
|
||||
commit('打开图片');
|
||||
// 上传前模板墙选中的模板:图片就绪后立即套入画布(实时可见)
|
||||
if (props.autoTpl && !autoTplConsumed) {
|
||||
autoTplConsumed = true; // 只套一次
|
||||
applyTpl(props.autoTpl);
|
||||
emit('applied');
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.file, () => {
|
||||
|
||||
@@ -9,6 +9,7 @@ import GenHistory from '@/tools/gen-history/GenHistory.vue';
|
||||
import { useGenHistory } from '@/tools/gen-history/gen-history';
|
||||
import { getMachineId, licenseHeaders } from '@/tools/license/license';
|
||||
import PsEditor from './PsEditor.vue';
|
||||
import { TEXT_TPLS, tplStyle, type TextTpl } from './text-tpls';
|
||||
|
||||
prepareZXingModule({ overrideWasmUrl: wasmUrl });
|
||||
const genHist = useGenHistory('image-tools');
|
||||
@@ -278,6 +279,13 @@ function mosaicPos(e: MouseEvent) {
|
||||
|
||||
// ---------- 图片编辑(PS 风格编辑器,组件内自带工具栏/图层/历史) ----------
|
||||
const psEditor = ref<{ exportDoc: () => Promise<{ blob: Blob; detail: string; w: number; h: number }> } | null>(null);
|
||||
// 上传前模板墙:先点模板记住,选图后由 PsEditor 自动套入
|
||||
const pendingTpl = ref<TextTpl | null>(null);
|
||||
|
||||
function chooseTpl(t: TextTpl) {
|
||||
pendingTpl.value = t;
|
||||
pickFiles(); // 选完图自动套用该模板
|
||||
}
|
||||
|
||||
function onPsError(msg: string) {
|
||||
errorMsg.value = msg;
|
||||
@@ -935,7 +943,7 @@ onUnmounted(() => {
|
||||
<div
|
||||
v-if="!tab.noFile"
|
||||
class="it-upload"
|
||||
:class="{ active: dragActive, has: files.length }"
|
||||
:class="{ active: dragActive, has: files.length, wall: !files.length && tab.key === 'edit' }"
|
||||
@click="!files.length && pickFiles()"
|
||||
@dragover.prevent="dragActive = true"
|
||||
@dragleave.prevent="dragActive = false"
|
||||
@@ -954,7 +962,7 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="files.length && tab.key === 'edit'">
|
||||
<PsEditor ref="psEditor" :file="files[0]" @error="onPsError" />
|
||||
<PsEditor ref="psEditor" :file="files[0]" :auto-tpl="pendingTpl" @error="onPsError" @applied="pendingTpl = null" />
|
||||
</template>
|
||||
<template v-else-if="files.length">
|
||||
<div class="it-files">
|
||||
@@ -966,6 +974,28 @@ onUnmounted(() => {
|
||||
<a v-if="tab.multi" href="javascript:;" class="it-add-more" @click.stop="pickFiles">+ 继续添加</a>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="tab.key === 'edit'">
|
||||
<div class="it-tpl-wall">
|
||||
<div class="it-tpl-wall-t">
|
||||
✨ 文字模板({{ TEXT_TPLS.length }} 套成套文案)
|
||||
<span class="it-tpl-wall-sub">点模板选图 → 整组标题自动套入画布</span>
|
||||
</div>
|
||||
<div class="it-tpl-wall-grid">
|
||||
<button
|
||||
v-for="t in TEXT_TPLS"
|
||||
:key="t.id"
|
||||
class="it-tpl-chip"
|
||||
:title="`${t.name}:${t.parts.join(' / ')} — 点击后选图自动套用`"
|
||||
@click.stop="chooseTpl(t)"
|
||||
>
|
||||
<span class="it-tpl-chip-txt" :style="tplStyle(t)">{{ t.parts[0] }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="it-tpl-wall-foot" @click.stop="pickFiles">
|
||||
⬆️ 点这里选择图片({{ MAX_MB }} MB 内 · 本地处理不上传)
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="it-upload-icon">⬆️</div>
|
||||
<div class="it-upload-big">
|
||||
@@ -1321,6 +1351,13 @@ onUnmounted(() => {
|
||||
padding: 10px 14px;
|
||||
}
|
||||
|
||||
&.wall {
|
||||
justify-content: flex-start;
|
||||
padding: 12px 14px;
|
||||
overflow-y: auto;
|
||||
min-height: 322px;
|
||||
}
|
||||
|
||||
.it-upload-icon {
|
||||
font-size: 36px;
|
||||
}
|
||||
@@ -1337,6 +1374,84 @@ onUnmounted(() => {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.it-tpl-wall {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.it-tpl-wall-t {
|
||||
width: 100%;
|
||||
margin-bottom: 8px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
opacity: 0.9;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
|
||||
.it-tpl-wall-sub {
|
||||
font-size: 11.5px;
|
||||
font-weight: 400;
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.it-tpl-wall-grid {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.it-tpl-wall-foot {
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px dashed rgba(128, 128, 128, 0.3);
|
||||
font-size: 12.5px;
|
||||
text-align: center;
|
||||
opacity: 0.65;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.12s;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.it-tpl-chip {
|
||||
height: 40px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.32);
|
||||
border-radius: 8px;
|
||||
background: rgba(128, 128, 128, 0.07);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 6px;
|
||||
transition: border-color 0.12s, transform 0.12s;
|
||||
|
||||
&:hover {
|
||||
border-color: #2563eb;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.it-tpl-chip-txt {
|
||||
font-size: 11.5px;
|
||||
line-height: 1.12;
|
||||
text-align: center;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
|
||||
.it-files {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// 文字花字模板(成套文案):画布内与上传前模板墙共用
|
||||
// ---------- 文字花字模板(共享:PsEditor 画布内 + image-tools 上传前模板墙) ----------(成套文案:点击一次插入整组标题+副标题,源自封面模板库文案) ----------
|
||||
export interface TextTpl {
|
||||
id: string; name: string; color: string;
|
||||
parts: string[]; // 主标题 → 副标题 → 小字,逐行成组插入
|
||||
grad?: [string, string]; bold?: boolean;
|
||||
stroke?: string; strokeW?: number; shadow?: string; badge?: string;
|
||||
}
|
||||
export const TEXT_TPLS: TextTpl[] = [
|
||||
{ id: 'wp', name: '白字黑描边·搞怪', color: '#ffffff', stroke: '#1a1a1a', strokeW: 0.10, bold: true, parts: ['最强拉轰!', '《躲汉子》'] },
|
||||
{ id: 'yp', name: '黄字紫描边·热榜', color: '#ffe14d', stroke: '#7b2cbf', strokeW: 0.10, bold: true, parts: ['B站史上', '点击最高的10首MV'] },
|
||||
{ id: 'wpu', name: '白字紫描边·科普', color: '#ffffff', stroke: '#8e44ad', strokeW: 0.09, bold: true, parts: ['熬夜', '如何科学修仙'] },
|
||||
{ id: 'yc', name: '黄字青描边·美食', color: '#ffeb3b', stroke: '#00e5ff', strokeW: 0.11, bold: true, parts: ['辣到没朋友!川菜', '辣子鸡 · 水煮肉片'] },
|
||||
{ id: 'rb', name: '红底白字·冠军', color: '#ffffff', badge: '#e53935', bold: true, parts: ['收视冠军?'] },
|
||||
{ id: 'bb', name: '蓝底白字·力作', color: '#ffffff', badge: '#1e88e5', bold: true, parts: ['翻身力作?'] },
|
||||
{ id: 'kb', name: '黑底黄字·高光', color: '#ffd600', badge: '#212121', bold: true, parts: ['秀翻全场!', 'ALL KILL!'] },
|
||||
{ id: 'gd', name: '鎏金渐变·打卡', color: '#ffcc00', grad: ['#fff3b0', '#ff9500'], stroke: '#7a4a00', strokeW: 0.07, bold: true, parts: ['香浓拿铁', '网红打卡'] },
|
||||
{ id: 'fg', name: '烈焰渐变·社会', color: '#ff4d4f', grad: ['#ff5252', '#ff8f00'], stroke: '#7a1f00', strokeW: 0.08, bold: true, parts: ['男子医院体验', '竟查出有孕在身'] },
|
||||
{ id: 'ws', name: '白字投影·Vlog', color: '#ffffff', shadow: 'rgba(0,0,0,0.75)', bold: true, parts: ['Vlog', '我的旅行日记'] },
|
||||
{ id: 'cb', name: '青字黑描边·热梗', color: '#18ffff', stroke: '#00364d', strokeW: 0.10, bold: true, parts: ['年轻人', '耗子尾汁'] },
|
||||
{ id: 'pb', name: '粉底白字·生活', color: '#ffffff', badge: '#ec407a', bold: true, parts: ['我的', '上海日租生活'] },
|
||||
{ id: 'ol', name: '空心描边·搞笑', color: 'rgba(255,255,255,0.06)', stroke: '#2962ff', strokeW: 0.10, bold: true, parts: ['你根本', '不会上厕所'] },
|
||||
{ id: 'gb', name: '荧光绿描边·攻略', color: '#76ff03', stroke: '#1b3d00', strokeW: 0.09, bold: true, parts: ['角色养成攻略', '躺平吧 赶紧的'] },
|
||||
{ id: 'wp2', name: '白字蓝边·职场', color: '#ffffff', stroke: '#0d47a1', strokeW: 0.10, bold: true, parts: ['合法打工人', 'SLAVE の一天 DAILY'] },
|
||||
{ id: 'gd2', name: '金渐变·B站', color: '#ffe082', grad: ['#fffde7', '#ffb300'], stroke: '#5d4037', strokeW: 0.07, bold: true, parts: ['B站', '崛起的十二年'] },
|
||||
{ id: 'rb2', name: '红底白字·毕业', color: '#ffffff', badge: '#c62828', bold: true, parts: ['毕业后找工作', '如此简单!'] },
|
||||
];
|
||||
|
||||
// 模板 chip 的 CSS 预览样式
|
||||
export function tplStyle(t: TextTpl): Record<string, string> {
|
||||
const s: Record<string, string> = { fontWeight: '700' };
|
||||
if (t.badge) {
|
||||
s.background = t.badge;
|
||||
s.color = t.color;
|
||||
s.padding = '4px 7px';
|
||||
s.borderRadius = '5px';
|
||||
}
|
||||
else if (t.grad) {
|
||||
s.backgroundImage = `linear-gradient(90deg, ${t.grad[0]}, ${t.grad[1]})`;
|
||||
s.backgroundClip = 'text';
|
||||
s.WebkitBackgroundClip = 'text';
|
||||
s.color = 'transparent';
|
||||
if (t.stroke) {
|
||||
s.WebkitTextStroke = `1px ${t.stroke}`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
s.color = t.color;
|
||||
if (t.stroke) {
|
||||
s.WebkitTextStroke = `${Math.max(1, Math.round((t.strokeW ?? 0.08) * 16))}px ${t.stroke}`;
|
||||
}
|
||||
}
|
||||
if (t.shadow) {
|
||||
s.textShadow = `2px 2px 3px ${t.shadow}`;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
Reference in new issue
Block a user