@@ -60,10 +60,11 @@ import {
6060 DatePicker as TinyDatePicker ,
6161 Numeric as TinyNumeric ,
6262 Pager as TinyPager ,
63- Popover as TinyPopover
63+ Popover as TinyPopover ,
64+ Notify
6465} from ' @opentiny/vue'
6566import * as tinyVueIcon from ' @opentiny/vue-icon'
66- import { getMetaApi , META_SERVICE } from ' @opentiny/tiny-engine-meta-register '
67+ import axios from ' axios '
6768
6869const props = defineProps ({
6970 style: {
@@ -169,52 +170,79 @@ const insertApi = (data = {}) => {
169170 if (! apiInfo) {
170171 return undefined
171172 }
172- return getMetaApi (META_SERVICE .Http )
173- .post (apiInfo .url , { nameEn: tableModel .value .nameEn , params: data })
174- .catch ((err ) => {
175- throw new Error (err)
176- })
173+ return axios .post (apiInfo .url , { nameEn: tableModel .value .nameEn , params: data }).catch ((err ) => {
174+ throw new Error (err)
175+ })
177176}
178177
179- const updateApi = (data ) => {
180- const apiInfo = props .modelApis .find ((api ) => api .nameEn === ' updateApi ' )
178+ const queryApi = (data = {} ) => {
179+ const apiInfo = props .modelApis .find ((api ) => api .nameEn === ' queryApi ' )
181180 if (! apiInfo) {
182181 return undefined
183182 }
184- const id = data . id
185- delete data . id
186- return getMetaApi ( META_SERVICE . Http )
183+ // 处理查询参数
184+ const params = Object . fromEntries ( tableModel . value . parameters . map (( item ) => [ item . prop , null ]))
185+ return axios
187186 .post (apiInfo .url , {
187+ currentPage: pagerState .currentPage || 1 ,
188+ pageSize: pagerState .pageSize || 10 ,
188189 nameEn: tableModel .value .nameEn ,
189- data: data,
190- params: { id }
190+ nameCn: tableModel .value .nameCn ,
191+ params: {
192+ ... params,
193+ ... data
194+ }
195+ })
196+ .then ((res ) => {
197+ if (res .data .error ) {
198+ Notify ({
199+ type: ' error' ,
200+ message: res .data .error .message ,
201+ position: ' top-right'
202+ })
203+ return
204+ }
205+ tableData .value = res .data .data .list
206+ pagerState .total = res .data .data .total
207+ return res
191208 })
192209 .catch ((err ) => {
193210 throw new Error (err)
194211 })
195212}
196213
197- const queryApi = (data ) => {
198- const apiInfo = props .modelApis .find ((api ) => api .nameEn === ' queryApi ' )
214+ const updateApi = (data ) => {
215+ const apiInfo = props .modelApis .find ((api ) => api .nameEn === ' updateApi ' )
199216 if (! apiInfo) {
200217 return undefined
201218 }
202- // 处理查询参数
203- const params = Object .fromEntries (tableModel .value .parameters .map ((item ) => [item .prop , null ]))
204- return getMetaApi (META_SERVICE .Http )
219+ const requestData = {}
220+ tableModel .value .parameters .forEach ((item ) => {
221+ if (data[item .prop ]) {
222+ requestData[item .prop ] = data[item .prop ]
223+ }
224+ })
225+ return axios
205226 .post (apiInfo .url , {
206- currentPage: pagerState .currentPage || 1 ,
207- pageSize: pagerState .pageSize || 10 ,
208227 nameEn: tableModel .value .nameEn ,
209- nameCn: tableModel .value .nameCn ,
210- params: {
211- ... params,
212- ... data
213- }
228+ data: requestData,
229+ params: { id: data .id }
214230 })
215231 .then ((res ) => {
216- tableData .value = res .list
217- pagerState .total = res .total
232+ if (res .data .error ) {
233+ Notify ({
234+ type: ' error' ,
235+ message: res .data .error .message ,
236+ position: ' top-right'
237+ })
238+ return
239+ }
240+ Notify ({
241+ type: ' success' ,
242+ message: ' 修改成功' ,
243+ position: ' top-right'
244+ })
245+ queryApi ()
218246 return res
219247 })
220248 .catch ((err ) => {
@@ -227,8 +255,25 @@ const deleteApi = (evidence) => {
227255 if (! apiInfo) {
228256 return undefined
229257 }
230- return getMetaApi ( META_SERVICE . Http )
258+ return axios
231259 .post (apiInfo .url , { ... evidence, nameEn: tableModel .value .nameEn })
260+ .then ((res ) => {
261+ if (res .data .error ) {
262+ Notify ({
263+ type: ' error' ,
264+ message: res .data .error .message ,
265+ position: ' top-right'
266+ })
267+ return
268+ }
269+ Notify ({
270+ type: ' success' ,
271+ message: ' 已删除' ,
272+ position: ' top-right'
273+ })
274+ queryApi ()
275+ return res
276+ })
232277 .catch ((err ) => {
233278 throw new Error (err)
234279 })
0 commit comments