|
@@ -88,28 +88,6 @@ export async function requestResultLoadingAndInfo(fn: any, param: any, loading:
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // try {
|
|
|
|
|
- // let result = await param ? fn(param) : fn()
|
|
|
|
|
- // if (!!result && (typeof result === 'object' || result === 'function') && typeof result.then === 'function') {
|
|
|
|
|
- // result = await result.then()
|
|
|
|
|
- // }
|
|
|
|
|
- // // result.then(res => {
|
|
|
|
|
- // // console.log('rreeeeeee', res)
|
|
|
|
|
- // // })
|
|
|
|
|
- // console.log('请求结果:', result)
|
|
|
|
|
- // console.log('请求结果:', typeof result)
|
|
|
|
|
- // message.success(sucInfo)
|
|
|
|
|
- // loading.value = false;
|
|
|
|
|
- // return Promise.resolve(result);
|
|
|
|
|
- // } catch (err) {
|
|
|
|
|
- // loading.value = false;
|
|
|
|
|
- // console.warn(`${fn}调用失败: ${err}`);
|
|
|
|
|
- // const temp = errInfo + err
|
|
|
|
|
- // message.error(temp)
|
|
|
|
|
- // return Promise.resolve(temp)
|
|
|
|
|
- // }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -119,28 +97,53 @@ export async function requestResultLoadingAndInfo(fn: any, param: any, loading:
|
|
|
* @param param
|
|
* @param param
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
-export async function queryResultLoadingAndInfo(fn: Function, loading: Ref<boolean>, param?: any) {
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await param ? fn(param) : fn()
|
|
|
|
|
- let result = res
|
|
|
|
|
- if (Array.isArray(res)) {
|
|
|
|
|
- // 列表数据需要一个key,要不然会报错,统一处理
|
|
|
|
|
- result = res.map((e: any, i: number) => {
|
|
|
|
|
- if (e.hasOwnProperty('key')) {
|
|
|
|
|
- return e
|
|
|
|
|
- } else {
|
|
|
|
|
- return { ...e, key: String(i) };
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- console.log('查询数据成功:', result)
|
|
|
|
|
- loading.value = false;
|
|
|
|
|
- return Promise.resolve(result);
|
|
|
|
|
- } catch (err) {
|
|
|
|
|
- loading.value = false;
|
|
|
|
|
- console.error('查询数据失败:', err)
|
|
|
|
|
- message.error(err.message)
|
|
|
|
|
- return Promise.resolve(err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+export async function queryResultLoadingAndInfo(fn: Function, loading: Ref<boolean>, param?: any): Promise<any[]> {
|
|
|
|
|
+ loading.value = true;
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ const tempFN = param ? fn(param) : fn()
|
|
|
|
|
+ tempFN.then((res: any) => {
|
|
|
|
|
+ let result = res
|
|
|
|
|
+ if (Array.isArray(res)) {
|
|
|
|
|
+ // 列表数据需要一个key,要不然会报错,统一处理
|
|
|
|
|
+ result = res.map((e: any, i: number) => {
|
|
|
|
|
+ if (e.hasOwnProperty('key')) {
|
|
|
|
|
+ return e
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return { ...e, key: String(i) };
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('查询数据成功:', result)
|
|
|
|
|
+ loading.value = false;
|
|
|
|
|
+ resolve(result as any[]);
|
|
|
|
|
+ }).catch((err: { message: string }) => {
|
|
|
|
|
+ loading.value = false;
|
|
|
|
|
+ console.error('查询数据失败:', err)
|
|
|
|
|
+ message.error(err.message)
|
|
|
|
|
+ reject(err)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ // try {
|
|
|
|
|
+ // const res = await param ? fn(param) : fn()
|
|
|
|
|
+ // let result = res
|
|
|
|
|
+ // if (Array.isArray(res)) {
|
|
|
|
|
+ // // 列表数据需要一个key,要不然会报错,统一处理
|
|
|
|
|
+ // result = res.map((e: any, i: number) => {
|
|
|
|
|
+ // if (e.hasOwnProperty('key')) {
|
|
|
|
|
+ // return e
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // return { ...e, key: String(i) };
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }
|
|
|
|
|
+ // console.log('查询数据成功:', result)
|
|
|
|
|
+ // loading.value = false;
|
|
|
|
|
+ // return Promise.resolve(result);
|
|
|
|
|
+ // } catch (err) {
|
|
|
|
|
+ // loading.value = false;
|
|
|
|
|
+ // console.error('查询数据失败:', err)
|
|
|
|
|
+ // message.error(err.message)
|
|
|
|
|
+ // return Promise.resolve(err)
|
|
|
|
|
+ // }
|
|
|
}
|
|
}
|
|
|
|
|
|