Ver código fonte

登录页面开发完成

seimin 3 anos atrás
pai
commit
9c050b6f3b
14 arquivos alterados com 327 adições e 63 exclusões
  1. 5 11
      App.vue
  2. 12 1
      package-lock.json
  3. 2 1
      package.json
  4. 22 15
      pages.json
  5. 195 0
      pages/login/login.vue
  6. 2 2
      request/config.js
  7. 0 6
      request/demo.js
  8. 10 0
      request/user.js
  9. BIN
      static/imgs/background.png
  10. 2 2
      store/index.js
  11. 0 25
      store/modules/demo.js
  12. 30 0
      store/modules/user.js
  13. 23 0
      uni.scss
  14. 24 0
      utils/index.js

+ 5 - 11
App.vue

@@ -1,8 +1,8 @@
1 1
 <script>
2
-import { mapActions } from "vuex";
2
+// import { mapActions } from "vuex";
3 3
 export default {
4 4
   methods: {
5
-    ...mapActions("demo", ["getData"]),
5
+    // ...mapActions("demo", ["getData"]),
6 6
   },
7 7
   onLaunch: function () {
8 8
     console.log("App Launch");
@@ -14,9 +14,9 @@ export default {
14 14
     console.log("App Hide");
15 15
   },
16 16
   mounted() {
17
-    this.getData().then((res) => {
18
-      console.log(res);
19
-    });
17
+    // this.getData().then((res) => {
18
+    //   console.log(res);
19
+    // });
20 20
   },
21 21
 };
22 22
 </script>
@@ -30,11 +30,5 @@ page {
30 30
   * {
31 31
     box-sizing: border-box;
32 32
   }
33
-  .red {
34
-    color: $textColorRed;
35
-  }
36
-  .green {
37
-    color: $defaultColor;
38
-  }
39 33
 }
40 34
 </style>

+ 12 - 1
package-lock.json

@@ -9,13 +9,19 @@
9 9
       "version": "1.0.0",
10 10
       "license": "ISC",
11 11
       "dependencies": {
12
-        "animate.css": "^4.1.1"
12
+        "animate.css": "^4.1.1",
13
+        "crypto-js": "^4.1.1"
13 14
       }
14 15
     },
15 16
     "node_modules/animate.css": {
16 17
       "version": "4.1.1",
17 18
       "resolved": "https://registry.npmmirror.com/animate.css/-/animate.css-4.1.1.tgz",
18 19
       "integrity": "sha512-+mRmCTv6SbCmtYJCN4faJMNFVNN5EuCTTprDTAo7YzIGji2KADmakjVA3+8mVDkZ2Bf09vayB35lSQIex2+QaQ=="
20
+    },
21
+    "node_modules/crypto-js": {
22
+      "version": "4.1.1",
23
+      "resolved": "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.1.1.tgz",
24
+      "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw=="
19 25
     }
20 26
   },
21 27
   "dependencies": {
@@ -23,6 +29,11 @@
23 29
       "version": "4.1.1",
24 30
       "resolved": "https://registry.npmmirror.com/animate.css/-/animate.css-4.1.1.tgz",
25 31
       "integrity": "sha512-+mRmCTv6SbCmtYJCN4faJMNFVNN5EuCTTprDTAo7YzIGji2KADmakjVA3+8mVDkZ2Bf09vayB35lSQIex2+QaQ=="
32
+    },
33
+    "crypto-js": {
34
+      "version": "4.1.1",
35
+      "resolved": "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.1.1.tgz",
36
+      "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw=="
26 37
     }
27 38
   }
28 39
 }

+ 2 - 1
package.json

@@ -14,6 +14,7 @@
14 14
   "author": "",
15 15
   "license": "ISC",
16 16
   "dependencies": {
17
-    "animate.css": "^4.1.1"
17
+    "animate.css": "^4.1.1",
18
+    "crypto-js": "^4.1.1"
18 19
   }
19 20
 }

+ 22 - 15
pages.json

@@ -1,17 +1,24 @@
1 1
 {
2
-	"pages": [{
3
-		"path": "pages/index/index",
4
-		"style": {
5
-			"navigationBarTitleText": "uni-app"
6
-		}
7
-	}],
8
-	"globalStyle": {
9
-		"navigationBarTextStyle": "black",
10
-		"navigationBarTitleText": "uni-app",
11
-		"navigationBarBackgroundColor": "#F8F8F8",
12
-		"backgroundColor": "#F8F8F8",
13
-		"app-plus": {
14
-			"background": "#efeff4"
15
-		}
16
-	}
2
+  "pages": [{
3
+      "path": "pages/login/login",
4
+      "style": {
5
+        "navigationBarTitleText": "登录"
6
+      }
7
+    },
8
+    {
9
+      "path": "pages/index/index",
10
+      "style": {
11
+        "navigationBarTitleText": "首页"
12
+      }
13
+    }
14
+  ],
15
+  "globalStyle": {
16
+    "navigationBarTextStyle": "white",
17
+    "navigationBarTitleText": "医疗服务中心转运系统",
18
+    "navigationBarBackgroundColor": "#353639",
19
+    "backgroundColor": "#F8F8F8",
20
+    "app-plus": {
21
+      "background": "#efeff4"
22
+    }
23
+  }
17 24
 }

