login.vue 4.9 KB

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