login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="page">
  3. <view class="logo">
  4. <image
  5. src="~@/static/logo.png"
  6. mode="aspectFit"
  7. class="img"
  8. ></image>
  9. </view>
  10. <view class="form">
  11. <input
  12. class="input"
  13. v-model="username"
  14. placeholder="请输入用户名"
  15. @blur="queryDep"
  16. />
  17. <ld-select
  18. :list="depList"
  19. placeholder="请选择部门"
  20. class="input select"
  21. v-model="depId"
  22. @change="selectDep"
  23. />
  24. <input
  25. class="input"
  26. :password="true"
  27. v-model="password"
  28. placeholder="请输入密码"
  29. />
  30. <button class="btn" @tap="calllogin">立即登录</button>
  31. <view class="label" @tap="forget">忘记密码?</view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { queryDep, LoginFunc } from "@/services/login";
  37. export default {
  38. data() {
  39. return {
  40. loading: false,
  41. username: "",
  42. password: "",
  43. depId: "",
  44. count: 0,
  45. count2: 0,
  46. depList: [],
  47. };
  48. },
  49. methods: {
  50. async calllogin() {
  51. this.loading = true;
  52. if (this.username == "") {
  53. uni.showToast({
  54. icon: "none",
  55. title: "请输入手机号或邮箱",
  56. });
  57. this.loading = false;
  58. return;
  59. }
  60. if (!this.depId) {
  61. uni.showToast({
  62. icon: "none",
  63. title: "请选择部门",
  64. });
  65. this.loading = false;
  66. return;
  67. }
  68. if (this.password == "") {
  69. uni.showToast({
  70. icon: "none",
  71. title: "请输入密码",
  72. });
  73. this.loading = false;
  74. return;
  75. }
  76. const { data } = await LoginFunc({
  77. UserName: this.username,
  78. Password: this.password,
  79. DepId: this.depId,
  80. });
  81. uni.setStorageSync("token", data.token);
  82. uni.setStorageSync("user", data.user);
  83. uni.reLaunch({
  84. url: "../index/index",
  85. });
  86. },
  87. forget() {
  88. this.count2++;
  89. if (this.count2 >= 5) {
  90. uni.showToast({
  91. icon: "none",
  92. title: `当前环境为${uni.getStorageSync("ENV")}`,
  93. });
  94. } else {
  95. uni.showToast({
  96. duration: 1500,
  97. icon: "none",
  98. title: "请联系系统管理员",
  99. });
  100. }
  101. },
  102. selectDep(value) {
  103. this.depId = value + "";
  104. },
  105. async queryDep() {
  106. const res = await queryDep({
  107. userName: this.username,
  108. });
  109. this.depId = null;
  110. this.depList = res.data.map((item) => ({
  111. label: item.Name,
  112. value: item.ID,
  113. }));
  114. },
  115. },
  116. };
  117. </script>
  118. <style lang="scss" scoped>
  119. .page {
  120. display: flex;
  121. flex-direction: column;
  122. justify-content: space-evenly;
  123. position: relative;
  124. // padding-bottom: 50px;
  125. min-height: 100vh;
  126. display: flex;
  127. flex-direction: column;
  128. background: url("~@/static/bg.png") no-repeat center;
  129. background-size: cover;
  130. background-attachment: fixed;
  131. }
  132. .logo {
  133. height: 220rpx;
  134. display: flex;
  135. justify-content: center;
  136. align-items: center;
  137. background: #fff;
  138. .img {
  139. height: 138rpx;
  140. }
  141. }
  142. .form {
  143. width: 530rpx;
  144. margin: 0 auto;
  145. flex-direction: column;
  146. display: flex;
  147. padding: 74rpx 56rpx;
  148. border: 1px solid #fff;
  149. .input {
  150. width: 100%;
  151. margin-bottom: 25rpx;
  152. background: #fff;
  153. height: 70rpx;
  154. color: #777777;
  155. padding-left: 20rpx;
  156. font-size: 24rpx;
  157. border-radius: 0px;
  158. }
  159. .select {
  160. padding: 0;
  161. }
  162. .btn {
  163. background: #5b78bf;
  164. font-size: 30rpx;
  165. color: #ffffff;
  166. width: 100%;
  167. height: 72rpx;
  168. margin-top: 100rpx;
  169. }
  170. .label {
  171. font-size: 26rpx;
  172. margin-top: 50rpx;
  173. text-align: center;
  174. color: #ffffff;
  175. }
  176. }
  177. </style>