mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-08-07 11:25:00 +08:00
manager 升级到vue3
This commit is contained in:
@@ -1,169 +1,108 @@
|
||||
<template>
|
||||
<div class="search">
|
||||
<Card>
|
||||
<Row class="operation">
|
||||
<i-switch v-model="strict" size="large" style="margin-right: 5px">
|
||||
<span slot="open">级联</span>
|
||||
<span slot="close">单选</span>
|
||||
</i-switch>
|
||||
<Button @click="addRoot">添加部门</Button>
|
||||
<Button @click="add" type="primary">添加子部门</Button>
|
||||
<Button @click="delAll">批量删除</Button>
|
||||
<Button @click="getParentList">刷新</Button>
|
||||
</Row>
|
||||
<Row type="flex" justify="start">
|
||||
<Col :md="8" :lg="8" :xl="6">
|
||||
<Alert show-icon>
|
||||
<el-card>
|
||||
<el-row class="operation">
|
||||
<el-switch
|
||||
v-model="strict"
|
||||
active-text="级联"
|
||||
inactive-text="单选"
|
||||
style="margin-right: 5px"
|
||||
/>
|
||||
<el-button @click="addRoot">添加部门</el-button>
|
||||
<el-button type="primary" @click="add">添加子部门</el-button>
|
||||
<el-button @click="delAll">批量删除</el-button>
|
||||
<el-button @click="getParentList">刷新</el-button>
|
||||
</el-row>
|
||||
<el-row type="flex" justify="start">
|
||||
<el-col :md="8" :lg="8" :xl="6">
|
||||
<el-alert type="info" show-icon :closable="false">
|
||||
当前选择编辑:
|
||||
<span class="select-title">{{ editTitle }}</span>
|
||||
<a class="select-clear" v-if="form.id" @click="cancelSelect"
|
||||
>取消选择</a
|
||||
>
|
||||
</Alert>
|
||||
<div class="tree-bar" :style="{ maxHeight: maxHeight }">
|
||||
<Tree
|
||||
ref="tree"
|
||||
<a v-if="form.id" class="select-clear" @click="cancelSelect">取消选择</a>
|
||||
</el-alert>
|
||||
<div v-loading="loading" class="tree-bar" :style="{ maxHeight: maxHeight }">
|
||||
<el-tree
|
||||
ref="treeRef"
|
||||
:data="data"
|
||||
:load-data="loadData"
|
||||
lazy
|
||||
:load="loadNode"
|
||||
:props="treeProps"
|
||||
node-key="id"
|
||||
show-checkbox
|
||||
@on-check-change="changeSelect"
|
||||
@on-select-change="selectTree"
|
||||
highlight-current
|
||||
:check-strictly="!strict"
|
||||
></Tree>
|
||||
<Spin size="large" fix v-if="loading"></Spin>
|
||||
:current-node-key="currentNodeKey"
|
||||
@node-click="onNodeClick"
|
||||
@check="onCheckChange"
|
||||
/>
|
||||
</div>
|
||||
</Col>
|
||||
<Col :md="15" :lg="13" :xl="9" style="margin-left: 10px">
|
||||
<Form
|
||||
ref="form"
|
||||
:model="form"
|
||||
:label-width="100"
|
||||
:rules="formValidate"
|
||||
>
|
||||
<!-- <FormItem label="上级部门" prop="parentTitle">
|
||||
<div style="display: flex">
|
||||
<Input
|
||||
v-model="form.parentTitle"
|
||||
readonly
|
||||
style="margin-right: 10px"
|
||||
/>
|
||||
<Poptip
|
||||
transfer
|
||||
trigger="click"
|
||||
placement="right-start"
|
||||
title="选择上级部门"
|
||||
width="250"
|
||||
>
|
||||
<Button icon="md-list">选择部门</Button>
|
||||
<div
|
||||
slot="content"
|
||||
style="position: relative; min-height: 5vh"
|
||||
>
|
||||
<Tree
|
||||
:data="dataEdit"
|
||||
:load-data="loadData"
|
||||
@on-select-change="selectTreeEdit"
|
||||
></Tree>
|
||||
<Spin size="large" fix v-if="loadingEdit"></Spin>
|
||||
</div>
|
||||
</Poptip>
|
||||
</div>
|
||||
</FormItem> -->
|
||||
<FormItem label="部门名称" prop="title">
|
||||
<Input v-model="form.title" />
|
||||
</FormItem>
|
||||
<FormItem label="选择角色">
|
||||
<Select
|
||||
:loading="userLoading"
|
||||
not-found-text="暂无角色"
|
||||
</el-col>
|
||||
<el-col :md="15" :lg="13" :xl="9" style="margin-left: 10px">
|
||||
<el-form ref="form" :model="form" label-width="100px" :rules="formValidate">
|
||||
<el-form-item label="部门名称" prop="title">
|
||||
<el-input v-model="form.title" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选择角色">
|
||||
<el-select
|
||||
v-model="selectedRole"
|
||||
multiple
|
||||
:loading="userLoading"
|
||||
placeholder="请选择角色"
|
||||
style="width: 100%"
|
||||
>
|
||||
<Option v-for="item in users" :value="item.id" :key="item.id">{{
|
||||
item.name
|
||||
}}</Option>
|
||||
</Select>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="排序值" prop="sortOrder">
|
||||
<Tooltip
|
||||
trigger="hover"
|
||||
placement="right"
|
||||
content="值越小越靠前,支持小数"
|
||||
>
|
||||
<InputNumber
|
||||
:max="1000"
|
||||
:min="0"
|
||||
v-model="form.sortOrder"
|
||||
></InputNumber>
|
||||
</Tooltip>
|
||||
</FormItem>
|
||||
<!-- <FormItem label="是否启用" prop="status">
|
||||
<i-switch size="large" v-model="form.status" :true-value="0" :false-value="-1">
|
||||
<span slot="open">启用</span>
|
||||
<span slot="close">禁用</span>
|
||||
</i-switch>
|
||||
</FormItem> -->
|
||||
<Form-item>
|
||||
<Button
|
||||
style="margin-right: 5px"
|
||||
@click="submitEdit"
|
||||
:loading="submitLoading"
|
||||
<el-option
|
||||
v-for="item in users"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序值" prop="sortOrder">
|
||||
<el-tooltip placement="right" content="值越小越靠前,支持小数">
|
||||
<el-input-number v-model="form.sortOrder" :max="1000" :min="0" />
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
>修改并保存</Button
|
||||
style="margin-right: 5px"
|
||||
:loading="submitLoading"
|
||||
@click="submitEdit"
|
||||
>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Form-item>
|
||||
</Form>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
修改并保存
|
||||
</el-button>
|
||||
<el-button @click="handleReset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-card>
|
||||
|
||||
<Modal
|
||||
:title="modalTitle"
|
||||
<el-dialog
|
||||
v-model="modalVisible"
|
||||
:mask-closable="false"
|
||||
:width="500"
|
||||
:title="modalTitle"
|
||||
width="500px"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<Form
|
||||
ref="formAdd"
|
||||
:model="formAdd"
|
||||
:label-width="85"
|
||||
:rules="formValidate"
|
||||
>
|
||||
<el-form ref="formAdd" :model="formAdd" label-width="85px" :rules="formValidate">
|
||||
<div v-if="showParent">
|
||||
<FormItem label="上级部门:">{{ form.title }}</FormItem>
|
||||
<el-form-item label="上级部门:">{{ form.title }}</el-form-item>
|
||||
</div>
|
||||
<FormItem label="部门名称" prop="title">
|
||||
<Input v-model="formAdd.title" />
|
||||
</FormItem>
|
||||
<FormItem label="排序值" prop="sortOrder">
|
||||
<Tooltip
|
||||
trigger="hover"
|
||||
placement="right"
|
||||
content="值越小越靠前,支持小数"
|
||||
>
|
||||
<InputNumber
|
||||
:max="1000"
|
||||
:min="0"
|
||||
v-model="formAdd.sortOrder"
|
||||
></InputNumber>
|
||||
</Tooltip>
|
||||
</FormItem>
|
||||
<!-- <FormItem label="是否启用" prop="status">
|
||||
<i-switch size="large" v-model="formAdd.status" :true-value="0" :false-value="-1">
|
||||
<span slot="open">启用</span>
|
||||
<span slot="close">禁用</span>
|
||||
</i-switch>
|
||||
</FormItem> -->
|
||||
</Form>
|
||||
<div slot="footer">
|
||||
<Button type="text" @click="cancelAdd">取消</Button>
|
||||
<Button type="primary" :loading="submitLoading" @click="submitAdd"
|
||||
>提交</Button
|
||||
>
|
||||
</div>
|
||||
</Modal>
|
||||
<el-form-item label="部门名称" prop="title">
|
||||
<el-input v-model="formAdd.title" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序值" prop="sortOrder">
|
||||
<el-tooltip placement="right" content="值越小越靠前,支持小数">
|
||||
<el-input-number v-model="formAdd.sortOrder" :max="1000" :min="0" />
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="cancelAdd">取消</el-button>
|
||||
<el-button type="primary" :loading="submitLoading" @click="submitAdd">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -178,25 +117,31 @@ import {
|
||||
getRoleList,
|
||||
updateDepartmentRole,
|
||||
} from "@/api/index";
|
||||
|
||||
export default {
|
||||
name: "department-manage",
|
||||
data() {
|
||||
return {
|
||||
loading: true, // 加载状态
|
||||
maxHeight: "500px", // 最大高度
|
||||
strict: true, // 级联还是单选
|
||||
userLoading: false, // 选择角色加载状态
|
||||
loadingEdit: false, // 编辑加载状态
|
||||
modalVisible: false, // modal显隐
|
||||
selectList: [], // 已选列表
|
||||
selectCount: 0, // 已选总数
|
||||
showParent: false, // 展示父级
|
||||
modalTitle: "", // modal标题
|
||||
editTitle: "", // 编辑标题
|
||||
selectedRole: [], //选择的角色
|
||||
searchKey: "", // 搜索关键字
|
||||
loading: true,
|
||||
maxHeight: "500px",
|
||||
strict: true,
|
||||
userLoading: false,
|
||||
loadingEdit: false,
|
||||
modalVisible: false,
|
||||
selectList: [],
|
||||
selectCount: 0,
|
||||
showParent: false,
|
||||
modalTitle: "",
|
||||
editTitle: "",
|
||||
selectedRole: [],
|
||||
searchKey: "",
|
||||
currentNodeKey: null,
|
||||
treeProps: {
|
||||
label: "title",
|
||||
children: "children",
|
||||
isLeaf: "isLeaf",
|
||||
},
|
||||
form: {
|
||||
// 提交表单
|
||||
id: "",
|
||||
title: "",
|
||||
parentId: "",
|
||||
@@ -204,10 +149,8 @@ export default {
|
||||
sortOrder: 0,
|
||||
status: 0,
|
||||
},
|
||||
|
||||
formAdd: {}, // 新增表单
|
||||
formAdd: {},
|
||||
formValidate: {
|
||||
// 验证规则
|
||||
title: [{ required: true, message: "名称不能为空", trigger: "blur" }],
|
||||
sortOrder: [
|
||||
{
|
||||
@@ -218,17 +161,16 @@ export default {
|
||||
},
|
||||
],
|
||||
},
|
||||
submitLoading: false, // 提交loading
|
||||
data: [], // 部门数据
|
||||
dataEdit: [], // 编辑时部门数据
|
||||
users: [], // 用户
|
||||
submitLoading: false,
|
||||
data: [],
|
||||
dataEdit: [],
|
||||
users: [],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
this.getParentList();
|
||||
},
|
||||
// 获取部门数据
|
||||
getParentList() {
|
||||
this.loading = true;
|
||||
initDepartment().then((res) => {
|
||||
@@ -238,61 +180,60 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
// 动态加载二级数据
|
||||
loadData(item, callback) {
|
||||
loadDepartment(item.id).then((res) => {
|
||||
loadNode(node, resolve) {
|
||||
const id = node.data?.id;
|
||||
if (id === undefined || id === null) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
loadDepartment(id).then((res) => {
|
||||
this.loadingEdit = false;
|
||||
if (res.success) {
|
||||
console.log(res.result);
|
||||
callback(res.result);
|
||||
resolve(res.result || []);
|
||||
} else {
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 点击树
|
||||
selectTree(v) {
|
||||
if (v.length > 0) {
|
||||
// 转换null为""
|
||||
for (let attr in v[0]) {
|
||||
if (v[0][attr] == null) {
|
||||
v[0][attr] = "";
|
||||
}
|
||||
}
|
||||
let str = JSON.stringify(v[0]);
|
||||
let data = JSON.parse(str);
|
||||
|
||||
this.editTitle = data.title;
|
||||
// 加载部门用户数据
|
||||
this.userLoading = true;
|
||||
|
||||
getUserByDepartmentId(data.id).then((res) => {
|
||||
let way = [];
|
||||
res.result &&
|
||||
res.result.forEach((item) => {
|
||||
way.push(item.roleId);
|
||||
});
|
||||
this.$set(this, "selectedRole", way);
|
||||
console.warn(this.selectedRole);
|
||||
});
|
||||
|
||||
getRoleList({
|
||||
pageNumber: 1,
|
||||
pageSize: 10000,
|
||||
}).then((res) => {
|
||||
this.userLoading = false;
|
||||
console.log(res);
|
||||
if (res.success) {
|
||||
this.users = res.result.records;
|
||||
// 回显
|
||||
this.form = data;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
onNodeClick(data) {
|
||||
if (!data) {
|
||||
this.cancelSelect();
|
||||
return;
|
||||
}
|
||||
},
|
||||
const row = JSON.parse(JSON.stringify(data));
|
||||
for (const attr in row) {
|
||||
if (row[attr] == null) {
|
||||
row[attr] = "";
|
||||
}
|
||||
}
|
||||
this.editTitle = row.title;
|
||||
this.currentNodeKey = row.id;
|
||||
this.userLoading = true;
|
||||
|
||||
// 排序
|
||||
getUserByDepartmentId(row.id).then((res) => {
|
||||
const way = [];
|
||||
res.result &&
|
||||
res.result.forEach((item) => {
|
||||
way.push(item.roleId);
|
||||
});
|
||||
this.selectedRole = way;
|
||||
});
|
||||
|
||||
getRoleList({
|
||||
pageNumber: 1,
|
||||
pageSize: 10000,
|
||||
}).then((res) => {
|
||||
this.userLoading = false;
|
||||
if (res.success) {
|
||||
this.users = res.result.records;
|
||||
this.form = row;
|
||||
}
|
||||
});
|
||||
},
|
||||
onCheckChange(_data, { checkedNodes }) {
|
||||
this.selectList = checkedNodes;
|
||||
this.selectCount = checkedNodes.length;
|
||||
},
|
||||
bubbleSort(array) {
|
||||
const len = array.length;
|
||||
if (len < 2) return array;
|
||||
@@ -307,42 +248,33 @@ export default {
|
||||
}
|
||||
return array;
|
||||
},
|
||||
|
||||
// 取消选择
|
||||
cancelSelect() {
|
||||
let data = this.$refs.tree.getSelectedNodes()[0];
|
||||
if (data) {
|
||||
data.selected = false;
|
||||
}
|
||||
this.$refs.treeRef?.setCurrentKey(null);
|
||||
this.currentNodeKey = null;
|
||||
this.$refs.form.resetFields();
|
||||
delete this.form.id;
|
||||
this.editTitle = "";
|
||||
this.selectedRole = [];
|
||||
},
|
||||
// 选择上级部门
|
||||
selectTreeEdit(v) {
|
||||
if (v.length > 0) {
|
||||
// 转换null为""
|
||||
for (let attr in v[0]) {
|
||||
for (const attr in v[0]) {
|
||||
if (v[0][attr] == null) {
|
||||
v[0][attr] = "";
|
||||
}
|
||||
}
|
||||
let str = JSON.stringify(v[0]);
|
||||
let data = JSON.parse(str);
|
||||
const data = JSON.parse(JSON.stringify(v[0]));
|
||||
this.form.parentId = data.id;
|
||||
this.form.parentTitle = data.title;
|
||||
}
|
||||
},
|
||||
// 取消添加部门
|
||||
cancelAdd() {
|
||||
this.modalVisible = false;
|
||||
},
|
||||
// 重置表单
|
||||
handleReset() {
|
||||
this.$refs.form.resetFields();
|
||||
this.form.status = 0;
|
||||
},
|
||||
// 提交表单
|
||||
submitEdit() {
|
||||
this.$refs.form.validate((valid) => {
|
||||
if (valid) {
|
||||
@@ -350,13 +282,12 @@ export default {
|
||||
this.$Message.warning("请先点击选择要修改的部门");
|
||||
return;
|
||||
}
|
||||
let roleWay = [];
|
||||
const roleWay = [];
|
||||
this.selectedRole.forEach((item) => {
|
||||
let role = {
|
||||
roleWay.push({
|
||||
departmentId: this.form.id,
|
||||
roleId: item,
|
||||
};
|
||||
roleWay.push(role);
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all([
|
||||
@@ -373,7 +304,6 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
// 确认添加部门
|
||||
submitAdd() {
|
||||
this.$refs.formAdd.validate((valid) => {
|
||||
if (valid) {
|
||||
@@ -389,7 +319,6 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
// 添加子部门
|
||||
add() {
|
||||
if (this.form.id == "" || this.form.id == null) {
|
||||
this.$Message.warning("请先点击选择一个部门");
|
||||
@@ -397,7 +326,6 @@ export default {
|
||||
}
|
||||
this.modalTitle = "添加子部门";
|
||||
this.showParent = true;
|
||||
|
||||
this.formAdd = {
|
||||
parentId: this.form.id,
|
||||
sortOrder: 0,
|
||||
@@ -405,7 +333,6 @@ export default {
|
||||
};
|
||||
this.modalVisible = true;
|
||||
},
|
||||
// 添加一级部门
|
||||
addRoot() {
|
||||
this.modalTitle = "添加一级部门";
|
||||
this.showParent = false;
|
||||
@@ -416,13 +343,6 @@ export default {
|
||||
};
|
||||
this.modalVisible = true;
|
||||
},
|
||||
// 选中回调
|
||||
changeSelect(v) {
|
||||
console.log(v);
|
||||
this.selectCount = v.length;
|
||||
this.selectList = v;
|
||||
},
|
||||
// 批量删除部门
|
||||
delAll() {
|
||||
if (this.selectCount <= 0) {
|
||||
this.$Message.warning("您还未勾选要删除的数据");
|
||||
@@ -454,13 +374,13 @@ export default {
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
// 计算高度
|
||||
let height = document.documentElement.clientHeight;
|
||||
const height = document.documentElement.clientHeight;
|
||||
this.maxHeight = Number(height - 287) + "px";
|
||||
this.init();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import "@/styles/tree-common.scss";
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user