完成验证码及登录功能

This commit is contained in:
橙子
2023-02-04 18:06:42 +08:00
parent cfd25b0a8d
commit b01d242cbc
276 changed files with 24201 additions and 22 deletions

View File

@@ -0,0 +1,46 @@
import Cookies from 'js-cookie'
const useAppStore = defineStore(
'app',
{
state: () => ({
sidebar: {
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
withoutAnimation: false,
hide: false
},
device: 'desktop',
size: Cookies.get('size') || 'default'
}),
actions: {
toggleSideBar(withoutAnimation) {
if (this.sidebar.hide) {
return false;
}
this.sidebar.opened = !this.sidebar.opened
this.sidebar.withoutAnimation = withoutAnimation
if (this.sidebar.opened) {
Cookies.set('sidebarStatus', 1)
} else {
Cookies.set('sidebarStatus', 0)
}
},
closeSideBar(withoutAnimation) {
Cookies.set('sidebarStatus', 0)
this.sidebar.opened = false
this.sidebar.withoutAnimation = withoutAnimation
},
toggleDevice(device) {
this.device = device
},
setSize(size) {
this.size = size;
Cookies.set('size', size)
},
toggleSideBarHide(status) {
this.sidebar.hide = status
}
}
})
export default useAppStore

View File

@@ -0,0 +1,57 @@
const useDictStore = defineStore(
'dict',
{
state: () => ({
dict: new Array()
}),
actions: {
// 获取字典
getDict(_key) {
if (_key == null && _key == "") {
return null;
}
try {
for (let i = 0; i < this.dict.length; i++) {
if (this.dict[i].key == _key) {
return this.dict[i].value;
}
}
} catch (e) {
return null;
}
},
// 设置字典
setDict(_key, value) {
if (_key !== null && _key !== "") {
this.dict.push({
key: _key,
value: value
});
}
},
// 删除字典
removeDict(_key) {
var bln = false;
try {
for (let i = 0; i < this.dict.length; i++) {
if (this.dict[i].key == _key) {
this.dict.splice(i, 1);
return true;
}
}
} catch (e) {
bln = false;
}
return bln;
},
// 清空字典
cleanDict() {
this.dict = new Array();
},
// 初始字典
initDict() {
}
}
})
export default useDictStore

View File

