login.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view class="body" :style="{height:screenHeight}">
  3. <view class="header">
  4. <view class="text1">安全生产<br />宣传教育<br />平台</view>
  5. <view class="text2 u-flex"><view class="line"></view>商品核销</view>
  6. </view>
  7. <view class="login-box">
  8. <view class="title">账号密码登录</view>
  9. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" >
  10. <u-form-item label="" prop="mobile" ref="mobile" borderBottom >
  11. <u--input
  12. v-model="form.mobile"
  13. border="none"
  14. placeholder="请输入手机号码"
  15. :customStyle="inputCustomStyle"
  16. ></u--input>
  17. </u-form-item>
  18. <u-form-item label="" prop="password" ref="password" borderBottom >
  19. <u--input
  20. v-model="form.password"
  21. border="none"
  22. :password="true"
  23. placeholder="输入密码"
  24. :customStyle="inputCustomStyle"
  25. ></u--input>
  26. </u-form-item>
  27. </u--form>
  28. <u-button
  29. @click="submit"
  30. text="登录"
  31. type="primary"
  32. :customStyle="{'margin-top':'60rpx',height:'98rpx','box-sizing':'border-box'}"
  33. >
  34. </u-button>
  35. </view>
  36. <view class="tip">
  37. 贵州省公路建设养护集团有限公司贵阳分公司
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. bname:'',
  46. //屏幕高度
  47. screenHeight: "",
  48. backUrl:null,
  49. form:{
  50. mobile:'',
  51. password:''
  52. },
  53. rules: {
  54. mobile: {
  55. type: 'string',
  56. required: true,
  57. message: '请输入手机号码',
  58. trigger: ['blur', 'change']
  59. },
  60. password: {
  61. type: 'string',
  62. required: true,
  63. message: '请填写密码',
  64. trigger: ['blur', 'change']
  65. },
  66. },
  67. inputCustomStyle:{
  68. height:'98rpx',
  69. 'border-color':'#eee',
  70. 'padding-left':'0',
  71. 'box-sizing':'border-box',
  72. }
  73. };
  74. },
  75. onLoad() {
  76. // 测试环境填充用户名密码
  77. if(process.env.NODE_ENV=='development'){
  78. this.form.mobile = '13682277062';
  79. this.form.password = '000000';
  80. }
  81. let that = this;
  82. uni.getSystemInfo({
  83. success: (res) => {
  84. this.screenHeight = res.windowHeight + "px"
  85. }
  86. });
  87. uni.getStorage({
  88. key: 'backUrl',
  89. success: function (res) {
  90. // console.log('getStorage',res);
  91. },
  92. complete(res) {
  93. if(res.data){
  94. that.backUrl = '/'+res.data;
  95. }else{
  96. that.backUrl = '/pages/index/index';
  97. }
  98. // console.log('backUrl',that.backUrl);
  99. }
  100. });
  101. },
  102. onReady() {
  103. //onReady 为uni-app支持的生命周期之一
  104. this.$refs.uForm.setRules(this.rules)
  105. },
  106. onShow() {
  107. },
  108. methods: {
  109. submit(){
  110. // console.log('form',this.form);
  111. this.$refs.uForm.validate().then(res => {
  112. // uni.$u.toast('校验通过')
  113. this.$u.api.login(this.form).then(res=>{
  114. // console.log('res',res.data);
  115. this.$u.vuex('vuex_user_info', res.data);
  116. uni.removeStorage({
  117. key:'backUrl'
  118. })
  119. uni.reLaunch({url: this.backUrl});
  120. }).catch(err=>{
  121. console.log('login',err);
  122. })
  123. }).catch(errors => {
  124. uni.$u.toast('请正确填写表单')
  125. })
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .body {
  132. background-color: #fff;
  133. padding: 45rpx;
  134. box-sizing: border-box;
  135. }
  136. .header{
  137. color: $uni-color-primary;
  138. .text1{
  139. font-size: 72rpx;
  140. font-family: AlibabaPuHuiTi_2_105_Heavy;
  141. line-height: 88rpx;
  142. margin-bottom: 40rpx;
  143. font-weight: bold;
  144. }
  145. .text2{
  146. font-size: 32rpx;
  147. font-family: PingFangSC-Regular, PingFang SC;
  148. font-weight: 400;
  149. margin-bottom: 100rpx;
  150. .line{
  151. width: 116rpx;
  152. height: 2rpx;
  153. background-color: $uni-color-primary;
  154. margin-right: 24rpx;
  155. }
  156. }
  157. }
  158. .login-box{
  159. position: relative;
  160. background-color: #fff;
  161. .title{
  162. font-size: 36rpx;
  163. font-family: PingFangSC-Regular, PingFang SC;
  164. font-weight: 400;
  165. color: #333333;
  166. line-height: 50rpx;
  167. }
  168. }
  169. .tip{
  170. position: fixed;
  171. bottom: 108rpx;
  172. width: calc( 100vw - 90rpx );
  173. box-sizing: border-box;
  174. text-align: center;
  175. font-size: 24rpx;
  176. font-weight: 400;
  177. color: #999;
  178. }
  179. </style>