#
whycq
2023-07-30 0eef5e57cd28c0b384f295df724599da468d7fe2
#
10个文件已添加
711 ■■■■■ 已修改文件
App.vue 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
index.html 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.js 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages.json 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/index.vue 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/login/logOut.vue 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/login/login.vue 476 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
static/logo.png 补丁 | 查看 | 原始文档 | blame | 历史
uni.promisify.adaptor.js 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
uni.scss 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
App.vue
New file
@@ -0,0 +1,17 @@
<script>
    export default {
        onLaunch: function() {
            console.log('App Launch')
        },
        onShow: function() {
            console.log('App Show')
        },
        onHide: function() {
            console.log('App Hide')
        }
    }
</script>
<style>
    /*每个页面公共css */
</style>
index.html
New file
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <script>
      var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
        CSS.supports('top: constant(a)'))
      document.write(
        '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
        (coverSupport ? ', viewport-fit=cover' : '') + '" />')
    </script>
    <title></title>
    <!--preload-links-->
    <!--app-context-->
  </head>
  <body>
    <div id="app"><!--app-html--></div>
    <script type="module" src="/main.js"></script>
  </body>
</html>
main.js
New file
@@ -0,0 +1,22 @@
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif
pages.json
New file
@@ -0,0 +1,17 @@
{
    "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
        {
            "path": "pages/index/index",
            "style": {
                "navigationBarTitleText": "uni-app"
            }
        }
    ],
    "globalStyle": {
        "navigationBarTextStyle": "black",
        "navigationBarTitleText": "uni-app",
        "navigationBarBackgroundColor": "#F8F8F8",
        "backgroundColor": "#F8F8F8"
    },
    "uniIdRouter": {}
}
pages/index/index.vue
New file
@@ -0,0 +1,52 @@
<template>
    <view class="content">
        <image class="logo" src="/static/logo.png"></image>
        <view class="text-area">
            <text class="title">{{title}}</text>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                title: 'Hello'
            }
        },
        onLoad() {
        },
        methods: {
        }
    }
</script>
<style>
    .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    .logo {
        height: 200rpx;
        width: 200rpx;
        margin-top: 200rpx;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 50rpx;
    }
    .text-area {
        display: flex;
        justify-content: center;
    }
    .title {
        font-size: 36rpx;
        color: #8f8f94;
    }
</style>
pages/login/logOut.vue
New file
@@ -0,0 +1,21 @@
<template>
    <view></view>
</template>
<script>
    export default {
        mounted() {
            uni.showToast({
                title: '注销成功',
                duration: 1000
            })
            setTimeout(() => {
                uni.removeStorageSync('token');
                uni.reLaunch({
                    url:"/pages/login/login"
                });
            }, 1000);
        },
    }
