This commit is contained in:
chansee97 2024-03-24 18:03:57 +08:00
parent 86a4e9b10b
commit ae009e7ff4
6 changed files with 34 additions and 9 deletions

View File

@ -3,7 +3,7 @@ import type { ProxyOptions } from 'vite'
/** 不同请求服务的环境配置 */
export const proxyConfig: Record<ServiceEnvType, ServiceEnvConfig> = {
dev: {
url: 'http://localhost:3000',
url: 'https://mock.apifox.com/m1/4071143-0-default',
urlPattern: '/url-pattern',
},
test: {

View File

@ -1,7 +1,8 @@
<script setup lang="ts">
import type { RouteLocationNormalized } from 'vue-router'
import { useAppStore, useTabStore } from '@/store'
import { NIcon } from 'naive-ui'
import { renderIcon } from '@/utils'
import { useAppStore, useTabStore } from '@/store'
const tabStore = useTabStore()
const appStore = useAppStore()
@ -90,6 +91,17 @@ function handleContextMenu(e: MouseEvent, route: RouteLocationNormalized) {
function onClickoutside() {
showDropdown.value = false
}
function renderDropTabsLabel(option: any) {
return option.meta.title
}
function renderDropTabsIcon(option: any) {
return renderIcon(option.meta.icon)!()
}
function handleDropTabs(key: string, option: any) {
router.push(option.path)
}
</script>
<template>
@ -121,6 +133,20 @@ function onClickoutside() {
<e-icon :icon="item.meta.icon" /> {{ item.meta.title }}
</div>
</n-tab>
<template #suffix>
<n-dropdown
:options="tabStore.allTabs"
:render-label="renderDropTabsLabel"
:render-icon="renderDropTabsIcon"
trigger="click"
size="small"
@select="handleDropTabs"
>
<n-button tertiary circle type="primary">
<i-icon-park-outline-application-menu />
</n-button>
</n-dropdown>
</template>
</n-tabs>
<n-dropdown
placement="bottom-start"

View File

@ -11,7 +11,7 @@ export function fetchPost(data: any) {
}
/* formPost方法测试 */
export function fetchFormPost(data: any) {
const methodInstance = alovaInstance.Post('/postAPI', data)
const methodInstance = alovaInstance.Post('/postFormAPI', data)
methodInstance.meta = {
isFormPost: true,
}

View File

@ -5,12 +5,8 @@ const { url, urlPattern } = proxyConfig[import.meta.env.MODE]
const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === 'Y' || false
export const request = createAlovaInstance({
baseURL: isHttpProxy ? urlPattern : url,
})
export const alovaInstance = createAlovaInstance({
baseURL: 'https://mock.apifox.com/m1/4071143-0-default',
baseURL: isHttpProxy ? urlPattern : url,
})
export const blankInstance = createAlovaInstance({

View File

@ -14,6 +14,9 @@ export const useTabStore = defineStore('tab-store', {
currentTabPath: '',
}
},
getters: {
allTabs: state => [...state.pinTabs, ...state.tabs],
},
actions: {
addTab(route: RouteLocationNormalized) {
// 根据meta确定是否不添加可用于错误页,登录页等

View File

@ -20,7 +20,7 @@ declare namespace Service {
successCode?: number | string
}
type RequestErrorType = 'Alova' | 'Response' | 'Business'
type RequestErrorType = 'Response' | 'Business'
type RequestCode = string | number
interface RequestError {