login.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. uni.request({
  98. url: 'http://36.134.91.96:10001/api' + '/blade-auth/oauth/token?' + formateObjToParamStr(loginForm),
  99. method: 'POST',
  100. header: {
  101. 'Content-Type': 'application/json',
  102. 'Captcha-Key': loginForm.key,
  103. 'Captcha-Code': loginForm.code,
  104. 'Tenant-Id': loginForm.tenantId,
  105. 'Authorization':'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
  106. 'Blade-Auth': undefined
  107. },
  108. success: res => {
  109. if(res.statusCode == 200){
  110. uni.setStorageSync('token', res.data.access_token)
  111. uni.setStorageSync('Authorization', res.data)
  112. Vue.prototype.$token = res.data
  113. uni.reLaunch({
  114. url: '/pages/equipment/equipment'
  115. })
  116. }else{
  117. console.log(res)
  118. uni.showToast({
  119. icon:"none",
  120. title: '账号密码错误!'
  121. })
  122. }
  123. },
  124. });
  125. },
  126. getCodeImg() {
  127. this.$get('/blade-auth/oauth/captcha').then((res) => {
  128. console.log(res)
  129. const data = res
  130. this.loginForm.key = data.key
  131. this.image = data.image
  132. })
  133. },
  134. },
  135. }
  136. </script>
  137. <style>
  138. </style>
  139. <style lang="less">
  140. /deep/ .uni-easyinput {
  141. margin-bottom: 24rpx;
  142. background-color: #F1F1F1;
  143. border-radius: 10rpx !important;
  144. }
  145. /deep/ .uni-easyinput__content {
  146. border-radius: 20rpx !important;
  147. border: none !important;
  148. }
  149. /deep/ .uni-easyinput__content-input {
  150. height: 110rpx;
  151. font-size: 32rpx;
  152. background-color: #F1F1F1;
  153. color: #999999;
  154. }
  155. .login {
  156. height: 100vh;
  157. width: 100vw;
  158. background-size: 100% 100%;
  159. .demo{
  160. margin-top: 30rpx;
  161. text-align: center;
  162. font-size: 24rpx;
  163. }
  164. .login-btn {
  165. button {
  166. background-color: #3370FF;
  167. color: #fff;
  168. font-size: 32rpx;
  169. border-radius: 45rpx;
  170. height: 90rpx;
  171. }
  172. .check-warp {
  173. margin-bottom: 32rpx;
  174. margin-top: 8rpx;
  175. font-size: 24rpx;
  176. display: flex;
  177. .check-icon-warp {
  178. height: 30rpx;
  179. width: 30rpx;
  180. border-radius: 50%;
  181. border: 2rpx solid #dddddd;
  182. margin-right: 10rpx;
  183. }
  184. .iconfont {
  185. color: #39C55A;
  186. text-align: center;
  187. position: relative;
  188. top: -2rpx;
  189. left: -2rpx;
  190. }
  191. }
  192. padding: 0 40rpx;
  193. }
  194. .login-header {
  195. padding: 128rpx 40rpx 0;
  196. background: url(../../static/images/login-header.png);
  197. background-size: 100% 100%;
  198. h2 {
  199. font-size: 48rpx;
  200. color: #333333;
  201. font-weight: 800;
  202. margin-top: 80rpx;
  203. }
  204. image {
  205. width: 280rpx;
  206. height: 90rpx;
  207. display: block;
  208. }
  209. }
  210. .login-form {
  211. margin-top: 64rpx;
  212. background: #fff;
  213. border-radius: 10rpx;
  214. padding: 0 40rpx;
  215. }
  216. }
  217. </style>