2024-04-10 17:08:26 +08:00
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:sk_base_mobile/apis/api.dart';
|
|
|
|
import 'package:sk_base_mobile/models/resource.model.dart';
|
|
|
|
import 'package:sk_base_mobile/store/auth.store.dart';
|
|
|
|
import 'package:sk_base_mobile/util/logger_util.dart';
|
|
|
|
|
|
|
|
class ResourceService extends GetxService {
|
|
|
|
static ResourceService get to => Get.find();
|
|
|
|
Future<ResourceService> init() async {
|
|
|
|
if (AuthStore.to.userInfo.value.id == null) return this;
|
|
|
|
|
|
|
|
await getResources();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
RxList<ResourceModel> resources = RxList([]);
|
|
|
|
Future<void> getResources() async {
|
|
|
|
try {
|
|
|
|
final response = await Api.getResources();
|
2024-04-10 17:38:23 +08:00
|
|
|
final appResources = (response.data as List)
|
2024-04-10 17:08:26 +08:00
|
|
|
.map((item) => ResourceModel.fromJson(item))
|
2024-04-10 17:38:23 +08:00
|
|
|
.toList()
|
|
|
|
.firstWhereOrNull(
|
|
|
|
(element) => element.name == 'App',
|
|
|
|
);
|
|
|
|
if (appResources != null) {
|
|
|
|
resources.assignAll(appResources.children);
|
|
|
|
}
|
2024-04-10 17:08:26 +08:00
|
|
|
} catch (e) {
|
|
|
|
LoggerUtil().error('getResources error: $e');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List<DictItemModel> getDictItemsByCode(String code) {
|
|
|
|
// return dictTypes.firstWhereOrNull((item) => item.code == code)?.dictItems ??
|
|
|
|
// [];
|
|
|
|
// }
|
|
|
|
}
|