-
Notifications
You must be signed in to change notification settings - Fork 283
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(site): refactor the implementation mode of switch dark theme #2995
Changes from all commits
0fe2122
bf6472a
1799218
3677496
af9383c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,6 +27,7 @@ const headerHtml = ` | |||||||||||||||||||||||||||||||||||||||||
<span class="header-detail-name">TinyVue</span> | ||||||||||||||||||||||||||||||||||||||||||
<div class="nav-menus nav-menus-left"></div> | ||||||||||||||||||||||||||||||||||||||||||
<button id="switchTheme" style="margin-left:150px">切换主题</button> | ||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||
</div>` | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -147,6 +148,10 @@ class DesignCommon { | |||||||||||||||||||||||||||||||||||||||||
link.href = '/static/css/design-common.css' | ||||||||||||||||||||||||||||||||||||||||||
link.rel = 'stylesheet' | ||||||||||||||||||||||||||||||||||||||||||
document.head.append(link) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
document.getElementById('switchTheme').addEventListener('click', () => { | ||||||||||||||||||||||||||||||||||||||||||
document.querySelector('html').classList.toggle('dark') | ||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+151
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Theme toggle logic contradicts PR objective and lacks persistence. The PR objective states that the theme switch functionality should be removed, requiring developers to "manually add class='dark' to HTML tags during development." However, this event listener is adding automated theme toggling that affects all users. Additionally, this implementation doesn't persist the user's theme preference across page reloads, which leads to a poor user experience if this is intended as a user-facing feature. If the intent is to remove theme switching as stated in the PR objectives, this event listener should be removed: - document.getElementById('switchTheme').addEventListener('click', () => {
- document.querySelector('html').classList.toggle('dark')
- }) If theme switching should be kept, consider adding persistence: document.getElementById('switchTheme').addEventListener('click', () => {
- document.querySelector('html').classList.toggle('dark')
+ const html = document.querySelector('html');
+ const isDark = html.classList.toggle('dark');
+ localStorage.setItem('theme-preference', isDark ? 'dark' : 'light');
})
+
+ // Apply saved theme preference on load
+ const savedTheme = localStorage.getItem('theme-preference');
+ if (savedTheme === 'dark') {
+ document.querySelector('html').classList.add('dark');
+ } 📝 Committable suggestion
Suggested change
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
renderFooter() { | ||||||||||||||||||||||||||||||||||||||||||
document.getElementById('footer').innerHTML = footerHtml | ||||||||||||||||||||||||||||||||||||||||||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,6 @@ | |
<div class="main-layout ti-hp100 ti-f-c ti-f-box-stretch"> | ||
<div class="content-layout ti-fi-1" :has-sider="!isFrame"> | ||
<div id="layoutSider" class="layout-sider" :class="{ 'saas-border': templateModeState.isSaas }" v-if="!isFrame"> | ||
<div style="padding: 10px 0; text-align: center"> | ||
<tiny-button :reset-time="0" type="info" @click="toggleDark()">{{ isDark ? 'dark' : 'light' }}</tiny-button> | ||
</div> | ||
<tiny-tree-menu | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 移除了切换主题按钮的代码,这意味着用户将无法通过UI切换主题。确保这是预期的行为,并且在文档中有说明如何手动切换主题。 |
||
ref="treeMenuRef" | ||
class="main-menu" | ||
|
@@ -68,7 +65,6 @@ import { getWord, i18nByKey, appData, appFn, useApiMode, useTemplateMode } from | |
import useTheme from '@/tools/useTheme' | ||
import FloatSettings from '@/views/components-doc/components/float-settings.vue' | ||
import VersionTip from '@/views/components-doc/components/version-tip.vue' | ||
import { useDark, useToggle } from '@vueuse/core' | ||
export default defineComponent({ | ||
name: 'LayoutVue', | ||
|
@@ -107,8 +103,6 @@ export default defineComponent({ | |
const getTo = (route, key) => `${import.meta.env.VITE_CONTEXT}${allPath}${lang}/${theme}/${route}${key}` | ||
const isThemeSaas = import.meta.env.VITE_TINY_THEME === 'saas' | ||
const isDark = useDark() | ||
const toggleDark = useToggle(isDark) | ||
const changeLanguage = () => { | ||
appFn.toggleLang() | ||
|
@@ -197,8 +191,6 @@ export default defineComponent({ | |
getWord, | ||
i18nByKey, | ||
isThemeSaas, | ||
isDark, | ||
toggleDark, | ||
isShowFilter | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This button addition contradicts the PR objective to remove the theme switch.
According to the PR objective, the goal is to remove the theme switch button from the official website, but this code is adding a new one instead. Additionally, I see the following issues with this button:
margin-left:150px
) which is generally not recommended for maintainabilityIf the intent is to remove theme switching as stated in the PR objectives, consider removing this button:
- <button id="switchTheme" style="margin-left:150px">切换主题</button>
If theme switching should be kept but implemented differently, consider proper styling and accessibility:
📝 Committable suggestion