Files
print-tag-system/plugin/preview/mount.ts
T
funjia ef41d98838 feat: 新增 plugin/ 插件化形态(funjia.print-tag)+ 可选 SN 条码/二维码
把本工程的标签排版能力改造成 FunjiaUI 远端插件,放进 plugin/ 子目录,
与原独立 Web 版并存(两者功能一致,模板/版面/打印行为逐项对齐)。

- 入口从 createApp().mount() 改为 activate(ctx) + ctx.addRoute,注册 1 菜单 / 1 路由 / 2 命令
- 11 个模板的渲染收敛成 SpecTag,差异集中到 templates/registry.ts(字段/选项/默认值原样保留)
- 店铺名 / 电话从写死改为可配置,记忆在插件私有存储
- 内置二维码图片改为打包 data URL —— 远端插件没有自己的 public/
- 去掉 @headlessui/vue(换原生 select)与 Tailwind,样式类名统一 pt- 前缀避免污染宿主
- 可选接入宿主 api::sn-code:按 SN 生成真 Code 128 条码与可扫二维码;
  关闭时(默认)完全保持原静态二维码行为。领码优先贴到已排版的格子,不够才新建
- 新增 commands: print-tag:issue-sn / print-tag:render-svg(后者纯本地出图,供其它插件复用)
- code128.ts 实现真 Code 128 Set B(含校验位);二维码走 qrcode-generator(真 QR)
- 自带本地预览器(preview/mock-api.ts 补了 /api/sn-codes mock)与 deploy / verify 脚本
- verify.mjs 修掉一处误报:源码边界判据改为「解析后是否逃出工程根」,
  而不是「说明符是否以 .. 开头」(后者会把 src/components/X.vue → ../codes 误判为越界)

已发布到插件仓库:funjia.print-tag@1.0.0
2026-10-03 23:48:32 +08:00

60 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 预览页的挂载入口 —— 两个 entry(源码 / 产物)共用这一份。
*
* 这里做的事,对应真实宿主 `main.ts` 里的同一批步骤:装 Element Plus、
* 注册图标、创建宿主、挂载界面。差别只在「宿主是谁」。
*/
import { createApp } from "vue";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import * as Icons from "@element-plus/icons-vue";
import App from "./App.vue";
import "./style.css";
import { createPreviewHost, type PreviewManifest } from "./host";
import * as apiContract from "./api-contract";
import type { PluginConfig, PreviewLoader } from "./loaders";
export function mountPreview(config: PluginConfig, loader: PreviewLoader): void {
const manifest: PreviewManifest = {
id: config.id,
name: config.name,
version: config.version,
kind: config.kind,
activation: config.activation,
/**
* `repository` / `checksum` 刻意留空。
*
* 预览不是从仓库装的,对应的是真实宿主里「手工填 URL 安装」那一种情形 ——
* 而 `ctx.plugin.repository` 有没有值,本身就是插件判断自己来源的判据
* (`demo.repo-badge` 就靠它显示「来自仓库」)。
* 所以:**依赖 `repository` 的分支在预览里走不到**,这是已知且刻意的差异,
* 界面顶部也会标出来。
*/
repository: undefined,
checksum: undefined,
};
const host = createPreviewHost(manifest);
const app = createApp(App, { host, loader, config });
app.use(ElementPlus);
// 图标全量注册,与宿主一致 —— 插件的 menuIcon: "Star" 在预览里才显示得出来
for (const [name, component] of Object.entries(Icons)) {
app.component(name, component as any);
}
app.mount("#app");
document.title = `插件预览 · ${config.name}(${loader.label}模式)`;
// 顺手挂到 window 上:卡住的时候可以直接在控制台里手玩
//
// `apiContract` 也一起挂出来,是为了让**排查与自动化脚本**能读到契约常量
// (存储键、401 的业务码…),而不是在几处各写一遍字面量 ——
// 写错了不会有任何编译错误,只会让脚本「查了一个错的键」然后静默通过。
(window as any).__preview__ = { host, manifest, config, loader, apiContract };
}