156 lines
4.5 KiB
JavaScript
156 lines
4.5 KiB
JavaScript
const tl_rtc_app_module_login = {
|
|
props: {
|
|
socket: {
|
|
type: Object,
|
|
default: null
|
|
},
|
|
isMobile: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
leftModule: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
rightModule: {
|
|
type: String,
|
|
default: ''
|
|
}
|
|
},
|
|
computed:{
|
|
propsSocket(){
|
|
return this.socket;
|
|
},
|
|
propsIsMobile(){
|
|
return this.isMobile;
|
|
},
|
|
propsLeftModule() {
|
|
return this.leftModule;
|
|
},
|
|
propsRightModule() {
|
|
return this.rightModule;
|
|
},
|
|
},
|
|
watch: {
|
|
leftModule: function (val) {
|
|
|
|
},
|
|
rightModule: function (val) {
|
|
|
|
}
|
|
},
|
|
data : function(){
|
|
return {
|
|
loginedCacheList: [],
|
|
loginedListCacheKey: 'tl_logined_list'
|
|
}
|
|
},
|
|
methods: {
|
|
/**
|
|
* 事件触发,向上传递
|
|
* @param {*} event
|
|
*/
|
|
leftModuleChange: function(event){
|
|
this.$emit('left-module-change', event)
|
|
},
|
|
/**
|
|
* 事件触发,向上传递
|
|
* @param {*} event
|
|
*/
|
|
rightModuleChange: function(event){
|
|
this.$emit('right-module-change', event)
|
|
},
|
|
/**
|
|
* 设置登录过的帐号缓存到localStorage
|
|
* @param {*} userId
|
|
* @param {*} username
|
|
* @param {*} avatarUrl
|
|
* @param {*} token
|
|
* @param {*} time
|
|
* @returns
|
|
*/
|
|
setCacheLoginAccount: function({
|
|
userId, username, avatarUrl, token, time, callback
|
|
}){
|
|
let loginedList = localStorage.getItem(this.loginedListCacheKey)
|
|
if(loginedList){
|
|
loginedList = JSON.parse(loginedList)
|
|
|
|
// 如果已经存在,不再添加
|
|
if(loginedList.some(item => item.userId == userId)){
|
|
callback && callback()
|
|
return
|
|
}
|
|
|
|
loginedList.push({
|
|
userId,
|
|
username,
|
|
avatarUrl,
|
|
token,
|
|
time
|
|
})
|
|
}else{
|
|
loginedList = [{
|
|
userId,
|
|
username,
|
|
avatarUrl,
|
|
token,
|
|
time
|
|
}]
|
|
}
|
|
|
|
if(loginedList.length > 3){
|
|
loginedList = loginedList.slice(0, 3)
|
|
}
|
|
|
|
localStorage.setItem(this.loginedListCacheKey, JSON.stringify(loginedList))
|
|
|
|
callback && callback()
|
|
},
|
|
/**
|
|
* 获取登录过的帐号缓存, 按time倒序
|
|
* @returns
|
|
*/
|
|
getCacheLoginAccount: function(){
|
|
let loginedList = localStorage.getItem(this.loginedListCacheKey)
|
|
if(loginedList){
|
|
loginedList = JSON.parse(loginedList)
|
|
loginedList.sort((a, b) => b.time - a.time)
|
|
this.loginedCacheList = loginedList
|
|
}
|
|
},
|
|
/**
|
|
* 清除登录过的帐号缓存
|
|
*/
|
|
cleanCacheAccount: function(){
|
|
localStorage.removeItem(this.loginedListCacheKey)
|
|
this.loginedCacheList = []
|
|
}
|
|
},
|
|
created() {
|
|
// 设置登录过的帐号
|
|
window.subModule.$on('sub-module-login-set-cache-account', this.setCacheLoginAccount)
|
|
},
|
|
mounted() {
|
|
let that = this
|
|
|
|
this.getCacheLoginAccount()
|
|
},
|
|
template: `
|
|
<div class="tl-rtc-app-left-panel">
|
|
<div class="tl-rtc-app-left-panel-login">
|
|
<div class="tl-rtc-app-left-panel-login-top-header">
|
|
<div class="tl-rtc-app-left-panel-login-top-header-title">统一认证登录</div>
|
|
</div>
|
|
|
|
<div class="tl-rtc-app-left-panel-login-item" style="cursor: default; min-height: 168px; align-items: flex-start;">
|
|
<div class="tl-rtc-app-left-panel-login-item-name" style="white-space: normal; line-height: 28px; padding-right: 12px;">
|
|
当前版本仅支持 SSO 登录,请从统一认证入口进入系统。登录成功后会自动跳转到当前页面。
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`
|
|
}
|
|
|
|
window.tl_rtc_app_module_login = tl_rtc_app_module_login |