Login.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div>
  3. <common @asynCallBack="asynCallBack"></common>
  4. <top-header :pageTitle="pageTitle" :leftShow="false"></top-header>
  5. <div class="mui-content">
  6. <div class="mui-content-padded">
  7. <div class="vongi-login-logo">
  8. <img src="~$project/assets/img/logo_xiaopengguanjia.png" />
  9. <h2>小鹏管家</h2>
  10. </div>
  11. <form class="mui-input-group vongi-login-form">
  12. <!-- <div class="mui-input-row">
  13. <input name="name" v-model="subForm.name" type="text" class="mui-input-clear" placeholder="请填写您的姓名">
  14. </div> -->
  15. <div class="mui-input-row">
  16. <input name="phone" v-model="subForm.phone" type="text" class="mui-input-clear" placeholder="请输入手机号码">
  17. </div>
  18. <div class="mui-input-row">
  19. <input v-model="verifyCode" type="text" class="mui-input-clear" placeholder="请输入验证码">
  20. <a @click="findByNameAndPhone" v-html="sendMsgWz"></a>
  21. </div>
  22. </form>
  23. <form class="mui-input-group vongi-xieyi">
  24. <div class="mui-input-row mui-radio mui-left">
  25. <label class="mui-h6">我已阅读并同意<span class="color4fc5f7">《用户使用协议》</span></label>
  26. <input name="radio1" type="radio">
  27. </div>
  28. </form>
  29. </div>
  30. <div class="vongi-btn vongi-login-btn">
  31. <button class="mui-btn mui-btn-primary" @click="nextStep">
  32. 注册/登录
  33. </button>
  34. </div>
  35. </div>
  36. <loading :visible="isLoading"></loading>
  37. </div>
  38. </template>
  39. <script>
  40. import * as API_Person from '@/apis/person'
  41. import * as API_Common from '@/apis/common'
  42. import Common from '$project/components/Common.vue'
  43. import Loading from '$project/components/Loading.vue'
  44. import TopHeader from '$project/components/TopHeader.vue'
  45. import {
  46. mapGetters,
  47. mapMutations
  48. } from 'vuex'
  49. import {
  50. checkPhone,
  51. } from '$project/utils'
  52. import * as types from '$project/store/mutation-types'
  53. export default {
  54. name: 'UserLogin',
  55. components: {
  56. Common,
  57. Loading,
  58. TopHeader
  59. },
  60. data() {
  61. return {
  62. pageTitle: '登录账号',
  63. subForm: {
  64. name: '',
  65. phone: '',
  66. },
  67. personId: '',
  68. verifyCode: '',
  69. sendMsgWz: '发送验证码',
  70. isLoading: false,
  71. project: this.$route.query.project,
  72. }
  73. },
  74. created() {
  75. //设置默认值,退出帐号后进入登录页面,输入框中保留上次登录时的姓名和手机号信息;
  76. if (this.person_temp) {
  77. this.subForm.name = this.person_temp.name;
  78. this.subForm.phone = this.person_temp.phone;
  79. }
  80. },
  81. methods: {
  82. //表单检测
  83. checkForm() {
  84. let phoneResult = checkPhone(this.subForm.phone);
  85. if (typeof phoneResult == 'string') {
  86. mui.toast(phoneResult);
  87. return false;
  88. } else {
  89. return true;
  90. }
  91. },
  92. //根据用户名和手机号查询人员信息
  93. findByNameAndPhone() {
  94. if (this.checkForm()) {
  95. this.isLoading = true;
  96. API_Person.findByNameAndPhone(this.subForm).then(response => {
  97. this.isLoading = false;
  98. this.personId = response;
  99. this.sendMsg();
  100. }).catch(error => {
  101. this.isLoading = false;
  102. mui.toast(error);
  103. })
  104. }
  105. },
  106. //发送验证码
  107. sendMsg() {
  108. this.isLoading = true;
  109. API_Common.sendMsg({
  110. personId: this.personId,
  111. telephone: this.subForm.phone,
  112. }).then(response => {
  113. //倒计时
  114. this.msgTimeInterval();
  115. this.isLoading = false;
  116. }).catch(error => {
  117. this.isLoading = false;
  118. mui.toast(error);
  119. })
  120. },
  121. //倒计时
  122. msgTimeInterval() {
  123. var time = 60;
  124. var _this = this;
  125. this.timer = setInterval(() => {
  126. if (time > 0) {
  127. _this.sendMsgWz = time-- + '秒';
  128. } else {
  129. _this.isSendMsg = true;
  130. _this.sendMsgWz = '发送验证码';
  131. clearInterval(_this.timer)
  132. }
  133. }, 1000)
  134. },
  135. //下一步
  136. nextStep() {
  137. if (!this.verifyCode) {
  138. mui.toast('请获取并填写验证码');
  139. } else {
  140. this.isLoading = true;
  141. API_Person.validateCode({
  142. personId: this.personId,
  143. verifyCode: this.verifyCode,
  144. openId: this.openId,
  145. telephone: this.subForm.phone,
  146. }).then(response => {
  147. if (response.token) {
  148. this.set_token(response.token);
  149. if (response.personInfo.faceImageUrl) {
  150. //跳转到项目主页上去
  151. window.location.href = '../' + this.project + '/#/master';
  152. } else {
  153. //上传头像
  154. this.$router.push({
  155. name: 'UserUploadPhoto',
  156. query: {
  157. personId: this.personId,
  158. project: this.project
  159. }
  160. })
  161. }
  162. } else {
  163. //注册
  164. this.confirmRegister();
  165. }
  166. this.isLoading = false;
  167. }).catch(error => {
  168. this.isLoading = false;
  169. mui.toast(error);
  170. })
  171. }
  172. },
  173. //注册
  174. confirmRegister() {
  175. var _this = this;
  176. var btnArray = ['否', '是'];
  177. mui.confirm('当前用户不存在,是否立即注册?', '提示', btnArray, function(e) {
  178. if (e.index == 1) {
  179. _this.$router.push({
  180. name: 'RegisterHome',
  181. query: {
  182. telephone: _this.subForm.phone,
  183. project: this.$route.query.project
  184. }
  185. })
  186. }
  187. })
  188. },
  189. //注册
  190. register() {
  191. this.$router.push({
  192. name: 'RegisterHome',
  193. query: {}
  194. })
  195. },
  196. asynCallBack() {
  197. },
  198. ...mapMutations({
  199. set_token: types.SET_TOKEN,
  200. })
  201. },
  202. mounted() {
  203. document.body.style.backgroundColor = '#fff';
  204. },
  205. destroyed() {
  206. document.body.style.backgroundColor = '';
  207. },
  208. computed: {
  209. ...mapGetters({
  210. openId: 'wx_openid',
  211. token: 'token',
  212. person_data: 'person_data',
  213. person_popedom: 'person_popedom',
  214. person_temp: 'person_temp'
  215. })
  216. }
  217. }
  218. </script>
  219. <style src="$project/assets/css/iconfont.css"></style>
  220. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  221. <style scoped>
  222. </style>