+ 195 - 0
pages/login/login.vue

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

+ 2 - 2
request/config.js

@@ -11,8 +11,8 @@ const config = {
11 11
 };
12 12
 // 后端服务地址
13 13
 const baseUrls = {
14
-  development: "http://itsmpoc.dashitech.com/service", //开发环境
15
-  production: "http://itsmpoc.dashitech.com/service", //生产环境
14
+  development: "http://192.168.3.108/service", //开发环境
15
+  production: "http://192.168.3.108/service", //生产环境
16 16
 };
17 17
 config.baseUrl = baseUrls[process.env.NODE_ENV];
18 18
 export default config;

+ 0 - 6
request/demo.js

@@ -1,6 +0,0 @@
1
-import { request } from "./index.js";
2
-// 测试接口
3
-export const reqGetData = () =>
4
-  request({
5
-    url: "/auth/getSysName",
6
-  });

+ 10 - 0
request/user.js

@@ -0,0 +1,10 @@
1
+import {
2
+  request
3
+} from "./index.js";
4
+// 测试接口
5
+export const reqLogin = (postData) =>
6
+  request({
7
+    url: "/auth/login",
8
+    data: postData,
9
+    method: 'POST'
10
+  });

BIN
static/imgs/background.png


+ 2 - 2
store/index.js

@@ -8,7 +8,7 @@
8 8
 import Vue from "vue";
9 9
 import Vuex from "vuex";
10 10
 
11
-import demo from "@/store/modules/demo";
11
+import user from "@/store/modules/user";
12 12
 
13 13
 Vue.use(Vuex);
14 14
 
@@ -25,7 +25,7 @@ const myPlugin = (store) => {
25 25
 
26 26
 export default new Vuex.Store({
27 27
   modules: {
28
-    demo,
28
+    user,
29 29
   },
30 30
   plugins: [myPlugin],
31 31
 });

+ 0 - 25
store/modules/demo.js

@@ -1,25 +0,0 @@
1
-import { reqGetData } from "@/request/demo.js";
2
-const state = {
3
-  dataList: [],
4
-};
5
-const getters = {};
6
-const mutations = {
7
-  // 获取三级导航
8
-  getData(state, dataList) {
9
-    state.dataList = dataList;
10
-  },
11
-};
12
-const actions = {
13
-  async getData({ commit, state }) {
14
-    console.log(state);
15
-    let result = await reqGetData();
16
-    commit("getData", result.data);
17
-  },
18
-};
19
-export default {
20
-  namespaced: true,
21
-  state,
22
-  getters,
23
-  mutations,
24
-  actions,
25
-};

+ 30 - 0
store/modules/user.js

@@ -0,0 +1,30 @@
1
+import {
2
+  reqLogin
3
+} from "@/request/user.js";
4
+const state = {
5
+  loginInfo: {},
6
+};
7
+const getters = {};
8
+const mutations = {
9
+  vxLogin(state, args) {
10
+    state.loginInfo = args;
11
+  },
12
+};
13
+const actions = {
14
+  async vxLogin({
15
+    commit
16
+  }, args) {
17
+    let result = await reqLogin(args);
18
+    if (result.status == 200) {
19
+      commit("vxLogin", result.user);
20
+    }
21
+    return result;
22
+  },
23
+};
24
+export default {
25
+  namespaced: true,
26
+  state,
27
+  getters,
28
+  mutations,
29
+  actions,
30
+};

+ 23 - 0
uni.scss

@@ -22,3 +22,26 @@ $textColorRed: #ff3b53;
22 22
   align-items: $alignItem;
23 23
   flex-direction: $flexDirection;
24 24
 }
25
+// 按钮背景色
26
+@mixin btn_background {
27
+  background-image: linear-gradient(90deg,#72c172,#3bb197);
28
+}
29
+
30
+// 全局样式
31
+.red {
32
+  color: $textColorRed;
33
+}
34
+.green {
35
+  color: $defaultColor;
36
+}
37
+// 内置复选框 start
38
+.uni-label-pointer{
39
+  @include flex;
40
+}
41
+uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
42
+    border-color: $defaultColor;
43
+}
44
+.uni-checkbox-input-checked{
45
+  color: $defaultColor !important;
46
+}
47
+// 内置复选框 end

+ 24 - 0
utils/index.js

@@ -0,0 +1,24 @@
1
+import {
2
+  AES,
3
+  mode,
4
+  pad,
5
+  enc
6
+} from "crypto-js";
7
+//aes加密
8
+export function encryptByEnAES(data) {
9
+  let Key = "dsadmin";
10
+  let tmpAES = AES.encrypt(data, Key, {
11
+    mode: mode.CBC,
12
+    padding: pad.Pkcs7,
13
+  });
14
+  return tmpAES.toString();
15
+}
16
+//aes解密
17
+export function encryptByDeAES(data) {
18
+  let Key = "dsadmin";
19
+  let tmpDeAES = AES.decrypt(data, Key, {
20
+    mode: mode.CBC,
21
+    padding: pad.Pkcs7,
22
+  });
23
+  return tmpDeAES.toString(enc.Utf8);
24
+}