login.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. (function() {
  2. Vue.component('login-form', {
  3. template: `<div><div class="container-fluid">
  4. <div class="container" id="head">
  5. <div class="ptb30 top-banner">
  6. <img src="../../../images/LOGO.png"/>
  7. <span class="qr-container">
  8. <img src="../../../images/qr_code.png" class="qr_code" />
  9. <p class="c-f12 text-center c-909090" style="padding-top:5px">下载APP</p>
  10. </span>
  11. </div>
  12. </div>
  13. </div>
  14. <div class="container-fluid chahua-bg">
  15. <div class="chahua container">
  16. <div class="loginForm fr" :class="{'loginForm-active':!registerFlag}">
  17. <div class="tabs-container no-borders mtb20 plr30">
  18. <ul class="nav nav-tabs c-border-b">
  19. <li :class="{'active': type==1}" @click="changeType(1)">
  20. <a style="padding:10px 0px;margin-left:35px;margin-right: 35px;font-size: 20px;">密码登录</a>
  21. </li>
  22. <li :class="{'active': type==2}" @click="changeType(2)">
  23. <a style="padding:10px 0px;margin-left:25px;margin-right: 25px;font-size: 20px;">验证码登录</a>
  24. </li>
  25. </ul>
  26. <div class="tab-content">
  27. <div class="tab-pane" :class="{'active': type==1}">
  28. <div class="panel-body no-borders" style="padding: 0px;">
  29. <form id="form1" class="m-t" role="form" onsubmit="return false;">
  30. <div class="form-group">
  31. <input class="form-control" type="text" v-model="account" placeholder="请输入身份证号或者手机号码">
  32. </div>
  33. <div class="form-group">
  34. <input class="form-control" type="password" v-model="password" placeholder="请输入密码">
  35. </div>
  36. <div class="text-right c-323232" style="margin-top:-10px;">忘记密码</div>
  37. <button type="submit" class="btn btn-theme block full-width m-b" @click="login">登 录</button>
  38. <a type="button" class="btn btn-default block full-width m-b" @click="toggleRegister">注 册</a>
  39. </form>
  40. </div>
  41. </div>
  42. <div class="tab-pane" :class="{'active': type==2}">
  43. <div class="panel-body no-borders" style="padding: 0px;">
  44. <form id="form2" class="m-t" role="form" onsubmit="return false;">
  45. <div class="form-group">
  46. <input class="form-control" type="text" maxlength="11" v-model="mobile" placeholder="请输入手机号码">
  47. </div>
  48. <div class="form-group">
  49. <input class="form-control" type="text" v-model="imgcaptcha" placeholder="请输入图形验证码">
  50. <a class="getCaptcha" :class="{'disabled': countdown}" @click="getCaptcha">{{infoText}}</a>
  51. </div>
  52. <div class="form-group">
  53. <input class="form-control" type="text" v-model="captcha" placeholder="请输入短信验证码">
  54. <a class="getCaptcha" :class="{'disabled': countdown}" @click="getCaptcha">{{infoText}}</a>
  55. </div>
  56. <button type="submit" class="btn btn-theme block full-width m-b" @click="login">登 录</button>
  57. <a type="button" class="btn btn-default block full-width m-b" @click="toggleRegister">注 册</a>
  58. </form>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div></div>`,
  66. props: [],
  67. data: function() {
  68. return {
  69. type: 1, //记录选择的登录方式,1-手机号登录,2-验证码登录
  70. account: '362321199703137824',
  71. mobile: '',
  72. password: '11111111',
  73. imgcaptcha: '',
  74. captcha: '',
  75. infoText: '获取验证码',
  76. countdown: false, //是否在倒计时
  77. codeType: 1,
  78. idCardNo: "350526199501142015",
  79. rPassword: 'a123123',
  80. confirmPassword: "a123123",
  81. toggle: true,
  82. registerFlag: false,
  83. maxLength: 18,
  84. }
  85. },
  86. methods: {
  87. changeType: function(val) {
  88. this.type = val;
  89. },
  90. getCaptcha: function() {
  91. //先校验手机号码是否正确
  92. var isMobile = isMobilePhone(this.mobile);
  93. if(!isMobile) {
  94. alert('请输入正确的手机号码!');
  95. return false;
  96. }
  97. setTimer(this);
  98. //发送请求
  99. // sendToGetCaptcha(this);
  100. },
  101. login: function() {
  102. var vm = this
  103. if(this.type == 1) {
  104. if(!vm.account) {
  105. console.log("账号不能为空!");
  106. return false;
  107. }
  108. if(!vm.password) {
  109. console.log("登录密码不能为空!");
  110. return false;
  111. }
  112. var data = {
  113. grant_type: httpRequest.grant_type,
  114. client_id: httpRequest.client_id,
  115. username: vm.account,
  116. password: vm.password
  117. }
  118. loginAPI.accessToken(data).then(function(oauthInfo) {
  119. sessionStorage.setItem("oauthInfo", JSON.stringify(oauthInfo));
  120. var data1 = {
  121. userName: oauthInfo.user,
  122. accessToken: "token=" + oauthInfo.accessToken
  123. }
  124. loginAPI.getUserInfo(data1).then(function(res) {
  125. console.log("登录成功");
  126. loginedList = [res.telephone]
  127. sessionStorage.setItem("loginedList", JSON.stringify(loginedList));
  128. sessionStorage.setItem("userAgent", JSON.stringify(res));
  129. vm.getJueSeData(res);
  130. }),
  131. function error(xhr, type, errorThrown) {
  132. if(type == "timeout" || type == "abort" || type == "error") {
  133. console.log("账号或密码错误");
  134. }
  135. }
  136. }).catch(function(e) {
  137. console.log("账号或密码错误")
  138. })
  139. } else {
  140. if(!vm.mobile) {
  141. console.log("手机号不能为空!");
  142. return false;
  143. }
  144. if(!vm.imgcaptcha) {
  145. console.log("图形验证码不能为空!");
  146. return false;
  147. }
  148. if(!vm.captcha) {
  149. console.log("手机验证码不能为空!");
  150. return false;
  151. }
  152. }
  153. },
  154. getJueSeData: function(userAgent) {
  155. var vm = this;
  156. //获取居民权限接口
  157. loginAPI.findByUserId({
  158. userId: userAgent.id
  159. }).then(function(data) {
  160. sessionStorage.setItem("roleList", JSON.stringify(data.detailModelList)); //缓存角色列表
  161. // location.href = "../../../home/html/home.html"//跳转到主页面
  162. location.href = "../../../page/mine/html/personal-info.html"
  163. })
  164. },
  165. toggleRegister: function() {
  166. location.href = "../../register/html/register.html"
  167. }
  168. },
  169. watch: {
  170. Password: function(newVal, oldVal) {
  171. var val = newVal.toString();
  172. var reg = /\s+/g; //去除空格
  173. if(reg.test(val)) {
  174. this.Password = oldVal;
  175. }
  176. },
  177. confirmPassword: function(newVal, oldVal) {
  178. var val = newVal.toString();
  179. var reg = /\s+/g; //去除空格
  180. if(reg.test(val)) {
  181. this.confirmPassword = oldVal;
  182. }
  183. },
  184. codeType: function(newVal) {
  185. var vm = this;
  186. var val = newVal.toString();
  187. if(val == 1) {
  188. $("#IDCard").attr("placeholder", "请输入身份证号")
  189. vm.maxLength = 18
  190. } else if(val == 2) {
  191. $("#IDCard").attr("placeholder", "请输入手机号码")
  192. vm.maxLength = 11
  193. }
  194. }
  195. }
  196. })
  197. //验证码定时
  198. function setTimer(vm) {
  199. var seconds = 59;
  200. vm.countdown = true;
  201. timer = setInterval(function() {
  202. if(seconds == 0) {
  203. clearInterval(timer);
  204. timer = null;
  205. seconds = 59;
  206. vm.infoText = "获取验证码";
  207. vm.countdown = false;
  208. return;
  209. }
  210. seconds--;
  211. vm.infoText = seconds + "s后重新获取";
  212. }, 1000)
  213. }
  214. function isCardNo(card, codeType) {
  215. var isidcard = false
  216. if(codeType == 1) { // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
  217. var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  218. if(!reg.test(card)) {
  219. alert("身份证号输入不合法");
  220. } else {
  221. isidcard = true
  222. }
  223. } else {
  224. var reg = /0?(13|14|15|18|17)[0-9]{9}/;
  225. if(!reg.test(card)) {
  226. alert("手机号码输入不合法");
  227. } else {
  228. isidcard = true
  229. }
  230. }
  231. return isidcard
  232. }
  233. function sendToGetCaptcha(vm) {
  234. var url = "common/captcha",
  235. params = {
  236. mobile: vm.mobile,
  237. type: 5,
  238. captchaToken: 5
  239. };
  240. httpRequest.post(url, {
  241. data: params
  242. }).then(function(res) {
  243. if(res.status == 200) {
  244. tip('发送成功', 'add');
  245. } else {
  246. tip('获取验证码失败');
  247. }
  248. });
  249. }
  250. function getPublicKey(vm) {
  251. var url = "login/public_key";
  252. httpRequest.post(url).then(function(res) {
  253. if(res.status) {
  254. var mod = res.data.modulus;
  255. var exp = res.data.exponent;
  256. key = RSAUtils.getKeyPair(exp, "", mod);
  257. if(key) {
  258. encryedPwd = RSAUtils.encryStr(key, vm.password);
  259. login({
  260. mobile: vm.mobile,
  261. password: encryedPwd,
  262. platform: 4
  263. })
  264. } else {
  265. tip("获取数据失败")
  266. $submit.removeAttr('disabled')
  267. }
  268. } else {
  269. tip(res.msg);
  270. }
  271. })
  272. }
  273. function login(data) {
  274. httpRequest.post('login/doctor', {
  275. data: data
  276. }).then(function(res) {
  277. if(res.status == 200) {
  278. var docInfo = res.data;
  279. localoginlStorage.setItem(httpRequest.agentName, JSON.stringify({
  280. id: docInfo.id,
  281. uid: docInfo.uid,
  282. token: docInfo.token,
  283. imei: localStorage.getItem('WLYY_IMEI'),
  284. platform: 4
  285. }));
  286. //将用户的角色信息单独存储在localstorage中
  287. localStorage.setItem("userRole", JSON.stringify(docInfo.userRole));
  288. window.location.href = "../home/html/index.html";
  289. } else {
  290. tip(res.msg);
  291. }
  292. });
  293. }
  294. })()