197 lines
5.9 KiB
Dart
197 lines
5.9 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:common_utils/common_utils.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
class PanelController extends GetxController {
|
|
PanelController();
|
|
|
|
static const String _tag = "菜单页面 Controller";
|
|
|
|
RxList<PanelItem> panelBtnList = <PanelItem>[
|
|
PanelItem(title: "购买", visible: false, type: PanelType.supermarketOrder),
|
|
PanelItem(title: "点餐", visible: false, type: PanelType.canteenOrder),
|
|
PanelItem(title: "预定", visible: false, type: PanelType.canteenReserve),
|
|
PanelItem(title: "核销", visible: false, type: PanelType.takeFood),
|
|
PanelItem(title: "交易查询", visible: true, type: PanelType.orderHistory),
|
|
PanelItem(title: "交易统计", visible: false, type: PanelType.canteenOrderTotal),
|
|
PanelItem(title: "开卡管理", visible: true, type: PanelType.cardActive),
|
|
PanelItem(title: "设置", visible: true, type: PanelType.setting),
|
|
PanelItem(title: "退出登录", visible: true, type: PanelType.logout),
|
|
// PanelItem(title: "测试", visible: true, type: PanelType.test),
|
|
].obs;
|
|
|
|
final canteenMenus = [
|
|
PanelType.canteenOrder,
|
|
PanelType.takeFood,
|
|
PanelType.canteenReserve,
|
|
PanelType.canteenOrderTotal,
|
|
];
|
|
|
|
final supermarketMenus = [
|
|
PanelType.supermarketOrder,
|
|
PanelType.takeFood,
|
|
];
|
|
|
|
final appC = Get.find<AppControl>();
|
|
|
|
late StreamSubscription mqUpdateListen;
|
|
|
|
late StreamSubscription<GlobalRouter> routerBus;
|
|
|
|
@override
|
|
void onInit() async {
|
|
super.onInit();
|
|
// 更新菜单
|
|
await _updateMenus();
|
|
routerBus = GlobalRouteObserver.globalRouteObserverBus
|
|
.on<GlobalRouter>()
|
|
.listen((event) => _updateMenus());
|
|
mqUpdateListen = appC.mqUpdateEventBus.on<MqtActionEnum>().listen(
|
|
(event) async {
|
|
if (event == MqtActionEnum.CONFIG) {
|
|
EasyLoading.show(
|
|
status: '配置修改中...',
|
|
maskType: EasyLoadingMaskType.black,
|
|
);
|
|
try {
|
|
await _updateMenus();
|
|
} finally {
|
|
EasyLoading.dismiss();
|
|
}
|
|
}
|
|
},
|
|
);
|
|
logger.i("菜单页面 Controller 初始化完成");
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
_initData();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
mqUpdateListen.cancel();
|
|
routerBus.cancel();
|
|
}
|
|
|
|
_initData() async {
|
|
update(["panel"]);
|
|
}
|
|
|
|
Future<void> doBtn(PanelType type) async {
|
|
final isNetwork = AppNetworkTool.isAutoNetwork();
|
|
// 业务页面统一装载在 /terminal 一级路由的内层 Navigator 中,
|
|
// 通过 arguments 告知终端外壳首次应显示的二级工作区。
|
|
void openTerminal(String route) =>
|
|
Get.toNamed(RouteNames.terminal, arguments: route);
|
|
switch (type) {
|
|
case PanelType.supermarketOrder:
|
|
if (!await _checkIsBind()) return;
|
|
openTerminal(RouteNames.supermarketProduct);
|
|
break;
|
|
case PanelType.canteenOrder:
|
|
if (!await _checkIsBind()) return;
|
|
openTerminal(RouteNames.canteenProduct);
|
|
break;
|
|
case PanelType.canteenReserve:
|
|
if (!await _checkIsBind()) return;
|
|
if (!isNetwork) {
|
|
Toast.error(msg: "请先连接网络");
|
|
return;
|
|
}
|
|
openTerminal(RouteNames.canteenReserve);
|
|
break;
|
|
case PanelType.takeFood:
|
|
if (!await _checkIsBind()) return;
|
|
if (!isNetwork) {
|
|
Toast.error(msg: "请先连接网络");
|
|
return;
|
|
}
|
|
openTerminal(RouteNames.takeFood);
|
|
break;
|
|
case PanelType.orderHistory:
|
|
if (!await _checkIsBind()) return;
|
|
openTerminal(RouteNames.orderHistory);
|
|
break;
|
|
case PanelType.canteenOrderTotal:
|
|
if (!await _checkIsBind()) return;
|
|
if (!isNetwork) {
|
|
Toast.error(msg: "请先连接网络");
|
|
return;
|
|
}
|
|
openTerminal(RouteNames.canteenOrderTotal);
|
|
break;
|
|
case PanelType.setting:
|
|
if (AppSysTool.isProd()) {
|
|
final flag = await settingPasswordDialog(Get.context!);
|
|
if (!flag) return;
|
|
}
|
|
openTerminal(RouteNames.setting);
|
|
break;
|
|
case PanelType.cardActive:
|
|
if (!await _checkIsBind()) return;
|
|
openTerminal(RouteNames.cardActive);
|
|
break;
|
|
case PanelType.logout:
|
|
final isNetwork = AppNetworkTool.isAutoNetwork();
|
|
if (isNetwork) {
|
|
await AppSettingTool.setUserSetting(UserSetting());
|
|
}
|
|
// 已在登录页时不再重复跳转,避免登录页自我替换换出空表单实例。
|
|
if (Get.currentRoute != RouteNames.login) {
|
|
Get.offAndToNamed(RouteNames.login);
|
|
}
|
|
break;
|
|
case PanelType.test:
|
|
final qrData = "?action=hardQrCodePay&orderId=123&mchId=123";
|
|
showQrCodeDialog(
|
|
Get.context!,
|
|
qrData: qrData,
|
|
onFinished: () {},
|
|
);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
Future<bool> _checkIsBind() async {
|
|
final sysSetting = await AppSettingTool.getSysSetting();
|
|
final id = sysSetting.serviceMerchantId;
|
|
if (ObjectUtil.isEmpty(id)) {
|
|
Toast.error(msg: "请前往设置绑定设备");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
Future<void> _updateMenus() async {
|
|
final sysSetting = await AppSettingTool.getSysSetting();
|
|
final sysType = sysSetting.sysType;
|
|
for (final v in panelBtnList) {
|
|
if (canteenMenus.contains(v.type) || supermarketMenus.contains(v.type)) {
|
|
v.visible = false;
|
|
}
|
|
}
|
|
for (final v in panelBtnList) {
|
|
if (sysType == SysType.CANTEEN) {
|
|
if (canteenMenus.contains(v.type)) {
|
|
v.visible = true;
|
|
}
|
|
} else if (sysType == SysType.SUPERMARKET) {
|
|
if (supermarketMenus.contains(v.type)) {
|
|
v.visible = true;
|
|
}
|
|
}
|
|
}
|
|
panelBtnList.refresh();
|
|
}
|
|
}
|