login.vue 5.0 KB

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