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.

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