@@ -0,0 +1,454 @@
import auth from '@/plugins/auth'
import router, { constantRoutes, dynamicRoutes } from '@/router'
import { getRouters } from '@/api/menu'
import Layout from '@/layout/index'
import ParentView from '@/components/ParentView'
import InnerLink from '@/layout/components/InnerLink'
// 匹配views里面所有的.vue文件
const modules = import.meta.glob('./../../views/**/*.vue')
const usePermissionStore = defineStore(
'permission',
{
state: () => ({
routes: [],
addRoutes: [],
defaultRoutes: [],
topbarRouters: [],
sidebarRouters: []
}),
actions: {
setRoutes(routes) {
this.addRoutes = routes
this.routes = constantRoutes.concat(routes)
},
setDefaultRoutes(routes) {
this.defaultRoutes = constantRoutes.concat(routes)
},
setTopbarRoutes(routes) {
this.topbarRouters = routes
},
setSidebarRouters(routes) {
this.sidebarRouters = routes
},
generateRoutes(roles) {
return new Promise(resolve => {
// 向后端请求路由数据
getRouters().then(response => {
// const res=[
// {
// "name": "System",
// "path": "/system",
// "hidden": false,
// "redirect": "noRedirect",
// "component": "Layout",
// "alwaysShow": true,
// "meta": {
// "title": "系统管理",
// "icon": "system",
// "noCache": false,
// "link": null
// },
// "children": [
// {
// "name": "User",
// "path": "user",
// "hidden": false,
// "component": "system/user/index",
// "meta": {
// "title": "用户管理",
// "icon": "user",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Role",
// "path": "role",
// "hidden": false,
// "component": "system/role/index",
// "meta": {
// "title": "角色管理",
// "icon": "peoples",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Menu",
// "path": "menu",
// "hidden": false,
// "component": "system/menu/index",
// "meta": {
// "title": "菜单管理",
// "icon": "tree-table",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Dept",
// "path": "dept",
// "hidden": false,
// "component": "system/dept/index",
// "meta": {
// "title": "部门管理",
// "icon": "tree",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Post",
// "path": "post",
// "hidden": false,
// "component": "system/post/index",
// "meta": {
// "title": "岗位管理",
// "icon": "post",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Dict",
// "path": "dict",
// "hidden": false,
// "component": "system/dict/index",
// "meta": {
// "title": "字典管理",
// "icon": "dict",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Config",
// "path": "config",
// "hidden": false,
// "component": "system/config/index",
// "meta": {
// "title": "参数设置",
// "icon": "edit",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Notice",
// "path": "notice",
// "hidden": false,
// "component": "system/notice/index",
// "meta": {
// "title": "通知公告",
// "icon": "message",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Log",
// "path": "log",
// "hidden": false,
// "redirect": "noRedirect",
// "component": "ParentView",
// "alwaysShow": true,
// "meta": {
// "title": "日志管理",
// "icon": "log",
// "noCache": false,
// "link": null
// },
// "children": [
// {
// "name": "Operlog",
// "path": "operlog",
// "hidden": false,
// "component": "monitor/operlog/index",
// "meta": {
// "title": "操作日志",
// "icon": "form",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Logininfor",
// "path": "logininfor",
// "hidden": false,
// "component": "monitor/logininfor/index",
// "meta": {
// "title": "登录日志",
// "icon": "logininfor",
// "noCache": false,
// "link": null
// }
// }
// ]
// }
// ]
// },
// {
// "name": "Monitor",
// "path": "/monitor",
// "hidden": false,
// "redirect": "noRedirect",
// "component": "Layout",
// "alwaysShow": true,
// "meta": {
// "title": "系统监控",
// "icon": "monitor",
// "noCache": false,
// "link": null
// },
// "children": [
// {
// "name": "Online",
// "path": "online",
// "hidden": false,
// "component": "monitor/online/index",
// "meta": {
// "title": "在线用户",
// "icon": "online",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Job",
// "path": "job",
// "hidden": false,
// "component": "monitor/job/index",
// "meta": {
// "title": "定时任务",
// "icon": "job",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Druid",
// "path": "druid",
// "hidden": false,
// "component": "monitor/druid/index",
// "meta": {
// "title": "数据监控",
// "icon": "druid",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Server",
// "path": "server",
// "hidden": false,
// "component": "monitor/server/index",
// "meta": {
// "title": "服务监控",
// "icon": "server",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Cache",
// "path": "cache",
// "hidden": false,
// "component": "monitor/cache/index",
// "meta": {
// "title": "缓存监控",
// "icon": "redis",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "CacheList",
// "path": "cacheList",
// "hidden": false,
// "component": "monitor/cache/list",
// "meta": {
// "title": "缓存列表",
// "icon": "redis-list",
// "noCache": false,
// "link": null
// }
// }
// ]
// },
// {
// "name": "Tool",
// "path": "/tool",
// "hidden": false,
// "redirect": "noRedirect",
// "component": "Layout",
// "alwaysShow": true,
// "meta": {
// "title": "系统工具",
// "icon": "tool",
// "noCache": false,
// "link": null
// },
// "children": [
// {
// "name": "Build",
// "path": "build",
// "hidden": false,
// "component": "tool/build/index",
// "meta": {
// "title": "表单构建",
// "icon": "build",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Gen",
// "path": "gen",
// "hidden": false,
// "component": "tool/gen/index",
// "meta": {
// "title": "代码生成",
// "icon": "code",
// "noCache": false,
// "link": null
// }
// },
// {
// "name": "Swagger",
// "path": "swagger",
// "hidden": false,
// "component": "tool/swagger/index",
// "meta": {
// "title": "系统接口",
// "icon": "swagger",
// "noCache": false,
// "link": null
// }
// }
// ]
// },
// {
// "name": "Http://ruoyi.vip",
// "path": "http://ruoyi.vip",
// "hidden": false,
// "component": "Layout",
// "meta": {
// "title": "若依官网",
// "icon": "guide",
// "noCache": false,
// "link": "http://ruoyi.vip"
// }
// }
// ];
console.log(response.data,"response.data")
const res=response.data;
const sdata = JSON.parse(JSON.stringify(res))
const rdata = JSON.parse(JSON.stringify(res))
const defaultData = JSON.parse(JSON.stringify(res))
const sidebarRoutes = filterAsyncRouter(sdata)
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
const defaultRoutes = filterAsyncRouter(defaultData)
const asyncRoutes = filterDynamicRoutes(dynamicRoutes)
asyncRoutes.forEach(route => { router.addRoute(route) })
this.setRoutes(rewriteRoutes)
this.setSidebarRouters(constantRoutes.concat(sidebarRoutes))
this.setDefaultRoutes(sidebarRoutes)
this.setTopbarRoutes(defaultRoutes)
resolve(rewriteRoutes)
})
})
}
}
})
// 遍历后台传来的路由字符串,转换为组件对象
function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
return asyncRouterMap.filter(route => {
if (type && route.children) {
route.children = filterChildren(route.children)
}
if (route.component) {
// Layout ParentView 组件特殊处理
if (route.component === 'Layout') {
route.component = Layout
} else if (route.component === 'ParentView') {
route.component = ParentView
} else if (route.component === 'InnerLink') {
route.component = InnerLink
} else {
route.component = loadView(route.component)
}
}
if (route.children != null && route.children && route.children.length) {
route.children = filterAsyncRouter(route.children, route, type)
} else {
delete route['children']
delete route['redirect']
}
return true
})
}
function filterChildren(childrenMap, lastRouter = false) {
var children = []
childrenMap.forEach((el, index) => {
if (el.children && el.children.length) {
if (el.component === 'ParentView' && !lastRouter) {
el.children.forEach(c => {
c.path = el.path + '/' + c.path
if (c.children && c.children.length) {
children = children.concat(filterChildren(c.children, c))
return
}
children.push(c)
})
return
}
}
if (lastRouter) {
el.path = lastRouter.path + '/' + el.path
}
children = children.concat(el)
})
return children
}
// 动态路由遍历,验证是否具备权限
export function filterDynamicRoutes(routes) {
const res = []
routes.forEach(route => {
if (route.permissions) {
if (auth.hasPermiOr(route.permissions)) {
res.push(route)
}
} else if (route.roles) {
if (auth.hasRoleOr(route.roles)) {
res.push(route)
}
}
})
return res
}
export const loadView = (view) => {
let res;
for (const path in modules) {
const dir = path.split('views/')[1].split('.vue')[0];
if (dir === view) {
res = () => modules[path]();
}
}
return res;
}
export default usePermissionStore

