File tree Expand file tree Collapse file tree 7 files changed +190
-5
lines changed Expand file tree Collapse file tree 7 files changed +190
-5
lines changed Original file line number Diff line number Diff line change 1
1
import ApiService from '@/services/api.service' ;
2
2
import TokenService from '@/services/token.service' ;
3
+ import ThemeService from '@/services/theme.service' ;
3
4
import LanguageService from '@/services/language.service' ;
4
5
5
6
import AuthenticateUser from '@/services/middleware/AuthenticateUser' ;
@@ -14,6 +15,8 @@ if (TokenService.isExist()) {
14
15
ApiService . setHeader ( HttpHeader . AUTHORIZATION , `Bearer ${ TokenService . get ( ) } ` ) ;
15
16
}
16
17
18
+ ThemeService . updateDOM ( ) ;
19
+
17
20
if ( LanguageService . isRtl ( ) ) {
18
21
import ( '@/assets/scss/app-rtl.scss' ) ;
19
22
} else {
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <button
3
+ type =" button"
4
+ class =" btn btn-sm text-white"
5
+ @click =" offcanvasShow = true"
6
+ >
7
+ <i class =" bi-gear h4" ></i >
8
+ </button >
9
+
10
+ <VOffcanvas v-model =" offcanvasShow" >
11
+ <template #title >{{ $t('Settings') }}</template >
12
+
13
+ <VForm id =" settings-form" class =" row" >
14
+ <div class =" col-6" >
15
+ <VSelect
16
+ v-model =" language"
17
+ :items =" languageItems"
18
+ item-text =" text"
19
+ item-key =" key"
20
+ >
21
+ <template #label >{{ $t('Language') }}</template >
22
+ </VSelect >
23
+ </div >
24
+
25
+ <div class =" col-6" >
26
+ <VSelect
27
+ v-model =" theme"
28
+ :items =" themeItems"
29
+ item-text =" text"
30
+ item-key =" key"
31
+ >
32
+ <template #label >{{ $t('Theme') }}</template >
33
+ </VSelect >
34
+ </div >
35
+ </VForm >
36
+ </VOffcanvas >
37
+ </template >
38
+
39
+ <script >
40
+ import { ref , watch } from ' vue' ;
41
+
42
+ // Components
43
+ import VOffcanvas from ' @/components/VOffcanvas.vue' ;
44
+ import VForm from ' @/components/form/VForm.vue' ;
45
+ import VSelect from ' @/components/form/VSelect.vue' ;
46
+
47
+ // Services
48
+ import LanguageService , { t } from ' @/services/language.service' ;
49
+ import ThemeService from ' @/services/theme.service' ;
50
+
51
+ export default {
52
+ name: ' AppSettings' ,
53
+
54
+ components: {
55
+ VOffcanvas,
56
+ VForm,
57
+ VSelect
58
+ },
59
+
60
+ setup () {
61
+ const offcanvasShow = ref (false );
62
+
63
+ const language = ref (LanguageService .get ());
64
+ const languageItems = [
65
+ {
66
+ key: ' en' ,
67
+ text: ' English'
68
+ },
69
+ {
70
+ key: ' fa' ,
71
+ text: ' فارسی'
72
+ }
73
+ ];
74
+
75
+ watch (language, (value ) => LanguageService .set (value));
76
+
77
+ const theme = ref (ThemeService .get ());
78
+ const themeItems = [
79
+ {
80
+ key: ' light' ,
81
+ text: t (' Light' )
82
+ },
83
+ {
84
+ key: ' dark' ,
85
+ text: t (' Dark' )
86
+ },
87
+ {
88
+ key: ' system' ,
89
+ text: t (' System' )
90
+ }
91
+ ];
92
+
93
+ watch (theme, (value ) => ThemeService .set (value));
94
+
95
+ return {
96
+ offcanvasShow,
97
+
98
+ language,
99
+ languageItems,
100
+
101
+ theme,
102
+ themeItems
103
+ };
104
+ }
105
+ }
106
+ </script >
Original file line number Diff line number Diff line change 16
16
<div class =" ms-auto" >
17
17
<slot name =" end" ></slot >
18
18
19
+ <AppSettings />
20
+
19
21
<button
20
22
type =" button"
21
23
class =" btn btn-sm text-white"
28
30
</template >
29
31
30
32
<script >
31
- import { useRouter } from " vue-router" ;
33
+ import { useRouter } from ' vue-router' ;
34
+
35
+ // Components
36
+ import AppSettings from ' @/components/layout/AppSettings.vue' ;
32
37
33
38
// Services
34
- import AuthenticationService from " @/services/authentication.service" ;
39
+ import AuthenticationService from ' @/services/authentication.service' ;
35
40
36
41
export default {
37
42
name: ' VHeader' ,
38
43
44
+ components: {
45
+ AppSettings
46
+ },
47
+
39
48
setup () {
40
49
const router = useRouter ();
41
50
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ export default {
3
3
"Username" : "Username" ,
4
4
"Password" : "Password" ,
5
5
"Submit" : "Submit" ,
6
+ "Cancel" : "Cancel" ,
6
7
"Dashboard" : "Dashboard" ,
7
8
"Users" : "Users" ,
8
9
"Authorization Error" : "Authorization Error" ,
@@ -26,5 +27,11 @@ export default {
26
27
"Not completed" : "Not completed" ,
27
28
"Filter by title" : "Filter by title" ,
28
29
"Filter by user" : "Filter by user" ,
29
- "Filter by status" : "Filter by status"
30
+ "Filter by status" : "Filter by status" ,
31
+ "Language" : "Language" ,
32
+ "Theme" : "Theme" ,
33
+ "Light" : "Light" ,
34
+ "Dark" : "Dark" ,
35
+ "System" : "System" ,
36
+ "Settings" : "Settings" ,
30
37
} ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ export default {
3
3
"Username" : "نام کاریری" ,
4
4
"Password" : "رمز عبور" ,
5
5
"Submit" : "ارسال" ,
6
+ "Cancel" : "انصراف" ,
6
7
"Dashboard" : "داشبورد" ,
7
8
"Users" : "کاربران" ,
8
9
"Authorization Error" : "خطای دسترسی" ,
@@ -26,5 +27,11 @@ export default {
26
27
"Not completed" : "تکمیل نشده" ,
27
28
"Filter by title" : "فیلتر بر اساس عنوان" ,
28
29
"Filter by user" : "فیلتر بر اساس کاربر" ,
29
- "Filter by status" : "فیلتر بر اساس وضعیت"
30
+ "Filter by status" : "فیلتر بر اساس وضعیت" ,
31
+ "Language" : "زبان" ,
32
+ "Theme" : "زمینه" ,
33
+ "Light" : "روشن" ,
34
+ "Dark" : "تیره" ,
35
+ "System" : "سیستم" ,
36
+ "Settings" : "تنظیمات" ,
30
37
} ;
Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ class LanguageService {
31
31
* @returns void
32
32
*/
33
33
static set ( value ) {
34
- vueI18N . global . locale = value ;
35
34
StorageService . set ( this . STORAGE_KEY , value ) ;
35
+ location . reload ( ) ;
36
36
}
37
37
38
38
/**
Original file line number Diff line number Diff line change
1
+ import StorageService from './storage.service' ;
2
+
3
+ class ThemeService {
4
+ /**
5
+ * Storage key
6
+ *
7
+ * @returns {String }
8
+ */
9
+ static get STORAGE_KEY ( ) {
10
+ return 'theme' ;
11
+ }
12
+
13
+ /**
14
+ * Default theme
15
+ *
16
+ * @returns {String }
17
+ */
18
+ static get DEFAULT ( ) {
19
+ return 'light' ;
20
+ }
21
+
22
+ /**
23
+ * Set theme
24
+ *
25
+ * @param {String } value
26
+ * @returns void
27
+ */
28
+ static set ( value ) {
29
+ StorageService . set ( this . STORAGE_KEY , value ) ;
30
+ this . updateDOM ( ) ;
31
+ }
32
+
33
+ /**
34
+ * Update dom based on current theme
35
+ *
36
+ * @returns void
37
+ */
38
+ static updateDOM ( ) {
39
+ const rootEl = document . documentElement ;
40
+ rootEl . setAttribute ( 'data-bs-theme' , this . get ( ) ) ;
41
+ }
42
+
43
+ /**
44
+ * Get theme
45
+ *
46
+ * @returns {String }
47
+ */
48
+ static get ( ) {
49
+ return StorageService . get ( this . STORAGE_KEY ) ?? this . DEFAULT ;
50
+ }
51
+ }
52
+
53
+ export default ThemeService ;
You can’t perform that action at this time.
0 commit comments