feat:修改
This commit is contained in:
		
							parent
							
								
									ec42803348
								
							
						
					
					
						commit
						47a575a464
					
				| @ -8,7 +8,7 @@ let baseHost = globalThis.host; | |||||||
| 
 | 
 | ||||||
| // 下载模型
 | // 下载模型
 | ||||||
| export async function download() { | export async function download() { | ||||||
|   return  request({ |   return await request({ | ||||||
|     host: baseHost, |     host: baseHost, | ||||||
|     url: '/para/initEsModel.ws', |     url: '/para/initEsModel.ws', | ||||||
|     method: 'post', |     method: 'post', | ||||||
| @ -21,8 +21,9 @@ interface WR{ | |||||||
|   code?:number |   code?:number | ||||||
|   keystr?:string |   keystr?:string | ||||||
| } | } | ||||||
|  | 
 | ||||||
| // 通用监管接口
 | // 通用监管接口
 | ||||||
| export async function writeObjectOut(params,filePath?:string): Promise<WR> { | export async function writeObjectOut(params, filePath?:string): Promise<WR> { | ||||||
|   const singlePlay = globalThis.singlePlay |   const singlePlay = globalThis.singlePlay | ||||||
|   if (singlePlay) { |   if (singlePlay) { | ||||||
|     return {code:1} |     return {code:1} | ||||||
| @ -55,8 +56,8 @@ export async function writeObjectOut(params,filePath?:string): Promise<WR> { | |||||||
|       `<${key}>${drvexam[key]}</${key}>`)); |       `<${key}>${drvexam[key]}</${key}>`)); | ||||||
| 
 | 
 | ||||||
|   console.log('surenjun filePath=>',filePath); |   console.log('surenjun filePath=>',filePath); | ||||||
|  |   const fileUtil = new FileUtil(globalThis.context); | ||||||
|   if(filePath){ |   if(filePath){ | ||||||
|     const fileUtil = new FileUtil(globalThis.context); |  | ||||||
|     await fileUtil.initFolder(filePath); |     await fileUtil.initFolder(filePath); | ||||||
|     fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify({ |     fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify({ | ||||||
|       xtlb,jkxlh,jkid,drvexam:{...drvexam,zp:''}, |       xtlb,jkxlh,jkid,drvexam:{...drvexam,zp:''}, | ||||||
| @ -64,10 +65,12 @@ export async function writeObjectOut(params,filePath?:string): Promise<WR> { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //对象转换成xml
 |   //对象转换成xml
 | ||||||
|   const temp =  request({ |   let temp = {} | ||||||
|     host: globalThis.JGHOST, |   try { | ||||||
|     url: '/dems_ws/services/TmriOutAccess?wsdl', |     temp = await request({ | ||||||
|     data: `<?xml version="1.0"?>
 |       host: globalThis.JGHOST, | ||||||
|  |       url: '/dems_ws/services/TmriOutAccess?wsdl', | ||||||
|  |       data: `<?xml version="1.0"?>
 | ||||||
|                 <SOAP-ENV:Envelope |                 <SOAP-ENV:Envelope | ||||||
|                   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" |                   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" | ||||||
|                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" |                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||||||
| @ -91,20 +94,15 @@ export async function writeObjectOut(params,filePath?:string): Promise<WR> { | |||||||
|                     </writeObjectOut> |                     </writeObjectOut> | ||||||
|                  </SOAP-ENV:Body> |                  </SOAP-ENV:Body> | ||||||
|                </SOAP-ENV:Envelope>`, |                </SOAP-ENV:Envelope>`, | ||||||
|     method: 'post', |       method: 'post', | ||||||
|     xml: true |       xml: true | ||||||
|   },) |     },) | ||||||
|  |   } catch (e) { | ||||||
|  |     temp =e | ||||||
|  |   } | ||||||
|   if(filePath){ |   if(filePath){ | ||||||
|     const fileUtil = new FileUtil(globalThis.context); |  | ||||||
|     await fileUtil.initFolder(filePath); |  | ||||||
|     fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify(temp) +`\n`); |     fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify(temp) +`\n`); | ||||||
|   } |   } | ||||||
|   // const {code} = temp;
 |  | ||||||
|   // if(code == '2300007' || code == '2300028'){
 |  | ||||||
|   //   return await writeObjectOut(params,filePath)
 |  | ||||||
|   // }else{
 |  | ||||||
|   //   return temp
 |  | ||||||
|   // }
 |  | ||||||
|   return temp |   return temp | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -115,7 +113,7 @@ export async function uploadExamProgressData(params) { | |||||||
|   if (singlePlay) { |   if (singlePlay) { | ||||||
|     return |     return | ||||||
|   } |   } | ||||||
|   return  request({ |   return await request({ | ||||||
|     url: '/der2/services/exam/uploadExamDataFile.ws', |     url: '/der2/services/exam/uploadExamDataFile.ws', | ||||||
|     data: `<?xml version="1.0" encoding="UTF-8"?>
 |     data: `<?xml version="1.0" encoding="UTF-8"?>
 | ||||||
|                 <uploadExamDataFileReq> |                 <uploadExamDataFileReq> | ||||||
| @ -142,7 +140,7 @@ export async function uploadExamMileage(params) { | |||||||
|     return |     return | ||||||
|   } |   } | ||||||
|   const time = await getCurrentTime() |   const time = await getCurrentTime() | ||||||
|   return  request({ |   return await request({ | ||||||
|     url: '/der2/services/exam/uploadExamMileage.ws', |     url: '/der2/services/exam/uploadExamMileage.ws', | ||||||
|     data: `<?xml version="1.0" encoding="UTF-8"?>
 |     data: `<?xml version="1.0" encoding="UTF-8"?>
 | ||||||
|                 <uploadExamMileageReq> |                 <uploadExamMileageReq> | ||||||
| @ -168,7 +166,7 @@ export async function uploadExamGrade(params) { | |||||||
|   } |   } | ||||||
|   const paramsArrs = Reflect.ownKeys(params).map((key: string) => (`<${key}>${params[key]}</${key}>`)) |   const paramsArrs = Reflect.ownKeys(params).map((key: string) => (`<${key}>${params[key]}</${key}>`)) | ||||||
|   const time = await getCurrentTime() |   const time = await getCurrentTime() | ||||||
|   return  request({ |   return await request({ | ||||||
|     url: '/der2/services/exam/uploadExamGrade.ws', |     url: '/der2/services/exam/uploadExamGrade.ws', | ||||||
|     data: `<?xml version="1.0" encoding="UTF-8"?>
 |     data: `<?xml version="1.0" encoding="UTF-8"?>
 | ||||||
|                 <uploadExamGradeReq> |                 <uploadExamGradeReq> | ||||||
| @ -190,9 +188,10 @@ function validateIP(path: string) { | |||||||
| 
 | 
 | ||||||
| // 上传运行时常
 | // 上传运行时常
 | ||||||
| export async function uploadHarmonyLiCheng(data) { | export async function uploadHarmonyLiCheng(data) { | ||||||
|   return  request({ |   return await request({ | ||||||
|     url: '/der2/services/data/harmonyLiCheng.ws', |     url: '/der2/services/data/harmonyLiCheng.ws', | ||||||
|     data, |     data, | ||||||
|     method: 'post', |     method: 'post', | ||||||
|   }) |   }) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -35,17 +35,17 @@ export default async function writeObjectOutNew(data,filePath): Promise<WR> { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // let connectTimeout = sjbs === '02-21-000014' ?60000:1
 |   // let connectTimeout = sjbs === '02-21-000014' ?60000:1
 | ||||||
| 
 |  | ||||||
|   console.info('surenjun','调用新监管') |   console.info('surenjun','调用新监管') | ||||||
| 
 |   let temp | ||||||
|   const temp = await request({ |   try { | ||||||
|     host: globalThis.JGHOST, |     temp = await request({ | ||||||
|     method: 'post', |       host: globalThis.JGHOST, | ||||||
|     //是否是新中心
 |       method: 'post', | ||||||
|     isNewCenter: true, |       //是否是新中心
 | ||||||
|     xml: true, |       isNewCenter: true, | ||||||
|     url: '/dems_ws/services/TmriOutAccess?wsdl', |       xml: true, | ||||||
|     data: `<?xml version="1.0"?>
 |       url: '/dems_ws/services/TmriOutAccess?wsdl', | ||||||
|  |       data: `<?xml version="1.0"?>
 | ||||||
|                 <SOAP-ENV:Envelope |                 <SOAP-ENV:Envelope | ||||||
|                   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" |                   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" | ||||||
|                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" |                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||||||
| @ -63,18 +63,13 @@ export default async function writeObjectOutNew(data,filePath): Promise<WR> { | |||||||
|                     </writeObjectOut> |                     </writeObjectOut> | ||||||
|                  </SOAP-ENV:Body> |                  </SOAP-ENV:Body> | ||||||
|                </SOAP-ENV:Envelope>`, |                </SOAP-ENV:Envelope>`, | ||||||
|   }) |     }) | ||||||
|  |   } catch (e) { | ||||||
|  |     temp = e | ||||||
|  |   } | ||||||
|   if(filePath){ |   if(filePath){ | ||||||
|     const fileUtil = new FileUtil(globalThis.context); |  | ||||||
|     await fileUtil.initFolder(filePath); |  | ||||||
|     fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify(temp) +`\n`); |     fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify(temp) +`\n`); | ||||||
|   } |   } | ||||||
|   // const {code} = temp;
 |  | ||||||
|   // if(code == '2300007' || code == '2300028'){
 |  | ||||||
|   //   return await writeObjectOutNew(params,filePath)
 |  | ||||||
|   // }else{
 |  | ||||||
|   //   return temp
 |  | ||||||
|   // }
 |  | ||||||
|   return temp |   return temp | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,13 +1,10 @@ | |||||||
| import http from '@ohos.net.http'; | import http from '@ohos.net.http'; | ||||||
| import convertxml from '@ohos.convertxml'; | import convertxml from '@ohos.convertxml'; | ||||||
| import prompt from '@ohos.prompt' | import prompt from '@ohos.prompt' | ||||||
| import { sendGreen } from '../../pages/judgeSDK/utils/judgeCommon'; | import { GlobalConfig } from '../../config/index' | ||||||
| import {GlobalConfig} from '../../config/index' |  | ||||||
| import FileUtil from '../../common/utils/File'; |  | ||||||
| import { dateFormat } from '../utils/tools' |  | ||||||
| 
 | 
 | ||||||
| const config = { | const config = { | ||||||
|   host:GlobalConfig.host, |   host: GlobalConfig.host, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -22,118 +19,146 @@ const config = { | |||||||
|  */ |  */ | ||||||
| // let httpRequest = http.createHttp();
 | // let httpRequest = http.createHttp();
 | ||||||
| 
 | 
 | ||||||
| export default async function request(req: any) { | export default async function request(req: any): Promise<any> { | ||||||
|   const {url,params = {},data = {},xml,method = 'get',host,isNewCenter = false} = req; |   return new Promise((reslove, reject) => { | ||||||
|   let httpRequest = http.createHttp(); |     let httpRequest = http.createHttp(); | ||||||
|   const options = { |     const {url,params = {},data = {},xml,method = 'get',host,isNewCenter = false} = req; | ||||||
|     method: http.RequestMethod[method.toUpperCase()], |     try { | ||||||
|     header: { |       const options = { | ||||||
|       'Content-Type': xml ? 'text/xml' : 'application/json' |         method: http.RequestMethod[method.toUpperCase()], | ||||||
|     }, |         header: { | ||||||
|     extraData: xml ? data : JSON.stringify(data), |           'Content-Type': xml ? 'text/xml' : 'application/json' | ||||||
|     //15秒超时
 |         }, | ||||||
|     connectTimeout:15 * 1000 |         extraData: xml ? data : JSON.stringify(data), | ||||||
|   } |         connectTimeout:15 * 1000 | ||||||
|   //params转url拼接参数
 |       } | ||||||
|   let paramsStr  = Reflect.ownKeys(params).reduce((p: string, n: string) => (`${p}${n}=${params[n]}&`), '?') || ''; |       let paramsStr = Reflect.ownKeys(params).reduce((p: string, n: string) => (`${p}${n}=${params[n]}&`), '?') || ''; | ||||||
|   paramsStr = paramsStr.toString(); |       paramsStr = paramsStr.toString(); | ||||||
|   paramsStr = paramsStr.substring(0, paramsStr.length-1) |       paramsStr = paramsStr.substring(0, paramsStr.length - 1) | ||||||
|   try { |       let baseUrl = host ? host : globalThis.host | ||||||
|     let baseUrl=host?host:globalThis.host |       // let baseUrl=host?config.csptHost:config.host'
 | ||||||
|     // let baseUrl=host?config.csptHost:config.host'
 |       console.log('响应头地址1' + baseUrl, url, options.extraData.length) | ||||||
|     console.log('响应头地址1' + baseUrl,url,options.extraData.length) |       // const {result,responseCode} = await
 | ||||||
|     const {result,responseCode} = await httpRequest.request(`${baseUrl}${url}${paramsStr}`, {...options}); |       httpRequest.request(`${baseUrl}${url}${paramsStr}`, { | ||||||
|     // fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(arrList))
 |         ...options | ||||||
|     // writeLog({
 |       }) | ||||||
|     //     time:dateFormat(new Date()),
 |         .then(async(data) => { | ||||||
|     //     url,
 |           const result = data.result | ||||||
|     //     result:JSON.stringify(result),
 |           console.log('响应头地址' + JSON.stringify(result)) | ||||||
|     //     extraData: JSON.stringify(data),
 |           let res: any = xml ? xmlToJson(result, url) : result; | ||||||
|     //     state:'end'
 |           console.log('响应头地址' + JSON.stringify(res)) | ||||||
|     // })
 | 
 | ||||||
|     console.log('响应头地址' + JSON.stringify(result)) |           let resObj = null; | ||||||
|     let res:any = xml ? xmlToJson(result,url) : result; |           if (typeof res === "string") { | ||||||
|     console.log('响应头地址' + JSON.stringify(res)) |             res = JSON.parse(res) | ||||||
| 
 |           } | ||||||
|     let resObj = null; |           //处理中心服务code
 | ||||||
|     if(typeof res === "string"){ |           if (res.Envelope) { | ||||||
|       res=JSON.parse(res) |             const msgXml = res.Envelope.Body.writeObjectOutResponse.return; | ||||||
|     } |             //Envelope.Body.writeObjectOutResponse.return
 | ||||||
|     //处理中心服务code
 |             const dd = handleCenterCode(msgXml, isNewCenter); | ||||||
|     if(res.Envelope){ |             httpRequest.destroy(); | ||||||
|       const msgXml = res.Envelope.Body.writeObjectOutResponse.return; |             // @ts-ignore
 | ||||||
|       //Envelope.Body.writeObjectOutResponse.return
 |             reslove(dd) | ||||||
|       const dd = handleCenterCode(msgXml,isNewCenter); |             return | ||||||
|       httpRequest.destroy(); |           } | ||||||
|       return dd | 
 | ||||||
|     } |           if (!xml) { | ||||||
| 
 |             if (res.head.resultCode === '0') { | ||||||
|     if(!xml){ |               // return res
 | ||||||
|       if(res.head.resultCode === '0'){ |               httpRequest.destroy(); | ||||||
|         return res |               reslove(res) | ||||||
|       }else{ |               return | ||||||
|         const resultMessage = res?.body?.resultMessage || res?.head?.resultMessage |             } else { | ||||||
|         prompt.showToast({ |               const resultMessage = res?.body?.resultMessage || res?.head?.resultMessage | ||||||
|           message: decodeURIComponent(resultMessage), |               prompt.showToast({ | ||||||
|           duration: 3000 |                 message: decodeURIComponent(resultMessage), | ||||||
|         }); |                 duration: 3000 | ||||||
|         return false |               }); | ||||||
|  |               httpRequest.destroy(); | ||||||
|  |               reject(false) | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |           for (let i in res) { | ||||||
|  |             resObj = res[i].head | ||||||
|  |           } | ||||||
|  |           console.info('jiangsong:res in request' + url + JSON.stringify(resObj)) | ||||||
|  |           if (resObj.resultCode === '0') { | ||||||
|  |             httpRequest.destroy(); | ||||||
|  |             reslove(res) | ||||||
|  |             return | ||||||
|  |           } else { | ||||||
|  |             prompt.showToast({ | ||||||
|  |               message: decodeURIComponent(resObj.resultMessage), | ||||||
|  |               duration: 3000 | ||||||
|  |             }); | ||||||
|  |             httpRequest.destroy(); | ||||||
|  |             reject(res) | ||||||
|  |           } | ||||||
|  |         }).catch(Error=>{ | ||||||
|  |         console.info('test-error0' + url + ' error:resp: ' + JSON.stringify(Error.message)) | ||||||
|  |         prompt.showToast({ | ||||||
|  |           message: Error?.message, | ||||||
|  |           duration: 5000 | ||||||
|  |         }); | ||||||
|  |         reject(Error) | ||||||
|  |       }) | ||||||
|  |       // fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(arrList))
 | ||||||
|  |       // writeLog({
 | ||||||
|  |       //     time:dateFormat(new Date()),
 | ||||||
|  |       //     url,
 | ||||||
|  |       //     result:JSON.stringify(result),
 | ||||||
|  |       //     extraData: JSON.stringify(data),
 | ||||||
|  |       //     state:'end'
 | ||||||
|  |       // })
 | ||||||
|  | 
 | ||||||
|  |     } catch (e) { | ||||||
|  |       console.info('test-error' + url + ' error:resp: ' + JSON.stringify(e)) | ||||||
|  |       if (!e || !(e?.message)) { | ||||||
|  |         httpRequest.destroy(); | ||||||
|  |         reject({ | ||||||
|  |           code: -1 | ||||||
|  |         }) | ||||||
|  |         // httpRequest.destroy();
 | ||||||
|  |         // return {code:-1}
 | ||||||
|       } |       } | ||||||
|     } |  | ||||||
|     for( let i in res ) { |  | ||||||
|       resObj = res[i].head |  | ||||||
|     } |  | ||||||
|     console.info('jiangsong:res in request' + url + JSON.stringify(resObj)) |  | ||||||
|     if(resObj.resultCode === '0') { |  | ||||||
|       httpRequest.destroy(); |  | ||||||
|       return res |  | ||||||
|     }else { |  | ||||||
|       prompt.showToast({ |       prompt.showToast({ | ||||||
|         message: decodeURIComponent(resObj.resultMessage), |         message: e?.message, | ||||||
|         duration: 3000 |         duration: 5000 | ||||||
|       }); |       }); | ||||||
|       httpRequest.destroy(); |       reject({ | ||||||
|       return res |         code: e.code | ||||||
|  |       }) | ||||||
|  |       // return {code:e.code}
 | ||||||
|  |       // return {code:e.code}
 | ||||||
|  |       // httpRequest.destroy();
 | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
|   } catch (e) { |   }) | ||||||
|     console.info('test-error' + url  + ' error:resp: '+ JSON.stringify(e)) | 
 | ||||||
|     if(!e||!(e?.message)){ |  | ||||||
|       httpRequest.destroy(); |  | ||||||
|       return {code:-1} |  | ||||||
|     } |  | ||||||
|     const code = e?.code; |  | ||||||
|     prompt.showToast({ |  | ||||||
|       message: e?.message, |  | ||||||
|       duration: 5000 |  | ||||||
|     }); |  | ||||||
|     httpRequest.destroy(); |  | ||||||
|     switch (code){ |  | ||||||
|     //断网
 |  | ||||||
|       case 2300007: return {code:2300007} |  | ||||||
|     // 超时
 |  | ||||||
|       case 2300028: return {code:2300028} |  | ||||||
|       default: |  | ||||||
|     } |  | ||||||
|     return {code:e.code} |  | ||||||
|   } |  | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| async function writeLog(param){ |  | ||||||
|   const fileUtil = new FileUtil(globalThis.context) |  | ||||||
|   const folderPath = await fileUtil.initFolder(`/errorMsg/`); |  | ||||||
|   fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(param)+`\n`) |  | ||||||
| 
 | 
 | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| //xml格式转JSON
 | //xml格式转JSON
 | ||||||
| function xmlToJson(result,url) { | function xmlToJson(result, url) { | ||||||
|   console.log("xmlToJson begin",url); |   console.log("xmlToJson begin", url); | ||||||
|   let xmlOptions = {trim : false, declarationKey:"_declaration", |   let xmlOptions = { | ||||||
|     instructionKey : "_instruction", attributesKey : "_attributes", |     trim: false, | ||||||
|     textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype", |     declarationKey: "_declaration", | ||||||
|     commentKey : "_comment", parentKey : "_parent", typeKey : "_type", |     instructionKey: "_instruction", | ||||||
|     nameKey : "_name", elementsKey : "_elements", "skipPreprocess" : true} |     attributesKey: "_attributes", | ||||||
|  |     textKey: "_text", | ||||||
|  |     cdataKey: "_cdata", | ||||||
|  |     doctypeKey: "_doctype", | ||||||
|  |     commentKey: "_comment", | ||||||
|  |     parentKey: "_parent", | ||||||
|  |     typeKey: "_type", | ||||||
|  |     nameKey: "_name", | ||||||
|  |     elementsKey: "_elements", | ||||||
|  |     "skipPreprocess": true | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   let strXml = result.toString(); |   let strXml = result.toString(); | ||||||
|   let conv = new convertxml.ConvertXML(); |   let conv = new convertxml.ConvertXML(); | ||||||
| @ -144,41 +169,41 @@ function xmlToJson(result,url) { | |||||||
|   let {_elements:xmlArr} = conv.convertToJSObject(strXml, xmlOptions); |   let {_elements:xmlArr} = conv.convertToJSObject(strXml, xmlOptions); | ||||||
|   console.log("xmlToJson deeml begin"); |   console.log("xmlToJson deeml begin"); | ||||||
|   let res = deeml(xmlArr); |   let res = deeml(xmlArr); | ||||||
|   console.log("xmlToJson end",url); |   console.log("xmlToJson end", url); | ||||||
|   return res |   return res | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //处理中心服务code
 | //处理中心服务code
 | ||||||
| function handleCenterCode(msgXml,isNewCenter){ | function handleCenterCode(msgXml, isNewCenter) { | ||||||
|   //新监管
 |   //新监管
 | ||||||
|   if(isNewCenter){ |   if (isNewCenter) { | ||||||
|     const msg = JSON.parse(msgXml); |     const msg = JSON.parse(msgXml); | ||||||
|     const result = msg?.data[0]?.result; |     const result = msg?.data[0]?.result; | ||||||
|     if(result){ |     if (result) { | ||||||
|       const {code,message,retval} = result |       const {code,message,retval} = result | ||||||
|       if(code != '1'){ |       if (code != '1') { | ||||||
|         const rMessage = decodeURIComponent(message as string) |         const rMessage = decodeURIComponent(message as string) | ||||||
|         // globalThis.title=rMessage
 |         // globalThis.title=rMessage
 | ||||||
|         // globalThis.type='1'
 |         // globalThis.type='1'
 | ||||||
|         // globalThis.errorDialog.open()
 |         // globalThis.errorDialog.open()
 | ||||||
|         prompt.showToast({ |         prompt.showToast({ | ||||||
|           message:rMessage, |           message: rMessage, | ||||||
|           duration: 3000 |           duration: 3000 | ||||||
|         }); |         }); | ||||||
|         return {code,message} |         return { code, message } | ||||||
|       }else{ |       } else { | ||||||
|         return { code ,keystr:retval} |         return { code, keystr: retval } | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //正则匹配code message字段
 |   //正则匹配code message字段
 | ||||||
|   const [code,message,keystr] = [/<code>(.*)<\/code>/i,/<message>(.*)<\/message>/i,/<keystr>(.*)<\/keystr>/i].map(pattern=>{ |   const [code, message, keystr] = [/<code>(.*)<\/code>/i, /<message>(.*)<\/message>/i, /<keystr>(.*)<\/keystr>/i].map(pattern => { | ||||||
|     const patternArr =  pattern.exec(msgXml); |     const patternArr = pattern.exec(msgXml); | ||||||
|     return patternArr && patternArr[1] |     return patternArr && patternArr[1] | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   if(code != '1'){ |   if (code != '1') { | ||||||
|     prompt.showToast({ |     prompt.showToast({ | ||||||
|       message: decodeURIComponent(message as string), |       message: decodeURIComponent(message as string), | ||||||
|       duration: 3000 |       duration: 3000 | ||||||
| @ -186,56 +211,58 @@ function handleCenterCode(msgXml,isNewCenter){ | |||||||
|     // globalThis.type='1'
 |     // globalThis.type='1'
 | ||||||
|     // globalThis.title=decodeURIComponent(message as string)
 |     // globalThis.title=decodeURIComponent(message as string)
 | ||||||
|     // globalThis.errorDialog.open()
 |     // globalThis.errorDialog.open()
 | ||||||
|     return {code,message:decodeURIComponent(message)} |     return { code, message: decodeURIComponent(message) } | ||||||
|   }else{ |   } else { | ||||||
|     return { code ,keystr, message } |     return { code, keystr, message } | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //JSON转xml格式
 | //JSON转xml格式
 | ||||||
| const deeml = (elements,_name?)=>{ | const deeml = (elements, _name?) => { | ||||||
|   const json = {} |   const json = {} | ||||||
| 
 | 
 | ||||||
|   elements.map(ele =>{ |   elements.map(ele => { | ||||||
|     const _elements = ele._elements |     const _elements = ele._elements | ||||||
|     if(ele._type === 'element'){ |     if (ele._type === 'element') { | ||||||
|       if(_elements==undefined){ |       if (_elements == undefined) { | ||||||
|         return |         return | ||||||
|       } |       } | ||||||
|       const thisJson = json[ele._name] |       const thisJson = json[ele._name] | ||||||
|       if(_elements && _elements.length === 1 && _elements[0]._type === 'text'){ |       if (_elements && _elements.length === 1 && _elements[0]._type === 'text') { | ||||||
|         // 如果值存在了
 |         // 如果值存在了
 | ||||||
|         if(thisJson){ |         if (thisJson) { | ||||||
|           handleCommonArr(_elements[0]._text) |           handleCommonArr(_elements[0]._text) | ||||||
|         }else{ |         } else { | ||||||
|           json[ele._name] = _elements[0]._text |           json[ele._name] = _elements[0]._text | ||||||
|         } |         } | ||||||
|       }else{ |       } else { | ||||||
|         if(thisJson){ |         if (thisJson) { | ||||||
|           handleCommonArr( deeml(ele._elements,ele._name) ) |           handleCommonArr(deeml(ele._elements, ele._name)) | ||||||
|         }else{ |         } else { | ||||||
|           json[ele._name] = deeml(ele._elements,ele._name) |           json[ele._name] = deeml(ele._elements, ele._name) | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       //通用处理重复标签
 |       //通用处理重复标签
 | ||||||
|       function handleCommonArr(obj){ |       function handleCommonArr(obj) { | ||||||
|         if(thisJson){ |         if (thisJson) { | ||||||
|           if(Array.isArray(thisJson)){ |           if (Array.isArray(thisJson)) { | ||||||
|             json[ele._name].push(obj) |             json[ele._name].push(obj) | ||||||
|           }else{ |           } else { | ||||||
|             json[ele._name] = [json[ele._name],obj] |             json[ele._name] = [json[ele._name], obj] | ||||||
|           } |           } | ||||||
|         }else{ |         } else { | ||||||
|           json[ele._name] = obj |           json[ele._name] = obj | ||||||
|         } |         } | ||||||
|       }0 |       } | ||||||
|     }else{ | 
 | ||||||
|  |       0 | ||||||
|  |     } else { | ||||||
|       //标签上有属性
 |       //标签上有属性
 | ||||||
|       if(ele._attributes){ |       if (ele._attributes) { | ||||||
|         json[_name] = { |         json[_name] = { | ||||||
|           value: ele._text, |           value: ele._text, | ||||||
|           attributes:ele.__attributes |           attributes: ele.__attributes | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| @ -245,5 +272,5 @@ const deeml = (elements,_name?)=>{ | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function isEmpty(param) { | function isEmpty(param) { | ||||||
|   return!Object.keys(param).length; |   return !Object.keys(param).length; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user