Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | <template> <v-container class="py-6" fluid> <!-- <v-row class="mb-6">--> <!-- <v-col cols="12">--> <!-- <p>このページというかprofile以下で扱うものは以下とする</p>--> <!-- <ul>--> <!-- <li>ログイン情報</li>--> <!-- <li>スタッフ情報(履歴書に記載する氏名とか学歴・職歴以外の部分)</li>--> <!-- <li>住所(複数個有るかもしれない)</li>--> <!-- <li>最寄り駅</li>--> <!-- </ul>--> <!-- <p>職歴・学歴・保有スキルなどについては、ドロワナビに専用のコンテンツを作る</p>--> <!-- <v-btn--> <!-- text="再読み込み"--> <!-- @click="onReloadProfile" />--> <!-- </v-col>--> <!-- </v-row>--> <v-row class="mb-6"> <v-col cols="12"> <h2 class="mb-2">{{ t('ui.page.profile.login.section.login.title') }}</h2> <v-table class="v-table--flat" density="compact"> <tbody> <!-- <tr>--> <!-- <th>{{ t('domain.user.id.label') }}</th>--> <!-- <td>{{ profile.id }}</td>--> <!-- </tr>--> <!-- <tr>--> <!-- <th>{{ t('domain.user.uid.label') }}</th>--> <!-- <td>{{ profile.uid }}</td>--> <!-- </tr>--> <tr> <th>{{ t('domain.user.displayName.label') }}</th> <td>{{ profile.displayName }}</td> </tr> <tr> <th>{{ t('domain.user.email.label') }}</th> <td>{{ profile.email }}</td> </tr> <!-- <tr>--> <!-- <th>{{ t('domain.user.emailVerified.label') }}</th>--> <!-- <td>{{ profile.emailVerified }}</td>--> <!-- </tr>--> <tr> <th>{{ t('domain.user.photoUrl.label') }}</th> <td> <img v-if="profile.photoUrl" :src="profile.photoUrl" alt="User photo" style="max-width: 64px; max-height: 64px; border-radius: 50%;" /> <span v-else>(なし)</span> </td> </tr> <!-- <tr>--> <!-- <th>{{ t('domain.user.disabled.label') }}</th>--> <!-- <td>{{ profile.disabled }}</td>--> <!-- </tr>--> <tr> <th>{{ t('domain.user.lastLoginAt.label') }}</th> <td>{{ profile.lastLoginAt }}</td> </tr> <tr> <th>{{ t('domain.user.createdAt.label') }}</th> <td>{{ profile.createdAt }}</td> </tr> <tr> <th>{{ t('domain.user.updatedAt.label') }}</th> <td>{{ profile.updatedAt }}</td> </tr> <!-- <tr>--> <!-- <th>{{ t('domain.user.deletedAt.label') }}</th>--> <!-- <td>{{ profile.deletedAt }}</td>--> <!-- </tr>--> </tbody> </v-table> </v-col> </v-row> <v-row class="mb-6"> <v-col cols="12"> <h2 class="mb-2">{{ t('ui.page.profile.login.section.identity.title') }}</h2> <!-- 検索(任意) --> <v-text-field v-model="identitiesSearch" :label="t('ui.form.search.label')" prepend-inner-icon="mdi-magnify" clearable class="mb-3" @update:modelValue="debouncedSearch" @keyup.enter="fetchIdentities" @click:clear="() => { identitiesSearch = ''; identitiesOptions.page = 1; fetchIdentities() }" /> <v-data-table-server :headers="identitiesHeaders" :items="identitiesItems" :items-length="identitiesTotal" :loading="identitiesLoading" :items-per-page="identitiesOptions.itemsPerPage" :page="identitiesOptions.page" :sort-by="identitiesOptions.sortBy" :items-per-page-options="perPageOptions" item-value="id" class="elevation-1 brand-data-table" @update:options="onUpdateIdentitiesOptions" > <template #item.createdAt="{ item }"> {{ new Date(item.createdAt).toLocaleString() }} </template> </v-data-table-server> </v-col> </v-row> </v-container> </template> <script setup lang="ts"> // region import import {useApi} from '@/composables/useApi' import {useSchemaLogger} from '@/libs/logger/logger' import {onMounted, ref} from "vue"; import {withLoading} from "@/libs/loading" import {normalizeError} from "@/utils" import { useI18n } from 'vue-i18n' import { usePerPageOptions } from '@/composables/usePerPageOptions' import { debounce } from 'lodash-es' import type { DataTableOptions } from '@/types/globals/datatables' // endregion import // region Component Injection // endregion Component Injection // region types type User = { id: number uid: string displayName: string | null email: string emailVerified: boolean photoUrl: string | null disabled: boolean lastLoginAt: string | null createdAt: string updatedAt: string deletedAt: string | null } const emptyUser: User = { id: 0, uid: '', displayName: null, email: '', emailVerified: false, photoUrl: null, disabled: false, lastLoginAt: null, createdAt: '', updatedAt: '', deletedAt: null, } type UserIdentity = { id: number userId: number provider: string providerUserId: string providerDisplayName: string emailAtSignup: string | null createdAt: string // updatedAt?: string } type ProfileResponse = { user: User authIdentities: UserIdentity[] } // endregion types // region interface // endregion interface // region constants const api = useApi() const { t } = useI18n() const logger = useSchemaLogger({module: 'me'}) const { perPageOptions } = usePerPageOptions() // endregion constants // region props // endregion props // region variable // endregion variable // region properties const profile = ref<User>(emptyUser) const identities = ref<UserIdentity[]>([]) // テーブル表示データ const identitiesItems = ref<any[]>([]) const identitiesTotal = ref(0) const identitiesLoading = ref(false) // 検索キーワード(必要なければ削除OK) const identitiesSearch = ref('') // サーバテーブルのオプション(Vuetify規約) const identitiesOptions = ref<DataTableOptions>({ page: 1, itemsPerPage: 10, sortBy: [{ key: 'created_at', order: 'desc' }], // ← APIはsnakeでOK(camel_snake_codecで自動変換するなら createdAt でも可) }) // ヘッダ(key はレスポンスに合わせて。middlewareでcamel化してるなら camelCase に) const identitiesHeaders = [ { title: t('domain.userIdentity.provider.label'), key: 'provider' }, { title: t('domain.userIdentity.providerUserId.label'), key: 'providerUserId' }, { title: t('domain.userIdentity.emailAtSignup.label'), key: 'emailAtSignup' }, { title: t('domain.userIdentity.providerDisplayName.label'), key: 'providerDisplayName' }, { title: t('domain.userIdentity.createdAt.label'), key: 'createdAt' }, ] // endregion properties // region emits // endregion emits // region validator // endregion validator // region methods // const onReloadProfile = async () => { // try { // // logger.debug('再読み込み開始:ローティング開始') // const res = await withLoading(() => handleFetchProfile(), 'me:reloadProfile') // profile.value = res.user // identities.value = res.authIdentities // } catch (e) { // logger.error('error', normalizeError(e)) // } // } const handleFetchProfile = async () => { try { const apiResponse = await api.get<ProfileResponse>('/fl/profile/') // console.log(`response data : ${JSON.stringify(apiResponse)}`) return apiResponse.data } catch (e) { logger.error('error', e) logger.error('error', normalizeError(e)) } } const debouncedSearch = debounce(() => { // 新しい検索時は 1 ページ目から identitiesOptions.value.page = 1 fetchIdentities() }, 400) // データ取得 const fetchIdentities = async () => { identitiesLoading.value = true try { const sortKey = identitiesOptions.value.sortBy?.[0]?.key ?? 'created_at' const order = identitiesOptions.value.sortBy?.[0]?.order ?? 'desc' const qRaw = identitiesSearch.value ?? '' const qSan = qRaw.trim() // 例:2文字未満は検索しない(必要なら) // const qParam = qSan.length >= 2 ? qSan : undefined const qParam = qSan !== '' ? qSan : undefined const { data } = await api.get('/fl/profile/identities', { params: { q: qParam, page: identitiesOptions.value.page, perPage: identitiesOptions.value.itemsPerPage, sort: sortKey, order, }, }) identitiesItems.value = data.items ?? [] identitiesTotal.value = data.total ?? 0 } catch (e) { console.error(e) identitiesItems.value = [] identitiesTotal.value = 0 } finally { identitiesLoading.value = false } } // Vuetifyの options 更新イベントで再取得 const onUpdateIdentitiesOptions = (opts: DataTableOptions) => { identitiesOptions.value = opts fetchIdentities() } // 初期ロード fetchIdentities() onMounted(async () => { try { const [user] = await withLoading(async () => { return await Promise.all([ handleFetchProfile() ]) }, 'me:onMounted') profile.value = user.user identities.value = user.authIdentities } catch (e) { logger.error('e: ', e) } }) // endregion methods // region export // endregion export </script> <style scoped> </style> |