Skip to content

Commit

Permalink
feat: 登录页改造
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Jul 10, 2023
1 parent b1a83f6 commit 5312951
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 161 deletions.
1 change: 0 additions & 1 deletion src/components/Table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface TableExpose {
setColumn: (columnProps: TableSetProps[]) => void
addColumn: (column: TableColumn, index?: number) => void
delColumn: (field: string) => void
selections: Recordable[]
elTableRef: ComponentRef<typeof ElTable>
}

Expand Down
14 changes: 1 addition & 13 deletions src/components/Table/src/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,11 @@ export default defineComponent({
}
}
const selections = ref<Recordable[]>([])
const selectionChange = (selection: Recordable[]) => {
selections.value = selection
}
expose({
setProps,
setColumn,
delColumn,
addColumn,
selections,
elTableRef
})
Expand Down Expand Up @@ -409,12 +402,7 @@ export default defineComponent({
return () => (
<div v-loading={unref(getProps).loading}>
<ElTable
ref={elTableRef}
data={unref(getProps).data}
onSelection-change={selectionChange}
{...unref(getBindValue)}
>
<ElTable ref={elTableRef} data={unref(getProps).data} {...unref(getBindValue)}>
{{
default: () => renderTableColumn(),
empty: () => getSlot(slots, 'empty') || unref(getProps).emptyText,
Expand Down
9 changes: 0 additions & 9 deletions src/hooks/web/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ export const useTable = (config: UseTableConfig) => {
table?.delColumn(field)
},

/**
* @description 获取全选数据
* @returns
*/
getSelections: async () => {
const table = await getTable()
return table?.selections || []
},

/**
* @description 获取ElTable组件的实例
* @returns ElTable instance
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ export default {
delOrAddAction: 'Delete or add action',
showOrHiddenStripe: 'Show or hidden stripe',
showOrHiddenBorder: 'Show or hidden border',
fixedHeaderOrAuto: 'Fixed header or auto'
fixedHeaderOrAuto: 'Fixed header or auto',
getSelections: 'Get selections'
},
richText: {
richText: 'Rich text',
Expand Down
3 changes: 2 additions & 1 deletion src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ export default {
delOrAddAction: '删除/添加操作列',
showOrHiddenStripe: '显示/隐藏斑马纹',
showOrHiddenBorder: '显示/隐藏边框',
fixedHeaderOrAuto: '固定头部/自动'
fixedHeaderOrAuto: '固定头部/自动',
getSelections: '获取多选数据'
},
richText: {
richText: '富文本',
Expand Down
80 changes: 40 additions & 40 deletions src/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,52 @@ const whiteList = ['/login'] // 不重定向白名单
router.beforeEach(async (to, from, next) => {
start()
loadStart()
// if (!wsCache.get(appStore.getUserInfo)) {
if (to.path === '/login') {
next({ path: '/' })
} else {
if (!dictStore.getIsSetDict) {
// 获取所有字典
const res = await getDictApi()
if (res) {
dictStore.setDictObj(res.data)
dictStore.setIsSetDict(true)
if (wsCache.get(appStore.getUserInfo)) {
if (to.path === '/login') {
next({ path: '/' })
} else {
if (!dictStore.getIsSetDict) {
// 获取所有字典
const res = await getDictApi()
if (res) {
dictStore.setDictObj(res.data)
dictStore.setIsSetDict(true)
}
}
if (permissionStore.getIsAddRouters) {
next()
return
}
}
if (permissionStore.getIsAddRouters) {
next()
return
}

// 开发者可根据实际情况进行修改
const roleRouters = wsCache.get('roleRouters') || []
const userInfo = wsCache.get(appStore.getUserInfo)
// 开发者可根据实际情况进行修改
const roleRouters = wsCache.get('roleRouters') || []
const userInfo = wsCache.get(appStore.getUserInfo)

// 是否使用动态路由
if (appStore.getDynamicRouter) {
userInfo.role === 'admin'
? await permissionStore.generateRoutes('admin', roleRouters as AppCustomRouteRecordRaw[])
: await permissionStore.generateRoutes('test', roleRouters as string[])
// 是否使用动态路由
if (appStore.getDynamicRouter) {
userInfo.role === 'admin'
? await permissionStore.generateRoutes('admin', roleRouters as AppCustomRouteRecordRaw[])
: await permissionStore.generateRoutes('test', roleRouters as string[])
} else {
await permissionStore.generateRoutes('none')
}

permissionStore.getAddRouters.forEach((route) => {
router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表
})
const redirectPath = from.query.redirect || to.path
const redirect = decodeURIComponent(redirectPath as string)
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }
permissionStore.setIsAddRouters(true)
next(nextData)
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
await permissionStore.generateRoutes('none')
next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
}

permissionStore.getAddRouters.forEach((route) => {
router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表
})
const redirectPath = from.query.redirect || to.path
const redirect = decodeURIComponent(redirectPath as string)
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }
permissionStore.setIsAddRouters(true)
next(nextData)
}
// } else {
// if (whiteList.indexOf(to.path) !== -1) {
// next()
// } else {
// next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
// }
// }
})

router.afterEach((to) => {
Expand Down
8 changes: 8 additions & 0 deletions src/views/Components/Table/UseTableDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ const fixedHeaderOrAuto = () => {
height.value = 'auto'
}
}
const getSelections = async () => {
const elTableRef = await getElTableExpose()
const selections = elTableRef?.getSelectionRows()
console.log(selections)
}
</script>

<template>
Expand Down Expand Up @@ -236,6 +242,8 @@ const fixedHeaderOrAuto = () => {
<ElButton @click="showOrHiddenStripe">{{ t('tableDemo.showOrHiddenStripe') }}</ElButton>

<ElButton @click="fixedHeaderOrAuto">{{ t('tableDemo.fixedHeaderOrAuto') }}</ElButton>

<ElButton @click="getSelections">{{ t('tableDemo.getSelections') }}</ElButton>
</ContentWrap>
<ContentWrap :title="`UseTable ${t('tableDemo.example')}`">
<Table
Expand Down
Loading

0 comments on commit 5312951

Please sign in to comment.