refactor: folders

This commit is contained in:
张传龙 2022-09-18 20:05:40 +08:00
parent bdbe9b8483
commit 6664ae8f7b
45 changed files with 138 additions and 139 deletions

View File

@ -1,4 +1,4 @@
import request from '@/utils/http' import { request } from '@/utils'
export default { export default {
getUser: () => request.get('/user'), getUser: () => request.get('/user'),

View File

@ -18,7 +18,7 @@ import { defineComponent, h } from 'vue'
import { useLoadingBar, useDialog, useMessage, useNotification } from 'naive-ui' import { useLoadingBar, useDialog, useMessage, useNotification } from 'naive-ui'
import { useCssVar } from '@vueuse/core' import { useCssVar } from '@vueuse/core'
import { kebabCase } from 'lodash-es' import { kebabCase } from 'lodash-es'
import { setupMessage, setupDialog } from '@/utils/common/naiveTools' import { setupMessage, setupDialog } from '@/utils'
import { naiveThemeOverrides } from '~/settings' import { naiveThemeOverrides } from '~/settings'
function setupCssVar() { function setupCssVar() {

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { renderIcon, renderCustomIcon } from '@/utils/icon' import { renderIcon, renderCustomIcon } from '@/utils'
const props = defineProps({ const props = defineProps({
icon: { icon: {

View File

@ -10,7 +10,7 @@
</template> </template>
<script setup> <script setup>
import { isNullOrWhitespace } from '@/utils/is' import { isNullOrWhitespace } from '@/utils'
defineProps({ defineProps({
label: { label: {

View File

@ -1,4 +1,4 @@
import { isNullOrWhitespace } from '@/utils/is' import { isNullOrWhitespace } from '@/utils'
const ACTIONS = { const ACTIONS = {
view: '查看', view: '查看',

View File

@ -7,7 +7,7 @@
</template> </template>
<script setup> <script setup>
import { useAppStore } from '@/store/modules/app' import { useAppStore } from '@/store'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
const appStore = useAppStore() const appStore = useAppStore()
const router = useRouter() const router = useRouter()

View File

@ -12,7 +12,7 @@
</template> </template>
<script setup> <script setup>
import { renderCustomIcon, renderIcon } from '@/utils/icon' import { renderCustomIcon, renderIcon } from '@/utils'
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()

View File

@ -6,7 +6,7 @@
</template> </template>
<script setup> <script setup>
import { useAppStore } from '@/store/modules/app' import { useAppStore } from '@/store'
const appStore = useAppStore() const appStore = useAppStore()
</script> </script>

View File

@ -8,8 +8,8 @@
</template> </template>
<script setup> <script setup>
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store'
import { renderIcon } from '@/utils/icon' import { renderIcon } from '@/utils'
const userStore = useUserStore() const userStore = useUserStore()

View File

@ -8,7 +8,7 @@
</template> </template>
<script setup> <script setup>
import { useAppStore } from '@/store/modules/app' import { useAppStore } from '@/store'
const title = import.meta.env.VITE_TITLE const title = import.meta.env.VITE_TITLE
const appStore = useAppStore() const appStore = useAppStore()

View File

@ -12,11 +12,8 @@
</template> </template>
<script setup> <script setup>
import { usePermissionStore } from '@/store/modules/permission' import { usePermissionStore, useAppStore } from '@/store'
import { renderCustomIcon, renderIcon, isExternal } from '@/utils'
import { isExternal } from '@/utils/is'
import { useAppStore } from '@/store/modules/app'
import { renderCustomIcon, renderIcon } from '@/utils/icon'
const router = useRouter() const router = useRouter()
const curRoute = useRoute() const curRoute = useRoute()

View File

@ -11,9 +11,8 @@
</template> </template>
<script setup> <script setup>
import { useTagsStore } from '@/store/modules/tags' import { useTagsStore, useAppStore } from '@/store'
import { renderIcon } from '@/utils/icon' import { renderIcon } from '@/utils'
import { useAppStore } from '@/store/modules/app'
const props = defineProps({ const props = defineProps({
show: { show: {

View File

@ -24,7 +24,7 @@
<script setup> <script setup>
import ContextMenu from './ContextMenu.vue' import ContextMenu from './ContextMenu.vue'
import { useTagsStore } from '@/store/modules/tags' import { useTagsStore } from '@/store'
import ScrollX from '@/components/common/ScrollX.vue' import ScrollX from '@/components/common/ScrollX.vue'
const route = useRoute() const route = useRoute()

View File

@ -30,7 +30,7 @@ import AppHeader from './components/header/index.vue'
import SideBar from './components/sidebar/index.vue' import SideBar from './components/sidebar/index.vue'
import AppMain from './components/AppMain.vue' import AppMain from './components/AppMain.vue'
import AppTags from './components/tags/index.vue' import AppTags from './components/tags/index.vue'
import { useAppStore } from '@/store/modules/app' import { useAppStore } from '@/store'
import { header, tags } from '~/settings' import { header, tags } from '~/settings'
const appStore = useAppStore() const appStore = useAppStore()

View File

@ -1,6 +1,7 @@
/** 重置样式 */
import '@/styles/reset.css' import '@/styles/reset.css'
import '@/styles/index.scss'
import 'uno.css' import 'uno.css'
import '@/styles/global.scss'
import 'virtual:svg-icons-register' import 'virtual:svg-icons-register'
import { createApp } from 'vue' import { createApp } from 'vue'

View File

@ -1,5 +1,4 @@
import { getToken, refreshAccessToken } from '@/utils/token' import { getToken, refreshAccessToken, isNullOrWhitespace } from '@/utils'
import { isNullOrWhitespace } from '@/utils/is'
const WHITE_LIST = ['/login', '/404'] const WHITE_LIST = ['/login', '/404']
export function createPermissionGuard(router) { export function createPermissionGuard(router) {

View File

@ -1,10 +1,8 @@
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router' import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import { setupRouterGuard } from './guard' import { setupRouterGuard } from './guard'
import { basicRoutes as routes, EMPTY_ROUTE, NOT_FOUND_ROUTE } from './routes' import { basicRoutes as routes, EMPTY_ROUTE, NOT_FOUND_ROUTE } from './routes'
import { getToken } from '@/utils/token' import { getToken, isNullOrWhitespace } from '@/utils'
import { isNullOrWhitespace } from '@/utils/is' import { useUserStore, usePermissionStore } from '@/store'
import { useUserStore } from '@/store/modules/user'
import { usePermissionStore } from '@/store/modules/permission'
const isHash = import.meta.env.VITE_USE_HASH === 'true' const isHash = import.meta.env.VITE_USE_HASH === 'true'
export const router = createRouter({ export const router = createRouter({

View File

@ -3,3 +3,5 @@ import { createPinia } from 'pinia'
export function setupStore(app) { export function setupStore(app) {
app.use(createPinia()) app.use(createPinia())
} }
export * from './modules'

View File

@ -0,0 +1,4 @@
export * from './app'
export * from './permission'
export * from './tags'
export * from './user'

View File

@ -1,4 +1,4 @@
import { sStorage } from '@/utils/cache' import { sStorage } from '@/utils'
export const activeTag = sStorage.get('activeTag') export const activeTag = sStorage.get('activeTag')
export const tags = sStorage.get('tags') export const tags = sStorage.get('tags')

View File

@ -1,7 +1,7 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { 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' import { sStorage } from '@/utils'
export const useTagsStore = defineStore('tag', { export const useTagsStore = defineStore('tag', {
state() { state() {

View File

@ -1,6 +1,5 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { removeToken } from '@/utils/token' import { removeToken, toLogin } from '@/utils'
import { toLogin } from '@/utils/auth'
import api from '@/api' import api from '@/api'
export const useUserStore = defineStore('user', { export const useUserStore = defineStore('user', {

View File

@ -1,14 +1,16 @@
html {
font-size: 4px; // * 1rem = 4px 方便unocss计算在unocss中 1字体单位 = 0.25rem相当于 1等份 = 1px
}
html, html,
body { body {
width: 100%; width: 100%;
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
background-color: #f2f2f2; }
font-family: 'Encode Sans Condensed', sans-serif;
html {
font-size: 4px; // * 1rem = 4px 方便unocss计算在unocss中 1字体单位 = 0.25rem相当于 1等份 = 1px
}
body {
font-size: 16px;
} }
#app { #app {
@ -16,7 +18,7 @@ body {
height: 100%; height: 100%;
} }
/* router view transition fade-slide */ /* transition fade-slide */
.fade-slide-leave-active, .fade-slide-leave-active,
.fade-slide-enter-active { .fade-slide-enter-active {
transition: all 0.3s; transition: all 0.3s;
@ -32,7 +34,6 @@ body {
transform: translateX(30px); transform: translateX(30px);
} }
/* 自定义滚动条样式 */
/* 自定义滚动条样式 */ /* 自定义滚动条样式 */
.cus-scroll { .cus-scroll {
overflow: auto; overflow: auto;

View File

@ -33,8 +33,3 @@ textarea {
border: none; border: none;
resize: none; resize: none;
} }
body {
font-size: 14px;
font-weight: 400;
}

2
src/utils/auth/index.js Normal file
View File

@ -0,0 +1,2 @@
export * from './auth'
export * from './token'

View File

@ -1,4 +1,4 @@
import { lStorage } from './cache' import { lStorage } from '@/utils'
import api from '@/api' import api from '@/api'
const TOKEN_CODE = 'access_token' const TOKEN_CODE = 'access_token'

View File

@ -0,0 +1,76 @@
import dayjs from 'dayjs'
/**
* @desc 格式化时间
* @param {(Object|string|number)} time
* @param {string} format
* @returns {string | null}
*/
export function formatDateTime(time = undefined, format = 'YYYY-MM-DD HH:mm:ss') {
return dayjs(time).format(format)
}
export function formatDate(date = undefined, format = 'YYYY-MM-DD') {
return formatDateTime(date, format)
}
/**
* @desc 函数节流
* @param {Function} fn
* @param {Number} wait
* @returns {Function}
*/
export function throttle(fn, wait) {
var context, args
var previous = 0
return function () {
var now = +new Date()
context = this
args = arguments
if (now - previous > wait) {
fn.apply(context, args)
previous = now
}
}
}
/**
* @desc 函数防抖
* @param {Function} func
* @param {number} wait
* @param {boolean} immediate
* @return {*}
*/
export function debounce(method, wait, immediate) {
let timeout
return function (...args) {
let context = this
if (timeout) {
clearTimeout(timeout)
}
// 立即执行需要两个条件一是immediate为true二是timeout未被赋值或被置为null
if (immediate) {
/**
* 如果定时器不存在则立即执行并设置一个定时器wait毫秒后将定时器置为null
* 这样确保立即执行后wait毫秒内不会被再次触发
*/
let callNow = !timeout
timeout = setTimeout(() => {
timeout = null
}, wait)
if (callNow) {
method.apply(context, args)
}
} else {
// 如果immediate为false则函数wait毫秒后执行
timeout = setTimeout(() => {
/**
* args是一个类数组对象所以使用fn.apply
* 也可写作method.call(context, ...args)
*/
method.apply(context, args)
}, wait)
}
}
}

View File

@ -0,0 +1,4 @@
export * from './common'
export * from './is'
export * from './icon'
export * from './naiveTools'

View File

@ -1,4 +1,4 @@
import { isNullOrUndef } from '@/utils/is' import { isNullOrUndef } from '@/utils'
export function setupMessage(NMessage) { export function setupMessage(NMessage) {
let loadingMessage = null let loadingMessage = null

View File

@ -1,7 +1,5 @@
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store'
import { isNullOrUndef } from '@/utils/is' import { isNullOrUndef, removeToken, toLogin } from '@/utils'
import { removeToken } from '@/utils/token'
import { toLogin } from '@/utils/auth'
export function addBaseParams(params) { export function addBaseParams(params) {
if (!params.userId) { if (!params.userId) {

View File

@ -14,6 +14,6 @@ export function createAxios(options = {}) {
return service return service
} }
export default createAxios({ export const request = createAxios({
baseURL: import.meta.env.VITE_BASE_API, baseURL: import.meta.env.VITE_BASE_API,
}) })

View File

@ -1,5 +1,4 @@
import { getToken } from '@/utils/token' import { getToken, toLogin } from '@/utils'
import { toLogin } from '@/utils/auth'
import { resolveResError } from './helpers' import { resolveResError } from './helpers'
export function reqResolve(config) { export function reqResolve(config) {

View File

@ -1,76 +1,4 @@
import dayjs from 'dayjs' export * from './common'
export * from './storage'
/** export * from './http'
* @desc 格式化时间 export * from './auth'
* @param {(Object|string|number)} time
* @param {string} format
* @returns {string | null}
*/
export function formatDateTime(time = undefined, format = 'YYYY-MM-DD HH:mm:ss') {
return dayjs(time).format(format)
}
export function formatDate(date = undefined, format = 'YYYY-MM-DD') {
return formatDateTime(date, format)
}
/**
* @desc 函数节流
* @param {Function} fn
* @param {Number} wait
* @returns {Function}
*/
export function throttle(fn, wait) {
var context, args
var previous = 0
return function () {
var now = +new Date()
context = this
args = arguments
if (now - previous > wait) {
fn.apply(context, args)
previous = now
}
}
}
/**
* @desc 函数防抖
* @param {Function} func
* @param {number} wait
* @param {boolean} immediate
* @return {*}
*/
export function debounce(method, wait, immediate) {
let timeout
return function (...args) {
let context = this
if (timeout) {
clearTimeout(timeout)
}
// 立即执行需要两个条件一是immediate为true二是timeout未被赋值或被置为null
if (immediate) {
/**
* 如果定时器不存在则立即执行并设置一个定时器wait毫秒后将定时器置为null
* 这样确保立即执行后wait毫秒内不会被再次触发
*/
let callNow = !timeout
timeout = setTimeout(() => {
timeout = null
}, wait)
if (callNow) {
method.apply(context, args)
}
} else {
// 如果immediate为false则函数wait毫秒后执行
timeout = setTimeout(() => {
/**
* args是一个类数组对象所以使用fn.apply
* 也可写作method.call(context, ...args)
*/
method.apply(context, args)
}, wait)
}
}
}

View File

@ -1,4 +1,4 @@
import { isNullOrUndef } from '@/utils/is' import { isNullOrUndef } from '@/utils'
class Storage { class Storage {
constructor(option) { constructor(option) {

View File

@ -1,4 +1,4 @@
import request from '@/utils/http' import { request } from '@/utils'
export default { export default {
getPosts: (params = {}) => request.get('posts', { params }), getPosts: (params = {}) => request.get('posts', { params }),

View File

@ -82,11 +82,9 @@
<script setup> <script setup>
import { NButton, NSwitch } from 'naive-ui' import { NButton, NSwitch } from 'naive-ui'
import { formatDateTime } from '@/utils' import { formatDateTime, renderIcon, isNullOrUndef } from '@/utils'
import { renderIcon } from '@/utils/icon'
import { useCRUD } from '@/composables' import { useCRUD } from '@/composables'
import api from './api' import api from './api'
import { isNullOrUndef } from '@/utils/is'
defineOptions({ name: 'CrudTable' }) defineOptions({ name: 'CrudTable' })

View File

@ -1,4 +1,4 @@
import request from '@/utils/http' import { request } from '@/utils'
export default { export default {
login: (data) => request.post('/auth/login', data, { noNeedToken: true }), login: (data) => request.post('/auth/login', data, { noNeedToken: true }),

View File

@ -46,8 +46,7 @@
</template> </template>
<script setup> <script setup>
import { lStorage } from '@/utils/cache' import { lStorage, setToken } from '@/utils'
import { setToken } from '@/utils/token'
import { useStorage } from '@vueuse/core' import { useStorage } from '@vueuse/core'
import bgImg from '@/assets/images/login_bg.webp' import bgImg from '@/assets/images/login_bg.webp'
import api from './api' import api from './api'

View File

@ -52,7 +52,7 @@
</template> </template>
<script setup> <script setup>
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store'
const userStore = useUserStore() const userStore = useUserStore()
</script> </script>