From eac2c14fbef0246b6aee62f1090fc96a71a74860 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Wed, 6 Dec 2023 09:40:06 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=A2=9E=E5=8A=A0formWatch=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/source/modules/crud.ts | 6 +++ src/views/crud/form/watch/api.ts | 43 +++++++++++++++++ src/views/crud/form/watch/crud.tsx | 72 +++++++++++++++++++++++++++++ src/views/crud/form/watch/index.vue | 33 +++++++++++++ src/views/crud/form/watch/mock.ts | 29 ++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 src/views/crud/form/watch/api.ts create mode 100644 src/views/crud/form/watch/crud.tsx create mode 100644 src/views/crud/form/watch/index.vue create mode 100644 src/views/crud/form/watch/mock.ts diff --git a/src/router/source/modules/crud.ts b/src/router/source/modules/crud.ts index 950af05d..83a8854a 100644 --- a/src/router/source/modules/crud.ts +++ b/src/router/source/modules/crud.ts @@ -448,6 +448,12 @@ export const crudResources = [ name: "FormView", path: "/crud/form/view", component: "/crud/form/view/index.vue" + }, + { + title: "表单Watch", + name: "FormWatch", + path: "/crud/form/watch", + component: "/crud/form/watch/index.vue" } ] }, diff --git a/src/views/crud/form/watch/api.ts b/src/views/crud/form/watch/api.ts new file mode 100644 index 00000000..c7badfc5 --- /dev/null +++ b/src/views/crud/form/watch/api.ts @@ -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 } + }); +} diff --git a/src/views/crud/form/watch/crud.tsx b/src/views/crud/form/watch/crud.tsx new file mode 100644 index 00000000..52e4c0f8 --- /dev/null +++ b/src/views/crud/form/watch/crud.tsx @@ -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 => { + 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,实时计算" + } + } + } + } + }; +} diff --git a/src/views/crud/form/watch/index.vue b/src/views/crud/form/watch/index.vue new file mode 100644 index 00000000..0cd67f61 --- /dev/null +++ b/src/views/crud/form/watch/index.vue @@ -0,0 +1,33 @@ + + + diff --git a/src/views/crud/form/watch/mock.ts b/src/views/crud/form/watch/mock.ts new file mode 100644 index 00000000..5fe6a461 --- /dev/null +++ b/src/views/crud/form/watch/mock.ts @@ -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;