优化代码

This commit is contained in:
wuxw 2024-12-05 11:14:05 +08:00
parent aed35786ea
commit 435311c502
4 changed files with 221 additions and 14 deletions

View File

@ -108,11 +108,7 @@
});
return;
}
let wAppId = uni.getStorageSync(constant.mapping.W_APP_ID);
uni.clearStorageSync();
if (wAppId != null && wAppId != undefined && wAppId != '') {
uni.setStorageSync(constant.mapping.W_APP_ID, wAppId);
}
that.logoutUser =false;
that.vc.navigateTo({
url: '/pages/login/login'

View File

@ -15,13 +15,13 @@ const baseUrl = '/';
// #ifndef H5
//服务器域名 小程序 或者 app 时 后端地址
const baseUrl = 'https://pms.x2wl.com/';
const baseUrl = 'https://crsdt.cn/';
// #endif
let commonBaseUrl = 'https://pms.x2wl.com/';
let commonBaseUrl = 'http://crsdt.cn/';
//商城的url
let mallUrl = 'https://mallapp.x2wl.com/';
let mallUrl = 'https://mallapp.crsdt.cn/';
//商城小程序ID
let mallMinAppId = "wxa4211361ca1e1bfb";

View File

@ -84,12 +84,12 @@
onLoad(option) {
let that = this;
this.logoUrl = constant.url.baseUrl + 'logo.png';
//todo 退西
uni.removeStorageSync("ownerInfo");
uni.removeStorageSync("userInfo");
uni.removeStorageSync("JAVA110_USER_INFO");
uni.removeStorageSync("currentCommunityInfo");
removeUserLoginInfo();
let wAppId = uni.getStorageSync(constant.mapping.W_APP_ID);
//todo 退西
uni.clearStorageSync();
if (wAppId) {
uni.setStorageSync(constant.mapping.W_APP_ID, wAppId);
}
},
methods: {
_doLogin: function() {

View File

@ -0,0 +1,211 @@
<template>
<view class="">
<view class="flex justify-center logo">
<view class="cu-avatar xl round margin-left logo-lage" :style="{backgroundImage: 'url(' + logoUrl + ')' }">
</view>
</view>
<view class="margin-top padding-left padding-right radius" v-if="!loginByPhone">
<view class="cu-form-group margin-top">
<view class="title">用户名</view>
<input placeholder="请输入用户名" name="input" v-model="username"></input>
</view>
<view class="cu-form-group border-bottom">
<view class="title">密码</view>
<input placeholder="请输入密码" type="password" name="input" v-model="password"></input>
</view>
</view>
<view class="margin-top padding-left padding-right radius" v-else>
<view class="cu-form-group margin-top">
<view class="title">手机号</view>
<input placeholder="请输入手机号" name="input" v-model="username"></input>
</view>
<view class="cu-form-group border-bottom">
<view class="title">验证码</view>
<input v-model="password" placeholder="请输入短信验证码" name="input"></input>
<button class='cu-btn bg-green shadow' :disabled="btnDisabled"
@click="sendMsgCode()">{{btnValue}}</button>
</view>
</view>
<view class="padding-left padding-right padding-top flex flex-direction margin-top">
<button class="cu-btn bg-green lg" @click="_doLogin()">登录</button>
<button class="cu-btn line-orange margin-tb-sm lg" @click="_doRegister()">注册</button>
</view>
<view class="padding-right flex justify-end">
<checkbox-group @change="_changeSaveLogin">
<checkbox style="transform: scale(0.7)" :checked="loginInfo == 'ON'" ></checkbox>
</checkbox-group>
<view class="read-me">
<text class="margin-left-xs">记住密码</text>
</view>
</view>
</view>
</template>
<script>
var _this;
import wInput from '../../components/watch-input.vue' //input
import wButton from '../../components/watch-button.vue' //button
import {
sendSmsCode,
ownerLogin,
} from '../../api/user/userApi.js'
import context from '../../lib/java110/Java110Context.js';
import {
getLoginCode
} from '../../lib/java110/page/Page.js';
import {
saveOwnerStorage,
saveUserLoginInfo,
removeUserLoginInfo,
getWAppId,
saveWAppId,
getLoginFlag
} from '@/lib/java110/utils/StorageUtil.js'
const constant = context.constant;
const factory = context.factory;
const login = 1; //1 code key
export default {
data() {
return {
logoUrl: '',
username: '',
password: '',
code: "",
loginByPhone: false,
msgCode: '',
btnDisabled: false,
btnValue: '验证码',
phoneLoginName: '验证码登录',
loginInfo:'OFF'
};
},
onLoad(option) {
let that = this;
this.logoUrl = constant.url.baseUrl + 'logo.png';
let wAppId = uni.getStorageSync(constant.mapping.W_APP_ID);
let _loginInfo = uni.getStorageSync('logoUserInfo');
//todo 退西
uni.clearStorageSync();
if (wAppId) {
uni.setStorageSync(constant.mapping.W_APP_ID, wAppId);
}
if(_loginInfo){
this.username = _loginInfo.username;
this.password = _loginInfo.password;
this.loginInfo = _loginInfo.loginInfo;
uni.setStorageSync('logoUserInfo',_loginInfo);
}
},
methods: {
_changeSaveLogin:function(){
if(this.loginInfo == 'ON'){
this.loginInfo = 'OFF';
uni.removeStorageSync('logoUserInfo');
}else{
this.loginInfo = 'ON';
}
},
_doLogin: function() {
let _that = this;
if (this.username == '') {
wx.showToast({
title: '请填写用户名',
icon: "none"
});
return;
}
if (this.password == '') {
wx.showToast({
title: '请填写密码',
icon: "none"
});
return;
}
let _obj = {
username: this.username,
password: this.password,
code: _that.code,
appId: this.vc.getWAppId(),
loginByPhone: this.loginByPhone
};
ownerLogin(this,_obj)
.then((_user) => {
if(_that.loginInfo == 'ON'){
uni.setStorageSync('logoUserInfo',{
username:_that.username,
password:_that.password,
loginInfo:_that.loginInfo
});
}
//todo
saveUserLoginInfo(_user.userId, _user.token, _user.key);
uni.navigateTo({
url:'/pages/login/loginInitWechat?communityId='+_user.communityId
})
},err=>{
uni.showToast({
icon:'none',
title:err
})
});
},
_doRegister: function() {
//let _url = '/pages/login/registerByWechat';
let _url = '/pages/login/register';
this.vc.navigateTo({
url: _url
})
},
sendMsgCode: function() {
sendSmsCode(this.username, this);
},
_doLoginPhone: function() {
this.loginByPhone = !this.loginByPhone;
if (this.loginByPhone) {
this.phoneLoginName = "密码登录"
} else {
this.phoneLoginName = "验证码登录"
}
this.username = '';
this.password = '';
}
}
}
</script>
<style>
page {
background-color: #FFF;
}
.logo {
margin-top: 160upx;
margin-bottom: 140upx;
}
.logo .logo-lage {
height: 180upx;
width: 180upx;
}
.login-nav {
background-color: #00AA00;
height: 120upx;
}
.login-nav text {
color: #FFFFFF;
font-size: 30upx;
}
</style>