login.vue 4.2 KB

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