Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
fix: 删除一些多余的旧代码
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Dec 17, 2021
1 parent 917e3f0 commit 9eaa568
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/components/JSON-schema-form/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function createPlaceholderMessage(component: ComponentMapType, label = ''
'Select',
'Cascader',
'Checkbox',
'CheckboxGroup',
'Switch',
'TreeSelect',
];
Expand Down
20 changes: 13 additions & 7 deletions src/components/JSON-schema-form/schema-form-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Col v-bind="schemaItem.colProps">
<Form.Item
v-bind="{ ...schemaItem.formItemProps }"
:label="renderLabelHelpMessage()"
:label="renderLabelHelpMessage"
:name="schemaItem.field"
:labelCol="itemLabelWidthProp.labelCol"
:wrapperCol="itemLabelWidthProp.wrapperCol"
:rules="handleRules()"
:rules="getRules"
>
<slot v-if="schemaItem.slot" :name="schemaItem.slot" v-bind="getValues"> </slot>
<component
Expand Down Expand Up @@ -148,7 +148,7 @@
}, {});
});
function renderLabelHelpMessage() {
const renderLabelHelpMessage = computed(() => {
const { label, helpMessage, helpComponentProps, subLabel } = props.schemaItem;
const renderLabel = subLabel ? (
<span>
Expand All @@ -167,7 +167,7 @@
<BasicHelp placement="top" class="mx-1" text={getHelpMessage} {...helpComponentProps} />
</span>
);
}
});
const getComponentsProps = computed(() => {
const { schemaItem, tableAction, formModel, formActionType } = props;
Expand All @@ -192,16 +192,21 @@
}
}
function handleRules(): ValidationRule[] {
const getRules = computed(() => {
const {
rules: defRules = [],
component,
rulesMessageJoinLabel,
label,
dynamicRules,
required,
field,
} = props.schemaItem;
if (field == 'field5') {
console.log('rules', props.schemaItem);
}
if (isFunction(dynamicRules)) {
return dynamicRules(unref(getValues)) as ValidationRule[];
}
Expand All @@ -214,10 +219,11 @@
: globalRulesMessageJoinLabel;
const defaultMsg = isString(component)
? `${createPlaceholderMessage(component, label)}${joinLabel ? label : ''}`
: '';
: undefined;
function validator(rule: any, value: any) {
const msg = rule.message || defaultMsg;
if (value === undefined || isNull(value)) {
// 空值
return Promise.reject(msg);
Expand Down Expand Up @@ -277,7 +283,7 @@
}
return rules;
}
});
onMounted(async () => {
if (getComponentProps.value?.request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<template>
<Tooltip placement="top">
<template #title>
<span>密度</span>
<span>列设置</span>
</template>

<Popover
placement="bottomLeft"
trigger="click"
Expand All @@ -13,15 +12,15 @@
<template #title>
<div class="popover-title">
<Checkbox :indeterminate="indeterminate" v-model:checked="checkAll"> 列展示 </Checkbox>

<Checkbox v-model:checked="checkIndex" @change="handleIndexCheckChange">
序号列
</Checkbox>

<Checkbox v-model:checked="checkBordered" @change="handleBorderedCheckChange">
边框
</Checkbox>
<a-button size="small" type="link" @click="reset"> 重置 </a-button>
</div>
</template>

<template #content>
<div ref="columnListRef">
<template v-for="item in tableColumns" :key="table.getColumnKey(item)">
Expand All @@ -36,7 +35,6 @@
{{ item.title }}
</Checkbox>
</div>

<div class="column-fixed">
<Tooltip placement="bottomLeft" :mouseLeaveDelay="0.4">
<template #title> 固定到左侧 </template>
Expand Down Expand Up @@ -66,7 +64,7 @@
</template>

<script lang="ts" setup>
import { computed, nextTick, ref, unref, watch } from 'vue';
import { computed, nextTick, ref, unref, watchEffect } from 'vue';
import { Tooltip, Popover, Divider } from 'ant-design-vue';
import {
SettingOutlined,
Expand Down Expand Up @@ -98,6 +96,7 @@
});
const checkIndex = ref(defaultShowIndex);
const checkBordered = ref(table.bordered);
const columnListRef = ref<HTMLDivElement>();
// 初始化选中状态
Expand All @@ -116,17 +115,20 @@
);
});
watch(tableColumns.value, (columns) => {
table.setProps({ columns });
watchEffect(() => {
table.setProps({ columns: tableColumns.value });
});
// 设置序号列
const handleIndexCheckChange = (e) => {
table.setProps({ showIndex: e.target.checked });
};
// 设置边框
const handleBorderedCheckChange = (e) => {
table.setProps({ bordered: e.target.checked });
};
const handleColumnFixed = (columItem: TableColumn, direction: 'left' | 'right') => {
columItem.fixed = columItem.fixed === direction ? false : direction;
table.setProps({ columns: tableColumns.value });
};
async function handleVisibleChange() {
Expand All @@ -146,23 +148,16 @@
}
// Sort column
const columns = tableColumns.value;
if (oldIndex > newIndex) {
columns.splice(newIndex, 0, columns[oldIndex]);
columns.splice(oldIndex + 1, 1);
} else {
columns.splice(newIndex + 1, 0, columns[oldIndex]);
columns.splice(oldIndex, 1);
}
table.setProps({ columns });
columns.splice(newIndex, 0, columns.splice(oldIndex, 1)[0]);
},
});
initSortable();
inited = true;
}
const reset = () => {
table.setProps({ columns: cloneDeep(defaultColumns), showIndex: defaultShowIndex });
initCheckStatus();
table.setProps({ showIndex: defaultShowIndex });
};
</script>

