login.vue 5.7 KB

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