From d67c03dd84be6c9c40b2cca12f12d7ef191f590c Mon Sep 17 00:00:00 2001
From: zhangtao <1176193409@qq.com>
Date: Tue, 24 May 2022 09:09:30 +0800
Subject: [PATCH 1/2] mune change
---
.env.localhost | 2 +-
mock/system/router.js | 6 +-
src/api/login/index.js | 2 +-
src/api/system/index.js | 2 +-
src/components/DataTable/index.vue | 5 +-
.../DataTable/tools/useDataSource.js | 16 ++++-
src/components/Dialog/index.vue | 48 +------------
src/components/Modal/index.vue | 61 ++++++++++++++++
src/components/Search/index.vue | 71 +++++++++++++------
src/layout/components/Menu/index.vue | 10 +--
src/layout/components/Tags/index.vue | 6 +-
src/router/routes/index.js | 12 ++--
src/store/modules/permission.js | 31 +++++---
src/views/login/index.vue | 4 +-
.../system/menu/components/RoleModal.vue | 50 +++++++++++++
src/views/system/menu/index.vue | 15 ++--
src/views/system/role/index.vue | 20 ++++--
src/views/system/role/info.js | 33 +++++----
18 files changed, 272 insertions(+), 122 deletions(-)
create mode 100644 src/components/Modal/index.vue
create mode 100644 src/views/system/menu/components/RoleModal.vue
diff --git a/.env.localhost b/.env.localhost
index 1104cf0..b919d0f 100644
--- a/.env.localhost
+++ b/.env.localhost
@@ -2,7 +2,7 @@
VITE_PUBLIC_PATH = '/'
# 是否启用MOCK
-VITE_APP_USE_MOCK = true
+VITE_APP_USE_MOCK = false
# proxy
VITE_PROXY = [["/api-local","http://127.0.0.1:8002/api"],["/api-mock","http://127.0.0.1:8003"]]
diff --git a/mock/system/router.js b/mock/system/router.js
index feafafa..4ea86ec 100644
--- a/mock/system/router.js
+++ b/mock/system/router.js
@@ -3,7 +3,7 @@ const asyncRoutes = [
path: '/system',
component: 'Layout',
redirect: '/system/menu',
- name: 'System',
+ title: 'System',
meta: {
title: '系统管理'
},
@@ -11,7 +11,7 @@ const asyncRoutes = [
{
path: 'menu',
component: 'views/system/menu/index',
- name: 'SystemMenu',
+ title: 'SystemMenu',
meta: {
title: '菜单管理'
}
@@ -19,7 +19,7 @@ const asyncRoutes = [
{
path: 'user',
component: 'views/system/user/index',
- name: 'SystemUser',
+ title: 'SystemUser',
meta: {
title: '用户管理'
}
diff --git a/src/api/login/index.js b/src/api/login/index.js
index bbfa1bd..9e49e6e 100644
--- a/src/api/login/index.js
+++ b/src/api/login/index.js
@@ -1,4 +1,4 @@
-import { mockAxios as request } from '@/utils/http'
+import { defAxios as request } from '@/utils/http'
export function userLogin(data = {}) {
return request({
diff --git a/src/api/system/index.js b/src/api/system/index.js
index e0e5943..453f6c7 100644
--- a/src/api/system/index.js
+++ b/src/api/system/index.js
@@ -1,4 +1,4 @@
-import { mockAxios as request } from '@/utils/http'
+import { defAxios as request } from '@/utils/http'
export function getMenu() {
return request({
diff --git a/src/components/DataTable/index.vue b/src/components/DataTable/index.vue
index 9632329..b9c31d1 100644
--- a/src/components/DataTable/index.vue
+++ b/src/components/DataTable/index.vue
@@ -76,7 +76,7 @@ export default {
/* tableData-start */
const tableData = ref([])
- const { getDataSourceRef, getRowKey, reload } = useDataSource(getProps, { getPaginationInfo, setPagination, tableData, setLoading }, emit)
+ const { getDataSourceRef, getRowKey, reload, reFetch } = useDataSource(getProps, { getPaginationInfo, setPagination, tableData, setLoading }, emit)
const isRequest = !!unref(getProps).request
const getBindProps = computed(() => {
return {
@@ -97,7 +97,8 @@ export default {
pagination,
updatePage,
updatePageSize,
- reload
+ reload,
+ reFetch
}
}
}
diff --git a/src/components/DataTable/tools/useDataSource.js b/src/components/DataTable/tools/useDataSource.js
index 9df01d8..fad04b9 100644
--- a/src/components/DataTable/tools/useDataSource.js
+++ b/src/components/DataTable/tools/useDataSource.js
@@ -99,6 +99,19 @@ export function useDataSource(propsRef, { getPaginationInfo, setPagination, setL
await fetch(opt)
}
+ async function reFetch(opt) {
+ console.log('opt', opt)
+ const { paginationSetting } = unref(propsRef)
+ const pageField = paginationSetting.pageField
+ const sizeField = paginationSetting.sizeField
+ const pageSize = paginationSetting.pageSize
+ setPagination({
+ [pageField]: 1,
+ [sizeField]: pageSize
+ })
+ await fetch(opt)
+ }
+
onMounted(() => {
setTimeout(() => {
fetch()
@@ -111,6 +124,7 @@ export function useDataSource(propsRef, { getPaginationInfo, setPagination, setL
getDataSource,
setTableData,
getRowKey,
- reload
+ reload,
+ reFetch
}
}
diff --git a/src/components/Dialog/index.vue b/src/components/Dialog/index.vue
index c1422b1..2d527fe 100644
--- a/src/components/Dialog/index.vue
+++ b/src/components/Dialog/index.vue
@@ -1,52 +1,6 @@
diff --git a/src/components/Modal/index.vue b/src/components/Modal/index.vue
new file mode 100644
index 0000000..14be664
--- /dev/null
+++ b/src/components/Modal/index.vue
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/Search/index.vue b/src/components/Search/index.vue
index 276f9cf..8d785eb 100644
--- a/src/components/Search/index.vue
+++ b/src/components/Search/index.vue
@@ -2,13 +2,25 @@
-
-
+
+
-
-
+
+
+
+
+
+
+ 查询
+ 重置
+ {{ showItemNum === getFormOptions.info.length - 1 ? '收起' : '展开' }}
+
@@ -25,36 +37,49 @@ export default {
default: () => []
}
},
+ emits: ['search'],
setup(props, { emit }) {
- // const formOption = reactive({
- // form: {
-
- // }
- // })
- const getFormRef = computed(() => {
- const { info } = unref(props)
- const form = ref({})
- info.forEach((item) => {
+ const showItemNum = ref(3)
+ const len = ref(props.info.length - 1)
+ const showButton = ref(!!(showItemNum.value < len.value))
+ /* 获取传递的props */
+ const data = reactive({
+ info: toRaw(props.info)
+ })
+ const form = ref({})
+ /* 初始化搜索表单信息 */
+ function initForm() {
+ data.info.forEach((item) => {
form.value[item.key] = ''
})
- return unref(form)
- })
- console.log(getFormRef)
+ }
+
const getFormOptions = computed(() => {
return {
- form: unref(getFormRef),
+ form: unref(form),
labelWidth: 'auto',
labelPlacement: 'left',
inline: true,
info: [...unref(props).info]
}
})
- function getFormInfo() {
- console.log(getFormOptions)
+ function handleSearch() {
+ emit('search', getFormOptions.value.form)
+ }
+ function handleReset() {
+ initForm()
+ emit('search', getFormOptions.value.form)
+ }
+ function showMoreItem() {
+ showItemNum.value = showItemNum.value === len.value ? 3 : len.value
}
return {
+ showItemNum,
+ showButton,
getFormOptions,
- getFormInfo
+ handleSearch,
+ handleReset,
+ showMoreItem
}
}
}
@@ -71,5 +96,11 @@ export default {
.n-select{
width: 200px;
}
+ transition: all 10s;
+}
+.form__button{
+ button+button{
+ margin-left: 20px;
+ }
}
diff --git a/src/layout/components/Menu/index.vue b/src/layout/components/Menu/index.vue
index ca193ce..70a7e45 100644
--- a/src/layout/components/Menu/index.vue
+++ b/src/layout/components/Menu/index.vue
@@ -1,7 +1,7 @@
@@ -29,6 +29,8 @@ const getMenuOptions = computed(() => {
return generateOptions(permissionStore.routes, '')
})
+console.log('getMenuOptions', getMenuOptions)
+
function resolvePath(basePath, path) {
if (isExternal(path)) return path
return (
@@ -43,10 +45,10 @@ function resolvePath(basePath, path) {
function generateOptions(routes, basePath) {
const options = []
routes.forEach((route) => {
- if (route.name && !route.isHidden) {
+ if (route.title && !route.isHidden) {
const curOption = {
- label: (route.meta && route.meta.title) || route.name,
- key: route.name,
+ label: (route.meta && route.meta.title) || route.title,
+ key: route.title,
path: resolvePath(basePath, route.path)
}
if (route.children && route.children.length) {
diff --git a/src/layout/components/Tags/index.vue b/src/layout/components/Tags/index.vue
index e5b9bb2..2d794d9 100644
--- a/src/layout/components/Tags/index.vue
+++ b/src/layout/components/Tags/index.vue
@@ -132,7 +132,7 @@ cacheRoutes.forEach((cacheRoute) => {
const findRoute = routes.find((route) => route.path === cacheRoute.path)
if (route) {
cacheRoute.meta = findRoute.meta || cacheRoute.meta
- cacheRoute.name = (findRoute.name || cacheRoute.name)
+ cacheRoute.title = (findRoute.title || cacheRoute.title)
}
})
@@ -163,8 +163,8 @@ watch(
* @return { Object }
*/
function getSimpleRoute(route) {
- const { fullPath, hash, meta, name, params, path, query } = route
- return { fullPath, hash, meta, name, params, path, query }
+ const { fullPath, hash, meta, title, params, path, query } = route
+ return { fullPath, hash, meta, title, params, path, query }
}
/**
diff --git a/src/router/routes/index.js b/src/router/routes/index.js
index 8b716be..bbf3be0 100644
--- a/src/router/routes/index.js
+++ b/src/router/routes/index.js
@@ -4,7 +4,7 @@ import Home from '@/views/dashboard/index.vue'
export const basicRoutes = [
{
path: '/login',
- name: 'Login',
+ title: 'Login',
component: () => import('@/views/login/index.vue'),
isHidden: true,
meta: {
@@ -13,16 +13,16 @@ export const basicRoutes = [
},
{
path: '/',
- name: 'Dashboard',
+ title: '控制台',
component: Layout,
redirect: '/home',
meta: {
- title: 'Dashboard'
+ title: '控制台'
},
children: [
{
path: 'home',
- name: 'Home',
+ title: 'Home',
component: Home,
meta: {
title: '首页',
@@ -34,7 +34,7 @@ export const basicRoutes = [
]
export const NOT_FOUND_ROUTE = {
- name: 'NOT_FOUND',
+ title: 'NOT_FOUND',
path: '/:pathMatch(.*)*',
redirect: '/404',
isHidden: true
@@ -42,7 +42,7 @@ export const NOT_FOUND_ROUTE = {
export const REDIRECT_ROUTE = {
path: '/redirect',
- name: 'Redirect',
+ title: 'Redirect',
component: Layout,
meta: {
title: 'Redirect',
diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index 2d0fa06..9bcf93c 100644
--- a/src/store/modules/permission.js
+++ b/src/store/modules/permission.js
@@ -53,19 +53,31 @@ function dataArrayToRoutes(routes) {
const res = []
routes.forEach(item => {
const tmp = { ...item }
- // 如果有component配置
- if (tmp.component) {
+ // // 如果有component配置
+ // if (tmp.component) {
+ // // Layout引入
+ // if (tmp.component === 'Layout') {
+ // tmp.component = Layout
+ // } else {
+ // const sub_view = tmp.component.replace(/^\/*/g, '')
+ // const component = `../${sub_view}.vue`
+ // tmp.component = modules[component]
+ // }
+ // if (tmp.children) {
+ // tmp.children = dataArrayToRoutes(tmp.children)
+ // }
+ // }
+ // 如果pid为0
+ if (tmp.pid === 0) {
// Layout引入
- if (tmp.component === 'Layout') {
- tmp.component = Layout
- } else {
- const sub_view = tmp.component.replace(/^\/*/g, '')
- const component = `../${sub_view}.vue`
- tmp.component = modules[component]
- }
+ tmp.component = Layout
if (tmp.children) {
tmp.children = dataArrayToRoutes(tmp.children)
}
+ } else {
+ const sub_view = tmp.component.replace(/^\/*/g, '')
+ const component = `../${sub_view}.vue`
+ tmp.component = modules[component]
}
res.push(tmp)
})
@@ -97,6 +109,7 @@ export const usePermissionStore = defineStore('permission', {
const res = await getMenu()
if (res.code === 0) {
const result = dataArrayToRoutes(res.data)
+ console.log(result)
this.accessRoutes = result
return Promise.resolve(result)
} else {
diff --git a/src/views/login/index.vue b/src/views/login/index.vue
index cc7b45f..aff6e29 100644
--- a/src/views/login/index.vue
+++ b/src/views/login/index.vue
@@ -13,8 +13,8 @@ export default {
async function handleLogin() {
try {
const params = {
- captcha: '1',
- key: '9132e06a-e2f0-4a9d-88da-b43ced72bb2e',
+ captcha: '520',
+ key: 'f2d40fb6-b946-4b99-969d-978c6d8a4ea2',
password: '123456',
remember: false,
username: 'admin'
diff --git a/src/views/system/menu/components/RoleModal.vue b/src/views/system/menu/components/RoleModal.vue
new file mode 100644
index 0000000..5d7bdc9
--- /dev/null
+++ b/src/views/system/menu/components/RoleModal.vue
@@ -0,0 +1,50 @@
+
+
+
+ 111
+
+
+
+
+
+
diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue
index e0b819e..d63333b 100644
--- a/src/views/system/menu/index.vue
+++ b/src/views/system/menu/index.vue
@@ -3,24 +3,27 @@
-
+
添加角色
+
+