Browse Source

权限分配

燃气自翻炒锅
pry 9 months ago
parent
commit
a12852a568
11 changed files with 493 additions and 206 deletions
  1. +180
    -77
      app/src/main/java/com/bonait/bnframework/Dialog/DialogManager.java
  2. +7
    -5
      app/src/main/java/com/bonait/bnframework/Dialog/DialogView.java
  3. +57
    -54
      app/src/main/java/com/bonait/bnframework/common/base/BaseFragment.java
  4. +10
    -3
      app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
  5. +9
    -0
      app/src/main/java/com/bonait/bnframework/common/helper/Convert.java
  6. +9
    -0
      app/src/main/java/com/bonait/bnframework/common/model/Authority.java
  7. +4
    -0
      app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java
  8. +11
    -0
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/GongnengFragment.java
  9. +56
    -25
      app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java
  10. +65
    -38
      app/src/main/java/com/bonait/bnframework/modules/mine/fragment/UserActivity.java
  11. +85
    -4
      app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java

+ 180
- 77
app/src/main/java/com/bonait/bnframework/Dialog/DialogManager.java View File

@@ -21,9 +21,14 @@ import com.bonait.bnframework.common.helper.MessageLog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogBuilder;

/**
* 自定义弹框
* 需要在 res->values->styles.xml中添加 custom_dialog2样式
* 需要在layout中添加dialog布局页面
*/
public class DialogManager {

private static DialogView dview;
// private static DialogView dview;

private static Context mContext;

@@ -39,47 +44,50 @@ public class DialogManager {
* */
private static void showDialog(String message, AlertDialogButton btn,DialogType dt, IDialogAction action) {
if(mContext==null) return;
dview=new DialogView(mContext, R.layout.activity_dialog, R.style.custom_dialog2);
if (dview != null) {
if (!dview.isShowing()) {

String btnName1="确定";
String btnName2="取消";
if(btn==AlertDialogButton.YesNoCancel||btn==AlertDialogButton.YesNo){
btnName1="是";
btnName2="否";
try{
DialogView dview=new DialogView(mContext, R.layout.activity_dialog, R.style.custom_dialog2);
if (dview != null) {
if (!dview.isShowing()) {

String btnName1="确定";
String btnName2="取消";
if(btn==AlertDialogButton.YesNoCancel||btn==AlertDialogButton.YesNo){
btnName1="是";
btnName2="否";
}

dview.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框
RelativeLayout rlTitle = (RelativeLayout) dview.findViewById(R.id.rl_title);
if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back);
if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back);
if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back);
TextView Tv=(TextView)dview.findViewById(R.id.tv_Title);
TextView Info=(TextView)dview.findViewById(R.id.tv_Info);
Button ok = (Button)dview.findViewById(R.id.btn_ok);
Button cancel = (Button)dview.findViewById(R.id.btn_cancel);

Tv.setText(dt.toString());
Info.setText(message);
ok.setText(btnName1);
cancel.setText(btnName2);

if(btn==AlertDialogButton.OK)cancel.setVisibility(View.GONE);

ok.setOnClickListener(view->{
if(action!=null)action.ExitDialog(true);
hide(dview);
});

cancel.setOnClickListener(view->{
if(action!=null)action.ExitDialog(false);
hide(dview);
});
dview.show();
}

dview.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框
RelativeLayout rlTitle = (RelativeLayout) dview.findViewById(R.id.rl_title);
if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back);
if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back);
if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back);
TextView Tv=(TextView)dview.findViewById(R.id.tv_Title);
TextView Info=(TextView)dview.findViewById(R.id.tv_Info);
Button ok = (Button)dview.findViewById(R.id.btn_ok);
Button cancel = (Button)dview.findViewById(R.id.btn_cancel);

Tv.setText(dt.toString());
Info.setText(message);
ok.setText(btnName1);
cancel.setText(btnName2);

if(btn==AlertDialogButton.OK)cancel.setVisibility(View.GONE);

ok.setOnClickListener(view->{
if(action!=null)action.ExitDialog(true);
hide(dview);
});

cancel.setOnClickListener(view->{
if(action!=null)action.ExitDialog(false);
hide(dview);
});
dview.show();
}
}catch(Exception e){
MessageLog.ShowError("打开弹框异常:"+e.toString());
}

}

