login.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view class="content">
  3. <uni-icons
  4. class="setting"
  5. type="gear"
  6. @click="handleServerSettings"
  7. size="50"
  8. color="#fff"
  9. ></uni-icons>
  10. <view class="login-title">
  11. <label>智慧工厂信息化系统</label>
  12. <text>株洲硬质合金集团型材分公司</text>
  13. </view>
  14. <view>
  15. <view class="login-content">
  16. <view>
  17. <view class="form">
  18. <view class="login-input">
  19. <label class="icon-lable"></label>
  20. <input
  21. name="input"
  22. v-model="userInfo.username"
  23. placeholder="请输入账号"
  24. />
  25. </view>
  26. <view class="login-input">
  27. <label class="icon-lable2"></label>
  28. <input
  29. class=""
  30. name="input"
  31. password
  32. v-model="userInfo.passwd"
  33. placeholder="请输入密码"
  34. />
  35. </view>
  36. <button @click="submit">登录</button>
  37. <view class="password-memo">
  38. <checkbox-group @change="checkboxChange">
  39. <label>
  40. <checkbox value="1" :checked="isMemo" />
  41. 记住密码
  42. </label>
  43. </checkbox-group>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <ServerSetting ref="serverSettingRef" @setServerStatus="setServerStatus" />
  50. </view>
  51. </template>
  52. <script>
  53. import { postJ } from "@/utils/api.js";
  54. import { login } from "@/api/common.js";
  55. import {
  56. setMemo,
  57. isMemo,
  58. removeMemo,
  59. setPassword,
  60. getPassword,
  61. } from "@/utils/passwordMemo.js";
  62. import ServerSetting from "@/components/ServerSetting/index";
  63. export default {
  64. components: { ServerSetting },
  65. data() {
  66. return {
  67. userInfo: {
  68. username: "",
  69. passwd: "",
  70. },
  71. isMemo: isMemo(),
  72. loginDisabled: false,
  73. };
  74. },
  75. onLoad() {
  76. if (this.isMemo) {
  77. const userInfo = getPassword();
  78. if (userInfo?.username) this.userInfo = userInfo;
  79. }
  80. },
  81. mounted() {
  82. // #ifdef APP-PLUS
  83. this.$nextTick(() => {
  84. this.$refs.serverSettingRef && this.$refs.serverSettingRef.serverCheck();
  85. });
  86. // #endif
  87. // uni.reLaunch({
  88. // url: "/pages/home/home",
  89. // });
  90. },
  91. methods: {
  92. setServerStatus(val) {
  93. this.loginDisabled = !val;
  94. },
  95. //登录
  96. // submit() {
  97. // // #ifdef APP-PLUS
  98. // if (!this.apiUrl) {
  99. // this.$refs.serverSettingRef.open();
  100. // return;
  101. // }
  102. // // #endif
  103. // const params = {
  104. // loginName: this.userInfo.username,
  105. // loginPwd: this.userInfo.passwd,
  106. // };
  107. // login(params)
  108. // .then((res) => {
  109. // if (this.isMemo) {
  110. // setPassword(this.userInfo);
  111. // }
  112. // let data = res.data;
  113. // uni.setStorageSync("token", data.token);
  114. // uni.setStorageSync("userInfo", data);
  115. // uni.showToast({
  116. // title: "登录成功",
  117. // icon: "success",
  118. // duration: 2000,
  119. // });
  120. // setTimeout(() => {
  121. // uni.reLaunch({
  122. // url: "/pages/home/home",
  123. // });
  124. // }, 2000);
  125. // })
  126. // .catch((err) => {
  127. // console.log(err, 222);
  128. // uni.showToast({
  129. // title: err.message || err,
  130. // icon: "none",
  131. // duration: 2000,
  132. // });
  133. // });
  134. // },
  135. //登录
  136. submit() {
  137. // #ifdef APP-PLUS
  138. if (!this.apiUrl) {
  139. this.$refs.serverSettingRef.open();
  140. return;
  141. }
  142. // #endif
  143. let param = {
  144. loginName: this.userInfo.username,
  145. loginPwd: this.userInfo.passwd
  146. }
  147. postJ(this.apiUrl + "/main/user/login",param)
  148. .then((res) => {
  149. if (this.isMemo) {
  150. setPassword(this.userInfo);
  151. }
  152. console.log(res);
  153. let data = res.data;
  154. uni.setStorageSync("token", data.token);
  155. uni.setStorageSync("userInfo", data.info);
  156. uni.showToast({
  157. title: "登录成功",
  158. icon: "success",
  159. duration: 2000,
  160. });
  161. setTimeout(() => {
  162. uni.reLaunch({
  163. url: "/pages/home/home",
  164. });
  165. }, 2000);
  166. })
  167. .catch((err) => {
  168. uni.showToast({
  169. title: err.message,
  170. icon: "none",
  171. duration: 2000,
  172. });
  173. });
  174. },
  175. handleServerSettings() {
  176. this.$refs.serverSettingRef.open();
  177. },
  178. checkboxChange(e) {
  179. this.isMemo = e.detail.value[0] === "1";
  180. if (this.isMemo) {
  181. setMemo();
  182. } else {
  183. removeMemo();
  184. }
  185. },
  186. },
  187. };
  188. </script>
  189. <style lang="scss" scoped>
  190. @import "login.scss";
  191. </style>