From adc522c1809dedbdda782535e8e8b64553934004 Mon Sep 17 00:00:00 2001 From: H0nGzA1 <2505811377@qq.com> Date: Wed, 17 May 2023 21:37:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AD=97=E5=85=B8=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=9A=E6=97=A0=E6=90=9C=E7=B4=A2=E6=A1=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98(https://gitee.com/huge-dream/django-vue3-adm?= =?UTF-8?q?in/issues/I6ZGNK)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/system/dictionary/subDict/crud.tsx | 441 +++++++++--------- 1 file changed, 225 insertions(+), 216 deletions(-) diff --git a/web/src/views/system/dictionary/subDict/crud.tsx b/web/src/views/system/dictionary/subDict/crud.tsx index 6e3963c..8ee841c 100644 --- a/web/src/views/system/dictionary/subDict/crud.tsx +++ b/web/src/views/system/dictionary/subDict/crud.tsx @@ -1,135 +1,144 @@ import * as api from './api'; -import { dict, UserPageQuery, AddReq, DelReq, EditReq, CrudOptions, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud'; -import { dictionary } from '/@/utils/dictionary'; +import { + dict, + UserPageQuery, + AddReq, + DelReq, + EditReq, + CrudOptions, + CreateCrudOptionsProps, + CreateCrudOptionsRet +} from '@fast-crud/fast-crud'; +import {dictionary} from '/@/utils/dictionary'; -export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { - const pageRequest = async (query: UserPageQuery) => { - return await api.GetList(query); - }; - const editRequest = async ({ form, row }: EditReq) => { - 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) => { - const data = crudExpose.getSearchFormData() - const parent = data.parent - form.parent = parent - if(parent){ - return await api.AddObj(form); - }else{ - return undefined - } +export const createCrudOptions = function ({crudExpose, context}: CreateCrudOptionsProps): CreateCrudOptionsRet { + const pageRequest = async (query: UserPageQuery) => { + return await api.GetList(query); + }; + const editRequest = async ({form, row}: EditReq) => { + 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) => { + const data = crudExpose.getSearchFormData() + const parent = data.parent + form.parent = parent + if (parent) { + return await api.AddObj(form); + } else { + return undefined + } - }; + }; - return { - crudOptions: { - request: { - pageRequest, - addRequest, - editRequest, - delRequest, - }, - rowHandle: { - //固定右侧 - fixed: 'right', - width: 200, - buttons: { - view: { - show: false, - }, - edit: { - iconRight: 'Edit', - type: 'text', - }, - remove: { - iconRight: 'Delete', - type: 'text', - }, - }, - }, - columns: { - _index: { - title: '序号', - form: { show: false }, - column: { - //type: 'index', - align: 'center', - width: '70px', - columnSetDisabled: true, //禁止在列设置中选择 - formatter: (context) => { - //计算序号,你可以自定义计算规则,此处为翻页累加 - let index = context.index ?? 1; - let pagination = crudExpose!.crudBinding.value.pagination; - // @ts-ignore - return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1; - }, - }, - }, - label: { - title: '名称', - search: { - disabled: false, - component: { - props: { - clearable: true, - }, - }, - }, - type: 'input', - form: { - rules: [ - // 表单校验规则 - { required: true, message: '名称必填项' }, - ], - component: { - props: { - clearable: true, - }, - placeholder: '请输入名称', - }, - }, - }, - type: { - title: '数据值类型', - type: 'dict-select', - search: { - disabled: true, - component: { - props: { - clearable: true, - }, - }, - }, - show: false, - dict: dict({ - data: [ - { label: 'text', value: 0 }, - { label: 'number', value: 1 }, - { label: 'date', value: 2 }, - { label: 'datetime', value: 3 }, - { label: 'time', value: 4 }, - { label: 'file', value: 5 }, - { label: 'boolean', value: 6 }, - { label: 'images', value: 7 }, - ], - }), - form: { - rules: [ - // 表单校验规则 - { required: true, message: '数据值类型必填项' }, - ], - value: 0, - component: { - props: { - clearable: true, - }, - placeholder: '请选择数据值类型', - }, - /* valueChange(key, value, form, { getColumn, mode, component, immediate, getComponent }) { + return { + crudOptions: { + request: { + pageRequest, + addRequest, + editRequest, + delRequest, + }, + rowHandle: { + //固定右侧 + fixed: 'right', + width: 200, + buttons: { + view: { + show: false, + }, + edit: { + iconRight: 'Edit', + type: 'text', + }, + remove: { + iconRight: 'Delete', + type: 'text', + }, + }, + }, + columns: { + _index: { + title: '序号', + form: {show: false}, + column: { + //type: 'index', + align: 'center', + width: '70px', + columnSetDisabled: true, //禁止在列设置中选择 + formatter: (context) => { + //计算序号,你可以自定义计算规则,此处为翻页累加 + let index = context.index ?? 1; + let pagination = crudExpose!.crudBinding.value.pagination; + // @ts-ignore + return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1; + }, + }, + }, + label: { + title: '名称', + search: { + show: true, + component: { + props: { + clearable: true, + }, + }, + }, + type: 'input', + form: { + rules: [ + // 表单校验规则 + {required: true, message: '名称必填项'}, + ], + component: { + props: { + clearable: true, + }, + placeholder: '请输入名称', + }, + }, + }, + type: { + title: '数据值类型', + type: 'dict-select', + search: { + disabled: true, + component: { + props: { + clearable: true, + }, + }, + }, + show: false, + dict: dict({ + data: [ + {label: 'text', value: 0}, + {label: 'number', value: 1}, + {label: 'date', value: 2}, + {label: 'datetime', value: 3}, + {label: 'time', value: 4}, + {label: 'file', value: 5}, + {label: 'boolean', value: 6}, + {label: 'images', value: 7}, + ], + }), + form: { + rules: [ + // 表单校验规则 + {required: true, message: '数据值类型必填项'}, + ], + value: 0, + component: { + props: { + clearable: true, + }, + placeholder: '请选择数据值类型', + }, + /* valueChange(key, value, form, { getColumn, mode, component, immediate, getComponent }) { const template = vm.getEditFormTemplate('value') // 选择框重新选择后,情况value值 if (!immediate) { @@ -178,22 +187,22 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp template.component.props = { accept: '.png,.jpeg,.jpg,.ico,.bmp,.gif', cropper: { viewMode: 1 } } } }, */ - }, - }, - value: { - title: '数据值', - search: { - disabled: true, - component: { - props: { - clearable: true, - }, - }, - }, - view: { - component: { props: { height: 100, width: 100 } }, - }, - /* // 提交时,处理数据 + }, + }, + value: { + title: '数据值', + search: { + show: true, + component: { + props: { + clearable: true, + }, + }, + }, + view: { + component: {props: {height: 100, width: 100}}, + }, + /* // 提交时,处理数据 valueResolve(row: any, col: any) { const value = row[col.key] const type = row.type @@ -225,76 +234,76 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp row[col.key] = value } }, */ - type: 'input', - form: { - rules: [ - // 表单校验规则 - { required: true, message: '数据值必填项' }, - ], - component: { - props: { - clearable: true, - }, - placeholder: '请输入数据值', - }, - }, - }, - status: { - title: '状态', - width: 80, - search: { - disabled: false, - }, - type: 'dict-radio', - dict: dict({ - data: dictionary('button_status_bool'), - }), - form: { - value: true, - rules: [ - // 表单校验规则 - { required: true, message: '状态必填项' }, - ], - }, - }, - sort: { - title: '排序', - width: 70, - type: 'number', - form: { - value: 1, - component: {}, - rules: [ - // 表单校验规则 - { required: true, message: '排序必填项' }, - ], - }, - }, - color: { - title: '标签颜色', - width: 90, - search: { - disabled: true, - }, - type: 'dict-select', - dict: dict({ - data: [ - { label: 'success', value: 'success', color: 'success' }, - { label: 'primary', value: 'primary', color: 'primary' }, - { label: 'info', value: 'info', color: 'info' }, - { label: 'danger', value: 'danger', color: 'danger' }, - { label: 'warning', value: 'warning', color: 'warning' }, - ], - }), - form: { - component: { - props: { - clearable: true, - }, - }, - }, - }, - }, - }, - }; + type: 'input', + form: { + rules: [ + // 表单校验规则 + {required: true, message: '数据值必填项'}, + ], + component: { + props: { + clearable: true, + }, + placeholder: '请输入数据值', + }, + }, + }, + status: { + title: '状态', + width: 80, + search: { + show: true + }, + type: 'dict-radio', + dict: dict({ + data: dictionary('button_status_bool'), + }), + form: { + value: true, + rules: [ + // 表单校验规则 + {required: true, message: '状态必填项'}, + ], + }, + }, + sort: { + title: '排序', + width: 70, + type: 'number', + form: { + value: 1, + component: {}, + rules: [ + // 表单校验规则 + {required: true, message: '排序必填项'}, + ], + }, + }, + color: { + title: '标签颜色', + width: 90, + search: { + disabled: true, + }, + type: 'dict-select', + dict: dict({ + data: [ + {label: 'success', value: 'success', color: 'success'}, + {label: 'primary', value: 'primary', color: 'primary'}, + {label: 'info', value: 'info', color: 'info'}, + {label: 'danger', value: 'danger', color: 'danger'}, + {label: 'warning', value: 'warning', color: 'warning'}, + ], + }), + form: { + component: { + props: { + clearable: true, + }, + }, + }, + }, + }, + }, + }; };