login.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="content">
  3. <uni-icons class="setting" type="gear" @click="handleServerSettings" size="50" color="#fff"></uni-icons>
  4. <view class="login-title">
  5. <label>智慧工厂信息化系统</label>
  6. <text>{{ gstitle}}</text>
  7. </view>
  8. <view>
  9. <view class="login-content">
  10. <view>
  11. <view class="form">
  12. <view class="login-input">
  13. <label class="icon-lable"></label>
  14. <input name="input" v-model="userInfo.username" placeholder="请输入账号" />
  15. </view>
  16. <view class="login-input">
  17. <label class="icon-lable2"></label>
  18. <input class="" name="input" password v-model="userInfo.passwd" placeholder="请输入密码" />
  19. </view>
  20. <button @click="submit">登录</button>
  21. <view class="password-memo">
  22. <checkbox-group @change="checkboxChange">
  23. <label>
  24. <checkbox value="1" :checked="isMemo" />
  25. 记住密码
  26. </label>
  27. </checkbox-group>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <ServerSetting ref="serverSettingRef" @setServerStatus="setServerStatus" />
  34. </view>
  35. </template>
  36. <script>
  37. import {
  38. postJ
  39. } from "@/utils/api.js";
  40. import {
  41. login,
  42. usName
  43. } from "@/api/common.js";
  44. import {
  45. getResourcesTree
  46. } from '@/api/pda/common.js'
  47. import {
  48. setMemo,
  49. isMemo,
  50. removeMemo,
  51. setPassword,
  52. getPassword,
  53. } from "@/utils/passwordMemo.js";
  54. import ServerSetting from "@/components/ServerSetting/index";
  55. export default {
  56. components: {
  57. ServerSetting
  58. },
  59. data() {
  60. return {
  61. userInfo: {
  62. username: "",
  63. passwd: "",
  64. },
  65. isMemo: isMemo(),
  66. loginDisabled: false,
  67. gstitle: null,
  68. };
  69. },
  70. onLoad() {
  71. if (this.isMemo) {
  72. const userInfo = getPassword();
  73. if (userInfo?.username) this.userInfo = userInfo;
  74. }
  75. this.getUsName()
  76. },
  77. mounted() {
  78. // #ifdef APP-PLUS
  79. this.$nextTick(() => {
  80. this.$refs.serverSettingRef && this.$refs.serverSettingRef.serverCheck();
  81. });
  82. // #endif
  83. // uni.reLaunch({
  84. // url: "/pages/home/home",
  85. // });
  86. },
  87. methods: {
  88. getUsName() {
  89. usName().then(res => {
  90. this.gstitle = res
  91. })
  92. },
  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);
  157. uni.showToast({
  158. title: "登录成功",
  159. icon: "success",
  160. duration: 2000,
  161. });
  162. this.getTree()
  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. getTree() {
  189. getResourcesTree().then(res => {
  190. console.log(res)
  191. if (res.length == 0) {
  192. uni.showToast({
  193. title: '您还未配置权限',
  194. icon: 'none'
  195. })
  196. }
  197. let List = JSON.stringify(res || [])
  198. uni.setStorageSync("treeList", List);
  199. })
  200. },
  201. },
  202. };
  203. </script>
  204. <style lang="scss" scoped>
  205. @import "login.scss";
  206. </style>