HomePage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <el-container :class="getRole">
  3. <el-aside>
  4. <div class="logo">
  5. <p v-if="userLoginDTO&&userLoginDTO.type=='0'">
  6. <b>医院知识库后台管理系统</b>
  7. </p>
  8. </div>
  9. <lt-menu
  10. v-if="menuWrappers&&menuWrappers.length"
  11. v-bind:role="getRole"
  12. v-bind:data="menuWrappers"
  13. ></lt-menu>
  14. </el-aside>
  15. <el-container>
  16. <el-header class="clearfix">
  17. <div class="title fl">
  18. <h2>{{organization&&organization.name}}</h2>
  19. </div>
  20. <div class="userInfo fr">
  21. <span class="username" @click="goCenter">
  22. <i>{{userLoginDTO&&userLoginDTO.linkman}}</i>
  23. <img class="actionDo" src="../../images/arrow_down.png" />
  24. </span>
  25. <ul class="action">
  26. <li @click="changeWords">修改密码</li>
  27. <li @click="logout">退出系统</li>
  28. </ul>
  29. </div>
  30. </el-header>
  31. <el-main ref="main">
  32. <!-- <el-scrollbar style="height: 100%"> -->
  33. <router-view v-if="ok" v-on:status-change="changeStatus"></router-view>
  34. <!-- </el-scrollbar> -->
  35. </el-main>
  36. </el-container>
  37. <el-dialog
  38. title="修改密码"
  39. class="changewords"
  40. :visible.sync="changePassWord"
  41. width="600"
  42. top="20vh"
  43. center
  44. >
  45. <el-form
  46. :model="ruleForm2"
  47. :rules="rules2"
  48. ref="ruleForm2"
  49. label-width="100px"
  50. class="demo-ruleForm"
  51. >
  52. <el-form-item label="旧密码:" prop="oldpass">
  53. <el-input
  54. type="password"
  55. placeholder="请输入旧密码"
  56. @keyup.enter.native="submitForm('ruleForm2')"
  57. v-model.trim="ruleForm2.oldpass"
  58. auto-complete="off"
  59. ></el-input>
  60. </el-form-item>
  61. <el-form-item label="新密码:" prop="pass">
  62. <el-input
  63. type="password"
  64. placeholder="6-20位,可输入字符、数字或符号"
  65. @keyup.enter.native="submitForm('ruleForm2')"
  66. v-model.trim="ruleForm2.pass"
  67. auto-complete="off"
  68. ></el-input>
  69. </el-form-item>
  70. <el-form-item label="再次输入新密码:" prop="checkPass">
  71. <el-input
  72. type="password"
  73. placeholder="6-20位,可输入字符、数字或符号"
  74. @keyup.enter.native="submitForm('ruleForm2')"
  75. v-model.trim="ruleForm2.checkPass"
  76. auto-complete="off"
  77. ></el-input>
  78. </el-form-item>
  79. </el-form>
  80. <span slot="footer" class="dialog-footer">
  81. <el-button type="primary" @click="submitForm('ruleForm2')">确 定</el-button>
  82. </span>
  83. </el-dialog>
  84. </el-container>
  85. </template>
  86. <script>
  87. import LtMenu from '../common/Menu.vue';
  88. import api from '@api/index.js';
  89. import newIcon from '../../images/new.png';
  90. import md5 from 'js-md5';
  91. export default {
  92. name: 'homepage',
  93. components: {
  94. 'lt-menu': LtMenu
  95. },
  96. data() {
  97. var validatePass1 = (rule, value, callback) => {
  98. if (value === '') {
  99. callback(new Error('请输入旧密码'));
  100. } else {
  101. callback();
  102. }
  103. };
  104. var validatePass = (rule, value, callback) => {
  105. if (value === '') {
  106. callback(new Error('请输入新密码'));
  107. } else {
  108. if (this.ruleForm2.checkPass !== '') {
  109. this.$refs.ruleForm2.validateField('checkPass');
  110. }
  111. callback();
  112. }
  113. };
  114. var validatePass2 = (rule, value, callback) => {
  115. if (value === '') {
  116. callback(new Error('请再次输入密码'));
  117. } else if (value !== this.ruleForm2.pass) {
  118. callback(new Error('两次输入密码不一致!'));
  119. } else {
  120. callback();
  121. }
  122. };
  123. return {
  124. menuWrappers: null,
  125. organization: null,
  126. userLoginDTO: null,
  127. authStatus: null,
  128. authStatusName: '',
  129. ok: false, //是否已获取到菜单
  130. versionName: '',
  131. versionVisible: false,
  132. versionInfo: '',
  133. isNewV: false,
  134. version: null, //版本信息接口返回的数据
  135. changePassWord: false,
  136. ruleForm2: {
  137. pass: '',
  138. checkPass: '',
  139. oldpass: ''
  140. },
  141. rules2: {
  142. oldpass: [
  143. { validator: validatePass1, trigger: 'change', required: true }
  144. ],
  145. pass: [
  146. {
  147. min: 6,
  148. max: 20,
  149. message: '密码要求6-20位,可输入字母、数字或符号',
  150. trigger: 'blur'
  151. },
  152. { validator: validatePass, trigger: 'blur', required: true }
  153. ],
  154. checkPass: [
  155. {
  156. min: 6,
  157. max: 20,
  158. message: '密码要求6-20位,可输入字母、数字或符号',
  159. trigger: 'blur'
  160. },
  161. { validator: validatePass2, trigger: 'blur', required: true }
  162. ]
  163. }
  164. };
  165. },
  166. computed: {
  167. getRole: function() {
  168. return 'admin';
  169. }
  170. },
  171. created() {
  172. //获取菜单
  173. this.getMenuList();
  174. },
  175. mounted() {},
  176. watch: {
  177. $route: function(to, from) {
  178. if (from.name == 'login') {
  179. this.getMenuList();
  180. }
  181. if (to.path == '/') {
  182. // 退出时清空菜单
  183. this.menuWrappers = [];
  184. this.isNewV = false;
  185. }
  186. }
  187. },
  188. methods: {
  189. CalcuMD5(password) {
  190. password = md5(password);
  191. return password;
  192. },
  193. submitForm(formName) {
  194. this.$refs[formName].validate(valid => {
  195. if (valid) {
  196. api
  197. .midifyPassword({
  198. password: this.CalcuMD5(this.ruleForm2.oldpass),
  199. modifyPassword: this.CalcuMD5(this.ruleForm2.pass)
  200. })
  201. .then(res => {
  202. if (res.data.code == '0') {
  203. const data = res.data.data;
  204. this.$refs['ruleForm2'].resetFields();
  205. this.changePassWord = false;
  206. this.$message({
  207. message: '修改成功,请重新登录',
  208. type: 'success',
  209. duration: 1500,
  210. onClose: () => {
  211. this.logout();
  212. }
  213. });
  214. } else if (res.data.code === '00020005') {
  215. console.log('原密码错误');
  216. this.$refs['ruleForm2'].clearValidate();
  217. // 手动操作校验、展示登录错误信息
  218. this.rules2.oldpass.push({
  219. // js新增一个自定义校验
  220. validator: (rule, value, callback) => {
  221. callback('旧密码输入错误');
  222. },
  223. trigger: 'change'
  224. });
  225. this.$refs['ruleForm2'].validateField('oldpass'); // 手动校验
  226. this.rules2.oldpass = this.rules2.oldpass.slice(0, 1); // 删除校验
  227. } else {
  228. this.$message({
  229. message: res.data.msg,
  230. type: 'error',
  231. duration: 1000
  232. });
  233. }
  234. })
  235. .catch(error => {
  236. console.log(error);
  237. });
  238. } else {
  239. console.log('error submit!!');
  240. return false;
  241. }
  242. });
  243. },
  244. resetForm(formName) {
  245. this.$refs[formName].resetFields();
  246. },
  247. changeWords() {
  248. this.changePassWord = true;
  249. this.$refs['ruleForm2'] && this.$refs['ruleForm2'].resetFields();
  250. },
  251. getMenuList() {
  252. api
  253. .getAccessdMenu()
  254. .then(res => {
  255. if (res.data.code == '0') {
  256. const data = res.data.data;
  257. this.ok = true;
  258. const hasConcole = data.menuWrappers.find(it => {
  259. return it.code.indexOf('-KZT') > -1;
  260. });
  261. this.menuWrappers = data.menuWrappers;
  262. this.organization = data.organization;
  263. this.userLoginDTO = data.userLoginDTO;
  264. localStorage.setItem(
  265. 'userLoginDTO',
  266. JSON.stringify(data.userLoginDTO)
  267. );
  268. localStorage.setItem(
  269. 'hospitalLoginDTO',
  270. JSON.stringify(data.hospitalLoginDTO)
  271. );
  272. if (hasConcole) {
  273. const url = '/admin/LT-KZT';
  274. this.$router.push({ path: url });
  275. }
  276. }
  277. })
  278. .catch(error => {
  279. console.log(error);
  280. });
  281. },
  282. isNewVersion() {
  283. //判断是否为新版
  284. },
  285. changeStatus(text) {
  286. //账号信息中提交认证后修改状态
  287. this.authStatus = 2;
  288. this.authStatusName = text;
  289. },
  290. goCenter() {},
  291. logout() {
  292. //退出
  293. localStorage.removeItem('token');
  294. this.$router.push({ path: '/' });
  295. }
  296. }
  297. };
  298. </script>
  299. <style lang="less">
  300. @import '../../less/common.less';
  301. .user .el-menu-item.is-active {
  302. color: @userBase;
  303. }
  304. .admin .el-menu-item.is-active {
  305. color: @adminBase;
  306. }
  307. .admin .username {
  308. cursor: pointer;
  309. }
  310. .version-info h3 {
  311. font-size: 14px;
  312. margin-bottom: 20px;
  313. span {
  314. float: right;
  315. font-weight: normal;
  316. }
  317. }
  318. </style>
  319. <style lang="less" scoped>
  320. @import '../../less/common.less';
  321. .el-menu-vertical-demo.el-menu {
  322. height: calc(100% - 120px);
  323. overflow-y: auto;
  324. }
  325. .userInfo {
  326. position: relative;
  327. padding-left: 20px;
  328. cursor: pointer;
  329. .username {
  330. font-size: 14px;
  331. color: #545455;
  332. img {
  333. width: 10px;
  334. margin-left: 8px;
  335. position: relative;
  336. bottom: 2px;
  337. }
  338. }
  339. &:hover .action {
  340. display: block;
  341. }
  342. .action {
  343. width: 94px;
  344. height: 70px;
  345. box-shadow: 1px 2px 8px 1px #ccc;
  346. border-radius: 3px;
  347. position: absolute;
  348. top: 50px;
  349. right: -5px;
  350. z-index: 999;
  351. background-color: #fff;
  352. color: #333;
  353. font-size: 14px;
  354. display: none;
  355. li {
  356. height: 35px;
  357. line-height: 35px;
  358. text-align: center;
  359. cursor: pointer;
  360. &:hover {
  361. background-color: #f2f2f2;
  362. }
  363. }
  364. }
  365. }
  366. .version {
  367. position: fixed;
  368. bottom: 0;
  369. width: @aside-width;
  370. min-width: 270px;
  371. font-size: 12px;
  372. /*text-indent: 50px;*/
  373. text-align: center;
  374. height: 54px;
  375. line-height: 54px;
  376. background: #fff;
  377. i {
  378. display: inline-block;
  379. width: 20px;
  380. height: 16px;
  381. img {
  382. vertical-align: text-top;
  383. }
  384. }
  385. }
  386. .user .version a {
  387. color: @userBase;
  388. }
  389. .admin .version a {
  390. color: @adminBase;
  391. }
  392. .user .logo {
  393. background: @userBase;
  394. p {
  395. font-size: 16px;
  396. line-height: normal;
  397. }
  398. }
  399. .admin .logo {
  400. background: @adminBase;
  401. p {
  402. font-size: 18px;
  403. line-height: 40px;
  404. }
  405. }
  406. .title {
  407. h2 {
  408. display: inline-block;
  409. line-height: 60px;
  410. font-size: 18px;
  411. }
  412. }
  413. .block {
  414. height: 40px;
  415. width: 100%;
  416. background: #fff;
  417. box-shadow: 0px 1px 2px #c9c9c9;
  418. }
  419. .el-main {
  420. padding: 0;
  421. }
  422. .el-button {
  423. margin-left: 15px;
  424. }
  425. .changewords {
  426. // /deep/ .el-icon-circle-close{
  427. // display: none;
  428. // }
  429. .dialog-footer {
  430. .el-button {
  431. // float: right;
  432. position: relative;
  433. left: 200px;
  434. }
  435. }
  436. }
  437. </style>