mobile_skt/lib/store/resource.store.dart

39 lines
1.2 KiB
Dart

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();
final appResources = (response.data as List)
.map((item) => ResourceModel.fromJson(item))
.toList()
.firstWhereOrNull(
(element) => element.name == 'App',
);
if (appResources != null) {
resources.assignAll(appResources.children);
}
} catch (e) {
LoggerUtil().error('getResources error: $e');
}
}
// List<DictItemModel> getDictItemsByCode(String code) {
// return dictTypes.firstWhereOrNull((item) => item.code == code)?.dictItems ??
// [];
// }
}