From 6f98e8fb0db8554dbb18254c3a799450059c083a Mon Sep 17 00:00:00 2001 From: XiaoDaiGua-Ray <443547225@qq.com> Date: Mon, 14 Aug 2023 17:42:05 +0800 Subject: [PATCH] =?UTF-8?q?v4.1.7=E7=BB=86=E8=8A=82=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cfg.ts | 4 ++++ mock/demo/person.mock.ts | 15 +++------------ mock/shared/database.ts | 20 ++++++++++++++++++-- mock/shared/utils.ts | 4 ++++ src/components/RayTable/src/index.tsx | 1 - src/views/demo/mock-demo/index.tsx | 3 +++ tsconfig.json | 7 +++++-- 7 files changed, 37 insertions(+), 17 deletions(-) diff --git a/cfg.ts b/cfg.ts index c3367645..9ac1939b 100644 --- a/cfg.ts +++ b/cfg.ts @@ -135,6 +135,10 @@ const config: AppConfigExport = { find: '@use-images', replacement: path.resolve(__dirname, './src/assets/images'), }, + { + find: '@mock', + replacement: path.resolve(__dirname, './mock'), + }, ], } diff --git a/mock/demo/person.mock.ts b/mock/demo/person.mock.ts index 8cfefbbf..f4232eeb 100644 --- a/mock/demo/person.mock.ts +++ b/mock/demo/person.mock.ts @@ -1,26 +1,17 @@ import { defineMock } from 'vite-plugin-mock-dev-server' +import { pagination, stringify, response, array } from '@mock/shared/utils' +import { tableMock } from '@mock/shared/database' import Mock from 'mockjs' -import { pagination, stringify, response } from '../shared/utils' -import { array } from '../shared/database' export const getPersonList = defineMock({ url: '/api/list', method: 'GET', delay: 500, response: (req, res) => { - const person = () => ({ - id: Mock.Random.guid(), - address: Mock.Random.county(true), - email: Mock.Random.email(), - name: Mock.Random.cname(), - age: Mock.Random.integer(18, 60), - createDate: Mock.Random.date(), - }) - const { query: { page, pageSize, email }, } = req - let list = array(100).map(() => person()) + let list = array(100).map(() => tableMock()) let length = list.length if (!page || !pageSize) { diff --git a/mock/shared/database.ts b/mock/shared/database.ts index 8652e13d..91b817c5 100644 --- a/mock/shared/database.ts +++ b/mock/shared/database.ts @@ -9,6 +9,22 @@ * @remark 今天也是元气满满撸代码的一天 */ -export function array(length: number) { - return new Array(length).fill(0) +import Mock from 'mockjs' + +/** + * + * @param option 自定义配置 + * + * 基础表格数据 + */ +export function tableMock(option?: object) { + return { + ...option, + id: Mock.Random.guid(), + address: Mock.Random.county(true), + email: Mock.Random.email(), + name: Mock.Random.cname(), + age: Mock.Random.integer(18, 60), + createDate: Mock.Random.date(), + } } diff --git a/mock/shared/utils.ts b/mock/shared/utils.ts index bfcb991b..94ccd564 100644 --- a/mock/shared/utils.ts +++ b/mock/shared/utils.ts @@ -11,6 +11,10 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +export function array(length: number) { + return new Array(length).fill(0) +} + /** * * @param pageCurrent 当前页码 diff --git a/src/components/RayTable/src/index.tsx b/src/components/RayTable/src/index.tsx index 7a2ca908..41213fd8 100644 --- a/src/components/RayTable/src/index.tsx +++ b/src/components/RayTable/src/index.tsx @@ -255,7 +255,6 @@ const RayTable = defineComponent({ } }, render() { - console.log(this.action) return ( { + console.log(data) + }, }) const columns = [ { diff --git a/tsconfig.json b/tsconfig.json index 6d680ace..322df7b6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,9 @@ "@use-api/*": ["src/axios/api/*"], "@use-images": ["src/assets/images"], "@use-images/*": ["src/assets/images"], - "@use-micro/*": ["src/micro/*"] + "@use-micro/*": ["src/micro/*"], + "@mock/*": ["mock/*"], + "@mock": ["mock/*"] }, "suppressImplicitAnyIndexErrors": true, "typeRoots": ["./src/types/app.d.ts", "./src/types/global.d.ts"], @@ -38,6 +40,7 @@ "package.json", "vite-env.d.ts", "./unplugin/**/*", - "src/**/*" + "src/**/*", + "mock/**/*" ] }