Skip to content

Commit

Permalink
feat(form-page): add form page demo
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Nov 17, 2020
1 parent 4ddee05 commit 0b6110a
Show file tree
Hide file tree
Showing 43 changed files with 1,389 additions and 116 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

- 新增 base64 文件流下载
- 优化上传组件及示例
- 新增可编辑行示例
- 新增个人页
- 新增表单页

### 🎫 Chores

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ yarn clean:lib # 删除node_modules,兼容window系统

## 正在开发的功能

- [ ] 新分支全局国家化
- [ ] 示例 page 页面
- [ ] 主题配置
- [ ] 黑暗主题
- [ ] 打包 CDN
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@iconify/iconify": "^2.0.0-rc.2",
"@vueuse/core": "^4.0.0-beta.41",
"ant-design-vue": "^2.0.0-rc.1",
"ant-design-vue": "^2.0.0-beta.15",
"apexcharts": "3.22.0",
"axios": "^0.21.0",
"echarts": "^4.9.0",
Expand Down
6 changes: 5 additions & 1 deletion src/components/Basic/src/BasicHelp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
bottom: 0,
}),
},
placement: {
type: String as PropType<string>,
defualt: 'right',
},
},
setup(props, { slots }) {
const getOverlayStyleRef = computed(() => {
Expand Down Expand Up @@ -97,7 +101,7 @@
overlayClassName: 'base-help__wrap',
autoAdjustOverflow: true,
overlayStyle: unref(getOverlayStyleRef),
placement: 'right',
placement: props.placement,
getPopupContainer: () => getPopupContainer(),
},
{
Expand Down
1 change: 1 addition & 0 deletions src/components/Footer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as AppFooter } from './src/index.vue';
57 changes: 57 additions & 0 deletions src/components/Footer/src/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<div class="app-footer" :style="{ width: getWidth }">
<div class="app-footer__left">
<slot name="left" />
</div>
<div class="app-footer__right">
<slot name="right" />
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, computed, unref } from 'vue';
import { SIDE_BAR_MINI_WIDTH, SIDE_BAR_SHOW_TIT_MINI_WIDTH } from '/@/enums/appEnum';
import { appStore } from '/@/store/modules/app';
import { menuStore } from '/@/store/modules/menu';
export default defineComponent({
name: 'AppFooter',
setup() {
const getMiniWidth = computed(() => {
const {
menuSetting: { collapsedShowTitle },
} = appStore.getProjectConfig;
return collapsedShowTitle ? SIDE_BAR_SHOW_TIT_MINI_WIDTH : SIDE_BAR_MINI_WIDTH;
});
const getWidth = computed(() => {
const { getCollapsedState, getMenuWidthState } = menuStore;
const width = getCollapsedState ? unref(getMiniWidth) : getMenuWidthState;
return `calc(100% - ${width}px)`;
});
return { getWidth };
},
});
</script>
<style lang="less" scoped>
.app-footer {
position: fixed;
right: 0;
bottom: 0;
z-index: 99;
display: flex;
width: 100%;
align-items: center;
padding: 0 24px;
line-height: 44px;
background: #fff;
border-top: 1px solid #f0f0f0;
box-shadow: 0 -6px 16px -8px rgba(0, 0, 0, 0.08), 0 -9px 28px 0 rgba(0, 0, 0, 0.05),
0 -12px 48px 16px rgba(0, 0, 0, 0.03);
transition: width 0.3s;
&__left {
flex: 1 1;
}
}
</style>
29 changes: 22 additions & 7 deletions src/components/Form/src/BasicForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Form v-bind="$attrs" ref="formElRef" :model="formModel">
<Form v-bind="{ ...$attrs, ...$props }" ref="formElRef" :model="formModel">
<Row :class="getProps.compact ? 'compact-form-row' : ''">
<slot name="formHeader" />
<template v-for="schema in getSchema" :key="schema.field">
Expand Down Expand Up @@ -54,8 +54,8 @@
const formModel = reactive({});
const actionState = reactive({
resetAction: () => {},
submitAction: () => {},
resetAction: {},
submitAction: {},
});
const advanceState = reactive<AdvanceState>({
Expand All @@ -67,7 +67,7 @@
const defaultValueRef = ref<any>({});
const propsRef = ref<Partial<FormProps>>({});
const schemaRef = ref<FormSchema[] | null>(null);
const schemaRef = ref<Nullable<FormSchema[]>>(null);
const formElRef = ref<Nullable<FormActionType>>(null);
const getMergePropsRef = computed(
Expand Down Expand Up @@ -98,7 +98,15 @@
for (const schema of schemas) {
const { defaultValue, component } = schema;
if (defaultValue && dateItemType.includes(component!)) {
schema.defaultValue = moment(defaultValue);
if (!Array.isArray(defaultValue)) {
schema.defaultValue = moment(defaultValue);
} else {
const def: moment.Moment[] = [];
defaultValue.forEach((item) => {
def.push(moment(item));
});
schema.defaultValue = def;
}
}
}
return schemas as FormSchema[];
Expand Down Expand Up @@ -139,8 +147,8 @@
formModel,
getSchema,
defaultValueRef,
formElRef: formElRef as any,
schemaRef: schemaRef as any,
formElRef: formElRef as Ref<FormActionType>,
schemaRef: schemaRef as Ref<FormSchema[]>,
handleFormValues,
actionState,
});
Expand All @@ -156,6 +164,13 @@
}
);
watch(
() => getSchema.value,
() => {
initDefault();
}
);
/**
* @description:设置表单
*/
Expand Down
16 changes: 12 additions & 4 deletions src/components/Form/src/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,21 @@ export default defineComponent({
}

function renderLabelHelpMessage() {
const { label, helpMessage, helpComponentProps } = props.schema;
const { label, helpMessage, helpComponentProps, subLabel } = props.schema;
const renderLabel = subLabel ? (
<span>
{label} <span style="color:#00000073">{subLabel}</span>
</span>
) : (
label
);
if (!helpMessage || (Array.isArray(helpMessage) && helpMessage.length === 0)) {
return label;
return renderLabel;
}
return (
<span>
{label}
<BasicHelp class="mx-1" text={helpMessage} {...helpComponentProps} />
{renderLabel}
<BasicHelp placement="top" class="mx-1" text={helpMessage} {...helpComponentProps} />
</span>
);
}
Expand Down Expand Up @@ -291,6 +298,7 @@ export default defineComponent({
const { colProps = {}, colSlot, renderColContent, component } = props.schema;
if (!componentMap.has(component)) return null;
const { baseColProps = {} } = props.formProps;

const realColProps = { ...baseColProps, ...colProps };
const { isIfShow, isShow } = getShow();
const getContent = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function createPlaceholderMessage(component: ComponentType) {
if (component.includes('Input') || component.includes('Complete')) {
return '请输入';
}
if (component.includes('Picker') && !component.includes('Range')) {
if (component.includes('Picker')) {
return '请选择';
}
if (
Expand Down
15 changes: 11 additions & 4 deletions src/components/Form/src/hooks/useLabelWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,26 @@ export function useItemLabelWidth(schemaItemRef: Ref<FormSchema>, propsRef: Ref<
const { labelCol = {}, wrapperCol = {} } = schemaItem.itemProps || {};
const { labelWidth, disabledLabelWidth } = schemaItem;

const { labelWidth: globalLabelWidth } = unref(propsRef) as any;
const {
labelWidth: globalLabelWidth,
labelCol: globalLabelCol,
wrapperCol: globWrapperCol,
} = unref(propsRef) as any;

// 如果全局有设置labelWidth, 则所有item使用
if ((!globalLabelWidth && !labelWidth) || disabledLabelWidth) {
if ((!globalLabelWidth && !labelWidth && !globalLabelCol) || disabledLabelWidth) {
return { labelCol, wrapperCol };
}
let width = labelWidth || globalLabelWidth;
const col = { ...globalLabelCol, ...labelCol };
const wrapCol = { ...globWrapperCol, ...wrapperCol };

if (width) {
width = isNumber(width) ? `${width}px` : width;
}
return {
labelCol: { style: { width }, ...labelCol },
wrapperCol: { style: { width: `calc(100% - ${width})` }, ...wrapperCol },
labelCol: { style: { width }, ...col },
wrapperCol: { style: { width: `calc(100% - ${width})` }, ...wrapCol },
};
});
}
3 changes: 3 additions & 0 deletions src/components/Form/src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type RegisterFn = (formInstance: FormActionType) => void;
export type UseFormReturnType = [RegisterFn, FormActionType];

export interface FormProps {
// layout?: 'vertical' | 'inline' | 'horizontal';
// 表单值
model?: any;
// 整个表单所有项宽度
Expand Down Expand Up @@ -108,6 +109,8 @@ export interface FormSchema {
valueField?: string;
// 标签名
label: string;
// 辅助文本
subLabel?: string;
// 文本右侧帮助文本
helpMessage?: string | string[];
// BaseHelp组件props
Expand Down
3 changes: 1 addition & 2 deletions src/components/Menu/src/BasicMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ export default defineComponent({
const flag = await beforeClickFn(menu);
if (!flag) return;
}
emit('menuClick', menu);
const { path } = menu;
menuState.selectedKeys = [path];
emit('menuClick', menu);
}

function handleMenuChange() {
Expand Down Expand Up @@ -219,7 +219,6 @@ export default defineComponent({
: {};
return (
<Menu
forceSubMenuRender={props.isAppMenu}
selectedKeys={selectedKeys}
defaultSelectedKeys={defaultSelectedKeys}
mode={mode}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Table/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default as BasicTable } from './src/BasicTable.vue';
export { default as TableAction } from './src/components/TableAction';
export { default as TableImg } from './src/components/TableImg.vue';
export { renderEditableCell } from './src/components/renderEditableCell';
export { renderEditableCell, renderEditableRow } from './src/components/renderEditable';
export { default as EditTableHeaderIcon } from './src/components/EditTableHeaderIcon.vue';

export * from './src/types/table';
Expand All @@ -11,3 +11,5 @@ export * from './src/types/tableAction';
export { useTable } from './src/hooks/useTable';

export type { FormSchema, FormProps } from '/@/components/Form/src/types/form';

export type { EditRecordRow } from './src/components/renderEditable';
4 changes: 2 additions & 2 deletions src/components/Table/src/components/TableAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineComponent({
disabled={disabled}
color={color}
{...action}
key={index}
key={`${index}-${label}`}
>
{() => (
<>
Expand Down Expand Up @@ -60,7 +60,7 @@ export default defineComponent({
} = popConfirm;
return (
<Popconfirm
key={`P-${index}`}
key={`p-${index}-${title}`}
title={title}
onConfirm={confirm}
onCancel={cancel}
Expand Down
Loading

0 comments on commit 0b6110a

Please sign in to comment.