123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <template>
- <view>
- <view style="height: 90rpx;"></view>
- <view style="padding-left: 30rpx;">
- <u-icon name="close" color="#666" size="24" @click="backto()"
- style="width: 40rpx;height: 40rpx;"></u-icon>
- </view>
- <view style="height: 260rpx;"></view>
- <view class="detext">登录即可体验完整功能</view>
- <veiw class="log">
- <view class="form-items">
- <u-icon name="account" color="#666" size="24" ></u-icon>
- <input
- type="number"
- style="flex: 1;margin-left: 16rpx;"
- v-model="phone"
- placeholder="请输入手机"
- maxlength="11"/>
- </view>
- <view class="form-items">
- <u-icon name="lock" color="#666" size="24" ></u-icon>
- <input
- type="password"
- style="flex: 1;margin-left: 16rpx;"
- v-model="password"
- placeholder="请输入密码"
- maxlength="11"/>
- </view>
- <view class="submitlog" @click="submit()">登录</view>
- <view class="forget">
- <view @click="navTo('/pages/auth/register')">注册账号</view>
- <view @click="navTo('/pages/auth/forgetPassword')">忘记密码</view>
- </view>
- </veiw>
- <view class="tips">
- <checkbox :checked="isAgreement" @click="handleAgreement()" color='#fff'
- activeBackgroundColor='#018C39 ' borderColor='#EDEEEF' activeBorderColor='#EDEEEF'/>
- <view @click="handleAgreement()">您同意并接受</view>
- <view class="btn" @click="openH5('/h5/userAgreement')">《用户协议》</view>
- <view class="btn" @click="openH5('/h5/privacyPolicy')">《隐私保护》</view>
- </view>
- <!-- 第三方登录 -->
- <view @click="handleWechatLogin()" class="wechat-btn">
- <image src="/static/images/wechat.png" style="width: 80rpx; height: 80rpx;"></image>
- </view>
- </view>
- </template>
- <script>
- import {login} from '@/api/user.js'
- export default {
- data() {
- return {
- phone:'',
- password:'',
- isAgreement:false,
- loginType:1,
- registrationID: '',
- }
- },
- watch: {
- isAgreement: {
- immediate: true,
- handler(value) {
- // #ifdef APP-PLUS
- if(value && !this.registrationID) {
- this.getRegistrationID()
- }
- // #endif
- }
- }
- },
- methods: {
- async getRegistrationID() {
- try {
- this.registrationID = await this.$getRegistrationID();
- console.log('推送ID:', this.registrationID);
- } catch (err) {
- this.registrationID = ''
- console.error('获取registrationID失败:', err);
- }
- },
- // 校验手机号
- validatePhone() {
- return /^1[3-9]\d{9}$/.test(this.phone);
- },
- // 跳转页面
- navTo(url){
- uni.navigateTo({
- url: url
- })
- },
- backto(){
- uni.navigateBack({
- url:-1
- })
- },
- handleAgreement(){
- this.isAgreement=!this.isAgreement;
- },
- openH5(url){
- var requestPath = uni.getStorageSync('requestPath');
- uni.setStorageSync('url',requestPath+url);
- uni.navigateTo({
- url: '../home/h5'
- })
- },
- handleWechatLogin(){
- //微信登录
- this.$showLoginPage("weixin");
- },
- submit(){
- if (!this.phone) {
- uni.showToast({ title: '请输入手机号', icon: 'none' });
- return;
- }
- if (!this.validatePhone()) {
- uni.showToast({ title: '手机号格式错误', icon: 'none' });
- return;
- }
- if (!this.password) {
- uni.showToast({ title: '请输入密码', icon: 'none' });
- return;
- }
- if(!this.isAgreement){
- uni.showToast({
- icon:'none',
- title: "请先同意协议后再登录",
- });
- return false;
- }
- const data={
- phone:this.phone,
- password:this.password,
- loginType:this.loginType,
- jpushId: this.registrationID,
- }
- login(data).then(res=>{
- if(res.code==200){
- uni.switchTab({
- url:'/pages/home/index'
- })
- uni.showToast({
- icon:'none',
- title: '登录成功',
- });
- uni.setStorageSync('AppToken', res.token);
- uni.setStorageSync('userInfo', JSON.stringify(res.user));
- }else{
- uni.showToast({
- icon:'none',
- title: res.msg,
- });
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .detext{
- font-size: 40rpx;
- font-weight: bold;
- text-align: center;
- margin-bottom: 40rpx;
- }
- .log{
- background: #fff ;
- width: calc(100% - 20rpx);
- margin: 10rpx ;
- padding: 20rpx 0;
- border-radius: 20rpx;
- display: flex;
- flex-direction: column;
- .form-items{
- background: #fff ;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- padding: 28rpx 0;
- margin: 0 20rpx;
- border-bottom: #eee solid 2rpx;
- }
- }
- .submitlog{
- background: linear-gradient(135deg, #38e663 0%, #018C39 100%);
- border-radius: 80rpx;
- color: #fff;
- margin: 0 auto;
- width: 80%;
- padding: 20rpx 0;
- text-align: center;
- margin-top: 40rpx;
- }
- .forget{
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 20rpx;
- font-size: 24rpx;
- color: #38e663 ;
- margin: 20rpx 0;
- }
- .tips{
- margin-top: 30rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 28rpx;
- color: #000;
- .btn{
- color: #018C39;
- }
- }
- /deep/ .uni-checkbox-input {
- border-radius: 50% !important;
- }
- .wechat-btn {
- margin-top: 100rpx !important;
- margin: 0 auto;
- width: fit-content;
- padding: 16rpx;
- display: flex;
- align-items: center;
- border-radius: 50%;
- border: 2rpx solid #28c445;
- }
- </style>
|