login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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_logo">
  5. <image :src="logo || 'https://img.picgo.net/2024/04/18/login_logo45cb6a5eb95c8c1c.png'"></image>
  6. </view>
  7. <view class="login-title">
  8. <label>智慧工厂信息化系统</label>
  9. <text>{{ companyName}}</text>
  10. </view>
  11. <view>
  12. <view class="login-content">
  13. <view>
  14. <view class="form">
  15. <view class="login-input">
  16. <label class="icon-lable"></label>
  17. <input name="input" v-model="userInfo.username" placeholder="请输入账号" />
  18. </view>
  19. <view class="login-input">
  20. <label class="icon-lable2"></label>
  21. <input class="" name="input" password v-model="userInfo.passwd" placeholder="请输入密码" />
  22. </view>
  23. <button @click="submit">登录</button>
  24. <view class="password-memo">
  25. <checkbox-group @change="checkboxChange">
  26. <label>
  27. <checkbox value="1" :checked="isMemo" />
  28. 记住密码
  29. </label>
  30. </checkbox-group>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <ServerSetting ref="serverSettingRef" @setServerStatus="setServerStatus" />
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. postJ
  42. } from "@/utils/api.js";
  43. import {
  44. login,
  45. usName
  46. } from "@/api/common.js";
  47. import {
  48. getResourcesTree
  49. } from '@/api/pda/common.js'
  50. import {
  51. setMemo,
  52. isMemo,
  53. removeMemo,
  54. setPassword,
  55. getPassword,
  56. } from "@/utils/passwordMemo.js";
  57. import ServerSetting from "@/components/ServerSetting/index";
  58. export default {
  59. components: {
  60. ServerSetting
  61. },
  62. data() {
  63. return {
  64. userInfo: {
  65. username: "",
  66. passwd: "",
  67. },
  68. isMemo: isMemo(),
  69. loginDisabled: false,
  70. companyName: null,
  71. logo: null,
  72. };
  73. },
  74. onLoad() {
  75. if (this.isMemo) {
  76. const userInfo = getPassword();
  77. if (userInfo?.username) this.userInfo = userInfo;
  78. }
  79. this.getUsName()
  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. getUsName() {
  93. usName().then(res => {
  94. this.companyName = res.companyName
  95. this.logo = res.logo
  96. })
  97. },
  98. setServerStatus(val) {
  99. this.loginDisabled = !val;
  100. },
  101. //登录
  102. // submit() {
  103. // // #ifdef APP-PLUS
  104. // if (!this.apiUrl) {
  105. // this.$refs.serverSettingRef.open();
  106. // return;
  107. // }
  108. // // #endif
  109. // const params = {
  110. // loginName: this.userInfo.username,
  111. // loginPwd: this.userInfo.passwd,
  112. // };
  113. // login(params)
  114. // .then((res) => {
  115. // if (this.isMemo) {
  116. // setPassword(this.userInfo);
  117. // }
  118. // let data = res.data;
  119. // uni.setStorageSync("token", data.token);
  120. // uni.setStorageSync("userInfo", data);
  121. // uni.showToast({
  122. // title: "登录成功",
  123. // icon: "success",
  124. // duration: 2000,
  125. // });
  126. // setTimeout(() => {
  127. // uni.reLaunch({
  128. // url: "/pages/home/home",
  129. // });
  130. // }, 2000);
  131. // })
  132. // .catch((err) => {
  133. // console.log(err, 222);
  134. // uni.showToast({
  135. // title: err.message || err,
  136. // icon: "none",
  137. // duration: 2000,
  138. // });
  139. // });
  140. // },
  141. //登录
  142. submit() {
  143. // #ifdef APP-PLUS
  144. if (!this.apiUrl) {
  145. this.$refs.serverSettingRef.open();
  146. return;
  147. }
  148. // #endif
  149. let param = {
  150. loginName: this.userInfo.username,
  151. loginPwd: this.userInfo.passwd
  152. }
  153. postJ(this.apiUrl + "/main/user/login", param)
  154. .then((res) => {
  155. if (this.isMemo) {
  156. setPassword(this.userInfo);
  157. }
  158. console.log(res);
  159. let data = res.data;
  160. uni.setStorageSync("token", data.token);
  161. uni.setStorageSync("userInfo", data);
  162. uni.showToast({
  163. title: "登录成功",
  164. icon: "success",
  165. duration: 2000,
  166. });
  167. this.getTree()
  168. setTimeout(() => {
  169. uni.reLaunch({
  170. url: "/pages/home/home",
  171. });
  172. }, 2000);
  173. })
  174. .catch((err) => {
  175. uni.showToast({
  176. title: err.message,
  177. icon: "none",
  178. duration: 2000,
  179. });
  180. });
  181. },
  182. handleServerSettings() {
  183. this.$refs.serverSettingRef.open();
  184. },
  185. checkboxChange(e) {
  186. this.isMemo = e.detail.value[0] === "1";
  187. if (this.isMemo) {
  188. setMemo();
  189. } else {
  190. removeMemo();
  191. }
  192. },
  193. getTree() {
  194. getResourcesTree().then(res => {
  195. console.log(res)
  196. if (res.length == 0) {
  197. uni.showToast({
  198. title: '您还未配置权限',
  199. icon: 'none'
  200. })
  201. }
  202. let List = JSON.stringify(res || [])
  203. uni.setStorageSync("treeList", List);
  204. })
  205. },
  206. },
  207. };
  208. </script>
  209. <style lang="scss" scoped>
  210. @import "login.scss";
  211. </style>