From 06476c182e71fc8ebc51307a87cd1b2d117696ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BC=BA?= <1206709430@qq.com> Date: Tue, 26 Dec 2023 15:36:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=B1=BB=E5=9E=8B=E7=9A=84table=E5=B1=85=E4=B8=AD?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/settings.ts | 247 +++++++++++++++++++++++--------------------- 1 file changed, 128 insertions(+), 119 deletions(-) diff --git a/web/src/settings.ts b/web/src/settings.ts index badd9f7..2c79c51 100644 --- a/web/src/settings.ts +++ b/web/src/settings.ts @@ -1,127 +1,129 @@ // 引入fast-crud -import { FastCrud, useTypes } from '@fast-crud/fast-crud'; -const { getType } = useTypes(); +import {FastCrud, useTypes} from '@fast-crud/fast-crud'; + +const {getType} = useTypes(); import '@fast-crud/fast-crud/dist/style.css'; -import { setLogger } from '@fast-crud/fast-crud'; -import { getBaseURL } from '/@/utils/baseUrl'; +import {setLogger} from '@fast-crud/fast-crud'; +import {getBaseURL} from '/@/utils/baseUrl'; // element import ui from '@fast-crud/ui-element'; -import { request } from '/@/utils/service'; +import {request} from '/@/utils/service'; //扩展包 -import { FsExtendsEditor,FsExtendsUploader } from '@fast-crud/fast-extends'; +import {FsExtendsEditor, FsExtendsUploader} from '@fast-crud/fast-extends'; import '@fast-crud/fast-extends/dist/style.css'; -import { successMessage, successNotification } from '/@/utils/message'; +import {successMessage, successNotification} from '/@/utils/message'; import XEUtils from "xe-utils"; + export default { - async install(app: any, options: any) { - // 先安装ui - app.use(ui); - // 然后安装FastCrud - app.use(FastCrud, { - //i18n, //i18n配置,可选,默认使用中文,具体用法请看demo里的 src/i18n/index.js 文件 - // 此处配置公共的dictRequest(字典请求) - async dictRequest({ dict }: any) { - const {isTree} = dict - //根据dict的url,异步返回一个字典数组 - return await request({ url: dict.url, params: dict.params || {} }).then((res:any)=>{ - if(isTree){ - return XEUtils.toArrayTree(res.data,{parentKey:'parent'}) - } - return res.data - }); - }, - //公共crud配置 - commonOptions() { - return { - request: { - //接口请求配置 - //你项目后台接口大概率与fast-crud所需要的返回结构不一致,所以需要配置此项 - //请参考文档http://fast-crud.docmirror.cn/api/crud-options/request.html - transformQuery: ({ page, form, sort }: any) => { - if (sort.asc !== undefined) { - form['ordering'] = `${sort.asc ? '' : '-'}${sort.prop}`; - } - //转换为你pageRequest所需要的请求参数结构 - return { page: page.currentPage, limit: page.pageSize, ...form }; - }, - transformRes: ({ res }: any) => { - //将pageRequest的返回数据,转换为fast-crud所需要的格式 - //return {records,currentPage,pageSize,total}; - return { records: res.data, currentPage: res.page, pageSize: res.limit, total: res.total }; - }, - }, - form: { - afterSubmit(ctx: any) { - // 增加crud提示 - if (ctx.res.code == 2000) { - successNotification(ctx.res.msg); - } - }, - }, - /* search: { - layout: 'multi-line', - collapse: true, - col: { - span: 4, - }, - options: { - labelCol: { - style: { - width: '100px', - }, - }, - }, - }, */ - }; - }, - }); - //富文本 - app.use(FsExtendsEditor, { - wangEditor: { - width: 300, - }, - }); - // 文件上传 - app.use(FsExtendsUploader, { - defaultType: "form", - form: { - action: `/api/system/file/`, - name: "file", - withCredentials: false, - uploadRequest: async ({ action, file, onProgress }) => { - // @ts-ignore - const data = new FormData(); - data.append("file", file); - return await request({ - url: action, - method: "post", - timeout: 60000, - headers: { - "Content-Type": "multipart/form-data" - }, - data, - onUploadProgress: (p) => { - onProgress({ percent: Math.round((p.loaded / p.total) * 100) }); - } - }); - }, - successHandle(ret) { - // 上传完成后的结果处理, 此处应返回格式为{url:xxx,key:xxx} - return { - url: getBaseURL() + ret.data.url, - key: ret.data.id, - ...ret.data - }; - } - } - }) - setLogger({ level: 'error' }); - // 设置自动染色 - const dictComponentList = ['dict-cascader', 'dict-checkbox', 'dict-radio', 'dict-select', 'dict-switch', 'dict-tree']; - dictComponentList.forEach((val) => { - getType(val).column.component.color = 'auto'; - }); - // 设置placeholder 的默认值 + async install(app: any, options: any) { + // 先安装ui + app.use(ui); + // 然后安装FastCrud + app.use(FastCrud, { + //i18n, //i18n配置,可选,默认使用中文,具体用法请看demo里的 src/i18n/index.js 文件 + // 此处配置公共的dictRequest(字典请求) + async dictRequest({dict}: any) { + const {isTree} = dict + //根据dict的url,异步返回一个字典数组 + return await request({url: dict.url, params: dict.params || {}}).then((res: any) => { + if (isTree) { + return XEUtils.toArrayTree(res.data, {parentKey: 'parent'}) + } + return res.data + }); + }, + //公共crud配置 + commonOptions() { + return { + request: { + //接口请求配置 + //你项目后台接口大概率与fast-crud所需要的返回结构不一致,所以需要配置此项 + //请参考文档http://fast-crud.docmirror.cn/api/crud-options/request.html + transformQuery: ({page, form, sort}: any) => { + if (sort.asc !== undefined) { + form['ordering'] = `${sort.asc ? '' : '-'}${sort.prop}`; + } + //转换为你pageRequest所需要的请求参数结构 + return {page: page.currentPage, limit: page.pageSize, ...form}; + }, + transformRes: ({res}: any) => { + //将pageRequest的返回数据,转换为fast-crud所需要的格式 + //return {records,currentPage,pageSize,total}; + return {records: res.data, currentPage: res.page, pageSize: res.limit, total: res.total}; + }, + }, + form: { + afterSubmit(ctx: any) { + // 增加crud提示 + if (ctx.res.code == 2000) { + successNotification(ctx.res.msg); + } + }, + }, + /* search: { + layout: 'multi-line', + collapse: true, + col: { + span: 4, + }, + options: { + labelCol: { + style: { + width: '100px', + }, + }, + }, + }, */ + }; + }, + }); + //富文本 + app.use(FsExtendsEditor, { + wangEditor: { + width: 300, + }, + }); + // 文件上传 + app.use(FsExtendsUploader, { + defaultType: "form", + form: { + action: `/api/system/file/`, + name: "file", + withCredentials: false, + uploadRequest: async ({action, file, onProgress}) => { + // @ts-ignore + const data = new FormData(); + data.append("file", file); + return await request({ + url: action, + method: "post", + timeout: 60000, + headers: { + "Content-Type": "multipart/form-data" + }, + data, + onUploadProgress: (p) => { + onProgress({percent: Math.round((p.loaded / p.total) * 100)}); + } + }); + }, + successHandle(ret) { + // 上传完成后的结果处理, 此处应返回格式为{url:xxx,key:xxx} + return { + url: getBaseURL() + ret.data.url, + key: ret.data.id, + ...ret.data + }; + } + } + }) + setLogger({level: 'error'}); + // 设置自动染色 + const dictComponentList = ['dict-cascader', 'dict-checkbox', 'dict-radio', 'dict-select', 'dict-switch', 'dict-tree']; + dictComponentList.forEach((val) => { + getType(val).column.component.color = 'auto'; + }); + // 设置placeholder 的默认值 const placeholderComponentList = [ {key: 'text', placeholder: "请输入"}, {key: 'textarea', placeholder: "请输入"}, @@ -131,14 +133,21 @@ export default { placeholderComponentList.forEach((val) => { if (getType(val.key)?.search?.component) { getType(val.key).search.component.placeholder = val.placeholder; - } else if(getType(val.key)?.search) { + } else if (getType(val.key)?.search) { getType(val.key).search.component = {placeholder: val.placeholder}; } if (getType(val.key)?.form?.component) { getType(val.key).form.component.placeholder = val.placeholder; - } else if(getType(val.key)?.form) { + } else if (getType(val.key)?.form) { getType(val.key).form.component = {placeholder: val.placeholder}; } + if (getType(val.key)?.column?.align) { + getType(val.key).column.align = 'center' + } else if (getType(val.key)?.column) { + getType(val.key).column = {align: 'center'}; + } else if (getType(val.key)) { + getType(val.key).column = {align: 'center'}; + } }); - }, + }, }; From e900cc228042f2f004f056b73cea702d3571815d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BC=BA?= <1206709430@qq.com> Date: Tue, 26 Dec 2023 15:38:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=B1=BB=E5=9E=8B=E7=9A=84table=E5=B1=85=E4=B8=AD?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/settings.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/settings.ts b/web/src/settings.ts index f40c4cc..5c2a477 100644 --- a/web/src/settings.ts +++ b/web/src/settings.ts @@ -11,9 +11,8 @@ import {request} from '/@/utils/service'; //扩展包 import {FsExtendsEditor, FsExtendsUploader} from '@fast-crud/fast-extends'; import '@fast-crud/fast-extends/dist/style.css'; -import {successMessage, successNotification} from '/@/utils/message'; +import {successNotification} from '/@/utils/message'; import XEUtils from "xe-utils"; -import {commonCrudConfig} from "/@/utils/commonCrud"; export default { async install(app: any, options: any) { // 先安装ui @@ -122,6 +121,7 @@ export default { const dictComponentList = ['dict-cascader', 'dict-checkbox', 'dict-radio', 'dict-select', 'dict-switch', 'dict-tree']; dictComponentList.forEach((val) => { getType(val).column.component.color = 'auto'; + getType(val).column.align = 'center'; }); // 设置placeholder 的默认值 const placeholderComponentList = [ From 87f978444538235aa63841cdd4d210844ba61ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BC=BA?= <1206709430@qq.com> Date: Tue, 26 Dec 2023 15:39:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96commonCrudConfig?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/utils/commonCrud.ts | 153 +++++++++++++++++++++--------------- 1 file changed, 91 insertions(+), 62 deletions(-) diff --git a/web/src/utils/commonCrud.ts b/web/src/utils/commonCrud.ts index b9719a7..7aed387 100644 --- a/web/src/utils/commonCrud.ts +++ b/web/src/utils/commonCrud.ts @@ -32,71 +32,11 @@ export const commonCrudConfig = (options = { }, }) => { return { - description: { - title: '备注', - search: { - show: options.description?.search || false - }, - type: 'textarea', - column: { - show: options.description?.table || false, - }, - form: { - component: { - show: options.description?.form || false, - placeholder: '请输入内容', - showWordLimit: true, - maxlength: '200', - } - } - }, - modifier_name: { - title: '修改人', - search: { - show: options.modifier_name?.search || false - }, - column: { - width: 100, - show: options.modifier_name?.table || false, - } - }, - update_datetime: { - title: '更新时间', - type: 'datetime', - search: { - show: options.update_datetime?.search || false - }, - column: { - width: 160, - show: options.update_datetime?.table || false, - } - }, - creator_name: { - title: '创建人', - search: { - show: options.creator_name?.search || false - }, - column: { - width: 100, - show: options.creator_name?.table || false, - } - }, - create_datetime: { - title: '创建时间', - type: 'datetime', - search: { - show: options.create_datetime?.search || false - }, - column: { - width: 160, - show: options.create_datetime?.table || false, - } - }, dept_belong_id: { title: '所属部门', type: 'dict-tree', search: { - show: false + show: false }, dict: dict({ url: '/api/system/dept/all_dept/', @@ -106,12 +46,13 @@ export const commonCrudConfig = (options = { children: 'children' // 数据字典中children字段的属性名 }), column: { + align: 'center', width: 150, show: options.dept_belong_id?.table || false, }, form: { + show: options.dept_belong_id?.form || false, component: { - show: options.dept_belong_id?.form || false, multiple: false, clearable: true, props: { @@ -125,6 +66,94 @@ export const commonCrudConfig = (options = { }, helper: "默认不填则为当前创建用户的部门ID" } + }, + description: { + title: '备注', + search: { + show: options.description?.search || false + }, + type: 'textarea', + column: { + width: 100, + show: options.description?.table || false, + }, + form: { + show: options.description?.form || false, + component: { + placeholder: '请输入内容', + showWordLimit: true, + maxlength: '200', + } + }, + viewForm: { + show: true + } + }, + modifier_name: { + title: '修改人', + search: { + show: options.modifier_name?.search || false + }, + column: { + width: 100, + show: options.modifier_name?.table || false, + }, + form: { + show: false, + }, + viewForm: { + show: true + } + }, + creator_name: { + title: '创建人', + search: { + show: options.creator_name?.search || false + }, + column: { + width: 100, + show: options.creator_name?.table || false, + }, + form: { + show: false, + }, + viewForm: { + show: true + } + }, + update_datetime: { + title: '更新时间', + type: 'datetime', + search: { + show: options.update_datetime?.search || false + }, + column: { + width: 160, + show: options.update_datetime?.table || false, + }, + form: { + show: false, + }, + viewForm: { + show: true + } + }, + create_datetime: { + title: '创建时间', + type: 'datetime', + search: { + show: options.create_datetime?.search || false + }, + column: { + width: 160, + show: options.create_datetime?.table || false, + }, + form: { + show: false, + }, + viewForm: { + show: true + } } } }