-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @ts-ignore | ||
import { requestForMock } from "/src/api/service"; | ||
const request = requestForMock; | ||
const apiPrefix = "/mock/FormWatch"; | ||
export function GetList(query: any) { | ||
return request({ | ||
url: apiPrefix + "/page", | ||
method: "get", | ||
data: query | ||
}); | ||
} | ||
|
||
export function AddObj(obj: any) { | ||
return request({ | ||
url: apiPrefix + "/add", | ||
method: "post", | ||
data: obj | ||
}); | ||
} | ||
|
||
export function UpdateObj(obj: any) { | ||
return request({ | ||
url: apiPrefix + "/update", | ||
method: "post", | ||
data: obj | ||
}); | ||
} | ||
|
||
export function DelObj(id: any) { | ||
return request({ | ||
url: apiPrefix + "/delete", | ||
method: "post", | ||
params: { id } | ||
}); | ||
} | ||
|
||
export function GetObj(id: any) { | ||
return request({ | ||
url: apiPrefix + "/get", | ||
method: "get", | ||
params: { id } | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as api from "./api"; | ||
import { AddReq, CreateCrudOptionsRet, DelReq, dict, EditReq, FormScopeContext, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud"; | ||
|
||
export default function (): CreateCrudOptionsRet { | ||
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => { | ||
return await api.GetList(query); | ||
}; | ||
const editRequest = async ({ form, row }: EditReq) => { | ||
if (form.id == null) { | ||
form.id = row.id; | ||
} | ||
return await api.UpdateObj(form); | ||
}; | ||
const delRequest = async ({ row }: DelReq) => { | ||
return await api.DelObj(row.id); | ||
}; | ||
|
||
const addRequest = async ({ form }: AddReq) => { | ||
return await api.AddObj(form); | ||
}; | ||
|
||
return { | ||
crudOptions: { | ||
settings: { | ||
viewFormUseCellComponent: true | ||
}, | ||
request: { | ||
pageRequest, | ||
addRequest, | ||
editRequest, | ||
delRequest | ||
}, | ||
form: { | ||
initialForm: { | ||
name: "123" | ||
}, | ||
watch(context: FormScopeContext) { | ||
const { form } = context; | ||
form.c = form.a + form.b; | ||
} | ||
}, | ||
columns: { | ||
name: { | ||
title: "姓名", | ||
type: "text" | ||
}, | ||
age: { | ||
title: "年龄", | ||
type: "text" | ||
}, | ||
a: { | ||
title: "a", | ||
type: "number" | ||
}, | ||
b: { | ||
title: "b", | ||
type: "number" | ||
}, | ||
c: { | ||
title: "c", | ||
type: "number", | ||
form: { | ||
component: { | ||
disabled: true | ||
}, | ||
helper: "c=a+b,实时计算" | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<fs-page> | ||
<template #header> | ||
<div class="title"> | ||
form监听 | ||
<span class="sub">监听form数据变化,触发计算操作(表单示例演示,c=a+b)</span> | ||
</div> | ||
</template> | ||
<fs-crud ref="crudRef" v-bind="crudBinding" /> | ||
</fs-page> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, onMounted } from "vue"; | ||
import { useFs } from "@fast-crud/fast-crud"; | ||
import createCrudOptions from "./crud"; | ||
export default defineComponent({ | ||
name: "FormWatch", | ||
setup() { | ||
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions }); | ||
// 页面打开后获取列表数据 | ||
onMounted(() => { | ||
crudExpose.doRefresh(); | ||
}); | ||
return { | ||
crudBinding, | ||
crudRef | ||
}; | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//@ts-ignore | ||
import mockUtil from "/src/mock/base"; | ||
|
||
const options: any = { | ||
name: "FormWatch", | ||
idGenerator: 0 | ||
}; | ||
const list = [ | ||
{ | ||
name: "王小虎", | ||
age: 15, | ||
a: 1, | ||
b: 2, | ||
c: null | ||
}, | ||
{ | ||
name: "王小虎", | ||
age: 15, | ||
a: 1, | ||
b: 3, | ||
c: null | ||
} | ||
]; | ||
|
||
options.list = list; | ||
options.copyTimes = 1000; | ||
const mock = mockUtil.buildMock(options); | ||
|
||
export default mock; |