login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. <seiminModel ref="seiminModel"></seiminModel>
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. encryptByEnAES,
  33. encryptByDeAES
  34. } from "../../utils/index.js";
  35. import {
  36. mapActions,
  37. mapMutations
  38. } from "vuex";
  39. export default {
  40. data() {
  41. return {
  42. username: "", //用户名
  43. password: "", //密码
  44. savePassword: false, //是否记住密码
  45. };
  46. },
  47. methods: {
  48. ...mapActions("login", ["vxLogin"]),
  49. ...mapMutations("other", ["changeSeiminModel", "resetVxOther"]),
  50. ...mapMutations("dictionary", ["resetVxDictionary"]),
  51. ...mapMutations("login", ["resetVxLogin"]),
  52. ...mapMutations("system", ["resetVxSystem"]),
  53. // 重置vuex数据
  54. resetVuex() {
  55. this.resetVxOther();
  56. this.resetVxDictionary();
  57. this.resetVxLogin();
  58. this.resetVxSystem();
  59. },
  60. // 登录
  61. login(e) {
  62. let {
  63. username, //账号
  64. password, //密码
  65. savePassword, //是否记住密码
  66. } = e.detail.value;
  67. savePassword = savePassword.length > 0;
  68. username = username.trim();
  69. password = password.trim();
  70. // 用户名,密码,域名(ip)不能为空
  71. if (username === "" || password === "") {
  72. uni.showToast({
  73. icon: "none",
  74. title: "账号或密码错误",
  75. });
  76. return;
  77. }
  78. uni.showLoading({
  79. title: "登录中",
  80. mask: true,
  81. });
  82. let postData = {
  83. username,
  84. password,
  85. type: "APP",
  86. };
  87. this.vxLogin(postData).then((res) => {
  88. uni.hideLoading();
  89. if (res.status == 200) {
  90. //获取角色信息
  91. res.user = res.user || {};
  92. res.user.user = res.user.user || {};
  93. let role = res.user.user.role || [];
  94. // 护士角色才能登录
  95. let nurseRole = role.some((item) => item.rolecode === "nurse");
  96. if (!nurseRole) {
  97. uni.showToast({
  98. icon: "none",
  99. title: "暂无护士角色权限!",
  100. });
  101. return;
  102. }
  103. // 如果记住密码,则缓存到本地
  104. if (savePassword) {
  105. //记住密码
  106. uni.setStorageSync("savePasswordObj", {
  107. username: encryptByEnAES(username), //用户名
  108. password: encryptByEnAES(password), //密码
  109. effectiveDuration: Date.now(), //当前时间戳
  110. });
  111. } else {
  112. uni.removeStorageSync("savePasswordObj");
  113. }
  114. // 跳转到首页(isShowSeiminModel,是否显示切换科室弹窗)
  115. this.changeSeiminModel(true);
  116. uni.reLaunch({
  117. url: "/pages/index/index",
  118. });
  119. } else {
  120. this.$refs.seiminModel.show({
  121. skin: "toast",
  122. icon: "error",
  123. content: res.remarks || "登录失败",
  124. });
  125. throw new Error(res.remarks || "登录失败");
  126. }
  127. });
  128. },
  129. },
  130. onLoad() {
  131. // 清除vuex
  132. this.resetVuex();
  133. // 是否记住密码
  134. let savePasswordObj = uni.getStorageSync("savePasswordObj");
  135. if (savePasswordObj) {
  136. let {
  137. username,
  138. password,
  139. effectiveDuration
  140. } = savePasswordObj;
  141. if (Date.now() - effectiveDuration < 10 * 24 * 60 * 60 * 1000) {
  142. //记住密码,10天内有效
  143. this.username = encryptByDeAES(username);
  144. this.password = encryptByDeAES(password);
  145. this.savePassword = true;
  146. }
  147. }
  148. },
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. .login {
  153. padding: 180rpx 32rpx 32rpx;
  154. height: 100vh;
  155. background: url("../../static/imgs/background.png") no-repeat center bottom;
  156. background-size: contain;
  157. .login_title {
  158. text-align: center;
  159. color: $defaultColor;
  160. font-weight: bold;
  161. }
  162. .form {
  163. .form_item {
  164. margin-top: 32rpx;
  165. @include flex;
  166. .form_title {
  167. @include flex(flex-start, center);
  168. width: 4em;
  169. .placeholder {
  170. display: inline-block;
  171. width: 1em;
  172. }
  173. }
  174. .form_input {
  175. box-sizing: content-box;
  176. flex: 1;
  177. padding: 16rpx;
  178. background-color: #fff;
  179. }
  180. }
  181. .form_submit {
  182. margin-top: 60rpx;
  183. border-radius: 16rpx;
  184. uni-button {
  185. @include btn_background;
  186. color: #fff;
  187. font-weight: bold;
  188. }
  189. }
  190. }
  191. .tips {
  192. font-size: 28rpx;
  193. margin-top: 16rpx;
  194. }
  195. }
  196. </style>