修复文件地址
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { Alova } from '@/utils/http/alova/index';
|
||||
import { ResultEnum } from '@/enums/httpEnum';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
import { ACCESS_TOKEN } from '@/store/mutation-types';
|
||||
import { storage } from '@/utils/Storage';
|
||||
import { useGlobSetting } from '@/hooks/setting';
|
||||
import { replaceToLogin } from '@/utils/loginRedirect';
|
||||
|
||||
const LOAN_FILE_HOST = 'http://192.168.1.26:7060';
|
||||
const { fileUrl = '', apiUrl = '', urlPrefix = '' } = useGlobSetting();
|
||||
|
||||
export interface LoanApplicationQueryListReq {
|
||||
pageNum: number;
|
||||
@@ -59,7 +60,23 @@ export interface LoanApplicationPageRes {
|
||||
export function getLoanFileUrl(file?: LoanFileObj) {
|
||||
if (!file?.url) return '';
|
||||
if (/^https?:\/\//i.test(file.url)) return file.url;
|
||||
return `${LOAN_FILE_HOST}${file.url.startsWith('/') ? file.url : `/${file.url}`}`;
|
||||
const fileHost = fileUrl.replace(/\/+$/, '');
|
||||
return `${fileHost}${file.url.startsWith('/') ? file.url : `/${file.url}`}`;
|
||||
}
|
||||
|
||||
function joinUrl(...parts: string[]) {
|
||||
return parts
|
||||
.filter(Boolean)
|
||||
.map((part, index) =>
|
||||
index === 0 ? part.replace(/\/+$/, '') : part.replace(/^\/+|\/+$/g, '')
|
||||
)
|
||||
.join('/');
|
||||
}
|
||||
|
||||
function getApiUrl(path: string) {
|
||||
const apiBase = joinUrl(apiUrl, urlPrefix);
|
||||
if (!apiBase) return path;
|
||||
return `${apiBase}${path.startsWith('/') ? path : `/${path}`}`;
|
||||
}
|
||||
|
||||
interface FinResult<T> {
|
||||
@@ -120,15 +137,8 @@ export async function handleLoanApplication(params: LoanApplicationHandleReq) {
|
||||
}
|
||||
|
||||
function redirectToLogin() {
|
||||
const { pathname, search, hash } = window.location;
|
||||
const currentPath = `${pathname}${search}${hash}`;
|
||||
const redirectPath =
|
||||
pathname === PageEnum.BASE_LOGIN
|
||||
? PageEnum.BASE_LOGIN
|
||||
: `${PageEnum.BASE_LOGIN}?redirect=${encodeURIComponent(currentPath)}`;
|
||||
|
||||
storage.clear();
|
||||
window.location.replace(redirectPath);
|
||||
replaceToLogin();
|
||||
}
|
||||
|
||||
function getExportFileName(disposition: string | null) {
|
||||
@@ -149,7 +159,7 @@ function getExportFileName(disposition: string | null) {
|
||||
|
||||
export async function exportLoanApplicationList(params: LoanApplicationQueryListReq) {
|
||||
const token = storage.get(ACCESS_TOKEN, '');
|
||||
const response = await fetch('/loan/application/export', {
|
||||
const response = await fetch(getApiUrl('/loan/application/export'), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@@ -61,7 +61,7 @@ export function getUserInfo() {
|
||||
*/
|
||||
export function login(params: LoginParams) {
|
||||
return Alova.Post<LoginRes>(
|
||||
'/fg-api/user/login',
|
||||
'/user/login',
|
||||
params,
|
||||
{
|
||||
meta: {
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
<template>
|
||||
<RouterView>
|
||||
<template #default="{ Component, route }">
|
||||
<template v-if="mode === 'production'">
|
||||
<transition :name="getTransitionName" mode="out-in" appear>
|
||||
<keep-alive v-if="keepAliveComponents.length" :include="keepAliveComponents">
|
||||
<component :is="Component" :key="route.fullPath" />
|
||||
</keep-alive>
|
||||
<component v-else :is="Component" :key="route.fullPath" />
|
||||
</transition>
|
||||
</template>
|
||||
<template v-else>
|
||||
<keep-alive v-if="keepAliveComponents.length" :include="keepAliveComponents">
|
||||
<component :is="Component" :key="route.fullPath" />
|
||||
</keep-alive>
|
||||
<component v-else :is="Component" :key="route.fullPath" />
|
||||
</template>
|
||||
<keep-alive v-if="keepAliveComponents.length" :include="keepAliveComponents">
|
||||
<component :is="Component" :key="route.fullPath" />
|
||||
</keep-alive>
|
||||
<component v-else :is="Component" :key="route.fullPath" />
|
||||
</template>
|
||||
</RouterView>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent, computed, unref } from 'vue';
|
||||
import { defineComponent, computed } from 'vue';
|
||||
import { useAsyncRouteStore } from '@/store/modules/asyncRoute';
|
||||
import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MainView',
|
||||
@@ -38,20 +27,12 @@
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
const { isPageAnimate, pageAnimateType } = useProjectSetting();
|
||||
const asyncRouteStore = useAsyncRouteStore();
|
||||
// 需要缓存的路由组件
|
||||
const keepAliveComponents = computed(() => asyncRouteStore.keepAliveComponents);
|
||||
|
||||
const getTransitionName = computed(() => {
|
||||
return unref(isPageAnimate) ? unref(pageAnimateType) : '';
|
||||
});
|
||||
|
||||
const mode = import.meta.env.MODE;
|
||||
return {
|
||||
keepAliveComponents,
|
||||
getTransitionName,
|
||||
mode,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -6,9 +6,9 @@ import mocks from './mocks';
|
||||
import { useUser } from '@/store/modules/user';
|
||||
import { storage } from '@/utils/Storage';
|
||||
import { useGlobSetting } from '@/hooks/setting';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
import { ResultEnum } from '@/enums/httpEnum';
|
||||
import { isUrl } from '@/utils';
|
||||
import { replaceToLogin } from '@/utils/loginRedirect';
|
||||
|
||||
const { useMock, apiUrl, urlPrefix, loggerMock } = useGlobSetting();
|
||||
|
||||
@@ -34,14 +34,8 @@ const mockAdapter = createAlovaMockAdapter([...mocks], {
|
||||
});
|
||||
|
||||
function redirectToLogin() {
|
||||
const loginPath = PageEnum.BASE_LOGIN;
|
||||
const { pathname, search, hash } = window.location;
|
||||
const currentPath = `${pathname}${search}${hash}`;
|
||||
const redirectPath =
|
||||
pathname === loginPath ? loginPath : `${loginPath}?redirect=${encodeURIComponent(currentPath)}`;
|
||||
|
||||
storage.clear();
|
||||
window.location.replace(redirectPath);
|
||||
replaceToLogin();
|
||||
}
|
||||
|
||||
export const Alova = createAlova({
|
||||
@@ -122,7 +116,6 @@ export const Alova = createAlova({
|
||||
// @ts-ignore
|
||||
const Modal = window.$dialog;
|
||||
|
||||
const LoginPath = PageEnum.BASE_LOGIN;
|
||||
if (ResultEnum.SUCCESS === code) {
|
||||
return result;
|
||||
}
|
||||
@@ -136,7 +129,7 @@ export const Alova = createAlova({
|
||||
maskClosable: false,
|
||||
onOk: async () => {
|
||||
storage.clear();
|
||||
window.location.href = LoginPath;
|
||||
replaceToLogin();
|
||||
},
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { getLoanFileUrl } from '@/api/loan/application';
|
||||
import type { LoanApplicationQueryListRes, LoanFileObj } from '@/api/loan/application';
|
||||
@@ -186,12 +186,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
function scrollToTop() {
|
||||
nextTick(() => {
|
||||
window.scrollTo({ top: 0, left: 0 });
|
||||
document.documentElement.scrollTop = 0;
|
||||
document.body.scrollTop = 0;
|
||||
|
||||
document
|
||||
.querySelectorAll<HTMLElement>('.layout-content, .main-view, .n-layout-scroll-container')
|
||||
.forEach((element) => {
|
||||
element.scrollTop = 0;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
router.push({ name: 'LoanApplication' });
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadDetail();
|
||||
scrollToTop();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -452,12 +452,15 @@
|
||||
}
|
||||
|
||||
function openDetail(row: LoanApplicationQueryListRes) {
|
||||
sessionStorage.setItem(`${DETAIL_STORAGE_PREFIX}:${row.id}`, JSON.stringify(row));
|
||||
if (!row.id) {
|
||||
message.error('申请记录缺少ID,无法打开详情');
|
||||
return;
|
||||
}
|
||||
|
||||
const id = String(row.id);
|
||||
sessionStorage.setItem(`${DETAIL_STORAGE_PREFIX}:${id}`, JSON.stringify(row));
|
||||
router.push({
|
||||
name: 'LoanApplicationDetail',
|
||||
params: {
|
||||
id: row.id,
|
||||
},
|
||||
path: `/loan/application/${id}`,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { ResultEnum } from '@/enums/httpEnum';
|
||||
@@ -89,6 +89,21 @@
|
||||
const userStore = useUserStore();
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
function getRedirectPath() {
|
||||
const redirect = route.query.redirect;
|
||||
const value = Array.isArray(redirect) ? redirect[0] : redirect;
|
||||
if (!value || value.startsWith('http') || value.startsWith('//')) return PageEnum.BASE_HOME;
|
||||
|
||||
const hashIndex = value.indexOf('#');
|
||||
if (hashIndex >= 0) {
|
||||
const hashPath = value.slice(hashIndex + 1);
|
||||
return hashPath.startsWith('/') ? hashPath : `/${hashPath}`;
|
||||
}
|
||||
|
||||
return value.startsWith('/') ? value : PageEnum.BASE_HOME;
|
||||
}
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
@@ -108,7 +123,7 @@
|
||||
message.destroyAll();
|
||||
if (code == ResultEnum.SUCCESS) {
|
||||
message.success('登录成功,即将进入系统');
|
||||
router.replace(PageEnum.BASE_HOME);
|
||||
router.replace(getRedirectPath());
|
||||
} else {
|
||||
message.info(msg || '登录失败');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user