userlogin.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view>
  3. <form @submit="loginSub">
  4. <view class="cu-form-group margin-top">
  5. <view class="title">号码</view>
  6. <input placeholder="请输入手机号" name="phone" v-model="form.phone"></input>
  7. </view>
  8. <view class="cu-form-group">
  9. <view class="title">密码</view>
  10. <input placeholder="请输入密码" password name="password" v-model="form.password"></input>
  11. </view>
  12. <view class="text-right text-gray margin-right margin-top cuIcon-question" @click="toReset">
  13. 忘记密码
  14. </view>
  15. <view class="padding flex flex-direction">
  16. <button class="cu-btn margin-tb-sm lg round" :class="'bg-'+theme.backgroundColor" form-type="submit">立即登录</button>
  17. <view class="margin-top flex justify-center text-sm" v-show="showPrivacyPolicy">
  18. <text>登录即代表您同意</text><navigator class="text-blue text-sm" :url="'/pages/public/webview/webview?title=用户协议&url='+protocolUrl">{{' 用户协议 '}}</navigator>和<navigator class="text-blue text-sm " :url="'/pages/public/webview/webview?title=隐私政策&url='+privacyPolicyUrl">{{' 隐私政策'}}</navigator>
  19. </view>
  20. </view>
  21. <view class="text-center">
  22. 没有账号?<text class="text-red" @click="toRegister">立即注册</text>
  23. </view>
  24. </form>
  25. </view>
  26. </template>
  27. <script>
  28. const app = getApp();
  29. import api from 'utils/api'
  30. import validate from 'utils/validate'
  31. import __config from '@/config/env';// 配置文件
  32. export default {
  33. data() {
  34. return {
  35. theme: app.globalData.theme, //全局颜色变量
  36. CustomBar: this.CustomBar,
  37. form: {},
  38. showPrivacyPolicy: __config.showPrivacyPolicy,
  39. privacyPolicyUrl: __config.privacyPolicyUrl,
  40. protocolUrl: __config.protocolUrl,
  41. };
  42. },
  43. components: {
  44. },
  45. props: {
  46. reUrl: {//重定向页面
  47. type: String,
  48. default: '/pages/home/index'
  49. }
  50. },
  51. onLoad() {
  52. },
  53. onShow() {
  54. },
  55. methods: {
  56. toReset(){
  57. uni.redirectTo({
  58. url: '/pages/login/register?type=reset'
  59. });
  60. },
  61. toRegister(){
  62. uni.redirectTo({
  63. url: '/pages/login/register'
  64. });
  65. },
  66. loginSub(e){
  67. if(!validate.validateMobile(this.form.phone)){
  68. uni.showToast({
  69. title: '请输入正确的手机号码',
  70. icon: 'none',
  71. duration: 3000
  72. });
  73. return;
  74. }
  75. if(!this.form.password){
  76. uni.showToast({
  77. title: '请输入密码',
  78. icon: 'none',
  79. duration: 3000
  80. });
  81. return;
  82. }
  83. api.login(this.form).then(res => {
  84. let userInfo = res.data;
  85. uni.setStorageSync('third_session', userInfo.thirdSession);
  86. uni.setStorageSync('user_info', userInfo);
  87. //登录完成跳到首页
  88. uni.reLaunch({
  89. url: this.reUrl?decodeURIComponent(this.reUrl):'/pages/home/index'
  90. });
  91. //获取购物车数量
  92. app.shoppingCartCount()
  93. });
  94. }
  95. }
  96. };
  97. </script>
  98. <style>
  99. </style>