Pārlūkot izejas kodu

fix: 新增mock数据请求功能

mtruning 3 gadi atpakaļ
vecāks
revīzija
bf020e3d3e

+ 2 - 1
src/api/axios.ts

@@ -26,11 +26,12 @@ axiosInstance.interceptors.response.use(
     if (code === ResultEnum.DATA_SUCCESS) return Promise.resolve(res.data)
     // 重定向
     if (ErrorPageNameMap.get(code)) redirectErrorPage(code)
-    return Promise.reject(res.data)
+    return Promise.resolve(res.data)
   },
   (err: AxiosResponse) => {
     const { code } = err.data as { code: number }
     if (ErrorPageNameMap.get(code)) redirectErrorPage(code)
+    window['$message'].error('接口异常,请检查!')
     Promise.reject(err)
   }
 )

+ 1 - 2
src/api/http.ts

@@ -1,11 +1,10 @@
 import axiosInstance from './axios'
 import { RequestHttpEnum, ContentTypeEnum } from '@/enums/httpEnum'
 
-export const get = (url: string, params: object) => {
+export const get = (url: string) => {
   return axiosInstance({
     url: url,
     method: RequestHttpEnum.GET,
-    params
   })
 }
 

+ 13 - 13
src/api/mock/test.mock.ts

@@ -4,37 +4,37 @@ export default {
     status: 200,
     msg: "请求成功",
     data: {
-      dimensions: ["product", "data1", "data2"],
+      dimensions: ["product", "dataOne", "dataTwo"],
       source: [
         {
           'product': '@name',
-          'data1|100-900': 3,
-          'data2|100-900': 3,
+          'dataOne|100-900': 3,
+          'dataTwo|100-900': 3,
         },
         {
           'product': '@name',
-          'data1|100-900': 3,
-          'data2|100-900': 3,
+          'dataOne|100-900': 3,
+          'dataTwo|100-900': 3,
         },
         {
           'product': '@name',
-          'data1|100-900': 3,
-          'data2|100-900': 3,
+          'dataOne1|100-900': 3,
+          'dataTwo|100-900': 3,
         },
         {
           'product': '@name',
-          'data1|100-900': 3,
-          'data2|100-900': 3,
+          'dataOne|100-900': 3,
+          'dataTwo|100-900': 3,
         },
         {
           'product': '@name',
-          'data1|100-900': 3,
-          'data2|100-900': 3,
+          'dataOne|100-900': 3,
+          'dataTwo|100-900': 3,
         },
         {
           'product': '@name',
-          'data1|100-900': 3,
-          'data2|100-900': 3,
+          'dataOne|100-900': 3,
+          'dataTwo|100-900': 3,
         },
       ]
     }

+ 1 - 0
src/packages/public/publicConfig.ts

@@ -23,6 +23,7 @@ export class publicConfig implements PublicConfigType {
   public data = { ...requestConfig }
   // 数据获取
   public requestData = []
+
   // 设置坐标
   public setPosition(x: number, y: number): void {
     this.attr.x = x

+ 2 - 2
src/settings/chartThemes/global.theme.json

@@ -79,7 +79,7 @@
     }
   },
   "dataset": {
-    "dimensions": [],
-    "source": []
+    "dimensions": [""],
+    "source": [{}]
   }
 }

+ 19 - 10
src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataAjax/index.vue

@@ -42,15 +42,17 @@
         </n-button>
       </n-space>
     </setting-item-box>
+    <go-skeleton :load="loading" :repeat="3"></go-skeleton>
     <chart-data-matching-and-show
-      v-show="showMatching"
+      v-show="showMatching && !loading"
       :targetData="targetData"
+      :ajax="true"
     ></chart-data-matching-and-show>
   </div>
 </template>
 
 <script setup lang="ts">
-import { PropType, ref, toRefs } from 'vue'
+import { PropType, ref } from 'vue'
 import { icon } from '@/plugins'
 import { CreateComponentType } from '@/packages/index.d'
 import { SettingItemBox } from '@/components/ChartItemSetting/index'
@@ -72,9 +74,8 @@ const props = defineProps({
 // 是否是开发环境
 const ISDEV = import.meta.env.DEV === true
 // 是否展示数据分析
+const loading = ref(false)
 const showMatching = ref(false)
-// 请求相关
-const { requestUrl, requestHttpType } = toRefs(props.targetData.data)
 
 // 选项
 const selectOptions: SelectHttpType[] = [
@@ -90,16 +91,24 @@ const selectOptions: SelectHttpType[] = [
 
 // 发送请求
 const sendHandle = async () => {
-  if(!requestUrl || !requestUrl.value) {
-    window['$message'].warn('请求参数不正确,请检查!')
+  loading.value = true
+  const { requestUrl, requestHttpType } = props.targetData.data
+  if(!requestUrl) {
+    window['$message'].warning('请求参数不正确,请检查!')
     return
   }
-  const res = await http(requestHttpType.value)(requestUrl.value as string, {})
-  console.log(res)
+  const res = await http(requestHttpType)((requestUrl as string).trim(), {})
+  loading.value = false
+  if(res.status === 200) {
+    // @ts-ignore
+    props.targetData.option.dataset = res.data
+    showMatching.value = true
+    return
+  }
+  window['$message'].warning('数据异常,请检查接口数据!')
 }
 </script>
 
 <style lang="scss" scoped>
-@include go('chart-configurations-data-ajax') {
-}
+@include go('chart-configurations-data-ajax') {}
 </style>

+ 10 - 4
src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMatchingAndShow/index.vue

@@ -36,7 +36,7 @@
             @before-upload="beforeUpload"
           >
             <n-space>
-              <n-button class="sourceBtn-item">
+              <n-button v-if="!ajax" class="sourceBtn-item">
                 <template #icon>
                   <n-icon>
                     <document-add-icon />
@@ -76,6 +76,11 @@ const props = defineProps({
   targetData: {
     type: Object as PropType<CreateComponentType>,
     required: true
+  },
+  ajax: {
+    type: Boolean,
+    default: false,
+    required: true
   }
 })
 
@@ -103,10 +108,11 @@ watch(() => props.targetData?.option?.dataset, (newData) => {
 
 // 处理映射列表状态结果
 const matchingHandle = (mapping: string) => {
+  let res = DataResultEnum.SUCCESS
   for (let i = 0; i < source.value.length; i++) {
-    let res = DataResultEnum.FAILURE
-    if (source.value[i][mapping] !== undefined) {
-      return DataResultEnum.SUCCESS
+    if (source.value[i][mapping] === undefined) {
+      res =  DataResultEnum.FAILURE
+      break
     }
     return res
   }