login.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <page-meta :root-font-size="getRootFontSize"></page-meta>
  3. <view class="container" :style="{ backgroundImage: 'url(' + $util.img('public/uniapp/cashier/login_bg.png') + ')' }">
  4. <view class="login-wrap">
  5. <view class="header">
  6. <image class="title" :src="$util.img('public/uniapp/cashier/login_logo.png')" mode="aspectFit"></image>
  7. <!-- <view class="desc">若未注册请先到牛云官网进行注册</view> -->
  8. </view>
  9. <view class="form-wrap">
  10. <view class="input-wrap"><input type="text" @confirm="login" v-model="formData.username" placeholder="请输入用户名" placeholder-class="placeholder" /></view>
  11. <view class="input-wrap">
  12. <input type="text" @confirm="login" v-model="formData.password" placeholder="请输入登录密码" placeholder-class="placeholder" v-show="passShow" />
  13. <input type="password" @confirm="login" v-model="formData.password" placeholder="请输入登录密码" placeholder-class="placeholder" v-show="!passShow" />
  14. <view class="iconfont" :class="{ iconyanjing5: passShow, iconinvisible: !passShow }" @click="passShow = !passShow"></view>
  15. </view>
  16. <view class="input-wrap">
  17. <input type="number" @confirm="login" v-model="formData.vercode" placeholder="请输入验证码" placeholder-class="placeholder" />
  18. <image :src="captcha.img" class="captcha" @click="getCaptcha"></image>
  19. </view>
  20. <button type="default" class="login-btn primary-btn" @click="login">登录</button>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import validate from 'common/js/validate.js';
  27. export default {
  28. data() {
  29. return {
  30. passShow: false,
  31. formData: {
  32. username: '',
  33. password: '',
  34. vercode: '',
  35. dynacode: '',
  36. key: ''
  37. },
  38. captcha: {
  39. id: '',
  40. img: ''
  41. },
  42. isSub: false
  43. };
  44. },
  45. onLoad() {
  46. this.getCaptcha();
  47. },
  48. methods: {
  49. /**
  50. * 获取验证码
  51. */
  52. getCaptcha() {
  53. this.$api.sendRequest({
  54. url: '/storeapi/captcha/captcha',
  55. data: {
  56. captcha_id: this.captcha.id
  57. },
  58. success: res => {
  59. if (res.code >= 0) {
  60. this.captcha = res.data;
  61. this.captcha.img = this.captcha.img.replace(/\r\n/g, '');
  62. }
  63. }
  64. });
  65. },
  66. login() {
  67. var data = {
  68. username: this.formData.username,
  69. password: this.formData.password
  70. };
  71. if (this.captcha.id != '') {
  72. data.captcha_id = this.captcha.id;
  73. data.captcha_code = this.formData.vercode;
  74. }
  75. uni.showLoading({});
  76. if (this.verify(data)) {
  77. if (this.isSub) return;
  78. this.isSub = true;
  79. this.$api.sendRequest({
  80. url: '/cashier/storeapi/login/login',
  81. data,
  82. success: res => {
  83. uni.hideLoading();
  84. if (res.code >= 0) {
  85. uni.setStorageSync('site_id', res.data.site_id);
  86. uni.setStorageSync('store_id', res.data.store_id);
  87. uni.setStorage({
  88. key: 'cashier_token',
  89. data: res.data.token,
  90. success: () => {
  91. this.$store.dispatch('getStoreInfo');
  92. this.$store.dispatch('getUserInfo');
  93. this.$store.dispatch('getUserGroup');
  94. }
  95. });
  96. } else {
  97. this.isSub = false;
  98. this.getCaptcha();
  99. this.$util.showToast({ title: res.message });
  100. }
  101. },
  102. fail: res => {
  103. this.isSub = false;
  104. this.getCaptcha();
  105. }
  106. });
  107. }
  108. },
  109. verify(data) {
  110. var rule = [
  111. { name: 'username', checkType: 'required', errorMsg: '请输入手机号' },
  112. { name: 'password', checkType: 'required', errorMsg: '请输入密码' },
  113. { name: 'captcha_code', checkType: 'required', errorMsg: '请输入验证码' }
  114. ];
  115. var checkRes = validate.check(data, rule);
  116. if (checkRes) {
  117. return true;
  118. } else {
  119. this.$util.showToast({ title: validate.error });
  120. return false;
  121. }
  122. }
  123. },
  124. computed: {
  125. menu() {
  126. return this.$store.state.menu;
  127. }
  128. },
  129. watch: {
  130. menu: function(menu) {
  131. if (menu && menu.length) {
  132. if (menu[0].path) this.$util.redirectTo(menu[0].path, {}, 'redirectTo');
  133. else this.$util.redirectTo('/pages/stat/index', {}, 'redirectTo');
  134. }
  135. }
  136. }
  137. };
  138. </script>
  139. <style lang="scss">
  140. page {
  141. width: 100vw;
  142. height: 100vh;
  143. background: #f7f8fa;
  144. }
  145. .container {
  146. position: absolute;
  147. left: 0;
  148. top: 0;
  149. bottom: 0;
  150. right: 0;
  151. background-size: cover;
  152. background-repeat: no-repeat;
  153. background-position: center;
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. .login-bg {
  158. margin-right: 1.5rem;
  159. width: 5.9rem;
  160. height: 4.3rem;
  161. image {
  162. width: 5.9rem;
  163. height: 4.3rem;
  164. }
  165. }
  166. }
  167. .login-wrap {
  168. padding: 0.3rem 0;
  169. width: 3.48rem;
  170. background-color: #fff;
  171. box-shadow: 0 0.01rem 0.09rem 0 rgba(15, 92, 251, 0.12);
  172. border-radius: 0.05rem;
  173. .header {
  174. text-align: center;
  175. .title {
  176. width: 2.13rem;
  177. height: 0.78rem;
  178. }
  179. .desc {
  180. font-size: 0.16rem;
  181. color: #969799;
  182. margin-top: 0.1rem;
  183. }
  184. }
  185. }
  186. .form-wrap {
  187. display: flex;
  188. flex-direction: column;
  189. align-items: center;
  190. margin-top: 0.3rem;
  191. .input-wrap {
  192. width: 2.85rem;
  193. padding: 0 0.1rem;
  194. border: 0.01rem solid #e6e6e6;
  195. margin-top: 0.25rem;
  196. display: flex;
  197. align-items: center;
  198. box-sizing: border-box;
  199. border-radius: 0.05rem;
  200. input {
  201. flex: 1;
  202. height: 0.4rem;
  203. line-height: 0.4rem;
  204. font-size: $uni-font-size-base;
  205. }
  206. .placeholder {
  207. font-size: $uni-font-size-base;
  208. color: #999999;
  209. font-weight: 500;
  210. }
  211. .send-code {
  212. color: $primary-color;
  213. cursor: pointer;
  214. &.disabled {
  215. cursor: not-allowed;
  216. color: #999;
  217. }
  218. }
  219. .captcha {
  220. width: 0.76rem;
  221. height: 0.3rem;
  222. cursor: pointer;
  223. }
  224. .iconfont {
  225. font-size: 0.14rem;
  226. cursor: pointer;
  227. }
  228. }
  229. .login-btn {
  230. width: 2.85rem;
  231. margin-top: 0.3rem;
  232. height: 0.4rem;
  233. line-height: 0.4rem;
  234. border-radius: 0.05rem;
  235. }
  236. }
  237. .login-action {
  238. margin-top: 0.1rem;
  239. text-align: right;
  240. color: #999;
  241. text {
  242. margin-left: 0.1rem;
  243. cursor: pointer;
  244. }
  245. }
  246. </style>