login.vue 5.6 KB

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