MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / initApi

Function initApi

public/iframe/lib/js/commonFun.js:523–576  ·  view source on GitHub ↗
(item, isSystem = false)

Source from the content-addressed store, hash-verified

521 return JSON.parse(newParams)
522 },
523 async initApi(item, isSystem = false) {
524 // 初始化接口数据
525 let { url, method, params, dataPath, option, dataOriginConfig, componentsType, dataConversionFunction, shareApiId, shareList } = item.property;
526 if (url.includes('windowLocationOrigin')) {
527 // 自动获取
528 url = url.replace('windowLocationOrigin', window.location.origin)
529 }
530 params = this.fixParamsTime(params)
531 method = method.default;
532 if (url && method || dataOriginConfig) {
533 vm.origin && (vm.sendMsg('loading', null, { loading: true, loadingText: '正在请求数据...' }))
534 try {
535 let data = null
536 if (shareApiId && (!shareList || shareList && shareList.length === 0)) {
537 // 如果是共享api 则不去请求接口 直接获取共享接口的response数据即可 减少请求接口的次数
538 vm.origin && this.sendMsg('loading', null, { loading: false })
539 // return;
540 }
541 if (isSystem) {
542 // 系统内置api
543 data = await axios({
544 method: dataOriginConfig.method,
545 url: dataOriginConfig.url,
546 data: dataOriginConfig.body,
547 timeout: 10000
548 })
549 } else {
550 data = await axios({
551 method,
552 url,
553 data: params,
554 timeout: 10000
555 })
556 }
557 data = data.data
558 this.setData(item, data)
559 item.property.responseData = data
560 // 蓝图绑定切换组件
561 if (item.property.bluePrintConfig && item.property.bluePrintConfig.requestCompleted) {
562 // 当数据请求接口完成时执行 才执行
563 await this.handlerBluePrintConfig(item.property.bluePrintConfig, item.property.responseData)
564 }
565 await shareList && shareList.forEach(item => {
566 // 如果有绑定的组件 则修改所有绑定的组件的值
567 const shareApiTemplate = this.findTemplateForId(item)
568 this.setData(shareApiTemplate, data)
569 })
570 } catch (err) {
571 console.log(err)
572 vm.origin && vm.Toast('请求数据失败', 'error');
573 }
574 vm.origin && vm.sendMsg('loading', null, { loading: false })
575 }
576 },
577 setData(item, data) {
578 // 请求完 根据组件设置的数据绑定方式绑定数据
579 const { dataPath, option, dataConversionFunction, componentsType } = item.property;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected