Skip to content

Commit

Permalink
sync feature updates since 7.30 (#37)
Browse files Browse the repository at this point in the history
* feat(projects): does the configuration support automatic updates

* chore(projects): use json5 resolve env VITE_OTHER_SERVICE_BASE_URL & fix proxy enable

* chore(projects): fix the type of TableApiFn

* optimize(projects): optimize response code comparison
  • Loading branch information
Ohh-889 authored Sep 5, 2024
1 parent b152c19 commit 647f014
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ VITE_STATIC_SUPER_ROLE=R_SUPER

# Used to differentiate storage across different domains
VITE_STORAGE_PREFIX=SOY_

# used to control whether the program automatically detects updates
VITE_AUTOMATICALLY_DETECT_UPDATE=Y
6 changes: 3 additions & 3 deletions build/config/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { createServiceConfig } from '../../src/utils/service';
* Set http proxy
*
* @param env - The current env
* @param isDev - Is development environment
* @param enable - If enable http proxy
*/
export function createViteProxy(env: Env.ImportMeta, isDev: boolean) {
const isEnableHttpProxy = isDev && env.VITE_HTTP_PROXY === 'Y';
export function createViteProxy(env: Env.ImportMeta, enable: boolean) {
const isEnableHttpProxy = enable && env.VITE_HTTP_PROXY === 'Y';

if (!isEnableHttpProxy) return undefined;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"clipboard": "2.0.11",
"dayjs": "1.11.11",
"echarts": "5.5.1",
"json5": "2.2.3",
"lodash-es": "4.17.21",
"nprogress": "0.2.0",
"pinia": "2.1.7",
Expand Down
2 changes: 0 additions & 2 deletions packages/scripts/src/commands/git-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ interface PromptObject {
* @param lang
*/
export async function gitCommit(lang: Lang = 'en-us') {
console.log(lang);

const { gitCommitMessages, gitCommitTypes, gitCommitScopes } = locales[lang];

const typesChoices = gitCommitTypes.map(([value, msg]) => {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { Button } from 'ant-design-vue';
import { $t } from '../locales';

export function setupAppVersionNotification() {
const canAutoUpdateApp = import.meta.env.VITE_AUTOMATICALLY_DETECT_UPDATE === 'Y';

if (!canAutoUpdateApp) return;

let isShow = false;

document.addEventListener('visibilitychange', async () => {
Expand Down
10 changes: 6 additions & 4 deletions src/service/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
async onBackendFail(response, instance) {
const authStore = useAuthStore();

const responseCode = String(response.data.code);

function handleLogout() {
authStore.resetStore();
}
Expand All @@ -49,14 +51,14 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt

// when the backend response code is in `logoutCodes`, it means the user will be logged out and redirected to login page
const logoutCodes = import.meta.env.VITE_SERVICE_LOGOUT_CODES?.split(',') || [];
if (logoutCodes.includes(response.data.code)) {
if (logoutCodes.includes(responseCode)) {
handleLogout();
return null;
}

// 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.code) && !request.state.errMsgStack?.includes(response.data.msg)) {
if (modalLogoutCodes.includes(responseCode) && !request.state.errMsgStack?.includes(response.data.msg)) {
request.state.errMsgStack = [...(request.state.errMsgStack || []), response.data.msg];

// prevent the user from refreshing the page
Expand All @@ -81,7 +83,7 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
// when the backend response code is in `expiredTokenCodes`, it means the token is expired, and refresh token
// the api `refreshToken` can not return error code in `expiredTokenCodes`, otherwise it will be a dead loop, should return `logoutCodes` or `modalLogoutCodes`
const expiredTokenCodes = import.meta.env.VITE_SERVICE_EXPIRED_TOKEN_CODES?.split(',') || [];
if (expiredTokenCodes.includes(response.data.code) && !request.state.isRefreshingToken) {
if (expiredTokenCodes.includes(responseCode) && !request.state.isRefreshingToken) {
request.state.isRefreshingToken = true;

const refreshConfig = await handleRefreshToken(response.config);
Expand All @@ -107,7 +109,7 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
// get backend error message and code
if (error.code === BACKEND_ERROR_CODE) {
message = error.response?.data?.msg || message;
backendErrorCode = error.response?.data?.code || '';
backendErrorCode = String(error.response?.data?.code || '');
}

// the error message is displayed in the modal
Expand Down
2 changes: 1 addition & 1 deletion src/typings/antd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare namespace AntDesign {

type TableColumn<T> = SetTableColumnKey<TableColumnType<T>, T> | SetTableColumnKey<TableColumnGroupType<T>, T>;

type TableApiFn<T = any, R = Api.SystemManage.CommonSearchParams> = (
type TableApiFn<T = any, R = Api.Common.CommonSearchParams> = (
params: R
) => Promise<FlatResponseData<Api.Common.PaginatingQueryRecord<T>>>;

Expand Down
3 changes: 3 additions & 0 deletions src/typings/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ declare namespace Api {
records: T[];
}

/** common search params of table */
type CommonSearchParams = Pick<Common.PaginatingCommonParams, 'current' | 'size'>;

/**
* enable status
*
Expand Down
2 changes: 2 additions & 0 deletions src/typings/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ declare namespace Env {
readonly VITE_ICONIFY_URL?: string;
/** Used to differentiate storage across different domains */
readonly VITE_STORAGE_PREFIX?: string;
/** Whether to automatically detect updates after configuring application packaging */
readonly VITE_AUTOMATICALLY_DETECT_UPDATE?: CommonType.YesOrNo;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/utils/service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json5 from 'json5';

/**
* Create service config by current env
*
Expand All @@ -8,10 +10,10 @@ export function createServiceConfig(env: Env.ImportMeta) {

let other = {} as Record<App.Service.OtherBaseURLKey, string>;
try {
other = JSON.parse(VITE_OTHER_SERVICE_BASE_URL);
other = json5.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');
console.error('VITE_OTHER_SERVICE_BASE_URL is not a valid json5 string');
}

const httpConfig: App.Service.SimpleServiceConfig = {
Expand Down
4 changes: 3 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default defineConfig(configEnv => {

const buildTime = getBuildTime();

const enableProxy = configEnv.command === 'serve' && !configEnv.isPreview;

return {
base: viteEnv.VITE_BASE_URL,
resolve: {
Expand All @@ -32,7 +34,7 @@ export default defineConfig(configEnv => {
host: '0.0.0.0',
port: 9527,
open: true,
proxy: createViteProxy(viteEnv, configEnv.command === 'serve'),
proxy: createViteProxy(viteEnv, enableProxy),
fs: {
cachedChecks: false
}
Expand Down

0 comments on commit 647f014

Please sign in to comment.