index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class=" login-confg u-flex f-d-c ">
  3. <view class="logo-back u-flex u-row-center u-col-bottom">
  4. <view class="logo"><u-image width="102" height="102" :src="icon.homelogo"></u-image></view>
  5. </view>
  6. <view style="margin-top: 208rpx;" class="u-flex u-d-c">
  7. <view class="loin-from u-p-l-26 u-p-r-26 ">
  8. <u-form :error-type="['toast']" :model="form" ref="uForm">
  9. <u-form-item :left-icon="icon.phone" prop="telephone" :left-icon-style="{ width: '33rpx', height: '33rpx', position: 'relative', top: '8rpx', marginRight: '66rpx' }"><u-input placeholder="请输入账号" v-model="form.telephone" /></u-form-item>
  10. <u-form-item :left-icon="icon.pwd" prop="name" :left-icon-style="{ width: '33rpx', height: '33rpx', position: 'relative', top: '8rpx', marginRight: '66rpx' }"><u-input placeholder="请输入密码" type="password" v-model="form.password" /></u-form-item>
  11. <u-form-item prop="identify">
  12. <view style="display: flex; align-items: center; justify-content: space-between;">
  13. <u-input style="flex1" placeholder="请输入验证码" v-model="form.identify" />
  14. <image :src="codeSrc" style="width: 200rpx; height:60rpx;" @click="getCode()"></image>
  15. </view>
  16. </u-form-item>
  17. </u-form>
  18. <!-- <navigator hover-class="none" url="../forgetpwd/index" class="no-pwd u-m-t-14 u-p-b-40 no-pwd">忘记密码?</navigator> -->
  19. <button class="login_btn u-m-t-40 u-" @click="submit">登录</button>
  20. </view>
  21. <!-- <view class="u-m-40 u-p-t-40" >
  22. <u-divider bg-color="rgba(0,0,0,0)" fontSize="28rpx">微信登录</u-divider>
  23. </view> -->
  24. <!-- <view class="u-flex wxlogoin" @click="wechatlogin">
  25. <view class="logoicon"><u-icon name="weixin-fill" color="#ffffff" size="60"></u-icon></view>
  26. </view> -->
  27. </view>
  28. <u-toast ref="lToast"></u-toast>
  29. </view>
  30. </template>
  31. <script>
  32. import md5 from 'js-md5';
  33. import phone from '@/static/img/phone.png';
  34. import password from '@/static/img/password.png';
  35. import homelogo from '@/static/img/homelogo.png';
  36. import { login, code } from '@/api/index.js';
  37. export default {
  38. data() {
  39. return {
  40. codeSrc: '',
  41. code: '', // 正确的验证码
  42. form: {
  43. telephone: undefined,
  44. password: undefined,
  45. identify: undefined
  46. },
  47. rules: {
  48. telephone: [
  49. {
  50. required: true,
  51. message: '请输入账号',
  52. trigger: ['change', 'blur']
  53. }
  54. ],
  55. password: [
  56. {
  57. required: true,
  58. message: '请输入密码',
  59. trigger: ['change', 'blur']
  60. }
  61. ],
  62. identify: [
  63. {
  64. required: true,
  65. message: '请输入验证码',
  66. trigger: ['change', 'blur']
  67. }
  68. ]
  69. },
  70. icon: {
  71. phone: phone,
  72. pwd: password,
  73. homelogo: homelogo
  74. }
  75. };
  76. },
  77. mounted() {
  78. this.getCode();
  79. },
  80. methods: {
  81. getCode() {
  82. code().then(reponse => {
  83. console.log(reponse);
  84. const { code, message, data } = reponse;
  85. if (code == 200) {
  86. this.codeSrc = data.image;
  87. this.code = data.code;
  88. } else {
  89. this.$u.toast(message);
  90. }
  91. });
  92. },
  93. wechatlogin() {
  94. uni.navigateTo({
  95. url: '../../writeoff/register/register'
  96. });
  97. },
  98. async submit() {
  99. let { telephone, password } = this.form;
  100. let username = String(telephone);
  101. password = md5(`${password}`);
  102. password = String(password);
  103. this.$refs.uForm.validate((valid, e) => {
  104. if (valid) {
  105. if (this.form.identify == this.code) {
  106. login({
  107. username,
  108. password,
  109. code: this.form.identify
  110. }).then(reponse => {
  111. const { code, message, data } = reponse;
  112. if (code == 200) {
  113. uni.setStorageSync('token', data.token);
  114. uni.setStorageSync('user', data);
  115. uni.switchTab({
  116. url: '../../../pages/onsitpection/home/index'
  117. });
  118. } else {
  119. this.$u.toast(message);
  120. }
  121. });
  122. } else {
  123. this.$u.toast('验证码错误');
  124. }
  125. } else {
  126. console.log('验证失败', valid, e);
  127. }
  128. });
  129. }
  130. },
  131. onReady() {
  132. this.$refs.uForm.setRules(this.rules);
  133. }
  134. };
  135. </script>
  136. <style lang="scss">
  137. page {
  138. width: 100%;
  139. height: 100%;
  140. }
  141. .login-confg {
  142. width: 100%;
  143. height: 100%;
  144. .logo-back {
  145. width: 100%;
  146. height: 444rpx;
  147. position: relative;
  148. z-index: -1;
  149. &::after {
  150. content: '';
  151. width: 140%;
  152. height: 444rpx;
  153. position: absolute;
  154. left: -20%;
  155. top: 0;
  156. z-index: -1;
  157. border-radius: 0 0 45% 45%;
  158. background: #1496f1;
  159. }
  160. .logo {
  161. width: 168rpx;
  162. height: 168rpx;
  163. background: #ffffff;
  164. box-shadow: 0px 13rpx 46rpx 0rpx rgba(120, 103, 255, 0.16);
  165. border-radius: 32rpx;
  166. position: relative;
  167. top: 94rpx;
  168. padding: 34rpx;
  169. }
  170. }
  171. }
  172. .loin-from {
  173. width: 610rpx;
  174. color: rgba(80, 80, 80, 1);
  175. background-color: rgba(255, 255, 255, 1);
  176. font-size: 14px;
  177. text-align: center;
  178. .u-form-item {
  179. padding: 10rpx !important;
  180. }
  181. .no-pwd {
  182. font-size: 28rpx;
  183. font-weight: 400;
  184. color: #4a8bff;
  185. }
  186. }
  187. .u-d-c {
  188. flex-direction: column;
  189. }
  190. .login_btn {
  191. width: 100%;
  192. height: 79rpx;
  193. background: #4a8bff;
  194. box-shadow: 0px 17rpx 40rpx 0px rgba(123, 102, 255, 0.22);
  195. border-radius: 40rpx;
  196. font-size: 30rpx;
  197. font-family: inpinheiti;
  198. font-weight: 400;
  199. color: #ffffff;
  200. line-height: 79rpx;
  201. }
  202. .no-pwd {
  203. color: rgba(166, 166, 166, 1);
  204. font-size: 28rpx;
  205. text-align: left;
  206. }
  207. .wxlogoin {
  208. .logoicon {
  209. width: 83rpx;
  210. height: 83rpx;
  211. background: #04be02;
  212. border-radius: 50%;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. }
  217. }
  218. </style>