refactor(sj_1.0.0_beta4): 优化代码

This commit is contained in:
xlsea 2024-06-07 10:20:29 +08:00
parent d64e0073ff
commit 0dbe824829
12 changed files with 21 additions and 107 deletions

View File

@ -4,8 +4,3 @@ VITE_ICONIFY_URL=/snail-job/iconify
# backend service base url, prod environment
VITE_SERVICE_BASE_URL=/snail-job
# other backend service base url, prod environment
VITE_OTHER_SERVICE_BASE_URL= `{
"demo": "http://localhost:9529"
}`

View File

@ -2,8 +2,3 @@ VITE_BASE_URL=/
# backend service base url, test environment
VITE_SERVICE_BASE_URL=http://localhost:8080/snail-job
# other backend service base url, test environment
VITE_OTHER_SERVICE_BASE_URL= `{
"demo": "http://localhost:9528"
}`

View File

@ -8,7 +8,7 @@ export function createServiceConfig(env: Env.ImportMeta) {
let other = {} as Record<Service.OtherBaseURLKey, string>;
try {
other = JSON.parse(VITE_OTHER_SERVICE_BASE_URL);
other = VITE_OTHER_SERVICE_BASE_URL ? JSON.parse(VITE_OTHER_SERVICE_BASE_URL) : {};
} catch (error) {
// eslint-disable-next-line no-console
console.error('VITE_OTHER_SERVICE_BASE_URL is not a valid JSON string');

View File

@ -7,6 +7,9 @@
"icons": {
"menu-fold-left": {
"body": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"2\"><path stroke-dasharray=\"10\" stroke-dashoffset=\"10\" d=\"M7 9L4 12L7 15\"><animate fill=\"freeze\" attributeName=\"stroke-dashoffset\" begin=\"0.6s\" dur=\"0.2s\" values=\"10;0\"/></path><path stroke-dasharray=\"16\" stroke-dashoffset=\"16\" d=\"M19 5H5\"><animate fill=\"freeze\" attributeName=\"stroke-dashoffset\" dur=\"0.2s\" values=\"16;0\"/></path><path stroke-dasharray=\"12\" stroke-dashoffset=\"12\" d=\"M19 12H10\"><animate fill=\"freeze\" attributeName=\"stroke-dashoffset\" begin=\"0.2s\" dur=\"0.2s\" values=\"12;0\"/></path><path stroke-dasharray=\"16\" stroke-dashoffset=\"16\" d=\"M19 19H5\"><animate fill=\"freeze\" attributeName=\"stroke-dashoffset\" begin=\"0.4s\" dur=\"0.2s\" values=\"16;0\"/></path></g>"
},
"menu-fold-right": {
"body": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"2\"><path stroke-dasharray=\"10\" stroke-dashoffset=\"10\" d=\"M17 9L20 12L17 15\"><animate fill=\"freeze\" attributeName=\"stroke-dashoffset\" begin=\"0.6s\" dur=\"0.2s\" values=\"10;0\"/></path><path stroke-dasharray=\"16\" stroke-dashoffset=\"16\" d=\"M5 5H19\"><animate fill=\"freeze\" attributeName=\"stroke-dashoffset\" dur=\"0.2s\" values=\"16;0\"/></path><path stroke-dasharray=\"12\" stroke-dashoffset=\"12\" d=\"M5 12H14\"><animate fill=\"freeze\" attributeName=\"stroke-dashoffset\" begin=\"0.2s\" dur=\"0.2s\" values=\"12;0\"/></path><path stroke-dasharray=\"16\" stroke-dashoffset=\"16\" d=\"M5 19H19\"><animate fill=\"freeze\" attributeName=\"stroke-dashoffset\" begin=\"0.4s\" dur=\"0.2s\" values=\"16;0\"/></path></g>"
}
}
}

View File

@ -1,4 +1,4 @@
import { addAPIProvider, disableCache } from '@iconify/vue';
import { addAPIProvider } from '@iconify/vue';
/** Setup the iconify offline */
export function setupIconifyOffline() {
@ -6,7 +6,5 @@ export function setupIconifyOffline() {
if (VITE_ICONIFY_URL) {
addAPIProvider('', { resources: [VITE_ICONIFY_URL] });
disableCache('all');
}
}

View File

@ -1,5 +1,5 @@
import type { AxiosResponse } from 'axios';
import { BACKEND_ERROR_CODE, createFlatRequest, createRequest } from '@sa/axios';
import { BACKEND_ERROR_CODE, createFlatRequest } from '@sa/axios';
import { useAuthStore } from '@/store/modules/auth';
import { $t } from '@/locales';
import { localStg } from '@/utils/storage';
@ -8,7 +8,7 @@ import { handleRefreshToken, showErrorMsg } from './shared';
import type { RequestInstanceState } from './type';
const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y';
const { baseURL, otherBaseURL } = getServiceBaseURL(import.meta.env, isHttpProxy);
const { baseURL } = getServiceBaseURL(import.meta.env, isHttpProxy);
export const request = createFlatRequest<App.Service.Response, RequestInstanceState>(
{
@ -59,10 +59,7 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
// when the backend response code is in `modalLogoutCodes`, it means the user will be logged out by displaying a modal
const modalLogoutCodes = import.meta.env.VITE_SERVICE_MODAL_LOGOUT_CODES?.split(',') || [];
if (
modalLogoutCodes.includes(response.data.status) &&
!request.state.errMsgStack?.includes(response.data.message)
) {
if (modalLogoutCodes.includes(response.data.status.toString())) {
request.state.errMsgStack = [...(request.state.errMsgStack || []), response.data.message];
// prevent the user from refreshing the page
@ -73,7 +70,7 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
request.state.isLogout = true;
window.$dialog?.error({
title: 'Error',
content: response.data.message,
content: $t('request.logoutWithModalMsg'),
positiveText: $t('common.confirm'),
maskClosable: false,
onPositiveClick() {
@ -138,45 +135,3 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
}
}
);
export const demoRequest = createRequest<App.Service.DemoResponse>(
{
baseURL: otherBaseURL.demo
},
{
async onRequest(config) {
const { headers } = config;
// set token
const token = localStg.get('token');
const Authorization = token ? `Bearer ${token}` : null;
Object.assign(headers, { Authorization });
return config;
},
isBackendSuccess(response) {
// when the backend response code is "200", it means the request is success
// you can change this logic by yourself
return response.data.status === '200';
},
async onBackendFail(_response) {
// when the backend response code is not "200", it means the request is fail
// for example: the token is expired, refresh token and retry request
},
transformBackendResponse(response) {
return response.data.result;
},
onError(error) {
// when the request is fail, you can show error message
let message = error.message;
// show backend error message
if (error.code === BACKEND_ERROR_CODE) {
message = error.response?.data?.message || message;
}
window.$message?.error(message);
}
}
);

View File

@ -8,11 +8,11 @@ interface Props {
defineProps<Props>();
onMounted(() => {
console.log('mounted');
// console.log('mounted');
});
onActivated(() => {
console.log('activated');
// console.log('activated');
});
</script>

View File

@ -1,5 +1,4 @@
<script setup lang="ts">
import { watch } from 'vue';
import { groupConfigIdModeRecord, groupConfigStatusRecord, yesOrNoRecord } from '@/constants/business';
import { $t } from '@/locales';
import { tagColor } from '@/utils/common';
@ -13,19 +12,11 @@ interface Props {
rowData?: Api.GroupConfig.GroupConfig | null;
}
const props = defineProps<Props>();
defineProps<Props>();
const visible = defineModel<boolean>('visible', {
default: false
});
watch(
() => props.rowData,
() => {
console.log(props.rowData);
},
{ immediate: true }
);
</script>
<template>

View File

@ -27,6 +27,6 @@ getCardData();
<style scoped>
.home-main {
max-height: calc(100vh - 148px);
max-height: calc(100vh - 155px);
}
</style>

View File

@ -1,5 +1,4 @@
<script setup lang="ts">
import { watch } from 'vue';
import { enableStatusNumberRecord, jobNotifyScene, retryNotifyScene, systemTaskType } from '@/constants/business';
import { $t } from '@/locales';
import { tagColor } from '@/utils/common';
@ -13,19 +12,11 @@ interface Props {
rowData?: Api.NotifyConfig.NotifyConfig | null;
}
const props = defineProps<Props>();
defineProps<Props>();
const visible = defineModel<boolean>('visible', {
default: false
});
watch(
() => props.rowData,
() => {
console.log(props.rowData);
},
{ immediate: true }
);
</script>
<template>

View File

@ -1,5 +1,4 @@
<script setup lang="ts">
import { watch } from 'vue';
import { DelayLevel, backOffRecord, enableStatusNumberRecord, routeKeyRecord } from '@/constants/business';
import { $t } from '@/locales';
import { tagColor } from '@/utils/common';
@ -30,14 +29,6 @@ function maxRetryCountUpdate(maxRetryCount: number) {
}
return desc.substring(1, desc.length);
}
watch(
() => props.rowData,
() => {
console.log(props.rowData);
},
{ immediate: true }
);
</script>
<template>

View File

@ -1,5 +1,4 @@
<script setup lang="ts">
import { watch } from 'vue';
import { NTag } from 'naive-ui';
import { roleRecord } from '@/constants/business';
import { $t } from '@/locales';
@ -14,19 +13,11 @@ interface Props {
rowData?: Api.UserManager.UserManager | null;
}
const props = defineProps<Props>();
defineProps<Props>();
const visible = defineModel<boolean>('visible', {
default: false
});
watch(
() => props.rowData,
() => {
console.log(props.rowData);
},
{ immediate: true }
);
</script>
<template>
@ -44,7 +35,7 @@ watch(
:span="2"
>
<NTag v-for="(item, index) in rowData?.permissions" :key="index" type="info">
<span style="font-weight: bolder">{{ item.groupName }}</span>
<span class="title">{{ item.groupName }}</span>
({{ item.namespaceName }})
</NTag>
</NDescriptionsItem>
@ -58,4 +49,8 @@ watch(
</OperateDrawer>
</template>
<style scoped></style>
<style scoped>
.title {
font-weight: bolder !important;
}
</style>