/**
@@ -87,50 +95,107 @@ public class DialogManager {
* */
private static void showDialog(Context ct,String message, AlertDialogButton btn,DialogType dt, IDialogAction action) {
if(ct==null) return;
dview=new DialogView(ct, R.layout.activity_dialog, R.style.custom_dialog2);
if (dview != null) {
if (!dview.isShowing()) {

String btnName1="确定";
String btnName2="取消";
if(btn==AlertDialogButton.YesNoCancel||btn==AlertDialogButton.YesNo){
btnName1="是";
btnName2="否";
try{
DialogView dview=new DialogView(ct, R.layout.activity_dialog, R.style.custom_dialog2);
if (dview != null) {
if (!dview.isShowing()) {

String btnName1="确定";
String btnName2="取消";
if(btn==AlertDialogButton.YesNoCancel||btn==AlertDialogButton.YesNo){
btnName1="是";
btnName2="否";
}

dview.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框
RelativeLayout rlTitle = (RelativeLayout) dview.findViewById(R.id.rl_title);
if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back);
if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back);
if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back);
TextView Tv=(TextView)dview.findViewById(R.id.tv_Title);
TextView Info=(TextView)dview.findViewById(R.id.tv_Info);
Button ok = (Button)dview.findViewById(R.id.btn_ok);
Button cancel = (Button)dview.findViewById(R.id.btn_cancel);

Tv.setText(dt.toString());
Info.setText(message);
ok.setText(btnName1);
cancel.setText(btnName2);

if(btn==AlertDialogButton.OK)cancel.setVisibility(View.GONE);

ok.setOnClickListener(view->{
if(action!=null)action.ExitDialog(true);
hide(dview);
});

cancel.setOnClickListener(view->{
if(action!=null)action.ExitDialog(false);
hide(dview);
});
dview.show();
}

dview.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框
RelativeLayout rlTitle = (RelativeLayout) dview.findViewById(R.id.rl_title);
if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back);
if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back);
if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back);
TextView Tv=(TextView)dview.findViewById(R.id.tv_Title);
TextView Info=(TextView)dview.findViewById(R.id.tv_Info);
Button ok = (Button)dview.findViewById(R.id.btn_ok);
Button cancel = (Button)dview.findViewById(R.id.btn_cancel);

Tv.setText(dt.toString());
Info.setText(message);
ok.setText(btnName1);
cancel.setText(btnName2);

if(btn==AlertDialogButton.OK)cancel.setVisibility(View.GONE);

ok.setOnClickListener(view->{
if(action!=null)action.ExitDialog(true);
hide(dview);
});

cancel.setOnClickListener(view->{
if(action!=null)action.ExitDialog(false);
hide(dview);
});
dview.show();
}
}catch(Exception e){
MessageLog.ShowError("打开弹框异常:"+e.toString());
}
}

/**
* 对话框,自定义按钮,非阻塞
* */
private static void showDialog(Activity activity,String message, AlertDialogButton btn,DialogType dt, IDialogAction action) {
if(activity==null) return;
try{
DialogView dview1=new DialogView(activity, R.layout.activity_dialog, R.style.custom_dialog2);
if (dview1 != null) {
if (!dview1.isShowing()) {

String btnName1="确定";
String btnName2="取消";
if(btn==AlertDialogButton.YesNoCancel||btn==AlertDialogButton.YesNo){
btnName1="是";
btnName2="否";
}

dview1.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框
RelativeLayout rlTitle = (RelativeLayout) dview1.findViewById(R.id.rl_title);
if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back);
if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back);
if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back);
TextView Tv=(TextView)dview1.findViewById(R.id.tv_Title);
TextView Info=(TextView)dview1.findViewById(R.id.tv_Info);
Button ok = (Button)dview1.findViewById(R.id.btn_ok);
Button cancel = (Button)dview1.findViewById(R.id.btn_cancel);

Tv.setText(dt.toString());
Info.setText(message);
ok.setText(btnName1);
cancel.setText(btnName2);

if(btn==AlertDialogButton.OK)cancel.setVisibility(View.GONE);

ok.setOnClickListener(view->{
if(action!=null)action.ExitDialog(true);
hide(dview1);
});

cancel.setOnClickListener(view->{
if(action!=null)action.ExitDialog(false);
hide(dview1);
});
dview1.show();
}
}
}catch(Exception e){
MessageLog.ShowError("打开弹框异常:"+e.toString());
}
}

