login.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view class="container-wrap my-fade-in" :style="{background: 'url(' + loginBg + ')'}">
  3. <uni-status-bar></uni-status-bar>
  4. <u-top-tips ref="uTips"></u-top-tips>
  5. <view class="container my-flex">
  6. <!-- 登录表单 -->
  7. <view class="form-wrap flex-column-center">
  8. <view class="logo-wrap my-flex">
  9. <view class="logo">
  10. <image src="../../static/images/LOGO.png" mode=""></image>
  11. </view>
  12. </view>
  13. <view class="form">
  14. <u-form :model="form" ref="uForm">
  15. <u-form-item :border-bottom="false" prop="account">
  16. <u-input style="font-size: 30rpx;" :accountIcon="true" height="72" :border="true" placeholder="请输入账号" v-model="form.account" />
  17. </u-form-item>
  18. <u-form-item :border-bottom="false" style="position: relative;" prop="password">
  19. <u-input @confirm="handleSubmit" style="font-size: 30rpx;" type="password" :border="true" placeholder="请输入密码" height="72" v-model="form.password"/>
  20. <!-- <span class="forget my-fontsize-Small" @tap="toggleForget">忘记密码</span> -->
  21. </u-form-item>
  22. <!-- <u-form-item :border-bottom="false" v-if="isDev">
  23. <u-input style="font-size: 24rpx;" height="72" :border="true" placeholder="请输入IP" v-model="ip" />
  24. </u-form-item> -->
  25. <u-form-item :border-bottom="false">
  26. <u-button throttleTime="300" type="primary" style="width: 100%;margin-top: 30rpx;" @click="login">立即登录</u-button>
  27. </u-form-item>
  28. <u-form-item :border-bottom="false" style="margin-top: 70rpx;">
  29. <u-checkbox-group @change="checkboxGroupChange">
  30. <u-checkbox v-model="remember">记住用户名</u-checkbox>
  31. </u-checkbox-group>
  32. </u-form-item>
  33. </u-form>
  34. </view>
  35. <view class="bottom-pic-wrap flex-column-center">
  36. <view class="bottom-pic">
  37. <image src="../../static/images/login-pic.png" mode="heightFix"></image>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="version" v-if="$storage.getStorageSync('version')">
  42. v{{ $storage.getStorageSync('version') || plus.runtime.version }}
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import loginBg from '@/static/images/login-bg.png'
  49. import { mapActions } from 'vuex'
  50. import config from '@/libs/config/config.js'
  51. export default {
  52. data() {
  53. return {
  54. loginBg,
  55. ip: '',
  56. remember: true,
  57. form: {
  58. account: '',
  59. password: '',
  60. mobileId: '_mobileId'
  61. },
  62. rules: {
  63. account: [
  64. {
  65. required: true,
  66. message: '账号不能为空',
  67. // 可以单个或者同时写两个触发验证方式
  68. trigger: ['blur']
  69. },
  70. {
  71. pattern: /^[0-9a-zA-Z]*$/g,
  72. // 正则检验前先将值转为字符串
  73. transform(value) {
  74. return String(value);
  75. },
  76. message: '只能包含字母或数字',
  77. trigger: ['change']
  78. }
  79. ],
  80. password: [
  81. {
  82. required: true,
  83. message: '密码不能为空',
  84. // 可以单个或者同时写两个触发验证方式
  85. trigger: ['blur']
  86. }
  87. ]
  88. }
  89. };
  90. },
  91. methods: {
  92. ...mapActions({
  93. setToken: 'user/setToken',
  94. setUserInfo: 'user/setUserInfo'
  95. }),
  96. handleSubmit() {
  97. this.login()
  98. },
  99. login() {
  100. this.$utils.formValidate(this.$refs.uForm).then(() => {
  101. this.$http.Login(this.form).then(res => {
  102. console.log(res)
  103. if(res.code === 0) {
  104. this.$storage.setStorageSync('token',res.result.token)
  105. this.saveUserInfo()
  106. }
  107. })
  108. })
  109. },
  110. // 获取并保存用户信息到本地
  111. saveUserInfo() {
  112. this.$http.GetUserInfo().then(res => {
  113. console.log(res)
  114. if(res.code == 0){
  115. this.setUserInfo(res.result)
  116. this.$storage.setStorageSync('userInfo', res.result)
  117. this.$utils.openNew('/pages/index/index')
  118. }
  119. })
  120. },
  121. checkboxGroupChange() {},
  122. toggleForget() {}
  123. },
  124. onLoad() {
  125. this.form.account = this.userInfo.account
  126. this.$utils.updateVersion()
  127. },
  128. onReady() {
  129. this.$refs.uForm.setRules(this.rules);
  130. },
  131. computed: {
  132. // 测试环境下显示ip输入
  133. isDev() {
  134. if(process.env.NODE_ENV === 'development') {
  135. return true
  136. }else {
  137. return false
  138. }
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. @import '../../static/css/mycss.scss';
  145. @import '../../static/css/animate.css';
  146. /deep/ .u-select__body__picker-view__item {
  147. .u-line-1 {
  148. font-size: 46rpx;
  149. }
  150. }
  151. /deep/ .u-select__header__btn {
  152. font-size: 46rpx;
  153. }
  154. /deep/ .u-drawer-content {
  155. border-radius: 20rpx 20rpx 0 0;
  156. }
  157. .container-wrap {
  158. width: 750rpx;
  159. .container {
  160. height: calc(100vh - var(--status-bar-height));
  161. .form-wrap {
  162. position: relative;
  163. width: 620rpx;
  164. height: 85vh;
  165. border-radius: 20rpx;
  166. background: #FFFFFF;
  167. box-shadow:0 5px 10px #383838;
  168. .logo-wrap {
  169. flex: 1;
  170. width: 100%;
  171. .logo {
  172. width: 250rpx;
  173. min-width: 250rpx;
  174. height: 100rpx;
  175. }
  176. }
  177. .form {
  178. flex: 1;
  179. padding: 0 50rpx;
  180. width: 100%;
  181. .forget {
  182. position: absolute;
  183. bottom: -30rpx;
  184. right: 0;
  185. color: #666666;
  186. }
  187. }
  188. .bottom-pic-wrap {
  189. flex: 1;
  190. width: 100%;
  191. .bottom-pic {
  192. height: 80%;
  193. min-height: 250rpx;
  194. // width: 311rpx;
  195. // height: 315rpx;
  196. }
  197. }
  198. }
  199. .forget-wrap {
  200. position: relative;
  201. width: 580rpx;
  202. height: 620rpx;
  203. box-shadow:0 5px 10px #383838;
  204. border-radius: 20rpx;
  205. background: #fff;
  206. .close-icon-wrap {
  207. position: absolute;
  208. top: 18rpx;
  209. right: 18rpx;
  210. .close-icon {
  211. width: 50rpx;
  212. height: 50rpx;
  213. }
  214. }
  215. .gantanhao-wrap {
  216. padding-top: 120rpx;
  217. .gantanhao {
  218. width: 200rpx;
  219. height: 160rpx;
  220. }
  221. }
  222. .text {
  223. padding-top: 75rpx;
  224. text-align: center;
  225. color: #333;
  226. .phone {
  227. color: rgb(200, 60, 160);
  228. font-weight: bold;
  229. }
  230. }
  231. }
  232. }
  233. .version {
  234. position: fixed;
  235. bottom: 0;
  236. left: 0;
  237. width: 100%;
  238. padding: 10rpx 0;
  239. text-align: center;
  240. }
  241. }
  242. </style>