xiaohaizhao пре 5 месеци
родитељ
комит
6a70c67fef
5 измењених фајлова са 104 додато и 69 уклоњено
  1. 43 33
      pages/login/modules/account.js
  2. 1 0
      pages/login/modules/login.js
  3. 1 1
      project.private.config.json
  4. 12 0
      utils/Api.js
  5. 47 35
      utils/Http.js

+ 43 - 33
pages/login/modules/account.js

@@ -62,45 +62,55 @@ Component({
 			})
 		},
 		/* 处理登录 */
-		handleLogin() {
-			_Http.login({
+		async handleLogin() {
+			let isRelease = wx.getAccountInfoSync().miniProgram.envVersion == 'release';
+			const s = isRelease ? await _Http.OldLogin(`?username=${this.data.accountno}&password=${encodeURIComponent(this.data.password)}`) : {
+				success: false
+			};
+			let res = s.success == true ? await _Http.SSO({
+				"accountno": s.data.userinfo.username,
+				"password": s.data.cookie.split("=")[1],
+				"imagecaptcha": this.data.imagecaptcha || '',
+				"systemclient": "wechatsaletool"
+			}) : await _Http.login({
 				"accountno": this.data.accountno,
 				"password": md5.hexMD5(this.data.password),
 				"imagecaptcha": this.data.imagecaptcha || '',
 				"systemclient": "wechatsaletool"
-			}).then(res => {
-				if (res.remindchangepassword) return wx.showModal({
-					title: '提示',
-					content: '当前密码为系统初始化密码,请修改后重新登录',
-					showCancel: false,
-					confirmText: "前去修改",
-					complete: () => {
-						wx.navigateTo({
-							url: '/pages/index/userCenter/changePassword/index?token=' + res.account_list[0].token
-						})
-						_Http.claerPassword = function () {
-							this.setData({
-								password: ""
-							})
-						}.bind(this);
-						getCurrentPages()[0].setData({
-							loading: false
+			});
+
+			if (res.remindchangepassword) return wx.showModal({
+				title: '提示',
+				content: '当前密码为系统初始化密码,请修改后重新登录',
+				showCancel: false,
+				confirmText: "前去修改",
+				complete: () => {
+					wx.navigateTo({
+						url: '/pages/index/userCenter/changePassword/index?token=' + res.account_list[0].token
+					})
+					_Http.claerPassword = function () {
+						this.setData({
+							password: ""
 						})
-					}
-				})
-				getCurrentPages()[0].setData({
-					loading: false
-				})
-				if (res.msg != '成功') return wx.showToast({
-					title: res.msg,
-					icon: "none"
-				})
-				wx.setStorageSync('loginMsg', {
-					accountno: this.data.accountno,
-					password: (this.data.memory) ? this.data.password : ''
-				})
-				loginMsg.loginMsg(res);
+					}.bind(this);
+					getCurrentPages()[0].setData({
+						loading: false
+					})
+				}
 			})
+			getCurrentPages()[0].setData({
+				loading: false
+			})
+			if (res.msg != '成功') return wx.showToast({
+				title: res.msg,
+				icon: "none"
+			})
+			wx.setStorageSync('loginMsg', {
+				accountno: this.data.accountno,
+				password: (this.data.memory) ? this.data.password : ''
+			})
+			loginMsg.loginMsg(res);
+
 		}
 	}
 })

+ 1 - 0
pages/login/modules/login.js

@@ -5,6 +5,7 @@ function loginMsg(res) {
     wx.setStorageSync('account_list', res.account_list);
     if (res.account_list.length == 1) {
         let item = res.account_list[0];
+        console.log(item)
         if (item.status == "INACTIVE") return wx.showToast({
             title: '该账号已被停用,无法登录',
             icon: "none"

+ 1 - 1
project.private.config.json

@@ -3,7 +3,7 @@
   "projectname": "%E7%BE%8E%E5%A4%A7E%E8%AE%A2%E5%8D%95",
   "setting": {
     "compileHotReLoad": true,
-    "urlCheck": true,
+    "urlCheck": false,
     "autoAudits": false,
     "coverView": true,
     "lazyloadPlaceholderEnable": false,

+ 12 - 0
utils/Api.js

@@ -15,6 +15,18 @@ class ApiModel extends HTTP {
             data
         })
     }
+    /* 老CRM登录 */
+    OldLogin(data) {
+        return this.getRequest({
+            url: 'http://61.164.207.46:9082/dmsService/rest/login' + data
+        })
+    }
+    SSO(data) {
+        return this.request({
+            data,
+            suffix: 'http://61.164.207.46:9089/yos/rest/sso/crm'
+        })
+    }
     /* 验证码登录 */
     plogin(data) {
         return this.request({

+ 47 - 35
utils/Http.js

@@ -46,7 +46,7 @@ class HTTP {
 		console.log("接口地址", this.baseUrl);
 	}
 	request({
-		url,
+		url = '',
 		data = {},
 		method = "POST",
 		header = {
@@ -54,19 +54,28 @@ class HTTP {
 			"accesstoken": data.accesstoken || wx.getStorageSync('userMsg').token || '',
 			"Cookie": `JSESSIONID=${this.jsessionid}`
 		},
-		showLoading = '加载中...'
+		suffix = '/yos/rest/index'
 	}) {
 		return new Promise((resolve, reject) => {
-			this._request(url, resolve, reject, data, method, header, showLoading);
+			this._request((suffix == '/yos/rest/index' ? this.baseUrl : "") + suffix + url, resolve, reject, data, method, header);
 		})
 	}
-	_request(url, resolve, reject, data, method, header, showLoading) {
-		/* if (showLoading) wx.showLoading({
-		    title: showLoading,
-		    mask: true
-		}) */
+
+	getRequest({
+		url,
+		method = "GET",
+		header = {
+			"Cookie": `JSESSIONID=${this.jsessionid}`
+		}
+	}) {
+		return new Promise((resolve, reject) => {
+			this._request(url, resolve, reject, {}, method, header);
+		})
+	}
+
+	_request(url, resolve, reject, data, method, header) {
 		wx.request({
-			url: this.baseUrl + '/yos/rest/index' + url,
+			url: url,
 			data,
 			method,
 			header,
@@ -78,7 +87,6 @@ class HTTP {
 				reject(err);
 			},
 			complete: (res) => {
-				// if (showLoading) wx.hideLoading()
 				this._handleSessionCookies(res);
 				if (res.errMsg != 'request:ok') {
 					wx.showToast({
@@ -102,38 +110,42 @@ class HTTP {
 
 	// 处理会话Cookie
 	_handleSessionCookies(res) {
-		try {
-			const cookies = res.cookies || [];
-			const headers = res.header || {};
+		return new Promise((resolve) => {
+			try {
+				const cookies = res.cookies || [];
+				const headers = res.header || {};
 
-			// 检查响应头中的Set-Cookie
-			const setCookie = headers['Set-Cookie'] || headers['set-cookie'];
-			if (setCookie) {
-				// 将字符串转换为数组
-				const cookieArray = Array.isArray(setCookie) ?
-					setCookie : [setCookie];
+				// 检查响应头中的Set-Cookie
+				const setCookie = headers['Set-Cookie'] || headers['set-cookie'];
+				if (setCookie) {
+					// 将字符串转换为数组
+					const cookieArray = Array.isArray(setCookie) ?
+						setCookie : [setCookie];
 
-				cookies.push(...cookieArray);
-			}
+					cookies.push(...cookieArray);
+				}
 
-			// 查找JSESSIONID
-			for (const cookie of cookies) {
-				const match = cookie.match(/JSESSIONID=([^;]+)/i);
-				if (match && match[1]) {
-					const newSessionId = match[1];
+				// 查找JSESSIONID
+				for (const cookie of cookies) {
+					const match = cookie.match(/JSESSIONID=([^;]+)/i);
+					if (match && match[1]) {
+						const newSessionId = match[1];
 
-					// 更新JSESSIONID
-					if (newSessionId !== this.jsessionid) {
-						this.jsessionid = newSessionId;
-						wx.removeStorageSync('JSESSIONID');
-						wx.setStorageSync('JSESSIONID', newSessionId);
+						// 更新JSESSIONID
+						if (newSessionId !== this.jsessionid) {
+							this.jsessionid = newSessionId;
+							wx.removeStorageSync('JSESSIONID');
+							wx.setStorageSync('JSESSIONID', newSessionId);
+						}
+						break;
 					}
-					break;
 				}
+				resolve(this.jsessionid)
+			} catch (error) {
+				resolve(this.jsessionid)
+				console.error('处理会话Cookie时出错:', error);
 			}
-		} catch (error) {
-			console.error('处理会话Cookie时出错:', error);
-		}
+		})
 	}
 }
 export {