Login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. },
  56. methods: {
  57. /* 登录按钮 */
  58. onSignIn() {
  59. const loading = this.$loading({
  60. lock: true,
  61. text: "登录中...",
  62. spinner: "el-icon-loading",
  63. background: "rgba(0, 0, 0, 0.7)"
  64. });
  65. reqLogin(this.form)
  66. .then(res => {
  67. loading.close();
  68. localStorage.setItem("token", res.token);
  69. this.doOrganizationChoose();
  70. })
  71. .catch(err => {
  72. console.log("登录失败", 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().then(res => {
  83. if (res == null || res.length == 0) {
  84. this.$message.info("您没有加入任何组织!");
  85. } else if (res.length > 1) {
  86. this.isShowDialog = true;
  87. this.orgList = res;
  88. } else {
  89. this.setOrganizationId(res[0].id);
  90. }
  91. }).catch(err => {
  92. console.log(err)
  93. this.loading = false;
  94. })
  95. },
  96. setOrganizationId(id){
  97. if (!id) {
  98. this.$message.error("发生了一点不愉快的错误!");
  99. return;
  100. }
  101. this.loading = true;
  102. reqOrganizationId({orgId: id}).then(res => {
  103. this.isShowDialog = false;
  104. //导航到 正式页面
  105. console.log(999999)
  106. this.$router.push({
  107. path: "/home",
  108. query: {
  109. // target: "定点屠宰智能管控"
  110. target: "产品制作智能监控"
  111. // target: "鲜肉储运智能管控"
  112. }
  113. });
  114. }).catch(err => {
  115. if (err.errMsg) this.$message.error(err.errMsg);
  116. else this.$message.error("服务器发生异常");
  117. }).finally( res => {
  118. this.loading = false;
  119. })
  120. },
  121. },
  122. mounted() {}
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .login {
  127. width: 100%;
  128. height: 100%;
  129. background: url(../../assets/login_bg.jpg) 0 0 no-repeat;
  130. background-size: 100%;
  131. .shade {
  132. height: 100%;
  133. width: 100%;
  134. background-color: #8899aa44;
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. .header {
  139. font-size: 60px;
  140. color: #eee;
  141. margin: 180px 0 50px 0;
  142. display: flex;
  143. justify-content: center;
  144. align-items: center;
  145. .logo {
  146. height: 70px;
  147. width: 70px;
  148. margin-right: 20px;
  149. }
  150. }
  151. .article {
  152. width: 400px;
  153. background-color: #ffffff44;
  154. padding: 20px 60px 40px 20px;
  155. border-radius: 20px;
  156. h1 {
  157. font-size: 20px;
  158. color: #eee;
  159. margin-left: 25px;
  160. }
  161. /deep/ .el-form-item .el-form-item__label {
  162. color: #eee;
  163. }
  164. }
  165. }
  166. }
  167. </style>