Skip to content

Commit

Permalink
feat: enhance system settings management with new dependency and cust…
Browse files Browse the repository at this point in the history
…omization tabs

- Introduced new tabs for managing system settings: 'Customize' and 'Dependency'.
- Refactored SystemDetail.vue to utilize the new tab components for better organization.
- Added form validation and file upload handling for custom logos in the Customize tab.
- Implemented state management for dependency settings, including auto-install options.
- Updated internationalization files to include new labels for dependency management.
- Improved the overall user experience by streamlining the settings interface and enhancing functionality.

These changes provide a more structured approach to managing system settings, improving usability and clarity in the user interface.
  • Loading branch information
tikazyq committed Jan 1, 2025
1 parent 0809ff5 commit 656c06a
Show file tree
Hide file tree
Showing 24 changed files with 468 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const getRowHash = (row: DatabaseTableRow) => {
return row.__hash__;
}
if (primaryColumnName.value) {
return getMd5(JSON.stringify(row[primaryColumnName.value]));
return getMd5(row[primaryColumnName.value]);
}
return getMd5(JSON.stringify(row));
return getMd5(row);
};
const getHeaderIcon = (column: DatabaseColumn) => {
Expand Down
12 changes: 10 additions & 2 deletions src/components/core/dependency/DependencySetupDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { computed, ref, watch } from 'vue';
import { useStore } from 'vuex';
import { translate } from '@/utils';
import useRequest from '@/services/request';
import { browser } from 'globals';
import { ClForm } from '@/components';
const t = translate;
Expand All @@ -13,6 +13,8 @@ const ns: ListStoreNamespace = 'dependency';
const store = useStore();
const { dependency: state, node: nodeState } = store.state as RootStoreState;
const formRef = ref<typeof ClForm>();
const config = computed(() => state.config);
const lang = computed(() => state.lang);
Expand Down Expand Up @@ -57,6 +59,9 @@ const onConfirm = async () => {
// Skip if the confirm button is disabled
if (confirmButtonDisabled.value) return;
// Validate form
await formRef.value?.validate();
// Install config setup
await store.dispatch(`${ns}/installConfigSetup`, {
id: activeConfigSetup.value?._id,
Expand Down Expand Up @@ -124,7 +129,7 @@ defineOptions({ name: 'ClDependencySetupDialog' });
@confirm="onConfirm"
@close="onClose"
>
<cl-form>
<cl-form ref="formRef" :model="form">
<cl-form-item :span="4" :label="t('views.env.deps.config.form.name')">
<cl-tag
:key="config?.name"
Expand All @@ -136,11 +141,14 @@ defineOptions({ name: 'ClDependencySetupDialog' });
<cl-form-item
:span="4"
:label="t('views.env.deps.configSetup.form.version')"
required
prop="version"
>
<el-select
v-model="form.version"
:disabled="getVersionsLoading"
:placeholder="t('common.status.loading')"
default-first-option
filterable
>
<el-option
Expand Down
1 change: 0 additions & 1 deletion src/components/ui/file/FileEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const activeFileItem = computed<FileNavItem | undefined>(
const themeColors = ref<monaco.editor.IColors>({});
const styles = computed<FileEditorStyles>(() => {
console.debug(themeColors.value);
return {
default: {
backgroundColor: themeColors.value['editor.background'],
Expand Down
1 change: 0 additions & 1 deletion src/components/ui/resize/ResizeHandle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const initResize = (event: MouseEvent) => {
direction === 'horizontal'
? targetRef?.clientHeight || 0
: targetRef?.clientWidth || 0;
console.debug(initialSize.value);
startX.value = event.clientX;
startY.value = event.clientY;
document.addEventListener('mousemove', resize);
Expand Down
7 changes: 5 additions & 2 deletions src/i18n/lang/en/views/system.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const system: LViewsSystem = {
menuItems: {
customize: 'Customize',
registration: 'User Registration',
customize: 'Customization',
dependency: 'Dependency Management',
},
customize: {
customTitle: 'Custom Site Title',
Expand All @@ -16,6 +16,9 @@ const system: LViewsSystem = {
fileSizeExceeded: 'File size exceeded',
},
},
dependency: {
autoInstall: 'Auto Install',
},
};

export default system;
7 changes: 5 additions & 2 deletions src/i18n/lang/zh/views/system.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const system: LViewsSystem = {
menuItems: {
customize: '自定义',
registration: '用户注册',
customize: '自定义管理',
dependency: '依赖管理',
},
customize: {
customTitle: '自定义网站标题',
Expand All @@ -15,6 +15,9 @@ const system: LViewsSystem = {
fileSizeExceeded: '文件大小超过限制',
},
},
dependency: {
autoInstall: '自动安装',
},
};

export default system;
3 changes: 3 additions & 0 deletions src/interfaces/common/concept.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare global {
type GeneralConcept = 'customize';
}
5 changes: 4 additions & 1 deletion src/interfaces/i18n/views/system.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface LViewsSystem {
menuItems: {
customize: string;
registration: string;
dependency: string;
};
customize: {
customTitle: string;
Expand All @@ -15,4 +15,7 @@ interface LViewsSystem {
fileSizeExceeded: string;
};
};
dependency: {
autoInstall: string;
};
}
16 changes: 14 additions & 2 deletions src/interfaces/models/setting.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
export declare global {
interface Setting extends BaseModel {
interface Setting<T = Record<string, any>> extends BaseModel {
key: string;
value: { [key: string]: any };
value: T;
}

interface SettingCustomize {
custom_title?: string;
show_custom_title?: boolean;
custom_logo?: string;
show_custom_logo?: boolean;
hide_platform_version?: boolean;
}

interface SettingDependency {
auto_install?: boolean;
}
}
17 changes: 13 additions & 4 deletions src/interfaces/store/modules/system.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ declare global {
}

interface SystemStoreState {
customize: Setting;
settings: Record<string, Setting>;
}

interface SystemStoreGetters
extends GetterTree<SystemStoreState, RootStoreState> {}

interface SystemStoreMutations extends MutationTree<SystemStoreState> {
setCustomize: StoreMutation<SystemStoreState, Setting>;
setSetting: StoreMutation<
SystemStoreState,
{ key: string; value: Setting }
>;
resetSetting: StoreMutation<SystemStoreState, { key: string }>;
setSettings: StoreMutation<
SystemStoreState,
{ settings: Record<string, Setting> }
>;
resetSettings: StoreMutation<SystemStoreState>;
}

interface SystemStoreActions extends BaseStoreActions {
getCustomize: StoreAction<SystemStoreState>;
saveCustomize: StoreAction<SystemStoreState>;
getSetting: StoreAction<SystemStoreState, { key: string }>;
saveSetting: StoreAction<SystemStoreState, { key: string; value: Setting }>;
}
}
10 changes: 7 additions & 3 deletions src/layouts/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const toggleSidebar = () => {
const systemInfo = computed<SystemInfo>(() => commonState.systemInfo || {});
const customize = computed<Setting>(() => systemState.customize);
const customize = computed<Setting>(() => systemState.settings.customize);
const showCustomTitle = computed<boolean>(
() => customize.value?.value?.show_custom_title
);
Expand All @@ -87,7 +87,7 @@ const customizedLogo = computed<string>(() => {
onBeforeMount(async () => {
if (isPro()) {
await store.dispatch('system/getCustomize');
await store.dispatch('system/getSetting', { key: 'customize' });
}
});
Expand Down Expand Up @@ -131,7 +131,11 @@ defineOptions({ name: 'ClSidebar' });
</div>
</div>
<div v-else class="logo">
<img class="logo-img" alt="logo-img" :src="logoIcon" />
<img
class="logo-img"
alt="logo-img"
:src="showCustomLogo ? customizedLogo : logoIcon"
/>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/layouts/content/list/ListLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const getNavActionButtonDisabled = (btn: ListActionButton) => {
const tableColumnsHash = computed<string>(() => {
const { tableColumns } = props;
return getMd5(JSON.stringify(tableColumns));
return getMd5(tableColumns);
});
const className = computed(() => {
Expand Down
13 changes: 3 additions & 10 deletions src/store/modules/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ const actions = {
total: res.total,
};
if (
getMd5(JSON.stringify(tableData.data)) !==
getMd5(JSON.stringify(state.installedDependenciesTableData))
getMd5(tableData.data) !== getMd5(state.installedDependenciesTableData)
) {
commit('setInstalledDependenciesTableData', tableData);
}
Expand Down Expand Up @@ -324,10 +323,7 @@ const actions = {
data: res.data || [],
total: res.total,
};
if (
getMd5(JSON.stringify(state.searchRepoTableData)) !==
getMd5(JSON.stringify(tableData.data))
) {
if (getMd5(state.searchRepoTableData) !== getMd5(tableData.data)) {
commit('setSearchRepoTableData', tableData);
}
return res;
Expand Down Expand Up @@ -488,10 +484,7 @@ const actions = {
data: res.data || [],
total: res.total,
};
if (
getMd5(JSON.stringify(state.configSetupTableData)) !==
getMd5(JSON.stringify(tableData.data))
) {
if (getMd5(state.configSetupTableData) !== getMd5(tableData.data)) {
commit('setConfigSetupTableData', tableData);
}
return res;
Expand Down
77 changes: 56 additions & 21 deletions src/store/modules/system.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
import useRequest from '@/services/request';
import { getMd5 } from '@/utils';

const { get, post, put } = useRequest();

export default {
namespaced: true,
state: {
customize: { key: 'customize', value: {} },
const getDefaultSetting = (key: string): Setting => {
return { key, value: {} };
};

const state = {
settings: {},
} as SystemStoreState;

const getters = {} as SystemStoreGetters;

const mutations = {
setSetting: (state: SystemStoreState, { key, value }) => {
state.settings[key] = value || getDefaultSetting(key);
},
resetSetting: (state: SystemStoreState, { key }) => {
state.settings[key] = getDefaultSetting(key);
},
getters: {},
mutations: {
setCustomize(state, siteTitle) {
state.customize = { ...siteTitle };
},
setSettings: (state: SystemStoreState, { settings }) => {
state.settings = settings;
},
actions: {
getCustomize: async ({ state }: StoreActionContext<SystemStoreState>) => {
const res = await get('/settings/customize');
state.customize = res.data || { key: 'customize', value: {} };
},
saveCustomize: async ({ state }: StoreActionContext<SystemStoreState>) => {
if (!state.customize._id) {
await post('/settings/customize', state.customize);
} else {
await put('/settings/customize', state.customize);
}
},
resetSettings: (state: SystemStoreState) => {
state.settings = {};
},
} as SystemStoreMutations;

const actions = {
getSetting: async (
{ commit }: StoreActionContext<SystemStoreState>,
{ key }: { key: string }
) => {
const res = await get(`/settings/${key}`);
const resData = res.data || getDefaultSetting(key);
commit('setSetting', { key, value: resData });
},
saveSetting: async (
_: StoreActionContext<SystemStoreState>,
{
key,
value,
}: {
key: string;
value: Setting;
}
) => {
if (!value._id) {
await post(`/settings/${key}`, value);
} else {
await put(`/settings/${key}`, value);
}
},
} as SystemStoreActions;

export default {
namespaced: true,
state,
getters,
mutations,
actions,
} as SystemStoreModule;
7 changes: 5 additions & 2 deletions src/utils/hash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import md5 from 'md5';

export const getMd5 = (text: string): string => {
return md5(text).toString();
export const getMd5 = (value: any): string => {
if (typeof value !== 'string') {
value = JSON.stringify(value);
}
return md5(value).toString();
};
11 changes: 11 additions & 0 deletions src/utils/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ export const getIconByTabName = (tabName: string): Icon => {
return ['fa', 'circle'];
}
};

export const getIconByNavItem = (item: NavItem): Icon => {
return getIconByTabName(item.id);
};

export const getIconByAction = (action: string): Icon | undefined => {
switch (action) {
// Basic Actions
Expand Down Expand Up @@ -294,3 +296,12 @@ export const getIconByRouteConcept = (concept: RouteConcept): Icon => {
return ['fa', 'circle'];
}
};

export const getIconByGeneralConcept = (concept: GeneralConcept): Icon => {
switch (concept) {
case 'customize':
return ['fa', 'palette'];
default:
return ['fa', 'circle'];
}
};
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export * from './notification';
export * from './time';
export * from './icon';
export * from './dependency';
export * from './base64';
Loading

0 comments on commit 656c06a

Please sign in to comment.