diff --git a/.vscode/settings.json b/.vscode/settings.json
index eb52453..aeeac4b 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -112,7 +112,7 @@
"lintstagedrc",
"tailwindcss",
"sider",
- "pnpm",
+ "pnpm"
],
// 控制相关文件嵌套展示
"explorer.fileNesting.enabled": true,
@@ -128,7 +128,11 @@
"vite.config.js": "tsconfig.json,tailwind.config.js,jsconfig.json, .cz-config.js"
},
"terminal.integrated.scrollback": 10000,
- "cSpell.enableFiletypes": [
- "!tailwindcss"
+ "cSpell.enableFiletypes": ["!tailwindcss"],
+ "i18n-ally.localesPaths": [
+ "src/language",
+ "src/utils/locales",
+ "src/views/home/locales",
+ "src/views/login/locales"
]
}
diff --git a/src/views/authority/admin/index.vue b/src/views/authority/admin/index.vue
index 569a09c..d571525 100644
--- a/src/views/authority/admin/index.vue
+++ b/src/views/authority/admin/index.vue
@@ -6,12 +6,23 @@
:shadow="defaultData.cardShadow"
>
-
-
+
+
+
@@ -45,11 +59,37 @@
数据列表
-
+
@@ -61,8 +101,12 @@
:tableName="'menuTable'"
:pagination-property="{
total: powerfulTableData.total,
+ pageSize: powerfulTableData.listQuery.pageSize,
+ currentPage: powerfulTableData.listQuery.pageNum,
}"
- @size-change="getList"
+ @size-change="handleSizeChange"
+ @current-change="handleCurrentChange"
+ @sort-change="handleSortChange"
@component-event="handleComponentChange"
@btn-click="handleBtnClick"
>
@@ -103,20 +147,36 @@
+
+
diff --git a/src/views/authority/admin/indexData.ts b/src/views/authority/admin/indexData.ts
index dd04c7b..9448a9f 100644
--- a/src/views/authority/admin/indexData.ts
+++ b/src/views/authority/admin/indexData.ts
@@ -6,11 +6,14 @@
* @LastEditTime: 2023-03-19 15:55:54
*/
import { useSettingStore } from '@/stores'
-import { ref, markRaw, reactive } from 'vue'
+import { ref, markRaw, reactive, computed, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { setData } from 'el-plus-powerful-table-ts/es'
import { Edit, Remove } from '@element-plus/icons-vue'
import type { PowerfulTableHeader } from 'el-plus-powerful-table-ts'
+import defaultData from '@/config/default-data'
+
+export { defaultData }
export type RowType = {
icon: string
@@ -29,10 +32,12 @@ interface PowerfulTableData {
pageNum: number
pageSize: number
username?: string
+ sortProp?: string
+ sortOrder?: string
}
}
-const defaultData = {
+const defaultFormData = {
icon: '',
id: -1,
roles: [],
@@ -41,13 +46,70 @@ const defaultData = {
createTime: '',
}
+const STORAGE_KEYS = {
+ SEARCH_EXPANDED: 'admin_search_expanded',
+ COLUMN_VISIBILITY: 'admin_column_visibility',
+ LIST_STATE: 'admin_list_state',
+}
+
+const getStorage = (key: string, defaultValue: any = null) => {
+ try {
+ const value = localStorage.getItem(key)
+ return value ? JSON.parse(value) : defaultValue
+ } catch {
+ return defaultValue
+ }
+}
+
+const setStorage = (key: string, value: any) => {
+ try {
+ localStorage.setItem(key, JSON.stringify(value))
+ } catch (e) {
+ console.error('Storage error:', e)
+ }
+}
+
export const useData = () => {
const settingStore = useSettingStore()
- const header: PowerfulTableHeader[] = [
+
+ const isSearchExpanded = ref(getStorage(STORAGE_KEYS.SEARCH_EXPANDED, true))
+
+ watch(isSearchExpanded, (newVal) => {
+ setStorage(STORAGE_KEYS.SEARCH_EXPANDED, newVal)
+ })
+
+ const columnVisibility = reactive<{ [key: string]: boolean }>(
+ getStorage(STORAGE_KEYS.COLUMN_VISIBILITY, {
+ id: true,
+ username: true,
+ roles: true,
+ status: true,
+ createTime: true,
+ operation: true,
+ }),
+ )
+
+ watch(
+ columnVisibility,
+ (newVal) => {
+ setStorage(STORAGE_KEYS.COLUMN_VISIBILITY, newVal)
+ },
+ { deep: true },
+ )
+
+ const savedListState = getStorage(STORAGE_KEYS.LIST_STATE, {
+ pageNum: 1,
+ pageSize: 10,
+ username: '',
+ sortProp: '',
+ sortOrder: '',
+ })
+
+ const allHeaders: PowerfulTableHeader[] = [
{
- label: '编号', //显示的标题
- minWidth: '80', //对应列的最小宽度
- sortable: true, //排序
+ label: '编号',
+ minWidth: '80',
+ sortable: true,
props: [
{
prop: 'id',
@@ -55,7 +117,7 @@ export const useData = () => {
],
},
{
- label: '帐号', //显示的名称
+ label: '帐号',
overflowTooltip: true,
props: [
{
@@ -64,7 +126,7 @@ export const useData = () => {
],
},
{
- label: '角色', //显示的名称
+ label: '角色',
props: [
{
type: 'slot',
@@ -74,7 +136,7 @@ export const useData = () => {
],
},
{
- label: '是否启用', //显示的名称
+ label: '是否启用',
props: [
{
prop: 'status',
@@ -98,7 +160,7 @@ export const useData = () => {
],
},
{
- label: '添加时间', //显示的名称
+ label: '添加时间',
props: [
{
prop: 'createTime',
@@ -106,7 +168,7 @@ export const useData = () => {
],
},
{
- label: '操作', //显示的标题
+ label: '操作',
minWidth: '180px',
props: [
{
@@ -135,7 +197,44 @@ export const useData = () => {
},
]
- // 弹窗开关
+ const columnOptions = [
+ { label: '编号', value: 'id' },
+ { label: '帐号', value: 'username' },
+ { label: '角色', value: 'roles' },
+ { label: '是否启用', value: 'status' },
+ { label: '添加时间', value: 'createTime' },
+ { label: '操作', value: 'operation' },
+ ]
+
+ const getColumnKey = (
+ header: PowerfulTableHeader,
+ index: number,
+ ): string => {
+ let prop: string | undefined
+ if (Array.isArray(header.props)) {
+ prop = header.props[0]?.prop
+ } else if (header.props) {
+ prop = header.props.prop
+ }
+ if (prop) return prop
+ if (header.label === '操作') return 'operation'
+ if (header.label === '角色') return 'roles'
+ return `col_${index}`
+ }
+
+ const header = computed(() => {
+ return allHeaders.filter((h, index) => {
+ const key = getColumnKey(h, index)
+ return columnVisibility[key] !== false
+ })
+ })
+
+ const resetColumns = () => {
+ Object.keys(columnVisibility).forEach((key) => {
+ columnVisibility[key] = true
+ })
+ }
+
const switchs = reactive({
role: false,
edit: false,
@@ -143,19 +242,29 @@ export const useData = () => {
const powerfulTableData: PowerfulTableData = reactive({
list: [],
- header: header,
+ header: [],
total: 0,
listQuery: {
- pageNum: 1,
- pageSize: 10,
- username: '',
+ pageNum: savedListState.pageNum || 1,
+ pageSize: savedListState.pageSize || 10,
+ username: savedListState.username || '',
+ sortProp: savedListState.sortProp || '',
+ sortOrder: savedListState.sortOrder || '',
},
})
- // row 数据
- const currentForm = ref({ ...defaultData })
+ const saveListState = () => {
+ setStorage(STORAGE_KEYS.LIST_STATE, {
+ pageNum: powerfulTableData.listQuery.pageNum,
+ pageSize: powerfulTableData.listQuery.pageSize,
+ username: powerfulTableData.listQuery.username,
+ sortProp: powerfulTableData.listQuery.sortProp,
+ sortOrder: powerfulTableData.listQuery.sortOrder,
+ })
+ }
+
+ const currentForm = ref({ ...defaultFormData })
- // 角色列表
const roleLists = ref<{ label: string; value: string }[]>([])
return {
@@ -164,5 +273,10 @@ export const useData = () => {
powerfulTableData,
currentForm,
roleLists,
+ isSearchExpanded,
+ columnVisibility,
+ columnOptions,
+ resetColumns,
+ saveListState,
}
}