mirror of
https://gitee.com/dromara/go-view.git
synced 2024-12-05 13:18:48 +08:00
fix: 新增mock数据请求功能
This commit is contained in:
parent
62ed00e31c
commit
27fcec9846
@ -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,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
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -79,7 +79,7 @@
|
||||
}
|
||||
},
|
||||
"dataset": {
|
||||
"dimensions": [],
|
||||
"source": []
|
||||
"dimensions": [""],
|
||||
"source": [{}]
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user