login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="login">
  3. <view class="login-title">商家登录</view>
  4. <view class="login-input">
  5. <view class="iconfont icon06_huiyuanguanli color-base-text"></view>
  6. <input class="uni-input" placeholder="请输入用户名" v-model="loginList.username" />
  7. </view>
  8. <view class="login-input">
  9. <view class="iconfont iconmima color-base-text"></view>
  10. <input class="uni-input" placeholder="请输入密码" v-model="loginList.password" password="true" />
  11. </view>
  12. <view class="login-input" v-if="captchaConfig == 1">
  13. <view class="iconfont iconyanzhengma1 color-base-text"></view>
  14. <input class="uni-input" placeholder="请输入验证码" type="number" v-model="loginList.vcode" @confirm="login()" />
  15. <image class="code" :src="captcha.img" mode="aspectFit" @click="getImg"></image>
  16. </view>
  17. <button type="primary" @click="login()">登录</button>
  18. <loading-cover ref="loadingCover"></loading-cover>
  19. </view>
  20. </template>
  21. <script>
  22. import validate from '@/common/js/validate.js';
  23. export default {
  24. data() {
  25. return {
  26. loginList: {
  27. username: '',
  28. password: '',
  29. vcode: ''
  30. },
  31. captchaConfig: 1,
  32. captcha: {
  33. id: '',
  34. img: ''
  35. },
  36. back: '', // 返回页
  37. redirect: 'redirectTo' // 跳转方式
  38. };
  39. },
  40. onLoad(option) {
  41. //防止开店过程中非法退出
  42. if (uni.getStorageSync('token')) uni.removeStorageSync('token');
  43. if (uni.getStorageSync('site_id')) uni.removeStorageSync('site_id');
  44. this.back = option.back || '';
  45. this.getCaptchaConfig();
  46. },
  47. methods: {
  48. //点击刷新验证码
  49. getImg() {
  50. this.getCodeImg();
  51. },
  52. //获取验证码配置
  53. getCaptchaConfig() {
  54. this.$api.sendRequest({
  55. url: '/shopapi/config/captchaConfig',
  56. data: {},
  57. success: res => {
  58. if (res.code >= 0 && res.data) {
  59. this.captchaConfig = res.data.shop_login;
  60. if (this.captchaConfig == 1) this.getCodeImg();
  61. else if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
  62. }
  63. }
  64. });
  65. },
  66. //获取验证码
  67. getCodeImg() {
  68. this.$api.sendRequest({
  69. url: '/shopapi/captcha/captcha',
  70. data: {
  71. captcha_id: this.captcha.id
  72. },
  73. success: res => {
  74. if (res.code >= 0 && res.data) {
  75. this.captcha = res.data;
  76. this.captcha.img = this.captcha.img.replace(/\r\n/g, '');
  77. }
  78. if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
  79. }
  80. });
  81. },
  82. //点击登录
  83. login() {
  84. if (this.vertify()) {
  85. this.$api.sendRequest({
  86. url: '/shopapi/login/login',
  87. data: {
  88. captcha_id: this.captcha.id,
  89. username: this.loginList.username,
  90. password: this.loginList.password,
  91. captcha_code: this.loginList.vcode
  92. },
  93. success: res => {
  94. if (res.code >= 0) {
  95. this.$util.showToast({
  96. title: '登录成功'
  97. });
  98. uni.setStorageSync('token', res.data.token);
  99. uni.setStorageSync('site_id', res.data.site_id);
  100. if (res.data.site_id > 0) {
  101. if (this.back != '') {
  102. this.$util.redirectTo(decodeURIComponent(this.back), {}, this.redirect);
  103. } else {
  104. this.$util.redirectTo('/pages/index/index', {}, this.redirect);
  105. }
  106. } else {
  107. this.getShopStatus();
  108. }
  109. } else {
  110. this.getImg();
  111. this.$util.showToast({
  112. title: res.message
  113. });
  114. }
  115. }
  116. });
  117. }
  118. },
  119. //获取店铺状态
  120. getShopStatus() {
  121. this.$api.sendRequest({
  122. url: '/shopapi/apply/index',
  123. success: res => {
  124. var data = res.data;
  125. if (res.code == 0 && data) {
  126. if (res.data.procedure == 1) {
  127. this.$util.redirectTo('/pages/apply/mode', {}, 'reLaunch');
  128. } else {
  129. this.$util.redirectTo('/pages/apply/audit', {}, 'reLaunch');
  130. }
  131. }
  132. }
  133. });
  134. },
  135. //表单验证
  136. vertify() {
  137. let rule = [];
  138. // 账号验证
  139. rule = [{ name: 'username', checkType: 'required', errorMsg: '请输入用户名' }, { name: 'password', checkType: 'required', errorMsg: '请输入密码' }];
  140. if (this.captchaConfig == 1 && this.captcha.id != '') rule.push({ name: 'vcode', checkType: 'required', errorMsg: '请输入验证码' });
  141. var checkRes = validate.check(this.loginList, rule);
  142. if (checkRes) {
  143. return true;
  144. } else {
  145. this.$util.showToast({ title: validate.error });
  146. return false;
  147. }
  148. }
  149. }
  150. };
  151. </script>
  152. <style lang="scss">
  153. page {
  154. background-color: #fff;
  155. }
  156. .login {
  157. margin: 0 60rpx 0;
  158. padding-top: 180rpx;
  159. .login-title {
  160. font-size: 60rpx;
  161. font-weight: 500;
  162. display: inline-block;
  163. margin-bottom: 50rpx;
  164. }
  165. .login-input {
  166. display: flex;
  167. height: 70rpx;
  168. margin: 50rpx auto 0;
  169. align-items: center;
  170. justify-content: center;
  171. border-bottom: 1px solid $color-line;
  172. border-radius: 10rpx;
  173. padding: 6rpx 10rpx;
  174. .iconfont {
  175. font-size: 40rpx;
  176. }
  177. .uni-input {
  178. flex: 1;
  179. margin-left: $margin-updown;
  180. }
  181. .code {
  182. width: 150rpx;
  183. height: 70rpx;
  184. }
  185. }
  186. button {
  187. margin: 180rpx auto 0;
  188. }
  189. .login-text {
  190. text-align: center;
  191. margin: 50rpx auto 0;
  192. color: $color-tip;
  193. }
  194. }
  195. </style>