login.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 { getResourcesTree } from '@/api/pda/common.js'
  58. import {
  59. setMemo,
  60. isMemo,
  61. removeMemo,
  62. setPassword,
  63. getPassword,
  64. } from "@/utils/passwordMemo.js";
  65. import ServerSetting from "@/components/ServerSetting/index";
  66. export default {
  67. components: { ServerSetting },
  68. data() {
  69. return {
  70. userInfo: {
  71. username: "",
  72. passwd: "",
  73. },
  74. isMemo: isMemo(),
  75. loginDisabled: false,
  76. };
  77. },
  78. onLoad() {
  79. if (this.isMemo) {
  80. const userInfo = getPassword();
  81. if (userInfo?.username) this.userInfo = userInfo;
  82. }
  83. },
  84. mounted() {
  85. // #ifdef APP-PLUS
  86. this.$nextTick(() => {
  87. this.$refs.serverSettingRef && this.$refs.serverSettingRef.serverCheck();
  88. });
  89. // #endif
  90. // uni.reLaunch({
  91. // url: "/pages/home/home",
  92. // });
  93. },
  94. methods: {
  95. setServerStatus(val) {
  96. this.loginDisabled = !val;
  97. },
  98. //登录
  99. // submit() {
  100. // // #ifdef APP-PLUS
  101. // if (!this.apiUrl) {
  102. // this.$refs.serverSettingRef.open();
  103. // return;
  104. // }
  105. // // #endif
  106. // const params = {
  107. // loginName: this.userInfo.username,
  108. // loginPwd: this.userInfo.passwd,
  109. // };
  110. // login(params)
  111. // .then((res) => {
  112. // if (this.isMemo) {
  113. // setPassword(this.userInfo);
  114. // }
  115. // let data = res.data;
  116. // uni.setStorageSync("token", data.token);
  117. // uni.setStorageSync("userInfo", data);
  118. // uni.showToast({
  119. // title: "登录成功",
  120. // icon: "success",
  121. // duration: 2000,
  122. // });
  123. // setTimeout(() => {
  124. // uni.reLaunch({
  125. // url: "/pages/home/home",
  126. // });
  127. // }, 2000);
  128. // })
  129. // .catch((err) => {
  130. // console.log(err, 222);
  131. // uni.showToast({
  132. // title: err.message || err,
  133. // icon: "none",
  134. // duration: 2000,
  135. // });
  136. // });
  137. // },
  138. //登录
  139. submit() {
  140. // #ifdef APP-PLUS
  141. if (!this.apiUrl) {
  142. this.$refs.serverSettingRef.open();
  143. return;
  144. }
  145. // #endif
  146. let param = {
  147. loginName: this.userInfo.username,
  148. loginPwd: this.userInfo.passwd
  149. }
  150. postJ(this.apiUrl + "/main/user/login",param)
  151. .then((res) => {
  152. if (this.isMemo) {
  153. setPassword(this.userInfo);
  154. }
  155. console.log(res);
  156. let data = res.data;
  157. uni.setStorageSync("token", data.token);
  158. uni.setStorageSync("userInfo", data.info);
  159. uni.showToast({
  160. title: "登录成功",
  161. icon: "success",
  162. duration: 2000,
  163. });
  164. this.getTree()
  165. setTimeout(() => {
  166. uni.reLaunch({
  167. url: "/pages/home/home",
  168. });
  169. }, 2000);
  170. })
  171. .catch((err) => {
  172. uni.showToast({
  173. title: err.message,
  174. icon: "none",
  175. duration: 2000,
  176. });
  177. });
  178. },
  179. handleServerSettings() {
  180. this.$refs.serverSettingRef.open();
  181. },
  182. checkboxChange(e) {
  183. this.isMemo = e.detail.value[0] === "1";
  184. if (this.isMemo) {
  185. setMemo();
  186. } else {
  187. removeMemo();
  188. }
  189. },
  190. getTree() {
  191. getResourcesTree().then(res => {
  192. console.log(res)
  193. if(res.length == 0) {
  194. uni.showToast({
  195. title: '您还未配置权限',
  196. icon: 'none'
  197. })
  198. }
  199. let List = JSON.stringify(res || [])
  200. uni.setStorageSync("treeList", List);
  201. })
  202. },
  203. },
  204. };
  205. </script>
  206. <style lang="scss" scoped>
  207. @import "login.scss";
  208. </style>