终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

69 lines
1.9 KiB

  1. using BPA.Message;
  2. using BPASmartClient.CustomResource.Pages.Enums;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace BPASmartClient.CustomResource.Pages.Model
  11. {
  12. public class Config
  13. {
  14. private volatile static Config _Instance;
  15. public static Config GetInstance => _Instance ?? (_Instance = new Config());
  16. private Config() { }
  17. public void Init()
  18. {
  19. if (File.Exists("up.hbl"))
  20. {
  21. var result = JsonConvert.DeserializeObject<UserManager>(File.ReadAllText("up.hbl").AESDecrypt());
  22. if (result == null || (result != null && result.userInfos.Count <= 0))
  23. {
  24. AddData();
  25. }
  26. else
  27. {
  28. Global.userManager = result;
  29. }
  30. }
  31. else
  32. {
  33. AddData();
  34. }
  35. }
  36. private void AddData()
  37. {
  38. Global.userManager.userInfos.Add(new UserInfo() { permission = Permission.管理员, UserName = "admin", Password = "admin" });
  39. SaveUser();
  40. }
  41. public void SaveUser()
  42. {
  43. File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt());
  44. }
  45. public string IdProcess()
  46. {
  47. erp:
  48. string id= Guid.NewGuid().ToString();
  49. if (Global.userManager.userInfos.Count > 0)
  50. {
  51. var res=Global.userManager.userInfos.FirstOrDefault(p => p.Id == id);
  52. if (res != null)
  53. {
  54. goto erp;
  55. }
  56. else
  57. {
  58. return id;
  59. }
  60. }
  61. return id;
  62. }
  63. }
  64. }