|
|
@@ -1,147 +1,270 @@
|
|
|
<template>
|
|
|
- <div>
|
|
|
- <BasicTable :rowSelection="{ type: 'checkbox' }" @register="registerTable" :clickToRowSelect="false">
|
|
|
- <template #toolbar>
|
|
|
- <Authority>
|
|
|
- <a-button type="primary" @click="handleCreate">新增角色</a-button>
|
|
|
- </Authority>
|
|
|
- <Authority>
|
|
|
- <Popconfirm title="您确定要批量删除数据" ok-text="确定" cancel-text="取消" @confirm="handleDeleteOrBatchDelete(null)">
|
|
|
- <a-button type="primary" color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
|
|
|
- </Popconfirm>
|
|
|
- </Authority>
|
|
|
- </template>
|
|
|
- <template #status="{ record }">
|
|
|
- <Switch :checked="record.status === 1" :loading="record.pendingStatus" checkedChildren="启用" unCheckedChildren="禁用"
|
|
|
- @change="(checked: boolean) => statusChange(checked, record)" />
|
|
|
- </template>
|
|
|
- <template #action="{ record }">
|
|
|
- <TableAction :actions="[
|
|
|
- {
|
|
|
- label: '编辑',
|
|
|
- icon: 'clarity:note-edit-line',
|
|
|
- onClick: handleEdit.bind(null, record),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '删除',
|
|
|
- icon: 'ant-design:delete-outlined',
|
|
|
- color: 'error',
|
|
|
- ifShow: record.roleType != RoleEnum.SYS_ADMIN,
|
|
|
- popConfirm: {
|
|
|
- title: '是否确认删除',
|
|
|
- confirm: handleDeleteOrBatchDelete.bind(null, record),
|
|
|
- },
|
|
|
- },
|
|
|
- ]" />
|
|
|
- </template>
|
|
|
- </BasicTable>
|
|
|
- <RoleDrawer @register="registerDrawer" @success="handleSuccess" />
|
|
|
- </div>
|
|
|
+ <div class="p-4">
|
|
|
+ <div class="zhiwei-header">
|
|
|
+ <div class="zhiwei-title">职位管理</div>
|
|
|
+ <div class="handle-btns">
|
|
|
+ <a-button class="btn" type="primary" @click="addHandle">新增</a-button>
|
|
|
+ <a-button class="btn" @click="editHandle">修改</a-button>
|
|
|
+ <a-button class="btn" danger @click="delHandle">删除</a-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="zhiwei-body">
|
|
|
+ <div class="structure-tree list-items">
|
|
|
+ <div class="item-title">部门列表</div>
|
|
|
+ <a-tree :replaceFields="replaceFields" :treeData="treeData" v-if="treeData" @select="nodeSelect"></a-tree>
|
|
|
+ </div>
|
|
|
+ <div class="posts-list list-items">
|
|
|
+ <div class="item-title">职位列表</div>
|
|
|
+ <div class="posts-box item-box">
|
|
|
+ <div class="posts item" v-for="(item, index) in posts.data" :key="index"
|
|
|
+ @click="chooseHandle(item, 'posts')">
|
|
|
+ <span :class="{ 'chosed': item.departid === posts.currentId }">{{ item.departName }}</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <ZhiweiDrawer :formData="formData" :drawerTitle="drawerTitle" @onSubmit="onSubmit" ref="drawerRef"></ZhiweiDrawer>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
-<script lang="ts">
|
|
|
-import { defineComponent, nextTick } from 'vue';
|
|
|
-import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
|
|
-import { delRole, getRoleListByPage, setRoleStatus } from '/@/api/system/system';
|
|
|
-import { useDrawer } from '/@/components/Drawer';
|
|
|
-import RoleDrawer from './RoleDrawer.vue';
|
|
|
-import { columns, searchFormSchema } from './role.data';
|
|
|
-import { RoleEnum } from '/@/enums/roleEnum';
|
|
|
-import { Authority } from '/@/components/Authority';
|
|
|
-import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
|
|
|
-import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
-import { Switch, Popconfirm } from 'ant-design-vue';
|
|
|
-import { roleList } from '/@/api/sys/user';
|
|
|
|
|
|
-export default defineComponent({
|
|
|
- name: 'RoleManagement',
|
|
|
- components: { BasicTable, RoleDrawer, TableAction, Authority, Switch, Popconfirm },
|
|
|
- setup() {
|
|
|
- const [registerDrawer, { openDrawer }] = useDrawer();
|
|
|
- function handleSuccess() {
|
|
|
- reload();
|
|
|
- }
|
|
|
- const [registerTable, { setProps, reload, setSelectedRowKeys }] = useTable({
|
|
|
- title: '角色列表',
|
|
|
- api: roleList,
|
|
|
- columns,
|
|
|
- formConfig: {
|
|
|
- labelWidth: 120,
|
|
|
- schemas: searchFormSchema,
|
|
|
- },
|
|
|
- useSearchForm: true,
|
|
|
- showTableSetting: true,
|
|
|
- bordered: true,
|
|
|
- showIndexColumn: false,
|
|
|
- actionColumn: {
|
|
|
- width: 200,
|
|
|
- title: '操作',
|
|
|
- dataIndex: 'action',
|
|
|
- slots: { customRender: 'action' },
|
|
|
- fixed: 'right',
|
|
|
- },
|
|
|
- });
|
|
|
- const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
|
|
|
- useBatchDelete(delRole, handleSuccess, setProps);
|
|
|
- selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
|
|
|
- // Demo:status为1的选择框禁用
|
|
|
- if (record.status === 1) {
|
|
|
- return { disabled: true };
|
|
|
- } else {
|
|
|
- return { disabled: false };
|
|
|
- }
|
|
|
- };
|
|
|
- nextTick(() => {
|
|
|
- setProps(selectionOptions);
|
|
|
- });
|
|
|
-
|
|
|
- function handleCreate() {
|
|
|
- openDrawer(true, {
|
|
|
- isUpdate: false,
|
|
|
- });
|
|
|
- }
|
|
|
+<script>
|
|
|
+import { defineComponent, reactive, ref, toRefs, computed, onMounted, watch } from 'vue';
|
|
|
+import ZhiweiDrawer from './ZhiweiDrawer.vue';
|
|
|
+import { structureList, getPostsList, delPosts } from '/@/api/sys/zhiwei';
|
|
|
+import { message } from 'ant-design-vue';
|
|
|
|
|
|
- function handleEdit(record: Recordable) {
|
|
|
- openDrawer(true, {
|
|
|
- record,
|
|
|
- isUpdate: true,
|
|
|
- });
|
|
|
- console.log(record)
|
|
|
- }
|
|
|
-
|
|
|
- const statusChange = async (checked, record) => {
|
|
|
- setProps({
|
|
|
- loading: true,
|
|
|
- });
|
|
|
- setSelectedRowKeys([]);
|
|
|
- resetSelectedRowKeys();
|
|
|
- const newStatus = checked ? 1 : 0;
|
|
|
- const { createMessage } = useMessage();
|
|
|
- try {
|
|
|
- await setRoleStatus(record.id, newStatus);
|
|
|
- if (newStatus) {
|
|
|
- createMessage.success(`启用成功`);
|
|
|
- } else {
|
|
|
- createMessage.success('禁用成功');
|
|
|
+export default defineComponent({
|
|
|
+ name: 'zhiwei',
|
|
|
+ components: { ZhiweiDrawer },
|
|
|
+ setup(props, { emit }) {
|
|
|
+ const drawerRef = ref(null)
|
|
|
+ const data = reactive({
|
|
|
+ replaceFields: {
|
|
|
+ children: 'children',
|
|
|
+ title: 'name',
|
|
|
+ key: 'id'
|
|
|
+ },
|
|
|
+ treeData: [],//单位列表树
|
|
|
+ currentNode: "",//当前选中的树节点
|
|
|
+ posts: {
|
|
|
+ currentId: "",
|
|
|
+ data: []
|
|
|
+ },//职位数据
|
|
|
+ formData: {
|
|
|
+ departid: "",
|
|
|
+ parentId: "",
|
|
|
+ departName: "",
|
|
|
+ orderId: 0,
|
|
|
+ orgId: ""
|
|
|
+ },
|
|
|
+ drawerTitle: '新增职位'
|
|
|
+ });
|
|
|
+ /**
|
|
|
+ * 点击树节点触发
|
|
|
+ */
|
|
|
+ const nodeSelect = (selectkey, { selectedNodes, node }) => {
|
|
|
+ if (node.dataRef.departid === data.currentNode) {
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ data.currentNode = node.dataRef.departid
|
|
|
+ }
|
|
|
+ resetDatas()
|
|
|
+ let params = {
|
|
|
+ departmentId: node.dataRef.departid
|
|
|
+ }
|
|
|
+ getPostsList(params).then(res => {
|
|
|
+ if (res.datas) {
|
|
|
+ data.posts.data = res.datas
|
|
|
+ }
|
|
|
+ })
|
|
|
+ };
|
|
|
+ const resetDatas = () => {
|
|
|
+ data.posts.data = []
|
|
|
+ data.posts.currentId = ""
|
|
|
+ }
|
|
|
+ const chooseHandle = (item) => {
|
|
|
+ if (data.posts.currentId === item.departid) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ data.posts.currentId = item.departid
|
|
|
}
|
|
|
- } finally {
|
|
|
- setProps({
|
|
|
- loading: false,
|
|
|
+ onMounted(() => {
|
|
|
+ structureList().then(res => {
|
|
|
+ res.length && (data.treeData = res)
|
|
|
+ })
|
|
|
});
|
|
|
- reload();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- return {
|
|
|
- registerTable,
|
|
|
- registerDrawer,
|
|
|
- handleCreate,
|
|
|
- handleEdit,
|
|
|
- handleSuccess,
|
|
|
- RoleEnum,
|
|
|
- hasBatchDelete,
|
|
|
- handleDeleteOrBatchDelete,
|
|
|
- statusChange,
|
|
|
- };
|
|
|
- },
|
|
|
+ /**
|
|
|
+ * 对职位的操作
|
|
|
+ */
|
|
|
+ const addHandle = () => {
|
|
|
+ if (data.currentNode === "") {
|
|
|
+ message.error('请先选择机构!')
|
|
|
+ } else {
|
|
|
+ data.formData = {
|
|
|
+ departid: "",
|
|
|
+ parentId: "",
|
|
|
+ departName: "",
|
|
|
+ orderId: data.posts.data.length + 1,
|
|
|
+ orgId: data.currentNode
|
|
|
+ }
|
|
|
+ data.drawerTitle = '新增职位'
|
|
|
+ drawerRef.value.showDrawer()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const editHandle = () => {
|
|
|
+ if (data.currentNode === "") {
|
|
|
+ message.error('请先选择机构!')
|
|
|
+ } else if (data.posts.currentId === "") {
|
|
|
+ message.error('请先选择职位!')
|
|
|
+ } else {
|
|
|
+ data.posts.data.forEach(item => {
|
|
|
+ if (item.departid === data.posts.currentId) {
|
|
|
+ data.formData = {
|
|
|
+ departid: data.posts.currentId,
|
|
|
+ parentId: item.parentId,
|
|
|
+ departName: item.departName,
|
|
|
+ orderId: item.orderId
|
|
|
+ }
|
|
|
+ data.drawerTitle = '修改职位'
|
|
|
+ drawerRef.value.showDrawer()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const delHandle = () => {
|
|
|
+ if (data.currentNode === "") {
|
|
|
+ message.error('请先选择机构!')
|
|
|
+ } else if (data.posts.currentId === "") {
|
|
|
+ message.error('请先选择职位!')
|
|
|
+ } else {
|
|
|
+ let params = {
|
|
|
+ orgId: data.currentNode,
|
|
|
+ departid: data.posts.currentId
|
|
|
+ }
|
|
|
+ delPosts(params).then(res => {
|
|
|
+ if (res.datas === 1) {
|
|
|
+ message.success('操作成功')
|
|
|
+ onSubmit(true)
|
|
|
+ } else {
|
|
|
+ message.error('操作失败')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const onSubmit = (e) => {
|
|
|
+ if (e) {
|
|
|
+ data.posts.data = []
|
|
|
+ data.posts.currentId = ""
|
|
|
+ let params = {
|
|
|
+ departmentId: data.currentNode
|
|
|
+ }
|
|
|
+ getPostsList(params).then(res => {
|
|
|
+ if (res.datas) {
|
|
|
+ data.posts.data = res.datas
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ drawerRef,
|
|
|
+ ...toRefs(data),
|
|
|
+ nodeSelect,
|
|
|
+ chooseHandle,
|
|
|
+ addHandle,
|
|
|
+ editHandle,
|
|
|
+ delHandle,
|
|
|
+ onSubmit
|
|
|
+ };
|
|
|
+ },
|
|
|
});
|
|
|
</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+.p-4 {
|
|
|
+ height: 100%;
|
|
|
+
|
|
|
+ .zhiwei-header {
|
|
|
+ padding: 10px;
|
|
|
+ width: 100%;
|
|
|
+ height: 70px;
|
|
|
+ background-color: #fff;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ .zhiwei-title {
|
|
|
+ font-size: 16px;
|
|
|
+ font-weight: 500;
|
|
|
+ margin-left: 20px;
|
|
|
+ user-select: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ .handle-btns {
|
|
|
+ margin-right: 20px;
|
|
|
+ display: flex;
|
|
|
+
|
|
|
+ .btn {
|
|
|
+ margin-right: 10px;
|
|
|
+
|
|
|
+ &:last-child {
|
|
|
+ margin-right: 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .zhiwei-body {
|
|
|
+ margin-top: 20px;
|
|
|
+ width: 100%;
|
|
|
+ // height: 800px;
|
|
|
+ height: calc(100% - 90px);
|
|
|
+ display: flex;
|
|
|
+
|
|
|
+ .list-items {
|
|
|
+ margin-right: 20px;
|
|
|
+ padding: 10px;
|
|
|
+ height: 100%;
|
|
|
+ overflow: auto;
|
|
|
+ flex: 1;
|
|
|
+ background-color: #fff;
|
|
|
+
|
|
|
+ &:last-child {
|
|
|
+ margin-right: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ .item-title {
|
|
|
+ padding-left: 10px;
|
|
|
+ height: 40px;
|
|
|
+ line-height: 40px;
|
|
|
+ font-size: 16px;
|
|
|
+ background-color: #9eafe7;
|
|
|
+ }
|
|
|
+
|
|
|
+ .item-box {
|
|
|
+ margin-top: 7px;
|
|
|
+
|
|
|
+ .item {
|
|
|
+ width: fit-content;
|
|
|
+ height: 32px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ span {
|
|
|
+ padding: 4px;
|
|
|
+ cursor: pointer;
|
|
|
+ user-select: none;
|
|
|
+
|
|
|
+ &:hover {
|
|
|
+ background-color: #f5f5f5;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .chosed {
|
|
|
+ background-color: #dbedff;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|