// 隐藏弹框
/**
* 隐藏弹框
* @param view
*/
private static void hide(DialogView view) {
if (view != null) {
if (view.isShowing()) {
@@ -214,5 +279,43 @@ public class DialogManager {
}



/**
* 信息提示框
* @param message 提示信息
* @param btn 显示按钮
* @param action 执行回调
*/
public static void showInfo( Activity activity,String message, AlertDialogButton btn, IDialogAction action) {
if(activity!=null)
activity.runOnUiThread(()->{showDialog(activity,message,btn,DialogType.提示,action);});
else showDialog(activity,message,btn,DialogType.提示,action);
}

/**
* 警告提示框
* @param message 警告信息
* @param btn 显示按钮
* @param action 执行回调
*/
public static void showWarn(Activity activity,String message, AlertDialogButton btn, IDialogAction action) {
if(activity!=null)
activity.runOnUiThread(()->{showDialog(activity,message,btn,DialogType.警告,action);});
else showDialog(activity,message,btn,DialogType.警告,action);
}

/**
* 错误提示框
* @param message 错误信息
* @param btn 显示按钮
* @param action 执行回调
*/
public static void showError( Activity activity,String message, AlertDialogButton btn, IDialogAction action) {
if(activity!=null)
activity.runOnUiThread(()->{showDialog(activity,message,btn,DialogType.错误,action);});
else showDialog(activity,message,btn,DialogType.错误,action);
}

}



+ 7
- 5
app/src/main/java/com/bonait/bnframework/Dialog/DialogView.java View File

@@ -1,5 +1,6 @@
package com.bonait.bnframework.Dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Window;
@@ -22,10 +23,11 @@ public class DialogView extends Dialog {
super(context, style);
setContentView(layout);
Window mWindow = getWindow();
// WindowManager.LayoutParams params = mWindow.getAttributes();
// params.width = WindowManager.LayoutParams.MATCH_PARENT;
// params.height = WindowManager.LayoutParams.WRAP_CONTENT;
// params.gravity = gravity;
// mWindow.setAttributes(params);
}

public DialogView(@NonNull Activity activity, int layout, int style) {
super(activity, style);
setContentView(layout);
Window mWindow = getWindow();
}
}

+ 57
- 54
app/src/main/java/com/bonait/bnframework/common/base/BaseFragment.java View File

@@ -76,61 +76,64 @@ public abstract class BaseFragment extends QMUIFragment implements EasyPermissio
public void skipToActivity(Class da) {
try{
Context context=this.getContext();
if(ConfigName.getInstance().user.name.equals("admin")
|| ConfigName.getInstance().user.account.equals("admin"))
{
Intent intent = new Intent(context, da);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else
{
if(da.getName().equals("com.bonait.bnframework.modules.home.fragment.from.OrderListActivity")
|| da.getName().equals("com.bonait.bnframework.modules.home.fragment.from.SalesStatisticsActivity")
)
{
Intent intent = new Intent(context, da);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return;
}

// 跳转到登录页面
final QMUIDialog.EditTextDialogBuilder builder2 = new QMUIDialog.EditTextDialogBuilder(context);
builder2.setTitle("权限验证")
.setPlaceholder("在此输入权限密码")
.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD)
.addAction("取消", new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
}
})
.addAction("确定", new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
CharSequence s = builder2.getEditText().getText();
if (s != null && s.length() > 0)
{
if(s.toString().equals(ConfigName.getInstance().user.pass))
{
Intent intent = new Intent(context, da);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
dialog.dismiss();
}else
{
ToastUtils.warning("权限密码不正确!");
}

}else
{
ToastUtils.warning("权限密码不能为空!");
}

}
})
.show();
}
Intent intent = new Intent(context, da);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

