|
|
@@ -1,13 +1,312 @@
|
|
|
+<style scoped lang="scss">
|
|
|
+.system-container {
|
|
|
+
|
|
|
+ :deep(.el-card__body) {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ flex: 1;
|
|
|
+ overflow: auto;
|
|
|
+
|
|
|
+ .el-table {
|
|
|
+ flex: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.page-content {
|
|
|
+ margin-bottom: 20px;
|
|
|
+}
|
|
|
+
|
|
|
+.page-pager {
|
|
|
+ background-color: #fff;
|
|
|
+ height: 24px;
|
|
|
+}
|
|
|
+</style>
|
|
|
<template>
|
|
|
+ <div class="system-container layout-padding">
|
|
|
+ <el-card shadow="hover" class="layout-padding-auto">
|
|
|
+ <el-form
|
|
|
+ :model="state.queryForm"
|
|
|
+ ref="formRulesOneRef"
|
|
|
+ size="default" label-width="0px" class="mt5">
|
|
|
+
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <ext-query-form
|
|
|
+ class="page-search"
|
|
|
+ ref="queryRef"
|
|
|
+ v-model="state.formQuery"
|
|
|
+ :columns="state.columns"
|
|
|
+ :import-config="state.importConfig"
|
|
|
+ :export-config="state.exportConfig"
|
|
|
+ @on-change="loadData(true)"
|
|
|
+ @imported="loadData(true)">
|
|
|
+ <!-- <template #extraQuery></template>
|
|
|
+ <template #extraLeft></template>
|
|
|
+ <template #extraRight></template>-->
|
|
|
+ <template #extraLeft>
|
|
|
+ <ext-button name="创建"
|
|
|
+ auth="'department.add'" icon="ele-FolderAdd"
|
|
|
+ size="default" type="success"
|
|
|
+ class="ml10" @click="onRowClick('add',null)"/>
|
|
|
+ </template>
|
|
|
+ </ext-query-form>
|
|
|
|
|
|
+ <el-row :gutter="20">
|
|
|
+
|
|
|
+ <el-col :span="24">
|
|
|
+ <ext-table
|
|
|
+ class="page-content"
|
|
|
+ :height="state.tableHeight"
|
|
|
+ :data-list="state.tableData.data"
|
|
|
+ :columns="state.columns"
|
|
|
+ :border="true"
|
|
|
+ :selectable="true"
|
|
|
+ :loading="state.tableData.loading">
|
|
|
+ </ext-table>
|
|
|
+
|
|
|
+ <!-- <el-affix position="bottom" :offset="48">-->
|
|
|
+ <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>
|
|
|
+ <!-- </el-affix>-->
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ </el-card>
|
|
|
+ </div>
|
|
|
+ <UserDialog ref="userDialogRef" @refresh="loadData(true)"/>
|
|
|
</template>
|
|
|
|
|
|
-<script>
|
|
|
-export default {
|
|
|
- name: "index"
|
|
|
+<script setup lang="ts" name="UserList">
|
|
|
+import {watch, defineAsyncComponent, getCurrentInstance, nextTick, onBeforeMount, onMounted, reactive, ref} from 'vue';
|
|
|
+import {$body, $get} from "/@/utils/request";
|
|
|
+import u from '/@/utils/u'
|
|
|
+import {Msg} from "/@/utils/message";
|
|
|
+import {Session} from "/@/utils/storage";
|
|
|
+import ExtButton from '/@/components/form/ExtButton.vue'
|
|
|
+import ExtPage from '/@/components/form/ExtPage.vue'
|
|
|
+import ExtQueryForm from "/@/components/form/ExtQueryForm.vue";
|
|
|
+import ExtTable from "/@/components/form/ExtTable.vue";
|
|
|
+
|
|
|
+import {ElButton, ElTree, ElTag} from 'element-plus'
|
|
|
+
|
|
|
+const {proxy}: any = getCurrentInstance();
|
|
|
+
|
|
|
+
|
|
|
+const UserDialog = defineAsyncComponent(() => import("/@/views/admin/user/dialog.vue"));
|
|
|
+
|
|
|
+//定义引用
|
|
|
+const queryRef = ref();
|
|
|
+const userDialogRef = ref();
|
|
|
+const treeRef = ref<InstanceType<typeof ElTree>>()
|
|
|
+//定义变量
|
|
|
+const state = reactive({
|
|
|
+ treeData: [],
|
|
|
+ filterText: null,
|
|
|
+ formQuery: {
|
|
|
+ departmentId: null
|
|
|
+ },
|
|
|
+ pageQuery: {
|
|
|
+ pageIndex: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ total: 0
|
|
|
+ },
|
|
|
+ tableData: {
|
|
|
+ data: [] as Array<any>,
|
|
|
+ loading: false
|
|
|
+ },
|
|
|
+ importConfig: {},
|
|
|
+ exportConfig: {},
|
|
|
+ columns: [
|
|
|
+ {label: '头像', prop: 'avatar', query: false, type: 'avatar', resizable: true},
|
|
|
+ {
|
|
|
+ label: '用户名', prop: 'userName', query: true, type: "text", resizable: true,
|
|
|
+ render: (h: any, row: any) => {
|
|
|
+ return h('div', null, [
|
|
|
+ h('div', {
|
|
|
+ style: {
|
|
|
+ cursor: 'pointer',
|
|
|
+ color: 'var(--el-color-primary-light-1)'
|
|
|
+ },
|
|
|
+ onClick: () => {
|
|
|
+ onRowClick('view', row)
|
|
|
+ }
|
|
|
+ }, row.userName)])
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {label: '姓名', prop: 'name', query: true, type: 'text', resizable: true},
|
|
|
+ {label: '手机号', prop: 'mobile', query: true, type: 'text', resizable: true},
|
|
|
+ {label: '邮箱', prop: 'email', query: true, type: 'text', resizable: true},
|
|
|
+ {
|
|
|
+ label: '部门', prop: 'departmentId', query: true, type: 'dept', resizable: true,
|
|
|
+ render: (h: any, row: any) => {
|
|
|
+ return h('div', null,
|
|
|
+ row.deptList?row.deptList.map((k: any) => h(ElTag, {
|
|
|
+ type: 'primary'
|
|
|
+ }, k.name)):'')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '角色', prop: 'roleId', query: true, type: 'select', resizable: true, conf: {url: 'entity/list', query: {entity: 'role'}},
|
|
|
+ render: (h: any, row: any) => {
|
|
|
+ return h('div', null,
|
|
|
+ row.roleList?row.roleList.map((k: any) => h(ElTag, {
|
|
|
+ type: 'success'
|
|
|
+ }, k.name)):'')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '岗位', prop: 'postId', query: true, type: 'text', resizable: true, conf: {url: 'entity/list', query: {entity: 'post'}},
|
|
|
+ render: (h: any, row: any) => {
|
|
|
+ return h('div', null,
|
|
|
+ row.postList ? row.postList.map((k: any) => h(ElTag, {
|
|
|
+ type: 'danger'
|
|
|
+ }, k.name)) : '')
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ {label: '工号', prop: 'code', width: 150, query: true, type: 'text', resizable: true},
|
|
|
+ {label: '是否删除', prop: 'deleted', query: true, type: 'bool'},
|
|
|
+ {label: '登录ip', prop: 'ip', width: 150, query: false, type: 'text', resizable: true},
|
|
|
+ {label: '职业信息', prop: 'job', query: false, type: 'text', resizable: true},
|
|
|
+ {label: '上次登录时间', prop: 'lastLoginAt', width: 180, query: true, type: 'datetime', resizable: true, conf: {format: (val: any) => u.fmt.fmtDateTime(val)}},
|
|
|
+ {label: '用户状态', prop: 'status', width: 150, sortable: 'custom', align: 'center', query: true, type: 'dict', conf: {dict: 'User.status'}},
|
|
|
+ {label: '创建时间', prop: 'createAt', query: true, type: 'datetime', resizable: true, conf: {format: (val: any) => u.fmt.fmtDate(val)}},
|
|
|
+ {label: '更新时间', prop: 'updateAt', query: true, type: 'datetime', resizable: true, conf: {format: (val: any) => u.fmt.fmtDate(val)}},
|
|
|
+ {
|
|
|
+ label: '操作', prop: 'action', width: 180, type: 'render', align: 'center', fixed: 'right',
|
|
|
+ render: (h: any, row: any) => {
|
|
|
+ return (
|
|
|
+ h('div', null, [
|
|
|
+ (proxy.$auth('user.modify')) ?
|
|
|
+ h(ElButton, {
|
|
|
+ type: 'warning',
|
|
|
+ size: 'default',
|
|
|
+ text: true,
|
|
|
+ onClick: () => {
|
|
|
+ onRowClick('edit', row)
|
|
|
+ }
|
|
|
+ }, () => '编辑') : '',
|
|
|
+ (proxy.$auth('user.remove')) ?
|
|
|
+ h(ElButton, {
|
|
|
+ type: 'danger',
|
|
|
+ text: true,
|
|
|
+ onClick() {
|
|
|
+ onRowDel(row)
|
|
|
+ }
|
|
|
+ }, () => '重置密码') : '',
|
|
|
+ ])
|
|
|
+ )
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ tableHeight: 500
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+interface Tree {
|
|
|
+ [key: string]: any
|
|
|
+}
|
|
|
+
|
|
|
+watch(() => state.filterText, (val) => {
|
|
|
+ treeRef.value!.filter(val)
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+// 监听双向绑定 modelValue 的变化
|
|
|
+// watch(
|
|
|
+// () => state.pageIndex,
|
|
|
+// () => {
|
|
|
+//
|
|
|
+// }
|
|
|
+// );
|
|
|
+
|
|
|
+//生命周期钩子
|
|
|
+onBeforeMount(() => {
|
|
|
+ let token = Session.get("token")
|
|
|
+ let encodeToken = encodeURIComponent(token)
|
|
|
+
|
|
|
+})
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ loadData();
|
|
|
+ loadTreeData()
|
|
|
+
|
|
|
+ nextTick(() => {
|
|
|
+ let bodyHeight = document.body.clientHeight;
|
|
|
+ let queryHeight = queryRef.value.$el.clientHeight;
|
|
|
+ state.tableHeight = bodyHeight - queryHeight - 220
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+//region 方法区
|
|
|
+// 初始化表格数据
|
|
|
+const loadData = (refresh: boolean = false) => {
|
|
|
+ if (refresh) {
|
|
|
+ state.pageQuery.pageIndex = 1;
|
|
|
+ }
|
|
|
+ state.tableData.loading = true;
|
|
|
+ $body(`/user/list`, {...state.formQuery, ...state.pageQuery}).then((res: any) => {
|
|
|
+ let {list, count} = res;
|
|
|
+ state.tableData.data = list;
|
|
|
+ state.pageQuery.total = count;
|
|
|
+ state.tableData.loading = false;
|
|
|
+ }).catch(e => {
|
|
|
+ console.error(e)
|
|
|
+ state.tableData.loading = false;
|
|
|
+ })
|
|
|
+};
|
|
|
+
|
|
|
+// 打开修改用户弹窗
|
|
|
+const onRowClick = (type: string, row: any) => {
|
|
|
+ userDialogRef.value.open(type, row);
|
|
|
+};
|
|
|
+// 删除用户
|
|
|
+const onRowDel = (row: any) => {
|
|
|
+ Msg.confirm(`此操作将永久删除:『${row.name}』,是否继续?`).then(() => {
|
|
|
+ $get(`/user/delete/${row.id}`).then(() => {
|
|
|
+ Msg.message("删除成功", 'success')
|
|
|
+ }).catch(() => {
|
|
|
+ Msg.message("删除失败", 'error')
|
|
|
+ })
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+const filterNode = (value: string, data: Tree) => {
|
|
|
+ if (!value) return true
|
|
|
+ return data.name.includes(value)
|
|
|
}
|
|
|
-</script>
|
|
|
|
|
|
-<style scoped>
|
|
|
+const handleNodeClick = (data: any) => {
|
|
|
+ console.log(data)
|
|
|
+ if (data) {
|
|
|
+ if (state.formQuery.departmentId === data.id) {
|
|
|
+ state.formQuery.departmentId = null;
|
|
|
+ treeRef.value?.setCurrentKey(null)
|
|
|
+ } else {
|
|
|
+ state.formQuery.departmentId = data.id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ loadData();
|
|
|
+}
|
|
|
+
|
|
|
+const loadTreeData = () => {
|
|
|
+ state.tableData.loading = true;
|
|
|
+ state.tableData.data = [];
|
|
|
+ $body(`/department/tree`).then((res: any) => {
|
|
|
+ state.treeData = res;
|
|
|
+ })
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+//endregion
|
|
|
+
|
|
|
|
|
|
-</style>
|
|
|
+// 暴露变量
|
|
|
+// defineExpose({
|
|
|
+// loadData,
|
|
|
+// });
|
|
|
+</script>
|