feat: 增加xgrid注释和判断

This commit is contained in:
xingyu4j 2022-11-15 15:22:31 +08:00
parent 4065387b54
commit 66476412bd
2 changed files with 63 additions and 8 deletions

View File

@ -37,6 +37,9 @@ const currentSize = computed(() => {
}) })
export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
/**
* grid options
*/
const gridOptions = reactive<VxeGridProps>({ const gridOptions = reactive<VxeGridProps>({
loading: true, loading: true,
size: currentSize as any, size: currentSize as any,
@ -113,24 +116,49 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
} }
}) })
// 刷新列表 /**
*
* @param ref
* @returns
*/
const reloadList = async (ref) => { const reloadList = async (ref) => {
if (!ref) {
console.error('未传入gridRef')
return
}
await nextTick() await nextTick()
ref.value?.commitProxy('query') ref.value.commitProxy('query')
} }
// 获取查询参数 // 获取查询参数
const getSearchData = async (ref) => { const getSearchData = async (ref) => {
if (!ref) {
console.error('未传入gridRef')
return
}
await nextTick() await nextTick()
const queryParams = Object.assign( const queryParams = Object.assign(
{}, {},
JSON.parse(JSON.stringify(ref.value?.getProxyInfo()?.form)) JSON.parse(JSON.stringify(ref.value.getProxyInfo()?.form))
) )
return queryParams return queryParams
} }
// 删除 /**
*
* @param ref
* @param ids rowid
* @returns
*/
const delList = async (ref, ids: string | number | string[] | number[]) => { const delList = async (ref, ids: string | number | string[] | number[]) => {
if (!ref) {
console.error('未传入gridRef')
return
}
if (!config?.delListApi) {
console.error('未传入delListApi')
return
}
await nextTick() await nextTick()
return new Promise(async () => { return new Promise(async () => {
message message
@ -141,12 +169,25 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
}) })
.finally(async () => { .finally(async () => {
// 刷新列表 // 刷新列表
ref.value?.commitProxy('query') ref.value.commitProxy('query')
}) })
}) })
} }
// 导出 /**
*
* @param ref
* @param fileName excel.xls
* @returns
*/
const exportList = async (ref, fileName?: string) => { const exportList = async (ref, fileName?: string) => {
if (!ref) {
console.error('未传入gridRef')
return
}
if (!config?.exportListApi) {
console.error('未传入exportListApi')
return
}
await nextTick() await nextTick()
const queryParams = Object.assign( const queryParams = Object.assign(
{}, {},
@ -157,12 +198,26 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
download.excel(res as unknown as Blob, fileName ? fileName : 'excel.xls') download.excel(res as unknown as Blob, fileName ? fileName : 'excel.xls')
}) })
} }
/**
* /
* @param ref
* @returns
*/
const zoom = async (ref) => {
if (!ref) {
console.error('未传入gridRef')
return
}
await nextTick()
ref.value.zoom(!ref.value.isMaximized())
}
return { return {
gridOptions, gridOptions,
reloadList, reloadList,
getSearchData, getSearchData,
delList, delList,
exportList exportList,
zoom
} }
} }

View File

@ -137,7 +137,7 @@ const handleDetail = async (rowId: number) => {
// //
const handleDelete = async (rowId: number) => { const handleDelete = async (rowId: number) => {
delList(xGrid, rowId) await delList(xGrid, rowId)
} }
// / // /