Expand Down
5 changes: 3 additions & 2 deletions src/components/dynamic-table/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type OnChangeCallbackParams = TableProps['onChange'];
*/
export interface TableColumn<T = any> extends TableColumnType {
title: string;
dataIndex: string;
dataIndex: string | '$action';
width?: number;
/** 指定搜索的字段 */
searchField?: string;
Expand All @@ -50,7 +50,8 @@ export interface TableColumn<T = any> extends TableColumnType {
hideInTable?: boolean;
/** 传递给 Form.Item 的配置,可以配置 rules */
formItemProps?: Partial<FormItemSchema>;
bodyCell?: (params: ColumnParams<T>) => VNode | string;
bodyCell?: (params: ColumnParams<T>) => VNode;
headerCell?: (params: ColumnParams<T>) => VNode;
actions?: (params: ColumnParams<T>) => ActionItem[];
}

Expand Down
25 changes: 16 additions & 9 deletions src/router/generator-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ export const generatorDynamicRouter = (menus: API.Menu[]): RouteRecordRaw[] => {
// 后端数据, 根级树数组, 根级 PID
// listToTree(data, childrenNav, 0)
// rootRouter.children = childrenNav
const routeList = filterAsyncRoute(menus);
console.log(routeList, '根据后端返回的权限路由生成');
const layout = routes.find((item) => item.name == 'Layout')!;
layout.children = [...common, ...routeList, notFound];
// const routes = [...common,...routeList]
// routes.forEach(item => router.addRoute('Layout', item))
router.addRoute(layout);
// router.addRoute(notFound)
return layout.children;
try {
console.log('menus', menus);

const routeList = filterAsyncRoute(menus);
const layout = routes.find((item) => item.name == 'Layout')!;
console.log(routeList, '根据后端返回的权限路由生成');
layout.children = [...common, ...routeList, notFound];
// const routes = [...common,...routeList]
// routes.forEach(item => router.addRoute('Layout', item))
router.addRoute(layout);
// router.addRoute(notFound)
return layout.children;
} catch (error) {
console.error('生成路由时出错', error);
return [];
}
};
2 changes: 1 addition & 1 deletion src/views/shared/demos/form/basic-form/form-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const schemas: FormItemSchema[] = [
},
],
},
rules: [{ required: true }],
rules: [{ required: true, message: '请选择你的爱好' }],
},
{
field: 'field7',
Expand Down
4 changes: 2 additions & 2 deletions src/views/shared/demos/form/basic-form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { defineComponent, ref } from 'vue';
import { Alert, message } from 'ant-design-vue';
import { SchemaForm } from '@/components/JSON-schema-form';
import { schemas } from '../rule-form/form-schema';
import { schemas } from './form-schema';
/**
* @description 基础表单
Expand All @@ -34,7 +34,7 @@
// 点击提交
const confirm = () => {
console.log('dynamicForm.value', dynamicForm.value);
console.log('dynamicForm.value', dynamicForm.value?.formModel);
dynamicForm.value?.validate().then(() => message.success('验证通过!'));
};
Expand Down
4 changes: 2 additions & 2 deletions src/views/shared/demos/form/rule-form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { defineComponent, ref } from 'vue';
import { Alert, message } from 'ant-design-vue';
import { SchemaForm } from '@/components/JSON-schema-form';
import { schemas } from '../rule-form/form-schema';
import { schemas } from './form-schema';
/**
* @description 验证表单
Expand All @@ -34,7 +34,7 @@
// 点击提交
const confirm = () => {
console.log('dynamicForm.value', dynamicForm.value);
console.log('dynamicForm.value', dynamicForm.value?.formModel);
dynamicForm.value?.validate().then(() => message.success('验证通过!'));
};
Expand Down

0 comments on commit 9eaa568

Please sign in to comment.