const tl_rtc_app_module_login_mobile = { props : { loginList : { type: Array, default: function(){ return []; } }, isMobile: { type: Boolean, default: false }, loginedCacheList: { type: Array, default: function(){ return []; } }, leftModule: { type: String, default: '' }, rightModule: { type: String, default: '' } }, data : function(){ return { selectedLoginedCache: {}, scanCode: '' } }, watch: { scanCode:{ handler: async function(val){ // 限制只能输入数字 if(!/^\d+$/.test(val)){ this.scanCode = val.replace(/[^\d]/g, '') } // 限制只能输入6位数字 if(val.length > 6){ this.scanCode = val.slice(0, 6) } // 输入6位数字后,自动登录 if(val.length === 6){ await this.quickLogin() } } }, leftModule: function (val) { }, rightModule: function (val) { } }, computed: { propsLoginList(){ return this.loginList; }, propsIsMobile(){ return this.isMobile; }, propsLoginedCacheList(){ if (this.loginedCacheList.length > 0){ this.chooseLoginedCache(this.loginedCacheList[0]) } return this.loginedCacheList; }, scanCodeDone(){ return this.scanCode.length === 6 }, propsLeftModule() { return this.leftModule; }, propsRightModule() { return this.rightModule; }, }, methods: { /** * 事件触发,向上传递 * @param {*} event */ leftModuleChange: function(event){ this.$emit('left-module-change', event) }, /** * 事件触发,向上传递 * @param {*} event */ rightModuleChange: function(event){ this.$emit('right-module-change', event) }, /** * 打开登录项 * @param {*} item * @returns */ openLoginItem: function(item){ if (![ 'account', 'email', 'scan' ].includes(item.type)){ item.handler && item.handler.call(this) return } item.handler && item.handler.call(this) // 通知兄弟子模块,数据变更 this.emitSubModuleEvent({ event: 'sub-module-login-content-data-change', data: { loginType : item.type } }) // 打开右侧模块 - 处理移动端情况 this.emitSubModuleEvent({ event: 'sub-module-core-change-module-show', data: { showRightModule: true, } }) }, /** * 一键登录 */ quickLogin: async function(){ const bfpData = await this.emitSubModuleEvent({ event: 'component-bfp-info', }) console.log("bfpData: ", bfpData) const {fps} = bfpData let params = { username: this.selectedLoginedCache.username, fps: fps, } if(!window.tl_rtc_app_comm.checkRequestParams(params)){ this.popErrorMsg("请求参数非法") return } const { data: loginRes } = await this.tlRequest({ url: '/api/web/user-login/login-by-fp', method: 'post', useCache: false, data: params, }) if(loginRes.success){ this.popSuccessMsg(loginRes.msg) window.location.reload() }else{ this.popErrorMsg(loginRes.msg) } }, /** * 选择登录过的帐号 */ chooseLoginedCache: function(item){ this.selectedLoginedCache = item }, /** * 清理常用帐号 */ cleanCacheAccount: function(){ let that = this layer.confirm('确定清理常用帐号?', { title: '提示', btn: ['确定', '取消'], shadeClose: 1 }, (index) => { layer.close(index) that.$emit('clean-cache-account') window.location.reload() }) }, /** * 初始化扫码输入框 */ initScanCodeInput: function(){ let that = this const inputs = document.querySelectorAll('.tl-rtc-app-left-panel-login-body-scan-code-container-item'); inputs.forEach((input, index) => { input.addEventListener('input', (e) => { // 清除空格或非数字输入 input.value = input.value.replace(/\D/g, ''); if (input.value.length === 1 && index < inputs.length - 1) { input.disabled = true; inputs[index + 1].disabled = false; inputs[index + 1].focus(); } that.scanCode = Array.from(inputs).map(input => input.value).join(''); }); input.addEventListener('keydown', (e) => { // 禁止空格键 if (e.key === ' ' || e.key === 'Spacebar') { e.preventDefault(); } if (e.key === 'Backspace' && index > 0) { input.value = ''; // 清空当前输入框 input.disabled = true; inputs[index - 1].disabled = false; inputs[index - 1].focus(); } }); input.addEventListener('focus', (e) => { if (input.disabled) { inputs[index].blur(); } }); input.addEventListener('paste', (e) => { const pasteData = e.clipboardData.getData('text').replace(/\D/g, ''); // 只保留数字 const pasteArray = pasteData.split('').slice(0, inputs.length - index); pasteArray.forEach((char, idx) => { if (inputs[index + idx]) { inputs[index + idx].value = char; if (index + idx < inputs.length - 1) { inputs[index + idx].disabled = true; inputs[index + idx + 1].disabled = false; } } }); const lastFilledIndex = index + pasteArray.length - 1; if (inputs[lastFilledIndex]) { inputs[lastFilledIndex].focus(); } e.preventDefault(); }); }); }, /** * 初始化二维码 */ initQrCode: function(){ const { skinBodyBackground, skinBodyColor } = window.tl_rtc_app_comm.getPropertyValues([ { key: "skinBodyBackground", value: "skin-body-background" }, { key: "skinBodyColor", value: "skin-body-color" }, ]) const dom = document.getElementById('tl-rtc-app-left-panel-login-body-scan-mobile') if(dom){ window.tl_rtc_app_comm.getQrCode( "tl-rtc-app-left-panel-login-body-scan-mobile", "扫码登录", skinBodyColor, skinBodyBackground ) } }, loginHelp: function(){ this.popWarningMsg("可加群联系开发人员") } }, mounted() { this.initQrCode(); this.initScanCodeInput(); }, template: `