Skip to content

Commit 624a047

Browse files
author
Andreas H. Kelch
committed
feat: added vi settings usage
1 parent c9cc121 commit 624a047

File tree

4 files changed

+148
-4
lines changed

4 files changed

+148
-4
lines changed

sources/app/src/App.vue

+45
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,60 @@
66
import { onBeforeMount } from 'vue'
77
import { RouterLink, RouterView } from 'vue-router'
88
import { useAppStore } from './stores/app'
9+
import { useColorStore } from './stores/color'
910
1011
const appStore = useAppStore()
12+
const colorStore = useColorStore()
1113
1214
onBeforeMount(() => {
1315
appStore.init()
1416
})
17+
18+
function getPrimaryColor(lightness) {
19+
return colorStore.getPrimaryColor(lightness)
20+
}
21+
22+
function getSecondaryColor(lightness) {
23+
return colorStore.getSecondaryColor(lightness)
24+
}
25+
26+
function getPrimaryAlphaColor(lightness,alpha) {
27+
return colorStore.getAlphaColor("primaryColor", lightness, alpha)
28+
}
29+
30+
1531
</script>
1632

1733
<style scoped></style>
1834
<style lang="postcss">
1935
@import 'style/style.css';
36+
* {
37+
--sl-color-primary-50: v-bind(getPrimaryColor(83));
38+
--sl-color-primary-100: v-bind(getPrimaryColor(78));
39+
--sl-color-primary-200: v-bind(getPrimaryColor(68));
40+
--sl-color-primary-300: v-bind(getPrimaryColor(58));
41+
--sl-color-primary-400: v-bind(getPrimaryColor(48));
42+
--sl-color-primary-500: v-bind(getPrimaryColor(43));
43+
--sl-color-primary-600: v-bind(getPrimaryColor(38));
44+
--sl-color-primary-700: v-bind(getPrimaryColor(28));
45+
--sl-color-primary-800: v-bind(getPrimaryColor(18));
46+
--sl-color-primary-900: v-bind(getPrimaryColor(8));
47+
--sl-color-primary-950: v-bind(getPrimaryColor(3));
48+
49+
--sl-color-secondary-50: v-bind(getSecondaryColor(60));
50+
--sl-color-secondary-100: v-bind(getSecondaryColor(55));
51+
--sl-color-secondary-200: v-bind(getSecondaryColor(45));
52+
--sl-color-secondary-300: v-bind(getSecondaryColor(35));
53+
--sl-color-secondary-400: v-bind(getSecondaryColor(25));
54+
--sl-color-secondary-500: v-bind(getSecondaryColor(20));
55+
--sl-color-secondary-600: v-bind(getSecondaryColor(15));
56+
--sl-color-secondary-700: v-bind(getSecondaryColor(5));
57+
--sl-color-secondary-800: v-bind(getSecondaryColor(0));
58+
--sl-color-secondary-900: v-bind(getSecondaryColor(0));
59+
--sl-color-secondary-950: v-bind(getSecondaryColor(0));
60+
61+
--sl-input-border-color-focus: var(--sl-color-primary-500);
62+
--sl-input-focus-ring-color: v-bind(getPrimaryAlphaColor(43, 40));
63+
}
2064
</style>
65+

sources/app/src/stores/app.js

+41-2
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,47 @@ import { useRouter } from 'vue-router'
33
import { defineStore } from 'pinia'
44
import { Request } from '@viur/vue-utils'
55
import { useUserStore } from '@viur/vue-utils/login/stores/user'
6+
import { useColorStore } from '@/stores/color.js'
7+
8+
69

