login.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="login">
  3. <view class="login-header">
  4. <image src="../../static/logo.png" mode=""></image>
  5. <h2>{{$t('login.title')}}</h2>
  6. </view>
  7. <view class="login-form">
  8. <uni-easyinput type="text" v-model="loginForm.tenantId" :placeholder="$t('login.form.tenantId')" />
  9. <uni-easyinput type="text" v-model="loginForm.username" :placeholder="$t('login.form.username')" />
  10. <uni-easyinput type="password" v-model="loginForm.password" :placeholder="$t('login.form.password')" />
  11. <!-- <uni-easyinput type="text" v-model="loginForm.code" placeholder="验证码" />
  12. <image :src="image" @click="getCodeImg" style="width:200rpx;height:100rpx" mode=""></image> -->
  13. </view>
  14. <view class="login-btn">
  15. <view class="check-warp">
  16. <view class="check-icon-warp">
  17. <i class="iconfont" style="margin-right:16rpx">&#xe6cb;</i>
  18. </view>
  19. {{$t('login.agreement.text')}}
  20. <span>{{$t('login.agreement.clause')}}</span>
  21. {{$t('login.agreement.and')}}
  22. <span>{{$t('login.agreement.agreement')}}</span>
  23. </view>
  24. <button type="default" @click="lodingFn">{{$t('login.loginText')}}</button>
  25. <p @click="toDemo" class="demo">{{$t('login.demo')}}</p>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import Vue from 'vue'
  31. import {
  32. getParams
  33. } from '@/util/uitl.js'
  34. export default {
  35. data() {
  36. return {
  37. loginForm: {
  38. //租户ID
  39. tenantId: '000000',
  40. //部门ID
  41. deptId: '',
  42. //角色ID
  43. roleId: '',
  44. //用户名
  45. username: 'admin',
  46. //密码
  47. password: '',
  48. //账号类型
  49. type: 'loginWithoutVerificationCode',
  50. //验证码的值
  51. code: '',
  52. //验证码的索引
  53. key: '',
  54. grant_type: 'captcha',
  55. scope: 'all'
  56. //预加载白色背景
  57. },
  58. image: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
  59. formData: {}
  60. }
  61. },
  62. onLoad() {
  63. const v = this
  64. v.getCodeImg()
  65. },
  66. methods: {
  67. toDemo(){
  68. uni.navigateTo({
  69. url: '/pages/equipment/equipmentDemo'
  70. })
  71. },
  72. init() {
  73. const v = this
  74. },
  75. lodingFn() {
  76. function filter(str) { // 特殊字符转义
  77. str += ''; // 隐式转换
  78. str = str.replace(/%/g, '%25');
  79. str = str.replace(/\+/g, '%2B');
  80. str = str.replace(/ /g, '%20');
  81. str = str.replace(/\//g, '%2F');
  82. str = str.replace(/\?/g, '%3F');
  83. str = str.replace(/&/g, '%26');
  84. str = str.replace(/\=/g, '%3D');
  85. str = str.replace(/#/g, '%23');
  86. return str;
  87. }
  88. function formateObjToParamStr(paramObj) {
  89. const sdata = [];
  90. for (let attr in paramObj) {
  91. sdata.push(`${attr}=${filter(paramObj[attr])}`);
  92. }
  93. return sdata.join('&');
  94. }
  95. const loginForm = {...this.loginForm}
  96. loginForm.password = this.$w_md5.hex_md5_32(loginForm.password)
  97. console.log(loginForm)
  98. uni.request({
  99. url: 'http://36.134.91.96:10001/api' + '/blade-auth/oauth/token?' + formateObjToParamStr(loginForm),
  100. method: 'POST',
  101. header: {
  102. 'Content-Type': 'application/json',
  103. 'Captcha-Key': loginForm.key,
  104. 'Captcha-Code': loginForm.code,
  105. 'Tenant-Id': loginForm.tenantId,
  106. 'Authorization':'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
  107. 'Blade-Auth': undefined
  108. },
  109. success: res => {
  110. if(res.statusCode == 200){
  111. uni.setStorageSync('token', res.data.access_token)
  112. uni.setStorageSync('Authorization', res.data)
  113. Vue.prototype.$token = res.data
  114. uni.reLaunch({
  115. url: '/pages/equipment/equipment'
  116. })
  117. }else{
  118. console.log(res)
  119. uni.showToast({
  120. icon:"none",
  121. title: '账号密码错误!'
  122. })
  123. }
  124. },
  125. });
  126. },
  127. getCodeImg() {
  128. this.$get('/blade-auth/oauth/captcha').then((res) => {
  129. console.log(res)
  130. const data = res
  131. this.loginForm.key = data.key
  132. this.image = data.image
  133. })
  134. },
  135. },
  136. }
  137. </script>
  138. <style>
  139. </style>
  140. <style lang="less">
  141. /deep/ .uni-easyinput {
  142. margin-bottom: 24rpx;
  143. background-color: #F1F1F1;
  144. border-radius: 10rpx !important;
  145. }
  146. /deep/ .uni-easyinput__content {
  147. border-radius: 20rpx !important;
  148. border: none !important;
  149. }
  150. /deep/ .uni-easyinput__content-input {
  151. height: 110rpx;
  152. font-size: 32rpx;
  153. background-color: #F1F1F1;
  154. color: #999999;
  155. }
  156. .login {
  157. height: 100vh;
  158. width: 100vw;
  159. background-size: 100% 100%;
  160. .demo{
  161. margin-top: 30rpx;
  162. text-align: center;
  163. font-size: 24rpx;
  164. }
  165. .login-btn {
  166. button {
  167. background-color: #3370FF;
  168. color: #fff;
  169. font-size: 32rpx;
  170. border-radius: 45rpx;
  171. height: 90rpx;
  172. }
  173. .check-warp {
  174. margin-bottom: 32rpx;
  175. margin-top: 8rpx;
  176. font-size: 24rpx;
  177. display: flex;
  178. .check-icon-warp {
  179. height: 30rpx;
  180. width: 30rpx;
  181. border-radius: 50%;
  182. border: 2rpx solid #dddddd;
  183. margin-right: 10rpx;
  184. }
  185. .iconfont {
  186. color: #39C55A;
  187. text-align: center;
  188. position: relative;
  189. top: -2rpx;
  190. left: -2rpx;
  191. }
  192. }
  193. padding: 0 40rpx;
  194. }
  195. .login-header {
  196. padding: 128rpx 40rpx 0;
  197. background: url(../../static/images/login-header.png);
  198. background-size: 100% 100%;
  199. h2 {
  200. font-size: 48rpx;
  201. color: #333333;
  202. font-weight: 800;
  203. margin-top: 80rpx;
  204. }
  205. image {
  206. width: 280rpx;
  207. height: 90rpx;
  208. display: block;
  209. }
  210. }
  211. .login-form {
  212. margin-top: 64rpx;
  213. background: #fff;
  214. border-radius: 10rpx;
  215. padding: 0 40rpx;
  216. }
  217. }
  218. </style>