login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 class="logo_bj">嘉实</view>
  7. </view>
  8. <view class="login-title">
  9. <label>工业互联网平台</label>
  10. <text>{{ companyName }}</text>
  11. </view>
  12. <view>
  13. <view class="login-content">
  14. <view>
  15. <view class="form">
  16. <view class="login-input">
  17. <label class="icon-lable"></label>
  18. <input name="input" v-model="userInfo.username" placeholder="请输入账号" />
  19. </view>
  20. <view class="login-input">
  21. <label class="icon-lable2"></label>
  22. <input class="" name="input" password v-model="userInfo.passwd" placeholder="请输入密码" />
  23. </view>
  24. <button @click="submit">登录</button>
  25. <view class="password-memo">
  26. <checkbox-group @change="checkboxChange">
  27. <label>
  28. <checkbox value="1" :checked="isMemo" />
  29. 记住密码
  30. </label>
  31. </checkbox-group>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <ServerSetting ref="serverSettingRef" @setServerStatus="setServerStatus" />
  38. </view>
  39. </template>
  40. <script>
  41. import { postJ } from '@/utils/api.js'
  42. import { login, usName } from '@/api/common.js'
  43. import { getResourcesTree } from '@/api/pda/common.js'
  44. import { setMemo, isMemo, removeMemo, setPassword, getPassword } from '@/utils/passwordMemo.js'
  45. import ServerSetting from '@/components/ServerSetting/index'
  46. export default {
  47. components: {
  48. ServerSetting
  49. },
  50. data() {
  51. return {
  52. userInfo: {
  53. username: '',
  54. passwd: ''
  55. },
  56. isMemo: isMemo(),
  57. loginDisabled: false,
  58. companyName: null,
  59. logo: null
  60. }
  61. },
  62. onLoad() {
  63. if (this.isMemo) {
  64. const userInfo = getPassword()
  65. if (userInfo?.username) this.userInfo = userInfo
  66. }
  67. this.getUsName()
  68. },
  69. mounted() {
  70. // #ifdef APP-PLUS
  71. this.$nextTick(() => {
  72. this.$refs.serverSettingRef && this.$refs.serverSettingRef.serverCheck()
  73. })
  74. // #endif
  75. // uni.reLaunch({
  76. // url: "/pages/home/home",
  77. // });
  78. },
  79. methods: {
  80. getUsName() {
  81. usName().then(res => {
  82. this.companyName = res.companyName
  83. this.logo = res.logo
  84. })
  85. },
  86. setServerStatus(val) {
  87. this.loginDisabled = !val
  88. },
  89. //登录
  90. // submit() {
  91. // // #ifdef APP-PLUS
  92. // if (!this.apiUrl) {
  93. // this.$refs.serverSettingRef.open();
  94. // return;
  95. // }
  96. // // #endif
  97. // const params = {
  98. // loginName: this.userInfo.username,
  99. // loginPwd: this.userInfo.passwd,
  100. // };
  101. // login(params)
  102. // .then((res) => {
  103. // if (this.isMemo) {
  104. // setPassword(this.userInfo);
  105. // }
  106. // let data = res.data;
  107. // uni.setStorageSync("token", data.token);
  108. // uni.setStorageSync("userInfo", data);
  109. // uni.showToast({
  110. // title: "登录成功",
  111. // icon: "success",
  112. // duration: 2000,
  113. // });
  114. // setTimeout(() => {
  115. // uni.reLaunch({
  116. // url: "/pages/home/home",
  117. // });
  118. // }, 2000);
  119. // })
  120. // .catch((err) => {
  121. // console.log(err, 222);
  122. // uni.showToast({
  123. // title: err.message || err,
  124. // icon: "none",
  125. // duration: 2000,
  126. // });
  127. // });
  128. // },
  129. //登录
  130. submit() {
  131. // #ifdef APP-PLUS
  132. if (!this.apiUrl) {
  133. this.$refs.serverSettingRef.open()
  134. return
  135. }
  136. // #endif
  137. let param = {
  138. loginName: this.userInfo.username,
  139. loginPwd: this.userInfo.passwd
  140. }
  141. postJ(this.apiUrl + '/main/user/login', param)
  142. .then(res => {
  143. if (this.isMemo) {
  144. setPassword(this.userInfo)
  145. }
  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>