From 9860e221460a0a4ac1903dad2c97160d0eed0e63 Mon Sep 17 00:00:00 2001
From: long <515897141@qq.com>
Date: 星期五, 03 三月 2023 10:59:42 +0800
Subject: [PATCH] 初始化

---
 src/utils/jun_login.js |  125 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/src/utils/jun_login.js b/src/utils/jun_login.js
new file mode 100644
index 0000000..7eef385
--- /dev/null
+++ b/src/utils/jun_login.js
@@ -0,0 +1,125 @@
+/**
+ * 鐧诲綍
+ */
+// const DEBUG = require('../config').isConsole
+// const ismock = require('../config').ismock
+import fn from './fn'
+import Req from './jun_httpInstall'
+import Store from '../store'
+import Config from '../config'
+// import { Message } from 'element-ui'
+
+let 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
+}
+
+/**
+ * 杩涘叆寰俊闀块摼锛屽彲鑾峰彇code
+ */
+function toLongUrl () {
+	// fn.urlReplace(Config.codeUrl)
+	// location.href = Config.codeUrl
+	location.href = Config.createCodeUrl()
+}
+
+/**
+ * 鐧诲綍
+ * @param {object}   option 鐧诲綍閫夐」
+ * @param {boolean}  option.force 鏄惁寮哄埗閲嶆柊鐧诲綍
+ * @param {function} option.callback 鐧诲綍鎴愬姛鍚庡洖璋�
+ */
+function checkLogin(option={}){
+	loginReq(option).then(()=>{
+		if (typeof option.callback === 'function') {
+			option.callback()
+		}
+	})
+}
+
+/**
+ * 鐧诲綍璇锋眰
+ * @param {object} option 
+ * @param {object} option.data 璇锋眰鍙傛暟
+ */
+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
+		}
+
+		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')
+
+			resolve(res)
+			
+		}).catch((res)=>{
+			console.log(res)
+			reject(res)
+		})
+	})
+}
+
+
+
+export default {
+	checkLogin,
+	loginReq,
+	toLongUrl
+}
\ No newline at end of file

--
Gitblit v1.8.0