labull-framework 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -6
- package/dist/chunk-ProductShell.vue_vue_type_style_index_0_scoped_f78521a6_lang-qtJ-k8Ss.js +118 -0
- package/dist/chunk-index-DfIoolMt.js +543 -0
- package/dist/index.js +30 -22
- package/dist/magic-block.js +702 -653
- package/dist/style.css +1 -1
- package/dist/types/magic-block-MagicBlockHost.vue.d.ts +1 -9
- package/dist/types/magic-block-MagicBlockPage.vue.d.ts +12 -0
- package/dist/types/magic-block-bridge.d.ts +8 -4
- package/dist/types/magic-block-devkit.d.ts +1 -1
- package/dist/types/magic-block-instances.d.ts +19 -14
- package/dist/types/magic-block-preview.d.ts +1 -1
- package/dist/types/magic-block-real.d.ts +1 -1
- package/dist/types/ui-ProductShell.vue.d.ts +2 -2
- package/dist/types/ui-ProductSide.vue.d.ts +1 -1
- package/dist/types/ui-ProductTabs.vue.d.ts +6 -1
- package/dist/types/ui-TabPage.vue.d.ts +6 -0
- package/dist/types/ui-real.d.ts +6 -3
- package/dist/types/ui-tab-context.d.ts +46 -0
- package/dist/types/ui-tabs.d.ts +63 -15
- package/dist/types/ui-types.d.ts +20 -12
- package/dist/ui.js +20 -12
- package/package.json +1 -1
- package/dist/chunk-_plugin-vue_export-helper-CHgC5LLL.js +0 -9
- package/dist/chunk-index-_jasBCim.js +0 -526
package/README.md
CHANGED
|
@@ -36,20 +36,46 @@ app.mount('#app')
|
|
|
36
36
|
|
|
37
37
|
```vue
|
|
38
38
|
<script setup lang="ts">
|
|
39
|
+
import { ref } from 'vue'
|
|
39
40
|
import { useAuth } from 'labull-framework/auth'
|
|
40
|
-
import {
|
|
41
|
+
import { openTab } from 'labull-framework/ui'
|
|
42
|
+
import type { SideItem } from 'labull-framework/ui'
|
|
41
43
|
|
|
42
44
|
const { user, isStaff, logout } = useAuth()
|
|
45
|
+
const notice = ref('')
|
|
46
|
+
|
|
47
|
+
/** 一级 = 模块(点它滑出二级菜单),二级 = 页面;点一项干什么写在它自己的 onClick 里。 */
|
|
48
|
+
const menu: SideItem[] = [
|
|
49
|
+
{ path: 'sales', title: '销售管理', icon: 'pi pi-shopping-cart', children: [
|
|
50
|
+
{ path: '/orders', title: '订单', icon: 'pi pi-list', onClick: () => openTab('/orders') },
|
|
51
|
+
{ path: '/orders/42', title: '订单 SO-1', icon: 'pi pi-file', onClick: () => openTab('/orders/42?orderId=7') },
|
|
52
|
+
{ title: '设置', icon: 'pi pi-cog', onClick: () => { notice.value = '这一项不开标签' } }, // 不写 onClick 时默认"有 path 就开那个标签"
|
|
53
|
+
]},
|
|
54
|
+
]
|
|
43
55
|
</script>
|
|
44
56
|
|
|
45
57
|
<template>
|
|
46
|
-
<ProductShell>
|
|
47
|
-
<template #appbar><b
|
|
48
|
-
<
|
|
58
|
+
<ProductShell :side="menu" caption="订单系统">
|
|
59
|
+
<template #appbar><b>{{ user?.name }}</b></template>
|
|
60
|
+
<RouterView /> <!-- 页面(= 标签内容)由路由给 -->
|
|
49
61
|
</ProductShell>
|
|
50
62
|
</template>
|
|
51
63
|
```
|
|
52
64
|
|
|
65
|
+
magic block:**一条路由 = 一个块** —— **块外面不放任何东西**(标题 / 按钮 / 参数展示都写进块自己的
|
|
66
|
+
`index.open.html`),块占满这条标签页:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
// main.ts:这一条路由就是这个块(没有页面文件)
|
|
70
|
+
{ path: '/orders', component: MagicBlockPage, props: { uuid: '6f1c…' },
|
|
71
|
+
meta: { title: '订单', icon: 'pi pi-list' } }
|
|
72
|
+
```
|
|
73
|
+
```js
|
|
74
|
+
// 块自己的 index.open.html 里:要什么问宿主
|
|
75
|
+
const tab = await magicBlock.context() // { path, params, query }
|
|
76
|
+
await magicBlock.setTabTitle('订单 SO-42', 'pi pi-file') // 给所属那条标签起名
|
|
77
|
+
```
|
|
78
|
+
|
|
53
79
|
后端地址走 `VITE_API_BASE`(默认 `http://localhost:3000`)。
|
|
54
80
|
|
|
55
81
|
## subpath 对照表(原包 → 现在怎么 import)
|
|
@@ -58,8 +84,8 @@ const { user, isStaff, logout } = useAuth()
|
|
|
58
84
|
|---|---|---|
|
|
59
85
|
| `@labull/theme` | `labull-framework/style.css`(或 `labull-framework/theme`) | `--sp-*` token + 完整主题层 + 结构类 + primeicons |
|
|
60
86
|
| `@labull/auth` | `labull-framework/auth` | `useAuth()` / `apiFetch()` / `ensureAuthenticated()` / `createAuthGate()` / `API_BASE` |
|
|
61
|
-
| `@labull/ui` | `labull-framework/ui` | `ProductShell` / `ProductSide` / `ProductTabs` / `AppSearch` / `UserMenu` / `labull`
|
|
62
|
-
| `@labull/magic-block` | `labull-framework/magic-block` | `
|
|
87
|
+
| `@labull/ui` | `labull-framework/ui` | `ProductShell` / `ProductSide` / `ProductTabs` / `TabPage` / `AppSearch` / `UserMenu` / `labull` 插件,以及标签那一套:`openTab` / `activateTab` / `closeTab` / `useTabs` / `useTabContext` |
|
|
88
|
+
| `@labull/magic-block` | `labull-framework/magic-block` | `MagicBlockPage`(一条路由 = 一个块,**唯一入口**) / `MagicBlockConsole` / 清单校验 / bridge |
|
|
63
89
|
|
|
64
90
|
根入口 `labull-framework` = `auth` + `ui`(最常用的两层)。
|
|
65
91
|
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { reactive as y, computed as l, provide as k, inject as d } from "vue";
|
|
2
|
+
import { useRouter as m } from "vue-router";
|
|
3
|
+
const r = y({ tabs: [], active: "" });
|
|
4
|
+
let c = null;
|
|
5
|
+
function C(t) {
|
|
6
|
+
c = t;
|
|
7
|
+
}
|
|
8
|
+
function a(t) {
|
|
9
|
+
return typeof t == "string" && t.trim() ? t.trim() : "";
|
|
10
|
+
}
|
|
11
|
+
function T(t) {
|
|
12
|
+
const o = t.split("/").filter(Boolean).pop();
|
|
13
|
+
return { title: o ? decodeURIComponent(o) : "首页", icon: "pi pi-file" };
|
|
14
|
+
}
|
|
15
|
+
function f(t) {
|
|
16
|
+
return r.tabs.find((o) => o.key === t);
|
|
17
|
+
}
|
|
18
|
+
function b(t, o, n) {
|
|
19
|
+
const e = f(t);
|
|
20
|
+
if (e) {
|
|
21
|
+
const u = a(n?.title);
|
|
22
|
+
u && (e.title = u);
|
|
23
|
+
const p = a(n?.icon);
|
|
24
|
+
return p && (e.icon = p), r.active = e.key, e.key;
|
|
25
|
+
}
|
|
26
|
+
const i = T(o), s = {
|
|
27
|
+
key: t,
|
|
28
|
+
path: o,
|
|
29
|
+
title: a(n?.title) || i.title,
|
|
30
|
+
icon: a(n?.icon) || i.icon
|
|
31
|
+
};
|
|
32
|
+
return r.tabs.push(s), r.active = s.key, s.key;
|
|
33
|
+
}
|
|
34
|
+
function h(t, o) {
|
|
35
|
+
const n = c ? c.resolve(t) : { fullPath: t, path: t.split("?")[0] ?? t, matched: !0 };
|
|
36
|
+
if (!n.matched)
|
|
37
|
+
return console.warn(`[labull] 这个应用里没有页面 ${t}:先把它加进路由表,再开标签。`), "";
|
|
38
|
+
const e = b(n.fullPath, n.path, o);
|
|
39
|
+
return c && c.current() !== e && c.go(e), e;
|
|
40
|
+
}
|
|
41
|
+
function g(t) {
|
|
42
|
+
f(t) && (r.active = t, c && c.current() !== t && c.go(t));
|
|
43
|
+
}
|
|
44
|
+
function j(t, o, n) {
|
|
45
|
+
return b(t, o, n);
|
|
46
|
+
}
|
|
47
|
+
function x(t) {
|
|
48
|
+
const o = r.tabs.findIndex((i) => i.key === t);
|
|
49
|
+
if (o < 0) return "";
|
|
50
|
+
const n = r.tabs.filter((i) => i.key !== t);
|
|
51
|
+
if (r.tabs = n, r.active !== t) return "";
|
|
52
|
+
const e = n[o] ?? n[o - 1] ?? n[n.length - 1];
|
|
53
|
+
return e ? (r.active = e.key, c && c.current() !== e.key && c.go(e.key), e.key) : (r.active = "", "");
|
|
54
|
+
}
|
|
55
|
+
function _(t, o, n) {
|
|
56
|
+
const e = f(t);
|
|
57
|
+
if (!e) return;
|
|
58
|
+
const i = a(o);
|
|
59
|
+
i && (e.title = i);
|
|
60
|
+
const s = a(n);
|
|
61
|
+
s && (e.icon = s);
|
|
62
|
+
}
|
|
63
|
+
function w() {
|
|
64
|
+
return {
|
|
65
|
+
tabs: l(() => r.tabs),
|
|
66
|
+
active: l(() => r.active),
|
|
67
|
+
openTab: h,
|
|
68
|
+
activateTab: g,
|
|
69
|
+
closeTab: x
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const I = (t, o) => {
|
|
73
|
+
const n = t.__vccOpts || t;
|
|
74
|
+
for (const [e, i] of o)
|
|
75
|
+
n[e] = i;
|
|
76
|
+
return n;
|
|
77
|
+
}, v = "labull:tab";
|
|
78
|
+
function B(t) {
|
|
79
|
+
const o = m(), { active: n } = w(), e = () => o.resolve(t.key), i = {
|
|
80
|
+
key: t.key,
|
|
81
|
+
path: t.path,
|
|
82
|
+
get params() {
|
|
83
|
+
return e().params;
|
|
84
|
+
},
|
|
85
|
+
get query() {
|
|
86
|
+
return e().query;
|
|
87
|
+
},
|
|
88
|
+
active: l(() => n.value === t.key),
|
|
89
|
+
setTitle(s, u) {
|
|
90
|
+
_(t.key, s, u);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return k(v, i), i;
|
|
94
|
+
}
|
|
95
|
+
function E() {
|
|
96
|
+
const t = d(v, null);
|
|
97
|
+
if (!t) throw new Error("[labull] 这里不在标签页里:页面与 magic block 必须放在外壳的标签内容区(标签页)里。");
|
|
98
|
+
return t;
|
|
99
|
+
}
|
|
100
|
+
function N(t, o) {
|
|
101
|
+
if (!o || typeof o.resolve != "function") return !1;
|
|
102
|
+
const n = o.resolve(t), e = n?.params ?? {}, i = n?.query ?? {};
|
|
103
|
+
return Object.keys(e).length > 0 || Object.keys(i).length > 0;
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
v as T,
|
|
107
|
+
I as _,
|
|
108
|
+
g as a,
|
|
109
|
+
N as b,
|
|
110
|
+
x as c,
|
|
111
|
+
w as d,
|
|
112
|
+
j as f,
|
|
113
|
+
C as i,
|
|
114
|
+
h as o,
|
|
115
|
+
B as p,
|
|
116
|
+
_ as s,
|
|
117
|
+
E as u
|
|
118
|
+
};
|