-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
624 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<div> | ||
<NuxtWelcome /> | ||
</div> | ||
<NuxtLayout> | ||
<NuxtPage /> | ||
</NuxtLayout> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* @Author: NMTuan | ||
* @Email: NMTuan@qq.com | ||
* @Date: 2023-06-27 15:59:25 | ||
* @LastEditTime: 2023-06-30 20:55:06 | ||
* @LastEditors: NMTuan | ||
* @Description: | ||
* @FilePath: \laf_curd\composables\request.js | ||
*/ | ||
export const request = (params, disabledLoading) => { | ||
// let loading | ||
const runtimeConfig = useRuntimeConfig() | ||
const userStore = useUserStore() | ||
|
||
const defaultParams = { | ||
url: undefined, | ||
method: 'GET', | ||
path: undefined, | ||
query: {}, | ||
body: {}, | ||
auth: true | ||
} | ||
|
||
params = { ...defaultParams, ...params } | ||
|
||
// 如果传了url则使用,否则用env中配置项。 | ||
const url = (params.url || runtimeConfig.public.requestUrl) + params.path | ||
delete params.url | ||
delete params.path | ||
|
||
// get请求不需要body | ||
if (params.method === 'GET') { | ||
delete params.body | ||
} | ||
|
||
// 鉴权 | ||
if (params.auth !== false) { | ||
params.headers = { | ||
Authorization: 'Bearer ' + userStore.token | ||
} | ||
} | ||
delete params.auth | ||
|
||
return new Promise((resolve, reject) => { | ||
if (!url) { | ||
reject({ | ||
code: 40000, | ||
message: 'no url' | ||
}) | ||
} | ||
// if (!disabledLoading) { | ||
// loading = ElLoading.service() | ||
// } | ||
$fetch(url, params) | ||
// .finally(() => { | ||
// if (!disabledLoading) { | ||
// loading.close() | ||
// } | ||
// }) | ||
.then((res) => { | ||
if (res instanceof Blob) { | ||
resolve(res) | ||
} else if (!res.error) { | ||
if (res.message) { | ||
// ElMessage({ | ||
// message: res.message, | ||
// type: 'success' | ||
// }) | ||
} | ||
resolve(res) | ||
} else { | ||
if (res.code && res.message) { | ||
// ElMessageBox.alert(res.message, { | ||
// title: `Error ${res.code}` | ||
// }) | ||
} | ||
reject(res) | ||
} | ||
}) | ||
.catch((res) => { | ||
if (res.response && res.response.status) { | ||
// ElMessageBox.alert('网络异常,请稍后重试!', { | ||
// title: `Error ${res.response.status}` | ||
// }) | ||
} | ||
reject(res) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* @Author: NMTuan | ||
* @Email: NMTuan@qq.com | ||
* @Date: 2023-06-29 21:14:49 | ||
* @LastEditTime: 2023-06-29 21:28:45 | ||
* @LastEditors: NMTuan | ||
* @Description: | ||
* @FilePath: \ezMemos\middleware\auth.global.ts | ||
*/ | ||
export default defineNuxtRouteMiddleware((to, from) => { | ||
const userStore = useUserStore() | ||
console.log('to', to) | ||
console.log('userStore', userStore.whiteList) | ||
|
||
// 不在白名单, 而且没token | ||
if (!userStore.whiteList.includes(to.path) && !userStore.token) { | ||
return navigateTo('/welcome') | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,27 @@ | ||
/* | ||
* @Author: NMTuan | ||
* @Email: NMTuan@qq.com | ||
* @Date: 2023-06-30 19:16:42 | ||
* @LastEditTime: 2023-06-30 20:30:13 | ||
* @LastEditors: NMTuan | ||
* @Description: | ||
* @FilePath: \laf_curd\nuxt.config.ts | ||
*/ | ||
// https://nuxt.com/docs/api/configuration/nuxt-config | ||
export default defineNuxtConfig({ | ||
devtools: { enabled: true } | ||
css: ['@unocss/reset/normalize.css'], | ||
modules: ['@unocss/nuxt', '@pinia/nuxt'], | ||
devtools: { enabled: true }, | ||
runtimeConfig: { | ||
public: { | ||
requestUrl: 'https://api.laf.run', | ||
pat: '' | ||
} | ||
}, | ||
experimental: { | ||
viewTransition: true | ||
}, | ||
imports: { | ||
dirs: ['stores'] | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!-- | ||
* @Author: NMTuan | ||
* @Email: NMTuan@qq.com | ||
* @Date: 2023-06-30 20:33:19 | ||
* @LastEditTime: 2023-06-30 20:34:11 | ||
* @LastEditors: NMTuan | ||
* @Description: | ||
* @FilePath: \laf_curd\pages\index.vue | ||
--> | ||
<template> | ||
<div> | ||
index ! | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!-- | ||
* @Author: NMTuan | ||
* @Email: NMTuan@qq.com | ||
* @Date: 2023-06-30 20:41:21 | ||
* @LastEditTime: 2023-06-30 20:43:25 | ||
* @LastEditors: NMTuan | ||
* @Description: | ||
* @FilePath: \laf_curd\pages\login.vue | ||
--> | ||
<template> | ||
<div> | ||
login ! | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!-- | ||
* @Author: NMTuan | ||
* @Email: NMTuan@qq.com | ||
* @Date: 2023-06-30 20:33:22 | ||
* @LastEditTime: 2023-06-30 20:53:15 | ||
* @LastEditors: NMTuan | ||
* @Description: | ||
* @FilePath: \laf_curd\pages\welcome.vue | ||
--> | ||
<template> | ||
<div> | ||
<div v-if="error">error</div> | ||
welcome ! | ||
|
||
<p>requestUrl:{{ requestUrl }}</p> | ||
|
||
<p>pat:{{ pat }}</p> | ||
|
||
<p><button @click="handlerLogin">login</button></p> | ||
</div> | ||
</template> | ||
<script setup> | ||
const runtimeConfig = useRuntimeConfig() | ||
const userStore = useUserStore() | ||
const { requestUrl, pat } = runtimeConfig.public | ||
const error = ref(false) | ||
|
||
const handlerLogin = async () => { | ||
if (!requestUrl || !pat) { | ||
error.value = true | ||
return | ||
} | ||
error.value = false | ||
request({ | ||
path: '/v1/auth/pat2token', | ||
method: 'POST', | ||
body: { | ||
pat | ||
} | ||
}) | ||
.then(res => { | ||
if (res.data) { | ||
userStore.update_token(res.data) | ||
navigateTo({ name: 'index' }) | ||
} | ||
}) | ||
.catch(err => { | ||
error.value = true | ||
}) | ||
} | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* @Author: NMTuan | ||
* @Email: NMTuan@qq.com | ||
* @Date: 2023-06-30 20:30:22 | ||
* @LastEditTime: 2023-06-30 20:59:01 | ||
* @LastEditors: NMTuan | ||
* @Description: | ||
* @FilePath: \laf_curd\stores\user.ts | ||
*/ | ||
import { defineStore } from 'pinia' | ||
|
||
export const useUserStore = defineStore('useUserStore', () => { | ||
const token = useCookie('laf_curd_token') | ||
const whiteList = ['/welcome'] // 不需要鉴权的url路径 | ||
|
||
const update_token = (val: string) => { | ||
token.value = val | ||
} | ||
|
||
return { | ||
token, | ||
whiteList, | ||
update_token | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineConfig, presetAttributify, presetUno } from 'unocss' | ||
import transformerDirectives from '@unocss/transformer-directives' | ||
import transformerVariantGroup from '@unocss/transformer-variant-group' | ||
import presetIcons from '@unocss/preset-icons' | ||
|
||
export default defineConfig({ | ||
presets: [ | ||
presetUno(), // default | ||
presetAttributify(), // attr mode: text="sm white" | ||
presetIcons() // icon: i-ri-home-fill | ||
], | ||
transformers: [ | ||
transformerDirectives(), // @apply or --at-apply | ||
transformerVariantGroup() // hover:(x x) | ||
] | ||
}) |
Oops, something went wrong.