ll
liukangdong
2024-11-29 b850badcf800eff5819e0789d1b81e5e27fcd037
h5/pages/login.vue
@@ -5,16 +5,17 @@
    <view class="login_list">
      <view class="login_list_item">
        <image src="@/static/login_ic_phone@2x.png" mode="widthFix" />
        <input v-model="form.username" maxlength="18" placeholder="请输入手机号" />
        <input v-model="form.phone" maxlength="18" placeholder="请输入手机号" />
      </view>
<!--      <view class="login_list_item">
<!--     <view class="login_list_item">
        <image src="@/static/login_ic_password@2x.png" mode="widthFix" />
        <input v-model="form.password" type="password" placeholder="密码" />
      </view> -->
      <view class="login_list_item">
     <view class="login_list_item">
        <image src="@/static/login_ic_password@2x.png" mode="widthFix"></image>
        <input v-model="form.code" placeholder="请输入验证码" type="text" />
        <view class="btn">获取验证码</view>
        <view v-if="downTime == 0" class="btn" @click="sendSms">获取验证码</view>
        <view v-else class="btn gray">{{ downTime }}</view>
      </view>
    </view>
    <view class="login_btn">
@@ -24,7 +25,7 @@
</template>
<script>
import { loginPost, loginCaptcha, getUserInfo, getSystemDictData } from '@/api'
import { loginPost, getUserInfo, sendSMsPost } from '@/api'
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'login',
@@ -32,20 +33,14 @@
  data() {
    return {
      form: {
        // username: '18056814089',
        username: '',
        password: '',
            code: ''
            phone: '17878787878',
            code: '1'
      },
      isShowProtocol: false,
      ProtocolFlag: false,
      captcha: {},
      htmlText: ''
         downTime: 0
    }
  },
  onLoad() {
    this.initCaptcha()
  },
  onBackPress(options) {
    uni.redirectTo({
@@ -55,39 +50,28 @@
  },
  methods: {
    ...mapMutations(["setToken", "setUserInfo"]),
    changeFalg() {
      this.ProtocolFlag = !this.ProtocolFlag
    },
    getContent() {
      getSystemDictData({
        dictCode: 'SYSTEM',
        label: 'USER_PROTOCOL'
      }).then(res => {
        this.htmlText = res.data.code
        this.isShowProtocol = true
      })
    },
    showContent() {
      this.getContent()
    },
    initCaptcha() {
      loginCaptcha().then(res => {
        this.captcha = res.data
      })
    },
      sendSms() {
         this.downTime = 60
         let timer = setInterval(() => {
            if(this.downTime == 0) return clearInterval(timer)
            this.downTime = this.downTime - 1
         }, 1000)
         const { form } = this
         sendSMsPost({
            phone: form.phone,
            type: 0
         }).then(res => {
            this.showToast('短信发送成功')
         })
      },
    onLogin() {
      const { form, ProtocolFlag } = this
      if (!ProtocolFlag) return uni.showToast({
        title: '请先阅读并同意用户协议',
        icon: 'none'
      })
      if (!form.username) return uni.showToast({
        title: '账号不能为空',
        icon: 'none'
      })
      if (!form.password) return uni.showToast({
        title: '密码不能为空',
      // if (!ProtocolFlag) return uni.showToast({
      //   title: '请先阅读并同意用户协议',
      //   icon: 'none'
      // })
      if (!form.phone) return uni.showToast({
        title: '手机号不能为空',
        icon: 'none'
      })
      if (!form.code) return uni.showToast({
@@ -96,15 +80,15 @@
      })
      loginPost({
        ...form,
        uuid: this.captcha.uuid,
        openId: this.$store.state.openId
      }).then(res => {
        if (res.code === 200) {
          this.setToken(res.data)
               this.showToast('登录成功')
          getUserInfo().then(ress => {
            this.setUserInfo(ress.data)
            uni.redirectTo({
              url: "/pages/staff/index"
              url: "/pages/index"
            })
          })
        }
@@ -162,7 +146,11 @@
      .btn{
         width: 145rpx;
         color:  $primaryColor;
            text-align: center;
      }
         .gray{
            color: #999999;
         }
      input {
        flex: 1;
        height: 100%;