From 3449c02d0c57caae72db00ede278adc2304b124f Mon Sep 17 00:00:00 2001 From: qier222 <68148142+qier222@users.noreply.github.com> Date: Sun, 25 Oct 2020 14:09:13 +0800 Subject: [PATCH 1/6] feat: automatically get daily signin points --- src/utils/common.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/common.js b/src/utils/common.js index cf693f0..4f76fd8 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -1,5 +1,6 @@ import { isAccountLoggedIn } from "./auth"; import { refreshCookie } from "@/api/auth"; +import { dailySignin } from "@/api/user"; import dayjs from "dayjs"; import store from "@/store"; @@ -79,9 +80,10 @@ export function updateHttps(url) { } export function dailyTask() { + let lastDate = store.state.settings.lastRefreshCookieDate; if ( - store.state.settings.lastRefreshCookieDate === undefined || - store.state.settings.lastRefreshCookieDate !== dayjs().date() + isAccountLoggedIn() && + (lastDate === undefined || lastDate !== dayjs().date()) ) { console.log("execute dailyTask"); store.commit("updateSettings", { @@ -89,5 +91,7 @@ export function dailyTask() { value: dayjs().date(), }); refreshCookie(); + dailySignin(0); + dailySignin(1); } } From e9b6a81befa95984a74b4409e17afa2859b65000 Mon Sep 17 00:00:00 2001 From: qier222 <68148142+qier222@users.noreply.github.com> Date: Sun, 25 Oct 2020 14:12:31 +0800 Subject: [PATCH 2/6] fix: some bugs --- src/api/user.js | 25 +++++++++++-------------- src/components/Cover.vue | 1 + src/components/Navbar.vue | 2 +- src/main.js | 1 - 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/api/user.js b/src/api/user.js index edabc43..45156e0 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -1,19 +1,5 @@ import request from "@/utils/request"; -export function login(params) { - // 必选参数 : - // phone: 手机号码 - // password: 密码 - // 可选参数 : - // countrycode: 国家码,用于国外手机号登陆,例如美国传入:1 - // md5_password: md5加密后的密码,传入后 password 将失效 - return request({ - url: "/login/cellphone", - method: "get", - params, - }); -} - export function userDetail(uid) { return request({ url: "/user/detail", @@ -44,3 +30,14 @@ export function userLikedSongsIDs(uid) { }, }); } + +export function dailySignin(type = 0) { + //可选参数 : type: 签到类型 , 默认 0, 其中 0 为安卓端签到 ,1 为 web/PC 签到 + return request({ + url: "/daily_signin", + method: "post", + params: { + type, + }, + }); +} diff --git a/src/components/Cover.vue b/src/components/Cover.vue index c074211..f821543 100644 --- a/src/components/Cover.vue +++ b/src/components/Cover.vue @@ -163,6 +163,7 @@ export default { filter: blur(16px) opacity(0.6); z-index: -1; height: 208px; + transform: scale(0.98); } .play-button { opacity: 0; diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index 8f06dfc..fbdfeab 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -27,7 +27,7 @@ @@ -36,6 +37,22 @@ +
+
+
{{ $t("settings.appearance.text") }}
+
+
+ +
+
{{ $t("settings.musicQuality.text") }}
@@ -109,8 +126,31 @@ export default { this.$store.commit("changeLang", lang); }, }, + appearance: { + get() { + if (this.settings.appearance === undefined) return "auto"; + return this.settings.appearance; + }, + set(value) { + this.$store.commit("updateSettings", { + key: "appearance", + value, + }); + if (value === "auto") { + document.body.setAttribute( + "data-theme", + window.matchMedia("(prefers-color-scheme: dark)").matches + ? "dark" + : "light" + ); + } else { + document.body.setAttribute("data-theme", value); + } + }, + }, musicQuality: { get() { + if (this.settings.appearance === undefined) return 320000; return this.settings.musicQuality; }, set(value) { @@ -163,13 +203,15 @@ export default { h2 { margin-top: 48px; font-size: 36px; + color: var(--color-text); } .user { display: flex; align-items: center; justify-content: space-between; - background: #f5f5f7; + background: var(--color-secondary-bg); + color: var(--color-text); padding: 16px 20px; border-radius: 16px; img.avatar { @@ -190,12 +232,13 @@ h2 { .nickname { font-size: 20px; font-weight: 600; - color: rgba(0, 0, 0, 0.88); margin-bottom: 2px; } .extra-info { font-size: 13px; - color: rgba(0, 0, 0, 0.68); + .text { + opacity: 0.68; + } .vip { display: flex; align-items: center; @@ -216,17 +259,20 @@ h2 { text-decoration: none; border-radius: 10px; padding: 8px 12px; - color: rgba(0, 0, 0, 0.68); + opacity: 0.68; + color: var(--color-text); transition: 0.2s; margin: { right: 12px; left: 12px; } &:hover { + opacity: 1; background: #eaeffd; color: #335eea; } &:active { + opacity: 1; transform: scale(0.92); transition: 0.2s; } @@ -239,11 +285,12 @@ h2 { display: flex; align-items: center; justify-content: space-between; + color: var(--color-text); .title { font-size: 18px; font-weight: 600; - color: rgba(0, 0, 0, 0.88); + opacity: 0.88; } select { @@ -252,13 +299,13 @@ h2 { border: none; padding: 8px 12px 8px 12px; border-radius: 8px; - color: rgba(0, 0, 0, 0.88); - background: #f5f5f7; + color: var(--color-text); + background: var(--color-secondary-bg); appearance: none; &:focus { outline: none; - color: #335eea; - background: #eaeffd; + color: var(--color-primary); + background: var(--color-primary-bg); } } } @@ -275,7 +322,6 @@ h2 { } .toggle { margin: auto; - background: white; } .toggle input { opacity: 0; @@ -292,7 +338,7 @@ h2 { transition: 0.4s ease; height: 32px; width: 68px; - background: #f5f5f7; + background: var(--color-secondary-bg); border-radius: 8px; } .toggle input + label:before { @@ -323,7 +369,7 @@ h2 { border-radius: 6px; } .toggle input:checked + label:before { - background: #335eea; + background: var(--color-primary); -webkit-transition: width 0.2s cubic-bezier(0, 0, 0, 0.1); transition: width 0.2s cubic-bezier(0, 0, 0, 0.1); } From c448230c141609bd290859e43678502751f58172 Mon Sep 17 00:00:00 2001 From: qier222 <68148142+qier222@users.noreply.github.com> Date: Sun, 25 Oct 2020 21:55:20 +0800 Subject: [PATCH 5/6] feat: dynamic PWA theme color --- src/store/index.js | 18 ++++-------------- src/utils/common.js | 12 ++++++++++++ src/views/settings.vue | 13 +++---------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 6b29733..5b10180 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,6 +5,7 @@ import mutations from "./mutations"; import actions from "./actions"; import initState from "./initState"; import { Howl, Howler } from "howler"; +import { changeAppearance } from "@/utils/common"; if (localStorage.getItem("appVersion") === null) { localStorage.setItem("player", JSON.stringify(initState.player)); @@ -45,23 +46,12 @@ if ([undefined, null].includes(store.state.settings.lang)) { localStorage.setItem("settings", JSON.stringify(store.state.settings)); } -if ( - store.state.settings.appearance !== "auto" && - store.state.settings.appearance !== undefined -) { - document.body.setAttribute("data-theme", store.state.settings.appearance); -} else { - document.body.setAttribute( - "data-theme", - window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" - ); -} +changeAppearance(store.state.settings.appearance); window .matchMedia("(prefers-color-scheme: dark)") - .addEventListener("change", (e) => { + .addEventListener("change", () => { if (store.state.settings.appearance === "auto") { - store.commit("updateTmpAppearance", e.matches ? "dark" : "light"); - document.body.setAttribute("data-theme", e.matches ? "dark" : "light"); + changeAppearance(store.state.settings.appearance); } }); diff --git a/src/utils/common.js b/src/utils/common.js index 6e75f54..3663147 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -95,3 +95,15 @@ export function dailyTask() { dailySignin(1); } } + +export function changeAppearance(appearance) { + if (appearance === "auto" || appearance === undefined) { + appearance = window.matchMedia("(prefers-color-scheme: dark)").matches + ? "dark" + : "light"; + } + document.body.setAttribute("data-theme", appearance); + document + .querySelector('meta[name="theme-color"]') + .setAttribute("content", appearance === "dark" ? "#222" : "#fff"); +} diff --git a/src/views/settings.vue b/src/views/settings.vue index 60df284..54517e8 100644 --- a/src/views/settings.vue +++ b/src/views/settings.vue @@ -113,6 +113,8 @@