新增第三方系统登陆

dev
smallchill 6 years ago
parent 58f9710dcb
commit 1f4af05d12
  1. 28
      src/api/user.js
  2. 6
      src/config/env.js
  3. 2
      src/config/website.js
  4. 2
      src/lang/en.js
  5. 2
      src/lang/zh.js
  6. 71
      src/page/login/index.vue
  7. 107
      src/page/login/thirdlogin.vue
  8. 3
      src/page/login/userlogin.vue
  9. 43
      src/store/modules/user.js
  10. 379
      src/util/util.js
  11. 93
      src/views/wel/index.vue

@ -19,6 +19,22 @@ export const loginByUsername = (tenantId, username, password, type, key, code) =
} }
}); });
export const loginBySocial = (tenantId, source, code, state) => request({
url: '/api/blade-auth/oauth/token',
method: 'post',
headers: {
'Tenant-Id': tenantId
},
params: {
tenantId,
source,
code,
state,
grant_type: "social",
scope: "all",
}
})
export const refreshToken = (refresh_token, tenantId) => request({ export const refreshToken = (refresh_token, tenantId) => request({
url: '/api/blade-auth/oauth/token', url: '/api/blade-auth/oauth/token',
method: 'post', method: 'post',
@ -33,6 +49,18 @@ export const refreshToken = (refresh_token, tenantId) => request({
} }
}); });
export const registerGuest = (form, oauthId) => request({
url: '/api/blade-user/register-guest',
method: 'post',
params: {
tenantId: form.tenantId,
name: form.name,
account: form.account,
password: form.password,
oauthId
}
});
export const getButtons = () => request({ export const getButtons = () => request({
url: '/api/blade-system/menu/buttons', url: '/api/blade-system/menu/buttons',
method: 'get' method: 'get'

@ -5,11 +5,11 @@ let iconfontVersion = ['567566_pwc3oottzol', '1066523_6bvkeuqao36'];
let iconfontUrl = `//at.alicdn.com/t/font_$key.css`; let iconfontUrl = `//at.alicdn.com/t/font_$key.css`;
let codeUrl = `${baseUrl}/code` let codeUrl = `${baseUrl}/code`
const env = process.env const env = process.env
if (env.NODE_ENV == 'development') { if (env.NODE_ENV === 'development') {
baseUrl = ``; // 开发环境地址 baseUrl = ``; // 开发环境地址
} else if (env.NODE_ENV == 'production') { } else if (env.NODE_ENV === 'production') {
baseUrl = ``; //生产环境地址 baseUrl = ``; //生产环境地址
} else if (env.NODE_ENV == 'test') { } else if (env.NODE_ENV === 'test') {
baseUrl = ``; //测试环境地址 baseUrl = ``; //测试环境地址
} }
export { export {

@ -38,6 +38,8 @@ export default {
children: 'children' children: 'children'
} }
}, },
// 授权地址
authUrl: 'http://localhost/blade-auth/oauth/render',
// 流程设计器地址 // 流程设计器地址
flowDesignUrl: 'http://localhost:9999', flowDesignUrl: 'http://localhost:9999',
} }

@ -73,6 +73,8 @@ export default {
password: 'Please input a password', password: 'Please input a password',
wechat: 'Wechat', wechat: 'Wechat',
qq: 'QQ', qq: 'QQ',
github: 'github',
gitee: 'gitee',
phone: 'Please input a phone', phone: 'Please input a phone',
code: 'Please input a code', code: 'Please input a code',
submit: 'Login', submit: 'Login',

@ -73,6 +73,8 @@ export default {
password: '请输入密码', password: '请输入密码',
wechat: '微信', wechat: '微信',
qq: 'QQ', qq: 'QQ',
github: 'github',
gitee: '码云',
phone: '请输入手机号', phone: '请输入手机号',
code: '请输入验证码', code: '请输入验证码',
submit: '登录', submit: '登录',

@ -1,8 +1,7 @@
<template> <template>
<div class="login-container" <div class="login-container"
ref="login"
@keyup.enter.native="handleLogin"> @keyup.enter.native="handleLogin">
<top-color v-show="false"/> <top-color v-show="false"></top-color>
<div class="login-weaper animated bounceInDown"> <div class="login-weaper animated bounceInDown">
<div class="login-left"> <div class="login-left">
<div class="login-time"> <div class="login-time">
@ -17,11 +16,11 @@
<div class="login-main"> <div class="login-main">
<h4 class="login-title"> <h4 class="login-title">
{{ $t('login.title') }}{{website.title}} {{ $t('login.title') }}{{website.title}}
<top-lang/> <top-lang></top-lang>
</h4> </h4>
<userLogin v-if="activeName==='user'"/> <userLogin v-if="activeName==='user'"></userLogin>
<codeLogin v-else-if="activeName==='code'"/> <codeLogin v-else-if="activeName==='code'"></codeLogin>
<thirdLogin v-else-if="activeName==='third'"/> <thirdLogin v-else-if="activeName==='third'"></thirdLogin>
<div class="login-menu"> <div class="login-menu">
<a href="#" <a href="#"
@click.stop="activeName='user'">{{ $t('login.userLogin') }}</a> @click.stop="activeName='user'">{{ $t('login.userLogin') }}</a>
@ -45,6 +44,7 @@
import {validatenull} from "@/util/validate"; import {validatenull} from "@/util/validate";
import topLang from "@/page/index/top/top-lang"; import topLang from "@/page/index/top/top-lang";
import topColor from "@/page/index/top/top-color"; import topColor from "@/page/index/top/top-color";
import {getQueryString, getTopUrl} from "@/util/util";
export default { export default {
name: "login", name: "login",
@ -58,43 +58,60 @@
data() { data() {
return { return {
time: "", time: "",
activeName: "user" activeName: "user",
socialForm: {
tenantId: "000000",
source: "",
code: "",
state: "",
}
}; };
}, },
watch: { watch: {
$route() { $route() {
const params = this.$route.query; this.handleLogin();
this.socialForm.state = params.state;
this.socialForm.code = params.code;
if (!validatenull(this.socialForm.state)) {
const loading = this.$loading({
lock: true,
text: `${
this.socialForm.state === "WX" ? "微信" : "QQ"
}登录中,请稍后`,
spinner: "el-icon-loading"
});
setTimeout(() => {
loading.close();
}, 2000);
}
} }
}, },
created() { created() {
this.handleLogin();
this.getTime(); this.getTime();
setInterval(() => {
this.getTime();
}, 1000);
}, },
mounted() { mounted() {
}, },
computed: { computed: {
...mapGetters(["website"]) ...mapGetters(["website", "tagWel"])
}, },
props: [], props: [],
methods: { methods: {
getTime() { getTime() {
this.time = dateFormat(new Date()); setInterval(() => {
this.time = dateFormat(new Date());
}, 1000);
},
handleLogin() {
const topUrl = getTopUrl();
const redirectUrl = "/oauth/redirect/";
if (topUrl.includes(redirectUrl)) {
let source = topUrl.split("?")[0];
source = source.split(redirectUrl)[1];
this.socialForm.source = source;
this.socialForm.code = getQueryString("code");
this.socialForm.state = getQueryString("state");
}
if (!validatenull(this.socialForm.source) && !validatenull(this.socialForm.code) && !validatenull(this.socialForm.state)) {
const loading = this.$loading({
lock: true,
text: '第三方系统登录中,请稍后。。。',
spinner: "el-icon-loading"
});
this.$store.dispatch("LoginBySocial", this.socialForm).then(() => {
window.location.href = topUrl.split(redirectUrl)[0];
this.$router.push({path: this.tagWel.value});
loading.close();
}).catch(() => {
loading.close();
});
}
} }
} }
}; };

@ -1,84 +1,59 @@
<template> <template>
<div class="social-container"> <div class="social-container">
<div class="box" <div class="box" @click="handleClick('github')">
@click="handleClick('wechat')"> <span class="container" :style="{backgroundColor:'#6ba2d6'}">
<span class="container" <i icon-class="github" class="iconfont icongithub"></i>
:style="{backgroundColor:'#6ba2d6'}">
<i icon-class="wechat"
class="iconfont icon-weixin"/>
</span> </span>
<p class="title">{{$t('login.wechat')}}</p> <p class="title">{{$t('login.github')}}</p>
</div> </div>
<div class="box" <div class="box" @click="handleClick('gitee')">
@click="handleClick('tencent')"> <span class="container" :style="{backgroundColor:'#c35152'}">
<span class="container" <i icon-class="gitee" class="iconfont icongitee2"></i>
:style="{backgroundColor:'#8dc349'}">
<i icon-class="qq"
class="iconfont icon-qq"/>
</span> </span>
<p class="title">{{$t('login.qq')}}</p> <p class="title">{{$t('login.gitee')}}</p>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { openWindow } from "@/util/util"; import website from '@/config/website';
export default { export default {
name: "thirdLogin", name: "thirdLogin",
methods: { methods: {
handleClick(thirdpart) { handleClick(source) {
let appid, client_id, redirect_uri, url; window.location.href = `${website.authUrl}/${source}`;
redirect_uri = encodeURIComponent( //openWindow(authUrl, source, 540, 540);
window.location.origin + "/#/authredirect"
);
if (thirdpart === "wechat") {
appid = "xxxx";
url =
"https://open.weixin.qq.com/connect/qrconnect?appid=" +
appid +
"&redirect_uri=" +
redirect_uri +
"&state=WX&response_type=code&scope=snsapi_login#wechat_redirect";
} else if (thirdpart === "tencent") {
client_id = "xxxx";
url =
"https://graph.qq.com/oauth2.0/authorize?response_type=code&state=QQ&client_id=" +
client_id +
"&redirect_uri=" +
redirect_uri;
} }
openWindow(url, thirdpart, 540, 540);
} }
} };
};
</script> </script>
<style rel="stylesheet/scss" lang="scss" scoped> <style rel="stylesheet/scss" lang="scss" scoped>
.social-container { .social-container {
margin: 20px 0; margin: 20px 0;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-around; justify-content: space-around;
.box { .box {
cursor: pointer; cursor: pointer;
} }
.iconfont { .iconfont {
color: #fff; color: #fff;
font-size: 30px; font-size: 30px;
} }
.container { .container {
$height: 50px; $height: 50px;
display: inline-block; display: inline-block;
width: $height; width: $height;
height: $height; height: $height;
line-height: $height; line-height: $height;
text-align: center; text-align: center;
border-radius: 4px; border-radius: 4px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.title { .title {
text-align: center; text-align: center;
}
} }
}
</style> </style>

@ -67,6 +67,7 @@
import {mapGetters} from "vuex"; import {mapGetters} from "vuex";
import {info} from "@/api/system/tenant"; import {info} from "@/api/system/tenant";
import {getCaptcha} from "@/api/user"; import {getCaptcha} from "@/api/user";
import {getTopUrl} from "@/util/util";
export default { export default {
name: "userlogin", name: "userlogin",
@ -146,7 +147,7 @@
}); });
}, },
getTenant() { getTenant() {
let domain = window.location.href.split("/#/")[0]; let domain = getTopUrl();
// 便 // 便
//domain = "https://bladex.vip"; //domain = "https://bladex.vip";
info(domain).then(res => { info(domain).then(res => {

@ -4,7 +4,7 @@ import {setStore, getStore} from '@/util/store'
import {isURL, validatenull} from '@/util/validate' import {isURL, validatenull} from '@/util/validate'
import {deepClone} from '@/util/util' import {deepClone} from '@/util/util'
import website from '@/config/website' import website from '@/config/website'
import {loginByUsername, getUserInfo, logout, refreshToken, getButtons} from '@/api/user' import {loginByUsername, loginBySocial, getUserInfo, logout, refreshToken, getButtons} from '@/api/user'
import {getTopMenu, getRoutes} from '@/api/system/menu' import {getTopMenu, getRoutes} from '@/api/system/menu'
import md5 from 'js-md5' import md5 from 'js-md5'
@ -69,15 +69,6 @@ const user = {
}) })
}) })
}, },
GetButtons({commit}) {
return new Promise((resolve) => {
getButtons().then(res => {
const data = res.data.data;
commit('SET_PERMISSION', data);
resolve();
})
})
},
//根据手机号登录 //根据手机号登录
LoginByPhone({commit}, userInfo) { LoginByPhone({commit}, userInfo) {
return new Promise((resolve) => { return new Promise((resolve) => {
@ -90,6 +81,28 @@ const user = {
}) })
}) })
}, },
//根据第三方信息登录
LoginBySocial({ commit }, userInfo) {
return new Promise((resolve) => {
loginBySocial(userInfo.tenantId, userInfo.source, userInfo.code, userInfo.state).then(res => {
const data = res.data;
if (data.error_description) {
Message({
message: data.error_description,
type: 'error'
})
} else {
commit('SET_TOKEN', data.access_token);
commit('SET_REFRESH_TOKEN', data.refresh_token);
commit('SET_USER_INFO', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
}
resolve();
})
})
},
//获取用户信息
GetUserInfo({commit}) { GetUserInfo({commit}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getUserInfo().then((res) => { getUserInfo().then((res) => {
@ -173,6 +186,16 @@ const user = {
}) })
}) })
}, },
//获取系统按钮
GetButtons({commit}) {
return new Promise((resolve) => {
getButtons().then(res => {
const data = res.data.data;
commit('SET_PERMISSION', data);
resolve();
})
})
},
}, },
mutations: { mutations: {
SET_TOKEN: (state, token) => { SET_TOKEN: (state, token) => {

@ -1,30 +1,30 @@
import { validatenull } from './validate' import {validatenull} from './validate'
//表单序列化 //表单序列化
export const serialize = data => { export const serialize = data => {
let list = []; let list = [];
Object.keys(data).forEach(ele => { Object.keys(data).forEach(ele => {
list.push(`${ele}=${data[ele]}`) list.push(`${ele}=${data[ele]}`)
}) })
return list.join('&'); return list.join('&');
}; };
export const getObjType = obj => { export const getObjType = obj => {
var toString = Object.prototype.toString; var toString = Object.prototype.toString;
var map = { var map = {
'[object Boolean]': 'boolean', '[object Boolean]': 'boolean',
'[object Number]': 'number', '[object Number]': 'number',
'[object String]': 'string', '[object String]': 'string',
'[object Function]': 'function', '[object Function]': 'function',
'[object Array]': 'array', '[object Array]': 'array',
'[object Date]': 'date', '[object Date]': 'date',
'[object RegExp]': 'regExp', '[object RegExp]': 'regExp',
'[object Undefined]': 'undefined', '[object Undefined]': 'undefined',
'[object Null]': 'null', '[object Null]': 'null',
'[object Object]': 'object' '[object Object]': 'object'
}; };
if (obj instanceof Element) { if (obj instanceof Element) {
return 'element'; return 'element';
} }
return map[toString.call(obj)]; return map[toString.call(obj)];
}; };
export const getViewDom = () => { export const getViewDom = () => {
return window.document.getElementById('avue-view').getElementsByClassName('el-scrollbar__wrap')[0] return window.document.getElementById('avue-view').getElementsByClassName('el-scrollbar__wrap')[0]
@ -33,66 +33,66 @@ export const getViewDom = () => {
* 对象深拷贝 * 对象深拷贝
*/ */
export const deepClone = data => { export const deepClone = data => {
var type = getObjType(data); var type = getObjType(data);
var obj; var obj;
if (type === 'array') { if (type === 'array') {
obj = []; obj = [];
} else if (type === 'object') { } else if (type === 'object') {
obj = {}; obj = {};
} else { } else {
//不再具有下一层次 //不再具有下一层次
return data; return data;
}
if (type === 'array') {
for (var i = 0, len = data.length; i < len; i++) {
obj.push(deepClone(data[i]));
} }
if (type === 'array') { } else if (type === 'object') {
for (var i = 0, len = data.length; i < len; i++) { for (var key in data) {
obj.push(deepClone(data[i])); obj[key] = deepClone(data[key]);
}
} else if (type === 'object') {
for (var key in data) {
obj[key] = deepClone(data[key]);
}
} }
return obj; }
return obj;
}; };
/** /**
* 设置灰度模式 * 设置灰度模式
*/ */
export const toggleGrayMode = (status) => { export const toggleGrayMode = (status) => {
if (status) { if (status) {
document.body.className = document.body.className + ' grayMode'; document.body.className = document.body.className + ' grayMode';
} else { } else {
document.body.className = document.body.className.replace(' grayMode', ''); document.body.className = document.body.className.replace(' grayMode', '');
} }
}; };
/** /**
* 设置主题 * 设置主题
*/ */
export const setTheme = (name) => { export const setTheme = (name) => {
document.body.className = name; document.body.className = name;
} }
/** /**
* 加密处理 * 加密处理
*/ */
export const encryption = (params) => { export const encryption = (params) => {
let { let {
data, data,
type, type,
param, param,
key key
} = params; } = params;
let result = JSON.parse(JSON.stringify(data)); let result = JSON.parse(JSON.stringify(data));
if (type == 'Base64') { if (type == 'Base64') {
param.forEach(ele => { param.forEach(ele => {
result[ele] = btoa(result[ele]); result[ele] = btoa(result[ele]);
}) })
} else if (type == 'Aes') { } else if (type == 'Aes') {
param.forEach(ele => { param.forEach(ele => {
result[ele] = window.CryptoJS.AES.encrypt(result[ele], key).toString(); result[ele] = window.CryptoJS.AES.encrypt(result[ele], key).toString();
}) })
} }
return result; return result;
}; };
@ -100,82 +100,83 @@ export const encryption = (params) => {
* 浏览器判断是否全屏 * 浏览器判断是否全屏
*/ */
export const fullscreenToggel = () => { export const fullscreenToggel = () => {
if (fullscreenEnable()) { if (fullscreenEnable()) {
exitFullScreen(); exitFullScreen();
} else { } else {
reqFullScreen(); reqFullScreen();
} }
}; };
/** /**
* esc监听全屏 * esc监听全屏
*/ */
export const listenfullscreen = (callback) => { export const listenfullscreen = (callback) => {
function listen() { function listen() {
callback() callback()
} }
document.addEventListener("fullscreenchange", function () {
listen(); document.addEventListener("fullscreenchange", function () {
}); listen();
document.addEventListener("mozfullscreenchange", function () { });
listen(); document.addEventListener("mozfullscreenchange", function () {
}); listen();
document.addEventListener("webkitfullscreenchange", function () { });
listen(); document.addEventListener("webkitfullscreenchange", function () {
}); listen();
document.addEventListener("msfullscreenchange", function () { });
listen(); document.addEventListener("msfullscreenchange", function () {
}); listen();
});
}; };
/** /**
* 浏览器判断是否全屏 * 浏览器判断是否全屏
*/ */
export const fullscreenEnable = () => { export const fullscreenEnable = () => {
var isFullscreen = document.isFullScreen || document.mozIsFullScreen || document.webkitIsFullScreen var isFullscreen = document.isFullScreen || document.mozIsFullScreen || document.webkitIsFullScreen
return isFullscreen; return isFullscreen;
} }
/** /**
* 浏览器全屏 * 浏览器全屏
*/ */
export const reqFullScreen = () => { export const reqFullScreen = () => {
if (document.documentElement.requestFullScreen) { if (document.documentElement.requestFullScreen) {
document.documentElement.requestFullScreen(); document.documentElement.requestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) { } else if (document.documentElement.webkitRequestFullScreen) {
document.documentElement.webkitRequestFullScreen(); document.documentElement.webkitRequestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) { } else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen(); document.documentElement.mozRequestFullScreen();
} }
}; };
/** /**
* 浏览器退出全屏 * 浏览器退出全屏
*/ */
export const exitFullScreen = () => { export const exitFullScreen = () => {
if (document.documentElement.requestFullScreen) { if (document.documentElement.requestFullScreen) {
document.exitFullScreen(); document.exitFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) { } else if (document.documentElement.webkitRequestFullScreen) {
document.webkitCancelFullScreen(); document.webkitCancelFullScreen();
} else if (document.documentElement.mozRequestFullScreen) { } else if (document.documentElement.mozRequestFullScreen) {
document.mozCancelFullScreen(); document.mozCancelFullScreen();
} }
}; };
/** /**
* 递归寻找子类的父类 * 递归寻找子类的父类
*/ */
export const findParent = (menu, id) => { export const findParent = (menu, id) => {
for (let i = 0; i < menu.length; i++) { for (let i = 0; i < menu.length; i++) {
if (menu[i].children.length != 0) { if (menu[i].children.length != 0) {
for (let j = 0; j < menu[i].children.length; j++) { for (let j = 0; j < menu[i].children.length; j++) {
if (menu[i].children[j].id == id) { if (menu[i].children[j].id == id) {
return menu[i]; return menu[i];
} else { } else {
if (menu[i].children[j].children.length != 0) { if (menu[i].children[j].children.length != 0) {
return findParent(menu[i].children[j].children, id); return findParent(menu[i].children[j].children, id);
} }
}
}
} }
}
} }
}
}; };
/** /**
* 判断2个对象属性和值是否相等 * 判断2个对象属性和值是否相等
@ -186,106 +187,124 @@ export const findParent = (menu, id) => {
*/ */
export const loadStyle = url => { export const loadStyle = url => {
const link = document.createElement('link'); const link = document.createElement('link');
link.type = 'text/css'; link.type = 'text/css';
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.href = url; link.href = url;
const head = document.getElementsByTagName('head')[0]; const head = document.getElementsByTagName('head')[0];
head.appendChild(link); head.appendChild(link);
}; };
/** /**
* 判断路由是否相等 * 判断路由是否相等
*/ */
export const diff = (obj1, obj2) => { export const diff = (obj1, obj2) => {
delete obj1.close; delete obj1.close;
var o1 = obj1 instanceof Object; var o1 = obj1 instanceof Object;
var o2 = obj2 instanceof Object; var o2 = obj2 instanceof Object;
if (!o1 || !o2) { /* 判断不是对象 */ if (!o1 || !o2) { /* 判断不是对象 */
return obj1 === obj2; return obj1 === obj2;
} }
if (Object.keys(obj1).length !== Object.keys(obj2).length) { if (Object.keys(obj1).length !== Object.keys(obj2).length) {
return false; return false;
//Object.keys() 返回一个由对象的自身可枚举属性(key值)组成的数组,例如:数组返回下表:let arr = ["a", "b", "c"];console.log(Object.keys(arr))->0,1,2; //Object.keys() 返回一个由对象的自身可枚举属性(key值)组成的数组,例如:数组返回下表:let arr = ["a", "b", "c"];console.log(Object.keys(arr))->0,1,2;
} }
for (var attr in obj1) { for (var attr in obj1) {
var t1 = obj1[attr] instanceof Object; var t1 = obj1[attr] instanceof Object;
var t2 = obj2[attr] instanceof Object; var t2 = obj2[attr] instanceof Object;
if (t1 && t2) { if (t1 && t2) {
return diff(obj1[attr], obj2[attr]); return diff(obj1[attr], obj2[attr]);
} else if (obj1[attr] !== obj2[attr]) { } else if (obj1[attr] !== obj2[attr]) {
return false; return false;
}
} }
return true; }
return true;
} }
/** /**
* 根据字典的value显示label * 根据字典的value显示label
*/ */
export const findByvalue = (dic, value) => { export const findByvalue = (dic, value) => {
let result = ''; let result = '';
if (validatenull(dic)) return value; if (validatenull(dic)) return value;
if (typeof (value) == 'string' || typeof (value) == 'number' || typeof (value) == 'boolean') { if (typeof (value) == 'string' || typeof (value) == 'number' || typeof (value) == 'boolean') {
let index = 0; let index = 0;
index = findArray(dic, value); index = findArray(dic, value);
if (index != -1) { if (index != -1) {
result = dic[index].label; result = dic[index].label;
} else { } else {
result = value; result = value;
}
} else if (value instanceof Array) {
result = [];
let index = 0;
value.forEach(ele => {
index = findArray(dic, ele);
if (index != -1) {
result.push(dic[index].label);
} else {
result.push(value);
}
});
result = result.toString();
} }
return result; } else if (value instanceof Array) {
result = [];
let index = 0;
value.forEach(ele => {
index = findArray(dic, ele);
if (index != -1) {
result.push(dic[index].label);
} else {
result.push(value);
}
});
result = result.toString();
}
return result;
}; };
/** /**
* 根据字典的value查找对应的index * 根据字典的value查找对应的index
*/ */
export const findArray = (dic, value) => { export const findArray = (dic, value) => {
for (let i = 0; i < dic.length; i++) { for (let i = 0; i < dic.length; i++) {
if (dic[i].value == value) { if (dic[i].value == value) {
return i; return i;
}
} }
return -1; }
return -1;
}; };
/** /**
* 生成随机len位数字 * 生成随机len位数字
*/ */
export const randomLenNum = (len, date) => { export const randomLenNum = (len, date) => {
let random = ''; let random = '';
random = Math.ceil(Math.random() * 100000000000000).toString().substr(0, len ? len : 4); random = Math.ceil(Math.random() * 100000000000000).toString().substr(0, len ? len : 4);
if (date) random = random + Date.now(); if (date) random = random + Date.now();
return random; return random;
}; };
/** /**
* 打开小窗口 * 打开小窗口
*/ */
export const openWindow = (url, title, w, h) => { export const openWindow = (url, title, w, h) => {
// Fixes dual-screen position Most browsers Firefox // Fixes dual-screen position Most browsers Firefox
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top
const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width
const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height
const left = ((width / 2) - (w / 2)) + dualScreenLeft const left = ((width / 2) - (w / 2)) + dualScreenLeft
const top = ((height / 2) - (h / 2)) + dualScreenTop const top = ((height / 2) - (h / 2)) + dualScreenTop
const newWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left) const newWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left)
// Puts focus on the newWindow // Puts focus on the newWindow
if (window.focus) { if (window.focus) {
newWindow.focus() newWindow.focus()
} }
}
/**
* 获取顶部地址栏地址
*/
export const getTopUrl = () => {
return window.location.href.split("/#/")[0];
}
/**
* 获取url参数
* @param name 参数名
*/
export const getQueryString = (name) => {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(decodeURI(r[2]));
return null;
} }

@ -1,5 +1,37 @@
<template> <template>
<div> <div>
<el-row>
<el-col :span="24">
<el-dialog title="账号注册"
append-to-body
:visible.sync="accountBox"
:close-on-click-modal="false"
:close-on-press-escape="false"
:show-close="false"
width="20%">
<el-form :model="form" ref="form" label-width="80px">
<el-form-item v-if="tenantMode" label="租户编号">
<el-input v-model="form.tenantId" placeholder="请输入租户编号"></el-input>
</el-form-item>
<el-form-item label="用户姓名">
<el-input v-model="form.name" placeholder="请输入用户姓名"></el-input>
</el-form-item>
<el-form-item label="账号名称">
<el-input v-model="form.account" placeholder="请输入账号名称"></el-input>
</el-form-item>
<el-form-item label="账号密码">
<el-input v-model="form.password" placeholder="请输入账号密码"></el-input>
</el-form-item>
<el-form-item label="确认密码">
<el-input v-model="form.password2" placeholder="请输入确认密码"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="handleRegister"> </el-button>
</span>
</el-dialog>
</el-col>
</el-row>
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<basic-container> <basic-container>
@ -417,11 +449,22 @@
<script> <script>
import {mapGetters} from "vuex"; import {mapGetters} from "vuex";
import {registerGuest} from "@/api/user";
import {getTopUrl} from "@/util/util";
import {info} from "@/api/system/tenant";
export default { export default {
name: "wel", name: "wel",
data() { data() {
return { return {
form: {
name: '',
account: '',
password: '',
password2: '',
},
tenantMode: true,
accountBox: false,
activeNames: ['1', '2', '3', '5'], activeNames: ['1', '2', '3', '5'],
logActiveNames: ['15'] logActiveNames: ['15']
}; };
@ -430,12 +473,60 @@
...mapGetters(["userInfo"]), ...mapGetters(["userInfo"]),
}, },
created() { created() {
this.getTenant();
},
mounted() {
//
if (this.userInfo.user_id === undefined || this.userInfo.user_id < 0) {
this.form.name = this.userInfo.user_name;
this.form.account = this.userInfo.user_name;
this.accountBox = true;
}
}, },
methods: { methods: {
handleRegister() {
if (this.form.tenantId === '') {
this.$message.warning("请先输入租户编号");
return;
}
if (this.form.account === '') {
this.$message.warning("请先输入账号名称");
return;
}
if (this.form.password === '' || this.form.password2 === '') {
this.$message.warning("请先输入密码");
return;
}
if (this.form.password !== this.form.password2) {
this.$message.warning("两次密码输入不一致");
return;
}
registerGuest(this.form, this.userInfo.oauth_id).then(res => {
const data = res.data;
if (data.success) {
this.$alert("注册申请已提交,请耐心等待管理员通过!", '注册提示')
} else {
this.$message.error(data.msg || '提交失败');
}
this.accountBox = false;
});
},
getTenant() {
let domain = getTopUrl();
// 便
//domain = "https://bladex.vip";
info(domain).then(res => {
const data = res.data;
if (data.success && data.data.tenantId) {
this.form.tenantId = data.data.tenantId;
this.tenantMode = false;
}
})
},
handleChange(val) { handleChange(val) {
window.console.log(val); window.console.log(val);
} }
} },
}; };
</script> </script>

Loading…
Cancel
Save