@finema/finework-layer 0.2.14 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,99 +1,102 @@
1
- <template>
2
- <div class="overflow-hidden pt-[80px]">
3
- <div class="flex min-h-[calc(100vh-80px)] flex-col">
4
- <nav
5
- class="fixed top-0 left-0 z-20 flex min-h-[80px] w-screen items-center justify-center bg-white"
6
- style="box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.04)"
7
- >
8
- <div class="mx-auto flex w-full px-4 md:px-8">
9
- <div class="flex items-center gap-4">
10
- <NuxtLink :to="routes.home.to">
11
- <img
12
- src="/logo-mini.png"
13
- alt="logo_mini"
14
- class="h-[27px] w-[172px] cursor-pointer"
15
- />
16
- </NuxtLink>
17
- <Apps />
18
- </div>
19
-
20
- <div class="flex flex-1 items-center justify-end gap-2">
21
- <DropdownMenu
22
- :items="userMenuItems"
23
- size="xl"
24
- :content="{
25
- align: 'end',
26
- side: 'bottom',
27
- }"
28
- :ui="{
29
- content: 'w-48',
30
- }"
31
- >
32
- <div class="relative flex cursor-pointer items-center gap-2">
33
- <div class="hidden flex-col justify-end text-right lg:flex">
34
- <p class="text-sm font-bold">
35
- {{
36
- auth.me.value?.display_name || auth.me.value?.full_name
37
- }}
38
- </p>
39
- <p class="text-muted text-xs">
40
- {{ auth.me.value?.email }}
41
- </p>
42
- </div>
43
- <Avatar
44
- class="border-muted size-[36px] border text-2xl"
45
- icon="ri:user-line"
46
- :src="auth.me.value?.avatar_url"
47
- />
48
- <Icon name="i-ph:caret-down-light" class="size-5" />
49
- </div>
50
- </DropdownMenu>
51
- </div>
52
- </div>
53
- </nav>
54
- <main class="mx-auto w-full max-w-7xl flex-1 px-4 pb-20 2xl:max-w-7/10">
55
- <div
56
- v-if="app.pageMeta.title"
57
- class="mb-4 flex flex-col justify-between gap-1 md:mb-6 md:gap-4 lg:flex-row lg:items-center"
58
- >
59
- <div class="flex flex-1 flex-col">
60
- <h1
61
- class="text-3xl font-bold wrap-break-word lg:max-w-2/3"
62
- :title="app.pageMeta.title"
63
- >
64
- {{ app.pageMeta.title }}
65
- <span id="page-title-extra" />
66
- </h1>
67
-
68
- <div id="page-subtitle" />
69
- </div>
70
- <div id="page-header" />
71
- </div>
72
- <slot />
73
- </main>
74
- <div id="page-footer" />
75
- </div>
76
- </div>
77
- </template>
78
-
79
- <script lang="ts" setup>
80
- import type { DropdownMenuItem } from '@nuxt/ui'
81
- import Apps from '../Apps.vue'
82
-
83
- const app = useApp()
84
- const auth = useAuth()
85
- const userMenuItems: DropdownMenuItem[] = [
86
- {
87
- label: 'View profile',
88
- icon: 'i-lucide-user',
89
- to: routes.account.profile.to,
90
- },
91
-
92
- {
93
- label: routes.logout.label,
94
- icon: 'i-lucide-log-out',
95
- to: routes.logout.to,
96
- external: true,
97
- },
98
- ]
99
- </script>
1
+ <template>
2
+ <div class="overflow-hidden pt-[80px]">
3
+ <div class="flex min-h-[calc(100vh-80px)] flex-col">
4
+ <nav
5
+ class="fixed top-0 left-0 z-20 flex min-h-[80px] w-screen items-center justify-center bg-white"
6
+ style="box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.04)"
7
+ >
8
+ <div class="mx-auto flex w-full px-4 md:px-8">
9
+ <div class="flex items-center gap-4">
10
+ <NuxtLink :to="routes.home.to">
11
+ <img
12
+ src="/logo-mini.png"
13
+ alt="logo_mini"
14
+ class="h-[27px] w-[172px] cursor-pointer"
15
+ />
16
+ </NuxtLink>
17
+ <Apps />
18
+ </div>
19
+
20
+ <div class="flex flex-1 items-center justify-end gap-2">
21
+ <DropdownMenu
22
+ :items="userMenuItems"
23
+ size="xl"
24
+ :content="{
25
+ align: 'end',
26
+ side: 'bottom',
27
+ }"
28
+ :ui="{
29
+ content: 'w-48',
30
+ }"
31
+ >
32
+ <div class="relative flex cursor-pointer items-center gap-2">
33
+ <div class="hidden flex-col justify-end text-right lg:flex">
34
+ <p class="text-sm font-bold">
35
+ {{
36
+ auth.me.value?.display_name || auth.me.value?.full_name
37
+ }}
38
+ </p>
39
+ <p class="text-muted text-xs">
40
+ {{ auth.me.value?.email }}
41
+ </p>
42
+ </div>
43
+ <Avatar
44
+ class="border-muted size-[36px] border text-2xl"
45
+ icon="ri:user-line"
46
+ :src="auth.me.value?.avatar_url"
47
+ />
48
+ <Icon
49
+ name="i-ph:caret-down-light"
50
+ class="size-5"
51
+ />
52
+ </div>
53
+ </DropdownMenu>
54
+ </div>
55
+ </div>
56
+ </nav>
57
+ <main class="mx-auto w-full max-w-7xl flex-1 px-4 pb-20 2xl:max-w-7/10">
58
+ <div
59
+ v-if="app.pageMeta.title"
60
+ class="mb-4 flex flex-col justify-between gap-1 md:mb-6 md:gap-4 lg:flex-row lg:items-center"
61
+ >
62
+ <div class="flex flex-1 flex-col">
63
+ <h1
64
+ class="text-3xl font-bold wrap-break-word lg:max-w-2/3"
65
+ :title="app.pageMeta.title"
66
+ >
67
+ {{ app.pageMeta.title }}
68
+ <span id="page-title-extra" />
69
+ </h1>
70
+
71
+ <div id="page-subtitle" />
72
+ </div>
73
+ <div id="page-header" />
74
+ </div>
75
+ <slot />
76
+ </main>
77
+ <div id="page-footer" />
78
+ </div>
79
+ </div>
80
+ </template>
81
+
82
+ <script lang="ts" setup>
83
+ import type { DropdownMenuItem } from '@nuxt/ui'
84
+ import Apps from '../Apps.vue'
85
+
86
+ const app = useApp()
87
+ const auth = useAuth()
88
+ const userMenuItems: DropdownMenuItem[] = [
89
+ {
90
+ label: 'View profile',
91
+ icon: 'i-lucide-user',
92
+ to: routes.account.profile.to,
93
+ },
94
+
95
+ {
96
+ label: routes.logout.label,
97
+ icon: 'i-lucide-log-out',
98
+ to: routes.logout.to,
99
+ external: true,
100
+ },
101
+ ]
102
+ </script>
@@ -1,56 +1,56 @@
1
- <template>
2
- <slot v-if="skip" />
3
- <template v-else>
4
- <Card v-if="status.isLoading">
5
- <div class="flex items-center justify-center py-12">
6
- <Loader />
7
- </div>
8
- </Card>
9
-
10
- <!-- Not Found State -->
11
- <Card v-else-if="status.isSuccess && !data || status.isError && status.errorData?.code === 'NOT_FOUND'">
12
- <div class="py-12 text-center">
13
- <Icon
14
- name="lucide:search-x"
15
- class="mx-auto mb-4 text-gray-400"
16
- size="48"
17
- />
18
- <h3 class="mb-2 text-lg font-medium text-gray-900">
19
- ไม่พบข้อมูล
20
- </h3>
21
- <p class="text-gray-600">
22
- ไม่พบข้อมูลที่คุณค้นหา กรุณาลองใหม่อีกครั้ง
23
- </p>
24
- </div>
25
- </Card>
26
- <Card v-else-if="status.isError">
27
- <div class="py-12 text-center">
28
- <Icon
29
- name="lucide:alert-circle"
30
- class="mx-auto mb-4 text-red-500"
31
- size="48"
32
- />
33
- <h3 class="mb-2 text-lg font-medium text-gray-900">
34
- เกิดข้อผิดพลาด
35
- </h3>
36
- <p class="text-gray-600">
37
- ไม่สามารถโหลดข้อมูลได้ กรุณาลองใหม่อีกครั้ง
38
- </p>
39
- </div>
40
- </Card>
41
- <slot
42
- v-else-if="data"
43
- :data="data"
44
- />
45
- </template>
46
- </template>
47
-
48
- <script lang="ts" setup generic="T">
49
- import type { IStatus } from '#core/types/lib'
50
-
51
- defineProps<{
52
- status: IStatus
53
- data: T
54
- skip?: boolean
55
- }>()
56
- </script>
1
+ <template>
2
+ <slot v-if="skip" />
3
+ <template v-else>
4
+ <Card v-if="status.isLoading">
5
+ <div class="flex items-center justify-center py-12">
6
+ <Loader />
7
+ </div>
8
+ </Card>
9
+
10
+ <!-- Not Found State -->
11
+ <Card v-else-if="status.isSuccess && !data || status.isError && status.errorData?.code === 'NOT_FOUND'">
12
+ <div class="py-12 text-center">
13
+ <Icon
14
+ name="lucide:search-x"
15
+ class="mx-auto mb-4 text-gray-400"
16
+ size="48"
17
+ />
18
+ <h3 class="mb-2 text-lg font-medium text-gray-900">
19
+ ไม่พบข้อมูล
20
+ </h3>
21
+ <p class="text-gray-600">
22
+ ไม่พบข้อมูลที่คุณค้นหา กรุณาลองใหม่อีกครั้ง
23
+ </p>
24
+ </div>
25
+ </Card>
26
+ <Card v-else-if="status.isError">
27
+ <div class="py-12 text-center">
28
+ <Icon
29
+ name="lucide:alert-circle"
30
+ class="mx-auto mb-4 text-red-500"
31
+ size="48"
32
+ />
33
+ <h3 class="mb-2 text-lg font-medium text-gray-900">
34
+ เกิดข้อผิดพลาด
35
+ </h3>
36
+ <p class="text-gray-600">
37
+ ไม่สามารถโหลดข้อมูลได้ กรุณาลองใหม่อีกครั้ง
38
+ </p>
39
+ </div>
40
+ </Card>
41
+ <slot
42
+ v-else-if="data"
43
+ :data="data"
44
+ />
45
+ </template>
46
+ </template>
47
+
48
+ <script lang="ts" setup generic="T">
49
+ import type { IStatus } from '#core/types/lib'
50
+
51
+ defineProps<{
52
+ status: IStatus
53
+ data: T
54
+ skip?: boolean
55
+ }>()
56
+ </script>
@@ -71,14 +71,29 @@ export const useAuth = () => {
71
71
  const isAuthenticated = computed(() => !!token.value)
72
72
  const me = defineStore('auth.me', () => {
73
73
  const value = ref<IUser | null>(null)
74
+ const timestamp = ref<number | null>(null)
74
75
 
75
76
  const set = (user: IUser | null) => {
76
77
  value.value = user
77
78
  }
78
79
 
80
+ const setTimestamp = (t: number | null) => {
81
+ timestamp.value = t
82
+ }
83
+
84
+ const isShouldFetch = computed(() => {
85
+ if (!value.value) return true
86
+
87
+ // expire 1 mins
88
+ return !timestamp.value || timestamp.value < Date.now() - 1000 * 60 * 1
89
+ })
90
+
79
91
  return {
80
92
  value,
81
93
  set,
94
+ timestamp,
95
+ setTimestamp,
96
+ isShouldFetch,
82
97
  }
83
98
  })()
84
99
 
@@ -111,11 +126,13 @@ export const useAuth = () => {
111
126
  }
112
127
 
113
128
  useWatchTrue(() => fetchMe.status.value.isSuccess, () => {
129
+ me.setTimestamp(Date.now())
114
130
  me.set(fetchMe.data.value)
115
131
  })
116
132
 
117
133
  useWatchTrue(() => fetchMe.status.value.isError, () => {
118
134
  token.value = undefined
135
+ me.setTimestamp(null)
119
136
  me.set(null)
120
137
  })
121
138
 
@@ -1,50 +1,50 @@
1
- import type { AxiosRequestConfig } from 'axios'
2
-
3
- export const useRequestOptions = () => {
4
- const config = useRuntimeConfig()
5
-
6
- const mock = (): Omit<AxiosRequestConfig, 'baseURL'> & {
7
- baseURL: string
8
- } => {
9
- return {
10
- baseURL: config.public.baseAPIMock || 'http://localhost:3000/api/mock',
11
- }
12
- }
13
-
14
- const base = (): Omit<AxiosRequestConfig, 'baseURL'> & {
15
- baseURL: string
16
- } => {
17
- return {
18
- baseURL: config.public.baseAPI,
19
- }
20
- }
21
-
22
- const auth = (): Omit<AxiosRequestConfig, 'baseURL'> & {
23
- baseURL: string
24
- } => {
25
- return {
26
- baseURL: config.public.baseAPI,
27
- headers: {
28
- Authorization: `Bearer ${useAuth().token.value}`,
29
- },
30
- }
31
- }
32
-
33
- const file = (): Omit<AxiosRequestConfig, 'baseURL'> & {
34
- baseURL: string
35
- } => {
36
- return {
37
- baseURL: config.public.baseAPI + '/uploads',
38
- headers: {
39
- Authorization: `Bearer ${useAuth().token.value}`,
40
- },
41
- }
42
- }
43
-
44
- return {
45
- base,
46
- mock,
47
- auth,
48
- file,
49
- }
50
- }
1
+ import type { AxiosRequestConfig } from 'axios'
2
+
3
+ export const useRequestOptions = () => {
4
+ const config = useRuntimeConfig()
5
+
6
+ const mock = (): Omit<AxiosRequestConfig, 'baseURL'> & {
7
+ baseURL: string
8
+ } => {
9
+ return {
10
+ baseURL: config.public.baseAPIMock || 'http://localhost:3000/api/mock',
11
+ }
12
+ }
13
+
14
+ const base = (): Omit<AxiosRequestConfig, 'baseURL'> & {
15
+ baseURL: string
16
+ } => {
17
+ return {
18
+ baseURL: config.public.baseAPI,
19
+ }
20
+ }
21
+
22
+ const auth = (): Omit<AxiosRequestConfig, 'baseURL'> & {
23
+ baseURL: string
24
+ } => {
25
+ return {
26
+ baseURL: config.public.baseAPI,
27
+ headers: {
28
+ Authorization: `Bearer ${useAuth().token.value}`,
29
+ },
30
+ }
31
+ }
32
+
33
+ const file = (): Omit<AxiosRequestConfig, 'baseURL'> & {
34
+ baseURL: string
35
+ } => {
36
+ return {
37
+ baseURL: config.public.baseAPI + '/uploads',
38
+ headers: {
39
+ Authorization: `Bearer ${useAuth().token.value}`,
40
+ },
41
+ }
42
+ }
43
+
44
+ return {
45
+ base,
46
+ mock,
47
+ auth,
48
+ file,
49
+ }
50
+ }