</script>
pages/login/login.vue
New file
@@ -0,0 +1,476 @@
<template>
    <view>
        <!-- 设置 -->
        <view class="settings">
            <view class="settings-btn">
                <uni-icons type="gear" size="30" color="#707070" @click="settings"></uni-icons>
            </view>
        </view>
        <!-- logo -->
        <view class="logo">
            <view class="logo-box">
                <image src="../../static/img/logo.png" mode="aspectFit"></image>
            </view>
        </view>
        <view class="content">
            <!-- 账号 -->
            <view class="box shadow-warp">
                <view class="box-icon">
                    <uni-icons type="person" size="20" color="#707070"></uni-icons>
                </view>
                <view class="box-text">账号:</view>
                <view class="box-input">
                    <input type="text" placeholder="请输入账号" v-model="user.userName"
                    placeholder-style="font-size:14px;color:#ccc;">
                </view>
                <view class="box-show"></view>
            </view>
            <!-- 密码 -->
            <view class="box shadow-warp">
                <view class="box-icon">
                    <uni-icons type="locked" size="20" color="#707070"></uni-icons>
                </view>
                <view class="box-text">密码:</view>
                <view class="box-input">
                    <input :password="!showPassword" placeholder="请输入密码" v-model="user.password"
                    placeholder-style="font-size:14px;color:#ccc;" >
                </view>
                <view class="box-show">
                    <uni-icons type="eye-filled" size="20" color="#707070" v-if="!showPassword" @click="changePassword"></uni-icons>
                    <uni-icons type="eye" size="20" color="#707070" v-if="showPassword" @click="changePassword"></uni-icons>
                </view>
            </view>
            <!-- 记住密码 -->
            <view class="check">
                <view class="check-left">
                    <view>记住密码</view>
                </view>
                <view class="check-right">
                    <switch :checked='remberPassword' color="#FFCC33" style="zoom:.5" @change="remberChange"/>
                </view>
            </view>
        </view>
        <!-- 登录按钮 -->
        <view class="submit">
            <view class="" style="width: 400rpx;">
                <button type="primary" @click="onLogin()" :loading="load.loading">{{load.btnText}}</button>
            </view>
        </view>
        <!-- 设置弹窗区域 -->
        <view>
            <uni-popup ref="inputDialog" type="dialog">
                <view class="popup">
                    <!-- 标题 -->
                    <view class="title">配置</view>
                    <view class="popup-item">
                        <view class="popup-item-left">IP:</view>
                        <view class="popup-item-right"><input type="text" v-model="url.ip"></view>
                    </view>
                    <view class="popup-item">
                        <view class="popup-item-left">端口:</view>
                        <view class="popup-item-right"><input type="text" v-model="url.port"></view>
                    </view>
                    <view class="popup-item">
                        <view class="popup-item-left">项目:</view>
                        <view class="popup-item-right"><input type="text" v-model="url.project"></view>
                    </view>
                    <view class="btn">
                        <view class="btn-left" @click="close">取消</view>
                        <view class="btn-right" @click="settingConfirm">确认</view>
                    </view>
                </view>
            </uni-popup>
        </view>
        <view>
            <!-- 提示窗示例 -->
            <uni-popup ref="upVersion" type="dialog">
                <uni-popup-dialog :type="msgType" title="通知" :content="dialogContent" @confirm="dialogConfirm"
                    @close="dialogClose"></uni-popup-dialog>
            </uni-popup>
        </view>
        <!-- 版本号 -->
        <!-- #ifdef APP-PLUS -->
        <view class="version">
            当前版本:{{version}}
        </view>
        <!-- #endif -->
    </view>
