starwork_flutter/lib/views/team/roleManage/role_manage_view.dart

346 lines
11 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:starwork_flutter/api/model/team/response/role_list_response.dart';
import 'package:starwork_flutter/common/constant/app_colors.dart';
import 'package:starwork_flutter/common/widgets/custome_app_bar_wdiget.dart';
import 'package:starwork_flutter/extension/function_extension.dart';
import 'package:starwork_flutter/routes/app_routes.dart';
import 'role_manage_controller.dart';
class RoleManageView extends GetView<RoleManageController> {
@override
Widget build(BuildContext context) {
// 即使不使用,只是引用一下 controller 就能触发初始化
final _ = controller; // 添加这一行
return Scaffold(
backgroundColor: AppColors.scaffoldBackgroundColor,
appBar: CustomAppBarWidget(
title: '角色分配'.tr,
backgroundColor: AppColors.scaffoldBackgroundColor,
),
body: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 10.w,
),
child: Column(
children: [
Row(
children: [
RichText(
text: TextSpan(
children: [
TextSpan(
text: '超级管理员'.tr,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
const TextSpan(
text: ' ',
),
TextSpan(
text: '具有团队全部管理权限'.tr,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.grey[500],
),
),
],
),
)
],
),
SizedBox(
height: 10.h,
),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8.r),
),
padding: EdgeInsets.symmetric(
horizontal: 10.w,
vertical: 10.h,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Obx(
() => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
controller.cacheUserInfo.value.nickname ?? '',
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
Text(
controller.cacheUserInfo.value.accountNo ?? '',
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.grey[500],
),
),
],
),
),
ElevatedButton(
onPressed: () {
controller.showFunctionNotOpen();
}.debounce(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
),
child: Text(
'转让'.tr,
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
)
],
),
),
SizedBox(
height: 10.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: TextSpan(
children: [
TextSpan(
text: '角色'.tr,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
const TextSpan(
text: ' ',
),
TextSpan(
text: '用于给其他用户快捷分配权限'.tr,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.grey[500],
),
),
],
),
),
GestureDetector(
onTap: () async {
var result = await Get.toNamed(AppRoutes.teamAddRole);
if (result != null && result == true) {
controller.requestRoleList();
}
},
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'新建角色',
style: TextStyle(
fontSize: 14.sp,
color: Colors.blue,
),
),
],
),
),
],
),
SizedBox(
height: 10.h,
),
_buildRoleList(),
],
),
),
),
);
}
_buildRoleList() {
return Obx(
() => Flexible(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8.r),
),
child: ListView.separated(
shrinkWrap: true,
itemCount: controller.roleList.length,
itemBuilder: (context, index) {
RoleListResponse role = controller.roleList[index];
return _buildRoleItem(role);
},
separatorBuilder: (context, index) {
return Padding(
padding: EdgeInsets.symmetric(
horizontal: 10.w,
),
child: Divider(
height: 0.5.h,
thickness: 0.5.h,
color: Colors.grey[100],
),
);
},
),
),
),
);
}
_buildRoleItem(RoleListResponse role) {
// 假设 role 对象中有 personList 字段,且每个 person 有 personName 属性
// 如果数据结构不同,请根据实际情况调整
String personNames = '';
// 示例:如果 role.personList 存在且不为空
if (role.personList != null && role.personList!.isNotEmpty) {
// 提取所有 personName 并用逗号连接
personNames = role.personList!.map((person) => person.personName ?? '').join(','); // 使用顿号或逗号分隔
} else {
// 默认值或空值处理
personNames = '暂无用户';
}
return Container(
width: double.infinity,
padding: EdgeInsets.symmetric(
horizontal: 10.w,
vertical: 10.h,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(
Icons.group_rounded,
color: Colors.blue,
),
SizedBox(
width: 6.w,
),
Text(
role.roleName ?? '',
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w600,
),
),
const Spacer(),
Icon(
Icons.arrow_forward_ios_rounded,
color: Colors.grey,
size: 16.sp,
)
],
),
SizedBox(
height: 10.h,
),
RichText(
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
text: TextSpan(
children: [
TextSpan(
text: '角色用户:'.tr,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.grey[500],
),
),
TextSpan(
text: personNames,
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w400,
color: Colors.black,
),
)
],
),
),
RichText(
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
text: TextSpan(
children: [
TextSpan(
text: '分配权限:'.tr,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.grey[500],
),
),
TextSpan(
text: '全部权限'.tr,
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w400,
color: Colors.black,
),
)
],
),
),
RichText(
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
text: TextSpan(
children: [
TextSpan(
text: '角色描述:'.tr,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Colors.grey[500],
),
),
TextSpan(
text: role.roleDesc ?? '',
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w400,
color: Colors.black,
),
)
],
),
)
],
),
);
}
}