Переглянути джерело

Merge branch 'ZL' into dev

ZL 2 місяців тому
батько
коміт
b95b4270a9

+ 9 - 4
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysRoleController.java

@@ -29,6 +29,7 @@ import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.config.mybatis.MybatisPlusSaasConfig;
 import org.jeecg.modules.base.service.BaseCommonService;
 import org.jeecg.modules.system.entity.*;
+import org.jeecg.modules.system.entity.AppmanageEntity.AppBaseInfo;
 import org.jeecg.modules.system.model.TreeModel;
 import org.jeecg.modules.system.service.*;
 import org.jeecg.modules.system.vo.SysUserRoleCountVo;
@@ -122,7 +123,7 @@ public class SysRoleController {
 	 * @param req
 	 * @return
 	 */
-	@RequiresPermissions("system:role:list")
+//	@RequiresPermissions("system:role:list")
 	@PermissionData
 	@RequestMapping(value = "/listByApp", method = RequestMethod.GET)
 	public Result<IPage<SysRole>> listByApp(SysRole role,
@@ -131,13 +132,17 @@ public class SysRoleController {
 												HttpServletRequest req) {
 
 		Result<IPage<SysRole>> result = new Result<IPage<SysRole>>();
-		if (role.getAppId().isEmpty()){
+		String appId = role.getAppId();
+		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+		Boolean isAdmin = loginUser.getUsername().equals("admin");
+		if (appId==null && !isAdmin){
 			result.setSuccess(true);
 			result.setResult(new Page<SysRole>());
+			return result;
 		}
 		QueryWrapper<SysRole> queryWrapper = QueryGenerator.initQueryWrapper(role, req.getParameterMap());
-		String s = QueryGenerator.installAuthJdbc(SysRole.class);
-		queryWrapper.orderByDesc("create_time");
+
+//		queryWrapper.orderByDesc("create_time");
 		Page<SysRole> page = new Page<SysRole>(pageNo, pageSize);
 		IPage<SysRole> pageList = sysRoleService.page(page, queryWrapper);
 

+ 12 - 10
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/SysPermissionDataRuleMapper.xml

@@ -11,16 +11,18 @@
 			join sys_user_role d on d.role_id = c.id
 			join sys_user e on d.user_id = e.id
 			where e.username = #{username} and b.id =  #{permissionId}
-		<!--update begin Author:lvdandan  Date:20200213 for:加入部门权限 -->
-		union
-		select data_rule_ids
-			from sys_depart_role_permission a
-			join sys_permission b on a.permission_id = b.id
-			join sys_depart_role c on a.role_id = c.id
-			join sys_depart_role_user d on d.drole_id = c.id
-			join sys_user e on d.user_id = e.id
-			where e.username = #{username} and b.id = #{permissionId}
-		<!--update end Author:lvdandan  Date:20200213 for:加入部门权限 -->
+
+		<!-- 修改为加入用户独立数据权限 -->
+		UNION
+		SELECT
+		data_rule_ids
+		FROM
+		sys_user_permission a
+		JOIN sys_permission b ON a.permission_id = b.id
+		JOIN sys_user e ON a.user_id = e.id
+		WHERE
+		e.username = #{username} and b.id =  #{permissionId}
+		<!-- 修改为加入用户独立数据权限 -->
 	</select>
 
 </mapper>

+ 4 - 5
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/AppmanageServiceImpl.java

@@ -653,18 +653,17 @@ public class AppmanageServiceImpl implements AppmanageService {
     public List<AppBaseInfo> appList() {
         String sql = QueryGenerator.installAuthJdbc(AppBaseInfo.class);
         //对sql进行处理避免注入
-        StringBuilder inSql = new StringBuilder("AND id IN (");
-        System.out.println("sql----------------------->"
-                +sql);
         if (sql.startsWith(" and id in (")&& sql.endsWith(")")){
+            StringBuilder inSql = new StringBuilder("AND id IN (");
             String inClause = sql.substring(" and id in (".length(), sql.length() - 1);
             List<String> ids = Arrays.asList(inClause.split(","));
             if (!ids.isEmpty()){
                 ids.forEach(id -> inSql.append(id).append(","));
                 inSql.deleteCharAt(inSql.length() - 1);
             }else inSql.append(inClause);
+            inSql .append(") ");
+            return baseInfoMapper.appList(inSql.toString());
         }
-        inSql .append(") ");
-        return baseInfoMapper.appList(inSql.toString());
+        return baseInfoMapper.appList("");
     }
 }

+ 28 - 6
jeecgboot-vue3/src/views/system/menu/components/DataRuleDrawer.vue

@@ -10,7 +10,17 @@
 
             <a-col :span="24">
               <div style="width: 100%; margin-top: 15px">
-                <a-button @click="saveDataRuleForRole" type="primary" size="small"> <Icon icon="ant-design:save-outlined"></Icon>点击保存</a-button>
+                <a-popconfirm
+                  title="请注意,现未勾选任何数据权限!"
+                  :open="visible"
+                  @confirm="saveDataRuleForRole"
+                  @cancel="cancel"
+                  @openChange="handleVisibleChange"
+                >
+                <a-button  type="primary" size="small"> <Icon icon="ant-design:save-outlined"></Icon>点击保存</a-button>
+
+                  </a-popconfirm
+                >
               </div>
             </a-col>
           </a-row>
@@ -34,6 +44,10 @@ const selectId = ref('');
 const dataRuleList = ref([]);
 const dataRuleChecked = ref([]);
 const ruleType = ref('');
+const visible = ref<boolean>(false);
+const cancel = () => {
+  visible.value = false;
+};
 /**
  * 数据
  */
@@ -44,8 +58,8 @@ const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (
   functionId.value = data.functionId;
   //角色的id
   selectId.value = data.selectId;
-
   ruleType.value = data.ruleType;
+  visible.value = false;
 
   try {
     let params;
@@ -83,10 +97,7 @@ function reset() {
  * 提交
  */
 async function saveDataRuleForRole() {
-  if (!unref(dataRuleChecked) || unref(dataRuleChecked).length == 0) {
-    createMessage.warning('请注意,现未勾选任何数据权限!');
-    return;
-  }
+  visible.value = false;
   if (!unref(selectId)) {
     createMessage.warning('请先选择配置对象!');
     return;
@@ -111,4 +122,15 @@ async function saveDataRuleForRole() {
   //刷新列表
   emit('success');
 }
+
+const handleVisibleChange = (bool: boolean) => {
+  if(!bool){
+    visible.value = false;
+  }
+  if (!unref(dataRuleChecked) || unref(dataRuleChecked).length == 0 ) {
+    visible.value = true;
+  }else{
+    saveDataRuleForRole();
+  }
+};
 </script>

+ 23 - 5
jeecgboot-vue3/src/views/system/role/index.vue

@@ -35,7 +35,7 @@
   <RoleIndexModal @register="registerIndexModal" />
 </template>
 <script lang="ts" name="system-role" setup>
-import { ref } from 'vue';
+import { ref, onMounted, watch } from 'vue';
 import { BasicTable, TableAction } from '/@/components/Table';
 import { useDrawer } from '/@/components/Drawer';
 import { useModal } from '/@/components/Modal';
@@ -54,6 +54,17 @@ const [registerDrawer, { openDrawer }] = useDrawer();
 const [registerIndexModal, { openModal: openIndexModal }] = useModal();
 const [rolePermissionDrawer, { openDrawer: openRolePermissionDrawer }] = useDrawer();
 const [registerDesc, { openDrawer: openRoleDesc }] = useDrawer();
+const isFirst = ref(true);
+const apps = ref([]);
+onMounted(async () => {
+  apps.value = await appList();
+});
+watch(() => apps.value,(newVal) => {
+    if (newVal.length > 0) {
+      reload();
+    }
+  }
+);
 
 // 列表页面公共参数、方法
 const { prefixCls, tableContext, onImportXls, onExportXls } = useListPage({
@@ -63,6 +74,8 @@ const { prefixCls, tableContext, onImportXls, onExportXls } = useListPage({
     api: list,
     columns: columns,
     striped: true,
+    immediate: false,
+    
     formConfig: {
       labelWidth: 65,
       rowProps: { gutter: 24 },
@@ -77,8 +90,14 @@ const { prefixCls, tableContext, onImportXls, onExportXls } = useListPage({
       column: 'createTime',
       order: 'desc',
     },
+    beforeFetch: async (params) => {
+      if (isFirst.value) {
+        params.appId = apps.value[0].id;
+        isFirst.value = false;
+      }
+    },
     afterFetch: async (record) => {
-      const app = await appList();
+      const app = apps.value;
       record.forEach((item) => {
         // 获取当前角色的appName
         const rightApp = app.find((m) => m.id === item.appId);
@@ -142,7 +161,7 @@ async function batchHandleDelete() {
  * 角色授权弹窗
  */
 function handlePerssion(record) {
-  openRolePermissionDrawer(true, { roleId: record.id,appId: record.appId,appName: record.appName });
+  openRolePermissionDrawer(true, { roleId: record.id, appId: record.appId, appName: record.appName });
 }
 /**
  * 首页配置弹窗
@@ -162,7 +181,7 @@ function handleUser(record) {
  */
 function getTableAction(record) {
   return [
-  {
+    {
       label: '授权',
       onClick: handlePerssion.bind(null, record),
     },
@@ -170,7 +189,6 @@ function getTableAction(record) {
       label: '分配用户',
       onClick: handleUser.bind(null, record),
     },
-    
   ];
 }
 

+ 24 - 22
jeecgboot-vue3/src/views/system/role/role.data.ts

@@ -1,6 +1,7 @@
 
 import { FormSchema } from '/@/components/Table';
 import { isRoleExist } from './role.api';
+import { appList } from '../menu/menu/menu.api';
 export const columns = [
   {
     title: '所属应用',
@@ -51,11 +52,12 @@ export const searchFormSchema: FormSchema[] = [
   {
     label: '应用',
     field: 'appId',
-    component: 'JDictSelectTag',
+    component: 'ApiSelect',
     componentProps: {
-      dictCode: 'app_base_info,name,id',
+      api: appList,
+      labelField: 'name',
+      valueField: 'id',
       placeholder: '请选择应用',
-      
     },
     colProps: { span: 6 },
   },
@@ -92,11 +94,11 @@ export const searchUserFormSchema: FormSchema[] = [
     field: 'deptId',
     label: '部门',
     component: 'JSelectDept',
-    componentProps:{
-      labelKey:'departName',
-      multiple:false,
-      rowKey:'id'
-  },
+    componentProps: {
+      labelKey: 'departName',
+      multiple: false,
+      rowKey: 'id'
+    },
     colProps: { span: 15 },
   },
 ];
@@ -114,11 +116,11 @@ export const searchUsermodelSchema: FormSchema[] = [
     field: 'deptId',
     label: '部门',
     component: 'JSelectDept',
-    componentProps:{
-      labelKey:'departName',
-      multiple:false,
-      rowKey:'id'
-  },
+    componentProps: {
+      labelKey: 'departName',
+      multiple: false,
+      rowKey: 'id'
+    },
     colProps: { span: 12, },
   },
   {
@@ -127,17 +129,17 @@ export const searchUsermodelSchema: FormSchema[] = [
     component: 'Input',
     colProps: { span: 12 },
   },
-  
+
 ];
 
 export const onCleanCode = (formRef: any) => {
   console.log('cleanCode');
-  console.log('formRef.value',formRef);
+  console.log('formRef.value', formRef);
   if (formRef) {
     formRef.setFieldsValue({
       roleCode: '',
     })
-    console.log('formRef.value',formRef.validate);
+    console.log('formRef.value', formRef.validate);
 
   }
 };
@@ -161,7 +163,7 @@ export const formSchema: FormSchema[] = [
         onCleanCode();
       },
     },
-    
+
   },
 
   {
@@ -175,14 +177,14 @@ export const formSchema: FormSchema[] = [
     label: '角色编码',
     required: true,
     component: 'Input',
-    componentProps: {placeholder: '请先选择应用'},
-    
+    componentProps: { placeholder: '请先选择应用' },
+
     dynamicDisabled: ({ values }) => {
       return !values.appId;
     },
     dynamicRules: ({ values, model }) => {
       console.log('values:', values);
-      
+
       return [
         {
           required: true,
@@ -190,14 +192,14 @@ export const formSchema: FormSchema[] = [
             if (!value) {
               return Promise.reject('请输入角色编码');
             }
-            
+
             if (values) {
               // console.log('values:', values.appId);
               // if (!values.appId) {
               //   return Promise.reject('请先选择应用');
               // }
               return new Promise((resolve, reject) => {
-                isRoleExist({ id: model.id, roleCode: value ,appId:model.appId})
+                isRoleExist({ id: model.id, roleCode: value, appId: model.appId })
                   .then((res) => {
                     res.success ? resolve() : reject(res.message || '校验失败');
                   })