// if(ConfigName.getInstance().user.name.equals("admin")|| ConfigName.getInstance().user.account.equals("admin"))
// {
// Intent intent = new Intent(context, da);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
// }else
// {
// String OrderListActivityName="com.bonait.bnframework.modules.home.fragment.from.OrderListActivity";
// String SalesStatisticsActivityName = "com.bonait.bnframework.modules.home.fragment.from.SalesStatisticsActivity";
// if(da.getName().equals(OrderListActivityName) || da.getName().equals(SalesStatisticsActivityName)){
// Intent intent = new Intent(context, da);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
// return;
// }
//
// // 跳转到登录页面
// final QMUIDialog.EditTextDialogBuilder builder2 = new QMUIDialog.EditTextDialogBuilder(context);
// builder2.setTitle("权限验证")
// .setPlaceholder("在此输入权限密码")
// .setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD)
// .addAction("取消", new QMUIDialogAction.ActionListener() {
// @Override
// public void onClick(QMUIDialog dialog, int index) {
// dialog.dismiss();
// }
// })
// .addAction("确定", new QMUIDialogAction.ActionListener() {
// @Override
// public void onClick(QMUIDialog dialog, int index) {
// CharSequence s = builder2.getEditText().getText();
// if (s != null && s.length() > 0)
// {
// if(s.toString().equals(ConfigName.getInstance().user.pass))
// {
// Intent intent = new Intent(context, da);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
// dialog.dismiss();
// }else
// {
// ToastUtils.warning("权限密码不正确!");
// }
//
// }else
// {
// ToastUtils.warning("权限密码不能为空!");
// }
//
// }
// })
// .show();
// }
}catch(Exception e){
MessageLog.ShowInfo("打开图片界面出错:"+e.toString());
}


+ 10
- 3
app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java View File