710
export const useAppStore = defineStore('app', () => {
811
const userStore = useUserStore()
12+
const colorStore = useColorStore()
913
const router = useRouter()
1014

1115
const state = reactive({
1216
init: false,
13-
name: 'TODO'
17+
"admin.login.background": publicAsset("login-background.jpg"),
18+
"admin.login.logo": publicAsset("logo.svg"),
19+
"admin.color.primary": "",
20+
"admin.color.secondary": ""
1421
})
1522

1623
async function init() {
1724
Request.get('/vi/settings')
1825
.then(async (resp) => {
1926
let data = await resp.json()
2027

28+
for (const key in data) {
29+
if (data[key] !== undefined || data[key] !== null) {
30+
if (data[key].length > 0) {
31+
if ((key.endsWith(".logo") || key.endsWith(".background")) && !key.startsWith("/")) {
32+
state[key] = publicAsset(data[key])
33+
continue
34+
}
35+
state[key] = data[key]
36+
}
37+
if (key === "admin.color.primary") {
38+
colorStore.state.primaryColor = state[key]
39+
}
40+
if (key === "admin.color.secondary") {
41+
colorStore.state.secondaryColor = state[key]
42+
}
43+
}
44+
}
45+
46+
2147
if (data['admin.user.google.clientID']) {
2248
userStore.googleInit(data['admin.user.google.clientID']).catch(() => {
2349
throw new Error('clientId is required since the plugin is not initialized with a Client Id')
@@ -44,8 +70,21 @@ export const useAppStore = defineStore('app', () => {
4470
}
4571
)
4672

73+
function publicAsset(path, prefix = "app") {
74+
if (import.meta.env.DEV) {
75+
if(path.startsWith("/")){
76+
return `${import.meta.env.VITE_API_URL}${path}`
77+
}else{
78+
return `${prefix}/${path}`
79+
}
80+
81+
}
82+
return path
83+
}
84+
4785
return {
4886
state,
49-
init
87+
init,
88+
publicAsset
5089
}
5190
})

sources/app/src/stores/color.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// @ts-nocheck
2+
import { reactive } from "vue"
3+
import { defineStore } from "pinia"
4+
5+
export const useColorStore = defineStore("colorStore", () => {
6+
const state = reactive({
7+
primaryColor: "#d00f1c",
8+
secondaryColor: "#333333"
9+
})
10+
11+
function getPrimaryColor(lightness = 0) {
12+
const [h,s,l] = colorConvert(state.primaryColor, lightness)
13+
return "hsl(" + h + "," + s + "%," + l + "%)"
14+
}
15+
function getSecondaryColor(lightness = 0) {
16+
const [h,s,l] = colorConvert(state.secondaryColor, lightness)
17+
return "hsl(" + h + "," + s + "%," + l + "%)"
18+
}
19+
function colorConvert(hexColor, lightness) {
20+
const r = parseInt("0x" + hexColor[1] + hexColor[2]) / 255
21+
const g = parseInt("0x" + hexColor[3] + hexColor[4]) / 255
22+
const b = parseInt("0x" + hexColor[5] + hexColor[6]) / 255
23+
24+
const cmin = Math.min(r, g, b)
25+
const cmax = Math.max(r, g, b)
26+
const delta = cmax - cmin
27+
let h
28+
let s
29+
let l
30+
31+
if (delta == 0) h = 0
32+
else if (cmax == r) h = ((g - b) / delta) % 6
33+
else if (cmax == g) h = (b - r) / delta + 2
34+
else h = (r - g) / delta + 4
35+
36+
h = Math.round(h * 60)
37+
38+
if (h < 0) h += 360
39+
40+
l = (cmax + cmin) / 2
41+
s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1))
42+
s = +(s * 100).toFixed(1)
43+
l = +(l * 100).toFixed(1)
44+
if (lightness) {
45+
l = lightness
46+
}
47+
return [h,s,l]
48+
49+
}
50+
51+
function getAlphaColor(color, lightness, alpha){
52+
const [h,s,l] = colorConvert(state[color], lightness)
53+
return "hsla(" + h + "," + s + "%," + l + "% , "+ alpha +"%)"
54+
}
55+
56+
return { state, getPrimaryColor, getSecondaryColor, getAlphaColor }
57+
})

sources/app/src/views/LoginView.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<template>
22
<the-login-screen
3-
logo="/app/logo.svg"
4-
backgroundImage="/app/login-background.jpg"
3+
:background-image="appStore.state['admin.login.background']"
4+
:logo="appStore.state['admin.login.logo']"
55
></the-login-screen>
66
</template>
77

88
<script setup>
99
import TheLoginScreen from '@viur/vue-utils/login/TheLoginScreen.vue'
10+
import {useAppStore} from "@/stores/app.js"
11+
const appStore = useAppStore()
12+
1013
</script>

0 commit comments

Comments
 (0)