Skip to content

Commit

Permalink
Merge pull request #9 from WeBankFinTech/fix-events
Browse files Browse the repository at this point in the history
fix: 事件参数
  • Loading branch information
aringlai authored Jul 27, 2023
2 parents a62fbad + 2d2f24a commit be7c63b
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 7 deletions.
95 changes: 95 additions & 0 deletions cypress/component/Event.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { ComponentType, EnumOption, FormSceneContext, TableSceneContext, doInitFields, doValidate, useForm, useSceneContext, useTable } from '@koala-form/core';
import { defineComponent, ref } from 'vue';

const Test = defineComponent({
setup() {
const {
ctxs: [form, table],
} = useSceneContext(['form', 'table']);

const formValue = ref();
const tableValue = ref();

useForm({
ctx: form as FormSceneContext,
fields: [
{
name: 'name',
label: '选中',
required: true,
components: {
name: ComponentType.Checkbox,
props: { id: 'name' },
events: {
onChange(val) {
formValue.value = val;
},
},
},
},
{
label: 'formValue',
components: {
name: 'div',
props: { id: 'formValue' },
slots: {
default: () => formValue.value,
},
},
},
{
label: 'tableValue',
components: {
name: 'div',
props: { id: 'tableValue' },
slots: {
default: () => tableValue.value,
},
},
},
],
});

useTable({
ctx: table as TableSceneContext,
table: { name: ComponentType.Table },
fields: [
{
name: 'name',
label: '选中',
required: true,
components: {
name: ComponentType.Checkbox,
props: { id: 'colName' },
events: {
onChange(record, val) {
tableValue.value = record.row.name + '' + val;
},
},
},
},
],
});

table.modelRef.value = [{ name: true }];

return () => [form.render(), table.render()];
},
});

describe('useForm.cy.tsx', () => {
it('表单场景渲染', () => {
const app = cy.mount(Test);
app.get('#name').click();
app.get('#formValue').contains('true');

app.get('#name').click();
app.get('#formValue').contains('false');

app.get('#colName').click();
app.get('#tableValue').contains('truetrue');

app.get('#colName').click();
app.get('#tableValue').contains('truefalse');
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@vitejs/plugin-vue": "^4.2.3",
"npm-run-all": "4.1.5",
"commitizen": "^4.2.1",
"vite": "^4.4.7",
"cz-conventional-changelog": "^3.3.0",
"conventional-changelog-cli": "^2.2.2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@koala-form/core",
"version": "2.0.1",
"version": "2.0.2",
"description": "基于Vue3的中后台表单解决方案",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/plugins/renderPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { PluginFunction } from './define';

const wrapProps = (props: Record<string, any>, slotParams?: any) => {
const _props = { ...props };
if (slotParams) {
if (slotParams?.__koalaColFlag) {
Object.keys(props).forEach((key) => {
if (isFunction(props[key]) && !key.startsWith('onUpdate')) {
if (isFunction(props[key]) && key.startsWith('on') && !key.startsWith('onUpdate:')) {
_props[key] = (...args: any[]) => props[key](slotParams, ...args);
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/useTable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export interface TableSceneContext extends SceneContext {
}

export interface TableSceneConfig extends SceneConfig {
ctx: TableSceneContext;
table: ComponentDesc;
ctx?: TableSceneContext;
table?: ComponentDesc;
fields: Field[];
}

Expand Down
Loading

0 comments on commit be7c63b

Please sign in to comment.