login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <view class="content">
  3. <view class="info_bg">
  4. <image src="../../static/management/login-bg.png" class="bgImg"></image>
  5. <div class="title">
  6. <image src="../../static/management/logo.svg"></image>
  7. <text>双碳感知资产运营管理平台</text>
  8. </div>
  9. </view>
  10. <view class="form-box">
  11. <view class="loginTxt">登录</view>
  12. <view class="row-input">
  13. <u-icon name="account" color="#2979ff" size="50" style="padding: 0 20rpx;"></u-icon>
  14. <input v-model="account" placeholder="请输入用户账号" maxlength="18" clearable />
  15. </view>
  16. <view class="row-input">
  17. <u-icon name="lock" color="#2979ff" size="50" style="padding: 0 20rpx;"></u-icon>
  18. <input v-model="password" placeholder="登陆密码" clearable :password="!isShowPassword" />
  19. <u-icon name="eye-fill" color="#2979ff" size="50" style="padding-right:20rpx" v-if="isShowPassword"
  20. @click="showOrHide"></u-icon>
  21. <u-icon name="eye-off" color="#2979ff" size="50" style="padding-right:0rpx" v-else @click="showOrHide">
  22. </u-icon>
  23. </view>
  24. <!-- <view class="menu-link">
  25. <text @click="forget">找回密码</text>
  26. </view> -->
  27. <view class="login-btn" @click="loginbtn">登录</view>
  28. <!-- <view class="tip-link">
  29. </view> -->
  30. </view>
  31. <u-toast ref="uToast" />
  32. </view>
  33. </template>
  34. <script>
  35. // function getUUID() {
  36. // return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
  37. // return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
  38. // })
  39. // }
  40. //const BaseApi= require("@/http/baseApi.js");
  41. export default {
  42. data() {
  43. return {
  44. isShowPassword: false,
  45. account: '',
  46. password: '',
  47. captcha: '',
  48. uuid: '',
  49. captchaPath: '',
  50. }
  51. },
  52. onLoad() {
  53. // this.getCaptcha();
  54. },
  55. onUnload() {
  56. //触发水印显示
  57. uni.$emit('ly-show-watermark');
  58. },
  59. methods: {
  60. loginbtn() {
  61. if (this.account == '') {
  62. this.$refs.uToast.show({
  63. type: 'error',
  64. message: "请输入账号",
  65. })
  66. } else if (this.password == '') {
  67. this.$refs.uToast.show({
  68. type: 'error',
  69. message: "请输入密码",
  70. })
  71. }
  72. let formData = {
  73. username: this.account,
  74. password: this.password,
  75. }
  76. //登录功能
  77. this.$api.post('/login', formData)
  78. .then(res => {
  79. if (res.data.code == 0) {
  80. uni.setStorageSync('tokendata', res.data.data.token); //token
  81. uni.setStorageSync('Userinformation', formData); //用户信息
  82. //获取用户的信息,如组织架构,个人信息,权限等
  83. Promise.all([this.getpermissions(), this.getDictList(), this.getuserInfo(), ]).then(() => {
  84. uni.navigateTo({
  85. url: '/pages/index/index'
  86. })
  87. });
  88. } else {
  89. this.$refs.uToast.show({
  90. type: 'error',
  91. message: "账号或者密码错误,请重新输入",
  92. })
  93. }
  94. })
  95. },
  96. getpermissions() {
  97. console.log('权限功能', )
  98. //获取用户权限功能
  99. return new Promise((resolve, reject) => {
  100. this.$api.get('/menu/permissions', {}).then((res) => {
  101. uni.setStorageSync('ButtonPermissions', res.data.data);
  102. resolve(res);
  103. // console.log('111111111111111111', res)
  104. }).catch(e => {
  105. reject(e)
  106. })
  107. });
  108. // this.$api.get('/menu/permissions', {})
  109. // .then(res1 => {
  110. // uni.setStorageSync('ButtonPermissions', res1.data.data); //权限列表
  111. // })
  112. },
  113. getDictList() {
  114. //获取字典列表, 添加并全局变量保存
  115. return new Promise((resolve, reject) => {
  116. this.$api.get('/all', {}).then((res) => {
  117. uni.setStorageSync('getDictDataList', res.data.data);
  118. resolve(res);
  119. // console.log('222222', res)
  120. }).catch(e => {
  121. reject(e)
  122. })
  123. });
  124. // this.$api.get('/all', {})
  125. // .then(res => {
  126. // // console.log('88888', res.data.data)
  127. // uni.setStorageSync('getDictDataList', res.data.data);
  128. // })
  129. },
  130. getuserInfo() {
  131. //获取用户信息
  132. return new Promise((resolve, reject) => {
  133. this.$api.get('/user/userInfo', {}).then((res) => {
  134. uni.setStorageSync('getuserInfo', res.data.data);
  135. resolve(res);
  136. //console.log('333333', res)
  137. }).catch(e => {
  138. reject(e)
  139. })
  140. });
  141. // this.$api.get('/user/userInfo', {})
  142. // .then(res => {
  143. // // console.log('88888', res.data.data)
  144. // uni.setStorageSync('getuserInfo', res.data.data);
  145. // })
  146. },
  147. // 密码显示/密码隐藏
  148. showOrHide() {
  149. this.isShowPassword = !this.isShowPassword
  150. },
  151. // 找回密码
  152. forget() {
  153. uni.navigateTo({
  154. url: '/pages/login/forget',
  155. success: res => {},
  156. fail: () => {},
  157. complete: () => {},
  158. })
  159. },
  160. // 注册
  161. register() {
  162. uni.navigateTo({
  163. url: '/pages/login/register',
  164. success: res => {},
  165. fail: () => {},
  166. complete: () => {},
  167. })
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss">
  173. .form-box {
  174. width: 91%;
  175. background: #fff;
  176. margin: -130rpx auto 0;
  177. position: relative;
  178. z-index: 3;
  179. padding: 60rpx 40rpx 100rpx;
  180. box-sizing: border-box;
  181. border-radius: 32rpx;
  182. .loginTxt{
  183. color: #0C1935;
  184. font-size: 40rpx;
  185. margin-bottom: 80rpx;
  186. text-align: center;
  187. }
  188. .row-input {
  189. display: flex;
  190. align-items: center;
  191. height: 80rpx;
  192. background-color: #F4F7FF;
  193. border-radius: 36rpx;
  194. margin-bottom: 40rpx;
  195. padding: 0 20rpx;
  196. input {
  197. width: 460rpx;
  198. font-size: 30rpx;
  199. color: #a1a2a3;
  200. flex: 1
  201. }
  202. }
  203. .login-btn {
  204. margin-top: 50px;
  205. font-size: 16px;
  206. letter-spacing: 7px;
  207. color: #FFFFFF;
  208. height: 40px;
  209. border-radius: 18px;
  210. background: #5C8FFF;
  211. text-align: center;
  212. line-height: 40px;
  213. }
  214. }
  215. .content {
  216. .bgImg {
  217. width: 78%;
  218. position: absolute;
  219. left: -5px;
  220. top: 9px;
  221. z-index: 0;
  222. }
  223. .title {
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. position: relative;
  228. z-index: 2;
  229. image {
  230. width: 64rpx;
  231. height: 64rpx;
  232. margin-right: 4rpx;
  233. }
  234. text {
  235. font-size: 36rpx;
  236. color: #fff;
  237. }
  238. }
  239. }
  240. .info_bg {
  241. padding-top: 40rpx;
  242. width: 100%;
  243. height: 400rpx;
  244. background: #5c8fff;
  245. border-radius: 0px 0px 32rpx 32rpx;
  246. position: relative;
  247. image {
  248. width: 272px;
  249. height: 157px;
  250. }
  251. }
  252. </style>