View File

@@ -0,0 +1,38 @@
import defaultSettings from '@/settings'
import { useDynamicTitle } from '@/utils/dynamicTitle'
const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle } = defaultSettings
const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''
const useSettingsStore = defineStore(
'settings',
{
state: () => ({
title: '',
theme: storageSetting.theme || '#409EFF',
sideTheme: storageSetting.sideTheme || sideTheme,
showSettings: showSettings,
topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
tagsView: storageSetting.tagsView === undefined ? tagsView : storageSetting.tagsView,
fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader,
sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo,
dynamicTitle: storageSetting.dynamicTitle === undefined ? dynamicTitle : storageSetting.dynamicTitle
}),
actions: {
// 修改布局设置
changeSetting(data) {
const { key, value } = data
if (this.hasOwnProperty(key)) {
this[key] = value
}
},
// 设置网页标题
setTitle(title) {
this.title = title
useDynamicTitle();
}
}
})
export default useSettingsStore

View File

@@ -0,0 +1,20 @@
const socketStore = defineStore(
'socket',
{
state: () => ({
onlineNum: 1
}),
actions: {
// 获取在线总数
getOnlineNum() {
return this.onlineNum;
},
// 设置在线总数
setOnlineNum(value) {
this.onlineNum = value;
}
}
})
export default socketStore

View File

