-
Notifications
You must be signed in to change notification settings - Fork 21
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
refactor: 重构主题色配置功能 #110
Merged
Merged
refactor: 重构主题色配置功能 #110
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default definePageConfig({ | ||
enablePageMeta: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<template> | ||
<theme-config class="lab-view background"> | ||
<title-bar title="实验室" back-button /> | ||
<title-bar title="主题" back-button /> | ||
<scroll-view :scroll-y="true"> | ||
<view class="flex-column"> | ||
<card class="lab-card"> | ||
|
@@ -12,30 +12,13 @@ | |
</view> | ||
<view class="theme-config"> | ||
<view class="theme-config-title">主题色彩</view> | ||
<view class="tab-bar"> | ||
<view class="tab-bar" > | ||
<text | ||
v-for="item in hadThemeList" | ||
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. 这里有类型错误,hadThemeList 的类型不是 ArrayLike @xixiIBN5100 |
||
class="tab" | ||
:class="currentTab === 'green' ? 'active' : undefined" | ||
@tap="() => handleTabClick('green')" | ||
> 绿 | ||
</text> | ||
<text | ||
class="tab" | ||
:class="currentTab === 'yellow' ? 'active' : undefined" | ||
@tap="() => handleTabClick('yellow')" | ||
> 黄 | ||
</text> | ||
<text | ||
class="tab" | ||
:class="currentTab === 'blue' ? 'active' : undefined" | ||
@tap="() => handleTabClick('blue')" | ||
> 蓝 | ||
</text> | ||
<text | ||
class="tab" | ||
:class="currentTab === 'pink' ? 'active' : undefined" | ||
@tap="() => handleTabClick('pink')" | ||
> 粉 | ||
:class="currentTab === item.name ? 'active' : undefined" | ||
@tap="() => handleTabClick(item.name)" | ||
> {{ nameMap[item.name] }} | ||
</text> | ||
</view> | ||
</view> | ||
|
@@ -61,31 +44,85 @@ import { Card, TitleBar, ThemeConfig } from "@/components"; | |
import DarkModeToggle from "./features/DarkModeToggle.vue"; | ||
import { labText } from "@/constants/copywriting"; | ||
import { getCopyRight } from "@/utils"; | ||
import { ref, computed,watch } from "vue"; | ||
import {ref, computed, watch, onMounted} from "vue"; | ||
import { serviceStore } from "@/store"; | ||
import store from "@/store"; | ||
import "./index.scss"; | ||
import {useRequest} from "@/hooks"; | ||
import {UserService} from "@/services"; | ||
import Taro from "@tarojs/taro"; | ||
|
||
let activeTheme = '' | ||
let idMap = {} | ||
let nameMap = { | ||
green: "绿", | ||
yellow: "黄", | ||
blue: "蓝", | ||
purple: "紫", | ||
pink: "粉" | ||
} | ||
const isEmpty = ref(false); | ||
|
||
const emptyText = computed(() => { | ||
return labText.empty; | ||
}); | ||
|
||
const hadThemeList = computed(() => { | ||
return serviceStore.theme.hadTheme; | ||
}); | ||
const themeMode = ref(serviceStore.theme.themeMode); | ||
const currentTab = ref(themeMode); | ||
|
||
|
||
useRequest(UserService.getUserTheme, { | ||
manual: false, | ||
onSuccess: (res) => { | ||
if(res.data.code === 1 && res.data.msg === "OK") { | ||
store.commit("setHadTheme", res.data.data.theme_list); | ||
res.data.data.theme_list.forEach((item:any) => { | ||
idMap[item.name] = item.id; | ||
}) | ||
} else { | ||
Taro.showToast({ | ||
icon: "none", | ||
title: res.data.msg | ||
}); | ||
} | ||
}, | ||
onError: (e:Error) =>{ | ||
return `失败\r\n${e.message || "网络错误"}`; | ||
} | ||
}) | ||
|
||
const { run } = useRequest(UserService.setTheme, { | ||
manual: true, | ||
onSuccess: (res) => { | ||
if(res.data.code === 1 && res.data.msg === "OK") { | ||
store.commit("setThemeMode", currentTab); | ||
currentTab.value = activeTheme; | ||
Taro.showToast({ title: "设置成功" }); | ||
} else { | ||
Taro.showToast({ | ||
icon: "none", | ||
title: res.data.msg | ||
}); | ||
} | ||
}, | ||
onError: (e:Error) =>{ | ||
return `失败\r\n${e.message || "网络错误"}`; | ||
} | ||
}) | ||
|
||
watch(() => serviceStore.theme.themeMode, (newValue) => { | ||
currentTab.value = newValue; | ||
themeMode.value = newValue; | ||
}); | ||
|
||
const setThemeMode = (currentTab: string) => { | ||
store.commit("setThemeMode", currentTab); | ||
run({ id:idMap[currentTab]} ) | ||
}; | ||
|
||
const handleTabClick = (theme: string) => { | ||
currentTab.value = theme; | ||
setThemeMode(theme); | ||
activeTheme = theme; | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
page.config.js
不是放在 src 目录下的呀。它是放在每个页面的文件夹下,应该是用来替换index.config.ts
的