@owocow/saber-ui 0.0.2 → 0.0.3
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 +206 -11
- package/dist/BadgeStatus.types.d.ts +1 -1
- package/dist/BadgeStatus.vue.d.ts +1 -1
- package/dist/SaberConfirmModal.vue_vue_type_script_setup_true_lang-Cqp9krYl.js +86 -0
- package/dist/SaberConfirmProvider.vue_vue_type_script_setup_true_lang-DUJ6ftNJ.js +30 -0
- package/dist/SaberDictCheckbox.vue_vue_type_script_setup_true_lang-DUbzy_C6.js +34 -0
- package/dist/SaberDictRadio.vue_vue_type_script_setup_true_lang-DR6-jSID.js +50 -0
- package/dist/SaberDictSelect.vue_vue_type_script_setup_true_lang-B8PTKNKX.js +35 -0
- package/dist/SaberDistrictSelect.vue_vue_type_script_setup_true_lang-BX8nLC35.js +257 -0
- package/dist/SaberInfo.vue_vue_type_script_setup_true_lang-B3W5VsGR.js +58 -0
- package/dist/SaberInfoProvider.vue_vue_type_script_setup_true_lang-3rF6bSCn.js +28 -0
- package/dist/SaberModal.vue_vue_type_script_setup_true_lang-DJno3jA3.js +71 -0
- package/dist/SaberModalWithMobile.vue_vue_type_script_setup_true_lang-aQlToncY.js +87 -0
- package/dist/SaberNoData.types.d.ts +11 -0
- package/dist/SaberNoData.vue.d.ts +24 -0
- package/dist/SaberPopSelect.vue_vue_type_script_setup_true_lang-BcS27NXI.js +125 -0
- package/dist/SaberStatus.vue_vue_type_script_setup_true_lang-D9aRVCow.js +38 -0
- package/dist/SaberSwitchBar.vue_vue_type_script_setup_true_lang-CDx3Dcas.js +47 -0
- package/dist/SaberUploadImage.vue_vue_type_script_setup_true_lang-CAwci2Vr.js +224 -0
- package/dist/colors.d.ts +1 -1
- package/dist/components/SaberConfirmModal.mjs +4 -0
- package/dist/components/SaberConfirmModal.vue.d.ts +28 -0
- package/dist/components/SaberConfirmProvider.mjs +4 -0
- package/dist/components/SaberConfirmProvider.vue.d.ts +2 -0
- package/dist/components/SaberInfo.mjs +4 -0
- package/dist/components/SaberInfo.types.d.ts +14 -0
- package/dist/components/SaberInfo.vue.d.ts +21 -0
- package/dist/components/SaberInfoProvider.mjs +4 -0
- package/dist/components/SaberInfoProvider.vue.d.ts +20 -0
- package/dist/components/SaberModalWithMobile.mjs +4 -0
- package/dist/components/SaberModalWithMobile.vue.d.ts +36 -0
- package/dist/components/SaberStatus.mjs +4 -0
- package/dist/components/SaberStatus.types.d.ts +1 -0
- package/dist/components/SaberStatus.vue.d.ts +8 -0
- package/dist/components/SaberSwitchBar.mjs +4 -0
- package/dist/components/SaberSwitchBar.types.d.ts +13 -0
- package/dist/components/SaberSwitchBar.vue.d.ts +18 -0
- package/dist/components/info-context.d.ts +3 -0
- package/dist/composables/index.d.ts +12 -0
- package/dist/composables/use-address-parse.d.ts +15 -0
- package/dist/composables/use-address-parse.mjs +20 -0
- package/dist/composables/use-boolean.d.ts +8 -0
- package/dist/composables/use-boolean.mjs +20 -0
- package/dist/composables/use-confirm.d.ts +34 -0
- package/dist/composables/use-confirm.mjs +28 -0
- package/dist/composables/use-delay-unmount.d.ts +7 -0
- package/dist/composables/use-delay-unmount.mjs +26 -0
- package/dist/composables/use-delete.d.ts +13 -0
- package/dist/composables/use-delete.mjs +19 -0
- package/dist/composables/use-loading.d.ts +6 -0
- package/dist/composables/use-loading.mjs +8 -0
- package/dist/composables/use-skeleton.d.ts +5 -0
- package/dist/composables/use-skeleton.mjs +23 -0
- package/dist/composables/use-table.d.ts +57 -0
- package/dist/composables/use-table.mjs +87 -0
- package/dist/composables.mjs +21 -0
- package/dist/district-service-cOu1tbQG.js +147 -0
- package/dist/district.d.ts +3 -0
- package/dist/district.mjs +8 -0
- package/dist/forms/components/SaberFilterBar.vue.d.ts +41 -0
- package/dist/forms/components/SaberFormModal.vue.d.ts +31 -0
- package/dist/forms/components/SaberModal.vue.d.ts +34 -0
- package/dist/forms/components/fields/SaberDictCheckbox.vue.d.ts +24 -0
- package/dist/forms/components/fields/SaberDictRadio.vue.d.ts +24 -0
- package/dist/forms/components/fields/SaberDictSelect.vue.d.ts +28 -0
- package/dist/forms/components/fields/SaberDistrictSelect.vue.d.ts +31 -0
- package/dist/forms/components/fields/SaberInput.vue.d.ts +16 -0
- package/dist/forms/components/fields/SaberInputNumber.vue.d.ts +11 -0
- package/dist/forms/components/fields/SaberPopSelect.vue.d.ts +25 -0
- package/dist/forms/components/fields/SaberRadioGroup.vue.d.ts +11 -0
- package/dist/forms/components/fields/SaberSelect.vue.d.ts +11 -0
- package/dist/forms/components/fields/SaberTextarea.vue.d.ts +11 -0
- package/dist/forms/components/fields/SaberUploadImage.vue.d.ts +113 -0
- package/dist/forms/dict-checkbox.mjs +4 -0
- package/dist/forms/dict-radio.mjs +4 -0
- package/dist/forms/dict-select.mjs +4 -0
- package/dist/forms/dict-source.d.ts +3 -0
- package/dist/forms/district-select.mjs +4 -0
- package/dist/forms/district-service.d.ts +46 -0
- package/dist/forms/filter-state.d.ts +4 -0
- package/dist/forms/index.d.ts +24 -0
- package/dist/forms/plugin.d.ts +20 -0
- package/dist/forms/pop-select.mjs +4 -0
- package/dist/forms/presets/basic.d.ts +5 -0
- package/dist/forms/registry.d.ts +15 -0
- package/dist/forms/types.d.ts +102 -0
- package/dist/forms/upload-image-source.d.ts +3 -0
- package/dist/forms/upload-image.mjs +4 -0
- package/dist/forms/use-dict-options.d.ts +8 -0
- package/dist/forms.mjs +45 -0
- package/dist/index.d.ts +62 -1
- package/dist/index.mjs +122 -33
- package/dist/info-context-MfOfJNDT.js +4 -0
- package/dist/plugin-Dr3z0YFg.js +396 -0
- package/dist/types/api.d.ts +30 -0
- package/dist/types/auth.d.ts +54 -0
- package/dist/types/common.d.ts +14 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.mjs +1 -0
- package/dist/upload-image-source-On8NHgmx.js +4 -0
- package/dist/use-dict-options-DjtbYYIa.js +38 -0
- package/dist/utils/addressParse.d.ts +37 -0
- package/dist/utils/addressParse.mjs +623 -0
- package/dist/utils/crypto.d.ts +11 -0
- package/dist/utils/crypto.mjs +36 -0
- package/dist/utils/filter.d.ts +20 -0
- package/dist/utils/filter.mjs +11 -0
- package/dist/utils/format.d.ts +9 -0
- package/dist/utils/format.mjs +7 -0
- package/dist/utils/http.d.ts +45 -0
- package/dist/utils/http.mjs +147 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.mjs +41 -0
- package/dist/utils/klona.d.ts +2 -0
- package/dist/utils/klona.mjs +4 -0
- package/dist/utils/nanoid.d.ts +2 -0
- package/dist/utils/nanoid.mjs +4 -0
- package/dist/utils/permission.d.ts +45 -0
- package/dist/utils/permission.mjs +38 -0
- package/dist/utils/rsa.d.ts +26 -0
- package/dist/utils/rsa.mjs +2073 -0
- package/dist/utils/storage.d.ts +29 -0
- package/dist/utils/storage.mjs +39 -0
- package/dist/utils/toast.d.ts +26 -0
- package/dist/utils/toast.mjs +17 -0
- package/dist/utils/tree.d.ts +20 -0
- package/dist/utils/tree.mjs +30 -0
- package/package.json +179 -9
- package/dist/index.cjs +0 -1
- package/dist/vite.cjs +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { reactive as t } from "vue";
|
|
2
|
+
const e = t({
|
|
3
|
+
open: !1,
|
|
4
|
+
loading: !1,
|
|
5
|
+
title: "确认操作",
|
|
6
|
+
message: "",
|
|
7
|
+
icon: "i-solar:info-circle-linear",
|
|
8
|
+
type: "delete",
|
|
9
|
+
confirmText: void 0,
|
|
10
|
+
resolve: null
|
|
11
|
+
});
|
|
12
|
+
function o() {
|
|
13
|
+
return e;
|
|
14
|
+
}
|
|
15
|
+
function l(n) {
|
|
16
|
+
const r = e.resolve;
|
|
17
|
+
e.resolve = null, e.loading = !1, e.open = !1, r == null || r(n);
|
|
18
|
+
}
|
|
19
|
+
function s() {
|
|
20
|
+
return (n = {}) => (e.resolve && l(!1), new Promise((r) => {
|
|
21
|
+
e.title = n.title ?? "确认操作", e.message = n.message ?? "", e.icon = n.icon ?? "i-solar:info-circle-linear", e.type = n.type ?? "delete", e.confirmText = n.confirmText, e.resolve = r, e.open = !0;
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
l as settleConfirm,
|
|
26
|
+
s as useConfirm,
|
|
27
|
+
o as useConfirmState
|
|
28
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ref as n, watch as f, onUnmounted as i } from "vue";
|
|
2
|
+
function s(l = 300) {
|
|
3
|
+
const t = n(!1), u = n(!1);
|
|
4
|
+
let e = null;
|
|
5
|
+
f(t, (a) => {
|
|
6
|
+
if (e && (clearTimeout(e), e = null), a) {
|
|
7
|
+
u.value = !0;
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
e = setTimeout(() => {
|
|
11
|
+
u.value = !1, e = null;
|
|
12
|
+
}, l);
|
|
13
|
+
}), i(() => {
|
|
14
|
+
e && clearTimeout(e);
|
|
15
|
+
});
|
|
16
|
+
function o() {
|
|
17
|
+
t.value = !0;
|
|
18
|
+
}
|
|
19
|
+
function r() {
|
|
20
|
+
t.value = !1;
|
|
21
|
+
}
|
|
22
|
+
return { open: t, mounted: u, show: o, hide: r };
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
s as useDelayUnmount
|
|
26
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConfirmOptions } from './use-confirm';
|
|
2
|
+
export interface UseDeleteOptions {
|
|
3
|
+
/** 是否需要二次确认,默认 true。 */
|
|
4
|
+
confirm?: boolean;
|
|
5
|
+
/** 默认确认弹窗配置,可被 requestDelete 的参数覆盖。 */
|
|
6
|
+
confirmOptions?: ConfirmOptions;
|
|
7
|
+
/** 删除成功后的回调。 */
|
|
8
|
+
onSuccess?: () => unknown | Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
export declare function useDelete<T>(apiFn: (item: T) => Promise<unknown>, options?: UseDeleteOptions): {
|
|
11
|
+
deleting: import('vue').Ref<boolean, boolean>;
|
|
12
|
+
requestDelete: (item: T, optionsOverride?: ConfirmOptions) => Promise<boolean>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ref as c } from "vue";
|
|
2
|
+
import { useConfirm as l } from "./use-confirm.mjs";
|
|
3
|
+
function w(r, n = {}) {
|
|
4
|
+
const { confirm: i = !0, confirmOptions: f, onSuccess: e } = n, o = l(), t = c(!1);
|
|
5
|
+
async function a(u, s) {
|
|
6
|
+
if (i && !await o({ ...f, ...s }))
|
|
7
|
+
return !1;
|
|
8
|
+
t.value = !0;
|
|
9
|
+
try {
|
|
10
|
+
return await r(u), await (e == null ? void 0 : e()), !0;
|
|
11
|
+
} finally {
|
|
12
|
+
t.value = !1;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return { deleting: t, requestDelete: a };
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
w as useDelete
|
|
19
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ref as n, watch as o, onUnmounted as i } from "vue";
|
|
2
|
+
function m(u, l = 300) {
|
|
3
|
+
const t = n(!1);
|
|
4
|
+
let e = null;
|
|
5
|
+
return o(
|
|
6
|
+
u,
|
|
7
|
+
(r) => {
|
|
8
|
+
if (e && (clearTimeout(e), e = null), !r) {
|
|
9
|
+
t.value = !1;
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
e = setTimeout(() => {
|
|
13
|
+
u.value && (t.value = !0), e = null;
|
|
14
|
+
}, l);
|
|
15
|
+
},
|
|
16
|
+
{ immediate: !0 }
|
|
17
|
+
), i(() => {
|
|
18
|
+
e && clearTimeout(e);
|
|
19
|
+
}), { showSkeleton: t };
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
m as useSkeleton
|
|
23
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
3
|
+
export type ApiFn = (args: any) => Promise<any>;
|
|
4
|
+
export type ApiParams<A extends ApiFn> = NonNullable<Parameters<A>[0]>;
|
|
5
|
+
export type TableDataWithIndex<T> = T & {
|
|
6
|
+
_index: number;
|
|
7
|
+
};
|
|
8
|
+
export interface PaginationConfig {
|
|
9
|
+
pageSizes?: number[];
|
|
10
|
+
pageSize?: number;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface TablePagination {
|
|
14
|
+
pageSizes: number[];
|
|
15
|
+
pageSize: number;
|
|
16
|
+
currentPage: number;
|
|
17
|
+
total: number;
|
|
18
|
+
}
|
|
19
|
+
export interface NormalizedTableResponse<T = unknown> {
|
|
20
|
+
rows: T[];
|
|
21
|
+
total: number;
|
|
22
|
+
}
|
|
23
|
+
export interface TableConfig<A extends ApiFn, T = any> {
|
|
24
|
+
/** 后端列表 API。 */
|
|
25
|
+
apiFn: A;
|
|
26
|
+
/** API 初始参数。 */
|
|
27
|
+
apiParams?: Partial<ApiParams<A>>;
|
|
28
|
+
/** 转换已经附带 _index 的行数据。 */
|
|
29
|
+
transformer?: (rows: TableDataWithIndex<T>[]) => any[];
|
|
30
|
+
/** 自定义响应归一化;默认兼容顶层与 data 内的 rows/total。 */
|
|
31
|
+
responseAdapter?: (response: Awaited<ReturnType<A>>) => NormalizedTableResponse<T>;
|
|
32
|
+
/** 获取并转换数据后的回调。 */
|
|
33
|
+
onFetched?: (data: any[]) => MaybePromise<void>;
|
|
34
|
+
/** 是否立即请求,默认 true。 */
|
|
35
|
+
immediate?: boolean;
|
|
36
|
+
/** 分页配置。 */
|
|
37
|
+
paginConfig?: PaginationConfig;
|
|
38
|
+
}
|
|
39
|
+
export declare function normalizeTableResponse<T = any>(response: any): NormalizedTableResponse<T>;
|
|
40
|
+
export declare function useTable<A extends ApiFn, T = any>(config: TableConfig<A, T>): {
|
|
41
|
+
loading: Ref<boolean, boolean>;
|
|
42
|
+
empty: Ref<boolean, boolean>;
|
|
43
|
+
data: Ref<any[], any[]>;
|
|
44
|
+
getData: () => Promise<any[]>;
|
|
45
|
+
params: ApiParams<A>;
|
|
46
|
+
updateSearchParams: (nextParams: Partial<ApiParams<A>>) => Promise<any[]>;
|
|
47
|
+
resetSearchParams: () => Promise<any[]>;
|
|
48
|
+
pagination: {
|
|
49
|
+
pageSizes: number[];
|
|
50
|
+
pageSize: number;
|
|
51
|
+
currentPage: number;
|
|
52
|
+
total: number;
|
|
53
|
+
};
|
|
54
|
+
total: import('vue').ComputedRef<number>;
|
|
55
|
+
startLoading: () => void;
|
|
56
|
+
endLoading: () => void;
|
|
57
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { reactive as y, ref as N, watch as z, computed as R } from "vue";
|
|
2
|
+
import { klona as h } from "klona/json";
|
|
3
|
+
import { useBoolean as C } from "./use-boolean.mjs";
|
|
4
|
+
import { useLoading as D } from "./use-loading.mjs";
|
|
5
|
+
function I(a) {
|
|
6
|
+
const r = Array.isArray(a == null ? void 0 : a.rows) ? a : a == null ? void 0 : a.data;
|
|
7
|
+
return {
|
|
8
|
+
rows: Array.isArray(r == null ? void 0 : r.rows) ? r.rows : [],
|
|
9
|
+
total: Number((r == null ? void 0 : r.total) ?? 0)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function H(a) {
|
|
13
|
+
const { loading: r, startLoading: d, endLoading: g } = D(), { bool: b, setBool: w } = C(), { apiFn: A, apiParams: f, transformer: p, responseAdapter: P, immediate: j = !0, paginConfig: O } = a, i = y(h({ ...f })), S = N([]), { pageSizes: k, pageSize: v, disabled: x = !1 } = O || {}, t = y({
|
|
14
|
+
pageSizes: k || [10, 20, 50, 100],
|
|
15
|
+
pageSize: v || 10,
|
|
16
|
+
currentPage: 1,
|
|
17
|
+
total: 0
|
|
18
|
+
});
|
|
19
|
+
let u = !1;
|
|
20
|
+
z(
|
|
21
|
+
() => t.currentPage,
|
|
22
|
+
() => {
|
|
23
|
+
u || s();
|
|
24
|
+
},
|
|
25
|
+
{ flush: "sync" }
|
|
26
|
+
), z(
|
|
27
|
+
() => t.pageSize,
|
|
28
|
+
() => {
|
|
29
|
+
u = !0, t.currentPage = 1, u = !1, s();
|
|
30
|
+
},
|
|
31
|
+
{ flush: "sync" }
|
|
32
|
+
);
|
|
33
|
+
function E(e) {
|
|
34
|
+
const o = t.currentPage || 1, c = t.pageSize > 0 ? t.pageSize : 10;
|
|
35
|
+
return e.map((m, n) => ({
|
|
36
|
+
...m,
|
|
37
|
+
_index: (o - 1) * c + n + 1
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
async function s() {
|
|
41
|
+
var e;
|
|
42
|
+
d();
|
|
43
|
+
try {
|
|
44
|
+
const o = T(i), c = await A(o), m = P ? P(c) : I(c), n = E(m.rows), l = p ? p(n) : n;
|
|
45
|
+
return t.total = m.total, S.value = l, w(l.length === 0), await ((e = a.onFetched) == null ? void 0 : e.call(a, l)), l;
|
|
46
|
+
} finally {
|
|
47
|
+
g();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function L() {
|
|
51
|
+
return x ? {} : {
|
|
52
|
+
pageNum: t.currentPage,
|
|
53
|
+
pageSize: t.pageSize
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function T(e) {
|
|
57
|
+
const o = {}, c = { ...L(), ...e };
|
|
58
|
+
return Object.entries(c).forEach(([m, n]) => {
|
|
59
|
+
n != null && n !== "" && (o[m] = n);
|
|
60
|
+
}), o;
|
|
61
|
+
}
|
|
62
|
+
function B(e) {
|
|
63
|
+
return Object.assign(i, e), s();
|
|
64
|
+
}
|
|
65
|
+
function F() {
|
|
66
|
+
u = !0, t.currentPage = 1, u = !1;
|
|
67
|
+
const e = h({ ...f });
|
|
68
|
+
return Object.keys(i).forEach((o) => delete i[o]), Object.assign(i, e), s();
|
|
69
|
+
}
|
|
70
|
+
return j && s(), {
|
|
71
|
+
loading: r,
|
|
72
|
+
empty: b,
|
|
73
|
+
data: S,
|
|
74
|
+
getData: s,
|
|
75
|
+
params: i,
|
|
76
|
+
updateSearchParams: B,
|
|
77
|
+
resetSearchParams: F,
|
|
78
|
+
pagination: t,
|
|
79
|
+
total: R(() => t.total),
|
|
80
|
+
startLoading: d,
|
|
81
|
+
endLoading: g
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
I as normalizeTableResponse,
|
|
86
|
+
H as useTable
|
|
87
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useBoolean as r } from "./composables/use-boolean.mjs";
|
|
2
|
+
import { useLoading as t } from "./composables/use-loading.mjs";
|
|
3
|
+
import { settleConfirm as f, useConfirm as n, useConfirmState as u } from "./composables/use-confirm.mjs";
|
|
4
|
+
import { useDelete as a } from "./composables/use-delete.mjs";
|
|
5
|
+
import { useSkeleton as x } from "./composables/use-skeleton.mjs";
|
|
6
|
+
import { useDelayUnmount as d } from "./composables/use-delay-unmount.mjs";
|
|
7
|
+
import { useAddressParse as b } from "./composables/use-address-parse.mjs";
|
|
8
|
+
import { normalizeTableResponse as S, useTable as T } from "./composables/use-table.mjs";
|
|
9
|
+
export {
|
|
10
|
+
S as normalizeTableResponse,
|
|
11
|
+
f as settleConfirm,
|
|
12
|
+
b as useAddressParse,
|
|
13
|
+
r as useBoolean,
|
|
14
|
+
n as useConfirm,
|
|
15
|
+
u as useConfirmState,
|
|
16
|
+
d as useDelayUnmount,
|
|
17
|
+
a as useDelete,
|
|
18
|
+
t as useLoading,
|
|
19
|
+
x as useSkeleton,
|
|
20
|
+
T as useTable
|
|
21
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { shallowRef as v, ref as p, inject as g } from "vue";
|
|
2
|
+
const b = "__saber_ui_amap_district_v1__", D = 10080 * 60 * 1e3, A = Symbol("SaberDistrictService");
|
|
3
|
+
function I(e) {
|
|
4
|
+
return e === "province" || e === "city" || e === "district" || e === "street";
|
|
5
|
+
}
|
|
6
|
+
function m(e) {
|
|
7
|
+
return Array.isArray(e) ? e.flatMap((t) => {
|
|
8
|
+
if (!t || typeof t != "object") return [];
|
|
9
|
+
const r = t;
|
|
10
|
+
if (typeof r.name != "string" || typeof r.adcode != "string" || !I(r.level))
|
|
11
|
+
return [];
|
|
12
|
+
const c = m(r.districts);
|
|
13
|
+
return [{
|
|
14
|
+
name: r.name,
|
|
15
|
+
adcode: r.adcode,
|
|
16
|
+
...typeof r.citycode == "string" && r.citycode ? { citycode: r.citycode } : {},
|
|
17
|
+
level: r.level,
|
|
18
|
+
...c.length ? { districts: c } : {}
|
|
19
|
+
}];
|
|
20
|
+
}) : [];
|
|
21
|
+
}
|
|
22
|
+
function S() {
|
|
23
|
+
try {
|
|
24
|
+
return typeof localStorage > "u" ? void 0 : localStorage;
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function E(e) {
|
|
30
|
+
const t = S();
|
|
31
|
+
if (!t) return null;
|
|
32
|
+
try {
|
|
33
|
+
const r = t.getItem(e);
|
|
34
|
+
if (!r) return null;
|
|
35
|
+
const c = JSON.parse(r);
|
|
36
|
+
return !Array.isArray(c.data) || typeof c.expireAt != "number" ? null : Date.now() >= c.expireAt ? (t.removeItem(e), null) : c.data;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function U(e, t, r) {
|
|
42
|
+
if (t <= 0) return;
|
|
43
|
+
const c = S();
|
|
44
|
+
if (c)
|
|
45
|
+
try {
|
|
46
|
+
const i = {
|
|
47
|
+
data: [...r],
|
|
48
|
+
expireAt: Date.now() + t
|
|
49
|
+
};
|
|
50
|
+
c.setItem(e, JSON.stringify(i));
|
|
51
|
+
} catch (i) {
|
|
52
|
+
console.warn("[SaberUI] Failed to cache district data.", i);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function _(e) {
|
|
56
|
+
const t = e.cacheKey ?? b, r = e.cacheTtl ?? D;
|
|
57
|
+
return {
|
|
58
|
+
async loadDistricts() {
|
|
59
|
+
const c = r > 0 ? E(t) : null;
|
|
60
|
+
if (c) return c;
|
|
61
|
+
const i = e.key.trim();
|
|
62
|
+
if (!i) throw new Error("[SaberUI] AMap district key is empty.");
|
|
63
|
+
const s = e.fetcher ?? globalThis.fetch;
|
|
64
|
+
if (!s) throw new Error("[SaberUI] fetch is unavailable; provide district.fetcher.");
|
|
65
|
+
const y = new URLSearchParams({
|
|
66
|
+
key: i,
|
|
67
|
+
keywords: "中国",
|
|
68
|
+
subdistrict: "3"
|
|
69
|
+
}), o = await s(`https://restapi.amap.com/v3/config/district?${y}`);
|
|
70
|
+
if (!o.ok) throw new Error(`[SaberUI] AMap district request failed (${o.status}).`);
|
|
71
|
+
const n = await o.json();
|
|
72
|
+
if (n.status !== "1") {
|
|
73
|
+
const a = typeof n.info == "string" ? n.info : "unknown error";
|
|
74
|
+
throw new Error(`[SaberUI] AMap district request failed: ${a}.`);
|
|
75
|
+
}
|
|
76
|
+
const u = (Array.isArray(n.districts) ? n.districts : [])[0], d = m(u == null ? void 0 : u.districts);
|
|
77
|
+
if (!d.length) throw new Error("[SaberUI] AMap district response contains no district data.");
|
|
78
|
+
return U(t, r, d), d;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function K(e) {
|
|
83
|
+
if (e != null && e.dataSource) return e.dataSource;
|
|
84
|
+
if (e != null && e.amapKey)
|
|
85
|
+
return _({
|
|
86
|
+
key: e.amapKey,
|
|
87
|
+
cacheKey: e.cacheKey,
|
|
88
|
+
cacheTtl: e.cacheTtl,
|
|
89
|
+
fetcher: e.fetcher
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function w(e, t, r = []) {
|
|
93
|
+
var c;
|
|
94
|
+
for (const i of e) {
|
|
95
|
+
if (i.adcode === t) return { node: i, path: r };
|
|
96
|
+
if ((c = i.districts) != null && c.length) {
|
|
97
|
+
const s = w(i.districts, t, [...r, i]);
|
|
98
|
+
if (s) return s;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
function T(e) {
|
|
104
|
+
const t = v([]), r = p(!1), c = v(null);
|
|
105
|
+
let i;
|
|
106
|
+
async function s(o = !1) {
|
|
107
|
+
if (!o && t.value.length) return t.value;
|
|
108
|
+
if (i) return i;
|
|
109
|
+
if (!e) {
|
|
110
|
+
const n = new Error(
|
|
111
|
+
"[SaberUI] District data source is not configured. Pass forms.district.amapKey or forms.district.dataSource to app.use(SaberUI)."
|
|
112
|
+
);
|
|
113
|
+
throw c.value = n, n;
|
|
114
|
+
}
|
|
115
|
+
return r.value = !0, c.value = null, i = Promise.resolve().then(() => e.loadDistricts()).then((n) => (t.value = [...n], t.value)).catch((n) => {
|
|
116
|
+
throw c.value = n, n;
|
|
117
|
+
}).finally(() => {
|
|
118
|
+
r.value = !1, i = void 0;
|
|
119
|
+
}), i;
|
|
120
|
+
}
|
|
121
|
+
function y(o) {
|
|
122
|
+
const n = w(t.value, String(o));
|
|
123
|
+
if (!n) return null;
|
|
124
|
+
const { node: l, path: u } = n, d = l.level === "province" ? l : u[0], a = l.level === "city" ? l : u.find((h) => h.level === "city"), f = l.level === "district" ? l : u.find((h) => h.level === "district");
|
|
125
|
+
return d ? {
|
|
126
|
+
province: d.name,
|
|
127
|
+
provinceCode: d.adcode,
|
|
128
|
+
city: (a == null ? void 0 : a.name) ?? null,
|
|
129
|
+
cityCode: (a == null ? void 0 : a.adcode) ?? null,
|
|
130
|
+
district: (f == null ? void 0 : f.name) ?? null,
|
|
131
|
+
districtCode: (f == null ? void 0 : f.adcode) ?? null
|
|
132
|
+
} : null;
|
|
133
|
+
}
|
|
134
|
+
return { districts: t, loading: r, error: c, load: s, resolveByCode: y };
|
|
135
|
+
}
|
|
136
|
+
function k() {
|
|
137
|
+
const e = g(A, void 0);
|
|
138
|
+
if (!e) throw new Error("[SaberUI] District service is unavailable. Install SaberUI before using it.");
|
|
139
|
+
return e;
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
A as D,
|
|
143
|
+
T as a,
|
|
144
|
+
_ as c,
|
|
145
|
+
K as r,
|
|
146
|
+
k as u
|
|
147
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createAmapDistrictDataSource, createDistrictService, DistrictServiceKey, resolveDistrictDataSource, useDistrictService, } from './forms/district-service';
|
|
2
|
+
export type { AmapDistrictDataSourceOptions, DistrictDataSource, DistrictService, ResolvedDistrict, SaberDistrictOptions, } from './forms/district-service';
|
|
3
|
+
export type { DistrictNode, DistrictValue } from './forms/types';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FilterField } from '../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
fields: FilterField[];
|
|
4
|
+
/** 与该值相同的字段视为未筛选。 */
|
|
5
|
+
initialParams?: Record<string, unknown> | null;
|
|
6
|
+
};
|
|
7
|
+
type __VLS_PublicProps = {
|
|
8
|
+
modelValue?: Record<string, unknown>;
|
|
9
|
+
} & __VLS_Props;
|
|
10
|
+
declare function __VLS_template(): {
|
|
11
|
+
attrs: Partial<{}>;
|
|
12
|
+
slots: {
|
|
13
|
+
leading?(_: {}): any;
|
|
14
|
+
trailing?(_: {}): any;
|
|
15
|
+
};
|
|
16
|
+
refs: {};
|
|
17
|
+
rootEl: HTMLDivElement;
|
|
18
|
+
};
|
|
19
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
20
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps, {
|
|
21
|
+
hasActiveFilters: import('vue').ComputedRef<boolean>;
|
|
22
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
23
|
+
search: () => any;
|
|
24
|
+
"update:modelValue": (value: Record<string, unknown>) => any;
|
|
25
|
+
reset: () => any;
|
|
26
|
+
refresh: () => any;
|
|
27
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
28
|
+
onSearch?: (() => any) | undefined;
|
|
29
|
+
"onUpdate:modelValue"?: ((value: Record<string, unknown>) => any) | undefined;
|
|
30
|
+
onReset?: (() => any) | undefined;
|
|
31
|
+
onRefresh?: (() => any) | undefined;
|
|
32
|
+
}>, {
|
|
33
|
+
initialParams: Record<string, unknown> | null;
|
|
34
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
35
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
36
|
+
export default _default;
|
|
37
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
38
|
+
new (): {
|
|
39
|
+
$slots: S;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FormField, FormSubmitHandler, FormValidator } from '../types';
|
|
2
|
+
declare const _default: <T extends Record<string, unknown>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
3
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
|
|
4
|
+
readonly "onUpdate:open"?: ((value: boolean) => any) | undefined;
|
|
5
|
+
readonly onError?: ((error: unknown) => any) | undefined;
|
|
6
|
+
readonly onSuccess?: ((result: unknown) => any) | undefined;
|
|
7
|
+
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, "onError" | "onUpdate:open" | "onSuccess"> & ({
|
|
8
|
+
open?: boolean;
|
|
9
|
+
} & {
|
|
10
|
+
fields: FormField<T>[];
|
|
11
|
+
model?: T;
|
|
12
|
+
validate?: FormValidator<T>;
|
|
13
|
+
submit: FormSubmitHandler<T>;
|
|
14
|
+
title?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
width?: string;
|
|
17
|
+
cancelLabel?: string;
|
|
18
|
+
submitLabel?: string;
|
|
19
|
+
closeOnSuccess?: boolean;
|
|
20
|
+
}) & Partial<{}>> & import('vue').PublicProps;
|
|
21
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
22
|
+
attrs: any;
|
|
23
|
+
slots: {};
|
|
24
|
+
emit: (((evt: "error", error: unknown) => void) & ((evt: "success", result: unknown) => void)) & ((evt: "update:open", value: boolean) => void);
|
|
25
|
+
}>) => import('vue').VNode & {
|
|
26
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
27
|
+
};
|
|
28
|
+
export default _default;
|
|
29
|
+
type __VLS_PrettifyLocal<T> = {
|
|
30
|
+
[K in keyof T]: T[K];
|
|
31
|
+
} & {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
title?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
width?: string;
|
|
5
|
+
showClose?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type __VLS_PublicProps = {
|
|
8
|
+
'open'?: boolean;
|
|
9
|
+
} & __VLS_Props;
|
|
10
|
+
declare function __VLS_template(): {
|
|
11
|
+
attrs: Partial<{}>;
|
|
12
|
+
slots: {
|
|
13
|
+
default?(_: {}): any;
|
|
14
|
+
footer?(_: {}): any;
|
|
15
|
+
};
|
|
16
|
+
refs: {};
|
|
17
|
+
rootEl: any;
|
|
18
|
+
};
|
|
19
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
20
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
21
|
+
"update:open": (value: boolean) => any;
|
|
22
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
23
|
+
"onUpdate:open"?: ((value: boolean) => any) | undefined;
|
|
24
|
+
}>, {
|
|
25
|
+
width: string;
|
|
26
|
+
showClose: boolean;
|
|
27
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
28
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
29
|
+
export default _default;
|
|
30
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
31
|
+
new (): {
|
|
32
|
+
$slots: S;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DictDataSource } from '../../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
dictType: string;
|
|
4
|
+
dataSource?: DictDataSource;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type __VLS_PublicProps = {
|
|
8
|
+
modelValue?: any[];
|
|
9
|
+
} & __VLS_Props;
|
|
10
|
+
declare const _default: import('vue').DefineComponent<__VLS_PublicProps, {
|
|
11
|
+
items: import('vue').ShallowRef<import('../..').DictOption<string | number>[], import('../..').DictOption<string | number>[]>;
|
|
12
|
+
loading: import('vue').Ref<boolean, boolean>;
|
|
13
|
+
error: import('vue').ShallowRef<unknown, unknown>;
|
|
14
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
15
|
+
change: (value: any[]) => any;
|
|
16
|
+
"update:modelValue": (value: any[]) => any;
|
|
17
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
18
|
+
onChange?: ((value: any[]) => any) | undefined;
|
|
19
|
+
"onUpdate:modelValue"?: ((value: any[]) => any) | undefined;
|
|
20
|
+
}>, {
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
dataSource: DictDataSource;
|
|
23
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DictDataSource } from '../../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
dictType: string;
|
|
4
|
+
dataSource?: DictDataSource;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type __VLS_PublicProps = {
|
|
8
|
+
modelValue?: any;
|
|
9
|
+
} & __VLS_Props;
|
|
10
|
+
declare const _default: import('vue').DefineComponent<__VLS_PublicProps, {
|
|
11
|
+
items: import('vue').ShallowRef<import('../..').DictOption<string | number>[], import('../..').DictOption<string | number>[]>;
|
|
12
|
+
loading: import('vue').Ref<boolean, boolean>;
|
|
13
|
+
error: import('vue').ShallowRef<unknown, unknown>;
|
|
14
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
15
|
+
change: (value: any) => any;
|
|
16
|
+
"update:modelValue": (value: any) => any;
|
|
17
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
18
|
+
onChange?: ((value: any) => any) | undefined;
|
|
19
|
+
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
20
|
+
}>, {
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
dataSource: DictDataSource;
|
|
23
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DictDataSource } from '../../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
dictType: string;
|
|
4
|
+
dataSource?: DictDataSource;
|
|
5
|
+
placeholder?: string;
|
|
6
|
+
clearable?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type __VLS_PublicProps = {
|
|
10
|
+
modelValue?: any;
|
|
11
|
+
} & __VLS_Props;
|
|
12
|
+
declare const _default: import('vue').DefineComponent<__VLS_PublicProps, {
|
|
13
|
+
items: import('vue').ShallowRef<import('../..').DictOption<string | number>[], import('../..').DictOption<string | number>[]>;
|
|
14
|
+
loading: import('vue').Ref<boolean, boolean>;
|
|
15
|
+
error: import('vue').ShallowRef<unknown, unknown>;
|
|
16
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
17
|
+
change: (value: any) => any;
|
|
18
|
+
"update:modelValue": (value: any) => any;
|
|
19
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
20
|
+
onChange?: ((value: any) => any) | undefined;
|
|
21
|
+
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
22
|
+
}>, {
|
|
23
|
+
placeholder: string;
|
|
24
|
+
disabled: boolean;
|
|
25
|
+
clearable: boolean;
|
|
26
|
+
dataSource: DictDataSource;
|
|
27
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
28
|
+
export default _default;
|