Commit 66476412bd31a8335d456064b28a2481f0aa59cb
1 parent
4065387b
feat: 增加xgrid注释和判断
Showing
2 changed files
with
63 additions
and
8 deletions
yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts
| ... | ... | @@ -37,6 +37,9 @@ const currentSize = computed(() => { |
| 37 | 37 | }) |
| 38 | 38 | |
| 39 | 39 | export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { |
| 40 | + /** | |
| 41 | + * grid options 初始化 | |
| 42 | + */ | |
| 40 | 43 | const gridOptions = reactive<VxeGridProps>({ |
| 41 | 44 | loading: true, |
| 42 | 45 | size: currentSize as any, |
| ... | ... | @@ -113,24 +116,49 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { |
| 113 | 116 | } |
| 114 | 117 | }) |
| 115 | 118 | |
| 116 | - // 刷新列表 | |
| 119 | + /** | |
| 120 | + * 刷新列表 | |
| 121 | + * @param ref | |
| 122 | + * @returns | |
| 123 | + */ | |
| 117 | 124 | const reloadList = async (ref) => { |
| 125 | + if (!ref) { | |
| 126 | + console.error('未传入gridRef') | |
| 127 | + return | |
| 128 | + } | |
| 118 | 129 | await nextTick() |
| 119 | - ref.value?.commitProxy('query') | |
| 130 | + ref.value.commitProxy('query') | |
| 120 | 131 | } |
| 121 | 132 | |
| 122 | 133 | // 获取查询参数 |
| 123 | 134 | const getSearchData = async (ref) => { |
| 135 | + if (!ref) { | |
| 136 | + console.error('未传入gridRef') | |
| 137 | + return | |
| 138 | + } | |
| 124 | 139 | await nextTick() |
| 125 | 140 | const queryParams = Object.assign( |
| 126 | 141 | {}, |
| 127 | - JSON.parse(JSON.stringify(ref.value?.getProxyInfo()?.form)) | |
| 142 | + JSON.parse(JSON.stringify(ref.value.getProxyInfo()?.form)) | |
| 128 | 143 | ) |
| 129 | 144 | return queryParams |
| 130 | 145 | } |
| 131 | 146 | |
| 132 | - // 删除 | |
| 147 | + /** | |
| 148 | + * 删除 | |
| 149 | + * @param ref | |
| 150 | + * @param ids rowid | |
| 151 | + * @returns | |
| 152 | + */ | |
| 133 | 153 | const delList = async (ref, ids: string | number | string[] | number[]) => { |
| 154 | + if (!ref) { | |
| 155 | + console.error('未传入gridRef') | |
| 156 | + return | |
| 157 | + } | |
| 158 | + if (!config?.delListApi) { | |
| 159 | + console.error('未传入delListApi') | |
| 160 | + return | |
| 161 | + } | |
| 134 | 162 | await nextTick() |
| 135 | 163 | return new Promise(async () => { |
| 136 | 164 | message |
| ... | ... | @@ -141,12 +169,25 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { |
| 141 | 169 | }) |
| 142 | 170 | .finally(async () => { |
| 143 | 171 | // 刷新列表 |
| 144 | - ref.value?.commitProxy('query') | |
| 172 | + ref.value.commitProxy('query') | |
| 145 | 173 | }) |
| 146 | 174 | }) |
| 147 | 175 | } |
| 148 | - // 导出 | |
| 176 | + /** | |
| 177 | + * 导出 | |
| 178 | + * @param ref | |
| 179 | + * @param fileName 文件名,默认excel.xls | |
| 180 | + * @returns | |
| 181 | + */ | |
| 149 | 182 | const exportList = async (ref, fileName?: string) => { |
| 183 | + if (!ref) { | |
| 184 | + console.error('未传入gridRef') | |
| 185 | + return | |
| 186 | + } | |
| 187 | + if (!config?.exportListApi) { | |
| 188 | + console.error('未传入exportListApi') | |
| 189 | + return | |
| 190 | + } | |
| 150 | 191 | await nextTick() |
| 151 | 192 | const queryParams = Object.assign( |
| 152 | 193 | {}, |
| ... | ... | @@ -157,12 +198,26 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { |
| 157 | 198 | download.excel(res as unknown as Blob, fileName ? fileName : 'excel.xls') |
| 158 | 199 | }) |
| 159 | 200 | } |
| 201 | + /** | |
| 202 | + * 表格最大/最小化 | |
| 203 | + * @param ref | |
| 204 | + * @returns | |
| 205 | + */ | |
| 206 | + const zoom = async (ref) => { | |
| 207 | + if (!ref) { | |
| 208 | + console.error('未传入gridRef') | |
| 209 | + return | |
| 210 | + } | |
| 211 | + await nextTick() | |
| 212 | + ref.value.zoom(!ref.value.isMaximized()) | |
| 213 | + } | |
| 160 | 214 | |
| 161 | 215 | return { |
| 162 | 216 | gridOptions, |
| 163 | 217 | reloadList, |
| 164 | 218 | getSearchData, |
| 165 | 219 | delList, |
| 166 | - exportList | |
| 220 | + exportList, | |
| 221 | + zoom | |
| 167 | 222 | } |
| 168 | 223 | } | ... | ... |
yudao-ui-admin-vue3/src/views/system/post/index.vue