Просмотр исходного кода

Merge branch '登录优化' into 9.36.4

xiaohaizhao 2 лет назад
Родитель
Сommit
d2d14d2966

+ 2 - 1
app.json

@@ -29,7 +29,8 @@
         "pages/tabbar/mine/webView",
         "pages/tabbar/mine/associatedPublicNumber",
         "pages/trace/insert",
-        "pages/trace/detail"
+        "pages/trace/detail",
+        "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: {

+ 36 - 62
pages/login/modules/login.js

@@ -1,85 +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) {
         wx.setStorageSync('userMsg', res.account_list[0])
-        query_userauth();
-        count = 0;
+        init();
     } else {
         wx.redirectTo({
             url: './selectSite',
         })
     }
 }
-/* 获取用户权限 */
-function query_userauth(i = 0) {
-    if (i == 5) return wx.showToast({
-        title: '权限查询失败,请稍后再试',
-        icon: "none"
-    })
-    if (i == 0) {
-        query_adspacelist();
-        querySite_Parameter();
-    }
-    wx.setStorageSync('userauth', {});
-    _Http.basic({
+
+function init() {
+    const _Http = getApp().globalData.http;
+    Promise.all([{
         "classname": "sysmanage.develop.userauth.userauth",
-        "method": "query_userauth",
+        "method": "query_userauth", //获取用户权限
         content: {
             nocache: true
         }
-    }).then(res => {
-        if (res.msg != '成功') return query_userauth(i + 1);
-        wx.setStorageSync('userauth', res.data);
-        console.log("获取用户权限", res.data)
-        count += 1;
-        toHome();
-    });
-    if (!getApp().globalData.socketEstablish) getApp().initSocket();
-}
-/* 查询站点数据 */
-function querySite_Parameter(i = 0) {
-    if (i == 5) return;
-    _Http.basic({
+    }, {
         "classname": "webmanage.site.site",
-        "method": "querySite_Parameter",
-        "content": {}
-    }).then(res => {
-        if (res.msg != '成功') return query_userauth(i + 1);
-        wx.setStorageSync('siteP', res.data);
-        count += 1;
-        toHome();
-    })
-}
-/* 查询轮播图 */
-function query_adspacelist(i = 0) {
-    if (i == 5) return;
-    _Http.basic({
+        "method": "querySite_Parameter", //查询站点数据
+        content: {
+            nocache: true
+        }
+    }, {
         "classname": "common.adspace.adspace",
-        "method": "query_adspacelist",
-        "content": {}
-    }).then(res => {
-        if (res.msg != '成功') return query_adspacelist(i + 1);
-        wx.setStorageSync('banner_list', res.data)
-        count += 1;
-        toHome();
+        "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'
+        })
     })
 }
 
-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'
-    })
-    count = 0;
-}
 /* 站点数据查询 */
 module.exports = {
     loginMsg,
-    query_userauth
+    init
 }

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

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

+ 16 - 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,16 @@ 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>
 
 <!-- 手机号登录  -->

+ 2 - 16
pages/login/selectSite.js

@@ -1,31 +1,17 @@
-const login = require('./modules/login');
 Page({
-
-    /**
-     * 页面的初始数据
-     */
     data: {
         account_list: ""
     },
-    /**
-     * 生命周期函数--监听页面加载
-     */
-    onLoad(options) {},
-
     toHome(e) {
         const {
             item
         } = e.currentTarget.dataset;
         wx.setStorageSync('userMsg', item);
-        login.query_userauth();
+        require('./modules/login').init();
     },
-    /**
-     * 生命周期函数--监听页面显示
-     */
     onShow() {
         this.setData({
             account_list: wx.getStorageSync('account_list')
         })
-    },
-    onShareAppMessage() {}
+    }
 })

+ 7 - 0
project.private.config.json

@@ -83,6 +83,13 @@
                     "query": "id=3768",
                     "launchMode": "default",
                     "scene": null
+                },
+                {
+                    "name": "开发者工具",
+                    "pathName": "pages/login/developerTools",
+                    "query": "",
+                    "launchMode": "default",
+                    "scene": null
                 }
             ]
         }

+ 9 - 2
utils/Http.js

@@ -1,7 +1,14 @@
 class HTTP {
     constructor() {
-        let ENV = wx.getAccountInfoSync().miniProgram.envVersion;
-        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";