|
@@ -1,49 +1,81 @@
|
|
|
<template>
|
|
|
- <div class="h-full overflow-hidden">
|
|
|
- <n-card title="权限管理" :bordered="false" class="rounded-16px shadow-sm">
|
|
|
- <n-space class="pb-12px" justify="space-between">
|
|
|
- <n-space>
|
|
|
- <AddView />
|
|
|
- <n-button type="error">
|
|
|
- <icon-ic-round-delete class="mr-4px text-20px" />
|
|
|
- 删除
|
|
|
- </n-button>
|
|
|
- <n-button type="success">
|
|
|
- <icon-uil:export class="mr-4px text-20px" />
|
|
|
- 导出Excel
|
|
|
- </n-button>
|
|
|
- </n-space>
|
|
|
- <n-space align="center" :size="18">
|
|
|
- <n-button size="small" type="primary">
|
|
|
- <icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': false }" />
|
|
|
- 刷新表格
|
|
|
- </n-button>
|
|
|
- <n-button size="small" type="primary">
|
|
|
- <icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': false }" />
|
|
|
- 激活
|
|
|
- </n-button>
|
|
|
- <column-setting v-model:columns="columns" />
|
|
|
- </n-space>
|
|
|
- </n-space>
|
|
|
- <n-input-group>
|
|
|
- <n-input :style="{ width: '50%' }" />
|
|
|
- <n-button type="primary">搜索</n-button>
|
|
|
- </n-input-group>
|
|
|
- <n-data-table :columns="columns" :data="tableData" :pagination="pagination" />
|
|
|
- </n-card>
|
|
|
- </div>
|
|
|
+ <div class="h-full overflow-hidden">
|
|
|
+ <n-card title="权限管理" :bordered="false" class="rounded-16px shadow-sm">
|
|
|
+ <n-space class="pb-12px" justify="space-between">
|
|
|
+ <n-space>
|
|
|
+ <n-button type="primary" @click="handleAddTable">
|
|
|
+ <icon-ic-round-plus class="mr-4px text-20px" />
|
|
|
+ 新增
|
|
|
+ </n-button>
|
|
|
+ <n-button type="error" @click="handleRemoved">
|
|
|
+ <icon-ic-round-delete class="mr-4px text-20px" />
|
|
|
+ 删除
|
|
|
+ </n-button>
|
|
|
+ <n-button type="success">
|
|
|
+ <icon-uil:export class="mr-4px text-20px" />
|
|
|
+ 导出Excel
|
|
|
+ </n-button>
|
|
|
+ </n-space>
|
|
|
+ <n-space align="center" :size="18">
|
|
|
+ <n-button size="small" type="primary" @click="getTableData">
|
|
|
+ <icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': false }" />
|
|
|
+ 刷新表格
|
|
|
+ </n-button>
|
|
|
+ <column-setting v-model:columns="columns" />
|
|
|
+ </n-space>
|
|
|
+ </n-space>
|
|
|
+ <n-input-group>
|
|
|
+ <n-input-number :style="{ width: '33%' }" @input="handleInput1" />
|
|
|
+ <n-input-number :style="{ width: '33%' }" @input="handleInput2" />
|
|
|
+ <n-button @click="searchForm">搜索</n-button>
|
|
|
+ </n-input-group>
|
|
|
+ <div style="height: 400px; overflow-y: auto;">
|
|
|
+ <n-data-table v-if="pageData.length <= 0 || inputInfo1.length === 0 && inputInfo2.length === 0" :columns="columns"
|
|
|
+ :data="tableData" :loading="loading" :pagination="pagination" :row-key="rowKey"
|
|
|
+ @update:checked-row-keys="handleCheck" />
|
|
|
+ <n-data-table v-if="pageData.length > 0" :columns="columns" :data="pageData" :loading="loading"
|
|
|
+ :pagination="pagination" :row-key="rowKey" @update:checked-row-keys="handleCheck" />
|
|
|
+ <AddView v-model:visible="visible" :type="modalType" :edit-data="editData" />
|
|
|
+ </div>
|
|
|
+ </n-card>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
-<script setup lang="ts">
|
|
|
-import { ref, reactive } from 'vue';
|
|
|
+<script lang="tsx">
|
|
|
+import { ref, reactive, defineComponent } from 'vue';
|
|
|
import type { Ref } from 'vue';
|
|
|
-import type { DataTableColumns, PaginationProps } from 'naive-ui';
|
|
|
-import { query, add } from '../../../service/api/user';
|
|
|
+import { NButton, NPopconfirm, NSpace } from 'naive-ui';
|
|
|
+import type { DataTableColumns, PaginationProps, DataTableRowKey } from 'naive-ui';
|
|
|
+import { query, add, deleted } from '../../../service/api/user';
|
|
|
+import type { ModalType } from './components/AddView.vue';
|
|
|
+import AddView from './components/AddView.vue';
|
|
|
import type { QueryParams, AddParams } from '~/src/service/api/user';
|
|
|
-import AddView from '~/src/views/management/auth/AddView.vue'
|
|
|
-
|
|
|
+import { useBoolean, useLoading } from '@/hooks';
|
|
|
+// import { init } from 'echarts';
|
|
|
+import { fetchUserList } from '@/service';
|
|
|
const queryInfo: QueryParams = {};
|
|
|
const addInfo: AddParams = {};
|
|
|
+const { loading,startLoading, endLoading} = useLoading(false);
|
|
|
+const { bool: visible, setTrue: openModal } = useBoolean();
|
|
|
+function setTableData(data: UserManagement.User[]) {
|
|
|
+ tableData.value = data as [];
|
|
|
+}
|
|
|
+// 接收input的值
|
|
|
+const inputInfo1 = ref();
|
|
|
+const inputInfo2 = ref();
|
|
|
+// 新的数组
|
|
|
+const pageData = ref([])
|
|
|
+type RowData = {
|
|
|
+ key: number;
|
|
|
+ id: number;
|
|
|
+ name: string;
|
|
|
+ description: string;
|
|
|
+ isActive: string;
|
|
|
+ createTime: number;
|
|
|
+ modifyTime: number;
|
|
|
+ createUid: number;
|
|
|
+ disabled: string;
|
|
|
+};
|
|
|
// // 定义响应式数据:收集用户写进来的关键字
|
|
|
// const keyword = ref<string>('');
|
|
|
// // // 搜索按钮的回调
|
|
@@ -54,75 +86,220 @@ const addInfo: AddParams = {};
|
|
|
// }
|
|
|
// };
|
|
|
export interface Props {
|
|
|
- /** 弹窗可见性 */
|
|
|
- visible: boolean;
|
|
|
- /**
|
|
|
- * 弹窗类型
|
|
|
- * add: 新增
|
|
|
- * edit: 编辑
|
|
|
- */
|
|
|
- type?: 'add' | 'edit';
|
|
|
- /** 编辑的表格行数据 */
|
|
|
- editData?: UserManagement.User | null;
|
|
|
+ /** 弹窗可见性 */
|
|
|
+ visible: boolean;
|
|
|
+ /**
|
|
|
+ * 弹窗类型
|
|
|
+ * add: 新增
|
|
|
+ * edit: 编辑
|
|
|
+ */
|
|
|
+ type?: 'add' | 'edit';
|
|
|
+ /** 编辑的表格行数据 */
|
|
|
+ editData?: UserManagement.User | null;
|
|
|
}
|
|
|
-const AddTableInfo = ref();
|
|
|
const pagination: PaginationProps = reactive({
|
|
|
- page: 1,
|
|
|
- pageSize: 10,
|
|
|
- showSizePicker: true,
|
|
|
- pageSizes: [10, 15, 20, 25, 30],
|
|
|
- onChange: (page: number) => {
|
|
|
- pagination.page = page;
|
|
|
- },
|
|
|
- onUpdatePageSize: (pageSize: number) => {
|
|
|
- pagination.pageSize = pageSize;
|
|
|
- pagination.page = 1;
|
|
|
- }
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ showSizePicker: true,
|
|
|
+ pageSizes: [10, 15, 20, 25, 30],
|
|
|
+ onChange: (page: number) => {
|
|
|
+ // 处理页码发生变化
|
|
|
+ pagination.page = page;
|
|
|
+ },
|
|
|
+ onUpdatePageSize: (pageSize: number) => {
|
|
|
+ pagination.pageSize = pageSize;
|
|
|
+ pagination.page = 1;
|
|
|
+ }
|
|
|
});
|
|
|
+function handleAddTable() {
|
|
|
+ openModal();
|
|
|
+ getTableData();
|
|
|
+ setModalType('add');
|
|
|
+}
|
|
|
|
|
|
const tableData = ref<QueryParams[]>([]);
|
|
|
|
|
|
-query(pagination.page, pagination.pageSize, queryInfo).then(result => {
|
|
|
- tableData.value = result.data as [];
|
|
|
+query(pagination.page, pagination.pageSize, queryInfo).then((result) => {
|
|
|
+ tableData.value = result.data as [];
|
|
|
});
|
|
|
add(addInfo).then(_res => {
|
|
|
- console.log(_res);
|
|
|
+ console.log(_res);
|
|
|
});
|
|
|
-const columns: Ref<DataTableColumns<QueryParams>> = ref([
|
|
|
- {
|
|
|
- type: 'selection',
|
|
|
- align: 'center'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'name',
|
|
|
- title: '名称',
|
|
|
- align: 'center'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'description',
|
|
|
- title: '描述',
|
|
|
- align: 'center'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'isActive',
|
|
|
- title: '是否激活',
|
|
|
- align: 'center'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'modifyTime',
|
|
|
- title: '修改时间',
|
|
|
- align: 'center'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'createUid',
|
|
|
- title: '创建用户ID',
|
|
|
- align: 'center'
|
|
|
- },
|
|
|
- {
|
|
|
- key: 'disabled',
|
|
|
- title: '状态',
|
|
|
- align: 'center'
|
|
|
- }
|
|
|
-]) as Ref<DataTableColumns<QueryParams>>;
|
|
|
+const keyId = ref() as any;
|
|
|
+
|
|
|
+function handleRemoved() {
|
|
|
+ deleted(keyId.value).then(() => {
|
|
|
+ console.log('djiao ')
|
|
|
+ }
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const columns: Ref<DataTableColumns<UserManagementAuth.User>> = ref([
|
|
|
+ {
|
|
|
+ type: 'selection',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'id',
|
|
|
+ title: 'ID',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'name',
|
|
|
+ title: '名称',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'description',
|
|
|
+ title: '描述',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'isActive',
|
|
|
+ title: '是否激活',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'modifyTime',
|
|
|
+ title: '修改时间',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'createUid',
|
|
|
+ title: '创建用户ID',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'disabled',
|
|
|
+ title: '状态',
|
|
|
+ align: 'center'
|
|
|
+ }, {
|
|
|
+ key: 'actions',
|
|
|
+ title: '操作',
|
|
|
+ align: 'center',
|
|
|
+ render: row => {
|
|
|
+ return (
|
|
|
+ <NSpace justify={'center'}>
|
|
|
+ <NButton size={'small'} onClick={() => handleEditTable(row.id)}>
|
|
|
+ 编辑
|
|
|
+ </NButton>
|
|
|
+ <NPopconfirm onPositiveClick={() => handleDeleteTable()}>
|
|
|
+ {{
|
|
|
+ default: () => '确认删除',
|
|
|
+ trigger: () => <NButton size={'small'}>
|
|
|
+ 删除
|
|
|
+ </NButton>
|
|
|
+ }}
|
|
|
+ </NPopconfirm>
|
|
|
+ </NSpace>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+]) as Ref<DataTableColumns<UserManagementAuth.User>>;
|
|
|
+
|
|
|
+// 编辑
|
|
|
+const editData = ref<UserManagement.User | null>(null);
|
|
|
+function setEditData(data: UserManagement.User | null) {
|
|
|
+ editData.value = data;
|
|
|
+}
|
|
|
+function handleEditTable(rowId: number) {
|
|
|
+ const findItem = tableData.value.find(item => item.id === rowId);
|
|
|
+ if (findItem) {
|
|
|
+ setEditData(findItem);
|
|
|
+ }
|
|
|
+ setModalType('edit');
|
|
|
+ openModal();
|
|
|
+}
|
|
|
+
|
|
|
+const modalType = ref<ModalType>('add' || 'edit');
|
|
|
+
|
|
|
+function setModalType(type: ModalType) {
|
|
|
+ modalType.value = type;
|
|
|
+}
|
|
|
+// 删除
|
|
|
+// 点击删除事件
|
|
|
+ async function handleDeleteTable() {
|
|
|
+ console.log(keyId.value)
|
|
|
+ await deleted(keyId.value).then((r) => {
|
|
|
+ window.$message?.info(`点击了删除,rowId为${keyId}`);
|
|
|
+ console.log(r)
|
|
|
+ })
|
|
|
+}
|
|
|
+export default defineComponent({
|
|
|
+ components: {
|
|
|
+ AddView,
|
|
|
+ },
|
|
|
+
|
|
|
+ setup() {
|
|
|
+ const checkedRowKeysRef = ref<DataTableRowKey[]>([])
|
|
|
+
|
|
|
+ return {
|
|
|
+ tableData,
|
|
|
+ columns,
|
|
|
+ checkedRowKeys: checkedRowKeysRef,
|
|
|
+ pagination,
|
|
|
+ loading,
|
|
|
+ modalType,
|
|
|
+ queryInfo,
|
|
|
+ editData,
|
|
|
+ inputInfo1,
|
|
|
+ // getTableData,
|
|
|
+ setTableData,
|
|
|
+ inputInfo2,
|
|
|
+ visible,
|
|
|
+ pageData,
|
|
|
+ handleRemoved,
|
|
|
+ handleAddTable,
|
|
|
+ rowKey: (row: RowData) => row.id,
|
|
|
+ handleDeleteTable(rowKeys: DataTableRowKey[]) {
|
|
|
+ checkedRowKeysRef.value = rowKeys
|
|
|
+ // console.log(rowKeys)
|
|
|
+ keyId.value = rowKeys;
|
|
|
+ },
|
|
|
+ handleCheck(rowKeys: DataTableRowKey[]) {
|
|
|
+ checkedRowKeysRef.value = rowKeys
|
|
|
+ // console.log(rowKeys)
|
|
|
+ keyId.value = rowKeys;
|
|
|
+ },
|
|
|
+ handleInput1(v: number) {
|
|
|
+ // console.log(v)
|
|
|
+ // 把字符串强行转换为number类型
|
|
|
+ inputInfo1.value = v.data
|
|
|
+ inputInfo1.value = Number(inputInfo1.value)
|
|
|
+ console.log(inputInfo1.value)
|
|
|
+ },
|
|
|
+ handleInput2(v: number) {
|
|
|
+ // console.log(v)
|
|
|
+ inputInfo2.value = v.data
|
|
|
+ inputInfo2.value = Number(inputInfo2.value)
|
|
|
+ },
|
|
|
+ // 点击搜索事件
|
|
|
+ async searchForm() {
|
|
|
+ await query(inputInfo1.value, inputInfo2.value, queryInfo).then((r) => {
|
|
|
+ // console.log(r)
|
|
|
+ pageData.value = r.data as [];
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+})
|
|
|
+// // 初始化
|
|
|
+
|
|
|
+// async function getTableData() {
|
|
|
+// startLoading();
|
|
|
+// const { data } = await fetchUserList();
|
|
|
+// if (data) {
|
|
|
+// setTimeout(() => {
|
|
|
+// setTableData(data);
|
|
|
+// endLoading();
|
|
|
+// }, 1000);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// function init() {
|
|
|
+// getTableData();
|
|
|
+// }
|
|
|
+
|
|
|
+// // 初始化
|
|
|
+// init();
|
|
|
</script>
|
|
|
<style scoped></style>
|