feat(permission): 添加权限管理模块
- 添加角色切换按钮
This commit is contained in:
parent
2e7ce3f619
commit
9cd49595db
17103
package-lock.json
generated
Normal file
17103
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
105
src/hooks/table-option.ts
Normal file
105
src/hooks/table-option.ts
Normal file
@ -0,0 +1,105 @@
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import Sortable from 'sortablejs';
|
||||
import { TableColumnData } from '@arco-design/web-vue/es/table/interface';
|
||||
|
||||
type SizeProps = 'mini' | 'small' | 'medium' | 'large';
|
||||
type Column = TableColumnData & { checked?: true };
|
||||
|
||||
export default function useTableOption() {
|
||||
const { t } = useI18n();
|
||||
const cloneColumns = ref<Column[]>([]);
|
||||
const showColumns = ref<Column[]>([]);
|
||||
const size = ref<SizeProps>('medium');
|
||||
|
||||
const densityList = computed(() => [
|
||||
{
|
||||
name: t('searchTable.size.mini'),
|
||||
value: 'mini',
|
||||
},
|
||||
{
|
||||
name: t('searchTable.size.small'),
|
||||
value: 'small',
|
||||
},
|
||||
{
|
||||
name: t('searchTable.size.medium'),
|
||||
value: 'medium',
|
||||
},
|
||||
{
|
||||
name: t('searchTable.size.large'),
|
||||
value: 'large',
|
||||
},
|
||||
]);
|
||||
|
||||
const handleSelectDensity = (
|
||||
val: string | number | Record<string, any> | undefined,
|
||||
e: Event
|
||||
) => {
|
||||
size.value = val as SizeProps;
|
||||
};
|
||||
|
||||
const handleChange = (
|
||||
checked: boolean | (string | boolean | number)[],
|
||||
column: Column,
|
||||
index: number
|
||||
) => {
|
||||
if (!checked) {
|
||||
cloneColumns.value = showColumns.value.filter(
|
||||
(item) => item.dataIndex !== column.dataIndex
|
||||
);
|
||||
} else {
|
||||
cloneColumns.value.splice(index, 0, column);
|
||||
}
|
||||
};
|
||||
const exchangeArray = <T extends Array<any>>(
|
||||
array: T,
|
||||
beforeIdx: number,
|
||||
newIdx: number,
|
||||
isDeep = false
|
||||
): T => {
|
||||
const newArray = isDeep ? cloneDeep(array) : array;
|
||||
if (beforeIdx > -1 && newIdx > -1) {
|
||||
// 先替换后面的,然后拿到替换的结果替换前面的
|
||||
newArray.splice(
|
||||
beforeIdx,
|
||||
1,
|
||||
newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
|
||||
);
|
||||
}
|
||||
return newArray;
|
||||
};
|
||||
|
||||
const popupVisibleChange = (val: boolean) => {
|
||||
if (val) {
|
||||
nextTick(() => {
|
||||
const el = document.getElementById('tableSetting') as HTMLElement;
|
||||
const sortable = new Sortable(el, {
|
||||
onEnd(e: any) {
|
||||
const { oldIndex, newIndex } = e;
|
||||
exchangeArray(cloneColumns.value, oldIndex, newIndex);
|
||||
exchangeArray(showColumns.value, oldIndex, newIndex);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
const deepClone = (val: any) => {
|
||||
cloneColumns.value = cloneDeep(val);
|
||||
cloneColumns.value.forEach((item, index) => {
|
||||
item.checked = true;
|
||||
});
|
||||
showColumns.value = cloneDeep(cloneColumns.value);
|
||||
};
|
||||
return {
|
||||
cloneColumns,
|
||||
showColumns,
|
||||
size,
|
||||
densityList,
|
||||
handleSelectDensity,
|
||||
handleChange,
|
||||
exchangeArray,
|
||||
popupVisibleChange,
|
||||
deepClone,
|
||||
};
|
||||
}
|
137
src/views/system/dept/components/dept-edit.vue
Normal file
137
src/views/system/dept/components/dept-edit.vue
Normal file
@ -0,0 +1,137 @@
|
||||
<template>
|
||||
<a-button v-if="props.isCreate" type="primary" @click="handleClick">
|
||||
<template #icon><icon-plus /></template>
|
||||
{{ modalTitle }}
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="!props.isCreate"
|
||||
type="outline"
|
||||
size="small"
|
||||
:style="{ marginRight: '10px' }"
|
||||
@click="handleClick"
|
||||
>
|
||||
{{ modalTitle }}
|
||||
</a-button>
|
||||
<a-modal
|
||||
width="600px"
|
||||
:visible="visible"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<template #title>{{ modalTitle }}</template>
|
||||
<a-form ref="createEditRef" :model="formData" :style="{ width: '500px' }">
|
||||
<a-form-item field="parentId" label="父部门">
|
||||
<a-tree-select
|
||||
v-model="formData.parentId"
|
||||
:field-names="{
|
||||
key: 'id',
|
||||
title: 'name',
|
||||
children: 'children',
|
||||
}"
|
||||
:data="props.trees as TreeNodeData[]"
|
||||
allow-clear
|
||||
placeholder="请选择父部门 ..."
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
field="name"
|
||||
label="部门名称"
|
||||
:validate-trigger="['change', 'input']"
|
||||
:rules="[{ required: true, message: '部门名称不能为空' }]"
|
||||
>
|
||||
<a-input v-model="formData.name" />
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
field="code"
|
||||
label="部门编码"
|
||||
:validate-trigger="['change', 'input']"
|
||||
:rules="[{ required: true, message: '部门编码不能为空' }]"
|
||||
>
|
||||
<a-input v-model="formData.code" />
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
field="deptSort"
|
||||
label="部门排序"
|
||||
:validate-trigger="['change', 'input']"
|
||||
:rules="[{ required: true, message: '排序不能为空' }]"
|
||||
>
|
||||
<a-input-number v-model="formData.deptSort" :default-value="0" />
|
||||
</a-form-item>
|
||||
<a-form-item field="remark" label="备注">
|
||||
<a-textarea v-model="formData.remark" placeholder="部门备注" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import useVisible from '@/hooks/visible';
|
||||
import { computed, PropType, ref } from 'vue';
|
||||
import { FormInstance } from '@arco-design/web-vue/es/form';
|
||||
import { DeptRecord, create, update } from '@/api/dept';
|
||||
import { Message, TreeNodeData } from '@arco-design/web-vue';
|
||||
|
||||
const props = defineProps({
|
||||
dept: {
|
||||
type: Object as PropType<DeptRecord>,
|
||||
},
|
||||
trees: {
|
||||
type: Array as PropType<TreeNodeData[]>,
|
||||
},
|
||||
isCreate: Boolean,
|
||||
});
|
||||
|
||||
const modalTitle = computed(() => {
|
||||
return props.isCreate ? '新增' : '编辑';
|
||||
});
|
||||
const { visible, setVisible } = useVisible(false);
|
||||
|
||||
const createEditRef = ref<FormInstance>();
|
||||
|
||||
const formData = ref<DeptRecord>({
|
||||
id: undefined,
|
||||
parentId: undefined,
|
||||
name: '',
|
||||
code: '',
|
||||
deptSort: 0,
|
||||
remark: '',
|
||||
...props.dept,
|
||||
});
|
||||
|
||||
const emit = defineEmits(['refresh']);
|
||||
const handleClick = () => {
|
||||
setVisible(true);
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const valid = await createEditRef.value?.validate();
|
||||
if (!valid) {
|
||||
if (props.isCreate) {
|
||||
const res = await create(formData.value);
|
||||
if (res.status === 200) {
|
||||
Message.success({
|
||||
content: `${modalTitle.value}成功`,
|
||||
duration: 5 * 1000,
|
||||
});
|
||||
}
|
||||
createEditRef.value?.resetFields();
|
||||
} else {
|
||||
const res = await update(formData.value);
|
||||
if (res.status === 200) {
|
||||
Message.success({
|
||||
content: `${modalTitle.value}成功`,
|
||||
duration: 5 * 1000,
|
||||
});
|
||||
}
|
||||
}
|
||||
emit('refresh');
|
||||
setVisible(false);
|
||||
}
|
||||
};
|
||||
const handleCancel = async () => {
|
||||
createEditRef.value?.resetFields();
|
||||
setVisible(false);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
280
src/views/system/dept/index.vue
Normal file
280
src/views/system/dept/index.vue
Normal file
@ -0,0 +1,280 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<Breadcrumb :items="['menu.system', 'menu.system.dept']" />
|
||||
<a-card class="general-card" :title="$t('menu.list.searchTable')">
|
||||
<a-row>
|
||||
<a-col :flex="1">
|
||||
<a-form
|
||||
:model="formModel"
|
||||
:label-col-props="{ span: 6 }"
|
||||
:wrapper-col-props="{ span: 18 }"
|
||||
label-align="right"
|
||||
>
|
||||
<a-row :gutter="16">
|
||||
<a-col :span="8">
|
||||
<a-form-item field="title" label="部门名称">
|
||||
<a-input
|
||||
v-model="formModel.name"
|
||||
placeholder="请输入部门名称"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
</a-col>
|
||||
<a-divider style="height: 42px" direction="vertical" />
|
||||
<a-col :flex="'46px'" style="text-align: right">
|
||||
<a-space :size="18">
|
||||
<a-button type="primary" @click="search">
|
||||
<template #icon>
|
||||
<icon-search />
|
||||
</template>
|
||||
{{ $t('searchTable.form.search') }}
|
||||
</a-button>
|
||||
<a-button @click="reset">
|
||||
<template #icon>
|
||||
<icon-refresh />
|
||||
</template>
|
||||
{{ $t('searchTable.form.reset') }}
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-divider style="margin-top: 10px" />
|
||||
<a-row style="margin-bottom: 16px">
|
||||
<a-col :span="12">
|
||||
<a-space>
|
||||
<DeptEdit
|
||||
ref="createRef"
|
||||
:trees="renderData"
|
||||
:is-create="true"
|
||||
@refresh="search"
|
||||
/>
|
||||
</a-space>
|
||||
</a-col>
|
||||
<a-col
|
||||
:span="12"
|
||||
style="display: flex; align-items: center; justify-content: end"
|
||||
>
|
||||
<a-tooltip :content="$t('searchTable.actions.refresh')">
|
||||
<div class="action-icon" @click="search">
|
||||
<icon-refresh size="18" />
|
||||
</div>
|
||||
</a-tooltip>
|
||||
<a-dropdown @select="handleSelectDensity">
|
||||
<a-tooltip :content="$t('searchTable.actions.density')">
|
||||
<div class="action-icon"><icon-line-height size="18" /></div>
|
||||
</a-tooltip>
|
||||
<template #content>
|
||||
<a-doption
|
||||
v-for="item in densityList"
|
||||
:key="item.value"
|
||||
:value="item.value"
|
||||
:class="{ active: item.value === size }"
|
||||
>
|
||||
<span>{{ item.name }}</span>
|
||||
</a-doption>
|
||||
</template>
|
||||
</a-dropdown>
|
||||
<a-tooltip :content="$t('searchTable.actions.columnSetting')">
|
||||
<a-popover
|
||||
trigger="click"
|
||||
position="bl"
|
||||
@popup-visible-change="popupVisibleChange"
|
||||
>
|
||||
<div class="action-icon"><icon-settings size="18" /></div>
|
||||
<template #content>
|
||||
<div id="tableSetting">
|
||||
<div
|
||||
v-for="(item, index) in showColumns"
|
||||
:key="item.dataIndex"
|
||||
class="setting"
|
||||
>
|
||||
<div style="margin-right: 4px; cursor: move">
|
||||
<icon-drag-arrow />
|
||||
</div>
|
||||
<div>
|
||||
<a-checkbox
|
||||
v-model="item.checked"
|
||||
@change="
|
||||
handleChange($event, item as TableColumnData, index)
|
||||
"
|
||||
>
|
||||
</a-checkbox>
|
||||
</div>
|
||||
<div class="title">
|
||||
{{ item.title === '#' ? '序列号' : item.title }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</a-popover>
|
||||
</a-tooltip>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-table
|
||||
row-key="id"
|
||||
:default-expand-all-rows="true"
|
||||
:loading="loading"
|
||||
:columns="(cloneColumns as TableColumnData[])"
|
||||
:data="renderData"
|
||||
:bordered="false"
|
||||
:size="size"
|
||||
>
|
||||
<template #operations="{ record }">
|
||||
<DeptEdit
|
||||
ref="editRef"
|
||||
:dept="record"
|
||||
:trees="renderData"
|
||||
:is-create="false"
|
||||
@refresh="search"
|
||||
/>
|
||||
<a-popconfirm
|
||||
content="确认删除此部门?"
|
||||
type="error"
|
||||
@ok="handleDelete(record)"
|
||||
>
|
||||
<a-button type="outline" size="small" status="danger">
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import useTableOption from '@/hooks/table-option'
|
||||
import { DeptRecord, getDeptTree, remove } from '@/api/dept';
|
||||
import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
|
||||
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import DeptEdit from './components/dept-edit.vue';
|
||||
|
||||
const { loading, setLoading } = useLoading(true);
|
||||
|
||||
const {
|
||||
cloneColumns,
|
||||
showColumns,
|
||||
size,
|
||||
densityList,
|
||||
handleSelectDensity,
|
||||
handleChange,
|
||||
popupVisibleChange,
|
||||
deepClone,
|
||||
} = useTableOption();
|
||||
|
||||
const generateFormModel = () => {
|
||||
return {
|
||||
name: '',
|
||||
code: '',
|
||||
};
|
||||
};
|
||||
|
||||
const { t } = useI18n();
|
||||
const renderData = ref<DeptRecord[]>([]);
|
||||
const formModel = ref(generateFormModel());
|
||||
const columns = computed<TableColumnData[]>(() => [
|
||||
{
|
||||
title: t('searchTable.columns.index'),
|
||||
dataIndex: 'id',
|
||||
slotName: 'index',
|
||||
},
|
||||
{
|
||||
title: '部门名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '部门编码',
|
||||
dataIndex: 'code',
|
||||
},
|
||||
{
|
||||
title: '部门排序',
|
||||
dataIndex: 'deptSort',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
},
|
||||
{
|
||||
title: t('searchTable.columns.operations'),
|
||||
dataIndex: 'operations',
|
||||
slotName: 'operations',
|
||||
},
|
||||
]);
|
||||
const fetchData = async (params?: Partial<DeptRecord>) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await getDeptTree(params);
|
||||
const { data } = res;
|
||||
renderData.value = data;
|
||||
} catch (err) {
|
||||
// you can report use errorHandler or other
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const search = () => {
|
||||
fetchData({
|
||||
...formModel.value,
|
||||
});
|
||||
};
|
||||
|
||||
fetchData();
|
||||
const reset = () => {
|
||||
formModel.value = generateFormModel();
|
||||
};
|
||||
|
||||
const handleDelete = async (record: DeptRecord) => {
|
||||
const res = await remove(record.id as number);
|
||||
if (res.status === 200) {
|
||||
Message.success({
|
||||
content: '删除成功',
|
||||
duration: 5 * 1000,
|
||||
});
|
||||
search();
|
||||
}
|
||||
};
|
||||
watch(() => columns.value, deepClone, { deep: true, immediate: true });
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'Dept',
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.container {
|
||||
padding: 0 20px 20px 20px;
|
||||
}
|
||||
:deep(.arco-table-th) {
|
||||
&:last-child {
|
||||
.arco-table-th-item-title {
|
||||
margin-left: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.action-icon {
|
||||
margin-left: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.active {
|
||||
color: #0960bd;
|
||||
background-color: #e3f4fc;
|
||||
}
|
||||
.setting {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 200px;
|
||||
.title {
|
||||
margin-left: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user