Login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="login">
  3. <div class="shade">
  4. <header class="header">
  5. <img class="logo" src="../../assets/logo.png" alt="长兴湖羊LOGO" />
  6. 长兴湖羊
  7. </header>
  8. <article class="article">
  9. <h1>登录界面</h1>
  10. <el-form label-position="right" label-width="80px" :model="form">
  11. <el-form-item label="账号:">
  12. <el-input v-model="form.userName" placeholder="请输入账号"></el-input>
  13. </el-form-item>
  14. <el-form-item label="密码:">
  15. <el-input v-model="form.userPwd" placeholder="请输入密码" show-password></el-input>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" @click="onSignIn">登录</el-button>
  19. </el-form-item>
  20. </el-form>
  21. </article>
  22. <el-dialog title="请选择一个组织" :visible.sync="isShowDialog" append-to-body>
  23. <el-select v-model="orgSelected">
  24. <el-option
  25. v-for="item in orgList"
  26. :key="item.id"
  27. :value="item.id"
  28. :label="item.orgName"
  29. ></el-option>
  30. </el-select>
  31. <div slot="footer">
  32. <el-button @click="isShowDialog=false">取 消</el-button>
  33. <el-button type="primary" @click="handleSet">设置</el-button>
  34. </div>
  35. </el-dialog>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import { reqLogin, reqOrgChoose, reqOrganizationId } from "@/api/login";
  41. export default {
  42. name: "login",
  43. data() {
  44. return {
  45. form: {
  46. userName: "huyang",
  47. userPwd: "123456"
  48. },
  49. isShowDialog: false,
  50. orgList: null,
  51. orgSelected: null
  52. };
  53. },
  54. created() {},
  55. methods: {
  56. /* 登录按钮 */
  57. onSignIn() {
  58. const loading = this.$loading({
  59. lock: true,
  60. text: "登录中...",
  61. spinner: "el-icon-loading",
  62. background: "rgba(0, 0, 0, 0.7)"
  63. });
  64. reqLogin(this.form)
  65. .then(res => {
  66. loading.close();
  67. localStorage.setItem("token", res.token);
  68. this.doOrganizationChoose();
  69. })
  70. .catch(err => {
  71. console.log("登录失败", err);
  72. this.$message.error("登录失败:" + err);
  73. });
  74. // this.$axios.post(`http://121.37.169.186:8081/my/login?accountName=${this.form.userName}&password=${this.form.userPwd}`)
  75. // .then(res => {
  76. // loading.close();
  77. // if(res.data.code === 10000) {
  78. // // localStorage.setItem("token", res.data.token);
  79. // // localStorage.setItem("token", res.token);
  80. // localStorage.setItem('accountName', res.data.accountName);
  81. // // this.$router.replace ("/home/dashboard");
  82. // } else {
  83. // this.$message.error(res.data.message);
  84. // }
  85. // })
  86. },
  87. handleSet: function() {
  88. if (!this.orgSelected) {
  89. this.$message.info("请先选择组织");
  90. } else this.setOrganizationId(this.orgSelected);
  91. },
  92. doOrganizationChoose() {
  93. this.loading = true;
  94. reqOrgChoose()
  95. .then(res => {
  96. if (res == null || res.length == 0) {
  97. this.$message.info("您没有加入任何组织!");
  98. } else if (res.length > 1) {
  99. this.isShowDialog = true;
  100. this.orgList = res;
  101. } else {
  102. this.setOrganizationId(res[0].id);
  103. }
  104. })
  105. .catch(err => {
  106. console.log(err);
  107. this.loading = false;
  108. this.$message.error("登录失败:" + err);
  109. });
  110. },
  111. setOrganizationId(id, accountName) {
  112. if (!id) {
  113. this.$message.error("发生了一点不愉快的错误!");
  114. return;
  115. }
  116. this.loading = true;
  117. reqOrganizationId({ orgId: id })
  118. .then(res => {
  119. this.isShowDialog = false;
  120. //导航到 正式页面
  121. // this.$router.replace({path: "/home", query: {name: accountName}});
  122. this.$router.replace ("/home/dashboard");
  123. })
  124. .catch(err => {
  125. if (err.errMsg) this.$message.error(err.errMsg);
  126. else this.$message.error("服务器发生异常");
  127. })
  128. .finally(res => {
  129. this.loading = false;
  130. });
  131. }
  132. },
  133. mounted() {}
  134. };
  135. </script>
  136. <style lang="scss" scoped>
  137. .login {
  138. width: 100%;
  139. height: 100%;
  140. background: url(../../assets/login_bg.jpg) 0 0 no-repeat;
  141. background-size: 100% 100%;
  142. .shade {
  143. height: 100%;
  144. width: 100%;
  145. background-color: #8899aa44;
  146. display: flex;
  147. flex-direction: column;
  148. align-items: center;
  149. .header {
  150. font-size: 60px;
  151. color: #eee;
  152. margin: 180px 0 50px 0;
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. .logo {
  157. height: 70px;
  158. width: 70px;
  159. margin-right: 20px;
  160. }
  161. }
  162. .article {
  163. width: 400px;
  164. background-color: #ffffff44;
  165. padding: 20px 60px 40px 20px;
  166. border-radius: 20px;
  167. h1 {
  168. font-size: 20px;
  169. color: #eee;
  170. margin-left: 25px;
  171. }
  172. /deep/ .el-form-item .el-form-item__label {
  173. color: #eee;
  174. }
  175. }
  176. }
  177. }
  178. </style>