login.vue 4.9 KB

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