login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. <view class="form_title">域<text class="placeholder"></text>名:</view>
  15. <input class="form_input" name="ip" :value="ip" placeholder="请输入域名或IP地址" />
  16. </view>
  17. <view class="form_item">
  18. <checkbox-group name="savePassword">
  19. <label>
  20. <checkbox value="true" :checked="savePassword" /><text>记住密码</text>
  21. </label>
  22. </checkbox-group>
  23. </view>
  24. <view class="form_submit">
  25. <button form-type="submit">登录</button>
  26. </view>
  27. </form>
  28. <view class="tips red">
  29. (此系统为护士人员使用,其他科室人员请勿进行操作)
  30. </view>
  31. <seiminModel ref="seiminModel"></seiminModel>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. changeIP,
  37. } from "../../request/config.js";
  38. import {
  39. encryptByEnAES,
  40. encryptByDeAES
  41. } from "../../utils/index.js";
  42. import {
  43. mapActions,
  44. mapMutations
  45. } from "vuex";
  46. export default {
  47. data() {
  48. return {
  49. reFresh: '',
  50. username: "", //用户名
  51. password: "", //密码
  52. ip: "", //域名
  53. savePassword: false, //是否记住密码
  54. };
  55. },
  56. methods: {
  57. ...mapActions("login", ["vxLogin"]),
  58. ...mapMutations("other", ["changeSeiminModel", "resetVxOther"]),
  59. ...mapMutations("dictionary", ["resetVxDictionary"]),
  60. ...mapMutations("login", ["resetVxLogin"]),
  61. ...mapMutations("system", ["resetVxSystem"]),
  62. // 重置vuex数据
  63. resetVuex() {
  64. this.resetVxOther();
  65. this.resetVxDictionary();
  66. this.resetVxLogin();
  67. this.resetVxSystem();
  68. },
  69. // 登录
  70. login(e) {
  71. let {
  72. username, //账号
  73. password, //密码
  74. ip, //域名
  75. savePassword, //是否记住密码
  76. } = e.detail.value;
  77. savePassword = savePassword.length > 0;
  78. username = username.trim();
  79. password = password.trim();
  80. ip = ip.trim();
  81. // 用户名,密码不能为空
  82. if (username === "" || password === "") {
  83. uni.showToast({
  84. icon: "none",
  85. title: "账号或密码错误",
  86. });
  87. return;
  88. }
  89. // 域名ip正则验证
  90. let regUrl =
  91. /^https?:\/\/([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)| (io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp))(\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))?$/;
  92. let regIp =
  93. /^https?:\/\/((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d)(\.((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d)){3}(\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5]))?$/;
  94. if (!regUrl.test(ip) && !regIp.test(ip)) {
  95. uni.showToast({
  96. icon: "none",
  97. title: "请输入正确的域名或IP",
  98. });
  99. return;
  100. }
  101. uni.showLoading({
  102. title: "登录中",
  103. mask: true,
  104. });
  105. let postData = {
  106. username,
  107. password,
  108. type: "APP",
  109. };
  110. changeIP(ip);
  111. this.vxLogin(postData).then((res) => {
  112. uni.hideLoading();
  113. if (res.status == 200) {
  114. //获取角色信息
  115. res.user = res.user || {};
  116. res.user.user = res.user.user || {};
  117. let role = res.user.user.role || [];
  118. // 护士角色才能登录
  119. let nurseRole = role.some((item) => item.rolecode === "nurse");
  120. if (!nurseRole) {
  121. uni.showToast({
  122. icon: "none",
  123. title: "暂无护士角色权限!",
  124. });
  125. return;
  126. }
  127. // 如果记住密码,则缓存到本地
  128. if (savePassword) {
  129. //记住密码
  130. uni.setStorageSync("savePasswordObj", {
  131. username: encryptByEnAES(username), //用户名
  132. password: encryptByEnAES(password), //密码
  133. ip, //域名
  134. effectiveDuration: Date.now(), //当前时间戳
  135. });
  136. } else {
  137. uni.removeStorageSync("savePasswordObj");
  138. }
  139. // 跳转到首页(isShowSeiminModel,是否显示切换科室弹窗)
  140. this.changeSeiminModel(true);
  141. uni.reLaunch({
  142. url: "/pages/index/index",
  143. });
  144. } else {
  145. this.$refs.seiminModel.show({
  146. skin: "toast",
  147. icon: "error",
  148. content: res.remarks || "登录失败",
  149. });
  150. throw new Error(res.remarks || "登录失败");
  151. }
  152. });
  153. },
  154. },
  155. onLoad() {
  156. // 清除vuex
  157. this.resetVuex();
  158. // 是否记住密码
  159. let savePasswordObj = uni.getStorageSync("savePasswordObj");
  160. // 初始化数据
  161. this.username = '';
  162. this.password = '';
  163. this.ip = 'http://zzzx.tjh.com';
  164. this.savePassword = false;
  165. if (savePasswordObj) {
  166. let {
  167. username,
  168. password,
  169. ip,
  170. effectiveDuration
  171. } = savePasswordObj;
  172. if (Date.now() - effectiveDuration < 10 * 24 * 60 * 60 * 1000) {
  173. //记住密码,10天内有效
  174. this.username = encryptByDeAES(username);
  175. this.password = encryptByDeAES(password);
  176. this.ip = ip;
  177. this.savePassword = true;
  178. }
  179. }
  180. },
  181. };
  182. </script>
  183. <style lang="scss" scoped>
  184. .login {
  185. padding: 180rpx 32rpx 32rpx;
  186. height: 100vh;
  187. background: url("../../static/imgs/background.png") no-repeat center bottom;
  188. background-size: contain;
  189. .login_title {
  190. text-align: center;
  191. color: $defaultColor;
  192. font-weight: bold;
  193. }
  194. .form {
  195. .form_item {
  196. margin-top: 32rpx;
  197. @include flex;
  198. .form_title {
  199. @include flex(flex-start, center);
  200. width: 4em;
  201. .placeholder {
  202. display: inline-block;
  203. width: 1em;
  204. }
  205. }
  206. .form_input {
  207. box-sizing: content-box;
  208. flex: 1;
  209. padding: 16rpx;
  210. background-color: #fff;
  211. }
  212. }
  213. .form_submit {
  214. margin-top: 60rpx;
  215. border-radius: 16rpx;
  216. uni-button {
  217. @include btn_background;
  218. color: #fff;
  219. font-weight: bold;
  220. }
  221. }
  222. }
  223. .tips {
  224. font-size: 28rpx;
  225. margin-top: 16rpx;
  226. }
  227. }
  228. </style>