From c6d3157eb616116c84d35e221ed9c57ef8da0ad6 Mon Sep 17 00:00:00 2001 From: long <515897141@qq.com> Date: 星期四, 01 二月 2024 16:24:11 +0800 Subject: [PATCH] 操作频繁锁(60秒) --- src/utils/jun_login.js | 160 ++++++++++++++++++++++++++--------------------------- 1 files changed, 78 insertions(+), 82 deletions(-) diff --git a/src/utils/jun_login.js b/src/utils/jun_login.js index 7eef385..eff9513 100644 --- a/src/utils/jun_login.js +++ b/src/utils/jun_login.js @@ -9,35 +9,35 @@ import Config from '../config' // import { Message } from 'element-ui' -let config = { - // 鐧诲綍璇锋眰鎺ュ彛閾炬帴 - url: 'weixin!ajaxGetInfoByCode', - // 2灏忔椂杩囨湡 - expire: 7.2e6, +const config = { + // 鐧诲綍璇锋眰鎺ュ彛閾炬帴 + url: 'weixin!ajaxGetInfoByCode', + // 2灏忔椂杩囨湡 + expire: 7.2e6 } /** * 妫�鏌ョ櫥褰曠紦瀛樿繃鏈燂紝榛樿涓嶈繃鏈� * @param {object} we_session 缂撳瓨瀵硅薄 */ -function checkExpire(we_session){ - // if ((we_session && Date.now() >= we_session.expire) || !we_session) { - // // 鍒犻櫎store缂撳瓨 - // Store.commit('unLogined') - // // wx.removeStorageSync('we_session') - // localStorage.removeItem('we_session') - // return true - // } - return false +function checkExpire(we_session) { + // if ((we_session && Date.now() >= we_session.expire) || !we_session) { + // // 鍒犻櫎store缂撳瓨 + // Store.commit('unLogined') + // // wx.removeStorageSync('we_session') + // localStorage.removeItem('we_session') + // return true + // } + return false } /** * 杩涘叆寰俊闀块摼锛屽彲鑾峰彇code */ -function toLongUrl () { - // fn.urlReplace(Config.codeUrl) - // location.href = Config.codeUrl - location.href = Config.createCodeUrl() +function toLongUrl() { + // fn.urlReplace(Config.codeUrl) + // location.href = Config.codeUrl + location.href = Config.createCodeUrl() } /** @@ -46,80 +46,76 @@ * @param {boolean} option.force 鏄惁寮哄埗閲嶆柊鐧诲綍 * @param {function} option.callback 鐧诲綍鎴愬姛鍚庡洖璋� */ -function checkLogin(option={}){ - loginReq(option).then(()=>{ - if (typeof option.callback === 'function') { - option.callback() - } - }) +function checkLogin(option = {}) { + loginReq(option).then(() => { + if (typeof option.callback === 'function') { + option.callback() + } + }) } /** * 鐧诲綍璇锋眰 - * @param {object} option + * @param {object} option * @param {object} option.data 璇锋眰鍙傛暟 */ -function loginReq(option){ - - if (Config.ismock || Config.istest) { - option.data.code = '011h5c000ySdaK1lbw000ubdtm2h5c00' - } +function loginReq(option) { + if (Config.ismock || Config.istest) { + option.data.code = '011h5c000ySdaK1lbw000ubdtm2h5c00' + } - return new Promise((resolve, reject)=>{ - // 鍓嶇疆鍒ゆ柇 - let userData = Store.getters.getUserData - if (userData.key) { - resolve(userData) - return - } + return new Promise((resolve, reject) => { + // 鍓嶇疆鍒ゆ柇 + const userData = Store.getters.getUserData + if (userData.key) { + resolve(userData) + return + } - if (!option || !option.data) { - reject() - console.error('璋冪敤loginReq锛岀己澶� option') - return - } - if (!option.data.code) { - console.error('璋冪敤loginReq锛岀己澶� code') - reject() - return - } - Req.http3.post({ - url: config.url, - data: option.data - }).then((res)=>{ - // 缂撳瓨key鍊� - fn.setLocalStorage('we_session', { - we_session: res.inf.key, - expire: Date.now() + config.expire - }) - // 缂撳瓨鐢ㄦ埛鏁版嵁 - Store.commit('setUserData', res.inf) - console.log(res.inf) + if (!option || !option.data) { + reject() + console.error('璋冪敤loginReq锛岀己澶� option') + return + } + if (!option.data.code) { + console.error('璋冪敤loginReq锛岀己澶� code') + reject() + return + } + Req.http3.post({ + url: config.url, + data: option.data + }).then((res) => { + // 缂撳瓨key鍊� + fn.setLocalStorage('we_session', { + we_session: res.inf.key, + expire: Date.now() + config.expire + }) + // 缂撳瓨鐢ㄦ埛鏁版嵁 + Store.commit('setUserData', res.inf) + console.log(res.inf) - // if (res.inf.name) { - // Store.commit('setNickName', res.inf.name) - // } - - // 澶勭悊鐧诲綍瀹屾垚 store - // getUserInfo().then(_res=>{ - // // Store.commit('setLogined', _res.inf) - // resolve(res) - // }) - // Store.commit('setLogined') + // if (res.inf.name) { + // Store.commit('setNickName', res.inf.name) + // } - resolve(res) - - }).catch((res)=>{ - console.log(res) - reject(res) - }) - }) + // 澶勭悊鐧诲綍瀹屾垚 store + // getUserInfo().then(_res=>{ + // // Store.commit('setLogined', _res.inf) + // resolve(res) + // }) + // Store.commit('setLogined') + + resolve(res) + }).catch((res) => { + console.log(res) + reject(res) + }) + }) } - - export default { - checkLogin, - loginReq, - toLongUrl -} \ No newline at end of file + checkLogin, + loginReq, + toLongUrl +} -- Gitblit v1.8.0