陈龙 2 months ago
parent
commit
26305a7eb7

+ 9 - 1
src/Auman.PieceWage.UniApp/App.vue

@@ -1,11 +1,19 @@
 <script>
+    import login from './utils/login';
     export default {
-        onLaunch: function() {
+        onLaunch: async function() {
             console.log('App Launch');
             // let info = uni.getSystemInfoSync();
             // this.data.statusBarHeight = info.statusBarHeight;
             // this.data.screenHeight = info.screenHeight;
             // this.globalData.InnerAudioContext = uni.createInnerAudioContext();
+            
+            let res = await login.login();
+            if (!res.success) {
+                uni.navigateTo({
+                    url: '/pages/login/index'
+                });
+            }
         },
         onShow: function() {
             console.log('App Show');

+ 22 - 2
src/Auman.PieceWage.UniApp/README.md

@@ -1,11 +1,31 @@
 # 开发日志
 
-## 0.0.10 `2024/2/09`
+## 0.1.0 `2025/2/10`
+
+1. 启用新首页。
+2. 优化 `utils\url.js`,可以保存和读取url信息。
+3. 优化 `utils\request.js`。
+4. 优化 `utils\token.js`。
+5. 优化 `utils\user.js`。
+6. 新增 `utils\login.js`,登录辅助类。
+7. 在 `APP.vue` 中执行自动登录操作。
+8. 优化 `pages\login\serverSetting.vue`。
+9. 优化 `pages\login\index.vue`。
+
+## 0.0.10 `2025/2/9`
 
 1. 更新测试API地址。
 2. 优化派报工操作。
 
-## 0.0.7 `2024/1/21`
+## 0.0.9 `2025/??/??`
+
+1. 日志凭空消失了!!!
+
+## 0.0.8 `2025/??/??`
+
+1. 日志跑路了!!!
+
+## 0.0.7 `2025/1/21`
 
 1. 完成派工功能。
 2. 完成报工功能。

+ 2 - 2
src/Auman.PieceWage.UniApp/manifest.json

@@ -2,8 +2,8 @@
     "name" : "生产流程管理",
     "appid" : "__UNI__0D07441",
     "description" : "生产流程管理",
-    "versionName" : "0.0.10",
-    "versionCode" : 10,
+    "versionName" : "0.1.0",
+    "versionCode" : 11,
     "transformPx" : false,
     /* 5+App特有相关 */
     "app-plus" : {

+ 22 - 20
src/Auman.PieceWage.UniApp/pages.json

@@ -1,23 +1,29 @@
 {
     "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
+        {
+            "path": "pages/home/newhome",
+            "style": {
+                "navigationBarTitleText": "首页"
+            }
+        },
         {
             "path": "pages/home/index",
             "style": {
                 "navigationStyle": "custom"
             }
-        }, 
+        },
         {
             "path": "pages/my/index",
             "style": {
                 "navigationBarTitleText": "我的"
             }
-        }, 
+        },
         {
             "path": "pages/login/index",
             "style": {
                 "navigationStyle": "custom"
             }
-        }, 
+        },
         {
             "path": "pages/login/serverSetting",
             "style": {
@@ -25,33 +31,29 @@
             }
         },
         {
-            "path" : "pages/my/protocol",
-            "style" : 
-            {
-                "navigationBarTitleText" : "服务协议和隐私政策"
+            "path": "pages/my/protocol",
+            "style": {
+                "navigationBarTitleText": "服务协议和隐私政策"
             }
         },
         {
-            "path" : "pages/dispatch/dispatch",
-            "style" : 
-            {
-                "navigationBarTitleText" : "派工",
+            "path": "pages/dispatch/dispatch",
+            "style": {
+                "navigationBarTitleText": "派工",
                 "enablePullDownRefresh": false
             }
         },
         {
-            "path" : "pages/work-order/work-order",
-            "style" : 
-            {
-                "navigationBarTitleText" : "报工",
+            "path": "pages/work-order/work-order",
+            "style": {
+                "navigationBarTitleText": "报工",
                 "enablePullDownRefresh": false
             }
         },
         {
-            "path" : "pages/workingTeam/select",
-            "style" : 
-            {
-                "navigationBarTitleText" : "选择工作组"
+            "path": "pages/workingTeam/select",
+            "style": {
+                "navigationBarTitleText": "选择工作组"
             }
         }
     ],
@@ -67,7 +69,7 @@
         "selectedColor": "#2185d0",
         "fontSize": "10px",
         "list": [{
-            "pagePath": "pages/home/index",
+            "pagePath": "pages/home/newhome",
             "text": "首页",
             "iconPath": "static/tabbar/house.png",
             "selectedIconPath": "static/tabbar/house_active.png"

+ 115 - 0
src/Auman.PieceWage.UniApp/pages/home/newhome.vue

@@ -0,0 +1,115 @@
+<template>
+    <view class="scroll-y-auto height-100pre">
+        <view class="flex flex-warp padding-lr-40 justify-bewteen child-gap-40">
+            <view class="card height-180 width-38per" @tap="go('switch', '/pages/dispatch/dispatch')">派工</view>
+            <view class="card height-180 width-38per" @tap="go('switch', '/pages/work-order/work-order')">报工</view>
+        </view>
+    </view>
+</template>
+
+<script>
+    import extend from '../../utils/extend.js';
+    import token from '../../utils/token.js';
+    import user from '../../utils/user.js';
+    import appUpdate from '../../utils/appUpdate.js';
+    import request from '../../utils/request.js';
+
+    export default {
+        data() {
+            return {
+                isLogin: false,
+                list: [],
+                isNew: true,
+                appWgtVersion: '',
+                isUpdating: false,
+                updateProcess: 0
+            }
+        },
+        async onShow() {
+            // #ifdef APP
+
+            let baseUrl = await request.getBaseUrl();
+            // console.log('baseUrl', baseUrl);
+
+            // 检查更新
+            let updateRes = await appUpdate.check('api/PDAScan/GetVersion?name=PDA');
+            this.isNew = updateRes.isNew;
+            this.appWgtVersion = updateRes.appWgtVersion;
+
+            let url = baseUrl + updateRes.url;
+            // console.log(updateRes);
+            // console.log('url:', url);
+            // this.$refs.newVerPopup.open();
+            if (updateRes.isNew) {
+                uni.showModal({
+                    title: '应用更新',
+                    content: `发现新版本 v${updateRes.appWgtVersion},立即更新?`,
+                    async success(r) {
+                        if (r.confirm) {
+                            let showLoading = plus.nativeUI.showWaiting('已下载 0%', {
+                                width: '120px',
+                                height: '100px',
+                                loading: {
+                                    type: 'circle'
+                                }
+                            });
+                            let ures = await appUpdate.update({
+                                url: url,
+                                progress(pr) {
+                                    _this.updateProcess = pr.progress;
+                                    showLoading.setTitle(`已下载 ${pr.progress}%`);
+                                }
+                            });
+                            showLoading.close();
+                            if (ures.success) {
+                                uni.hideLoading();
+                            } else {
+                                uni.showModal({
+                                    title: '错误',
+                                    content: ures.message
+                                });
+                            }
+                        }
+                    }
+                });
+            }
+
+            // #endif
+        },
+        methods: {
+            /**
+             * 页面跳转
+             * @param {string} type 类型。navigate | switch。
+             * @param {string} url 页面地址
+             */
+            go(type, url) {
+                switch (type) {
+                    case 'navigate':
+                        uni.navigateTo({
+                            url: url
+                        });
+                        break;
+                    case 'switch':
+                        uni.switchTab({
+                            url: url
+                        });
+                        break;
+                }
+            }
+        }
+    }
+</script>
+
+<style lang="scss">
+    .card {
+        position: relative;
+        display: flex;
+        background-color: #ffffff;
+        border: 1upx solid #dfdfdf;
+        align-items: center;
+        justify-content: center;
+        box-shadow: 0 0 30upx rgba(0, 0, 0, 0.08);
+        border-radius: 20upx;
+        overflow: hidden;
+    }
+</style>

+ 9 - 34
src/Auman.PieceWage.UniApp/pages/login/index.vue

@@ -8,8 +8,9 @@
             <view class="flex direction-column padding child-gap-40">
                 <uni-easyinput placeholder="输入账号" v-model="username"></uni-easyinput>
                 <uni-easyinput placeholder="输入密码" v-model="password" type="password" @confirm="login"></uni-easyinput>
-                <view class="flex padding-top-40">
+                <view class="flex direction-column padding-top-40 child-gap">
                     <button type="lightblue" border="round" class="grow-1" @tap="login">登录</button>
+                    <button type="default" border="round" class="grow-1" @tap="openSetting">设置</button>
                 </view>
             </view>
         </view>
@@ -25,9 +26,9 @@
 <script>
     import extend from '../../utils/extend.js';
     import request from '../../utils/request.js';
-    import token from '../../utils/token.js';
-    import user from '../../utils/user.js';
     import url from '../../utils/url.js';
+    import login from '../../utils/login.js';
+    import message from '../../utils/message.js';
 
     export default {
         data() {
@@ -39,7 +40,7 @@
             }
         },
         onLoad(opts) {
-            let info = user.getRemember();
+            let info = login.getRemember();
             if (extend.isObject(info)) {
                 this.username = info.username;
                 this.password = info.password;
@@ -77,39 +78,13 @@
                     title: '登陆中...',
                     mask: true,
                 });
-                let res = await token.getByServer({
-                    url: 'oauth2/token',
-                    data: data
-                });
+                let res = await login.login(data);
                 uni.hideLoading();
                 if (res.success) {
-                    // 登录成功
-                    user.setRemember({
-                        username: this.username,
-                        password: this.password
-                    });
-
-                    let userRes = await user.getByServer({
-                        url: 'auman/user/info'
-                    });
-
-                    if (userRes.success) {
-                        let url = extend.isNonEmptyString(this.prevPage) ? this.prevPage : '/pages/home/index';
-                        uni.switchTab({
-                            url: url
-                        });
-                    } else {
-                        uni.showModal({
-                            title: '错误',
-                            content: res.message,
-                            mask: true
-                        });
-                    }
+                    this.back();
                 } else {
-                    uni.showModal({
-                        title: '错误',
-                        content: res.message,
-                        mask: true
+                    message.error({
+                        content: res.message
                     });
                 }
             },

+ 65 - 18
src/Auman.PieceWage.UniApp/pages/login/serverSetting.vue

@@ -1,14 +1,26 @@
 <template>
     <view class="flex direction-column padding gap">
-        <uni-easyinput placeholder="服务地址" v-model="apiUrl" :disabled="disabledInput"
+        <uni-easyinput placeholder="认证地址" v-model="authUrl" :disabled="disabledInput"
+            @input="inputChange"></uni-easyinput>
+        <uni-easyinput placeholder="接口地址" v-model="apiUrl" :disabled="disabledInput"
             @input="inputChange"></uni-easyinput>
         <radio-group @change="radioChange">
             <label class="label" v-for="(item, index) in list" :key="item.id">
                 <view>
                     <radio :value="item.id" :checked="index === current"></radio>
                 </view>
-                <view><text :class="'code bg-light-'+ item.type + ' text-' + item.type">{{item.text}}</text><text
-                        style="padding-left: 8upx;">{{item.url}}</text>
+                <view class="flex">
+                    <view :class="'code bg-light-'+ item.type + ' text-' + item.type">{{item.text}}</view>
+                    <view class="url">
+                        <view class="url-item">
+                            <text class="url-title">接口:</text>
+                            <text>{{item.url.api}}</text>
+                        </view>
+                        <view class="url-item">
+                            <text class="url-title">认证:</text>
+                            <text>{{item.url.auth}}</text>
+                        </view>
+                    </view>
                 </view>
             </label>
         </radio-group>
@@ -22,6 +34,8 @@
     import extend from '../../utils/extend.js';
     import request from '../../utils/request.js';
     import token from '../../utils/token.js';
+    import url from '../../utils/url.js';
+    import login from '../../utils/login.js';
 
     let storageKey = 'server_setting';
     let setting = {
@@ -29,14 +43,20 @@
         list: [{
                 id: 1,
                 text: '外网',
-                url: 'http://106.12.207.123:8081/',
+                url: {
+                    api: '',
+                    auth: ''
+                },
                 editabled: false,
                 type: 'blue'
             },
             {
                 id: 3,
                 text: '自定义',
-                url: '',
+                url: {
+                    api: '',
+                    auth: ''
+                },
                 editabled: true,
                 type: 'red'
             }
@@ -46,6 +66,7 @@
     export default {
         data() {
             return {
+                authUrl: '',
                 apiUrl: '',
                 disabledInput: false,
                 list: [],
@@ -53,9 +74,12 @@
             }
         },
         onLoad() {
+            setting.list[0].url.auth = url.auth;
+            setting.list[0].url.api = url.api;
             let res = extend.readStorage(storageKey);
             if (extend.isNull(res)) {
                 this.list = setting.list;
+                this.authUrl = '';
                 this.apiUrl = '';
                 this.disabledInput = false;
             } else {
@@ -68,7 +92,8 @@
                     }
                     if (setting.list[i].id === setting.id) {
                         this.current = i;
-                        this.apiUrl = setting.list[i].url;
+                        this.authUrl = setting.list[i].url.auth;
+                        this.apiUrl = setting.list[i].url.api;
                     }
                 }
                 this.list = setting.list;
@@ -81,14 +106,11 @@
                     id: this.list[this.current].id,
                     list: this.list
                 });
-                let baseUrl = await request.getBaseUrl();
-                request.setBaseUrl(this.apiUrl);
-                if (baseUrl !== this.apiUrl && token.has()) {
-                    let tokenRes = await token.getByServer();
-                    if (!tokenRes.success) {
-                        token.clear();
-                    }
-                }
+                url.set({
+                    auth: this.authUrl,
+                    api: this.apiUrl
+                });
+                let res = await login.login();
                 uni.showToast({
                     icon: 'success',
                     title: '已保存'
@@ -98,7 +120,8 @@
                 for (let i = 0; i < this.list.length; i++) {
                     if (this.list[i].id === parseInt(evt.detail.value)) {
                         this.current = i;
-                        this.apiUrl = this.list[i].url;
+                        this.apiUrl = this.list[i].url.api;
+                        this.authUrl = this.list[i].url.auth;
                         this.disabledInput = !setting.list[i].editabled;
                         break;
                     }
@@ -107,7 +130,8 @@
             inputChange() {
                 let _this = this;
                 let timer = setTimeout(() => {
-                    _this.list[_this.current].url = _this.apiUrl;
+                    _this.list[_this.current].url.auth = _this.authUrl;
+                    _this.list[_this.current].url.api = _this.apiUrl;
                     clearTimeout(timer);
                 }, 50);
             }
@@ -127,10 +151,33 @@
     }
 
     .code {
-        // background-color: #d0ebff;
+        display: flex;
         padding: 6upx 12upx;
         border-radius: 8upx;
         line-height: 2;
-        // color: #007aff;
+        align-items: center;
+    }
+
+    .url {
+        flex-grow: 1;
+        padding-left: 10upx;
+
+        .url-item {
+            .url-title {
+                padding: 6upx;
+                margin-right: 10upx;
+                border-radius: 10upx;
+                color: #4f4f4f;
+                background-color: #e4fffc;
+            }
+        }
+        
+        .url-item+.url-item {
+            padding-top: 12upx;
+        }
+
+        text {
+            font-size: 24upx;
+        }
     }
 </style>

+ 16 - 10
src/Auman.PieceWage.UniApp/styles/main.css

@@ -43,10 +43,18 @@ text {
     width: 33.3%;
 }
 
+.width-38per {
+    width: 38%;
+}
+
 .width-40per {
     width: 40%;
 }
 
+.width-42per {
+    width: 42%;
+}
+
 .width-45per {
     width: 45%;
 }
@@ -382,12 +390,11 @@ text {
     margin-top: 20upx !important;
 }
 
-.flex-warp.child-gap>view+view,
-.flex-warp.child-gap>button+button,
-.flex-warp.child-gap>view+button,
-.flex-warp.child-gap>button+view {
+.flex-warp.child-gap>view,
+.flex-warp.child-gap>button {
     margin-top: 20upx;
-    margin-bottom: 20upx;
+    margin-left: 20upx;
+    margin-right: 20upx;
 }
 
 .child-gap-40>view+view,
@@ -405,12 +412,11 @@ text {
     margin-top: 40upx !important;
 }
 
-.flex-warp.child-gap-40>view+view,
-.flex-warp.child-gap-40>button+button,
-.flex-warp.child-gap-40>view+button,
-.flex-warp.child-gap-40>button+view {
+.flex-warp.child-gap-40>view,
+.flex-warp.child-gap-40>button {
     margin-top: 40upx;
-    margin-bottom: 40upx;
+    margin-left: 40upx;
+    margin-right: 40upx;
 }
 
 /* 网格 */

+ 71 - 0
src/Auman.PieceWage.UniApp/utils/login.js

@@ -0,0 +1,71 @@
+import extend from "./extend";
+import token from "./token";
+import user from "./user";
+
+/**
+ * 登录类
+ */
+class Login {
+    /**
+     * 是否登录
+     * @returns {boolean}
+     */
+    logined() {
+        return token.has();
+    }
+
+    /**
+     * 获取登录信息
+     * @returns {object}
+     */
+    getRemember() {
+        return user.getRemember();
+    }
+
+    /**
+     * 登录
+     * @param {object} data 登录参数
+     * @param {string} data.username 用户名
+     * @param {string} data.password 密码
+     * @param {string} data.client_id
+     * @param {string} data.client_secret
+     * @param {string} data.grant_type
+     * @returns {{success:boolean,message:string}}
+     */
+    async login(data) {
+        let result = {
+            success: false,
+            message: ''
+        };
+        let res = await token.getByServer({
+            url: 'oauth2/token',
+            data: data
+        });
+        if (res.success) {
+            let userRes = await user.getByServer({
+                url: 'auman/user/info'
+            });
+
+            if (userRes.success) {
+                result.success = true;
+
+                // 登录成功
+                user.setRemember({
+                    username: this.username,
+                    password: this.password
+                });
+            } else {
+                result.message = userRes.message;
+            }
+        } else {
+            result.message = res.message;
+        }
+        if (!result.success) {
+            token.clear();
+            user.clear();
+        }
+        return result;
+    }
+}
+
+export default new Login();

+ 13 - 42
src/Auman.PieceWage.UniApp/utils/request.js

@@ -5,16 +5,6 @@ import ResultData from './resultData.js';
 import Tone from './tone.js';
 import url from './url.js';
 
-/**
- * 基础链接存储键
- */
-const baseUrlKey = 'base_url';
-
-/**
- * 基础链改变标记接存储键
- */
-const baseUrlChangedKey = 'base_url_changed';
-
 /**
  * 发送请求集合
  */
@@ -29,25 +19,6 @@ const tone = new Tone();
  * 网络请求
  */
 const request = {
-    /**
-     * 设置基础地址
-     * @param {string} url - 基础地址
-     */
-    async setBaseUrl(url) {
-        if (!extend.isString(url)) {
-            url = '';
-        }
-        extend.addStorage(baseUrlKey, url);
-    },
-
-    /**
-     * 获取基础地址
-     */
-    async getBaseUrl() {
-        return url.apiUrl;
-        // return extend.readStorage(baseUrlKey);
-    },
-
     /**
      * 网络请求
      * @param {Object} opts - 请求参数
@@ -70,12 +41,12 @@ const request = {
                 return;
             }
             let data = null;
-            let url = '';
-            let baseUrl = await request.getBaseUrl();
+            let baseUrl = url.api;
+            let sendUrl = '';
 
             try {
                 if (extend.isUrl(opts.url)) {
-                    url = opts.url;
+                    sendUrl = opts.url;
                 } else {
                     if (extend.isEmptyString(baseUrl)) {
                         resolve({
@@ -84,7 +55,7 @@ const request = {
                         });
                         return;
                     } else {
-                        url = baseUrl + opts.url;
+                        sendUrl = baseUrl + opts.url;
                     }
                 }
                 if (!extend.isObject(opts.header)) {
@@ -120,17 +91,17 @@ const request = {
                 /* 调试代码-记得删除 */
 
                 // 存储访问次数
-                let mapValue = sendMap.get(url);
+                let mapValue = sendMap.get(sendUrl);
                 if (extend.isNumber(mapValue)) {
                     mapValue++;
                 } else {
                     mapValue = 1;
                 }
-                sendMap.set(url, mapValue);
+                sendMap.set(sendUrl, mapValue);
 
                 // 发送访问请求
                 uni.request({
-                    url: url,
+                    url: sendUrl,
                     method: opts.method || 'get',
                     dataType: opts.dataType || 'json',
                     responseType: opts.responseType || 'text',
@@ -138,13 +109,13 @@ const request = {
                     data: opts.data,
                     timeout: 300000,
                     async success(res) {
-                        let mapValue = sendMap.get(url);
+                        let mapValue = sendMap.get(sendUrl);
                         if (mapValue > 2) {
-                            sendMap.delete(url);
+                            sendMap.delete(sendUrl);
                             let errRes = result.get(res);
                             return resolve(new ResultData({
                                 success: false,
-                                message: `状态码:${res.statusCode}\n${errRes.message}\n${url}`
+                                message: `状态码:${res.statusCode}\n${errRes.message}\n${sendUrl}`
                             }));
                         }
                         if (res.statusCode === 401) {
@@ -159,7 +130,7 @@ const request = {
                                 }));
                             }
                         }
-                        sendMap.delete(url);
+                        sendMap.delete(sendUrl);
                         res = result.get(res);
                         if (!res.success) {
                             tone.playDing();
@@ -174,7 +145,7 @@ const request = {
                     fail(ex) {
                         tone.playDing();
                         console.error(ex);
-                        sendMap.delete(url);
+                        sendMap.delete(sendUrl);
                         ex = extend.errorFormatter(ex);
                         resolve(new ResultData({
                             success: false,
@@ -184,7 +155,7 @@ const request = {
                 });
             } catch (ex) {
                 tone.playDing();
-                sendMap.delete(url);
+                sendMap.delete(sendUrl);
                 let err = extend.errorFormatter(ex);
                 console.error(ex);
                 resolve(new ResultData({

+ 1 - 1
src/Auman.PieceWage.UniApp/utils/token.js

@@ -106,7 +106,7 @@ export default {
             };
         }
         let res = await request.send({
-            url: `${url.authUrl}${opts.url}`,
+            url: `${url.auth}${opts.url}`,
             method: 'post',
             type: 'url',
             data: opts.data

+ 40 - 2
src/Auman.PieceWage.UniApp/utils/url.js

@@ -1,3 +1,5 @@
+import extend from "./extend";
+const urlkey = 'url_key';
 /**
  * 地址类
  */
@@ -5,12 +7,48 @@ class Url {
     /**
      * 认证地址
      */
-    authUrl = 'http://219.151.179.47:8087/';
+    get auth() {
+        let url = this.get();
+        return url.auth;
+    }
 
     /**
      * 接口地址
      */
-    apiUrl = 'http://219.151.179.47:8081/';
+    get api() {
+        let url = this.get();
+        return url.api;
+    }
+
+    /**
+     * 设置地址
+     * @param {object} url url对象
+     * @param {string} url.auth 认证地址
+     * @param {string} url.api 接口地址
+     */
+    set(url) {
+        if (extend.isObject(url)) {
+            extend.addStorage(urlkey, url);
+        }
+    }
+
+    /**
+     * 获取地址
+     * @returns {{auth: string, api: string}}
+     */
+    get() {
+        let url = extend.readStorage(urlkey);
+        if (extend.isNull(url)) {
+            url = {};
+        }
+        if (extend.isEmptyString(url.authUrl)) {
+            url.auth = 'http://219.151.179.47:8087/'
+        }
+        if (extend.isEmptyString(url.authUrl)) {
+            url.api = 'http://219.151.179.47:8081/'
+        }
+        return url;
+    }
 }
 
 /**