login.vue 4.9 KB

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