Home.vue 7.4 KB

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