Commit 66476412bd31a8335d456064b28a2481f0aa59cb

Authored by xingyu4j
1 parent 4065387b

feat: 增加xgrid注释和判断

yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts
@@ -37,6 +37,9 @@ const currentSize = computed(() => { @@ -37,6 +37,9 @@ const currentSize = computed(() => {
37 }) 37 })
38 38
39 export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { 39 export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
  40 + /**
  41 + * grid options 初始化
  42 + */
40 const gridOptions = reactive<VxeGridProps>({ 43 const gridOptions = reactive<VxeGridProps>({
41 loading: true, 44 loading: true,
42 size: currentSize as any, 45 size: currentSize as any,
@@ -113,24 +116,49 @@ export const useVxeGrid = &lt;T = any&gt;(config?: UseVxeGridConfig&lt;T&gt;) =&gt; { @@ -113,24 +116,49 @@ export const useVxeGrid = &lt;T = any&gt;(config?: UseVxeGridConfig&lt;T&gt;) =&gt; {
113 } 116 }
114 }) 117 })
115 118
116 - // 刷新列表 119 + /**
  120 + * 刷新列表
  121 + * @param ref
  122 + * @returns
  123 + */
117 const reloadList = async (ref) => { 124 const reloadList = async (ref) => {
  125 + if (!ref) {
  126 + console.error('未传入gridRef')
  127 + return
  128 + }
118 await nextTick() 129 await nextTick()
119 - ref.value?.commitProxy('query') 130 + ref.value.commitProxy('query')
120 } 131 }
121 132
122 // 获取查询参数 133 // 获取查询参数
123 const getSearchData = async (ref) => { 134 const getSearchData = async (ref) => {
  135 + if (!ref) {
  136 + console.error('未传入gridRef')
  137 + return
  138 + }
124 await nextTick() 139 await nextTick()
125 const queryParams = Object.assign( 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 return queryParams 144 return queryParams
130 } 145 }
131 146
132 - // 删除 147 + /**
  148 + * 删除
  149 + * @param ref
  150 + * @param ids rowid
  151 + * @returns
  152 + */
133 const delList = async (ref, ids: string | number | string[] | number[]) => { 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 await nextTick() 162 await nextTick()
135 return new Promise(async () => { 163 return new Promise(async () => {
136 message 164 message
@@ -141,12 +169,25 @@ export const useVxeGrid = &lt;T = any&gt;(config?: UseVxeGridConfig&lt;T&gt;) =&gt; { @@ -141,12 +169,25 @@ export const useVxeGrid = &lt;T = any&gt;(config?: UseVxeGridConfig&lt;T&gt;) =&gt; {
141 }) 169 })
142 .finally(async () => { 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 const exportList = async (ref, fileName?: string) => { 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 await nextTick() 191 await nextTick()
151 const queryParams = Object.assign( 192 const queryParams = Object.assign(
152 {}, 193 {},
@@ -157,12 +198,26 @@ export const useVxeGrid = &lt;T = any&gt;(config?: UseVxeGridConfig&lt;T&gt;) =&gt; { @@ -157,12 +198,26 @@ export const useVxeGrid = &lt;T = any&gt;(config?: UseVxeGridConfig&lt;T&gt;) =&gt; {
157 download.excel(res as unknown as Blob, fileName ? fileName : 'excel.xls') 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 return { 215 return {
162 gridOptions, 216 gridOptions,
163 reloadList, 217 reloadList,
164 getSearchData, 218 getSearchData,
165 delList, 219 delList,
166 - exportList 220 + exportList,
  221 + zoom
167 } 222 }
168 } 223 }
yudao-ui-admin-vue3/src/views/system/post/index.vue
@@ -137,7 +137,7 @@ const handleDetail = async (rowId: number) =&gt; { @@ -137,7 +137,7 @@ const handleDetail = async (rowId: number) =&gt; {
137 137
138 // 删除操作 138 // 删除操作
139 const handleDelete = async (rowId: number) => { 139 const handleDelete = async (rowId: number) => {
140 - delList(xGrid, rowId) 140 + await delList(xGrid, rowId)
141 } 141 }
142 142
143 // 提交新增/修改的表单 143 // 提交新增/修改的表单