Login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. },
  75. handleSet: function() {
  76. if (!this.orgSelected) {
  77. this.$message.info("请先选择组织");
  78. } else this.setOrganizationId(this.orgSelected);
  79. },
  80. doOrganizationChoose() {
  81. this.loading = true;
  82. reqOrgChoose()
  83. .then(res => {
  84. if (res == null || res.length == 0) {
  85. this.$message.info("您没有加入任何组织!");
  86. } else if (res.length > 1) {
  87. this.isShowDialog = true;
  88. this.orgList = res;
  89. } else {
  90. this.setOrganizationId(res[0].id);
  91. }
  92. })
  93. .catch(err => {
  94. console.log(err);
  95. this.loading = false;
  96. this.$message.error("登录失败:" + err);
  97. });
  98. },
  99. setOrganizationId(id) {
  100. if (!id) {
  101. this.$message.error("发生了一点不愉快的错误!");
  102. return;
  103. }
  104. this.loading = true;
  105. reqOrganizationId({ orgId: id })
  106. .then(res => {
  107. this.isShowDialog = false;
  108. //导航到 正式页面
  109. this.$router.replace("/home/firmInfo");
  110. })
  111. .catch(err => {
  112. if (err.errMsg) this.$message.error(err.errMsg);
  113. else this.$message.error("服务器发生异常");
  114. })
  115. .finally(res => {
  116. this.loading = false;
  117. });
  118. }
  119. },
  120. mounted() {}
  121. };
  122. </script>
  123. <style lang="scss" scoped>
  124. .login {
  125. width: 100%;
  126. height: 100%;
  127. background: url(../../assets/login_bg.jpg) 0 0 no-repeat;
  128. background-size: 100% 100%;
  129. .shade {
  130. height: 100%;
  131. width: 100%;
  132. background-color: #8899aa44;
  133. display: flex;
  134. flex-direction: column;
  135. align-items: center;
  136. .header {
  137. font-size: 60px;
  138. color: #eee;
  139. margin: 180px 0 50px 0;
  140. display: flex;
  141. justify-content: center;
  142. align-items: center;
  143. .logo {
  144. height: 70px;
  145. width: 70px;
  146. margin-right: 20px;
  147. }
  148. }
  149. .article {
  150. width: 400px;
  151. background-color: #ffffff44;
  152. padding: 20px 60px 40px 20px;
  153. border-radius: 20px;
  154. h1 {
  155. font-size: 20px;
  156. color: #eee;
  157. margin-left: 25px;
  158. }
  159. /deep/ .el-form-item .el-form-item__label {
  160. color: #eee;
  161. }
  162. }
  163. }
  164. }
  165. </style>