uniapp

#login.vue

复制代码
onReady() {//记住密码
            //缓存的账号
            const QS_username = uni.getStorageSync('QS_username');
            //缓存的密码
            const QS_password = uni.getStorageSync('QS_password');
            console.log("缓存的账号:"+QS_username)
            console.log("缓存的密码:"+QS_password)
            
            //有缓存就赋值给文本没有就清空
            if (QS_username && QS_password) {
                this.username = QS_username;
                this.password = QS_password;
            } else {
                this.username = '';
                this.password = '';
            }
            //自动登录
            },
复制代码
复制代码
//复选框
            checkboxChange: function(e) {
                console.log("复选框状态:"+e.detail.value.length);
                if (e.detail.value.length == 1) {
                    //获取缓存的账号 赋值
                    uni.getStorageSync('QS_username',this.username);
                    uni.getStorageSync('QS_password',this.password);
                } else {//销毁
                    uni.removeStorageSync('QS_username');
                    uni.removeStorageSync('QS_password');              
                }
            },
            
复制代码
复制代码
uni.request({
                    url: $config.urls.get_token,
                    method: 'POST',
                    data: {
                        username: this.username,
                        password: this.password
                    },
                    success: (res) => {
                        console.log(res);
                        
                        //勾选就缓存账号和密码
                        if (this.rememberPsw) {
                            uni.setStorageSync('QS_username', this.username);
                            uni.setStorageSync('QS_password', this.password);
                        } else {//销毁缓存
                            uni.removeStorageSync('QS_username');
                            uni.removeStorageSync('QS_password');
                        }
                        
                        if (res.statusCode==200){
                            this.jwt_token = res.data.access
                            this.uid = res.data.uid
                            $config.user.set_user(this.username, this.uid, res.data.access)
                            uni.switchTab({
                                url:'/pages/my/my'
                            });
                        }else{
                            uni.showToast({
                                title: res.errMsg,
                                icon:'none'
                            });
                        }
                    },
                    fail: (err) => {
                        console.log(err);
                    },
                    complete: () => {}
                });
复制代码

====

<!-- 记住密码功能 -->
            <view class="item">
                <checkbox-group @change="checkboxChange">
                    <checkbox  id="chkRem" type="checkbox"  :checked='rememberPsw' @tap="rememberPsw =! rememberPsw" color="#09CC86"/>
                    <text class="remember_pwd">记住账号密码</text>
                </checkbox-group>
            </view>
data() {
            return {
                username:'',
                password:'',
                rememberPsw: true, //复选框状态 默认勾选
            }
        },

但有个问题,存储的密码是明文

? 需要寻找加密方案=》

posted on   koolman  阅读(114)  评论(0)    收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示