You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

817 lines
27 KiB

3 months ago
3 months ago
3 months ago
3 months ago
4 weeks ago
2 months ago
3 months ago
3 months ago
3 months ago
4 weeks ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 weeks ago
3 months ago
3 months ago
4 weeks ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 weeks ago
2 months ago
3 months ago
3 months ago
4 weeks ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <script setup>
  2. import { nextTick, onMounted, reactive, ref } from 'vue'
  3. import { ElMessage } from 'element-plus'
  4. import _ from 'lodash'
  5. import request from '@/util/http'
  6. import API from '@/util/http'
  7. import { useAdminStore } from "@/store/index.js"
  8. import { storeToRefs } from "pinia"
  9. const adminStore = useAdminStore();
  10. const { adminData, menuTree } = storeToRefs(adminStore);
  11. import { permissionMapping, findMenuById } from "@/utils/menuTreePermission.js"
  12. import { tr } from 'element-plus/es/locales.mjs'
  13. // 表单验证ref
  14. const Ref = ref(null)
  15. const roleData = ref([])
  16. const roleTotal = ref(100)
  17. const treeRef = ref(null)
  18. const admin = ref({
  19. account: '',
  20. market: '',
  21. postiton: ''
  22. })
  23. const role = ref({
  24. name: ''
  25. })
  26. const getRoleObj = ref({
  27. pageNum: 1,
  28. pageSize: 10
  29. })
  30. const permissionAddVisible = ref(false)
  31. const addRole = ref({
  32. roleName: '',
  33. parentId: null,
  34. checkedKeys: [],
  35. market: ''
  36. })
  37. const addRoleMarket = ref([])
  38. const channelList = ref(['美股', '港股', 'hc第一频道'])
  39. const getRoleList = async function (val) {
  40. if (!findMenuById(menuTree.value, permissionMapping.view_role_information)) {
  41. ElMessage.error('无此权限')
  42. return
  43. }
  44. try {
  45. if (typeof val === 'number') {
  46. getRoleObj.value.pageNum = val
  47. }
  48. console.log('搜索参数', getRoleObj.value, role.value)
  49. const result = await request({
  50. url: '/role/selectBy',
  51. data: {
  52. ...getRoleObj.value,
  53. roleVo: {
  54. roleName: role.value.name
  55. }
  56. }
  57. })
  58. roleData.value = result.data.list
  59. console.log('roleData', roleData.value)
  60. roleTotal.value = result.data.total
  61. } catch (error) {
  62. console.log('请求失败', error)
  63. }
  64. }
  65. // 试试D老师的方法
  66. const formatPermissions = (tree) => {
  67. if (!tree || tree.length === 0) return '';
  68. return tree.map(menu => {
  69. const mainMenu = menu.menuName;
  70. const subMenus = menu.children?.map(child => child.menuName) || [];
  71. // 如果有子菜单,显示前2个子菜单名称
  72. if (subMenus.length > 0) {
  73. const maxSub = Math.min(2, subMenus.length);
  74. const subText = subMenus.slice(0, maxSub).join('、');
  75. const moreText = subMenus.length > maxSub ? '...' : '';
  76. return `${mainMenu}+${subText}${moreText}`;
  77. }
  78. // 没有子菜单时只显示主菜单
  79. return mainMenu;
  80. }).join('+');
  81. };
  82. const trimJwCode = () => {
  83. if (admin.value.account) {
  84. admin.value.account = admin.value.account.replace(/\s/g, '');
  85. }
  86. }
  87. const searchRole = function () {
  88. trimJwCode();
  89. getRoleObj.value.pageNum = 1
  90. getRoleList()
  91. }
  92. // 重置
  93. const reset = function () {
  94. admin.value = {}
  95. role.value.name = ''
  96. // 重置页码
  97. getRoleObj.value.pageNum = 1
  98. getRoleList()
  99. }
  100. const RoleArea = ref([])
  101. const getRoleArea = async function () {
  102. try {
  103. const result = await request({
  104. url: '/general/allRoleMarket',
  105. data: {}
  106. })
  107. RoleArea.value = result.data
  108. } catch (error) {
  109. console.log('请求失败', error)
  110. }
  111. }
  112. // 新增角色弹窗
  113. const openPermissionAddVisible = function () {
  114. permissionAddVisible.value = true
  115. getRoles()
  116. getLists()
  117. }
  118. const closePermissionAddVisible = function () {
  119. permissionAddVisible.value = false
  120. Ref.value.resetFields();
  121. getRoleList()
  122. }
  123. // 新增角色初始化
  124. const permissionAddInit = function () {
  125. openPermissionAddVisible()
  126. }
  127. const handleDialogClose = function () {
  128. closePermissionAddVisible()
  129. console.log('hhh');
  130. }
  131. // 权限类别
  132. const permissionList = ref([])
  133. const getRoles = async function () {
  134. try {
  135. const res = await API({ url: '/role/selectAll' })
  136. permissionList.value = res.data.map(item => ({
  137. label: item.roleName,
  138. value: item.id
  139. }))
  140. console.log('权限列表:', permissionList.value)
  141. } catch (error) {
  142. console.error('获取权限列表失败:', error)
  143. }
  144. }
  145. const collectIds = (tree) => {
  146. let ids = [];
  147. tree.forEach((node) => {
  148. ids.push(node.id);
  149. if (node.children && node.children.length > 0) {
  150. ids = ids.concat(collectIds(node.children));
  151. }
  152. });
  153. return ids;
  154. }
  155. //给data数据加上disabled属性,控制是否禁用
  156. function processTreeData(data) {
  157. return data.map(item => ({
  158. ...item,
  159. disabled: item.id != null || item.menuName.includes("敏感权限"), //控制权限显示的条件
  160. children: item.children ? processTreeData(item.children) : []
  161. }));
  162. }
  163. const handleAddRole = async function () {
  164. if (!findMenuById(menuTree.value, permissionMapping.add_role_information)) {
  165. ElMessage.error('无此权限')
  166. return
  167. }
  168. try {
  169. await new Promise((resolve, reject) => {
  170. Ref.value.validate((valid) => {
  171. if (valid) {
  172. resolve(); // 验证通过,继续执行后续代码
  173. } else {
  174. reject(new Error('请检查并完善表单信息')); // 验证失败,抛出错误
  175. }
  176. });
  177. });
  178. addRole.value.roleName = addRole.value.roleName.replace(/\s+/g, '');
  179. console.log('去除角色名空格:', addRole.value.roleName);
  180. // 确保提交时包含所有选中的权限ID(包括父节点)
  181. const finalCheckedKeys = addRole.value.checkedKeys || [];
  182. const res = await API({
  183. url: '/role/add',
  184. data: {
  185. "roleName": addRole.value.roleName,
  186. "menuIds": finalCheckedKeys,
  187. "fatherId": addRole.value.parentId,
  188. "market": addRole.value.market
  189. }
  190. })
  191. if (res.code === 200) {
  192. ElMessage.success('角色' + addRole.value.roleName + '添加成功')
  193. console.log('成功了,看看addRole', addRole.value)
  194. console.log('提交的权限ID列表:', finalCheckedKeys)
  195. closePermissionAddVisible()
  196. } else {
  197. ElMessage.error(res.msg)
  198. }
  199. } catch (error) {
  200. console.log('请求失败', error)
  201. console.log('失败,看看addRole', addRole.value)
  202. }
  203. }
  204. const handleRolePageSizeChange = (val) => {
  205. getRoleObj.value.pageSize = val
  206. getRoleList() // 调用角色管理的查询
  207. }
  208. // 角色管理分页 - 当前页变化
  209. const handleRoleCurrentChange = (val) => {
  210. getRoleObj.value.pageNum = val
  211. getRoleList() // 调用角色管理的查询
  212. }
  213. const data = ref([])
  214. const getLists = async function () {
  215. try {
  216. console.log('addRole.value.roleId', addRole.value.roleId);
  217. let roleId = addRole.value.parentId
  218. if (addRole.value.parentId === null || addRole.value.parentId === undefined) {
  219. roleId = 2
  220. }
  221. const res = await API({
  222. url: '/menu/tree',
  223. data: { id: roleId }
  224. })
  225. data.value = res.data
  226. data.value = filterPermission(data.value)
  227. console.log('看看data', data.value)
  228. console.log('parentID:', addRole.value.parentId, 'roleId:', roleId)
  229. if (addRole.value.parentId && addRole.value.parentId !== 2) {
  230. const result = await API({
  231. url: '/general/roleMarket',
  232. data: { id: addRole.value.parentId }
  233. })
  234. if (result.code === 200) {
  235. if (typeof result.data === 'string' && result.data) {
  236. addRoleMarket.value = result.data.split(',')
  237. addRole.value.market = ''
  238. } else if (Array.isArray(result.data)) {
  239. addRoleMarket.value = result.data
  240. addRole.value.market = ''
  241. } else {
  242. addRoleMarket.value = []
  243. addRole.value.market = ''
  244. }
  245. } else {
  246. ElMessage.error('该上级角色无归属地区')
  247. console.log('该上级角色无归属地区')
  248. }
  249. console.log('addRoleMarket.value', addRoleMarket.value)
  250. } else {
  251. addRoleMarket.value = RoleArea.value
  252. console.log('elseRoleArea', RoleArea);
  253. }
  254. } catch (error) {
  255. console.log('请求失败', error)
  256. }
  257. }
  258. //金豆过滤
  259. const goldenBeanMenuIds = new Set([
  260. permissionMapping.gold_bean_audit,
  261. permissionMapping.gold_bean_recharge,
  262. permissionMapping.gold_bean_consumption,
  263. permissionMapping.gold_bean_customer_details
  264. ])
  265. // 15,43,44,45,46,47,// 金豆审核
  266. // 18,52,53,54,// 金豆充值
  267. // 20,57,58,59,60,// 金豆消耗
  268. // 23// 金豆客户账户明细
  269. const filterGoldenBeanMenus = (tree) => {
  270. return tree
  271. .filter(item => {
  272. // 排除金豆相关的顶层菜单
  273. if (goldenBeanMenuIds.has(item.id)) {
  274. return false
  275. }
  276. // 递归处理子菜单
  277. if (item.children && item.children.length > 0) {
  278. item.children = filterGoldenBeanMenus(item.children)
  279. }
  280. return true
  281. })
  282. }
  283. // 过滤权限模块(????????)俺不会
  284. const filterPermission = (tree) => {
  285. return tree.filter(item => {
  286. if (item.id === permissionMapping.permission_management) {
  287. return false
  288. }
  289. else if (item.children && item.children.length > 0) {
  290. item.children = filterPermission(item.children)
  291. }
  292. return true
  293. })
  294. }
  295. // 处理编辑角色权限时的勾选事件
  296. const handleEditRolePermissionCheck = (checkedNodes, checkedInfo) => {
  297. const { checkedKeys, checkedNodes: allCheckedNodes } = checkedInfo
  298. // 判断是否有选中的节点
  299. if (allCheckedNodes.length === 0) {
  300. permissionEditRoleObj.value.checkedKeys = []
  301. ifHasChannel.value = false
  302. return
  303. }
  304. // 由于设置了 check-strictly="false",Element Plus 会自动处理父子节点联动
  305. // 我们只需要使用 checkedKeys,它已经包含了所有必要的节点ID
  306. permissionEditRoleObj.value.checkedKeys = checkedKeys
  307. console.log('编辑角色选中的权限ID:', checkedKeys)
  308. console.log('选中的节点数量:', allCheckedNodes.length)
  309. if (checkedKeys.includes(124)||checkedKeys.includes(125)||checkedKeys.includes(126)||checkedKeys.includes(127)) {
  310. ifHasChannel.value = true
  311. } else {
  312. ifHasChannel.value = false
  313. }
  314. };
  315. //用于标记是否勾选频道管理
  316. const ifHasChannel = ref(false)
  317. const handleCheckChange = async (checkedNodes, checkedInfo) => {
  318. const { checkedKeys, checkedNodes: allCheckedNodes } = checkedInfo
  319. // 判断是否有选中的节点
  320. if (allCheckedNodes.length === 0) {
  321. addRole.value.checkedKeys = []
  322. ifHasChannel.value = false
  323. return
  324. }
  325. // 创建一个Set存储所有需要选中的ID(包括父级)
  326. const allKeys = new Set(checkedKeys)
  327. // 遍历所有选中的节点,为每个节点添加其父级
  328. allCheckedNodes.forEach(node => {
  329. // 为每个选中的节点单独查找父级
  330. selectParentNodes(data.value, node.id, allKeys)
  331. });
  332. // 将Set转换为数组并更新
  333. addRole.value.checkedKeys = Array.from(allKeys)
  334. console.log('新增角色包含所有父级的选中项:', addRole.value.checkedKeys)
  335. if (addRole.value.checkedKeys.includes(124)) {
  336. ifHasChannel.value = true
  337. console.log('勾选了频道');
  338. } else {
  339. ifHasChannel.value = false
  340. }
  341. }
  342. const selectParentNodes = (treeData, nodeId, checkedKeys) => {
  343. if (!Array.isArray(treeData)) return false
  344. for (const item of treeData) {
  345. // 先检查子节点
  346. if (item.children && item.children.length > 0) {
  347. const foundInChildren = selectParentNodes(item.children, nodeId, checkedKeys);
  348. if (foundInChildren) {
  349. // 找到子节点后添加当前节点(父节点)
  350. checkedKeys.add(item.id);
  351. return true
  352. }
  353. }
  354. // 检查当前节点是否为目标节点
  355. if (item.id === nodeId) {
  356. return true
  357. }
  358. }
  359. return false
  360. };
  361. //点击角色权限菜单树点击展示逻辑
  362. const menuTreeVisible = ref(false)
  363. const currentRoleMenuTree = ref([])
  364. const currentRoleName = ref('')
  365. const Rolecheckedkeys = ref([])
  366. const showMenuTree = (treeData, roleName) => {
  367. currentRoleMenuTree.value = processTreeData(treeData) || [];
  368. console.log('currentRoleMenuTree.value', currentRoleMenuTree.value)
  369. Rolecheckedkeys.value = collectIds(treeData)
  370. console.log('Rolecheckedkeys', Rolecheckedkeys.value)
  371. currentRoleName.value = roleName || '权限详情'
  372. menuTreeVisible.value = true;
  373. }
  374. // 编辑角色对象
  375. const permissionEditRoleObj = ref({
  376. id: null,
  377. roleName: '',
  378. market: '',
  379. parentId: null,
  380. parentName: '',
  381. checkedKeys: []
  382. })
  383. // 编辑角色弹窗
  384. const permissionEditRoleVisible = ref(false)
  385. const collectIds2 = (tree) => {
  386. let ids = []
  387. tree.forEach((node) => {
  388. // 如果当前节点没有 children 或 children 为空,说明是叶子节点
  389. if (!node.children || node.children.length === 0) {
  390. ids.push(node.id)
  391. } else {
  392. // 如果有 children,递归收集子节点的叶子节点
  393. ids = ids.concat(collectIds2(node.children))
  394. }
  395. })
  396. return ids
  397. }
  398. // 编辑角色初始化
  399. const permissionEditRoleInit = async function (row) {
  400. console.log('row', row)
  401. console.log('row.tree', row.tree)
  402. permissionEditRoleObj.value = {}
  403. permissionEditRoleObj.value.id = row.id
  404. permissionEditRoleObj.value.roleName = row.roleName
  405. permissionEditRoleObj.value.market = row.market
  406. permissionEditRoleObj.value.parentId = row.fatherId
  407. permissionEditRoleObj.value.parentName = row.fatherName
  408. try {
  409. let roleId = permissionEditRoleObj.value.parentId;
  410. // 如果没有上级角色,设置为管理员的id
  411. if (permissionEditRoleObj.value.parentId === null || permissionEditRoleObj.value.parentId === undefined) {
  412. roleId = 2;
  413. }
  414. // 调用 /tree 接口,使用上级角色 ID 获取权限列表
  415. const res = await API({
  416. url: '/menu/tree',
  417. data: { id: roleId }
  418. });
  419. data.value = res.data;
  420. data.value = filterPermission(data.value)
  421. //data.value = filterGoldenBeanMenus(data.value);
  422. // 收集当前行权限树的叶子节点id(只收集实际选中的叶子节点)
  423. if (row.tree && row.tree.length > 0) {
  424. const leafIds = collectIds2(row.tree);
  425. permissionEditRoleObj.value.checkedKeys = leafIds;
  426. console.log('编辑角色初始化时的权限列表', permissionEditRoleObj.value.checkedKeys);
  427. } else {
  428. permissionEditRoleObj.value.checkedKeys = [];
  429. }
  430. } catch (error) {
  431. console.log('根据上级角色获取权限列表失败', error);
  432. data.value = [];
  433. permissionEditRoleObj.value.checkedKeys = [];
  434. }
  435. console.log('编辑角色', permissionEditRoleObj.value);
  436. permissionEditRoleVisible.value = true;
  437. // 等待DOM更新后手动设置树的选中状态
  438. await nextTick();
  439. if (treeRef.value && permissionEditRoleObj.value.checkedKeys.length > 0) {
  440. treeRef.value.setCheckedKeys(permissionEditRoleObj.value.checkedKeys);
  441. console.log('手动设置树的选中状态:', permissionEditRoleObj.value.checkedKeys);
  442. }
  443. };
  444. // 编辑角色提交
  445. const permissionEditRole = async function () {
  446. if (!findMenuById(menuTree.value, permissionMapping.edit_role_information)) {
  447. ElMessage.error('无此权限')
  448. return
  449. }
  450. try {
  451. await new Promise((resolve, reject) => {
  452. Ref.value.validate((valid) => {
  453. if (valid) {
  454. resolve();
  455. } else {
  456. reject(new Error('请检查并完善表单信息'));
  457. }
  458. });
  459. });
  460. // 确保提交时包含所有选中的权限ID(包括父节点)
  461. let finalCheckedKeys = permissionEditRoleObj.value.checkedKeys || [];
  462. // 为所有选中的节点添加其父节点ID
  463. const allKeys = new Set(finalCheckedKeys);
  464. finalCheckedKeys.forEach(nodeId => {
  465. selectParentNodesForSubmit(data.value, nodeId, allKeys);
  466. });
  467. finalCheckedKeys = Array.from(allKeys);
  468. const res = await API({
  469. url: '/menu/update',
  470. data: {
  471. "id": permissionEditRoleObj.value.id,
  472. "roleName": permissionEditRoleObj.value.roleName,
  473. "menuIds": finalCheckedKeys,
  474. "fatherId": permissionEditRoleObj.value.parentId,
  475. "market": permissionEditRoleObj.value.market
  476. }
  477. });
  478. if (res.code === 200) {
  479. console.log('编辑角色成功', permissionEditRoleObj.value);
  480. console.log('提交的权限ID列表:', finalCheckedKeys);
  481. permissionEditRoleVisible.value = false;
  482. getRoleList();
  483. ElMessage.success('编辑角色成功');
  484. } else if (res.code === 0) {
  485. console.log('角色名重复', permissionEditRoleObj.value);
  486. ElMessage.error('角色名重复');
  487. } else {
  488. console.log('编辑角色失败', res);
  489. ElMessage.error('编辑角色失败');
  490. }
  491. } catch (error) {
  492. console.log('编辑角色失败', error);
  493. console.log('失败,看看permissionEditRoleObj', permissionEditRoleObj.value);
  494. }
  495. };
  496. // 为提交时查找父节点的辅助函数
  497. const selectParentNodesForSubmit = (treeData, nodeId, checkedKeys) => {
  498. if (!Array.isArray(treeData)) return false;
  499. for (const item of treeData) {
  500. // 先检查子节点
  501. if (item.children && item.children.length > 0) {
  502. const foundInChildren = selectParentNodesForSubmit(item.children, nodeId, checkedKeys);
  503. if (foundInChildren) {
  504. // 找到子节点后添加当前节点(父节点)
  505. checkedKeys.add(item.id);
  506. return true;
  507. }
  508. }
  509. // 检查当前节点是否为目标节点
  510. if (item.id === nodeId) {
  511. return true;
  512. }
  513. }
  514. return false;
  515. };
  516. const Rolerules = reactive({
  517. roleName: [
  518. { required: true, message: '请输入角色名称', trigger: 'blur' },
  519. { min: 2, max: 20, message: '角色名称长度应在2-20个字符之间', trigger: 'blur' }
  520. ],
  521. market: [
  522. { required: true, message: '请选择归属地区', trigger: 'change' }
  523. ],
  524. checkedKeys: [
  525. {
  526. required: true,
  527. message: '请选择权限列表',
  528. trigger: 'change', // 选框变化或提交时触发,可根据实际调整
  529. validator: (rule, value, callback) => {
  530. if (value && value.length > 0) {
  531. callback(); // 有选中项,校验通过
  532. } else {
  533. callback(new Error('请选择权限列表')); // 未选中,抛出错误提示
  534. }
  535. }
  536. }
  537. ]
  538. });
  539. const throttledHandleAddRole = _.throttle(handleAddRole, 5000, {
  540. trailing: false
  541. })
  542. const canLook = findMenuById(menuTree.value, permissionMapping.view_role_information)
  543. const canAdd = findMenuById(menuTree.value, permissionMapping.add_role_information)
  544. const canEdit = findMenuById(menuTree.value, permissionMapping.edit_role_information)
  545. // 挂载
  546. onMounted(async function () {
  547. await getRoleList()
  548. await getRoleArea()
  549. })
  550. </script>
  551. <template>
  552. <div>
  553. <el-card class="card1" style="margin-bottom: 1vh;">
  554. <div style="display: flex;">
  555. <el-text size="large">角色名称</el-text>
  556. <el-input v-model="role.name" style="width: 240px" placeholder="请输入角色名称" clearable />
  557. <div style="margin-left: auto;">
  558. <el-button type="primary" @click="searchRole()" :disabled="!canLook" v-if="canLook">查询</el-button>
  559. <el-button type="success" @click="reset()">重置</el-button>
  560. </div>
  561. </div>
  562. </el-card>
  563. <el-card class="card2">
  564. <div class="add-item">
  565. <el-button style="color: #048efb; border: 1px solid #048efb" @click="permissionAddInit()" :disabled="!canAdd"
  566. v-if="canAdd">新增角色</el-button>
  567. </div>
  568. <div>
  569. <el-table :data="roleData" style="width: 82vw;height:62.3vh" show-overflow-tooltip
  570. :row-style="{ height: '56px' }">
  571. <el-table-column type="index" label="序号" width="100px" fixed="left">
  572. <template #default="scope">
  573. <span>{{
  574. scope.$index + 1 + (getRoleObj.pageNum - 1) * getRoleObj.pageSize
  575. }}</span>
  576. </template>
  577. </el-table-column>
  578. <el-table-column prop="roleName" label="角色名称" />
  579. <el-table-column prop="fatherName" label="上级角色">
  580. <template #default="scope">
  581. {{ scope.row.fatherName || '-' }}
  582. </template>
  583. </el-table-column>
  584. <el-table-column label="权限范围" show-overflow-tooltip>
  585. <template #default="scope">
  586. <div class="permission-cell" @click="showMenuTree(scope.row.tree, scope.row.roleName)">
  587. {{ formatPermissions(scope.row.tree) }}
  588. </div>
  589. </template>
  590. </el-table-column>
  591. <el-table-column prop="operation" label="操作" width="200px">
  592. <template #default="scope">
  593. <el-button type="warning" text @click="permissionEditRoleInit(scope.row)"
  594. :disabled="(scope.row.id === 2) || (scope.row.id === 1) || !canEdit" v-if="canEdit">
  595. 编辑
  596. </el-button>
  597. </template>
  598. </el-table-column>
  599. </el-table>
  600. </div>
  601. <div style="margin-top: 20px;display: flex;">
  602. <el-pagination background :current-page="getRoleObj.pageNum" :page-size="getRoleObj.pageSize"
  603. :page-sizes="[5, 10, 20, 50, 100]" layout="total, sizes, prev, pager, next, jumper" :total="roleTotal"
  604. @size-change="handleRolePageSizeChange" @current-change="handleRoleCurrentChange"></el-pagination>
  605. </div>
  606. </el-card>
  607. </div>
  608. <!-- 角色菜单树展示 -->
  609. <el-dialog v-model="menuTreeVisible" :title='`权限详情:${currentRoleName}`' width="600px">
  610. <el-tree :data="currentRoleMenuTree" node-key="id" :props="{ label: 'menuName', children: 'children' }"
  611. show-checkbox check-strictly :expand-on-click-node="false"
  612. :default-expanded-keys="currentRoleMenuTree.map(item => item.id)" :default-checked-keys="Rolecheckedkeys" />
  613. <template #footer>
  614. <el-button @click="menuTreeVisible = false" type="primary">关闭</el-button>
  615. </template>
  616. </el-dialog>
  617. <!-- 新增角色 -->
  618. <el-dialog v-model="permissionAddVisible" title="新增角色" width="800px" :close-on-click-modal="false"
  619. @close="handleDialogClose">
  620. <template #footer>
  621. <el-form ref="Ref" :rules="Rolerules" :model="addRole" label-width="auto"
  622. style="max-width: 600px; align-items: center">
  623. <el-form-item prop="roleName" label="角色名称:" required>
  624. <el-input v-model="addRole.roleName" placeholder="请输入角色名称" style="width: 220px" />
  625. </el-form-item>
  626. <el-form-item prop="parentName" label="上级角色:">
  627. <el-select v-model="addRole.parentId" placeholder="请选择上级角色" style="width: 220px" @change="getLists" clearable>
  628. <el-option v-for="item in permissionList" :key="item.value" :label="item.label"
  629. :value="item.value"></el-option>
  630. </el-select>
  631. </el-form-item>
  632. <el-form-item prop="market" label="归属地区:" required>
  633. <el-select v-model="addRole.market" placeholder="请选择归属地区" style="width: 220px" clearable>
  634. <el-option v-for="item in addRoleMarket" :key="item" :label="item" :value="item" />
  635. </el-select>
  636. <text>(此地区无实际意义仅用于各分部负责人查看其地区角色)</text>
  637. </el-form-item>
  638. <el-form-item prop="checkedKeys" label="权限列表:" required>
  639. <el-tree v-if="data.length > 0" :data="data" show-checkbox node-key="id"
  640. :props="{ label: 'menuName', children: 'children' }" :checked-keys="addRole.checkedKeys"
  641. :check-strictly="false" @check="handleCheckChange">
  642. <template #default="{ node }">
  643. <span>{{ node.label }}</span>
  644. </template>
  645. </el-tree>
  646. <div v-else style="display: flex; align-items: center; gap: 8px;">
  647. <span style="color: #999;">暂无数据</span>
  648. </div>
  649. </el-form-item>
  650. <el-form-item v-show="ifHasChannel" prop="channel" label="频道名称:" required>
  651. <el-select v-model="addRole.channel" placeholder="请选择频道" style="width: 220px" clearable>
  652. <el-option v-for="item in channelList" :key="item" :label="item" :value="item" />
  653. </el-select>
  654. </el-form-item>
  655. </el-form>
  656. <div>
  657. <el-button @click="closePermissionAddVisible()">取消</el-button>
  658. <el-button type="primary" @click="throttledHandleAddRole">
  659. 提交
  660. </el-button>
  661. </div>
  662. </template>
  663. </el-dialog>
  664. <!-- 編輯角色彈窗 -->
  665. <el-dialog v-model="permissionEditRoleVisible" title="编辑角色" width="800px" :close-on-click-modal="false">
  666. <template #footer>
  667. <el-form ref="Ref" :rules="Rolerules" :model="permissionEditRoleObj" label-width="auto"
  668. style="max-width: 600px; align-items: center">
  669. <el-form-item prop="roleName" label="角色名称:" required>
  670. <el-input v-model="permissionEditRoleObj.roleName" placeholder="请输入角色名称" style="width: 220px" />
  671. </el-form-item>
  672. <el-form-item prop="parentName" label="上级角色:">
  673. <el-input v-model="permissionEditRoleObj.parentName" placeholder="无上级角色" disabled style="width: 220px">
  674. <el-option v-for="item in permissionList" :key="item.value" :label="item.label"
  675. :value="item.value"></el-option>
  676. </el-input>
  677. </el-form-item>
  678. <el-form-item prop="market" label="归属地区" required>
  679. <el-input v-model="permissionEditRoleObj.market" placeholder="请输入归属地区" style="width: 220px" disabled />
  680. <text>(此地区无实际意义仅用于各分部负责人查看其地区角色)</text>
  681. </el-form-item>
  682. <el-form-item prop="checkedKeys" label="权限列表:" required>
  683. <el-tree v-if="data.length > 0" :data="data" show-checkbox node-key="id" ref="treeRef"
  684. :props="{ label: 'menuName', children: 'children' }"
  685. :default-checked-keys="permissionEditRoleObj.checkedKeys" :check-strictly="false"
  686. @check="handleEditRolePermissionCheck">
  687. <!-- <template #default="{ node, data }"> data删掉了不影响功能 -->
  688. <template #default="{ node }">
  689. <span>{{ node.label }}</span>
  690. </template>
  691. </el-tree>
  692. <div v-else style="display: flex; align-items: center; gap: 8px;">
  693. <span style="color: #999;">暂无数据</span>
  694. </div>
  695. </el-form-item>
  696. <el-form-item v-show="ifHasChannel" prop="channel" label="频道名称:" required>
  697. <el-select v-model="permissionEditRoleObj.channel" placeholder="请选择频道" style="width: 220px" clearable>
  698. <el-option v-for="item in channelList" :key="item" :label="item" :value="item" />
  699. </el-select>
  700. </el-form-item>
  701. </el-form>
  702. <div>
  703. <el-button @click="permissionEditRoleVisible = false">取消</el-button>
  704. <el-button type="primary" @click="permissionEditRole">
  705. 提交
  706. </el-button>
  707. </div>
  708. </template>
  709. </el-dialog>
  710. </template>
  711. <style scoped lang="scss">
  712. // 新增用户按钮
  713. .add-item {
  714. margin-bottom: 1vh;
  715. }
  716. // 搜索的卡片样式
  717. .card1 {
  718. background: #F3FAFE;
  719. }
  720. // 表单的卡片样式
  721. .card2 {
  722. background: #E7F4FD;
  723. }
  724. // 表头背景等
  725. :deep(.el-table__header-wrapper),
  726. :deep(.el-table__body-wrapper),
  727. :deep(.el-table__cell),
  728. /* 表格 */
  729. :deep(.el-table__body td) {
  730. background-color: #F3FAFE !important;
  731. }
  732. /* 表头 */
  733. :deep(.el-table__header th) {
  734. background-color: #F3FAFE !important;
  735. }
  736. /* 鼠标悬停 */
  737. :deep(.el-table__row:hover > .el-table__cell) {
  738. background-color: #E5EBFE !important;
  739. }
  740. .head-card {
  741. display: flex;
  742. }
  743. .permission-cell {
  744. cursor: pointer;
  745. color: #409eff;
  746. /* 蓝色文字,提示可点击 */
  747. }
  748. </style>