@@ -9,6 +9,7 @@ import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS;
import com.bonait.bnframework.common.db.res.StatusMode;
import com.bonait.bnframework.common.model.AddrType;
import com.bonait.bnframework.common.model.Authority;
import com.bonait.bnframework.common.model.mode.CloudGood;
import com.bonait.bnframework.common.model.mode.DeviceInformation;
import com.bonait.bnframework.common.model.mode.OrganizeMode;
@@ -50,6 +51,11 @@ public class ConfigName {
public Context Home;
public Application app;
public boolean IsPortraitScreen = true;//是否竖屏

/**
* 当前权限
*/
public Authority CurrentAuthority= Authority.操作员;
//endregion

//region 主页
@@ -456,9 +462,10 @@ public class ConfigName {

//region 用户角色
public List<String> UserRole = new ArrayList<String>() {{
add("一般用户");
add("研发用户");
add("超级管理员");
add(Authority.操作员.name());
add(Authority.维修员.name());
add(Authority.管理员.name());
add(Authority.研发员.name());
}};
//endregion
}

+ 9
- 0
app/src/main/java/com/bonait/bnframework/common/helper/Convert.java View File

@@ -1,6 +1,7 @@
package com.bonait.bnframework.common.helper;

import com.bonait.bnframework.common.helper.Result.OperateResultT;
import com.bonait.bnframework.common.model.Authority;

public class Convert {
public static OperateResultT<Boolean> TryToBoolean(Object value){
@@ -47,4 +48,12 @@ public class Convert {
return OperateResultT.CreateFailedT(e);
}
}

public static OperateResultT<Authority> TryToAuthority(String value){
try{
return OperateResultT.CreateSuccess(Authority.valueOf(value));
}catch(IllegalArgumentException e){
return OperateResultT.CreateFailedT("无效的枚举值:"+value);
}
}
}

+ 9
- 0
app/src/main/java/com/bonait/bnframework/common/model/Authority.java View File

@@ -0,0 +1,9 @@
package com.bonait.bnframework.common.model;

public enum Authority {
管理员,
研发员,
操作员,
维修员,

}

+ 4
- 0
app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java View File

@@ -5,10 +5,14 @@ import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.bonait.bnframework.Dialog.DialogManager;
import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.common.base.BaseActivity;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.helper.AlertDialogButton;
import com.bonait.bnframework.common.model.Authority;
import com.bonait.bnframework.common.tabbar.MainNavigateTabBar;
import com.bonait.bnframework.common.utils.NetworkUtils;
import com.bonait.bnframework.modules.home.adapter.FragmentAdapter;


+ 11
- 0
app/src/main/java/com/bonait/bnframework/modules/home/fragment/GongnengFragment.java View File

@@ -9,8 +9,13 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.bonait.bnframework.Dialog.DialogManager;
import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.helper.AlertDialogButton;
import com.bonait.bnframework.common.model.Authority;
import com.bonait.bnframework.modules.home.fragment.from.CpActivity;
import com.bonait.bnframework.modules.home.fragment.from.DiyActivity;
import com.bonait.bnframework.modules.home.fragment.from.JcsjglActivity;
@@ -57,6 +62,12 @@ public class GongnengFragment extends BaseFragment {
// @OnClick({R.id.jcsjgl,R.id.lcgl,R.id.yfpf,R.id.log,R.id.ssjk})
@OnClick({R.id.material_management,R.id.recipe_managerment,R.id.warehouse_management,R.id.log_info})
public void onViewClicked(View view) {
if(view.getId() !=R.id.log_info){
if(ConfigName.getInstance().CurrentAuthority== Authority.操作员||ConfigName.getInstance().CurrentAuthority== Authority.维修员){
DialogManager.showInfo(getContext(),"权限不足!", AlertDialogButton.OK,null);
return;
}
}
switch (view.getId()) {
case R.id.material_management://
skipToActivity(JcsjglActivity.class);


+ 56
- 25
app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java View File

@@ -18,6 +18,8 @@ import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperTextView;
import com.bonait.bnframework.Dialog.DialogManager;
import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.business.ExecuteTheRecipe;
@@ -27,7 +29,9 @@ import com.bonait.bnframework.common.constant.Constants;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.helper.AlertDialogButton;
import com.bonait.bnframework.common.helper.I.IRun;
import com.bonait.bnframework.common.model.Authority;
import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.common.utils.UpdateAppUtils;
@@ -171,14 +175,20 @@ public class MyFragment extends BaseFragment {
.show();
break;
case R.id.stv_user_qx://
if(ConfigName.getInstance().user.name.equals("admin")
|| ConfigName.getInstance().user.account.equals("admin"))
{
skipToUserActivity();
}else
{
ToastUtils.warning("对不起,你暂无权限!");

if(ConfigName.getInstance().CurrentAuthority!= Authority.管理员){
DialogManager.showInfo(getContext(),"权限不足!", AlertDialogButton.OK,null);
return;
}
skipToUserActivity();
// if(ConfigName.getInstance().user.name.equals("admin")
// || ConfigName.getInstance().user.account.equals("admin"))
// {
// skipToUserActivity();
// }else
// {
// ToastUtils.warning("对不起,你暂无权限!");
// }
break;
case R.id.stv_update://
//检查权限,并启动版本更新
@@ -188,32 +198,53 @@ public class MyFragment extends BaseFragment {
skipToNoticeActivity();
break;
case R.id.stv_huifu://
String title = "温馨提示!";
String message = "客官确定要恢复出厂设置吗,小菠萝温馨提示你,此操作将会影响到实际运行哦?";
AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
ConfigData.getInstance().RevertPLCProcess();
ToastUtils.info("恢复出厂设置成功!");
dialog.dismiss();
}

if(ConfigName.getInstance().CurrentAuthority!= Authority.管理员){
DialogManager.showInfo(getContext(),"权限不足!", AlertDialogButton.OK,null);
return;
}

DialogManager.showInfo(getContext(),"恢复出厂设置会影响设备运行,请问是否继续?",AlertDialogButton.YesNo,s->{
ConfigData.getInstance().RevertPLCProcess();
});

// String title = "温馨提示!";
// String message = "客官确定要恢复出厂设置吗,小菠萝温馨提示你,此操作将会影响到实际运行哦?";
// AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() {
// @Override
// public void onClick(QMUIDialog dialog, int index) {
// ConfigData.getInstance().RevertPLCProcess();
// ToastUtils.info("恢复出厂设置成功!");
// dialog.dismiss();
// }
// });
break;
case R.id.stv_logout://
String title1 = "温馨提示!";
String message1 = "客官确定要退出程序吗,小菠萝会想你的哦?";
AlertDialogUtils.showDialog(context, title1, message1, new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
skipToLoginActivity();
dialog.dismiss();
}
});

DialogManager.showInfo(getContext(),"确定退出当前程序?", AlertDialogButton.OKCancel,s->{if(s) skipToLoginActivity();});

// String title1 = "温馨提示!";
// String message1 = "客官确定要退出程序吗,小菠萝会想你的哦?";
// AlertDialogUtils.showDialog(context, title1, message1, new QMUIDialogAction.ActionListener() {
// @Override
// public void onClick(QMUIDialog dialog, int index) {
// skipToLoginActivity();
// dialog.dismiss();
// }
// });
break;
case R.id.stv_plc_add:
if(ConfigName.getInstance().CurrentAuthority!= Authority.管理员&&ConfigName.getInstance().CurrentAuthority!= Authority.维修员){
DialogManager.showInfo(getContext(),"权限不足!", AlertDialogButton.OK,null);
return;
}
skipToActivity(PlcControlActivity.class);
break;
case R.id.stv_system_par:
if(ConfigName.getInstance().CurrentAuthority!= Authority.管理员&&ConfigName.getInstance().CurrentAuthority!= Authority.维修员){
DialogManager.showInfo(getContext(),"权限不足!", AlertDialogButton.OK,null);
return;
}
skipToActivity(SystemParameterActivity.class);
break;
}


+ 65
- 38
app/src/main/java/com/bonait/bnframework/modules/mine/fragment/UserActivity.java View File

@@ -12,6 +12,8 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.bonait.bnframework.Dialog.DialogManager;
import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseActivity;
import com.bonait.bnframework.common.constant.ConfigName;
@@ -22,10 +24,12 @@ import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
import com.bonait.bnframework.common.db.mode.BPA_SILOS;
import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.helper.AlertDialogButton;
import com.bonait.bnframework.common.helper.I.IRunT;
import com.bonait.bnframework.common.helper.I.MyClickListener;
import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback;
import com.bonait.bnframework.common.message.MessageManager;
import com.bonait.bnframework.common.model.Authority;
import com.bonait.bnframework.common.model.ResAPI;
import com.bonait.bnframework.common.model.mode.ActionJsonMode;
import com.bonait.bnframework.common.model.mode.BatchingInfo;
@@ -124,6 +128,7 @@ public class UserActivity extends BaseActivity implements MyClickListener {
if(QueryDB.GetUserIsCZ(bpa_user.account,bpa_user.name))
{
ToastUtils.warning("已有该账户,请重新填写账户信息!");
// DialogManager.showWarn(MainApplication.getContext(),"已有该账户,请重新填写账户信息!", AlertDialogButton.OK,null);
return;
}
QueryDB.AddUser(bpa_user);
@@ -143,50 +148,67 @@ public class UserActivity extends BaseActivity implements MyClickListener {

case R.id.synchronous://新增用户

String title = "温馨提示!";
String message = "客官确定要恢复出厂账户吗?";
AlertDialogUtils.showDialog(this, title, message, new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
// String title = "温馨提示!";
// String message = "客官确定要恢复出厂账户吗?";
DialogManager.showWarn(this,"用户信息恢复出厂设置后不可恢复!\r\n请问是否继续?",AlertDialogButton.YesNo,(s)->{
if(s){
ArrayList<BPA_USER> users=QueryDB.GetUserALL();
for (BPA_USER item:users)
{
for (BPA_USER item:users){
QueryDB.DeleteUser(item);
}
BPA_USER user = new BPA_USER();
user.id = "20230415-fyf";
user.name = "管理员";
user.name = "Administrator";
user.account = "admin";
user.pass = "123456";
user.deviceID = ConfigName.getInstance().DeviceId;
user.userID = "超级管理员";
user.exp = "管理员";
user.userID = Authority.管理员.name();
QueryDB.AddUser(user);

BPA_USER user1 = new BPA_USER();
user1.name = "一般用户";
user1.account = "ybyh";
user1.pass = "123456";
user1.deviceID = ConfigName.getInstance().DeviceId;
user1.userID = "一般用户";
user1.exp = "一般用户";
QueryDB.AddUser(user1);


BPA_USER user2 = new BPA_USER();
user2.name = "研发用户";
user2.account = "yfyh";
user2.pass = "123456";
user2.deviceID = ConfigName.getInstance().DeviceId;
user2.userID = "研发用户";
user2.exp = "研发用户";
QueryDB.AddUser(user2);

ToastUtils.info("恢复出厂成功!");
Initdata();
dialog.dismiss();
}
});

// AlertDialogUtils.showDialog(this, title, message, new QMUIDialogAction.ActionListener() {
// @Override
// public void onClick(QMUIDialog dialog, int index) {
// ArrayList<BPA_USER> users=QueryDB.GetUserALL();
// for (BPA_USER item:users)
// {
// QueryDB.DeleteUser(item);
// }
// BPA_USER user = new BPA_USER();
// user.id = "20230415-fyf";
// user.name = "管理员";
// user.account = "admin";
// user.pass = "123456";
// user.deviceID = ConfigName.getInstance().DeviceId;
// user.userID = "超级管理员";
// user.exp = "管理员";
// QueryDB.AddUser(user);
//
// BPA_USER user1 = new BPA_USER();
// user1.name = "一般用户";
// user1.account = "ybyh";
// user1.pass = "123456";
// user1.deviceID = ConfigName.getInstance().DeviceId;
// user1.userID = "一般用户";
// user1.exp = "一般用户";
// QueryDB.AddUser(user1);
//
//
// BPA_USER user2 = new BPA_USER();
// user2.name = "研发用户";
// user2.account = "yfyh";
// user2.pass = "123456";
// user2.deviceID = ConfigName.getInstance().DeviceId;
// user2.userID = "研发用户";
// user2.exp = "研发用户";
// QueryDB.AddUser(user2);
//
// ToastUtils.info("恢复出厂成功!");
// Initdata();
// dialog.dismiss();
// }
// });
break;
}
}
@@ -210,7 +232,8 @@ public class UserActivity extends BaseActivity implements MyClickListener {
String name = ((BPA_USER) data).name;
String ac = ((BPA_USER) data).account;
if (name.equals("admin") || ac.equals("admin")) {
ToastUtils.warning("对不起,admin账户禁止操作!");
// ToastUtils.warning("对不起,admin账户禁止操作!");
DialogManager.showWarn(this, "对不起,admin账户禁止操作!",AlertDialogButton.OK,null);
return;
}
switch (v.getId()) {
@@ -356,9 +379,13 @@ public class UserActivity extends BaseActivity implements MyClickListener {
break;

case R.id.button_item://删除按钮
QueryDB.DeleteUser((BPA_USER) data);
Initdata();
ToastUtils.info("删除成功");
DialogManager.showWarn(this,"用户删除后不可恢复,请问是否继续?",AlertDialogButton.YesNo,s->{
if(s){
QueryDB.DeleteUser((BPA_USER) data);
Initdata();
// ToastUtils.info("删除成功");
}
});
break;
}
}


+ 85
- 4
app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java View File

@@ -22,17 +22,20 @@ import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.bonait.bnframework.Dialog.DialogManager;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.common.base.BaseActivity;
import com.bonait.bnframework.common.bg.SnowView;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.constant.Constants;
import com.bonait.bnframework.common.constant.SPConstants;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.helper.AlertDialogButton;
import com.bonait.bnframework.common.helper.Convert;
import com.bonait.bnframework.common.helper.Result.OperateResultT;
import com.bonait.bnframework.common.model.Authority;
import com.bonait.bnframework.common.utils.AppUtils;
import com.bonait.bnframework.common.utils.Des3Utils;
import com.bonait.bnframework.common.utils.KeyboardToolUtils;
@@ -52,7 +55,11 @@ import com.qmuiteam.qmui.util.QMUIStatusBarHelper;

import org.litepal.LitePal;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

import butterknife.BindView;
import butterknife.ButterKnife;
@@ -171,11 +178,69 @@ public class LoginActivity extends BaseActivity implements Validator.ValidationL
}
}

public String getMD5(String input) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(input.getBytes());
byte messageDigest[] = digest.digest();

// Create Hex String
StringBuilder hexString = new StringBuilder();
for (byte aMessageDigest : messageDigest) {
String h = Integer.toHexString(0xFF & aMessageDigest);
while (h.length() < 2) h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}

String AuthCode;

public OperateResultT<String> getPassword(){
if(!AuthCode.isEmpty()&&AuthCode.length()>0){
String[] code=AuthCode.split(" - ");
StringBuilder sb = new StringBuilder();
if(code!=null&&code.length==4){
sb.append(code[2]);
sb.append(code[3]);
sb.append(code[0]);
sb.append(code[1]);
}
return OperateResultT.CreateSuccess(getMD5(sb.toString()).substring(0,8).toLowerCase());
}
return OperateResultT.CreateFailedT("密码解析失败");
}

/**
* 忘记密码
*/
private void forgotPassword() {
ToastUtils.info("请与管理员联系修改密码!");
// ToastUtils.info("请与管理员联系修改密码!");
try{
String uid= UUID.randomUUID().toString();
String md5=getMD5(uid);
StringBuilder sb = new StringBuilder();
StringBuilder tempAuthCode=new StringBuilder();
if(!md5.isEmpty()&&md5.length()==32){
for(int i=0;i<md5.length();i+=2){
sb.append(md5.charAt(i));
}

for(int i=0;i<4;i++){
tempAuthCode.append(sb.toString().substring(i*4,i*4+4));
if(i<3) tempAuthCode.append(" — ");
}
}
AuthCode=tempAuthCode.toString();
DialogManager.showInfo(this,"请联系海科找回密码。\r\n \r\n授权码:"+AuthCode.toUpperCase(), AlertDialogButton.OK,null);
}catch(Exception e){

}
}

// *************************以下为登录验证及跳转界面相关*************************//
@@ -195,10 +260,26 @@ public class LoginActivity extends BaseActivity implements Validator.ValidationL
if (user != null) {
ConfigName.getInstance().user = user;
ConfigData.getInstance().SavePZ();
Convert.TryToAuthority(user.userID).OnSource(s->{ConfigName.getInstance().CurrentAuthority=s.Content;});
//跳转到主页
skipToMainActivity();
} else {
ToastUtils.warning("账号密码不正确!");

AtomicBoolean isOk = new AtomicBoolean(false);
if(!AuthCode.isEmpty()&&AuthCode.length()>0){
if(userAccount=="admin"){
getPassword().OnSource(s->{
if(password.equals(s)) {
isOk.set(true);
ConfigName.getInstance().CurrentAuthority= Authority.管理员;
skipToMainActivity();
}
});
}
}

if(!isOk.get())
DialogManager.showError(this,"账号或密码不正确!",AlertDialogButton.OK,null);
}
}



Loading…
Cancel
Save