feat: 处理接口刷新问题

main
许宏杰 2 months ago
parent 4e47261228
commit e99ab7f222

@ -9,6 +9,8 @@ import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils'
import { setOption } from '@/packages/public/chart'
import { isNil } from 'lodash'
// 获取类型
type ChartEditStoreType = typeof useChartEditStore
@ -60,7 +62,8 @@ export const useChartDataFetch = (
} = toRefs(targetComponent.request)
// 非请求类型
console.log(requestDataType.value !== RequestDataTypeEnum.AJAX)
if (requestDataType.value !== RequestDataTypeEnum.AJAX) return
try {
@ -70,13 +73,10 @@ export const useChartDataFetch = (
// requestOriginUrl 允许为空
const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl.value
if (!completePath) return
clearInterval(fetchInterval)
const fetchFn = async () => {
console.log('看板编辑')
const res = await customizeHttp(toRaw(targetComponent.request), toRaw(chartEditStore.getRequestGlobalConfig))
if (res) {
try {
const filter = targetComponent.filter
@ -93,10 +93,11 @@ export const useChartDataFetch = (
}
// 普通初始化与组件交互处理监听
watch(
const stopWatch = watch(
() => targetComponent.request.requestParams,
() => {
fetchFn()
fetchFn()
},
{
immediate: true,
@ -104,6 +105,15 @@ export const useChartDataFetch = (
}
)
if(chartEditStore.isEdit && !isPreview()){
console.log(chartEditStore.isEdit,'是否编辑')
stopWatch();
}else{
console.log(chartEditStore.isEdit,'新增或者预览')
}
// 定时时间
const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value
// 单位
@ -126,7 +136,8 @@ export const useChartDataFetch = (
if (updateCallback) updateCallback(newData)
})
: requestIntervalFn()
} else {
}
else {
requestIntervalFn()
}
return { vChartRef }

@ -248,6 +248,7 @@ export interface ChartEditStoreType {
[ChartEditStoreEnum.RECORD_CHART]?: RecordChartType
[ChartEditStoreEnum.REQUEST_GLOBAL_CONFIG]: RequestGlobalConfigType
[ChartEditStoreEnum.COMPONENT_LIST]: Array<CreateComponentType | CreateComponentGroupType>
isEdit?:Boolean
}
// 存储数据类型

@ -155,7 +155,8 @@ export const useChartEditStore = defineStore({
}
},
// 图表数组(需存储给后端)
componentList: []
componentList: [],
isEdit: true,
}),
getters: {
getProjectInfo(): ProjectInfoType {
@ -193,6 +194,10 @@ export const useChartEditStore = defineStore({
this.componentList = []
},
setEdit(booole:Boolean){
this.isEdit = booole
},
// * 获取需要存储的数据项
getStorageInfo(): ChartEditStorage {
return {

@ -43,6 +43,9 @@
import { onMounted, ref } from 'vue'
import { projectListApi, deleteProjectApi, historyMessageRoomList, historyMessageRoomDel } from '@/api/path'
import { useRouter } from 'vue-router'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
const chartEditStore = useChartEditStore()
let list = ref([])
let boardLsit = ref([])
@ -63,7 +66,8 @@ const delProjectItem = async id => {
}
const getBoardInfo = id => {
router.push('/board/' + id)
chartEditStore.setEdit(true)
router.push({path:'/board/' + id})
}
const formatFristIssue = value => {
@ -72,7 +76,10 @@ const formatFristIssue = value => {
}
//list
const messageList = async () => {
const res = await historyMessageRoomList()
const res = await historyMessageRoomList({
current: 1,
size: 100,
})
list.value = res.data.records
}
//

@ -109,6 +109,7 @@ const handlerBoard = async path => {
const handlerPath = (path, index) => {
history.value.fetchList()
chartEditStore.setComponentList()
chartEditStore.setEdit(false)
saveMessage(path)

@ -46,7 +46,7 @@
<script setup lang="ts">
import userIcon from '@/assets/images/ai/user-icon.png'
import { lineAndBar } from '../ChartDataAjax/handlerFormat.js'
import { ref, toRefs, computed, onBeforeUnmount, nextTick, watch, toRaw, reactive, onMounted } from 'vue'
import { ref, toRefs, computed, onBeforeUnmount, nextTick, watch, toRaw, reactive, watchEffect } from 'vue'
import { icon } from '@/plugins'
import { useDesignStore } from '@/store/modules/designStore/designStore'
import { SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
@ -105,11 +105,12 @@ const sendHandle = async () => {
loading: true
})
lastIndex.value = messageList.value.length - 1
if (!targetData.value.request.requestUrl) targetData.value.request.requestUrl = 'https://baijiahu.mynatapp.cc/api'
targetData.value.request = {
requestDataType: RequestDataTypeEnum.AJAX,
requestHttpType: RequestHttpEnum.POST,
requestUrl: '',
requestUrl: 'https://baijiahu.mynatapp.cc/api',
requestInterval: 300, //600
requestIntervalUnit: RequestHttpIntervalEnum.SECOND,
requestContentType: RequestContentTypeEnum.DEFAULT,
@ -119,7 +120,7 @@ const sendHandle = async () => {
},
requestParams: {
Body: {
'form-data': {},
'form-data': {prompt:keyWord.value},
'x-www-form-urlencoded': {},
json: '',
xml: ''
@ -128,6 +129,7 @@ const sendHandle = async () => {
Params: {}
}
}
try {
const res = await customizeHttp(toRaw(targetData.value.request), toRaw(chartEditStore.getRequestGlobalConfig))
loading.value = false
@ -175,6 +177,15 @@ watch(
{ deep: true }
)
// watchEffect(() => {
// const filter = targetData.value?.filter
// if (lastFilter !== filter && firstFocus) {
// lastFilter = filter
// sendHandle()
// }
// firstFocus++
// })
onBeforeUnmount(() => {
lastFilter = null
})

@ -61,7 +61,6 @@ export const dragHandle = async (e: DragEvent) => {
//默认切换成动态请求
if(chartsType.package === 'Charts'){
newComponent.request.requestDataType = 1
}else{
newComponent.request.requestDataType =0
}

Loading…
Cancel
Save