Login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <home-base :show="false"><view class="div container">
  3. <view class="div common-header-wrap">
  4. <view :style="'height:'+navHeight+'px'"></view>
  5. <view class="common-header-holder"></view>
  6. <view class="common-header-fixed">
  7. <title-header />
  8. <uni-nav-bar title="商家登录" class="common-header">
  9. </uni-nav-bar>
  10. </view>
  11. </view>
  12. <view class="div main-content">
  13. <view class="div top-wrapper">
  14. <view class="div">
  15. <flex-line class="input-wrapper" :show-border="true">
  16. <input class="field-input" v-model="sellername" placeholder="商家账户" />
  17. </flex-line>
  18. </view>
  19. <view class="div">
  20. <flex-line class="input-wrapper" :show-border="true">
  21. <input class="field-input" type="password" v-model="password" placeholder="请输入密码" maxlength="20" />
  22. </flex-line>
  23. </view>
  24. </view>
  25. <view class="div common-btn ds-button-large mt-10 mb-10" @click="signin">登录</view>
  26. </view>
  27. </view></home-base>
  28. </template>
  29. <script>
  30. import {getFontSize} from '@/util/common'
  31. import TitleHeader from '../../TitleHeader'
  32. import HomeBase from '../HomeBase'
  33. import { sellerlogin } from '../../../api/sellerLogin'
  34. import { mapState, mapMutations, mapActions } from 'vuex'
  35. import flexLine from '../../flexLine'
  36. export default {
  37. name: 'login',
  38. mounted(){
  39. // #ifdef MP-WEIXIN
  40. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  41. // #endif
  42. },
  43. data(){
  44. return {
  45. navHeight: 0,
  46. sellername: '',
  47. password: ''
  48. }
  49. },
  50. components:{TitleHeader,HomeBase,flexLine,},
  51. onLoad: function (option) {
  52. uni.hideLoading()
  53. if (option.clear) {
  54. this.sellerLogout()
  55. }
  56. this.fetchConfig({}).then(
  57. response => {
  58. },
  59. error => {
  60. uni.showToast({icon:'none',title: error.message})
  61. }
  62. )
  63. },
  64. computed:{
  65. fontSize(){
  66. return getFontSize()
  67. },
  68. ...mapState({
  69. config: state => state.config.config
  70. }),
  71. },
  72. methods:{
  73. goBack(){uni.navigateBack({delta:1})},
  74. ...mapActions({
  75. fetchConfig: 'fetchConfig'
  76. }),
  77. ...mapMutations({
  78. saveAuthInfo: 'sellerLogin',
  79. sellerLogout: 'sellerLogout'
  80. }),
  81. signin () {
  82. let sellername = this.sellername
  83. let password = this.password
  84. if (sellername.length === 0) {
  85. uni.showToast({icon:'none',title: '请输入用户名/邮箱/手机号'})
  86. return
  87. }
  88. // TODO: 用户名(为手机号或邮箱)校验
  89. if (password.length === 0) {
  90. uni.showToast({icon:'none',title: '请输入密码'})
  91. return
  92. }
  93. if (password.length < 6) {
  94. uni.showToast({icon:'none',title: '至少输入6位密码'})
  95. return
  96. }
  97. uni.showLoading({ title: '加载中' })
  98. sellerlogin(sellername, password).then(
  99. response => {
  100. uni.hideLoading()
  101. this.saveAuthInfo({ token: response.result.token, info: response.result.info })
  102. this.goSellerIndex()
  103. },
  104. error => {
  105. uni.hideLoading()
  106. uni.showToast({icon:'none',title: error.message})
  107. }
  108. )
  109. },
  110. goSellerIndex () {
  111. uni.reLaunch({url:'/pages/seller/index/Index'})
  112. }
  113. }
  114. }
  115. </script>
  116. <style scoped lang='scss'>
  117. .common-header{
  118. .btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
  119. }
  120. .container {
  121. flex: 1;
  122. display: flex;
  123. flex-direction: column;
  124. justify-content: flex-start;
  125. align-items: stretch;
  126. .main-content{background: #fff;padding:0 $pageSpace}
  127. .top-wrapper {
  128. .input-wrapper {
  129. display: flex;
  130. align-content: center;
  131. align-items: center;
  132. padding-left: 0.5rem;
  133. background-color: #fff;
  134. height: 2.2rem;
  135. .img {
  136. width: 1.2rem;
  137. height: 1.2rem;
  138. margin: 0;
  139. padding: 0;
  140. }
  141. input {
  142. flex: 1;
  143. font-size:$subFontSize;
  144. }
  145. .bottom-input {
  146. border-bottom-width: 0;
  147. }
  148. }
  149. }
  150. }
  151. </style>