Home.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <el-container>
  3. <el-header style="padding: 0;">
  4. <el-menu class="el-menu" mode="horizontal">
  5. <el-menu-item index="1">
  6. <router-link
  7. to="/home/overview"
  8. style="text-decoration-line: none"
  9. title="回到主页"
  10. >
  11. 云平台主页
  12. </router-link>
  13. </el-menu-item>
  14. <el-menu-item
  15. index="4"
  16. style="float: right;"
  17. title="退出系统"
  18. @click="logout"
  19. >
  20. <v-icon name="sign-out-alt" />
  21. <span style="cursor: pointer"> 退出 </span>
  22. </el-menu-item>
  23. <el-menu-item index="3" style="float: right;" title="个人信息管理">
  24. <v-icon name="user" />
  25. <span @click="openUserDialog" style="cursor: pointer">
  26. {{ user.displayName }}
  27. </span>
  28. </el-menu-item>
  29. <el-menu-item index="2" style="float: right;" title="机构名称">
  30. <v-icon name="users" /> {{ user.rootOrgName }}
  31. </el-menu-item>
  32. </el-menu>
  33. </el-header>
  34. <el-container>
  35. <HomeSide v-if="ifShowHomeSide" :key="sideKey" />
  36. <el-container class="main-body">
  37. <LinkTitles v-if="ifShowHomeSide" :key="Math.random()" />
  38. <router-view class="main-content"></router-view>
  39. <el-footer class="footer">&copy; 启明泰和 2019</el-footer>
  40. </el-container>
  41. </el-container>
  42. <!-- 添加用户信息弹出框 -->
  43. <el-dialog title="个人信息" :visible.sync="userDialog">
  44. <el-tabs value="first">
  45. <el-tab-pane label="用户权限" name="first">
  46. <el-form :inline="true" label-position="right" label-width="90px">
  47. <el-row :gutter="10">
  48. <el-col>
  49. <el-tag
  50. v-for="role in user.roleList"
  51. :key="role.roleId"
  52. type="primary"
  53. style="margin-left:10px;margin-top:10px;"
  54. >
  55. {{ role.roleName }}
  56. </el-tag>
  57. </el-col>
  58. </el-row>
  59. </el-form>
  60. </el-tab-pane>
  61. <el-tab-pane label="修改密码" name="second">
  62. <el-form
  63. :inline="true"
  64. :model="passForm"
  65. ref="passForm"
  66. :rules="passRules"
  67. label-position="right"
  68. label-width="90px"
  69. >
  70. <el-row>
  71. <el-form-item label="密码" label-width="120px" prop="pass">
  72. <el-input
  73. type="password"
  74. class="pull_length"
  75. v-model="passForm.pass"
  76. auto-complete="off"
  77. placeholder="请输入密码"
  78. />
  79. </el-form-item>
  80. </el-row>
  81. <el-row>
  82. <el-form-item
  83. label="确认密码"
  84. label-width="120px"
  85. prop="checkPass"
  86. >
  87. <el-input
  88. type="password"
  89. class="pull_length"
  90. v-model="passForm.checkPass"
  91. auto-complete="off"
  92. placeholder="请输入确认密码"
  93. />
  94. </el-form-item>
  95. </el-row>
  96. <el-row style="margin-left:100px">
  97. <el-button type="primary" @click="submitForm">保 存</el-button>
  98. <el-button @click="userDialog = false">取 消</el-button>
  99. </el-row>
  100. </el-form>
  101. </el-tab-pane>
  102. </el-tabs>
  103. </el-dialog>
  104. </el-container>
  105. </template>
  106. <script>
  107. import { mapActions, mapState } from "vuex";
  108. import { USER_SIGNOUT } from "../../store/user";
  109. import { CORE_API } from "@/constants/constants";
  110. import HomeSide from "./HomeSide.vue";
  111. import LinkTitles from "./LinkTitles.vue";
  112. export default {
  113. name: "Home",
  114. data() {
  115. var validatePass = (rule, value, callback) => {
  116. if (value === "") {
  117. callback(new Error("请输入密码"));
  118. } else {
  119. if (this.passForm.checkPass !== "") {
  120. this.$refs.passForm.validateField("checkPass");
  121. }
  122. callback();
  123. }
  124. };
  125. var validatePass2 = (rule, value, callback) => {
  126. if (value === "") {
  127. callback(new Error("请输入确认密码"));
  128. } else if (value !== this.passForm.pass) {
  129. callback(new Error("两次输入密码不一致!"));
  130. } else {
  131. callback();
  132. }
  133. };
  134. return {
  135. userDialog: false,
  136. passForm: { pass: "", checkPass: "" },
  137. passRules: {
  138. pass: [{ validator: validatePass, trigger: "blur" }],
  139. checkPass: [{ validator: validatePass2, trigger: "blur" }]
  140. }
  141. };
  142. },
  143. components: { HomeSide, LinkTitles },
  144. computed: {
  145. ...mapState({ user: state => state.user }),
  146. ifShowHomeSide() {
  147. return this.$route.fullPath.startsWith("/home") === false;
  148. },
  149. sideKey() {
  150. const module = this.$route.fullPath.split("/")[1];
  151. return module;
  152. }
  153. },
  154. methods: {
  155. ...mapActions([USER_SIGNOUT]),
  156. openUserDialog() {
  157. this.passForm = { pass: "", checkPass: "" };
  158. this.userDialog = true;
  159. },
  160. //保存密码
  161. submitForm() {
  162. this.$refs.passForm.validate(valid => {
  163. if (valid) {
  164. var userId = this.user.userId;
  165. var password = encodeURIComponent(this.passForm.pass);
  166. var url =
  167. CORE_API +
  168. "/user/password?userId=" +
  169. userId +
  170. "&password=" +
  171. password;
  172. this.$httpWithMsg.put(url).then(() => {
  173. this.$notify({
  174. type: "success",
  175. message: "修改密码成功!"
  176. });
  177. this.resetForm();
  178. this.userDialog = false;
  179. });
  180. } else {
  181. console.log("error submit!");
  182. return false;
  183. }
  184. });
  185. },
  186. //重置
  187. resetForm() {
  188. this.$refs.passForm.resetFields();
  189. },
  190. isSuperAdmin() {
  191. if (!this.user.roleList) {
  192. return false;
  193. }
  194. for (let role of this.user.roleList) {
  195. if (role.roleCode == "SUPER_ADMIN") {
  196. return true;
  197. }
  198. }
  199. return false;
  200. },
  201. logout() {
  202. this.$http
  203. .post(CORE_API + "/auth/logout")
  204. .then(() => {
  205. const orgId = this.user.rootOrgId;
  206. this.USER_SIGNOUT();
  207. window.name = "";
  208. this.$router.replace({
  209. path: "/login" + "?orgId=" + orgId
  210. });
  211. })
  212. .catch(response => {
  213. const orgId = this.user.rootOrgId;
  214. if (response.status == 500) {
  215. this.$notify({
  216. showClose: true,
  217. message: response.data.desc,
  218. type: "error"
  219. });
  220. }
  221. this.USER_SIGNOUT();
  222. window.name = "";
  223. this.$router.replace({
  224. path: "/login" + "?orgId=" + orgId
  225. });
  226. });
  227. }
  228. }
  229. };
  230. </script>
  231. <style scoped>
  232. .el-menu,
  233. .el-footer {
  234. background-color: #3c8dbd;
  235. color: #ffffff;
  236. text-align: center;
  237. line-height: 60px;
  238. }
  239. .el-footer {
  240. color: #878e93;
  241. background-color: white;
  242. line-height: 40px;
  243. height: 40px !important;
  244. }
  245. .el-menu.el-menu--horizontal {
  246. border-bottom: none;
  247. }
  248. .el-menu >>> .el-menu-item {
  249. color: white !important;
  250. }
  251. .el-menu >>> .el-menu-item:hover {
  252. color: #777777 !important;
  253. }
  254. .el-menu >>> .is-active.el-menu-item:focus {
  255. color: #777777 !important;
  256. }
  257. body > .el-container {
  258. margin-bottom: 40px;
  259. }
  260. .main-body {
  261. min-height: calc(100vh - 100px);
  262. display: flex;
  263. flex-direction: column;
  264. justify-content: space-between;
  265. margin-top: 20px;
  266. margin-left: 20px;
  267. }
  268. .main-content {
  269. min-height: calc(100vh - 60px - 60px - 40px);
  270. margin-top: 20px;
  271. margin-right: 20px;
  272. }
  273. .footer {
  274. justify-self: flex-end;
  275. margin-left: -20px;
  276. }
  277. </style>
  278. <style>
  279. .submenu-style .el-menu {
  280. min-width: 100px !important;
  281. }
  282. </style>