刘磊
2025-04-19 2f18780a16a68f7fc67dd3bca61b8d0aed7c8e1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<template>
    <view class="login">
        <view class="content">
            <view class="header">
                <image :src="require('static/image/login.png')"></image>
            </view>
            <view class="main">
                <wInput v-model="phoneData" type="text" maxlength="15" placeholder="用户名">
                </wInput>
                <wInput v-model="passData" type="password" maxlength="15" placeholder="密码">
                </wInput>
                <checkbox :checked="RememberThePassword" @click="Check">记住密码</checkbox>
            </view>
            <wButton class="wbutton" text="登 录" :rotate="isRotate" @click="startLogin"></wButton>
        </view>
    </view>
</template>
 
<script>
    var _this;
    import wInput from '../../components/watch-login/watch-input.vue'
    import wButton from '../../components/watch-login/watch-button.vue'
    export default {
        data() {
            return {
                phoneData: '', //用户/电话//admin
                passData: '',//123456
                isRotate: false,
                RememberThePassword: false
            }
        },
        components: {
            wInput,
            wButton,
        },
        mounted() {
            _this = this;
 
            const HCRtp = uni.getStorageSync('HCRtp');
            if (HCRtp) 
                _this.RememberThePassword = true;
             else
                _this.RememberThePassword = false;
            if (HCRtp) {
                //缓存的账号
                const HCuname = uni.getStorageSync('HCuname');
                //缓存的密码
                const HCpassw = uni.getStorageSync('HCpassw');
                //有缓存就赋值给文本没有就清空
                if (HCuname && HCpassw) {
                    _this.phoneData = HCuname;
                    _this.passData = HCpassw;
                } else {
                    _this.phoneData = '';
                    _this.passData = '';
                }
            }
        },
        methods: {
            startLogin(e) {
                if (e.isRotate) //判断是否加载中,避免重复点击请求
                    return false;
 
                let userName = this.phoneData;
                if ('' == userName || null == userName) {
                    uni.showToast({
                        icon: 'none',
                        position: 'bottom',
                        title: '用户名不能为空'
                    })
                    return;
                }
                let pwd = this.passData;
                if ('' == pwd || null == pwd || pwd.length < 5) {
                    uni.showToast({
                        icon: 'none',
                        position: 'bottom',
                        title: '密码不能小于五位数'
                    })
                    return;
                }
                _this.isRotate = true;
                let data = {
                    'userName': userName,
                    'password': pwd,
                    'VerificationCode': 'App',
                    'UUID': 'App'
                }
                // uni.navigateTo({
                //     url: "../AssemblyArea/ProgressProducts/CallMaterial/index"
                // })
                // return;
                this.$AjaxRequest.Params('post', 'Sys_User/login', data, null);
                this.$AjaxRequest.Request().then(function(result) {
                    if (result.data.status) {
 
                        if (_this.RememberThePassword) {
                            uni.setStorageSync('HCuname', _this.phoneData);
                            uni.setStorageSync('HCpassw', _this.passData);
                        } else {
                            uni.removeStorageSync('HCuname');
                            uni.removeStorageSync('HCpassw');
                        }
                        uni.setStorageSync('HCRtp', _this.RememberThePassword);
                        uni.navigateTo({
                            url: "./main"
                        });
                        _this.$UserTool.setUserInfo(result.data.data);
                        _this.$UserTool.setAllUserInfo({
                            label: result.data.data.userName,
                            value: result.data.data.userName,
                        });
                        //console.log(_this.$UserTool);
                    } else {
                        uni.showToast({
                            icon: 'none',
                            title: result.data.message,
                            duration: 2000
                        });
                    }
                }).catch(function(err) {
                    //console.log(err);
                    uni.showToast({
                        icon: 'none',
                        title: "请求后台异常,错误信息." + err.errMsg,
                        duration: 2000
                    });
                    //console.log(err);
                });
                _this.isRotate = false;
            },
            Check(e) {
                _this.RememberThePassword = !_this.RememberThePassword;
            }
        }
    }
</script>
 
<style>
    @import url("../../components/watch-login/css/icon.css");
    @import url("./css/main.css");
</style>