2
0

store.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. import moment from "moment"
  4. Vue.use(Vuex);
  5. const store = new Vuex.Store({
  6. state: {
  7. serverInfo: {},
  8. userInfo: null,
  9. menus: [
  10. {
  11. path: '/',
  12. title: "概览",
  13. icon: 'dashboard',
  14. roles: ['管理员'],
  15. }, {
  16. path: "/devices",
  17. icon: "video-camera",
  18. title: "国标设备",
  19. roles: ['管理员','操作员','观众'],
  20. }, {
  21. path: '/screen',
  22. icon: 'th-large',
  23. title: "分屏展示",
  24. // roles: ['管理员','操作员','观众'],
  25. }, {
  26. path: "/cloudrecord",
  27. icon: "cloud",
  28. title: "云端录像",
  29. versionType: "旗舰版",
  30. roles: ['管理员','操作员','观众'],
  31. }, {
  32. path: "/alarms",
  33. icon: "bell",
  34. title: "报警查询",
  35. roles: ['管理员','操作员'],
  36. }, {
  37. path: "/cascade",
  38. icon: "cloud-upload",
  39. title: "国标级联",
  40. versionType: "旗舰版",
  41. roles: ['管理员'],
  42. }, {
  43. path: "/user",
  44. icon: "users",
  45. title: "用户管理",
  46. roles: ['管理员'],
  47. }, {
  48. path: "/logs",
  49. icon: "file",
  50. title: "操作日志",
  51. roles: ['管理员'],
  52. }, {
  53. path: "/config",
  54. icon: "cogs",
  55. title: "基础配置",
  56. roles: ['管理员'],
  57. }, {
  58. path: "/about",
  59. icon: "support",
  60. title: "版本信息",
  61. roles: ['管理员'],
  62. }
  63. ]
  64. },
  65. mutations: {
  66. updateUserInfo(state, userInfo) {
  67. state.userInfo = userInfo;
  68. },
  69. updateServerInfo(state, serverInfo) {
  70. state.serverInfo = serverInfo;
  71. }
  72. },
  73. actions: {
  74. getUserInfo({ commit, state }) {
  75. return new Promise((resolve, reject) => {
  76. $.get("/api/v1/userinfo").then(msg => {
  77. var userInfo = msg;
  78. commit('updateUserInfo', userInfo);
  79. resolve(userInfo);
  80. }).fail(() => {
  81. resolve(null);
  82. })
  83. })
  84. },
  85. logout({ commit, state }) {
  86. return new Promise((resolve, reject) => {
  87. $.get("/api/v1/logout").then(data => {
  88. commit('updateUserInfo', null);
  89. resolve(null);
  90. }).fail(() => {
  91. resolve(null);
  92. })
  93. })
  94. },
  95. getServerInfo({ commit }) {
  96. return new Promise((resolve, reject) => {
  97. $.get("/api/v1/getserverinfo").then(serverInfo => {
  98. try {
  99. if (serverInfo.ServerTime) {
  100. var stime = moment(serverInfo.ServerTime, "YYYY-MM-DD HH:mm:ss");
  101. serverInfo.DiffDuration = moment.duration(stime.diff(moment()))
  102. }
  103. commit('updateServerInfo', serverInfo);
  104. resolve(serverInfo)
  105. return
  106. } catch (error) {
  107. console.log(error)
  108. }
  109. resolve({});
  110. }).fail(() => {
  111. resolve({});
  112. })
  113. })
  114. }
  115. }
  116. })
  117. export default store;