</template>
<script>
    import md5 from '../../static/js/md5.js'
    export default {
        data() {
            return {
                version: '',
                showPassword: false,
                value: '',
                remberPassword: true,
                url: {
                    ip: '',
                    port: '',
                    project: ''
                },
                baseUrl: '',
                user: {
                    userName: '',
                    password: '',
                },
                load: {
                    loading: false,
                    btnText: '登录'
                },
                msgType: 'success',
                filename: '',
                dialogContent: ''
            }
        },
        onLoad() {
            this.user = uni.getStorageSync('user')
            this.url = uni.getStorageSync('url')
            this.baseUrl = uni.getStorageSync('baseUrl')
            if (!this.user) {
                this.user = {userName: '',password: ''}
            }
            if (!this.url) {
                this.url = {ip: '',port: '',project: ''}
            }
            // this.getVersion()
        },
        onShow () {
            // 手机端版本号
            // // #ifdef APP-PLUS
            // var that = this
            // plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
            //     that.version = wgtinfo.version
            // });
            // // #endif
            this.getVersion()
        },
        methods: {
            // 显示/隐藏密码
            changePassword() {
                this.showPassword = !this.showPassword;
            },
            remberChange(e) {
                this.remberPassword = !this.remberPassword
            },
            // 设置窗口开启按钮
            settings() {
                this.$refs.inputDialog.open()
            },
            // 设置窗口确认修改按钮
            dialogInputConfirm() {
                this.$refs.inputDialog.close()
            },
            // 设置窗口关闭按钮
            close() {
                this.$refs.inputDialog.close()
            },
            // 保存ip
            settingConfirm() {
                this.baseUrl = "http://" + this.url.ip + ':' + this.url.port + '/' + this.url.project
                uni.setStorageSync('baseUrl', this.baseUrl);
                uni.setStorageSync('url', this.url);
                this.$refs.inputDialog.close()
            },
            onLogin() {
                let that = this
                uni.request({
                    url: that.baseUrl + '/login.action',
                    fail(result) {
                        uni.showToast({
                            icon: 'error',
                            title: '请求失败'
                        })
                    },
                    data: {
                        username: that.user.userName,
                        password: md5.hex_md5(that.user.password)
                    },
                    header: {
                        "content-type": "application/json"
                    },
                    success(result) {
                        if (result.statusCode === 404) {
                            uni.showToast({
                                title: '登录失败',
                                icon: "error"
                            })
                            return
                        }
                        let res = result.data
                        if (res.code === 200) {
                            that.load.loading = true;
                            that.load.btnText = '登录中';
                            uni.setStorageSync('token', res.data.token);
                            if(that.remberPassword){
                                uni.setStorageSync('user', that.user);
                            }else{
                                uni.removeStorageSync('user');
                            }
                            setTimeout(() => {
                                uni.showToast({
                                    title: '登录成功'
                                })
                                setTimeout(() => {
                                    uni.reLaunch({
                                        url: '../home/home'
                                    });
                                }, 300)
                            }, 700)
                        } else {
                            uni.showToast({
                                title: res.msg
                            })
                        }
                    },
                })
            },
            //检测当前平台,如果是安卓则启动安卓更新
            getVersion() {
                let that = this;
                uni.getSystemInfo({
                    success: (res) => {
                        if (res.platform == "android") {
                            that.AndroidCheckUpdate();
                        }
                    }
                })
            },
            // 获取当前版本号
            AndroidCheckUpdate() {
                let that = this;
                plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
                    that.version = wgtinfo.version //客户端版本号
                })
                setTimeout(()=>{
                    that.getUpdateVersion()
                },100)
            },
            // 校验版本
            getUpdateVersion() {
                let that = this
                let type = 0
                if (that.baseUrl == 'http://undefined:undefined/undefined') {
                    return
                }
                let url = that.baseUrl + '/appVersion/checkUpdate/' + that.version + '/' + type
                uni.request({
                    url: url,
                    method: 'GET',
                    success(res) {
                        var res = res.data
                        if (res.data) {
                            that.filename = res.data.path
                            that.dialogContent = '发现新版本:' + res.data.version + ', 是否立即更新'
                            that.$refs.upVersion.open()
                        }
                    }
                })
            },
            dialogConfirm() {
                this.$refs.upVersion.close()
                this.downWgt()
            },
            dialogClose() {
                this.$refs.upVersion.close()
            },
            downWgt() {
                let that = this;
                const downloadUrl = that.baseUrl + "/appVersion/downloadApp/" + that.filename
                uni.showLoading({
                    title: '更新中……'
                })
                const downloadTask = uni.downloadFile({ //执行下载
                    url: downloadUrl, //下载地址
                    timeout: 1000 * 30, //30秒超时时间
                    success: downloadResult => { //下载成功
                        console.log(downloadResult);
                        that.showdownLine = false
                        uni.hideLoading();
                        if (downloadResult.statusCode == 200) {
                            uni.showModal({
                                title: '',
                                content: '更新成功,确定现在重启吗?',
                                confirmText: '重启',
                                confirmColor: '#EE8F57',
                                success: function(res) {
                                    if (res.confirm == true) {
                                        plus.runtime.install( //安装
                                            downloadResult.tempFilePath, {
                                                force: true
                                            },
                                            function(res) {
                                                utils.showToast('更新成功,重启中');
                                                plus.runtime.restart();
                                            }
                                        );
                                    }
                                }
                            });
                        } else {
                            uni.hideLoading();
                            that.showdownLine = false
                            uni.showToast({
                                title:'请先上传安装包',
                                icon: 'error'
                            })
                        }
                    },
                    fail: err => {
                        uni.hideLoading();
                        that.showdownLine = false
                        that.$u.toast(downloadResult.errMsg)
                    },
                    complete: com => {
                        console.log(com)
                    }
                });
                // 下载进度
                downloadTask.onProgressUpdate(res => {
                    that.downloadNum = res.progress
                    console.log('下载进度' + that.downloadNum);
                });
            },
        }
    }
