login.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. var _this;
  2. new Vue({
  3. el: '#app',
  4. data: function() {
  5. return {
  6. userName: "",
  7. userPwd: "",
  8. codeImg: "",
  9. codePwd: "",
  10. uuId: "",
  11. logining: false
  12. }
  13. },
  14. created() {
  15. _this = this;
  16. _this.getCode();
  17. _this.checkUuid(0);
  18. let _src = window.location.href.split("?id=");
  19. defUrl = _src.length > 1?_src[1]:"main";
  20. if (localStorage.getItem("ylToken") != "null" && localStorage.getItem("ylToken") != null) {
  21. top.location.href = "./view/"+defUrl+".html";
  22. } else {
  23. }
  24. },
  25. methods: {
  26. checkUuid(num){
  27. $.ajax({
  28. url: genUrl + "/gps-web/h5/blogin?&_t="+new Date().getTime(),
  29. type: "GET",
  30. dataType: "JSON",
  31. async: true,
  32. data:{},
  33. error: function(XMLHttpRequest) {
  34. console.log(11111)
  35. },
  36. success:function (res) {
  37. if(res.result!=""){
  38. _this.getSeId(res.result.uuid,num);
  39. }
  40. }
  41. })
  42. },
  43. getSeId(code,_num){
  44. $.ajax({
  45. url: genUrl + "/gps-web/h5/login?_t="+new Date().getTime(),
  46. type: "POST",
  47. dataType: "JSON",
  48. contentType: 'application/json; charset=UTF-8',
  49. async: true,
  50. data: JSON.stringify({
  51. code: [{x: 135, y: 501, t: 28185}],
  52. codeId: code,
  53. h5login: true,
  54. loginLang: "zh_CN",
  55. loginType: "user",
  56. loginWay: "ie",
  57. password: "827ccb0eea8a706c4c34a16891f84e7b",
  58. plateColor: "1",
  59. smsCode: null,
  60. userId: "YZ"
  61. }),
  62. error: function(XMLHttpRequest) {
  63. console.log(11111)
  64. },
  65. success:function (res) {
  66. if(res.result!=""){
  67. _SeId = res.result.split("ok#")[1];
  68. if(_num == 1){
  69. _this.getCTok();
  70. }
  71. }
  72. }
  73. })
  74. },
  75. getCTok(){
  76. $.ajax({
  77. url: genUrl + "/gps-web/h5/alogin?sessionId="+_SeId+"&_t="+new Date().getTime(),
  78. type: "GET",
  79. dataType: "JSON",
  80. async: true,
  81. data:{},
  82. error: function(XMLHttpRequest) {
  83. console.log(11111)
  84. },
  85. success:function (res) {
  86. if(res.result!=""){
  87. localStorage.removeItem("AjaxGen");
  88. localStorage.setItem("AjaxGen",res.result.authorization);
  89. _this.getYsyTok()
  90. }else{
  91. _this.checkUuid(1);
  92. }
  93. }
  94. })
  95. },
  96. getYsyTok(){
  97. $.ajax({
  98. url: "https://open.ys7.com/api/lapp/token/get",
  99. type: "POST",
  100. dataType: "JSON",
  101. async: false,
  102. data:{
  103. appKey:"443b2b196905436dbdf1ad6f30b0ac0d",
  104. appSecret:"08d8c3401a809115d442108883735c70"
  105. },
  106. success:function (json) {
  107. if(json.code == 200){
  108. localStorage.removeItem("ysyToken");
  109. localStorage.setItem("ysyToken",json.data.accessToken);
  110. top.location.href = "./view/"+defUrl+".html";
  111. }
  112. }
  113. })
  114. },
  115. getCode(){
  116. $.ajax({
  117. url: "http://121.37.6.200:8088/captchaImage",
  118. type: "GET",
  119. dataType: "JSON",
  120. async: true,
  121. data:{},
  122. error: function(XMLHttpRequest) {
  123. console.log(11111)
  124. },
  125. success:function (res) {
  126. if(res.code == 200){
  127. _this.uuId = res.uuid;
  128. _this.codeImg = "data:image/jpg;base64,"+res.img;
  129. }
  130. }
  131. })
  132. },
  133. logIn(){
  134. if(_this.userName == ""){
  135. _this.$message({
  136. message: '请填写用户账号!',
  137. type: 'warning'
  138. });
  139. return;
  140. }
  141. if(_this.userPwd == ""){
  142. _this.$message({
  143. message: '请填写用户密码!',
  144. type: 'warning'
  145. });
  146. return;
  147. }
  148. if(_this.codePwd == ""){
  149. _this.$message({
  150. message: '请填写验证码!',
  151. type: 'warning'
  152. });
  153. return;
  154. }
  155. _this.logining = true;
  156. $.ajax({
  157. url: "http://121.37.6.200:8088/login",
  158. type: "POST",
  159. dataType: "JSON",
  160. async: false,
  161. contentType: 'application/json; charset=UTF-8',
  162. data: JSON.stringify({
  163. code: _this.codePwd,
  164. password: _this.userPwd,
  165. username: _this.userName,
  166. uuid: _this.uuId
  167. }),
  168. success:function (json) {
  169. if(json.code == 200){
  170. localStorage.removeItem("ylToken");
  171. localStorage.setItem("ylToken",json.token);
  172. _this.getCTok();
  173. }else{
  174. _this.$message({
  175. message: json.msg,
  176. type: 'warning'
  177. });
  178. _this.getCode();
  179. _this.logining = false;
  180. }
  181. }
  182. })
  183. },
  184. keyDown(ev){
  185. console.log(ev)
  186. }
  187. }
  188. })