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
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* 预览环境里的 `funjiaui` 替身。
|
||||
*
|
||||
* ## 先讲清楚它不是什么
|
||||
*
|
||||
* **它不是 FunjiaUI。** 预览服务器只装了 Vue 和 Element Plus —— FunjiaUI 是
|
||||
* 宿主的私有依赖(`git+…#v1.4.0` 那种),插件工程没有理由依赖它,预览也不该
|
||||
* 为了它把安装成本抬上去。所以这里是一组桩:**保证 import 成功、装饰器调用
|
||||
* 不崩、占位可见**,但不会产生任何真实表格/表单行为。
|
||||
*
|
||||
* 于是有一条你得记住的边界:
|
||||
*
|
||||
* > 预览里能跑通 ≠ 宿主里一定能跑通。
|
||||
* > 预览回答的是「我写的这些东西长什么样」,用到 FunjiaUI 深水区
|
||||
* > (`UmTable` 的列配置、远程配置类、装饰器元数据)的行为仍然要在宿主里验一遍。
|
||||
*
|
||||
* ## 两条通道,两个实现
|
||||
*
|
||||
* | 通道 | 谁在用 | 实现 |
|
||||
* | ---- | ------ | ---- |
|
||||
* | ESM 具名导入 `import { UmTable } from "funjiaui"` | `kind: esm` 的产物 | 本文件的静态导出 |
|
||||
* | 全局取用 `window.funjiaui.UmTable` | `kind: iife` 的产物 | `createFunjiauiFallback()` 的 Proxy |
|
||||
*
|
||||
* ESM 必须有**静态具名导出**(浏览器要能在实例化阶段解析出每一个名字),所以
|
||||
* 下面是一个个列出来的,不能用循环生成。IIFE 走 Proxy,任意名字都能兜住,
|
||||
* 代价是拿到的东西一律是「装饰器桩」形态(能当装饰器、能当函数调,不能当组件渲染)。
|
||||
*
|
||||
* 如果你 import 了一个下面没列的名字,`npm run verify` 会指出来让你补 ——
|
||||
* 这样桩和实际用法不会悄悄脱节。
|
||||
*/
|
||||
|
||||
import { defineComponent, h } from "vue";
|
||||
|
||||
/* ------------------------------------------------------------ 组件桩 */
|
||||
|
||||
const STUB_STYLE = {
|
||||
border: "1px dashed #e6a23c",
|
||||
borderRadius: "6px",
|
||||
padding: "8px 10px",
|
||||
margin: "4px 0",
|
||||
background: "#fdf6ec",
|
||||
color: "#a06d1f",
|
||||
fontSize: "12px",
|
||||
lineHeight: "1.6",
|
||||
};
|
||||
|
||||
/**
|
||||
* 把组件渲染成一块显眼的占位。
|
||||
*
|
||||
* 刻意做得「丑且明显」—— 它必须和真实界面区分得开,否则会出现
|
||||
* 「预览里看着挺正常,装到宿主里发现完全不是这回事」这种最坏的情况。
|
||||
*/
|
||||
function stubComponent(name: string) {
|
||||
return defineComponent({
|
||||
name,
|
||||
inheritAttrs: false,
|
||||
setup(_props, { slots }) {
|
||||
return () =>
|
||||
h("div", { style: STUB_STYLE, "data-funjiaui-stub": name }, [
|
||||
`[预览桩] funjiaui.${name} —— 真实渲染要在宿主里看`,
|
||||
slots.default ? h("div", { style: { marginTop: "4px", opacity: "0.75" } }, slots.default()) : null,
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export const AreaTree = stubComponent("AreaTree");
|
||||
export const Iconfont = stubComponent("Iconfont");
|
||||
export const UmByClass = stubComponent("UmByClass");
|
||||
export const UmByClassEnhance = stubComponent("UmByClassEnhance");
|
||||
export const UmColumnRender = stubComponent("UmColumnRender");
|
||||
export const UmDialog = stubComponent("UmDialog");
|
||||
export const UmDistrictTree = stubComponent("UmDistrictTree");
|
||||
export const UmDistrictTreeNode = stubComponent("UmDistrictTreeNode");
|
||||
export const UmPagination = stubComponent("UmPagination");
|
||||
export const UmRemoteClass = stubComponent("UmRemoteClass");
|
||||
export const UmSearchForm = stubComponent("UmSearchForm");
|
||||
export const UmSyncNodeForm = stubComponent("UmSyncNodeForm");
|
||||
export const UmTable = stubComponent("UmTable");
|
||||
export const UmTableColumn = stubComponent("UmTableColumn");
|
||||
export const UmTableDialog = stubComponent("UmTableDialog");
|
||||
export const UmTableForm = stubComponent("UmTableForm");
|
||||
export const UmTableOperate = stubComponent("UmTableOperate");
|
||||
export const UmTableToolbar = stubComponent("UmTableToolbar");
|
||||
export const UmTree = stubComponent("UmTree");
|
||||
export const UmTreeSelect = stubComponent("UmTreeSelect");
|
||||
|
||||
/* ---------------------------------------------------------- 装饰器桩 */
|
||||
|
||||
/**
|
||||
* 装饰器桩:要同时吃得下两种写法。
|
||||
*
|
||||
* ```ts
|
||||
* class X { @TableColumnPropertyDecorator({ title: "编号" }) code = "" }
|
||||
* class Y { @TableColumnPropertyDecorator code = "" }
|
||||
* ```
|
||||
*
|
||||
* 判据是「参数里有没有『类/原型 + 字符串属性名』」—— 有就是被当成装饰器直接调用了。
|
||||
* 工厂形式先收到一份配置对象,此时返回**自身**,等下一次调用落到直用分支,
|
||||
* 于是两种写法都不会抛 `… is not a function`。
|
||||
*
|
||||
* 配置类插件的**定义期**就执行装饰器,所以这里一旦崩,整个插件模块都求值不了 ——
|
||||
* 表现是「脚本已执行但没拿到插件」,极容易误判成路径问题。这就是为什么它必须够宽容。
|
||||
*/
|
||||
function stubDecorator(...args: any[]): any {
|
||||
const looksLikeDecoratorCall =
|
||||
args.length >= 2 &&
|
||||
(typeof args[0] === "function" || (typeof args[0] === "object" && args[0] !== null)) &&
|
||||
typeof args[1] === "string";
|
||||
if (looksLikeDecoratorCall) return args[2];
|
||||
return stubDecorator;
|
||||
}
|
||||
|
||||
export const TableColumnMethodDecorator = stubDecorator;
|
||||
export const TableColumnPropertyDecorator = stubDecorator;
|
||||
export const TableFormColumnPropertyDecorator = stubDecorator;
|
||||
export const TableSearchFormPropertyDecorator = stubDecorator;
|
||||
|
||||
/* -------------------------------------------------------- 常量与工具 */
|
||||
|
||||
export const DEFAULT_DEFER_TYPES: any[] = [];
|
||||
export const EVENT_PHASES: any[] = [];
|
||||
export const FIXED_VALUES: any[] = [];
|
||||
export const SAFE_SCRIPT_PATH = "";
|
||||
|
||||
/** 纯函数居多,给个「形状对得上」的空实现,够插件在预览里跑通非 UI 流程 */
|
||||
export const toGlobalKey = (name: string): string => String(name).replace(/[^A-Za-z0-9_$]/g, "_");
|
||||
export const normalizeFieldName = (name: string): string => String(name);
|
||||
export const transformFields = (..._args: any[]): Record<string, any> => ({});
|
||||
export const collectClassMembers = (..._args: any[]): any[] => [];
|
||||
export const collectDataColumns = (..._args: any[]): any[] => [];
|
||||
export const collectOperateGroups = (..._args: any[]): any[] => [];
|
||||
export const collectToolbar = (..._args: any[]): any[] => [];
|
||||
export const collectTypedTasks = (..._args: any[]): any[] => [];
|
||||
export const sortTasksByPriority = (..._args: any[]): any[] => [];
|
||||
export const buildOperateColumn = (..._args: any[]): any => null;
|
||||
export const resolveScriptUrl = (..._args: any[]): string => "";
|
||||
export const loadRemoteScript = async (..._args: any[]): Promise<void> => undefined;
|
||||
export const clearRemoteScript = (): void => undefined;
|
||||
|
||||
/* ------------------------------------------------------ Proxy 兜底 */
|
||||
|
||||
/**
|
||||
* `window.funjiaui` 的兜底实现(给 IIFE 插件用)。
|
||||
*
|
||||
* Proxy 能兜住**任意**名字,所以老插件里那些没被上面列全的 API 也不会抛错。
|
||||
* 局限要说清楚:取到的值统一是「装饰器桩」形态 —— 当装饰器用没问题,
|
||||
* 当组件渲染不行(组件需要 `render`/`setup`,不是普通函数)。
|
||||
* 真遇到这种插件,就在上面补一个具名 `stubComponent`。
|
||||
*/
|
||||
export function createFunjiauiFallback(): any {
|
||||
const cache = new Map<string, any>();
|
||||
return new Proxy(
|
||||
{ __previewStub: true },
|
||||
{
|
||||
get(_target, key) {
|
||||
if (typeof key === "symbol") return undefined;
|
||||
if (!cache.has(key)) cache.set(key, stubDecorator);
|
||||
return cache.get(key);
|
||||
},
|
||||
has: () => true,
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user