login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="login">
  3. <view class="login_title"> 医疗服务中心转运系统 </view>
  4. <form @submit="login" class="form">
  5. <view class="form_item">
  6. <view class="form_title">用户名:</view>
  7. <input class="form_input" name="username" :value="username" placeholder="请输入用户名" />
  8. </view>
  9. <view class="form_item">
  10. <view class="form_title">密<text class="placeholder"></text>码:</view>
  11. <input class="form_input" name="password" :value="password" password placeholder="请输入密码" />
  12. </view>
  13. <view class="form_item">
  14. <checkbox-group name="savePassword">
  15. <label>
  16. <checkbox value="true" :checked="savePassword" /><text>记住密码</text>
  17. </label>
  18. </checkbox-group>
  19. </view>
  20. <view class="form_submit">
  21. <button form-type="submit">登录</button>
  22. </view>
  23. </form>
  24. <view class="tips red">
  25. (此系统为护士人员使用,其他科室人员请勿进行操作)
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. encryptByEnAES,
  32. encryptByDeAES
  33. } from '../../utils/index.js'
  34. import {
  35. mapActions
  36. } from "vuex";
  37. export default {
  38. data() {
  39. return {
  40. username: '', //用户名
  41. password: '', //密码
  42. savePassword: false, //是否记住密码
  43. };
  44. },
  45. methods: {
  46. ...mapActions("user", ["vxLogin"]),
  47. // 登录
  48. login(e) {
  49. let {
  50. username, //账号
  51. password, //密码
  52. savePassword //是否记住密码
  53. } = e.detail.value;
  54. savePassword = savePassword.length > 0;
  55. username = username.trim();
  56. password = password.trim();
  57. // 用户名,密码,域名(ip)不能为空
  58. if (username === "" || password === "") {
  59. uni.showToast({
  60. icon: "none",
  61. title: "账号或密码错误",
  62. });
  63. return;
  64. }
  65. uni.showLoading({
  66. title: "登录中",
  67. mask: true,
  68. });
  69. let postData = {
  70. username,
  71. password,
  72. type: 'APP'
  73. };
  74. this.vxLogin(postData).then((res) => {
  75. uni.hideLoading();
  76. if (res.status == 200) {
  77. //获取角色信息
  78. let role = res.user.user.role;
  79. // 护士角色才能登录
  80. let nurseRole = role.some((item) => item.rolecode === "nurse");
  81. if (!nurseRole) {
  82. uni.showToast({
  83. icon: "none",
  84. title: "暂无护士角色权限!",
  85. });
  86. return;
  87. }
  88. // 如果记住密码,则缓存到本地
  89. if (savePassword) {
  90. //记住密码
  91. uni.setStorageSync("savePasswordObj", {
  92. username: encryptByEnAES(username), //用户名
  93. password: encryptByEnAES(password), //密码
  94. effectiveDuration: Date.now(), //当前时间戳
  95. })
  96. } else {
  97. uni.removeStorageSync('savePasswordObj');
  98. }
  99. // 跳转到首页
  100. uni.navigateTo({
  101. url: '../index/index'
  102. })
  103. } else {
  104. uni.showToast({
  105. icon: "none",
  106. title: res.remarks || "登录失败",
  107. });
  108. }
  109. });
  110. },
  111. },
  112. onLoad() {
  113. // 是否记住密码
  114. let savePasswordObj = uni.getStorageSync("savePasswordObj");
  115. if (savePasswordObj) {
  116. console.log(savePasswordObj);
  117. let {
  118. username,
  119. password,
  120. effectiveDuration
  121. } = savePasswordObj;
  122. if (Date.now() - effectiveDuration < 10 * 24 * 60 * 60 * 1000) {
  123. //记住密码,10天内有效
  124. this.username = encryptByDeAES(username);
  125. this.password = encryptByDeAES(password);
  126. this.savePassword = true;
  127. }
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .login {
  134. padding: 180rpx 32rpx 32rpx;
  135. height: 100vh;
  136. background: url("../../static/imgs/background.png") no-repeat center bottom;
  137. background-size: contain;
  138. .login_title {
  139. text-align: center;
  140. color: $defaultColor;
  141. font-weight: bold;
  142. }
  143. .form {
  144. .form_item {
  145. margin-top: 32rpx;
  146. @include flex;
  147. .form_title {
  148. @include flex(flex-start, center);
  149. width: 140rpx;
  150. .placeholder {
  151. display: inline-block;
  152. width: 1em;
  153. }
  154. }
  155. .form_input {
  156. box-sizing: content-box;
  157. flex: 1;
  158. padding: 16rpx;
  159. background-color: #fff;
  160. }
  161. }
  162. .form_submit {
  163. margin-top: 60rpx;
  164. border-radius: 16rpx;
  165. uni-button {
  166. @include btn_background;
  167. color: #fff;
  168. font-weight: bold;
  169. }
  170. }
  171. }
  172. .tips {
  173. font-size: 28rpx;
  174. margin-top: 16rpx;
  175. }
  176. }
  177. </style>