123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <template>
- <view class="login" style="background: url(../../static/login-bg.png);background-size: 100% 100%;">
- <view style="height:120rpx;width: 100%;">
- </view>
- <view class="login-form">
- <image src="../../static/logo.png" mode=""></image>
- <view class="">
- <uni-forms :modelValue="loginForm">
- <uni-forms-item required label="账号" name="name">
- <uni-easyinput type="text" v-model="loginForm.username" placeholder="请输入账号" />
- </uni-forms-item>
- <uni-forms-item required name="hobby" label="密码">
- <uni-easyinput type="password" v-model="loginForm.password" placeholder="请输入密码" />
- </uni-forms-item>
- </uni-forms>
- <button type="default" @click="lodingFn">登录</button>
- </view>
- </view>
- </view>
- </template>
- <script>
- import Vue from 'vue'
- import {
- TOKEN_NAME,
- OPENID
- } from '../../util/cacheConstant.js'
- import {
- usernameLogin,
- isBind
- } from "@/util/api.js";
-
- export default {
- data() {
- return {
- image: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
- loginForm: {
- //租户ID
- tenantId: '849380',
- //部门ID
- deptId: '',
- //角色ID
- roleId: '',
- //用户名
- username: '',
- //密码
- password: '',
- //账号类型
- type: 'account',
- //验证码的值
- code: '',
- //验证码的索引
- key: '',
- grant_type: 'captcha',
- scope: 'all',
- type:'storageApplet',
- jsCode:""
- //预加载白色背景
- },
- }
- },
- onLoad() {
- const v = this
- uni.getStorage({
- key: 'automaticLogin',
- success: function (res) {
- if(res.data) v.init()
-
- }
- });
- },
- methods: {
- init() {
- const v = this
- //v.getCodeImg()
- Vue.prototype.$token = null
- wx.login({
- success: res => {
- v.loginForm.jsCode = res.code
- 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 = {...v.loginForm}
-
-
- loginForm.password = this.$w_md5.hex_md5_32(loginForm.password)
- uni.request({
- url: 'https://cfm.bytesail.cn/api' + '/blade-auth/oauth/token?' + formateObjToParamStr(loginForm),
- method: 'POST',
- header: {
- 'Tenant-Id': v.loginForm.tenantId,
- 'Authorization':'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
- 'Content-Type':'application/json;charset=UTF-8',
- },
- success: (res) => {
-
- if(res.statusCode == 200){
- wx.setStorageSync(TOKEN_NAME, res.data)
- Vue.prototype.$token = res.data
- wx.reLaunch({
- url: '/pages/home'
- })
- }else{
- uni.showToast({
- icon: "error",
- title: res.data.error_description,
- duration: 2000
- });
- }
-
- },
- fail: (err) => {
-
- }
- });
- },
- fail: (response) => {
- wx.showToast({
- title: response,
- icon: 'none',
- duration: 2000
- });
- }
- })
- },
- getCodeImg() {
- const v = this
- v.$get('/blade-auth/oauth/captcha', {}).then(data => {
- v.loginForm.key = data.key
- v.image = data.image
- })
- },
- lodingFn() {
- const v = this
- const loginForm = {...v.loginForm}
- loginForm.password = this.$w_md5.hex_md5_32(loginForm.password)
- 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('&');
- }
- wx.login({
- success: res => {
- v.loginForm.jsCode = res.code
- const loginForm = {...v.loginForm}
- loginForm.password = this.$w_md5.hex_md5_32(loginForm.password)
- uni.request({
- url: 'https://cfm.bytesail.cn/api' + '/blade-auth/oauth/token?' + formateObjToParamStr(loginForm),
- method: 'POST',
- header: {
- 'Captcha-Key': v.loginForm.key,
- 'Captcha-Code': v.loginForm.code,
- 'Tenant-Id': v.loginForm.tenantId,
- 'Authorization':'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
- 'Content-Type':'application/json;charset=UTF-8',
- },
- success: (res) => {
- console.log(res)
- uni.setStorage({
- key: 'automaticLogin',
- data: true,
- success: function () {
-
- }
- });
- if(res.statusCode == 200){
- wx.setStorageSync(TOKEN_NAME, res.data)
- Vue.prototype.$token = res.data
- wx.reLaunch({
- url: '/pages/home'
- })
- }else{
- uni.showToast({
- icon: "none",
- title: res.data.error_description,
- duration: 2000
- });
- }
-
- },
- fail: (err) => {
- uni.showToast({
- title: '失败' + err,
- duration: 12000
- });
- }
- });
- }
- })
-
- },
- },
- }
- </script>
- <style lang="less">
- .login {
- height: 100vh;
- width: 100vw;
- background-size: 100% 100%;
- image {
- width: 550rpx;
- height: 125rpx;
- margin: 0 auto 100rpx;
- display: block;
- }
- .login-form {
- margin: 0 auto;
- width: 80%;
- background: #fff;
- border-radius: 10rpx;
- padding: 150rpx 50rpx;
- }
- }
- </style>
|