@@ -0,0 +1,182 @@
const useTagsViewStore = defineStore(
'tags-view',
{
state: () => ({
visitedViews: [],
cachedViews: [],
iframeViews: []
}),
actions: {
addView(view) {
this.addVisitedView(view)
this.addCachedView(view)
},
addIframeView(view) {
if (this.iframeViews.some(v => v.path === view.path)) return
this.iframeViews.push(
Object.assign({}, view, {
title: view.meta.title || 'no-name'
})
)
},
addVisitedView(view) {
if (this.visitedViews.some(v => v.path === view.path)) return
this.visitedViews.push(
Object.assign({}, view, {
title: view.meta.title || 'no-name'
})
)
},
addCachedView(view) {
if (this.cachedViews.includes(view.name)) return
if (!view.meta.noCache) {
this.cachedViews.push(view.name)
}
},
delView(view) {
return new Promise(resolve => {
this.delVisitedView(view)
this.delCachedView(view)
resolve({
visitedViews: [...this.visitedViews],
cachedViews: [...this.cachedViews]
})
})
},
delVisitedView(view) {
return new Promise(resolve => {
for (const [i, v] of this.visitedViews.entries()) {
if (v.path === view.path) {
this.visitedViews.splice(i, 1)
break
}
}
this.iframeViews = this.iframeViews.filter(item => item.path !== view.path)
resolve([...this.visitedViews])
})
},
delIframeView(view) {
return new Promise(resolve => {
this.iframeViews = this.iframeViews.filter(item => item.path !== view.path)
resolve([...this.iframeViews])
})
},
delCachedView(view) {
return new Promise(resolve => {
const index = this.cachedViews.indexOf(view.name)
index > -1 && this.cachedViews.splice(index, 1)
resolve([...this.cachedViews])
})
},
delOthersViews(view) {
return new Promise(resolve => {
this.delOthersVisitedViews(view)
this.delOthersCachedViews(view)
resolve({
visitedViews: [...this.visitedViews],
cachedViews: [...this.cachedViews]
})
})
},
delOthersVisitedViews(view) {
return new Promise(resolve => {
this.visitedViews = this.visitedViews.filter(v => {
return v.meta.affix || v.path === view.path
})
this.iframeViews = this.iframeViews.filter(item => item.path === view.path)
resolve([...this.visitedViews])
})
},
delOthersCachedViews(view) {
return new Promise(resolve => {
const index = this.cachedViews.indexOf(view.name)
if (index > -1) {
this.cachedViews = this.cachedViews.slice(index, index + 1)
} else {
this.cachedViews = []
}
resolve([...this.cachedViews])
})
},
delAllViews(view) {
return new Promise(resolve => {
this.delAllVisitedViews(view)
this.delAllCachedViews(view)
resolve({
visitedViews: [...this.visitedViews],
cachedViews: [...this.cachedViews]
})
})
},
delAllVisitedViews(view) {
return new Promise(resolve => {
const affixTags = this.visitedViews.filter(tag => tag.meta.affix)
this.visitedViews = affixTags
this.iframeViews = []
resolve([...this.visitedViews])
})
},
delAllCachedViews(view) {
return new Promise(resolve => {
this.cachedViews = []
resolve([...this.cachedViews])
})
},
updateVisitedView(view) {
for (let v of this.visitedViews) {
if (v.path === view.path) {
v = Object.assign(v, view)
break
}
}
},
delRightTags(view) {
return new Promise(resolve => {
const index = this.visitedViews.findIndex(v => v.path === view.path)
if (index === -1) {
return
}
this.visitedViews = this.visitedViews.filter((item, idx) => {
if (idx <= index || (item.meta && item.meta.affix)) {
return true
}
const i = this.cachedViews.indexOf(item.name)
if (i > -1) {
this.cachedViews.splice(i, 1)
}
if(item.meta.link) {
const fi = this.iframeViews.findIndex(v => v.path === item.path)
this.iframeViews.splice(fi, 1)
}
return false
})
resolve([...this.visitedViews])
})
},
delLeftTags(view) {
return new Promise(resolve => {
const index = this.visitedViews.findIndex(v => v.path === view.path)
if (index === -1) {
return
}
this.visitedViews = this.visitedViews.filter((item, idx) => {
if (idx >= index || (item.meta && item.meta.affix)) {
return true
}
const i = this.cachedViews.indexOf(item.name)
if (i > -1) {
this.cachedViews.splice(i, 1)
}
if(item.meta.link) {
const fi = this.iframeViews.findIndex(v => v.path === item.path)
this.iframeViews.splice(fi, 1)
}
return false
})
resolve([...this.visitedViews])
})
}
}
})
export default useTagsViewStore

View File

@@ -0,0 +1,80 @@
import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import defAva from '@/assets/images/profile.jpg'
const useUserStore = defineStore(
'user',
{
state: () => ({
token: getToken(),
name: '',
avatar: '',
roles: [],
permissions: []
}),
actions: {
// 登录
login(userInfo) {
const username = userInfo.username.trim()
const password = userInfo.password
const code = userInfo.code
const uuid = userInfo.uuid
return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => {
setToken(res.data.token);
this.token = res.data.token;
resolve();
}).catch(error => {
reject(error)
})
})
},
// 获取用户信息
getInfo() {
return new Promise((resolve, reject) => {
getInfo().then(response => {
const res=response.data;
const user = res.user
const avatar = (user.icon == "" || user.icon == null) ? defAva : import.meta.env.VITE_APP_BASE_API + "/file/"+user.icon;
if (res.roleCodes && res.roleCodes.length > 0) { // 验证返回的roles是否是一个非空数组
this.roles = res.roleCodes
this.permissions = res.permissionCodes
// this.roles = ["admin"];
// this.permissions=["*:*:*"]
} else {
this.roles = ['ROLE_DEFAULT']
}
// this.roles = ["admin"];
// this.permissions=["*:*:*"]
this.name = user.userName
this.avatar = avatar;
resolve(res)
}).catch(error => {
reject(error)
})
})
},
// 退出系统
logOut() {
return new Promise((resolve, reject) => {
logout(this.token).then(() => {
this.token = ''
this.roles = []
this.permissions = []
removeToken()
resolve()
}).catch(error => {
reject(error)
})
})
}
}
})
export default useUserStore