</script>
<style>
    @import url('../../static/css/wms.css/wms.css');
    /* 设置区域 */
    .settings {
        min-height: 100rpx;
    }
    .settings-btn {
        float: right;
        margin-right: 10rpx;
    }
    .logo {
        height: 25%;
        width: 100%;
        display: flex;
        justify-content: center;
    }
    .logo-box {
        margin: auto 0;
    }
    image {
        height: 300rpx;
    }
    /* 输入框区域 */
    .content {
        min-height: 250rpx;
        /* background-color: coral; */
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        color: #606266;
    }
    .box {
        width: 80%;
        height: 100rpx;
        margin-top: 30rpx;
        background-color: white;
        display: flex;
        font-size: 14px;
        align-items: center;
    }
    .box-icon {
        width: 80rpx;
        text-align: center;
    }
    .box-text {
        width: 100rpx;
        text-align: center;
    }
    .box-show {
        margin-left: auto;
        /* margin-right: 10rpx; */
        width: 60rpx;
        text-align: center;
    }
    input {
        padding-left: 10rpx;
        font-size: 14px;
        color: #303133;
    }
    .check {
        width: 78%;
        display: flex;
        font-size: 12px;
        color: #606266;
        margin-top: 10rpx;
    }
    .check-right {
        margin-left: auto;
    }
    .submit {
        display: flex;
        justify-content: center;
        position: fixed;
        width: 100%;
        bottom: 100rpx;
    }
    .version {
        position: fixed;
        width: 100%;
        bottom: 0;
        text-align: center;
        font-size: 12px;
        color: #909399;
    }
    /* ------ */
    .shadow-warp {
        position: relative;
        box-shadow: 0 0 10upx rgba(0, 0, 0, 0.1);
    }
    .shadow-warp:before,
    .shadow-warp:after {
        position: absolute;
        content: "";
        top: 20upx;
        bottom: 30upx;
        left: 20upx;
        width: 50%;
        box-shadow: 0 30upx 20upx rgba(0, 0, 0, 0.2);
        transform: rotate(-3deg);
        z-index: -1;
    }
    .shadow-warp:after {
        right: 20upx;
        left: auto;
        transform: rotate(3deg);
    }
</style>
static/logo.png
uni.promisify.adaptor.js
New file
@@ -0,0 +1,10 @@
uni.addInterceptor({
  returnValue (res) {
    if (!(!!res && (typeof res === "object" || typeof res === "function") && typeof res.then === "function")) {
      return res;
    }
    return new Promise((resolve, reject) => {
      res.then((res) => res[0] ? reject(res[0]) : resolve(res[1]));
    });
  },
});
uni.scss
New file
@@ -0,0 +1,76 @@
/**
 * 这里是uni-app内置的常用样式变量
 *
 * uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
 * 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
 *
 */
/**
 * 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
 *
 * 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
 */
/* 颜色变量 */
/* 行为相关颜色 */
$uni-color-primary: #007aff;
$uni-color-success: #4cd964;
$uni-color-warning: #f0ad4e;
$uni-color-error: #dd524d;
/* 文字基本颜色 */
$uni-text-color:#333;//基本色
$uni-text-color-inverse:#fff;//反色
$uni-text-color-grey:#999;//辅助灰色,如加载更多的提示信息
$uni-text-color-placeholder: #808080;
$uni-text-color-disable:#c0c0c0;
/* 背景颜色 */
$uni-bg-color:#ffffff;
$uni-bg-color-grey:#f8f8f8;
$uni-bg-color-hover:#f1f1f1;//点击状态颜色
$uni-bg-color-mask:rgba(0, 0, 0, 0.4);//遮罩颜色
/* 边框颜色 */
$uni-border-color:#c8c7cc;
/* 尺寸变量 */
/* 文字尺寸 */
$uni-font-size-sm:12px;
$uni-font-size-base:14px;
$uni-font-size-lg:16;
/* 图片尺寸 */
$uni-img-size-sm:20px;
$uni-img-size-base:26px;
$uni-img-size-lg:40px;
/* Border Radius */
$uni-border-radius-sm: 2px;
$uni-border-radius-base: 3px;
$uni-border-radius-lg: 6px;
$uni-border-radius-circle: 50%;
/* 水平间距 */
$uni-spacing-row-sm: 5px;
$uni-spacing-row-base: 10px;
$uni-spacing-row-lg: 15px;
/* 垂直间距 */
$uni-spacing-col-sm: 4px;
$uni-spacing-col-base: 8px;
$uni-spacing-col-lg: 12px;
/* 透明度 */
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
/* 文章场景相关 */
$uni-color-title: #2C405A; // 文章标题颜色
$uni-font-size-title:20px;
$uni-color-subtitle: #555555; // 二级标题颜色
$uni-font-size-subtitle:26px;
$uni-color-paragraph: #3F536E; // 文章段落颜色
$uni-font-size-paragraph:15px;