Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
1f69f07100
@ -4,7 +4,7 @@ import vue from '@vitejs/plugin-vue'
|
|||||||
* * 扩展setup插件,支持在script标签中使用name属性
|
* * 扩展setup插件,支持在script标签中使用name属性
|
||||||
* usage: <script setup name="MyComp"></script>
|
* usage: <script setup name="MyComp"></script>
|
||||||
*/
|
*/
|
||||||
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
|
import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * unocss插件,原子css
|
* * unocss插件,原子css
|
||||||
@ -20,7 +20,7 @@ import { configMockPlugin } from './mock'
|
|||||||
import unplugin from './unplugin'
|
import unplugin from './unplugin'
|
||||||
|
|
||||||
export function createVitePlugins(viteEnv, isBuild) {
|
export function createVitePlugins(viteEnv, isBuild) {
|
||||||
const plugins = [vue(), VueSetupExtend(), ...unplugin, configHtmlPlugin(viteEnv, isBuild), Unocss()]
|
const plugins = [vue(), vueSetupExtend(), ...unplugin, configHtmlPlugin(viteEnv, isBuild), Unocss()]
|
||||||
|
|
||||||
if (viteEnv?.VITE_APP_USE_MOCK) {
|
if (viteEnv?.VITE_APP_USE_MOCK) {
|
||||||
plugins.push(configMockPlugin(isBuild))
|
plugins.push(configMockPlugin(isBuild))
|
||||||
|
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@ -30,7 +30,7 @@ specifiers:
|
|||||||
vite: ^2.9.9
|
vite: ^2.9.9
|
||||||
vite-plugin-html: ^3.2.0
|
vite-plugin-html: ^3.2.0
|
||||||
vite-plugin-mock: ^2.9.6
|
vite-plugin-mock: ^2.9.6
|
||||||
vite-plugin-vue-setup-extend: ^0.3.0
|
vite-plugin-vue-setup-extend-plus: ^0.1.0
|
||||||
vue: ^3.2.31
|
vue: ^3.2.31
|
||||||
vue-router: ^4.0.15
|
vue-router: ^4.0.15
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ devDependencies:
|
|||||||
vite: 2.9.9_sass@1.49.10
|
vite: 2.9.9_sass@1.49.10
|
||||||
vite-plugin-html: 3.2.0_vite@2.9.9
|
vite-plugin-html: 3.2.0_vite@2.9.9
|
||||||
vite-plugin-mock: 2.9.6_mockjs@1.1.0+vite@2.9.9
|
vite-plugin-mock: 2.9.6_mockjs@1.1.0+vite@2.9.9
|
||||||
vite-plugin-vue-setup-extend: 0.3.0_vite@2.9.9
|
vite-plugin-vue-setup-extend-plus: 0.1.0
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
@ -2788,14 +2788,8 @@ packages:
|
|||||||
- supports-color
|
- supports-color
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/vite-plugin-vue-setup-extend/0.3.0_vite@2.9.9:
|
/vite-plugin-vue-setup-extend-plus/0.1.0:
|
||||||
resolution: {integrity: sha512-9Nd7Bj4TftB2CoOAD2ZI4cHLW5zjKMF3LNihWbrnAPx3nuGBn33tM9SVUGBVjBB6uv1mGAPavwKCTU0xAD8qhw==}
|
resolution: {integrity: sha512-pa27KIsHIBvBMv4xz9uB3UCfAuP2tr7PLlFhCS9vw+aXd326LEHsvhqd3hCQDOR5MjlQVyQH6vwuGr3u+KRiiw==}
|
||||||
peerDependencies:
|
|
||||||
vite: '>=2.0.0'
|
|
||||||
dependencies:
|
|
||||||
'@vue/compiler-sfc': 3.2.31
|
|
||||||
magic-string: 0.25.9
|
|
||||||
vite: 2.9.9_sass@1.49.10
|
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/vite/2.9.9_sass@1.49.10:
|
/vite/2.9.9_sass@1.49.10:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { createSessionStorage } from '@/utils/cache'
|
import { sStorage } from '@/utils/cache'
|
||||||
|
|
||||||
export const tagsSS = createSessionStorage({ prefixKey: 'tag_' })
|
export const activeTag = sStorage.get('activeTag')
|
||||||
export const activeTag = tagsSS.get('activeTag')
|
export const tags = sStorage.get('tags')
|
||||||
export const tags = tagsSS.get('tags')
|
|
||||||
|
|
||||||
export const WITHOUT_TAG_PATHS = ['/404', '/login', '/redirect']
|
export const WITHOUT_TAG_PATHS = ['/404', '/login', '/redirect']
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { tagsSS, activeTag, tags, WITHOUT_TAG_PATHS } from './helpers'
|
import { activeTag, tags, WITHOUT_TAG_PATHS } from './helpers'
|
||||||
import { router } from '@/router'
|
import { router } from '@/router'
|
||||||
|
import { sStorage } from '@/utils/cache'
|
||||||
|
|
||||||
export const useTagsStore = defineStore('tag', {
|
export const useTagsStore = defineStore('tag', {
|
||||||
state() {
|
state() {
|
||||||
@ -12,11 +13,11 @@ export const useTagsStore = defineStore('tag', {
|
|||||||
actions: {
|
actions: {
|
||||||
setActiveTag(path) {
|
setActiveTag(path) {
|
||||||
this.activeTag = path
|
this.activeTag = path
|
||||||
tagsSS.set('activeTag', path)
|
sStorage.set('activeTag', path)
|
||||||
},
|
},
|
||||||
setTags(tags) {
|
setTags(tags) {
|
||||||
this.tags = tags
|
this.tags = tags
|
||||||
tagsSS.set('tags', tags)
|
sStorage.set('tags', tags)
|
||||||
},
|
},
|
||||||
addTag(tag = {}) {
|
addTag(tag = {}) {
|
||||||
this.setActiveTag(tag.path)
|
this.setActiveTag(tag.path)
|
||||||
|
12
src/utils/cache/index.js
vendored
12
src/utils/cache/index.js
vendored
@ -1,15 +1,21 @@
|
|||||||
import { createWebStorage } from './web-storage'
|
import { createStorage } from './storage'
|
||||||
|
|
||||||
|
const prefixKey = 'Vue_Naive_Admin_'
|
||||||
|
|
||||||
export const createLocalStorage = function (option = {}) {
|
export const createLocalStorage = function (option = {}) {
|
||||||
return createWebStorage({
|
return createStorage({
|
||||||
prefixKey: option.prefixKey || '',
|
prefixKey: option.prefixKey || '',
|
||||||
storage: localStorage,
|
storage: localStorage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createSessionStorage = function (option = {}) {
|
export const createSessionStorage = function (option = {}) {
|
||||||
return createWebStorage({
|
return createStorage({
|
||||||
prefixKey: option.prefixKey || '',
|
prefixKey: option.prefixKey || '',
|
||||||
storage: sessionStorage,
|
storage: sessionStorage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const lStorage = createLocalStorage({ prefixKey })
|
||||||
|
|
||||||
|
export const sStorage = createSessionStorage({ prefixKey })
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { isNullOrUndef } from '@/utils/is'
|
import { isNullOrUndef } from '@/utils/is'
|
||||||
|
|
||||||
class WebStorage {
|
class Storage {
|
||||||
constructor(option) {
|
constructor(option) {
|
||||||
this.storage = option.storage
|
this.storage = option.storage
|
||||||
this.prefixKey = option.prefixKey
|
this.prefixKey = option.prefixKey
|
||||||
@ -50,6 +50,6 @@ class WebStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createWebStorage({ prefixKey = '', storage = sessionStorage }) {
|
export function createStorage({ prefixKey = '', storage = sessionStorage }) {
|
||||||
return new WebStorage({ prefixKey, storage })
|
return new Storage({ prefixKey, storage })
|
||||||
}
|
}
|
@ -1,25 +1,23 @@
|
|||||||
import { createLocalStorage } from './cache'
|
import { lStorage } from './cache'
|
||||||
import { refreshToken } from '@/api/auth'
|
import { refreshToken } from '@/api/auth'
|
||||||
|
|
||||||
const TOKEN_CODE = 'access_token'
|
const TOKEN_CODE = 'access_token'
|
||||||
const DURATION = 6 * 60 * 60
|
const DURATION = 6 * 60 * 60
|
||||||
|
|
||||||
export const lsToken = createLocalStorage()
|
|
||||||
|
|
||||||
export function getToken() {
|
export function getToken() {
|
||||||
return lsToken.get(TOKEN_CODE)
|
return lStorage.get(TOKEN_CODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setToken(token) {
|
export function setToken(token) {
|
||||||
lsToken.set(TOKEN_CODE, token, DURATION)
|
lStorage.set(TOKEN_CODE, token, DURATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeToken() {
|
export function removeToken() {
|
||||||
lsToken.remove(TOKEN_CODE)
|
lStorage.remove(TOKEN_CODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function refreshAccessToken() {
|
export async function refreshAccessToken() {
|
||||||
const tokenItem = lsToken.getItem(TOKEN_CODE)
|
const tokenItem = lStorage.getItem(TOKEN_CODE)
|
||||||
if (!tokenItem) {
|
if (!tokenItem) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -10,28 +10,33 @@
|
|||||||
<icon-custom-logo mr30 text-50 />
|
<icon-custom-logo mr30 text-50 />
|
||||||
{{ title }}
|
{{ title }}
|
||||||
</h5>
|
</h5>
|
||||||
<div mt-35 w-full max-w-360>
|
<div mt-30 w-full max-w-360>
|
||||||
<n-input
|
<n-input
|
||||||
v-model:value="loginInfo.name"
|
v-model:value="loginInfo.name"
|
||||||
autofocus
|
autofocus
|
||||||
class="text-16 items-center h-50 pl-10"
|
class="text-16 items-center h-50 pl-10"
|
||||||
placeholder="请输入用户名"
|
placeholder="admin"
|
||||||
:maxlength="20"
|
:maxlength="20"
|
||||||
>
|
>
|
||||||
</n-input>
|
</n-input>
|
||||||
</div>
|
</div>
|
||||||
<div mt-35 w-full max-w-360>
|
<div mt-30 w-full max-w-360>
|
||||||
<n-input
|
<n-input
|
||||||
v-model:value="loginInfo.password"
|
v-model:value="loginInfo.password"
|
||||||
class="text-16 items-center h-50 pl-10"
|
class="text-16 items-center h-50 pl-10"
|
||||||
type="password"
|
type="password"
|
||||||
show-password-on="mousedown"
|
show-password-on="mousedown"
|
||||||
placeholder="密码"
|
placeholder="123456"
|
||||||
:maxlength="20"
|
:maxlength="20"
|
||||||
@keydown.enter="handleLogin"
|
@keydown.enter="handleLogin"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div mt-35 w-full max-w-360>
|
|
||||||
|
<div mt-20 w-full max-w-360>
|
||||||
|
<n-checkbox :checked="isRemember" label="记住我" :on-update:checked="(val) => (isRemember = val)" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div mt-20 w-full max-w-360>
|
||||||
<n-button w-full h-50 rounded-5 text-16 type="primary" @click="handleLogin">登录</n-button>
|
<n-button w-full h-50 rounded-5 text-16 type="primary" @click="handleLogin">登录</n-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -41,8 +46,9 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { login } from '@/api/auth'
|
import { login } from '@/api/auth'
|
||||||
import { createLocalStorage } from '@/utils/cache'
|
import { lStorage } from '@/utils/cache'
|
||||||
import { setToken } from '@/utils/token'
|
import { setToken } from '@/utils/token'
|
||||||
|
import { useStorage } from '@vueuse/core'
|
||||||
|
|
||||||
const title = import.meta.env.VITE_APP_TITLE
|
const title = import.meta.env.VITE_APP_TITLE
|
||||||
|
|
||||||
@ -50,17 +56,21 @@ const router = useRouter()
|
|||||||
const query = unref(router.currentRoute).query
|
const query = unref(router.currentRoute).query
|
||||||
|
|
||||||
const loginInfo = ref({
|
const loginInfo = ref({
|
||||||
name: 'admin',
|
name: '',
|
||||||
password: '123456',
|
password: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
const ls = createLocalStorage({ prefixKey: 'login_' })
|
initLoginInfo()
|
||||||
const lsLoginInfo = ls.get('loginInfo')
|
|
||||||
if (lsLoginInfo) {
|
function initLoginInfo() {
|
||||||
loginInfo.value.name = lsLoginInfo.name || ''
|
const localLoginInfo = lStorage.get('loginInfo')
|
||||||
loginInfo.value.password = lsLoginInfo.password || ''
|
if (localLoginInfo) {
|
||||||
|
loginInfo.value.name = localLoginInfo.name || ''
|
||||||
|
loginInfo.value.password = localLoginInfo.password || ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isRemember = useStorage('isRemember', false)
|
||||||
async function handleLogin() {
|
async function handleLogin() {
|
||||||
const { name, password } = loginInfo.value
|
const { name, password } = loginInfo.value
|
||||||
if (!name || !password) {
|
if (!name || !password) {
|
||||||
@ -72,9 +82,12 @@ async function handleLogin() {
|
|||||||
const res = await login({ name, password: password.toString() })
|
const res = await login({ name, password: password.toString() })
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
$message.success('登录成功')
|
$message.success('登录成功')
|
||||||
ls.set('loginInfo', { name, password })
|
|
||||||
setToken(res.data.token)
|
setToken(res.data.token)
|
||||||
|
if (isRemember.value) {
|
||||||
|
lStorage.set('loginInfo', { name, password })
|
||||||
|
} else {
|
||||||
|
lStorage.remove('loginInfo')
|
||||||
|
}
|
||||||
if (query.redirect) {
|
if (query.redirect) {
|
||||||
const path = query.redirect
|
const path = query.redirect
|
||||||
Reflect.deleteProperty(query, 'redirect')
|
Reflect.deleteProperty(query, 'redirect')
|
||||||
|
Loading…
Reference in New Issue
Block a user