1- import { ref } from "vue" ;
1+ import { h , ref } from "vue" ;
22
3- import { getRoleList , updateRole } from "@/api/tableExample" ;
3+ import { createRole , getRoleList , updateRole } from "@/api/tableExample" ;
44// import { useUserStoreHook } from "@/store/modules/user";
55import { onStatusChange , usePublicHooks } from "@/utils/common" ;
66import { useTableBase } from "@/utils/tableHook" ;
7+ import type { FormItemProps } from "./utils/types" ;
8+ import { addDialog } from "@/components/ReDialog/index" ;
9+ import { deviceDetection } from "@pureadmin/utils" ;
10+ import editForm from "./form/index.vue" ;
11+ import { message } from "@/utils/message" ;
712
813export function useTable ( ) {
914 const switchLoadMap = ref ( { } ) ;
@@ -47,6 +52,59 @@ export function useTable() {
4752 }
4853 ] ;
4954
55+ const formRef = ref ( ) ;
56+ const ruleFormRef = ref ( ) ;
57+ function openDialog ( title = "新增" , row ?: FormItemProps ) {
58+ addDialog ( {
59+ title : `${ title } 角色` ,
60+ props : {
61+ title,
62+ formInline : {
63+ name : row ?. name ?? "" ,
64+ code : row ?. code ?? "" ,
65+ status : row ?. status ,
66+ is_super_role : row ?. is_super_role ,
67+ member : row ?. member ?? [ ] ,
68+ remark : row ?. remark ?? ""
69+ }
70+ } ,
71+ width : "46%" ,
72+ draggable : true ,
73+ fullscreen : deviceDetection ( ) ,
74+ fullscreenIcon : true ,
75+ closeOnClickModal : false ,
76+ contentRenderer : ( ) => h ( editForm , { ref : formRef , title, formInline : null } ) ,
77+ beforeSure : ( done , { options } ) => {
78+ const FormRef = formRef . value . getRef ( ) ;
79+ const curData = options . props . formInline as FormItemProps ;
80+ function chores ( ) {
81+ message ( `您${ title } 了名称为${ curData . name } 的这条数据` , {
82+ type : "success"
83+ } ) ;
84+ done ( ) ; // 关闭弹框
85+ onSearch ( ) ; // 刷新表格数据
86+ }
87+ FormRef . validate ( valid => {
88+ if ( valid ) {
89+ console . log ( "curData" , curData ) ;
90+ // 表单规则校验通过
91+ if ( title === "新增" ) {
92+ // 实际开发先调用新增接口,再进行下面操作
93+ createRole ( curData ) . then ( ( ) => {
94+ chores ( ) ;
95+ } )
96+ } else {
97+ // 实际开发先调用修改接口,再进行下面操作
98+ updateRole ( row . id , curData ) . then ( ( ) => {
99+ chores ( ) ;
100+ } )
101+ }
102+ }
103+ } ) ;
104+ }
105+ } ) ;
106+ }
107+
50108 const {
51109 tableLoading,
52110 tableColumns,
@@ -63,6 +121,7 @@ export function useTable() {
63121 tableColumns,
64122 dataList,
65123 tablePagination,
66- onSearch
124+ onSearch,
125+ openDialog
67126 } ;
68127}
0 commit comments