xiaohaizhao 1 year ago
parent
commit
32cbecf318

+ 2 - 1
app.json

@@ -15,7 +15,8 @@
     "pages/tabbar/mine/address/index",
     "pages/tabbar/mine/address/update",
     "pages/tabbar/mine/webView",
-    "pages/tabbar/mine/associatedPublicNumber"
+    "pages/tabbar/mine/associatedPublicNumber",
+    "pages/login/developerTools"
   ],
   "subpackages": [
     {

+ 60 - 0
pages/login/developerTools.js

@@ -0,0 +1,60 @@
+let _Http = getApp().globalData.http
+Page({
+    data: {
+        verification: false,
+        password: ""
+    },
+    onLoad(options) {
+        if (_Http.ENV != 'develop') {
+            this.setData({
+                verification: true
+            })
+        } else {
+            this.init();
+        }
+    },
+    init() {
+        this.setData({
+            runtimeEnvironment: _Http.ENV == 'develop' ? '开发环境' : '生产环境',
+            "baseUrl": _Http.baseUrl,
+            urls: _Http.urls,
+            verification: false
+        })
+    },
+    onInput(e) {
+        this.setData({
+            password: e.detail
+        })
+    },
+    enterInto() {
+        if (this.data.password != 'jxys@12345') return wx.showToast({
+            title: '密码错误',
+            icon: "none"
+        })
+        this.init()
+    },
+    onChange({
+        detail
+    }) {
+        console.log(detail)
+        let that = this;
+        wx.showModal({
+            title: '提示',
+            content: `是否确定将服务地址修改为“${detail}”?`,
+            complete: (res) => {
+                if (res.cancel) that.setData({
+                    baseUrl: that.data.baseUrl
+                })
+                if (res.confirm) {
+                    that.setData({
+                        baseUrl: detail
+                    })
+                    _Http.baseUrl = detail;
+                    wx.showToast({
+                        title: '修改成功',
+                    })
+                }
+            }
+        })
+    }
+})

+ 8 - 0
pages/login/developerTools.json

@@ -0,0 +1,8 @@
+{
+  "usingComponents": {
+      "van-radio": "@vant/weapp/radio/index",
+      "van-radio-group": "@vant/weapp/radio-group/index",
+      "van-field": "@vant/weapp/field/index"
+  },
+  "navigationBarTitleText": "开发者工具"
+}

+ 17 - 0
pages/login/developerTools.scss

@@ -0,0 +1,17 @@
+.box {
+	width: 720rpx;
+	margin: 0 auto;
+	margin-top: 12rpx;
+}
+
+.group {
+	border: 1px solid #333;
+	border-radius: 8rpx;
+	padding: 20rpx;
+	box-sizing: border-box;
+}
+
+.radio {
+	font-size: 14px;
+	margin-top: 12rpx;
+}

+ 24 - 0
pages/login/developerTools.wxml

@@ -0,0 +1,24 @@
+<block wx:if="{{verification}}">
+    <van-field value="{{ password }}" type="password" placeholder="请输入管理密码" border="{{ false }}" bind:change="onInput" use-button-slot>
+        <van-button slot="button" disabled='{{!password}}' size="small" type="primary" bindtap="enterInto">
+            进入
+        </van-button>
+    </van-field>
+</block>
+
+<block wx:else>
+    <view class="box">
+        运行环境:{{runtimeEnvironment}}
+    </view>
+
+    <view class="box">
+        服务地址:{{baseUrl}}
+    </view>
+
+    <view class="box group">
+        切换服务地址
+        <van-radio-group value="{{ baseUrl }}" bind:change="onChange">
+            <van-radio custom-class='radio' wx:for="{{urls}}" wx:key="name" name="{{item.url}}">{{item.name}}:{{item.url}}</van-radio>
+        </van-radio-group>
+    </view>
+</block>

+ 3 - 1
pages/login/modules/account.js

@@ -20,7 +20,9 @@ Component({
             this.setData({
                 ...wx.getStorageSync('loginMsg')
             });
-            this.allowOrNot();
+            setTimeout(() => {
+                this.allowOrNot();
+            }, 100)
         }
     },
     methods: {

+ 46 - 74
pages/login/modules/login.js

@@ -1,87 +1,59 @@
-const _Http = getApp().globalData.http;
-let count = 0; //接口完成数量
-
 function loginMsg(res) {
 	wx.setStorageSync('account_list', res.account_list);
 	if (res.account_list.length == 1) {
-		let item = res.account_list[0];
-		wx.setStorageSync('userrole', item.usertype == 1 ? '业务员' : '经销商');
-		wx.setStorageSync('userMsg', item)
-		query_userauth();
+			wx.setStorageSync('userMsg', res.account_list[0])
+			init();
 	} else {
-		wx.redirectTo({
-			url: './selectSite',
-		})
+			wx.redirectTo({
+					url: './selectSite',
+			})
 	}
 }
-/* 获取用户权限 */
-function query_userauth() {
-	query_adspacelist();
-	querySite_Parameter();
-	wx.setStorageSync('userauth', []);
-	_Http.basic({
-		"classname": "sysmanage.develop.userauth.userauth",
-		"method": "query_userauth",
-		content: {
-			nocache: true
-		}
-	}).then(res => {
-		console.log("查询权限", res.data)
-		if (res.msg != '成功') return wx.showToast({
-			title: '权限查询失败,请稍后再试',
-			icon: "none"
-		})
-		wx.setStorageSync('userauth', res.data);
-		count += 1;
-		toHome();
-	});
-	if (!getApp().globalData.socketEstablish) getApp().initSocket();
-}
-/* 查询站点数据 */
-function querySite_Parameter() {
-	_Http.basic({
-		"classname": "webmanage.site.site",
-		"method": "querySite_Parameter",
-		"content": {}
-	}).then(res => {
-		if (res.msg != '成功') return wx.showToast({
-			title: res.msg,
-			icon: "none"
-		});
-		wx.setStorageSync('siteP', res.data);
-		count += 1;
-		toHome();
-	})
-}
-/* 查询轮播图 */
-function query_adspacelist() {
-	_Http.basic({
-		"classname": "common.adspace.adspace",
-		"method": "query_adspacelist",
-		"content": {}
-	}).then(res => {
-		if (res.msg != '成功') return wx.showToast({
-			title: res.msg,
-			icon: "none"
-		});
-		wx.setStorageSync('banner_list', res.data)
-		count += 1;
-		toHome();
-	})
-}
 
-function toHome() {
-	if (count < 3) return;
-	let pages = getCurrentPages();
-	let prevPage = pages[pages.length - 2];
-	if (prevPage && prevPage.__route__ == 'pages/tabbar/home/index') prevPage.refreshData();
-	wx.switchTab({
-		url: '/pages/tabbar/home/index'
+function init() {
+	const _Http = getApp().globalData.http;
+	Promise.all([{
+			"classname": "sysmanage.develop.userauth.userauth",
+			"method": "query_userauth", //获取用户权限
+			content: {
+					nocache: true
+			}
+	}, {
+			"classname": "webmanage.site.site",
+			"method": "querySite_Parameter", //查询站点数据
+			content: {
+					nocache: true
+			}
+	}, {
+			"classname": "common.adspace.adspace",
+			"method": "query_adspacelist", //查询轮播图
+			content: {
+					nocache: true
+			}
+	}].map(v => _Http.basic(v))).then(list => {
+			console.log("登录初始化", list)
+			if (list.some(res => res.msg != '成功')) return list.filter(res => {
+					if (res.msg != '成功') wx.showToast({
+							title: res.msg,
+							icon: "none",
+							mask: true
+					})
+			})
+			wx.setStorageSync('userauth', list[0].data);
+			wx.setStorageSync('siteP', list[1].data);
+			wx.setStorageSync('banner_list', list[2].data)
+			if (!getApp().globalData.socketEstablish) getApp().initSocket();
+			let pages = getCurrentPages();
+			let prevPage = pages[pages.length - 2];
+			if (prevPage && prevPage.__route__ == 'pages/tabbar/home/index') prevPage.refreshData();
+			wx.switchTab({
+					url: '/pages/tabbar/home/index'
+			})
 	})
-	count = 0;
 }
+
 /* 站点数据查询 */
 module.exports = {
 	loginMsg,
-	query_userauth
+	init
 }

+ 15 - 4
pages/login/phone.js

@@ -1,6 +1,4 @@
 import Toast from '@vant/weapp/toast/toast';
-const _Http = getApp().globalData.http,
-	loginMsg = require("./modules/login");
 Page({
 
 	/**
@@ -15,6 +13,9 @@ Page({
 		if (wx.getStorageSync('isAgree')) this.setData({
 			isAgree: wx.getStorageSync('isAgree')
 		})
+		this.setData({
+			devCount: 0
+		})
 	},
 	/* 微信登录 */
 	wechatLogin() {
@@ -25,7 +26,7 @@ Page({
 		wx.login({
 			success(res) {
 				if (res.code) {
-					_Http.loginbywechat({
+					getApp().globalData.http.loginbywechat({
 						wechat_code: res.code,
 						"systemclient": "wechatsaletool"
 					}).then(res => {
@@ -34,7 +35,7 @@ Page({
 							title: res.msg,
 							icon: "none"
 						})
-						loginMsg.loginMsg(res);
+						require("./modules/login").loginMsg(res);
 						console.log('是否为初始密码', res.remindchangepassword == 1)
 						getApp().globalData.remindchangepassword = res.remindchangepassword == 1;
 					})
@@ -64,5 +65,15 @@ Page({
 			isAgree: detail
 		})
 	},
+	todev() {
+		if (this.data.devCount == 5) {
+			wx.navigateTo({
+				url: '/pages/login/developerTools',
+			})
+			this.data.devCount = 0;
+		} else {
+			this.data.devCount += 1;
+		}
+	},
 	onShareAppMessage() {}
 })

+ 1 - 1
pages/login/phone.wxml

@@ -1,5 +1,5 @@
 <view class="logo">
-    <image src="/static/image/logo.png" />
+	<image src="/static/image/logo.png" bindtap="todev" />
 </view>
 
 <!-- 手机号登录/账号登录  -->

+ 1 - 2
pages/login/selectSite.js

@@ -1,4 +1,3 @@
-const login = require('./modules/login');
 Page({
 
     /**
@@ -18,7 +17,7 @@ Page({
         } = e.currentTarget.dataset;
         wx.setStorageSync('userrole', item.usertype == 1 ? '业务员' : '经销商');
         wx.setStorageSync('userMsg', item);
-        login.query_userauth();
+        require('./modules/login').init();
     },
     /**
      * 生命周期函数--监听页面显示

+ 18 - 15
utils/Http.js

@@ -1,11 +1,18 @@
 class HTTP {
     constructor() {
-        let ENV = wx.getAccountInfoSync().miniProgram.envVersion;
-        // ENV = 'release';
-        if (ENV === 'release') { // 正式版
+        this.ENV = wx.getAccountInfoSync().miniProgram.envVersion;
+        this.urls = [{
+            name: "生产环境",
+            url: "https://oms.idcgroup.com.cn:8079"
+        }, {
+            name: "开发环境",
+            url: "http://61.164.207.46:8000"
+        }]
+        if (this.ENV === 'release') { // 正式版
             this.baseUrl = "https://oms.idcgroup.com.cn:8079";
         } else {
             this.baseUrl = "http://61.164.207.46:8000";
+            // this.baseUrl = "https://oms.idcgroup.com.cn:8079";
         }
         console.log("接口地址:", this.baseUrl)
     }
@@ -16,15 +23,15 @@ class HTTP {
         header = {
             'content-type': 'application/json'
         },
-        showLoading = '加载中...'
+        loading = true
     }) {
         return new Promise((resolve, reject) => {
-            this._request(url, resolve, reject, data, method, header, showLoading);
+            this._request(url, resolve, reject, data, method, header, loading);
         })
     }
-    _request(url, resolve, reject, data, method, header, showLoading) {
-        /* if (showLoading) wx.showLoading({
-            title: showLoading,
+    _request(url, resolve, reject, data, method, header, loading) {
+        /* if (loading) wx.showLoading({
+            title: '加载中...',
             mask: true
         }) */
         wx.request({
@@ -33,14 +40,10 @@ class HTTP {
             method: method,
             header: header,
             timeout: 60000,
-            success: (res) => {
-                resolve(res.data);
-            },
-            fial: (err) => {
-                reject(err);
-            },
+            success: res => resolve(res.data),
+            fial: err => reject(err),
             complete: (res) => {
-                // if (showLoading) wx.hideLoading()
+                // if (loading) wx.hideLoading()
                 if (res.errMsg != 'request:ok') {
                     wx.showToast({
                         title: '网络异常,请重新进入',