login-app.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div class="login">
  3. <div class="login-form">
  4. <div class="title">密码登录</div>
  5. <div class="form-input">
  6. <van-field
  7. class="input-item"
  8. readonly
  9. clickable
  10. input-align="right"
  11. name="datetimePicker"
  12. v-model="userTypeName"
  13. label="用户类型"
  14. placeholder="请选择用户类型"
  15. @click="showPicker = true"
  16. />
  17. <van-popup v-model="showPicker" position="bottom">
  18. <van-picker
  19. confirm-button-text="确认"
  20. cancel-button-text="取消"
  21. title="用户类型"
  22. show-toolbar
  23. default-index="100"
  24. :columns="userTypes"
  25. @confirm="(value) => onConfirm(value)"
  26. @cancel="showPicker = false"
  27. />
  28. </van-popup>
  29. </div>
  30. <div v-if="userType == '1'">
  31. <div class="form-input">
  32. <input type="text" placeholder="请输入用户名" v-model="account"/>
  33. </div>
  34. <div class="form-input">
  35. <input type="password" placeholder="请输入密码" v-model="password"/>
  36. <p class="right" @click="bizPass">忘记密码</p>
  37. </div>
  38. </div>
  39. <div v-if="userType == '2'">
  40. <div class="form-input">
  41. <p class="left">
  42. <span> +86 </span>
  43. <span>
  44. <i class="iconfont icon-zuo"></i>
  45. </span>
  46. </p>
  47. <input type="text" placeholder="请输入手机号" v-model="account"/>
  48. </div>
  49. <div class="form-input">
  50. <input type="password" placeholder="请输入密码" v-model="password"/>
  51. <p class="right" @click="$router.push({path:'/forgetPassword',query:{type:'1'}})">忘记密码</p>
  52. </div>
  53. </div>
  54. </div>
  55. <div class="login-button">
  56. <p>
  57. <button class="but-type1" type="info" @click="loginMain">登录</button>
  58. </p>
  59. <p v-if="userType == '2'">
  60. <button class="but-type2" @click="userRegister()">去注册</button>
  61. </p>
  62. </div>
  63. <div class="foot-pact" v-show="isOriginHei">
  64. <div class="check">
  65. <van-checkbox
  66. checked-color="#2A3980"
  67. v-model="checked"
  68. ></van-checkbox>
  69. </div>
  70. <div class="text1">已阅读并同意</div>
  71. <div class="text2" @click="$router.push('/term')">《服务协议条款及隐私条款》</div>
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. import { mapActions } from 'vuex'
  77. import { login } from '../service/api_user.js'
  78. import { Toast } from 'vant'
  79. import auth from '@/service/auth'
  80. export default {
  81. data() {
  82. return {
  83. checked: false,
  84. showPicker: false,
  85. userType: '2',
  86. userTypeName: '个人用户',
  87. userTypes: [
  88. {
  89. text: '企业用户',
  90. value: '1'
  91. },
  92. {
  93. text: '个人用户',
  94. value: '2'
  95. }
  96. ],
  97. account: '',
  98. password: '',
  99. isOriginHei: true,
  100. screenHeight: document.documentElement.clientHeight, // 此处也可能是其他获取方法
  101. originHeight: document.documentElement.clientHeight
  102. }
  103. },
  104. mounted() {
  105. console.log('_this.$router_:', this.$router)
  106. const self = this
  107. window.onresize = function() {
  108. return (function() {
  109. self.screenHeight = document.documentElement.clientHeight
  110. })()
  111. }
  112. if (window.history && window.history.pushState && window.history.state.url != document.URL) {
  113. var state = { title: 'title', url: document.URL }
  114. window.history.pushState(state, 'title', '#')
  115. // history.pushState(null, null, document.URL)
  116. // window.addEventListener('popstate', this.goBack, false)
  117. }
  118. },
  119. destroyed() {
  120. // window.removeEventListener('popstate', this.goBack, false)
  121. },
  122. watch: {
  123. screenHeight(val) {
  124. if (this.originHeight > val + 100) {
  125. // 加100为了兼容华为的返回键
  126. this.isOriginHei = false
  127. } else {
  128. if (this.userType == '1') {
  129. this.isOriginHei = false
  130. } else {
  131. this.isOriginHei = true
  132. }
  133. }
  134. }
  135. },
  136. methods: {
  137. ...mapActions({ login: 'user/login' }),
  138. loginMain() {
  139. const _this = this
  140. if (!this.account || !this.password) {
  141. Toast('请填写账号和密码')
  142. return false
  143. }
  144. if (this.userType == '2' && this.checked === false) {
  145. Toast('请阅读并同意服务协议条款及隐私条款')
  146. return false
  147. }
  148. this.$auth.setUserType(this.$auth.TYPE_USER)
  149. login({
  150. userType: this.userType,
  151. userName: this.account,
  152. password: this.password,
  153. code: '',
  154. type: this.$auth.TYPE_USER
  155. }).then((res) => {
  156. if (res.errno === 0 && res.data) {
  157. _this.login(res.data)
  158. _this.$router.push({ path: '/home-app' })
  159. if (window.history && window.history.length > 1) {
  160. // window.history.back()
  161. // window.history.back()
  162. } else {
  163. // _this.$router.push({ path: '/home' })
  164. }
  165. } else {
  166. Toast(res.errmsg)
  167. }
  168. })
  169. },
  170. goBack() {
  171. // console.log("点击了浏览器的返回按钮");
  172. // history.pushState(null, null, document.URL)
  173. },
  174. userRegister() {
  175. // wx.miniProgram.navigateTo({ url: '/pages/userInfo/user' })
  176. this.$router.replace('/register')
  177. },
  178. onConfirm(value) {
  179. this.userType = value.value
  180. this.userTypeName = value.text
  181. this.showPicker = false
  182. if (this.userType == '1') {
  183. this.isOriginHei = false
  184. } else {
  185. this.isOriginHei = true
  186. }
  187. },
  188. bizPass() {
  189. Toast('请联系园区管理员')
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. .login {
  196. width: 100%;
  197. height: 100vh;
  198. background: #fff;
  199. overflow: hidden;
  200. background-size: 100% 100%;
  201. padding: 150px 40px 40px;
  202. box-sizing: border-box;
  203. .login-form {
  204. .title {
  205. font-size: 32px;
  206. color: $text1;
  207. font-weight: 700;
  208. margin-bottom: 120px;
  209. }
  210. .form-input {
  211. margin-top: 20px;
  212. border-bottom: 1px solid #f2f2f2;
  213. padding: 0 30px;
  214. @include fj;
  215. .left {
  216. @include fj;
  217. width: 140px;
  218. font-size: 28px;
  219. color: $text3;
  220. align-items: center;
  221. span {
  222. flex: 1;
  223. text-align: center;
  224. i {
  225. font-size: 28px;
  226. color: $color1;
  227. }
  228. }
  229. }
  230. .right {
  231. padding-left: 40px;
  232. font-size: 24px;
  233. color: $text1;
  234. line-height: 80px;
  235. }
  236. input {
  237. flex: 1;
  238. font-size: 24px;
  239. color: $text1;
  240. line-height: 80px;
  241. }
  242. input::-webkit-input-placeholder {
  243. color: $text2;
  244. }
  245. }
  246. }
  247. .login-button {
  248. margin-top: 230px;
  249. width: 100%;
  250. p {
  251. margin: 20px 0;
  252. }
  253. }
  254. .foot-pact {
  255. position: absolute;
  256. bottom: 30px;
  257. padding: 0 85px;
  258. @include fj;
  259. .check {
  260. margin-right: 10px;
  261. /deep/ .van-icon {
  262. font-size: 30px;
  263. }
  264. }
  265. .text1 {
  266. font-size: 20px;
  267. color: $text3;
  268. line-height: 45px;
  269. }
  270. .text2 {
  271. font-size: 20px;
  272. color: $main;
  273. line-height: 45px;
  274. }
  275. }
  276. }
  277. </style>