123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <template>
- <view class="login">
- <view class="login-header">
- <image src="../../static/logo.png" mode=""></image>
- <h2>{{$t('login.title')}}</h2>
- </view>
- <view class="login-form">
- <uni-easyinput type="text" v-model="loginForm.tenantId" :placeholder="$t('login.form.tenantId')" />
- <uni-easyinput type="text" v-model="loginForm.username" :placeholder="$t('login.form.username')" />
- <uni-easyinput type="password" v-model="loginForm.password" :placeholder="$t('login.form.password')" />
- <uni-easyinput type="text" v-model="loginForm.code" placeholder="验证码" />
- <image :src="image" @click="getCodeImg" style="width:200rpx;height:100rpx" mode=""></image>
- </view>
- <view class="login-btn">
- <view class="check-warp">
- <view class="check-icon-warp">
- <i class="iconfont" style="margin-right:16rpx"></i>
- </view>
- {{$t('login.agreement.text')}}
- {{$t('login.agreement.clause')}}
- {{$t('login.agreement.and')}}
- {{$t('login.agreement.agreement')}}
- <span></span>
-
- <span></span>
- </view>
- <button type="default" @click="lodingFn">{{$t('login.loginText')}}</button>
- <p @click="toDemo" class="demo">{{$t('login.demo')}}</p>
- <!-- <p @click="change11">切换 {{system_info}}</p> -->
- </view>
- </view>
- </template>
- <script>
- import Vue from 'vue'
- import {
- getParams
- } from '@/util/uitl.js'
- export default {
- data() {
- return {
- loginForm: {
- //租户ID
- tenantId: '',
- //部门ID
- deptId: '',
- //角色ID
- roleId: '',
- //用户名
- username: '',
- //密码
- password: '',
- //账号类型
- type: 'loginWithoutVerificationCode',
- //验证码的值
- code: '',
- //验证码的索引
- key: '',
- grant_type: 'captcha',
- scope: 'all'
- //预加载白色背景
- },
- image: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
- formData: {},
- system_info:'123123123123',
- }
- },
- onLoad() {
- const v = this
- v.getCodeImg()
- },
- methods: {
- toDemo() {
- uni.navigateTo({
- url: '/pages/equipment/equipmentDemo'
- })
- },
- init() {
- const v = this
- },
- lodingFn() {
- function filter(str) { // 特殊字符转义
- str += ''; // 隐式转换
- str = str.replace(/%/g, '%25');
- str = str.replace(/\+/g, '%2B');
- str = str.replace(/ /g, '%20');
- str = str.replace(/\//g, '%2F');
- str = str.replace(/\?/g, '%3F');
- str = str.replace(/&/g, '%26');
- str = str.replace(/\=/g, '%3D');
- str = str.replace(/#/g, '%23');
- return str;
- }
- function formateObjToParamStr(paramObj) {
- const sdata = [];
- for (let attr in paramObj) {
- sdata.push(`${attr}=${filter(paramObj[attr])}`);
- }
- return sdata.join('&');
- }
- const loginForm = {
- ...this.loginForm
- }
- loginForm.password = this.$w_md5.hex_md5_32(loginForm.password)
- console.log(loginForm)
- uni.request({
- url: 'https://cfm.bytesail.cn/api' + '/blade-auth/oauth/token?' + formateObjToParamStr(
- loginForm),
- method: 'POST',
- header: {
- 'Content-Type': 'application/json',
- 'Captcha-Key': loginForm.key,
- 'Captcha-Code': loginForm.code,
- 'Tenant-Id': loginForm.tenantId,
- 'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
- 'Blade-Auth': undefined
- },
- success: res => {
- if (res.statusCode == 200) {
- uni.setStorageSync('token', res.data.access_token)
- uni.setStorageSync('Authorization', res.data)
- Vue.prototype.$token = res.data
- uni.reLaunch({
- url: '/pages/equipment/equipment'
- })
- } else {
- console.log(res)
- uni.showToast({
- icon: "none",
- title: res.data.error_description
- })
- this.getCodeImg()
- }
- },
- });
- },
- getCodeImg() {
- this.$get('/blade-auth/oauth/captcha').then((res) => {
- console.log(res)
- const data = res
- this.loginForm.key = data.key
- this.image = data.image
- })
- },
- change11() {
- let system_info = uni.getStorageSync('locale');
- console.log(system_info)
- !system_info || system_info == 'zh-CN' ? system_info = this._i18n.locale = 'en' :
- system_info = this._i18n.locale = 'zh-CN'
-
- uni.setStorageSync('locale', system_info);
-
- }
- },
- }
- </script>
- <style>
- </style>
- <style lang="less">
- /deep/ .uni-easyinput {
- margin-bottom: 24rpx;
- background-color: #F1F1F1;
- border-radius: 10rpx !important;
- }
- /deep/ .uni-easyinput__content {
- border-radius: 20rpx !important;
- border: none !important;
- }
- /deep/ .uni-easyinput__content-input {
- height: 110rpx;
- font-size: 32rpx;
- background-color: #F1F1F1;
- color: #999999;
- }
- .login {
- height: 100vh;
- width: 100vw;
- background-size: 100% 100%;
- .demo {
- margin-top: 30rpx;
- text-align: center;
- font-size: 24rpx;
- }
- .login-btn {
- button {
- background-color: #3370FF;
- color: #fff;
- font-size: 32rpx;
- border-radius: 45rpx;
- height: 90rpx;
- }
- .check-warp {
- margin-bottom: 32rpx;
- margin-top: 8rpx;
- font-size: 24rpx;
- display: flex;
- .check-icon-warp {
- height: 30rpx;
- width: 30rpx;
- border-radius: 50%;
- border: 2rpx solid #dddddd;
- margin-right: 10rpx;
- }
- .iconfont {
- color: #39C55A;
- text-align: center;
- position: relative;
- top: -2rpx;
- left: -2rpx;
- }
- }
- padding: 0 40rpx;
- }
- .login-header {
- padding: 128rpx 40rpx 0;
- background: url(../../static/images/login-header.png);
- background-size: 100% 100%;
- h2 {
- font-size: 48rpx;
- color: #333333;
- font-weight: 800;
- margin-top: 80rpx;
- }
- image {
- width: 280rpx;
- height: 90rpx;
- display: block;
- }
- }
- .login-form {
- margin-top: 64rpx;
- background: #fff;
- border-radius: 10rpx;
- padding: 0 40rpx;
- }
- }
- </style>
|