|
@@ -1,20 +1,71 @@
|
|
|
-import { ref } from "vue";
|
|
|
+import { computed, ref } from "vue";
|
|
|
|
|
|
export function useTabs({ config, Form }: { config: ClForm.Config; Form: Vue.Ref<any> }) {
|
|
|
// 选中
|
|
|
- const active = ref<any>();
|
|
|
+ const active = ref<string | undefined>();
|
|
|
+
|
|
|
+ // 列表
|
|
|
+ const list = computed(() => {
|
|
|
+ return get()?.props?.labels || [];
|
|
|
+ });
|
|
|
+
|
|
|
+ // 获取选项
|
|
|
+ function getItem(value: any) {
|
|
|
+ return list.value.find((e) => e.value == value);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否已加载
|
|
|
+ function isLoaded(value: any) {
|
|
|
+ const d = getItem(value);
|
|
|
+ return d?.lazy ? d.loaded : true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载后
|
|
|
+ function onLoad(value: any) {
|
|
|
+ const d = getItem(value);
|
|
|
+ d!.loaded = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找分组
|
|
|
+ function findGroup(list: ClForm.Item[], prop: string) {
|
|
|
+ let name;
|
|
|
+
|
|
|
+ function deep(d: ClForm.Item) {
|
|
|
+ if (d.prop == prop) {
|
|
|
+ name = d.group;
|
|
|
+ } else {
|
|
|
+ if (d.children) {
|
|
|
+ d.children.forEach(deep);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ list.forEach(deep);
|
|
|
+
|
|
|
+ return name;
|
|
|
+ }
|
|
|
|
|
|
// 获取参数
|
|
|
function get() {
|
|
|
return config.items.find((e) => e.type === "tabs");
|
|
|
}
|
|
|
|
|
|
+ // 设置参数
|
|
|
function set(data: any) {
|
|
|
active.value = data;
|
|
|
}
|
|
|
|
|
|
+ // 清空
|
|
|
function clear() {
|
|
|
- active.value = null;
|
|
|
+ // 清空选中
|
|
|
+ active.value = undefined;
|
|
|
+
|
|
|
+ // 清空加载状态
|
|
|
+ list.value.forEach((e) => {
|
|
|
+ if (e.lazy && e.loaded) {
|
|
|
+ e.loaded = undefined;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// 切换
|
|
@@ -29,8 +80,8 @@ export function useTabs({ config, Form }: { config: ClForm.Config; Form: Vue.Ref
|
|
|
let isError = false;
|
|
|
|
|
|
const arr = config.items
|
|
|
- .filter((e: any) => e.group == active.value && !e._hidden && e.prop)
|
|
|
- .map((e: any) => {
|
|
|
+ .filter((e) => e.group == active.value && !e._hidden && e.prop)
|
|
|
+ .map((e) => {
|
|
|
return new Promise((r: Function) => {
|
|
|
// 验证表单
|
|
|
Form.value.validateField(e.prop, (valid: string) => {
|
|
@@ -75,10 +126,14 @@ export function useTabs({ config, Form }: { config: ClForm.Config; Form: Vue.Ref
|
|
|
|
|
|
return {
|
|
|
active,
|
|
|
+ list,
|
|
|
+ isLoaded,
|
|
|
+ onLoad,
|
|
|
get,
|
|
|
set,
|
|
|
change,
|
|
|
clear,
|
|
|
- mergeProp
|
|
|
+ mergeProp,
|
|
|
+ findGroup
|
|
|
};
|
|
|
}
|