Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复许可证失效主题切换错误问题 #7075

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

lan-yonghui
Copy link
Member

No description provided.

Copy link

f2c-ci-robot bot commented Nov 15, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

MsgSuccess(i18n.t('commons.msg.operationSuccess'));
loading.value = false;
await search();
return;
}
}
if (key === 'MenuTabs') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码库中的函数是用于设置主题颜色和配置页面标题的。然而在当前版本中(2021年9月),它可能不再符合最新的设计标准或最佳实践。

建议修改此片段以遵循如下原则:

  1. 强调组件之间的功能关系。
  2. 使用更具描述性的变量名,如theme而不是res.data.theme;同样,使用具有更清晰含义的名称来标识属性,并避免不必要的省略号,例如data' 和 themeColor' 而不是仅写为'main_theme_color'.

以下是根据上述指示进行调整后的代码:

let theme;
// 根据需要从不同的来源获取主题信息
function getThemeInfo() {
    // 模拟不同的数据来源并返回一个对象
}
const setThemePreference = (newTheme) => {};

这样可以在不同场景下轻松地改变默认的配色方案和其他外观参数而不影响整个应用的可读性。

@1Panel-bot 1Panel-bot added the dev label Nov 15, 2024
@@ -90,6 +90,7 @@ const submit = async () => {
globalStore.isProductPro = true;
const xpackRes = await getXpackSetting();
if (xpackRes) {
globalStore.themeConfig.theme = xpackRes.data.theme;
globalStore.themeConfig.themeColor = xpackRes.data.themeColor;
}
loading.value = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这个代码中没有发现明显的错误或优化问题。

themeConfig对象应该使用JSON.stringify来避免字符串格式化时丢失信息的问题。这样在异步操作后的数据结构可能会发生变化,如果不进行转换,可能会引发解析错误或者影响其他函数的结果准确性。

所以可以改写为:

const submit = async () => {

   globalStore.isProductPro = true;

   const res = await getXpackSetting();

   if (res && typeof(res.data) === "object") { // 验证返回值是否满足预期类型

      try {
         let themeCfgStr = JSON.stringify(globalStore.themeConfig);
         window.localStorage.setItem("Theme Config", themeCfgStr); // 这样会保证数据是有效的,因为本地存储会自动处理null和undefined等。
         
         return new Promise((resolve, reject) => {

          globalStore.themeConfig.theme = Object.assign({}, ...res.data).theme;
          
          setTimeout(() => resolve({ data: Object.values(res.data)[0], success: true }), 0);

        });
       } catch(e){
        console.log('Error:', e)
        return null;
       }
        
     }

这个版本的逻辑更清晰,并确保了数据的安全性和有效性。

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Nov 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wanghe-fit2cloud

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot merged commit eea4cf6 into dev Nov 15, 2024
6 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev@fix_theme_license branch November 15, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants